From patchwork Sun Jul 8 17:58:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: sector file: This reintroduces the sector file From: Adrian Schmutzler X-Patchwork-Id: 879 Message-Id: <1531072691-4284-1-git-send-email-freifunk@adrianschmutzler.de> To: franken-dev@freifunk.net Date: Sun, 8 Jul 2018 19:58:11 +0200 Signed-off-by: Adrian Schmutzler --- Preparation for later use. --- .../fff/fff-hoods/files/usr/sbin/configurehood | 28 ++++++++++++++++++++++ .../files/lib/functions/fff/keyxchange | 2 ++ .../files/etc/uci-defaults/99-fff-sysupgrade | 1 + .../fff-web/files/etc/uci-defaults/93-fff-uhttpd | 1 + 4 files changed, 32 insertions(+) diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index 00e3641..48e03ad 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -7,6 +7,8 @@ . /lib/functions/fff/timeserver . /usr/lib/functions/fff/hoodfile +sectorfilelocal=/etc/sectorfile +sectorfiletmp=/tmp/sectorfile hoodfilelocal=/etc/hoodfile @@ -76,6 +78,9 @@ else if hasInternet ; then getKeyserverHoodfile "$hoodfiletmp" && cp "$hoodfiletmp" "$hoodfilewww" + rm -f "$sectorfiletmp" + [ -s "$sectorfilelocal" ] || rm -f "$sectorfilewww" # If internet present, no custom config should be distributed, except when local file is present + #SECTOR FILE: 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 @@ -85,6 +90,8 @@ else #first we delete all wifi settings rm -f "$hoodfileref" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place rm -f "$hoodfilewww" # delete this, so wrong hood file is not broadcasted anymore + rm -f "$sectorfilewww" # always delete: no broadcast for isolated device + rm -f "$sectorfiletmp" uci -q del "system.@system[0].hood" uci -q commit system @@ -93,9 +100,15 @@ else sleep 30 # Wait for the config AP, which may be created at the same time as this script has started getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile "$hoodfiletmp" + + #SECTOR FILE: Set up uplink data on first contact: + if [ -s /tmp/keyxchangev2data ]; then + wget -T15 -t5 "http://[fe80::1%w2sta]:2342/sectorfile" -O "$sectorfiletmp" || wget -T15 -t5 "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectorfiletmp" + fi else echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1" getGatewayHoodfile "$hoodfiletmp" && cp "$hoodfiletmp" "$hoodfilewww" + #SECTOR FILE: Do nothing fi fi fi @@ -106,6 +119,20 @@ if [ -s "$hoodfiletmp" ]; then # https://pw.freifunk-franken.de/patch/205/ # but without signature, every hood file we get is valid! + [ -s "$sectorfilelocal" ] && sectorfiletmp="$sectorfilelocal" # Use local file if present (configuration set by user) + if [ -s "$sectorfiletmp" ] ; then + json_load "$(cat "$sectorfiletmp")" + json_select hood + json_get_var mesh_id mesh_id + json_get_var mesh_bssid mesh_bssid + json_get_var mesh_essid mesh_essid + json_get_var essid essid + json_get_var chan2ghz channel2 + json_get_var mesh_type2 mesh_type2 + json_get_var chan5ghz channel5 + json_get_var mesh_type5 mesh_type5 + fi + sumnew=$(cat "$hoodfiletmp" 2>/dev/null | sha256sum | cut -f1 -d " ") sumold=$(cat "$hoodfileref" 2>/dev/null | sha256sum | cut -f1 -d " ") @@ -185,6 +212,7 @@ if [ -s "$hoodfiletmp" ]; then # copy the file to webroot so that other mesh routers can download it; # copy only after all other steps so IF can be reentered if something goes wrong cp "$hoodfiletmp" "$hoodfileref" + [ -s "$sectorfiletmp" ] && cp "$sectorfiletmp" "$sectorfilewww" # This is a workaround to enable alfred on devices which do not see a configap during initial setup /etc/init.d/alfred restart diff --git a/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchange b/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchange index e601e0d..c0e35ac 100644 --- a/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchange +++ b/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchange @@ -8,6 +8,8 @@ hoodfiletmp="/tmp/hoodfile" hoodfileref="/tmp/hoodfileref" hoodfilewww="/tmp/hoodfilewww" +sectorfilewww="/tmp/sectorfilewww" + getJsonPath() { jsonfile="" if [ -s "$hoodfilewww" ] ; then diff --git a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade index 7ff83f5..d9ebe15 100644 --- a/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade +++ b/src/packages/fff/fff-sysupgrade/files/etc/uci-defaults/99-fff-sysupgrade @@ -10,4 +10,5 @@ cat > /etc/sysupgrade.conf <<-__EOF__ /etc/network.config /etc/config/fff /etc/hoodfile +/etc/sectorfile __EOF__ diff --git a/src/packages/fff/fff-web/files/etc/uci-defaults/93-fff-uhttpd b/src/packages/fff/fff-web/files/etc/uci-defaults/93-fff-uhttpd index 248a78b..bb99900 100644 --- a/src/packages/fff/fff-web/files/etc/uci-defaults/93-fff-uhttpd +++ b/src/packages/fff/fff-web/files/etc/uci-defaults/93-fff-uhttpd @@ -3,6 +3,7 @@ . /lib/functions/fff/keyxchange ln -s "$hoodfilewww" /www/hood/keyxchangev2data +ln -s "$sectorfilewww" /www/hood/sectorfile uci batch <