diff options
Diffstat (limited to 'contrib/package/meshwizard/files/usr/bin')
7 files changed, 211 insertions, 132 deletions
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh index e3eb6a7793..f5c44161ec 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh @@ -1,75 +1,63 @@ #!/bin/sh -# This will add $net to the zone firewall (and remove it from other zones where it is referenced) -# It will also setup rules defined in /etc/config/freifunk and /etc/config/profile_<community> -# Arg $1 = $net +# Add "freifunk" firewall zone +# If wan is used for olsr then delete wan zone and all wan rules +# Also setup rules defined in /etc/config/freifunk and /etc/config/profile_<community> -net=$1 . /etc/functions.sh . $dir/functions.sh -config_load firewall -# Get some variables -type="$(uci -q get wireless.$net.type)" -vap="$(uci -q get meshwizard.netconfig.$net\_vap)" +wan_is_olsr=$(uci -q get meshwizard.netconfig.wan_config) + +config_load firewall -# Add local_restrict to wan firewall zone +# Add local_restrict to wan firewall zone (if wan is not used for olsr) +# If wan is used for olsr then remove the firewall zone wan handle_zonewan() { config_get name "$1" name if [ "$name" == "wan" ]; then - uci set firewall.$1.local_restrict=1 + if [ "$wan_is_olsr" == 1 ]; then + uci del firewall.$1 && uci_commitverbose "WAN is used for olsr, delete firewall zone wan" firewall + else + uci set firewall.$1.local_restrict=1 && uci_commitverbose "Enable local_restrict for zone wan" firewall + fi fi } -config_foreach handle_zonewan zone && uci_commitverbose "Enable local_restrict for zone wan" firewall +config_foreach handle_zonewan zone -# Delete old firewall zone for freifunk +# Rename firewall zone for freifunk if unnamed and delete wan zone if it is used for olsr; else enable local restrict handle_fwzone() { config_get name "$1" name config_get network "$1" network - if [ "$2" == "zoneconf" ]; then - if [ "$name" == "freifunk" ]; then - # rename section if unnamed - if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then - section_rename firewall $1 zone_freifunk - fi + if [ "$name" == "freifunk" ]; then + # rename section if unnamed + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename firewall $1 zone_freifunk + fi + fi + + if [ "$name" == "wan" ]; then + if [ "$wan_is_olsr" == 1 ]; then + uci del firewall.$1 && uci_commitverbose "WAN is used for olsr, delete firewall zone wan" firewall else - if [ -n "$netrenamed" -a -n "$(echo $network | grep $netrenamed)" ] && [ ! "$name" == "freifunk" ]; then - echo " Removed $netrenamed from firewall zone $name." - network_new=$(echo $network | sed -e 's/'$netrenamed'//' -e 's/^ //' -e 's/ / /' -e 's/ $//') - uci set firewall.$1.network="$network_new" - fi + uci set firewall.$1.local_restrict=1 && uci_commitverbose "Enable local_restrict for zone wan" firewall fi fi } -config_foreach handle_fwzone zone zoneconf - -# setup freifunk firewall zone -# add $netrenamed and if needed ${netrenamed}dhcp to the networks for this zone -config_get network zone_freifunk network - -# remove ${netrenamed}dhcp from networks list -[ -n "$network" -a -n "$net" ] && network="${network/${netrenamed}dhcp/}" -network=$(echo $network) # Removes leading and trailing whitespaces - -[ -n "$netrenamed" ] && [ -z "$(echo $network | grep $netrenamed)" ] && network="$network $netrenamed" - -if [ "$type" == "atheros" -a "$vap" == 1 ]; then - [ -n "$netrenamed" ] && [ "$network" == "${network/${netrenamed}dhcp/}" ] && network="$network ${netrenamed}dhcp" -fi +config_foreach handle_fwzone zone uci batch << EOF set firewall.zone_freifunk="zone" set firewall.zone_freifunk.name="freifunk" -set firewall.zone_freifunk.network="$network" set firewall.zone_freifunk.input="$zone_freifunk_input" set firewall.zone_freifunk.forward="$zone_freifunk_forward" set firewall.zone_freifunk.output="$zone_freifunk_output" EOF -uci_commitverbose "Setup freifunk firewall zone" firewall +uci_commitverbose "Setup firewall zones" firewall -# Usually we need to setup masquerading for lan, except lan is an olsr interface or has an olsr hna +# Usually we need to setup masquerading for lan, except lan is an olsr interface or has an olsr hna-entry handle_interface() { config_get interface "$1" interface @@ -80,13 +68,16 @@ handle_interface() { config_load olsrd config_foreach handle_interface Interface -handle_hna() { - config_get netaddr "$1" netaddr - if [ "$NETWORK" == "$netaddr" ]; then - no_masq_lan=1 - fi -} -config_foreach handle_hna Hna4 +LANIP="$(uci -q get network.lan.ipaddr)" +if [ -n "$LANIP" ]; then + handle_hna() { + config_get netaddr "$1" netaddr + if [ "$LANIP" == "$netaddr" ]; then + no_masq_lan=1 + fi + } + config_foreach handle_hna Hna4 +fi currms=$(uci -q get firewall.zone_freifunk.masq_src) if [ ! "$no_masq_lan" == "1" ]; then @@ -94,22 +85,8 @@ if [ ! "$no_masq_lan" == "1" ]; then [ -z "$(echo $currms |grep lan)" ] && uci add_list firewall.zone_freifunk.masq_src="lan" fi -# If wifi-interfaces are outside of the mesh network they should be natted -for i in $networks; do - # Get dhcprange and meshnet - dhcprange=$(uci get meshwizard.netconfig.$i\_dhcprange) - meshnet="$(uci get profile_$community.profile.mesh_network)" - # check if the dhcprange is inside meshnet - dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" - if [ ! "$dhcpinmesh" == 1 ]; then - [ -z "$(echo $currms |grep ${netrenamed}dhcp)" ] && uci add_list firewall.zone_freifunk.masq_src="${netrenamed}dhcp" - fi -done - -uci_commitverbose "Setup masquerading rules" firewall # Rules, Forwardings, advanced config and includes -# Clear firewall configuration for config in freifunk profile_$community; do @@ -126,6 +103,22 @@ for config in freifunk profile_$community; do config_foreach handle_firewall $section done done - uci_commitverbose "Setup rules, forwardings, advanced config and includes." firewall +# If wan is used for olsr we need to cleanup old wan (forward) rules + +if [ "$wan_is_olsr" == 1 ]; then + handle_wanrules() { + config_get src "$1" src + config_get dest "$1" dest + if [ "$src" == "wan" ] || [ "$dest" == "wan" ]; then + uci del firewall.$1 + fi + } + for i in rule forwarding; do + config_load firewall + config_foreach handle_wanrules $i + done + uci_commitverbose "Wan is used for olsr, delete wan firewall rules and forwardings" firewall +fi + diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall_interface.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall_interface.sh new file mode 100755 index 0000000000..83b41d0a01 --- /dev/null +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall_interface.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# This will add $net to the zone firewall (and remove it from other zones where it is referenced) +# It will also setup rules defined in /etc/config/freifunk and /etc/config/profile_<community> +# Arg $1 = $net + +net=$1 +. /etc/functions.sh +. $dir/functions.sh +config_load firewall + +# Get some variables +type="$(uci -q get wireless.$net.type)" +vap="$(uci -q get meshwizard.netconfig.$net\_vap)" +wan_is_olsr=$(uci -q get meshwizard.netconfig.wan_config) + +# Delete old firewall zone for freifunk +handle_fwzone() { + config_get name "$1" name + config_get network "$1" network + + if [ "$2" == "zoneconf" ]; then + if [ "$name" == "freifunk" ]; then + # rename section if unnamed + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename firewall $1 zone_freifunk + fi + else + if [ ! "$name" == "freifunk" ] && [ -n "$netrenamed" -a -n "$(echo $network | grep $netrenamed)" ]; then + echo " Removed $netrenamed from firewall zone $name." + network_new=$(echo $network | sed -e 's/'$netrenamed'//' -e 's/^ //' -e 's/ / /' -e 's/ $//') + uci set firewall.$1.network="$network_new" + fi + fi + fi +} + +config_foreach handle_fwzone zone zoneconf + +# Add $netrenamed and if needed ${netrenamed}dhcp to the "freifunk" zone +config_get network zone_freifunk network + +# remove ${netrenamed}dhcp from networks list +[ -n "$network" -a -n "$net" ] && network="${network/${netrenamed}dhcp/}" +network=$(echo $network) # Removes leading and trailing whitespaces + +[ -n "$netrenamed" ] && [ -z "$(echo $network | grep $netrenamed)" ] && network="$network $netrenamed" + +if [ "$type" == "atheros" -a "$vap" == 1 ]; then + [ -n "$netrenamed" ] && [ "$network" == "${network/${netrenamed}dhcp/}" ] && network="$network ${netrenamed}dhcp" +fi + +uci set firewall.zone_freifunk.network="$network" + +uci_commitverbose "Add '$netrenamed' to freifunk firewall zone" firewall + +currms=$(uci -q get firewall.zone_freifunk.masq_src) + +# If interfaces are outside of the mesh network they should be natted +for i in $networks; do + # Get dhcprange and meshnet + dhcprange=$(uci -q get meshwizard.netconfig.$i\_dhcprange) + if [ -n "$dhcprange" ]; then + meshnet="$(uci get profile_$community.profile.mesh_network)" + # check if the dhcprange is inside meshnet + dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" + if [ ! "$dhcpinmesh" == 1 ]; then + [ -z "$(echo $currms |grep ${netrenamed}dhcp)" ] && uci add_list firewall.zone_freifunk.masq_src="${netrenamed}dhcp" + fi + fi +done + +uci_commitverbose "Setup masquerading rules for '$netrenamed'" firewall diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh index 1492cbbb0d..9958af1ac9 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh @@ -61,12 +61,12 @@ if [ "$net_dhcp" == 1 ]; then uci set network.${netrenamed}dhcp.interface="$netrenamed" fi - uci batch << EOF +uci batch << EOF set network.${netrenamed}dhcp.proto=static set network.${netrenamed}dhcp.ipaddr="$START" set network.${netrenamed}dhcp.netmask="$NETMASK" +uci_commitverbose "Setup interface for ${netrenamed}dhcp" network EOF fi -uci_commitverbose "Setup interface for ${netrenamed}dhcp" network diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh index ba11b5174a..39a4849c82 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh @@ -1,13 +1,11 @@ #!/bin/sh # Sets up olsrd -# arg $1 = net - -net=$1 . /etc/functions.sh . $dir/functions.sh # Rename interface defaults + handle_interfacedefaults() { if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then section_rename olsrd $1 InterfaceDefaults @@ -21,53 +19,14 @@ uci set olsrd.InterfaceDefaults=InterfaceDefaults set_defaults "olsr_interfacedefaults_" olsrd.InterfaceDefaults uci_commitverbose "Setup olsr interface defaults" olsrd -# Rename interface for $netrenamed -handle_interface() { - config_get interface "$1" Interface - if [ "$interface" == "$netrenamed" ]; then - if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then - section_rename olsrd $1 $netrenamed - fi - fi -} - -config_foreach handle_interface Interface - -# Setup new interface for $netrenamed - -uci set olsrd.$netrenamed=Interface -set_defaults "olsr_interface_" olsrd.$net -uci set olsrd.$netrenamed.interface="$netrenamed" - -uci_commitverbose "Setup olsr interface for $netrenamed." olsrd - -# If dhcp-network is inside the mesh_network then add HNA for it -dhcprange=$(uci get meshwizard.netconfig.$net\_dhcprange) -meshnet="$(uci get profile_$community.profile.mesh_network)" - -uci -q delete olsrd.${netrenamed}clients - -# check if the dhcprange is inside meshnet -dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" - -# If it is setup hna for it -if [ "$dhcpinmesh" == 1 ]; then - uci set olsrd.${netrenamed}clients="Hna4" - eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange) - uci set olsrd.${netrenamed}clients.netaddr="$NETWORK" - uci set olsrd.${netrenamed}clients.netmask="$NETMASK" - uci_commitverbose "Setup HNA for network $dhcprange" olsrd -fi - - # Rename nameservice, dyngw and httpinfo plugins handle_plugin() { - config_get library "$1" library + config_get library "$1" library if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then new="$(echo $library | cut -d '.' -f 1)" section_rename olsrd $1 $new - fi + fi } config_foreach handle_plugin LoadPlugin @@ -97,6 +56,6 @@ if [ "$sharenet" == 1 ]; then uci set olsrd.dyngw_plain=LoadPlugin uci set olsrd.dyngw_plain.ignore=0 uci set olsrd.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4" + uci_commitverbose "Setup olsrd_dyngw_plain plugin" olsrd fi - diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh new file mode 100755 index 0000000000..7472b625d9 --- /dev/null +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd_interface.sh @@ -0,0 +1,50 @@ +#!/bin/sh +# Sets up olsrd interfaces +# arg $1 = net + +net=$1 + +. /etc/functions.sh +. $dir/functions.sh + +# Rename interface for $netrenamed +handle_interface() { + config_get interface "$1" Interface + if [ "$interface" == "$netrenamed" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename olsrd $1 $netrenamed + fi + fi +} + +config_foreach handle_interface Interface + +# Setup new interface for $netrenamed + +uci set olsrd.$netrenamed=Interface +set_defaults "olsr_interface_" olsrd.$net +uci set olsrd.$netrenamed.interface="$netrenamed" + +uci_commitverbose "Setup olsr interface for $netrenamed." olsrd + +# If dhcp-network is inside the mesh_network then add HNA for it +dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange) + +uci -q delete olsrd.${netrenamed}clients + +# check if the dhcprange is inside meshnet + +if [ "$dhcp_range" == 1 ]; then + dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)" + meshnet="$(uci get profile_$community.profile.mesh_network)" + + # If it is setup hna for it + if [ "$dhcpinmesh" == 1 ]; then + uci set olsrd.${netrenamed}clients="Hna4" + eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange) + uci set olsrd.${netrenamed}clients.netaddr="$NETWORK" + uci set olsrd.${netrenamed}clients.netmask="$NETMASK" + uci_commitverbose "Setup HNA for network $dhcprange" olsrd + fi +fi + diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh index 1d1e248593..afbe1d5dae 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh @@ -11,24 +11,25 @@ if [ ! "$has_luci_splash" == TRUE ]; then exit fi -handle_splash() { - config_get network "$1" network - if [ "$network" == "${netrenamed}dhcp" ]; then - if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then - section_rename luci_splash $1 ${netrenamed}dhcp +dhcprange=$(uci -q get meshwizard.netconfig.$net\_dhcprange) + +if [ "$dhcp_range" == 1 ]; then + handle_splash() { + config_get network "$1" network + if [ "$network" == "${netrenamed}dhcp" ]; then + if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then + section_rename luci_splash $1 ${netrenamed}dhcp + fi fi - fi -} -config_load luci_splash -config_foreach handle_splash iface + } + config_load luci_splash + config_foreach handle_splash iface -uci batch << EOF -set luci_splash.${netrenamed}dhcp="iface" -set luci_splash.${netrenamed}dhcp.network="${netrenamed}dhcp" -set luci_splash.${netrenamed}dhcp.zone="freifunk" -EOF + uci set luci_splash.${netrenamed}dhcp="iface" + uci set luci_splash.${netrenamed}dhcp.network="${netrenamed}dhcp" + uci set luci_splash.${netrenamed}dhcp.zone="freifunk" -uci_commitverbose "Setup dhcpsplash for ${netrenamed}dhcp" luci_splash - -/etc/init.d/luci_splash enable + uci_commitverbose "Setup dhcpsplash for ${netrenamed}dhcp" luci_splash + /etc/init.d/luci_splash enable +fi diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh index 4b330ddeca..2b85b73799 100755 --- a/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh +++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh @@ -12,7 +12,7 @@ . /etc/functions.sh echo " -/* Meshwizard 0.0.4 */ +/* Meshwizard 0.0.5 */ " # config @@ -55,6 +55,8 @@ done < /tmp/meshwizard.tmp $dir/helpers/initial_config.sh $dir/helpers/setup_dnsmasq.sh $dir/helpers/setup_system.sh +$dir/helpers/setup_olsrd.sh +$dir/helpers/setup_firewall.sh # Configure found networks for net in $networks; do @@ -62,8 +64,10 @@ for net in $networks; do netrenamed="${net/radio/wireless}" export netrenamed $dir/helpers/setup_network.sh $net - $dir/helpers/setup_wifi.sh $net - $dir/helpers/setup_olsrd.sh $net + if [ ! "$net" == "wan" ]; then + $dir/helpers/setup_wifi.sh $net + fi + $dir/helpers/setup_olsrd_interface.sh $net net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp) if [ "$net_dhcp" == 1 ]; then @@ -71,9 +75,9 @@ for net in $networks; do fi $dir/helpers/setup_splash.sh $net - $dir/helpers/setup_firewall.sh $net + $dir/helpers/setup_firewall_interface.sh $net done ##### Reboot the router (because simply restarting services gave errors) -reboot +#reboot |