From 38ac0950e452852dd60432880a56e9302699f421 Mon Sep 17 00:00:00 2001 From: Packet Please Date: Thu, 11 Apr 2024 00:28:11 +0200 Subject: [PATCH] treewide: make fmt Signed-off-by: Packet Please --- luci/luci-app-falter-owm/files/owm-defaults | 7 +- luci/luci-app-falter-owm/files/owm.sh | 197 +++++++++--------- .../root/usr/libexec/rpcd/ffwizard-berlin | 24 +-- .../files/register_keys.sh | 2 +- .../files/autoupdate.sh | 30 +-- .../files/post-inst.sh | 4 +- .../files/etc/uci-defaults/90-bbbdigger | 18 +- .../files/lib/functions/semver.sh | 2 +- .../freifunk-berlin-01-migration.sh | 57 +++-- .../files/register-services.sh | 3 +- .../files/hotplug.d/30-ssid-changer | 2 +- .../files/tunnelman.sh | 60 +++--- .../uci-defaults/freifunk-berlin-z95_notunnel | 53 +++-- ...ifunk-berlin-z95_tunnelberlin-tunneldigger | 31 ++- .../files/etc/profile.d/10_dynbanner.sh | 10 +- .../files/etc/rc.local.d/olsr-dnsmasq | 2 +- .../freifunk-berlin-ffwizard3-json | 2 +- .../freifunk-berlin-freifunk-defaults | 2 +- .../files/lib/functions/guard.sh | 30 +-- .../falter-common/files/sbin/ffwizard2uci | 60 +++--- .../falter-common/files/sbin/uci2ffwizard | 10 +- packages/falter-common/files/usr/bin/watch.sh | 15 +- .../files/etc/uci-defaults/65-falter-firewall | 10 +- .../freifunk-berlin-dhcp-defaults | 2 +- .../freifunk-berlin-ffuplink-defaults | 1 - .../freifunk-berlin-network-defaults | 59 +++--- .../freifunk-berlin-olsrd-defaults | 12 +- .../freifunk-berlin-statistics-defaults | 6 +- .../freifunk-berlin-system-defaults | 4 +- .../freifunk-berlin-wireless-defaults | 4 +- .../etc/hotplug.d/iface/30-policyrouting | 142 ++++++------- .../hotplug.d/iface/60-ffuplink_policyrouting | 56 ++--- .../pingcheck/offline.d/60-freifunk-notunnel | 1 - .../etc/pingcheck/offline.d/60-freifunk-wan | 1 - .../etc/pingcheck/online.d/60-freifunk-wan | 1 - .../etc/uci-defaults/freifunk-policyrouting | 2 - 36 files changed, 455 insertions(+), 467 deletions(-) diff --git a/luci/luci-app-falter-owm/files/owm-defaults b/luci/luci-app-falter-owm/files/owm-defaults index 7099bba5..7948fedc 100644 --- a/luci/luci-app-falter-owm/files/owm-defaults +++ b/luci/luci-app-falter-owm/files/owm-defaults @@ -1,7 +1,10 @@ #!/bin/sh test -f /etc/crontabs/root || touch /etc/crontabs/root OWM="/usr/sbin/owm.sh" -SEED="$( dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read -r line; then echo "0x${line#* }"; fi )" +SEED="$(dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read -r line; then echo "0x${line#* }"; fi)" MIN1="$((SEED % 29))" MIN2="$((MIN1 + 30))" -(crontab -l | grep -v "$OWM"; echo "$MIN1,$MIN2 * * * * test -e $OWM && $OWM") | crontab - +( + crontab -l | grep -v "$OWM" + echo "$MIN1,$MIN2 * * * * test -e $OWM && $OWM" +) | crontab - diff --git a/luci/luci-app-falter-owm/files/owm.sh b/luci/luci-app-falter-owm/files/owm.sh index f4ac7f39..8cc6a895 100755 --- a/luci/luci-app-falter-owm/files/owm.sh +++ b/luci/luci-app-falter-owm/files/owm.sh @@ -7,7 +7,6 @@ # Copyright (C) 2021 Patrick Grimm # Copyright (C) 2021 Martin Hübner - # Omit warning for missing local statement. busybox-ash has them included # shellcheck shell=dash @@ -32,7 +31,7 @@ OWM_API_VER="1.0" printhelp() { - printf "owm.sh - Tool for registering routers at openwifimap.net\n + printf "owm.sh - Tool for registering routers at openwifimap.net\n Options: \t--help|-h:\tprint this text @@ -52,12 +51,11 @@ To override the server used by this script, set freifunk.community.owm_api. # save positional argument, as it would get overwritten otherwise. CMD_1="$1" if [ -n "$CMD_1" ] && [ "$CMD_1" != "--dry-run" ]; then - [ "$CMD_1" != "-h" ] && [ "$CMD_1" != "--help" ] && printf "Unrecognized argument %s.\n\n" "$CMD_1" - printhelp - exit 1 + [ "$CMD_1" != "-h" ] && [ "$CMD_1" != "--help" ] && printf "Unrecognized argument %s.\n\n" "$CMD_1" + printhelp + exit 1 fi - # calback function: This function aggregates all items of the 'contact' # option list from /etc/config/freifunk into one single string for better # transport @@ -69,7 +67,6 @@ handle_contact() { fi } - ###################### # # # Collect OWM-Data # @@ -77,17 +74,17 @@ handle_contact() { ###################### olsr4_links() { - json_select "$2" - json_get_var localIP localIP - json_get_var remoteIP remoteIP - remotehost="$(nslookup "$remoteIP" | grep name | sed -e 's/.*name = \(.*\)/\1/' | sed 's/^mid\d*\.//' )" - json_get_var linkQuality linkQuality - json_get_var olsrInterface olsrInterface - json_get_var ifName ifName - json_select .. - if ! echo "$olsrInterface" | grep -q -E '.*(wg|ts)_.*'; then - olsr4links="$olsr4links$localIP $remoteIP $remotehost $linkQuality $ifName;" - fi + json_select "$2" + json_get_var localIP localIP + json_get_var remoteIP remoteIP + remotehost="$(nslookup "$remoteIP" | grep name | sed -e 's/.*name = \(.*\)/\1/' | sed 's/^mid\d*\.//')" + json_get_var linkQuality linkQuality + json_get_var olsrInterface olsrInterface + json_get_var ifName ifName + json_select .. + if ! echo "$olsrInterface" | grep -q -E '.*(wg|ts)_.*'; then + olsr4links="$olsr4links$localIP $remoteIP $remotehost $linkQuality $ifName;" + fi } # This section is relevant for hopglass statistics feature (isUplink/isHotspot) @@ -102,21 +99,19 @@ latitude="$(uci_get system @system[-1] latitude)" # Stop execution if lat/lon is not set. # if [ -z "$latitude" ] || [ -z "$longitude" ]; then - printf "latitude/longitude is not set.\nStopping now...\n" - exit 2 + printf "latitude/longitude is not set.\nStopping now...\n" + exit 2 fi - # collect data on OLSR-links -json_load "$( printf "/links" | nc 127.0.0.1 9090 2>/dev/null)" 2>/dev/null +json_load "$(printf "/links" | nc 127.0.0.1 9090 2>/dev/null)" 2>/dev/null #json_get_var timeSinceStartup timeSinceStartup olsr4links="" -if json_is_a links array;then - json_for_each_item olsr4_links links +if json_is_a links array; then + json_for_each_item olsr4_links links fi json_cleanup - # collect board info json_load "$(ubus call system board)" json_get_var model model @@ -133,10 +128,10 @@ json_get_values loads load # if file freifunk_release is available, override version and revision if [ -f /etc/freifunk_release ]; then - . /etc/freifunk_release - distribution="$FREIFUNK_DISTRIB_ID" - version="$FREIFUNK_RELEASE" - revision="$FREIFUNK_REVISION" + . /etc/freifunk_release + distribution="$FREIFUNK_DISTRIB_ID" + version="$FREIFUNK_RELEASE" + revision="$FREIFUNK_REVISION" fi # Get Sysload @@ -165,7 +160,6 @@ config_list_foreach contact contact handle_contact # omit the first pipe-symbol. contacts=$(echo "$CONTACT_AGGREGATOR" | sed 's/|//') - # community info ssid="$(uci_get freifunk community ssid)" mesh_network="$(uci_get freifunk community mesh_network)" @@ -178,8 +172,6 @@ com_ssid_scheme=$(uci_get freifunk community ssid_scheme) com_splash_network=$(uci_get freifunk community splash_network) com_splash_prefix=$(uci_get freifunk community splash_prefix) - - ########################### # # # Construct JSON-string # @@ -189,36 +181,36 @@ com_splash_prefix=$(uci_get freifunk community splash_prefix) json_init json_add_object freifunk { - json_add_object contact - { - if [ -n "$name" ]; then json_add_string name "$name"; fi - # contact list superseeds the use of mail option - if [ -n "$contacts" ]; then - json_add_string mail "$contacts" - else - if [ -n "$mail" ]; then json_add_string mail "$mail"; fi - fi - if [ -n "$nick" ]; then json_add_string nickname "$nick"; fi - if [ -n "$phone" ]; then json_add_string phone "$phone"; fi - if [ -n "$homepage" ]; then json_add_string homepage "$homepage"; fi # was array of homepages - if [ -n "$note" ]; then json_add_string note "$note"; fi - } - json_close_object - - json_add_object community - { - json_add_string ssid "$ssid" - json_add_string mesh_network "$mesh_network" - json_add_string owm_api "$uci_owm_api" - json_add_string name "$com_name" - json_add_string homepage "$com_homepage" - json_add_string longitude "$com_longitude" - json_add_string latitude "$com_latitude" - json_add_string ssid_scheme "$com_ssid_scheme" - json_add_string splash_network "$com_splash_network" - json_add_int splash_prefix $com_splash_prefix - } - json_close_object + json_add_object contact + { + if [ -n "$name" ]; then json_add_string name "$name"; fi + # contact list superseeds the use of mail option + if [ -n "$contacts" ]; then + json_add_string mail "$contacts" + else + if [ -n "$mail" ]; then json_add_string mail "$mail"; fi + fi + if [ -n "$nick" ]; then json_add_string nickname "$nick"; fi + if [ -n "$phone" ]; then json_add_string phone "$phone"; fi + if [ -n "$homepage" ]; then json_add_string homepage "$homepage"; fi # was array of homepages + if [ -n "$note" ]; then json_add_string note "$note"; fi + } + json_close_object + + json_add_object community + { + json_add_string ssid "$ssid" + json_add_string mesh_network "$mesh_network" + json_add_string owm_api "$uci_owm_api" + json_add_string name "$com_name" + json_add_string homepage "$com_homepage" + json_add_string longitude "$com_longitude" + json_add_string latitude "$com_latitude" + json_add_string ssid_scheme "$com_ssid_scheme" + json_add_string splash_network "$com_splash_network" + json_add_int splash_prefix $com_splash_prefix + } + json_close_object } json_close_object @@ -229,22 +221,22 @@ json_add_double api_rev $OWM_API_VER json_add_object system { - json_add_array sysinfo - { - json_add_string "" "system is deprecated" - json_add_string "" "$model" - } - json_close_array - json_add_array uptime - { - json_add_int "" $uptime - } - json_close_array - json_add_array loadavg - { - json_add_double "" $load5 - } - json_close_array + json_add_array sysinfo + { + json_add_string "" "system is deprecated" + json_add_string "" "$model" + } + json_close_array + json_add_array uptime + { + json_add_int "" $uptime + } + json_close_array + json_add_array loadavg + { + json_add_double "" $load5 + } + json_close_array } json_close_object @@ -252,28 +244,28 @@ json_close_object # That string gets substituted by the olsrd-config-string afterwards json_add_object olsr { - json_add_string ipv4Config '$OLSRCONFIG' + json_add_string ipv4Config '$OLSRCONFIG' } json_close_object json_add_array links { - IFSORIG="$IFS" - IFS=';' - for i in ${olsr4links} ; do - IFS="$IFSORIG" - set -- $i - json_add_object - { - json_add_string sourceAddr4 "$1" - json_add_string destAddr4 "$2" - json_add_string id "$3" - json_add_double quality "$4" - } - json_close_object - IFS=';' - done - IFS="$IFSORIG" + IFSORIG="$IFS" + IFS=';' + for i in ${olsr4links}; do + IFS="$IFSORIG" + set -- $i + json_add_object + { + json_add_string sourceAddr4 "$1" + json_add_string destAddr4 "$2" + json_add_string id "$3" + json_add_double quality "$4" + } + json_close_object + IFS=';' + done + IFS="$IFSORIG" } json_close_array @@ -287,10 +279,10 @@ json_add_int updateInterval 3600 json_add_string hardware "$system" json_add_object firmware { - json_add_string name "$distribution $version" - json_add_string revision "$revision" - json_add_string kernelVersion "$kernelVersion" - json_add_string kernelBuildDate "$buildDate" + json_add_string name "$distribution $version" + json_add_string revision "$revision" + json_add_string kernelVersion "$kernelVersion" + json_add_string kernelBuildDate "$buildDate" } json_close_object @@ -298,15 +290,14 @@ json_close_object JSON_STRING=$(json_dump) # insert json-string from OLSR and repair wrong syntax at string-borders (shell-quotes...) -JSON_STRING=$(echo "$JSON_STRING" | sed -e 's|$OLSRCONFIG|'"$OLSRCONFIG"'|; s|"{|{|; s|}"|}|' ) +JSON_STRING=$(echo "$JSON_STRING" | sed -e 's|$OLSRCONFIG|'"$OLSRCONFIG"'|; s|"{|{|; s|}"|}|') # just print data to stdout, if we have test-run. if [ "$CMD_1" = "--dry-run" ]; then - printf "%s\n" "$JSON_STRING" - exit 0 + printf "%s\n" "$JSON_STRING" + exit 0 fi - ################################ # # # Send data to openwifimap # diff --git a/luci/luci-app-ffwizard-falter/root/usr/libexec/rpcd/ffwizard-berlin b/luci/luci-app-ffwizard-falter/root/usr/libexec/rpcd/ffwizard-berlin index f0e803bf..a8571712 100755 --- a/luci/luci-app-ffwizard-falter/root/usr/libexec/rpcd/ffwizard-berlin +++ b/luci/luci-app-ffwizard-falter/root/usr/libexec/rpcd/ffwizard-berlin @@ -5,20 +5,20 @@ . /usr/share/libubox/jshn.sh case "$1" in - list) - echo '{ "has_root-pass": {} }' - ;; - call) - case "$2" in - has_root-pass) -USER=root -# taken from http://serverfault.com/a/240961 -grep ${USER} /etc/shadow | awk -F":" '{ if ($2 == "!" || $2 == "") \ + list) + echo '{ "has_root-pass": {} }' + ;; + call) + case "$2" in + has_root-pass) + USER=root + # taken from http://serverfault.com/a/240961 + grep ${USER} /etc/shadow | awk -F":" '{ if ($2 == "!" || $2 == "") \ printf "{ \"password_is_set\" : \"no\" }";\ else \ printf "{ \"password_is_set\" : \"yes\" }"\ }' - ;; - esac - ;; + ;; + esac + ;; esac diff --git a/packages/falter-berlin-admin-keys/files/register_keys.sh b/packages/falter-berlin-admin-keys/files/register_keys.sh index 8a19da9f..b3d01317 100755 --- a/packages/falter-berlin-admin-keys/files/register_keys.sh +++ b/packages/falter-berlin-admin-keys/files/register_keys.sh @@ -8,6 +8,6 @@ KEY_FILES=$(find "$SCRIPTPATH" -name "*.pub") for KEY_FILE in $KEY_FILES; do KEY=$(cat "$KEY_FILE") if ! grep -q "$KEY" /etc/dropbear/authorized_keys; then - echo "$KEY" >> /etc/dropbear/authorized_keys + echo "$KEY" >>/etc/dropbear/authorized_keys fi done diff --git a/packages/falter-berlin-autoupdate/files/autoupdate.sh b/packages/falter-berlin-autoupdate/files/autoupdate.sh index 4c03f3e7..656dd6a4 100755 --- a/packages/falter-berlin-autoupdate/files/autoupdate.sh +++ b/packages/falter-berlin-autoupdate/files/autoupdate.sh @@ -91,21 +91,21 @@ MIN_RAM_FREE=1536 # amount of kiB that must be free in RAM after firmware-downlo while getopts him:Nntf option; do case $option in - h) - print_help - exit 0 - ;; - i) OPT_IGNORE_CERTS=1 ;; - m) MIN_CERTS=$OPTARG ;; - N) OPT_NOW=1 ;; - n) OPT_N=1 ;; - t) OPT_TESTRUN=1 ;; - f) OPT_FORCE=1 ;; - *) - printf "\nUnknown argument! Please use valid arguments only.\n\n" - print_help - exit 2 - ;; + h) + print_help + exit 0 + ;; + i) OPT_IGNORE_CERTS=1 ;; + m) MIN_CERTS=$OPTARG ;; + N) OPT_NOW=1 ;; + n) OPT_N=1 ;; + t) OPT_TESTRUN=1 ;; + f) OPT_FORCE=1 ;; + *) + printf "\nUnknown argument! Please use valid arguments only.\n\n" + print_help + exit 2 + ;; esac done diff --git a/packages/falter-berlin-autoupdate/files/post-inst.sh b/packages/falter-berlin-autoupdate/files/post-inst.sh index 412b696d..0abebc53 100644 --- a/packages/falter-berlin-autoupdate/files/post-inst.sh +++ b/packages/falter-berlin-autoupdate/files/post-inst.sh @@ -8,8 +8,8 @@ crontab -l | grep /usr/bin/autoupdate >>/dev/null if [ $? != 0 ]; then # get a fairly random update-time, to protect the servers from DoS. Will be something between 3 and 5 a.m. - HOUR=$(( ($( dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read line; then echo 0x${line#* }; fi ) % 3) + 3)) - MIN=$(( $( dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read line; then echo 0x${line#* }; fi ) % 59)) + HOUR=$((($(dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read line; then echo 0x${line#* }; fi) % 3) + 3)) + MIN=$(($(dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read line; then echo 0x${line#* }; fi) % 59)) echo "$MIN $HOUR * * * test -e /usr/bin/autoupdate && /usr/bin/autoupdate" >>/etc/crontabs/root /etc/init.d/cron restart diff --git a/packages/falter-berlin-bbbdigger/files/etc/uci-defaults/90-bbbdigger b/packages/falter-berlin-bbbdigger/files/etc/uci-defaults/90-bbbdigger index 4f6145eb..db8f7d24 100755 --- a/packages/falter-berlin-bbbdigger/files/etc/uci-defaults/90-bbbdigger +++ b/packages/falter-berlin-bbbdigger/files/etc/uci-defaults/90-bbbdigger @@ -18,19 +18,19 @@ BIND=wan # See the website https://www.itwissen.info/MAC-Adresse-MAC-address.html MAC=$(uci -q get network.${IFACE}_dev.macaddr) if [ $? -eq 1 ]; then - # start with b6 for Berliner 6ackbone - MAC="b6" - for _byte in 2 3 4 5 6; do - MAC=$MAC`dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 ":%02x"'` - done + # start with b6 for Berliner 6ackbone + MAC="b6" + for _byte in 2 3 4 5 6; do + MAC=$MAC$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | hexdump -e '1/1 ":%02x"') + done fi UUID=$(uci -q get tunneldigger.${IFACE}.uuid) if [ $? -eq 1 ]; then - UUID=$MAC - for _byte in 7 8 9 10; do - UUID=$UUID`dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 ":%02x"'` - done + UUID=$MAC + for _byte in 7 8 9 10; do + UUID=$UUID$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | hexdump -e '1/1 ":%02x"') + done fi # tunneldigger setup diff --git a/packages/falter-berlin-migration/files/lib/functions/semver.sh b/packages/falter-berlin-migration/files/lib/functions/semver.sh index a605d83e..9c9371c6 100755 --- a/packages/falter-berlin-migration/files/lib/functions/semver.sh +++ b/packages/falter-berlin-migration/files/lib/functions/semver.sh @@ -101,7 +101,7 @@ semverLT() { return 0 fi - if [ $MAJOR_A -le $MAJOR_B ] && [ $MINOR_A -le $MINOR_B ] && [ $PATCH_A -lt $PATCH_B ]; then + if [ $MAJOR_A -le $MAJOR_B ] && [ $MINOR_A -le $MINOR_B ] && [ $PATCH_A -lt $PATCH_B ]; then return 0 fi diff --git a/packages/falter-berlin-migration/uci-defaults/freifunk-berlin-01-migration.sh b/packages/falter-berlin-migration/uci-defaults/freifunk-berlin-01-migration.sh index f8ba3e49..14d2cd73 100644 --- a/packages/falter-berlin-migration/uci-defaults/freifunk-berlin-01-migration.sh +++ b/packages/falter-berlin-migration/uci-defaults/freifunk-berlin-01-migration.sh @@ -18,7 +18,6 @@ # exponential-calculations are supported by busybox-ash # shellcheck disable=SC3019 - . /lib/functions.sh . /lib/functions/semver.sh . /etc/openwrt_release @@ -164,7 +163,7 @@ update_collectd_memory_leak_hotfix() { sed -i '/luci_statistics restart$/d' $CRONTAB /etc/init.d/cron restart - if [ "$(grep MemTotal: < /proc/meminfo | awk \{'print $2'\})" -lt "65536" ]; then + if [ "$(grep MemTotal: &- | hexdump | if read -r line; then echo "0x${line#* }"; fi ) % 280)) + sleep $(($(dd if=/dev/urandom bs=2 count=1 2>&- | hexdump | if read -r line; then echo "0x${line#* }"; fi) % 280)) fi # check, if we are online diff --git a/packages/falter-berlin-tunnelmanager/files/tunnelman.sh b/packages/falter-berlin-tunnelmanager/files/tunnelman.sh index 656941f5..a21ee72f 100755 --- a/packages/falter-berlin-tunnelmanager/files/tunnelman.sh +++ b/packages/falter-berlin-tunnelmanager/files/tunnelman.sh @@ -245,40 +245,40 @@ ENDPOINT_COUNT=0 while getopts a:c:g:i:m:n:o:t:T:D:U:A: option; do case $option in - a) OPT_UPLINK_IP=$OPTARG ;; - c) OPT_TUNNEL_COUNT=$OPTARG ;; - g) OPT_UPLINK_GW=$OPTARG ;; - i) OPT_UPLINK_INTERFACE=$OPTARG ;; - m) OPT_MTU=$OPTARG ;; - n) OPT_NAMESPACE_NAME=$OPTARG ;; - o) OPT_INTERVAL=$OPTARG ;; - t) OPT_TUNNEL_TIMEOUT=$OPTARG ;; - D) OPT_DOWN_SCRIPT=$OPTARG ;; - U) OPT_UP_SCRIPT=$OPTARG ;; - A) OPT_UP_SCRIPT_ARGS=$OPTARG ;; - T) - if [ $ENDPOINT_COUNT = 0 ]; then - OPT_TUNNEL_ENDPOINTS=$OPTARG - ENDPOINT_COUNT=$((ENDPOINT_COUNT + 1)) - else - OPT_TUNNEL_ENDPOINTS="$OPT_TUNNEL_ENDPOINTS $OPTARG" - ENDPOINT_COUNT=$((ENDPOINT_COUNT + 1)) - fi - ;; - *) - print_help - exit 2 - ;; + a) OPT_UPLINK_IP=$OPTARG ;; + c) OPT_TUNNEL_COUNT=$OPTARG ;; + g) OPT_UPLINK_GW=$OPTARG ;; + i) OPT_UPLINK_INTERFACE=$OPTARG ;; + m) OPT_MTU=$OPTARG ;; + n) OPT_NAMESPACE_NAME=$OPTARG ;; + o) OPT_INTERVAL=$OPTARG ;; + t) OPT_TUNNEL_TIMEOUT=$OPTARG ;; + D) OPT_DOWN_SCRIPT=$OPTARG ;; + U) OPT_UP_SCRIPT=$OPTARG ;; + A) OPT_UP_SCRIPT_ARGS=$OPTARG ;; + T) + if [ $ENDPOINT_COUNT = 0 ]; then + OPT_TUNNEL_ENDPOINTS=$OPTARG + ENDPOINT_COUNT=$((ENDPOINT_COUNT + 1)) + else + OPT_TUNNEL_ENDPOINTS="$OPT_TUNNEL_ENDPOINTS $OPTARG" + ENDPOINT_COUNT=$((ENDPOINT_COUNT + 1)) + fi + ;; + *) + print_help + exit 2 + ;; esac done # check if we got all information necessary -if [ -z "$OPT_UPLINK_IP" ] || [ -z "$OPT_TUNNEL_COUNT" ] || - [ -z "$OPT_UPLINK_GW" ] || [ -z "$OPT_UPLINK_INTERFACE" ] || - [ -z "$OPT_NAMESPACE_NAME" ] || [ -z "$OPT_INTERVAL" ] || - [ -z "$OPT_UP_SCRIPT" ] || [ -z "$OPT_TUNNEL_ENDPOINTS" ] || - [ -z "$OPT_DOWN_SCRIPT" ] || [ -z "$OPT_MTU" ] || - [ -z "$OPT_TUNNEL_TIMEOUT" ]; then +if [ -z "$OPT_UPLINK_IP" ] || [ -z "$OPT_TUNNEL_COUNT" ] \ + || [ -z "$OPT_UPLINK_GW" ] || [ -z "$OPT_UPLINK_INTERFACE" ] \ + || [ -z "$OPT_NAMESPACE_NAME" ] || [ -z "$OPT_INTERVAL" ] \ + || [ -z "$OPT_UP_SCRIPT" ] || [ -z "$OPT_TUNNEL_ENDPOINTS" ] \ + || [ -z "$OPT_DOWN_SCRIPT" ] || [ -z "$OPT_MTU" ] \ + || [ -z "$OPT_TUNNEL_TIMEOUT" ]; then printf "Not enough options. Please give all necessary options!\n\n" print_help exit 2 diff --git a/packages/falter-berlin-uplink-notunnel/uci-defaults/freifunk-berlin-z95_notunnel b/packages/falter-berlin-uplink-notunnel/uci-defaults/freifunk-berlin-z95_notunnel index 414841cc..ae5245fd 100644 --- a/packages/falter-berlin-uplink-notunnel/uci-defaults/freifunk-berlin-z95_notunnel +++ b/packages/falter-berlin-uplink-notunnel/uci-defaults/freifunk-berlin-z95_notunnel @@ -12,27 +12,27 @@ uci commit firewall current_preset=$(uci get ffberlin-uplink.preset.current) if [ ${current_preset} != ${THIS_UPLINKNAME} ]; then - # do not track preset when it was 'undefined', aka never configured - if [ ${current_preset} != "undefined" ]; then - logger -t "ffuplink" "uplink-preset has been changed." - uci set ffberlin-uplink.preset.previous=${current_preset} - create_ffuplink - fi - uci set ffberlin-uplink.preset.current=${THIS_UPLINKNAME} + # do not track preset when it was 'undefined', aka never configured + if [ ${current_preset} != "undefined" ]; then + logger -t "ffuplink" "uplink-preset has been changed." + uci set ffberlin-uplink.preset.previous=${current_preset} + create_ffuplink + fi + uci set ffberlin-uplink.preset.current=${THIS_UPLINKNAME} fi # set set auth-type required for this uplink-type, e.g. for freifunk-wizard uci set ffberlin-uplink.uplink.auth=none # disable tunneldigger for ffuplink, if tunneldigger was the previous setup if [ ${current_preset} == "tunnelberlin_tunneldigger" ]; then - uci set tunneldigger.ffuplink.enabled=0 - uci commit tunneldigger + uci set tunneldigger.ffuplink.enabled=0 + uci commit tunneldigger fi macaddr=$(uci -q get ffberlin-uplink.uplink.macaddr) if [ -z "$macaddr" ]; then - macaddr=$(generate_random_mac_hex "fe") - uci set ffberlin-uplink.uplink.macaddr=$macaddr + macaddr=$(generate_random_mac_hex "fe") + uci set ffberlin-uplink.uplink.macaddr=$macaddr fi uci commit ffberlin-uplink @@ -49,22 +49,22 @@ uci commit network.ffuplink_dev # add ffuplink_dev to the br-wan bridge if not there handle_wan_device() { - local config=$1 - local name="" - local _ports="" - local wandev + local config=$1 + local name="" + local _ports="" + local wandev - wandev="$(uci -q get network.wan.device)" - if [ -z $wandev ]; then - return - fi + wandev="$(uci -q get network.wan.device)" + if [ -z $wandev ]; then + return + fi - config_get name $config name - if [ "X${name}X" == "Xbr-wanX" ]; then - config_get _ports $config _ports - list_contains _ports ffuplink_wan || uci add_list network.${config}.ports="ffuplink_wan" - uci commit network.${config} - fi + config_get name $config name + if [ "X${name}X" == "Xbr-wanX" ]; then + config_get _ports $config _ports + list_contains _ports ffuplink_wan || uci add_list network.${config}.ports="ffuplink_wan" + uci commit network.${config} + fi } reset_cb @@ -72,6 +72,5 @@ config_load network config_foreach handle_wan_device device uci set network.ffuplink.proto=dhcp -uci set network.ffuplink.hostname="freifunk-$(echo $macaddr|tr -d :)-uplink" +uci set network.ffuplink.hostname="freifunk-$(echo $macaddr | tr -d :)-uplink" uci commit network.ffuplink - diff --git a/packages/falter-berlin-uplink-tunnelberlin/uci-defaults/freifunk-berlin-z95_tunnelberlin-tunneldigger b/packages/falter-berlin-uplink-tunnelberlin/uci-defaults/freifunk-berlin-z95_tunnelberlin-tunneldigger index d851d8be..f3964d5a 100644 --- a/packages/falter-berlin-uplink-tunnelberlin/uci-defaults/freifunk-berlin-z95_tunnelberlin-tunneldigger +++ b/packages/falter-berlin-uplink-tunnelberlin/uci-defaults/freifunk-berlin-z95_tunnelberlin-tunneldigger @@ -12,23 +12,23 @@ uci commit firewall current_preset=$(uci get ffberlin-uplink.preset.current) if [ ${current_preset} != ${THIS_UPLINKNAME} ]; then - if [ ${current_preset} != "undefined" ]; then - # when the uplink-preset has changed, recreate remember the preset we are coming from - # and prepare for reinit of the relevant settings via freifunk-berlin-ffuplink-defaults - # uci-defaults - logger -t "ffuplink" "uplink-preset has been changed." - uci set ffberlin-uplink.preset.previous=${current_preset} - create_ffuplink - fi - uci set ffberlin-uplink.preset.current=${THIS_UPLINKNAME} + if [ ${current_preset} != "undefined" ]; then + # when the uplink-preset has changed, recreate remember the preset we are coming from + # and prepare for reinit of the relevant settings via freifunk-berlin-ffuplink-defaults + # uci-defaults + logger -t "ffuplink" "uplink-preset has been changed." + uci set ffberlin-uplink.preset.previous=${current_preset} + create_ffuplink + fi + uci set ffberlin-uplink.preset.current=${THIS_UPLINKNAME} fi # set set auth-type required for this uplink-type, e.g. for freifunk-wizard uci set ffberlin-uplink.uplink.auth=none macaddr=$(uci -q get ffberlin-uplink.uplink.macaddr) if [ -z "$macaddr" ]; then - macaddr=$(generate_random_mac_hex "fe") - uci set ffberlin-uplink.uplink.macaddr=$macaddr + macaddr=$(generate_random_mac_hex "fe") + uci set ffberlin-uplink.uplink.macaddr=$macaddr fi uci commit ffberlin-uplink @@ -47,10 +47,10 @@ uci commit network.ffuplink # tunneldigger setup UUID=$(uci -q get tunneldigger.ffuplink.uuid) if [ $? -eq 1 ]; then - UUID=$macaddr - for _byte in 7 8 9 10; do - UUID=$UUID`dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 ":%02x"'` - done + UUID=$macaddr + for _byte in 7 8 9 10; do + UUID=$UUID$(dd if=/dev/urandom bs=1 count=1 2>/dev/null | hexdump -e '1/1 ":%02x"') + done fi uci delete tunneldigger.ffuplink @@ -64,4 +64,3 @@ uci set tunneldigger.ffuplink.broker_selection=usage uci set tunneldigger.ffuplink.bind_interface=wan uci set tunneldigger.ffuplink.enabled=1 uci commit tunneldigger - diff --git a/packages/falter-common/files/etc/profile.d/10_dynbanner.sh b/packages/falter-common/files/etc/profile.d/10_dynbanner.sh index 8328b128..bc9466c7 100755 --- a/packages/falter-common/files/etc/profile.d/10_dynbanner.sh +++ b/packages/falter-common/files/etc/profile.d/10_dynbanner.sh @@ -9,13 +9,13 @@ HOSTNAME=$(uci -q get system.@system[0].hostname)".olsr" IPADDR=$(uci -q get network.dhcp.ipaddr) -UPTIME=$(uptime | cut -d ',' -f 0 | cut -d ' ' -f 4-) > /dev/null 2>&1 -FREEFL=$(df -h | grep " /overlay" | sed -E -e s/[[:space:]]+/\;/g | cut -d';' -f4 ) > /dev/null 2>&1 -SYS_LOAD=$(cut -d' ' -f 1-3 < /proc/loadavg ) > /dev/null 2>&1 -CLIENTS=$(wc -l /tmp/dhcp.leases | cut -d' ' -f1) > /dev/null 2>&1 +UPTIME=$(uptime | cut -d ',' -f 0 | cut -d ' ' -f 4-) >/dev/null 2>&1 +FREEFL=$(df -h | grep " /overlay" | sed -E -e s/[[:space:]]+/\;/g | cut -d';' -f4) >/dev/null 2>&1 +SYS_LOAD=$(cut -d' ' -f 1-3 /dev/null 2>&1 +CLIENTS=$(wc -l /tmp/dhcp.leases | cut -d' ' -f1) >/dev/null 2>&1 printf \ -" Host.............................: %s + " Host.............................: %s IP-Address.......................: %s Uptime...........................: %s Free flash.......................: %s diff --git a/packages/falter-common/files/etc/rc.local.d/olsr-dnsmasq b/packages/falter-common/files/etc/rc.local.d/olsr-dnsmasq index bdb2cf8e..835b4432 100755 --- a/packages/falter-common/files/etc/rc.local.d/olsr-dnsmasq +++ b/packages/falter-common/files/etc/rc.local.d/olsr-dnsmasq @@ -3,7 +3,7 @@ test -f /etc/crontabs/root || touch /etc/crontabs/root grep -q 'killall -HUP dnsmasq' /etc/crontabs/root || { - echo "*/5 * * * * killall -HUP dnsmasq" >> /etc/crontabs/root + echo "*/5 * * * * killall -HUP dnsmasq" >>/etc/crontabs/root } /etc/init.d/cron restart & diff --git a/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-ffwizard3-json b/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-ffwizard3-json index c1893857..d76156e9 100644 --- a/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-ffwizard3-json +++ b/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-ffwizard3-json @@ -15,6 +15,6 @@ fi # create a ffwizard3-file, if there is none already if [ ! -f /etc/ffwizard3.json ]; then - uci2ffwizard > /etc/ffwizard3.json + uci2ffwizard >/etc/ffwizard3.json exit 0 fi diff --git a/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-freifunk-defaults b/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-freifunk-defaults index 8cb96026..9e08922d 100644 --- a/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-freifunk-defaults +++ b/packages/falter-common/files/etc/uci-defaults/freifunk-berlin-freifunk-defaults @@ -4,7 +4,7 @@ # write the freifunk-file on newly installed nodes if [ ! -f /etc/config/freifunk ]; then - cat < /etc/config/freifunk + cat </etc/config/freifunk package 'freifunk' config 'public' 'contact' diff --git a/packages/falter-common/files/lib/functions/guard.sh b/packages/falter-common/files/lib/functions/guard.sh index c97119bd..c29fd318 100644 --- a/packages/falter-common/files/lib/functions/guard.sh +++ b/packages/falter-common/files/lib/functions/guard.sh @@ -7,28 +7,28 @@ NAME="default" # check if defaults have already been set guard() { - OPTION=$1 + OPTION=$1 - [ ! -f $CFG_FILE ] && touch $CFG_FILE && uci set $CFG.$NAME=$SECTION - [ "$(uci -q get "$CFG.$NAME.$OPTION")" = "1" ] && exit 0 - uci set "$CFG.$NAME.$OPTION=1" - uci commit $CFG + [ ! -f $CFG_FILE ] && touch $CFG_FILE && uci set $CFG.$NAME=$SECTION + [ "$(uci -q get "$CFG.$NAME.$OPTION")" = "1" ] && exit 0 + uci set "$CFG.$NAME.$OPTION=1" + uci commit $CFG } guard_rename() { - SRC=$1 - DEST=$2 + SRC=$1 + DEST=$2 - # get current setting or exit when not defined - cur_set=$(uci -q get "$CFG.$NAME.$SRC") || return 0 - uci delete "$CFG.$NAME.$SRC" - uci set "$CFG.$NAME.$DEST=$cur_set" - uci commit $CFG + # get current setting or exit when not defined + cur_set=$(uci -q get "$CFG.$NAME.$SRC") || return 0 + uci delete "$CFG.$NAME.$SRC" + uci set "$CFG.$NAME.$DEST=$cur_set" + uci commit $CFG } guard_delete() { - OPTION=$1 + OPTION=$1 - uci -q delete "$CFG.$NAME.$OPTION" || return 0 - uci commit $CFG + uci -q delete "$CFG.$NAME.$OPTION" || return 0 + uci commit $CFG } diff --git a/packages/falter-common/files/sbin/ffwizard2uci b/packages/falter-common/files/sbin/ffwizard2uci index 75059084..4b2f4f26 100755 --- a/packages/falter-common/files/sbin/ffwizard2uci +++ b/packages/falter-common/files/sbin/ffwizard2uci @@ -20,8 +20,8 @@ FFWIZARD3_FILE="$1" if [ ! -f "$FFWIZARD3_FILE" ]; then - echo "ERROR: There is no file $FFWIZARD3_FILE" 1>&2; - echo "Closing..." 1>&2; + echo "ERROR: There is no file $FFWIZARD3_FILE" 1>&2 + echo "Closing..." 1>&2 exit 1 fi @@ -34,37 +34,37 @@ json_get_var json_created created json_get_var json_version version json_select contact - idx=1 - # iterate over objects inside contact-list - # we must write the vars immediately, otherwise they get lost - while json_is_a ${idx} object; do - json_select $idx - json_get_var nick nickname - json_get_var name realname - json_get_var mail email - json_get_var phone phone - json_get_var homepage homepage - json_get_var url url +idx=1 +# iterate over objects inside contact-list +# we must write the vars immediately, otherwise they get lost +while json_is_a ${idx} object; do + json_select $idx + json_get_var nick nickname + json_get_var name realname + json_get_var mail email + json_get_var phone phone + json_get_var homepage homepage + json_get_var url url - # if there is no contact-section, create one - has_contact=$(uci_get freifunk contact) - if [ -z "$has_contact" ]; then - uci_add freifunk public contact - fi + # if there is no contact-section, create one + has_contact=$(uci_get freifunk contact) + if [ -z "$has_contact" ]; then + uci_add freifunk public contact + fi - if [ -n "$nick" ]; then uci_set freifunk contact nickname "$nick"; fi - if [ -n "$name" ]; then uci_set freifunk contact name "$name"; fi - if [ -n "$mail" ]; then uci_set freifunk contact mail "$mail"; fi - if [ -n "$phone" ]; then uci_set freifunk contact phone "$phone"; fi - if [ -n "$homepage" ]; then uci_set freifunk contact homepage "$homepage"; fi - if [ -n "$url" ]; then uci_set freifunk contact mail "$url"; fi - json_select .. - idx=$(( idx + 1 )) - done - uci_commit freifunk + if [ -n "$nick" ]; then uci_set freifunk contact nickname "$nick"; fi + if [ -n "$name" ]; then uci_set freifunk contact name "$name"; fi + if [ -n "$mail" ]; then uci_set freifunk contact mail "$mail"; fi + if [ -n "$phone" ]; then uci_set freifunk contact phone "$phone"; fi + if [ -n "$homepage" ]; then uci_set freifunk contact homepage "$homepage"; fi + if [ -n "$url" ]; then uci_set freifunk contact mail "$url"; fi + json_select .. + idx=$((idx + 1)) +done +uci_commit freifunk # json_select node - # json_get_var name hostname - # json_get_var community community +# json_get_var name hostname +# json_get_var community community # ToDo: add the rest of the fields here. diff --git a/packages/falter-common/files/sbin/uci2ffwizard b/packages/falter-common/files/sbin/uci2ffwizard index efa35c74..9634774d 100755 --- a/packages/falter-common/files/sbin/uci2ffwizard +++ b/packages/falter-common/files/sbin/uci2ffwizard @@ -48,9 +48,9 @@ fi uci_load ffwizard share="$(uci_get ffwizard settings sharenet)" usersBandwidthDown=$(uci_get ffwizard settings usersBandwidthDown) -download="$(( usersBandwidthDown * 1000 ))" +download="$((usersBandwidthDown * 1000))" usersBandwidthUp=$(uci_get ffwizard settings usersBandwidthUp) -upload="$(( usersBandwidthUp * 1000 ))" +upload="$((usersBandwidthUp * 1000))" monitoring="$(uci_get ffwizard settings enableStats)" mesh1="$(uci_get ffwizard settings meship_radio0)" mesh2="$(uci_get ffwizard settings meship_radio1)" @@ -59,8 +59,7 @@ dhcp="$(uci_get ffwizard settings dhcpmesh)" # autoupdate-stuff uci_load autoupdate # swap value, as we have different properties here. -autoupdate_enabled="$(( ! $(uci_get autoupdate cfg disabled) ))" - +autoupdate_enabled="$((!$(uci_get autoupdate cfg disabled)))" # tunnel-stuff uci_load ffberlin-uplink @@ -77,7 +76,6 @@ has_bbbdigger="$(uci_get tunneldigger bbbdigger interface)" json_load "$(ubus call system board)" json_get_var hostname hostname - ############################# # # # construct json-string # @@ -155,7 +153,7 @@ json_init { while IFS= read -r line; do json_add_string "" "$line" - done < /etc/dropbear/authorized_keys + done /dev/null +echo "$WANDEV" | grep ^br- >/dev/null BRIDGECHECK=$? # setup wan as a bridge if [ "X${WANDEV}X" = "XX" ]; then - # This device does not have a wan port. Create a wan device without - # a physical port. This makes it easier to change a single - # port device from the client network to wan. This is also needed - # in the case where the user decides to use the "notunnel" variant - NEWDEV=$(uci add network device) - uci set "network.$NEWDEV.type=bridge" - uci set "network.$NEWDEV.name=br-wan" - - # create a wan interface, even if it can't do anything - uci set network.wan=interface - uci set network.wan.device="br-wan" - uci set network.wan.proto="dhcp" - - # create a wan6 interface, even if it can't do anything - uci set network.wan6=interface - uci set network.wan6.device="br-wan" - uci set network.wan6.proto="dhcpv6" + # This device does not have a wan port. Create a wan device without + # a physical port. This makes it easier to change a single + # port device from the client network to wan. This is also needed + # in the case where the user decides to use the "notunnel" variant + NEWDEV=$(uci add network device) + uci set "network.$NEWDEV.type=bridge" + uci set "network.$NEWDEV.name=br-wan" + + # create a wan interface, even if it can't do anything + uci set network.wan=interface + uci set network.wan.device="br-wan" + uci set network.wan.proto="dhcp" + + # create a wan6 interface, even if it can't do anything + uci set network.wan6=interface + uci set network.wan6.device="br-wan" + uci set network.wan6.proto="dhcpv6" elif [ $BRIDGECHECK = "0" ]; then - # The wan device is a bridge (ex DSA with multiple physical ports) - # everything should be set up fine in this case - : # do nothing + # The wan device is a bridge (ex DSA with multiple physical ports) + # everything should be set up fine in this case + : # do nothing else - # The wan device is not a bridge. Change it to a bridge - NEWDEV=$(uci add network device) - uci set "network.$NEWDEV.type=bridge" - uci set "network.$NEWDEV.name=br-wan" - uci add_list "network.$NEWDEV.ports=$WANDEV" - - uci set network.wan.device="br-wan" - uci set network.wan6.device="br-wan" + # The wan device is not a bridge. Change it to a bridge + NEWDEV=$(uci add network device) + uci set "network.$NEWDEV.type=bridge" + uci set "network.$NEWDEV.name=br-wan" + uci add_list "network.$NEWDEV.ports=$WANDEV" + + uci set network.wan.device="br-wan" + uci set network.wan6.device="br-wan" fi # do not use dns servers provided by dhcp - we maintain a static list of diff --git a/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-olsrd-defaults b/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-olsrd-defaults index 74b8d1ae..0909ba9a 100644 --- a/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-olsrd-defaults +++ b/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-olsrd-defaults @@ -37,9 +37,9 @@ uci set olsrd.$PLUGIN.ignore=0 # add dyngw plain plugin - it is ipv4 only PLUGIN="$(uci add olsrd LoadPlugin)" uci set olsrd.$PLUGIN.library=olsrd_dyn_gw -uci add_list olsrd.$PLUGIN.Ping=46.182.19.48 # dns.digitalcourage.de -uci add_list olsrd.$PLUGIN.Ping=80.67.169.40 # www.fdn.fr/actions/dns -uci add_list olsrd.$PLUGIN.Ping=194.150.168.168 # dns.as250.net +uci add_list olsrd.$PLUGIN.Ping=46.182.19.48 # dns.digitalcourage.de +uci add_list olsrd.$PLUGIN.Ping=80.67.169.40 # www.fdn.fr/actions/dns +uci add_list olsrd.$PLUGIN.Ping=194.150.168.168 # dns.as250.net uci set olsrd.$PLUGIN.ignore=0 # set olsrd defaults @@ -82,6 +82,6 @@ uci commit olsrd # add routing tables tables="/etc/iproute2/rt_tables" test -d /etc/iproute2/ || mkdir -p /etc/iproute2/ -grep -q "111 olsr" $tables || echo "111 olsr" >> $tables -grep -q "112 olsr-default" $tables || echo "112 olsr-default" >> $tables -grep -q "113 olsr-tunnel" $tables || echo "113 olsr-tunnel" >> $tables +grep -q "111 olsr" $tables || echo "111 olsr" >>$tables +grep -q "112 olsr-default" $tables || echo "112 olsr-default" >>$tables +grep -q "113 olsr-tunnel" $tables || echo "113 olsr-tunnel" >>$tables diff --git a/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-statistics-defaults b/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-statistics-defaults index ae8758ff..d00f2afa 100644 --- a/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-statistics-defaults +++ b/packages/falter-defaults/files/etc/uci-defaults/freifunk-berlin-statistics-defaults @@ -11,10 +11,10 @@ uci import luci_statistics </dev/null 2>&1 - if [ "$?" = 0 ]; then - logger -s -t policyrouting "Add route: $cmd (IPv6)" - fi + if [ -n "$net6" ]; then + cmd="ip -6 route add $net6 dev ${DEVICE} table localnets" + $cmd >/dev/null 2>&1 + if [ "$?" = 0 ]; then + logger -s -t policyrouting "Add route: $cmd (IPv6)" + fi - fi + fi - networks="" - for z in $zones; do - network_zone="$(uci -q get firewall.zone_${z}.network)" - if [ -z "$network_zone" ]; then - network_zone="$z" - fi - networks="$networks $network_zone" - done - for n in $networks; do - if [ "$INTERFACE" = "$n" ]; then - for p in $proto; do - logger -s -t policyrouting "Use mesh gateway for interface ${DEVICE} (IPv$p)" + networks="" + for z in $zones; do + network_zone="$(uci -q get firewall.zone_${z}.network)" + if [ -z "$network_zone" ]; then + network_zone="$z" + fi + networks="$networks $network_zone" + done + for n in $networks; do + if [ "$INTERFACE" = "$n" ]; then + for p in $proto; do + logger -s -t policyrouting "Use mesh gateway for interface ${DEVICE} (IPv$p)" - # add olsr-tunnel rule (SmartGateway tunnel) if not present - if [ ! "$(ip -$p rule show | egrep "from all iif ${DEVICE} (\[detached\] )?lookup olsr-tunnel")" ]; then - ip -$p rule add dev "${DEVICE}" lookup olsr-tunnel prio 19999 - fi + # add olsr-tunnel rule (SmartGateway tunnel) if not present + if [ ! "$(ip -$p rule show | egrep "from all iif ${DEVICE} (\[detached\] )?lookup olsr-tunnel")" ]; then + ip -$p rule add dev "${DEVICE}" lookup olsr-tunnel prio 19999 + fi - # add olsr-default rule (Default route from mesh) if not present - if [ ! "$(ip -$p rule show | egrep "from all iif ${DEVICE} (\[detached\] )?lookup olsr-default")" ]; then - ip -$p rule add dev "${DEVICE}" lookup olsr-default prio 20000 - fi + # add olsr-default rule (Default route from mesh) if not present + if [ ! "$(ip -$p rule show | egrep "from all iif ${DEVICE} (\[detached\] )?lookup olsr-default")" ]; then + ip -$p rule add dev "${DEVICE}" lookup olsr-default prio 20000 + fi - # add unreachable rules (prevents using router's default route (without VPN)) - if [ "$strict" != 0 ] && [ ! "$(ip -$p rule show | egrep "from all iif ${DEVICE} (\[detached\] )?unreachable")" ]; then - ip -$p rule add dev "${DEVICE}" unreachable prio 20001 - fi + # add unreachable rules (prevents using router's default route (without VPN)) + if [ "$strict" != 0 ] && [ ! "$(ip -$p rule show | egrep "from all iif ${DEVICE} (\[detached\] )?unreachable")" ]; then + ip -$p rule add dev "${DEVICE}" unreachable prio 20001 + fi - # uci stuff - if [ -z "$(uci -P /var/state get freifunk-policyrouting.${INTERFACE})" ]; then - uci -P /var/state set freifunk-policyrouting.${INTERFACE}="state" - fi - uci -P /var/state set freifunk-policyrouting.${INTERFACE}.device="${DEVICE}" + # uci stuff + if [ -z "$(uci -P /var/state get freifunk-policyrouting.${INTERFACE})" ]; then + uci -P /var/state set freifunk-policyrouting.${INTERFACE}="state" + fi + uci -P /var/state set freifunk-policyrouting.${INTERFACE}.device="${DEVICE}" - done - fi - done - fi + done + fi + done + fi fi diff --git a/packages/falter-policyrouting/files/etc/hotplug.d/iface/60-ffuplink_policyrouting b/packages/falter-policyrouting/files/etc/hotplug.d/iface/60-ffuplink_policyrouting index ba685ccf..f46e9a3e 100755 --- a/packages/falter-policyrouting/files/etc/hotplug.d/iface/60-ffuplink_policyrouting +++ b/packages/falter-policyrouting/files/etc/hotplug.d/iface/60-ffuplink_policyrouting @@ -20,35 +20,35 @@ config_get zones pr zones [ "$pr_enable" = 1 ] || exit if [ "$ACTION" = ifup ]; then - logger -t ff-userlog "ffuplink interface is up" - logger -t ff-userlog "creating ffuplink ip-rules" - ifaces=$(uci -q get firewall.zone_freifunk.network) - network_get_subnet uplink_net ffuplink - if [ -z "$uplink_net" ]; then - logger -t ff-userlog "UCI did not return a valid IP-net for ffuplink; querying directly with ip-tool" - uplink_net=$(ip -4 -o addr show dev ffuplink|awk '{print $4}') - fi - if [ -z "$uplink_net" ]; then - logger -t ff-userlog "no valid IP-net found for ffuplink; TRAFFIC FOR UPLINK-NETWORK WILL NOT BE BLOCKED" - fi - eval "$(/bin/ipcalc.sh "$uplink_net")" - for iface in $ifaces; do - network_get_physdev netdev "$iface" - [ ! '0.0.0.0' = "$NETWORK" ] && ip rule add prio 19989 to "$NETWORK/$PREFIX" iif "$netdev" prohibit - ip rule add prio 19990 iif "$netdev" lookup ffuplink - done - logger -t ff-userlog "ffuplink-interface is setup" + logger -t ff-userlog "ffuplink interface is up" + logger -t ff-userlog "creating ffuplink ip-rules" + ifaces=$(uci -q get firewall.zone_freifunk.network) + network_get_subnet uplink_net ffuplink + if [ -z "$uplink_net" ]; then + logger -t ff-userlog "UCI did not return a valid IP-net for ffuplink; querying directly with ip-tool" + uplink_net=$(ip -4 -o addr show dev ffuplink | awk '{print $4}') + fi + if [ -z "$uplink_net" ]; then + logger -t ff-userlog "no valid IP-net found for ffuplink; TRAFFIC FOR UPLINK-NETWORK WILL NOT BE BLOCKED" + fi + eval "$(/bin/ipcalc.sh "$uplink_net")" + for iface in $ifaces; do + network_get_physdev netdev "$iface" + [ ! '0.0.0.0' = "$NETWORK" ] && ip rule add prio 19989 to "$NETWORK/$PREFIX" iif "$netdev" prohibit + ip rule add prio 19990 iif "$netdev" lookup ffuplink + done + logger -t ff-userlog "ffuplink-interface is setup" fi if [ "$ACTION" = ifdown ]; then - logger -t ff-userlog "ffuplink interface going down" - ip route flush table ffuplink - while true; do - ip rule show | grep -q "^19990:" || break - ip rule del prio 19990 - done - while true; do - ip rule show | grep -q "^19989:" || break - ip rule del prio 19989 - done + logger -t ff-userlog "ffuplink interface going down" + ip route flush table ffuplink + while true; do + ip rule show | grep -q "^19990:" || break + ip rule del prio 19990 + done + while true; do + ip rule show | grep -q "^19989:" || break + ip rule del prio 19989 + done fi diff --git a/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-notunnel b/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-notunnel index dc94251f..000dee78 100755 --- a/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-notunnel +++ b/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-notunnel @@ -14,4 +14,3 @@ config_get ffuplink preset current # Internet connectivity via WAN is up, start the ffuplink interface logger -t freifunk-pingcheck "WAN is down, stopping ffuplink" ifdown ffuplink - diff --git a/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-wan b/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-wan index 743c0c2b..d505559a 100755 --- a/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-wan +++ b/packages/falter-policyrouting/files/etc/pingcheck/offline.d/60-freifunk-wan @@ -7,4 +7,3 @@ logger -t freifunk-pingcheck "WAN is down, rerouting all local traffic over the mesh network" ip rule add prio 3000 iif lo lookup olsr-tunnel ip rule add prio 3001 iif lo lookup olsr-default - diff --git a/packages/falter-policyrouting/files/etc/pingcheck/online.d/60-freifunk-wan b/packages/falter-policyrouting/files/etc/pingcheck/online.d/60-freifunk-wan index e6bb2ad3..efade118 100755 --- a/packages/falter-policyrouting/files/etc/pingcheck/online.d/60-freifunk-wan +++ b/packages/falter-policyrouting/files/etc/pingcheck/online.d/60-freifunk-wan @@ -7,4 +7,3 @@ logger -t freifunk-pingcheck "WAN connectivity is up, routing all local traffic through WAN" ip rule del prio 3000 iif lo lookup olsr-tunnel ip rule del prio 3001 iif lo lookup olsr-default - diff --git a/packages/falter-policyrouting/files/etc/uci-defaults/freifunk-policyrouting b/packages/falter-policyrouting/files/etc/uci-defaults/freifunk-policyrouting index 8bbc6a60..03eef1a1 100644 --- a/packages/falter-policyrouting/files/etc/uci-defaults/freifunk-policyrouting +++ b/packages/falter-policyrouting/files/etc/uci-defaults/freifunk-policyrouting @@ -5,10 +5,8 @@ # guard will stop the script, if option was set already and will set it otherwise guard "freifunk_policyrouting" - uci batch <<-EOF add ucitrack freifunk-policyrouting add_list ucitrack.@freifunk-policyrouting[-1].exec="/etc/init.d/freifunk-policyrouting restart" commit ucitrack EOF -