#!/bin/sh -e . ../common.sh # setup random ip net=$( uci get cloud.cur.net_robinson) net_fake=$(uci get cloud.cur.net_fake) prefix=$(ipcalc.sh $net | grep ^PREFIX | cut -f2 -d=) gen_randip () { local r=$RANDOM randip=$( ipcalc.sh $net $((($r % 2**(24 - $prefix) - 1) * 2**8 + 1)) 1 \ | grep ^START | cut -f2 -d= ) } gen_randip while ! arping -I br-mesh -D -c 5 -q $randip; do gen_randip done mesh_add_ipv4 $randip 255.0.0.0 # setup dhcp, start fake DNS echo " set dhcp.mesh=dhcp set dhcp.mesh.start=3 set dhcp.mesh.limit=254 set dhcp.mesh.leasetime=60 set dhcp.mesh.interface=mesh set dhcp.fakedns=domain set dhcp.fakedns.ip=$(ipcalc.sh $net_fake 1 0 | grep ^START | cut -f2 -d=) set dhcp.fakedns.name='#' " | uci batch /etc/init.d/dnsmasq restart # disable batman-adv-mangling with DHCP packets batctl gw off # start redirection httpd, add robinson IP to service httpd echo "http://$randip/robinson.html" > /tmp/redirection_target enable_httpd redirection $randip:81 change_service_httpd_listen $randip:80 /etc/init.d/uhttpd restart # redirect all tcp traffic to local httpd, all dns traffic to local NS iptables -t nat -F prerouting_robinson_fake iptables -t nat -F prerouting_robinson_inet iptables -t nat -A prerouting_robinson_inet -p tcp \ -j DNAT --to-destination $randip:81 iptables -t nat -A prerouting_robinson_inet -p udp --dport 53 \ -j DNAT --to-destination $randip:53