diff options
author | wrtbuild <wrtbuild@localhost.(none)> | 2011-10-16 07:34:24 (GMT) |
---|---|---|
committer | wrtbuild <wrtbuild@localhost.(none)> | 2011-10-16 07:34:24 (GMT) |
commit | 64ca2d1ca4e6f9ae279fc17d84b2abd453140d28 (patch) | |
tree | 84a28cd644955e52bd6b91f2c474e9f338841119 /files/common/sbin | |
parent | 0850ac21d153d490ddc2b02f29b74b4b5ed88181 (diff) |
add makefile to generate images
Diffstat (limited to 'files/common/sbin')
-rwxr-xr-x | files/common/sbin/n2n_watchdog | 26 | ||||
-rwxr-xr-x | files/common/sbin/setup_router | 64 | ||||
-rwxr-xr-x | files/common/sbin/splash_sync | 51 | ||||
-rwxr-xr-x | files/common/sbin/test_gateway | 15 | ||||
-rwxr-xr-x | files/common/sbin/test_vpn | 15 |
5 files changed, 171 insertions, 0 deletions
diff --git a/files/common/sbin/n2n_watchdog b/files/common/sbin/n2n_watchdog new file mode 100755 index 0000000..247753b --- /dev/null +++ b/files/common/sbin/n2n_watchdog @@ -0,0 +1,26 @@ +#!/bin/ash + +if [[ `uci get batman-adv.bat0.gw_mode` = "server" ]]; then + + n2n_pwd=`wget http://www.freifunk-jena.de/n2n -O - -q` + n2n1_pwd_old=`uci get n2n.@edge[1].key` + n2n2_pwd_old=`uci get n2n.@edge[0].key` + + if [[ $n2n_pwd != $n2n1_pwd_old && $n2n_pwd != "" -o $n2n_pwd != $n2n2_pwd_old && $n2n_pwd != "" ]]; then + uci set n2n.@edge[0].key=$n2n_pwd + uci set n2n.@edge[1].key=$n2n_pwd + uci commit n2n + /etc/init.d/n2n restart + logger "n2n password updated and restarted (new password)" + fi + + sleep 5 + n2n_neighbors=`batctl o | grep n2n | wc -l` + + if [[ $n2n_neighbors -lt 1 ]]; then + /etc/init.d/n2n restart + logger "n2n restarted (no neighbors via n2n)" + fi +else + exit 0 +fi diff --git a/files/common/sbin/setup_router b/files/common/sbin/setup_router new file mode 100755 index 0000000..36b62e5 --- /dev/null +++ b/files/common/sbin/setup_router @@ -0,0 +1,64 @@ +#!/bin/sh +echo "Soll dieser Router als Gateway arbeiten? (j/n) " +read router +echo +if [[ $router = "j" ]] + then + #Act a a Router + #set ipv4 Adress + echo "Bitte warten, es wird automatisch eine freie IP ermittelt (Kann bis zu 10 Minuten dauern)" + /etc/init.d/n2n enable + /etc/init.d/n2n start + sleep 20 + for i in `seq 1 254 `; do + LOSS=`ping -c3 10.17.$i.1 | grep loss | awk '{print $7}' | sed 's/%//g'; sleep 1` + sleep 1; + if [[ 99 -lt $LOSS ]]; then + NODE_IP=10.17.$i.1 + oct3=$i + break + fi + done + + uci set network.mesh.ipaddr=$NODE_IP + uci set network.mesh.proto=static + uci set network.mesh.netmask=255.255.0.0 + uci set dhcp.mesh=dhcp + uci set dhcp.mesh.start=2 + uci set dhcp.mesh.limit=254 + uci set dhcp.mesh.leasetime=12h + uci set dhcp.mesh.interface=mesh + uci set dhcp.mesh.start_ip=10.17.$oct3.2 + uci set dhcp.mesh.end_ip=10.17.$oct3.254 + uci commit dhcp + # Batman Server Mode + uci set batman-adv.bat0.gw_mode=server + uci commit batman-adv + # Add Cron Jobs + echo "* * * * * /sbin/test_gateway > /dev/null" >> /etc/crontabs/root + echo "* * * * * /sbin/splash_sync > /dev/null" >> /etc/crontabs/root + echo "*/15 * * * * /sbin/n2n_watchdog > /dev/null" >> /etc/crontabs/root + /etc/init.d/cron restart + echo $'\n\n\n\n' + echo "Einrichtung des Routers abgeschossen! +Dieser Router hat folgende IP: $NODE_IP" + echo $'\n\n\n\n' + else + # Act as a node only + uci del dhcp.mesh + uci commit dhcp + uci del network.mesh.ipaddr + uci del network.mesh.proto + uci del network.mesh.netmask + uci commit network + echo "Der Router wird als normaler Node konfiguriert" + echo + # Batman Client Mode + uci set batman-adv.bat0.gw_mode=client + uci commit batman-adv +fi +uci commit +/etc/init.d/batman-adv restart +#TODO: Generate Subnet +#TODO: DHCP Configuration +#HINT: Port freifunk-wizzard-leipzig in from lua (http://luci.subsignal.org/trac/browser/luci/branches/luci-0.10/applications/luci-ffwizard-leipzig/luasrc/model/cbi/ffwizard.lua) diff --git a/files/common/sbin/splash_sync b/files/common/sbin/splash_sync new file mode 100755 index 0000000..3a2b0f1 --- /dev/null +++ b/files/common/sbin/splash_sync @@ -0,0 +1,51 @@ +#!/bin/sh +. $IPKG_INSTROOT/etc/functions.sh +x=0 +config_load splash_users +test=1 +myip=`uci get network.mesh.ipaddr` +splash_check() { + timeout=6000 + current_time=`date +%s` + config_get mac "$1" mac + config_get time "$1" time + local config="$1" + let time_check=$time+$timeout + if [ $time_check -gt $current_time ]; then + # User ist noch gesplashed + iptables -t nat -D ffj_splash -m mac --mac-source $mac -j ACCEPT + iptables -t nat -I ffj_splash 1 -m mac --mac-source $mac -j ACCEPT + else + # User is not longer splashed / the user must click again + iptables -t nat -D ffj_splash -m mac --mac-source $mac -j ACCEPT + uci delete splash_users.@user[$x].mac + uci delete splash_users.@user[$x].time + uci delete splash_users.@user[$x] + + fi + let x=$x+1 +} +#chain refresh +iptables -t nat -D zone_mesh_prerouting -p tcp -j ffj_splash +iptables -t nat -F ffj_splash +iptables -t nat -X ffj_splash +#recreation +iptables -t nat -N ffj_splash +iptables -t nat -I zone_mesh_prerouting 1 -p tcp -j ffj_splash +config_foreach splash_check user +#DNS Whitelisting +iptables -t nat -p udp -A ffj_splash --dport 53 -j ACCEPT +#Jabber Whitelisting +iptables -t nat -p tcp -A ffj_splash --dport 5222 -j ACCEPT +iptables -t nat -p tcp -A ffj_splash --dport 5223 -j ACCEPT +#Free Wavez in Freifunk +iptables -t nat -A ffj_splash -s 10.0.0.0/8 -d 10.0.0.0/8 -j ACCEPT +#Freifunk-Jena Whitelisting +iptables -t nat -A ffj_splash -d freifunk-jena.de -j ACCEPT +iptables -t nat -A ffj_splash -d www.freifunk-jena.de -j ACCEPT +#Jappix Whitelisting +iptables -t nat -A ffj_splash -d static.jappix.com -j ACCEPT +iptables -t nat -A ffj_splash -p tcp -j DNAT --to $myip:80 + + + diff --git a/files/common/sbin/test_gateway b/files/common/sbin/test_gateway new file mode 100755 index 0000000..97296e2 --- /dev/null +++ b/files/common/sbin/test_gateway @@ -0,0 +1,15 @@ +#!/bin/sh +TESTHOST=4.2.2.4 +ping -c 1 -w 5 $TESTHOST &>/dev/null + +if [ $? -ne 0 ] ; then + // IP not reachable -> try if-down-up + ifdown wan + ifup wan + sleep 10 + // Test Again + ping -c 1 -w 5 4.2.2.4 &>/dev/null + if [ $? -ne 0 ] ; then + ifdown wan + fi +fi diff --git a/files/common/sbin/test_vpn b/files/common/sbin/test_vpn new file mode 100755 index 0000000..f69b5a7 --- /dev/null +++ b/files/common/sbin/test_vpn @@ -0,0 +1,15 @@ +#!/bin/sh +TESTHOST=4.2.2.4 +ping -c 1 -w 5 -I tun0 $TESTHOST &>/dev/null + +if [ $? -ne 0 ] ; then + // IP not reachable -> restart openvpn + /etc/init.d/openvpn restart + sleep 10 + // Test Again + ping -c 1 -w 5 -I tun0 $TESTHOST &>/dev/null + if [ $? -ne 0 ] ; then + /etc/init.d/openvpn stop + ifdown wan + fi +fi |