From patchwork Thu Oct 26 06:50:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: fff-hoods: Introduce sector files for custom settings From: Adrian Schmutzler X-Patchwork-Id: 631 Message-Id: <1509000604-5199-1-git-send-email-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Thu, 26 Oct 2017 08:50:04 +0200 First draft, untested. While the hood file is only set by the keyexchange/hood, this introduces a local additional configuration in a second file. This file is retrieved from the first configap we got in w2sta mode, of which we save the fdff address to identify it later. Thus, a router always "knows" its specific uplink, as long as the gateway connection is stable; otherwise: reset. The implementation is similar to the hoodfiles with a tmp version and a copy in the /www/public. On the "section head", the initial configuration is located in /etc/sectorfile and distributed from there to other nodes. Syntax should be like the node file, except that it only contains the values to be overwritten. Happy commenting. Signed-off-by: Adrian Schmutzler --- .../fff/fff-hoods/files/usr/sbin/configurehood | 60 ++++++++++++++++++++-- .../fff/fff-web/files/www/public/cgi-bin/fdff.html | 9 ++++ 2 files changed, 65 insertions(+), 4 deletions(-) create mode 100755 src/packages/fff/fff-web/files/www/public/cgi-bin/fdff.html diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index ac8cd54..4e9c6e6 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -4,7 +4,12 @@ . /lib/functions/fff/wireless . /lib/functions/fff/timeserver +sectorlocal=/etc/sectorfile +sectortmp=/tmp/sectorfile +sectorcopy=/www/public/sectorfile + rm -f /tmp/keyxchangev2data +rm -f "$sectortmp" # Gatewaycheck function isGatewayAvailable() { @@ -60,6 +65,12 @@ long=$(uci -q get system.@system[0].longitude) # if we have Internet, we download the Hoodfile from the keyxchangev2 if hasInternet ; then wget -T15 -t5 "http://keyserver.freifunk-franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data + if uci -q get "system.@system[0].uplink" ; then + uci -q delete "system.@system[0].uplink" + uci -q commit system + rm -f "$sectorcopy" + fi + #UPLINK: No uplink download if internet present #if no Internet, we connect to the hidden AP and download the file from another Node in range else # connect to wireless hidden ap here and download the json File from the nearest router @@ -68,6 +79,11 @@ else #now we haven't a gateway in Range, we search for a hidden AP to get a keyxchangev2data file! #first we delete all wifi settings rm -f /www/public/keyxchangev2data # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place + rm -f "$sectorcopy" + if uci -q get "system.@system[0].uplink" ; then + uci -q delete "system.@system[0].uplink" + uci -q commit system + fi if ! wifiDelAll; then echo "Can't delete current wifi setup" @@ -100,9 +116,21 @@ else sleep 10; # and here we can download the Hoodfile from the other node wget -T15 -t5 "http://[fe80::1%w2sta]/keyxchangev2data" -O /tmp/keyxchangev2data + #UPLINK: Set up uplink data on first contact: + wget -T15 -t5 "http://[fe80::1%w2sta]/cgi-bin/fdff.html" -O /tmp/uplinkmac + wget -T15 -t5 "http://[fe80::1%w2sta]/sectorfile" -O "$sectortmp" + [ -s /tmp/uplinkmac ] && uplink="$(cat /tmp/uplinkmac)" + if [ -n "$uplink" ] ; then + uci -q set "system.@system[0].uplink=$uplink" + uci -q commit system + fi + rm -f /tmp/uplinkmac else echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1" wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O /tmp/keyxchangev2data + #UPLINK: Reuse uplink address + uplink="$(uci -q get "system.@system[0].uplink")" + [ -n "$uplink" ] && wget -T15 -t5 "http://[${uplink}]/sectorfile" -O "$sectortmp" fi fi @@ -111,15 +139,32 @@ if [ -s /tmp/keyxchangev2data ]; then # we get a json file in this format: # https://pw.freifunk-franken.de/patch/205/ # but without signature, every hood file we get is valid! + + [ -s "$sectorlocal" ] && sectortmp="$sectorlocal" # Use real local file if present (configuration set by user) + if [ -s "$sectortmp" ] ; then + json_load "$(cat "$sectortmp")" + json_select hood + json_get_var s_mesh_id mesh_id + json_get_var s_mesh_bssid mesh_bssid + json_get_var s_mesh_essid mesh_essid + json_get_var s_essid essid + json_get_var s_chan2ghz channel2 + json_get_var s_mesh_type2 mesh_type2 + json_get_var s_chan5ghz channel5 + json_get_var s_mesh_type5 mesh_type5 + fi catnew="$(cat /tmp/keyxchangev2data | sed 's/"timestamp":[0-9]*/"timestamp":0/')" catold="$(cat /www/public/keyxchangev2data 2>/dev/null | sed 's/"timestamp":[0-9]*/"timestamp":0/')" sumnew=$(echo "$catnew" | sha256sum | cut -f1 -d " ") sumold=$(echo "$catold" | sha256sum | cut -f1 -d " ") + sumsnew=$(cat "$sectortmp" | sha256sum | cut -f1 -d " ") + sumsold=$(cat "$sectorcopy" | sha256sum | cut -f1 -d " ") + json_load "$(cat /tmp/keyxchangev2data)" - if [ "$sumnew" != "$sumold" ]; then + if [ "$sumnew" != "$sumold" ] || [ "$sumsnew" != "$sumsold" ] ; then echo "New file detect, we reconfigure the Node"; json_select hood @@ -140,9 +185,15 @@ if [ -s /tmp/keyxchangev2data ]; then #json_get_var protocol protocol json_select ".." # back to root - - [ -n "$chan2ghz" ] || chan2ghz="1" - [ -n "$chan5ghz" ] || chan5ghz="36" + + [ -n s_mesh_id ] && mesh_id=s_mesh_id + [ -n s_mesh_bssid ] && mesh_bssid=s_mesh_bssid + [ -n s_mesh_essid ] && mesh_essid=s_mesh_essid + [ -n s_essid ] && essid=s_essid + [ -n s_chan2ghz ] && channel2=s_chan2ghz + [ -n s_mesh_type2 ] && mesh_type2=s_mesh_type2 + [ -n s_chan5ghz ] && channel5=s_chan5ghz + [ -n s_mesh_type5 ] && mesh_type5=s_mesh_type5 echo "Setting hood name: $hood" uci set "system.@system[0].hood=$hood" @@ -192,6 +243,7 @@ if [ -s /tmp/keyxchangev2data ]; then # copy the file to webroot so that other Meshrouter can download it; # copy only after all other steps so IF can be reentered if something goes wrong cp /tmp/keyxchangev2data /www/public/ + cp "$sectortmp" "$sectorcopy" else echo "We have no new file. We do nothing. We try it again in 5 minutes..."; diff --git a/src/packages/fff/fff-web/files/www/public/cgi-bin/fdff.html b/src/packages/fff/fff-web/files/www/public/cgi-bin/fdff.html new file mode 100755 index 0000000..f128276 --- /dev/null +++ b/src/packages/fff/fff-web/files/www/public/cgi-bin/fdff.html @@ -0,0 +1,9 @@ +#!/usr/bin/haserl + +<% +prefix="fdff::" +suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }' /sys/class/net/br-mesh/address) +addr="$(echo "$prefix$suffix")" +echo "$addr" + +%>