[PATCH] fff-hoods: Use variables for hood file names

Adrian Schmutzler freifunk at adrianschmutzler.de
Do Okt 19 13:06:28 CEST 2017


Since names may change, this puts the relevant file names for
hood files into variables, so they can be changed at once
without the risk of forgetting some occurrences.

Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
---
 .../fff-hoods/files/lib/functions/fff/keyxchange   | 12 ++++++----
 .../fff/fff-hoods/files/usr/sbin/configurehood     | 27 +++++++++++-----------
 .../fff/fff-vpn-select/files/usr/sbin/vpn-select   |  5 ++--
 .../fff/fff-web/files/www/ssl/cgi-bin/home.html    |  4 +++-
 4 files changed, 28 insertions(+), 20 deletions(-)

diff --git a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
index d7c2c13..cdaa8eb 100644
--- a/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
+++ b/src/packages/fff/fff-hoods/files/lib/functions/fff/keyxchange
@@ -4,12 +4,16 @@
 
 . /usr/share/libubox/jshn.sh
 
+hoodfile="/tmp/keyxchangev2data"
+hoodfilecopy="/www/public/keyxchangev2data"
+hiddenapfile="/tmp/hiddenapflag"
+
 getJsonPath() {
 	jsonfile=""
-	if [ -s /www/public/keyxchangev2data ] ; then
-		jsonfile="/www/public/keyxchangev2data"
-	elif [ -s /tmp/keyxchangev2data ] ; then
-		jsonfile="/tmp/keyxchangev2data"
+	if [ -s "$hoodfilecopy" ] ; then
+		jsonfile="$hoodfilecopy"
+	elif [ -s "$hoodfile" ] ; then
+		jsonfile="$hoodfile"
 	fi
 	echo "$jsonfile"
 }
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index f7ddb6e..303c54d 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -1,10 +1,11 @@
 #!/bin/sh
 
 . /usr/share/libubox/jshn.sh
+. /lib/functions/fff/keyxchange
 . /lib/functions/fff/wireless
 . /lib/functions/fff/timeserver
 
-rm -f /tmp/keyxchangev2data
+rm -f "$hoodfile"
 
 # Gatewaycheck function
 isGatewayAvailable() {
@@ -33,7 +34,7 @@ chan5ghz="36"
 
 # Hidden AP check
 
-if [ -f /tmp/hiddenapflag ]; then
+if [ -f "$hiddenapfile" ]; then
 	if isGatewayAvailable ; then
 
 		for radio in $(uci show wireless | sed -n 's,.*\.\([a-z0-9]*\)=wifi-device,\1,p'); do
@@ -54,7 +55,7 @@ if [ -f /tmp/hiddenapflag ]; then
 
 		wifi
 	fi
-	rm /tmp/hiddenapflag
+	rm "$hiddenapfile"
 fi
 
 lat=$(uci -q get system. at system[0].latitude)
@@ -62,7 +63,7 @@ long=$(uci -q get system. at 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
+	wget -T15 -t5 "http://keyserver.freifunk-franken.de/v2/?lat=$lat&long=$long" -O "$hoodfile"
 	#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
@@ -70,7 +71,7 @@ else
 	if ! isGatewayAvailable ; then
 		#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 "$hoodfilecopy" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
 
 		if ! wifiDelAll; then
 			echo "Can't delete current wifi setup"
@@ -102,25 +103,25 @@ else
 		# wait a moment to start the interface
 		sleep 10;
 		# and here we can download the Hoodfile from the other node
-		wget -T15 -t5 "http://[fe80::1%w2sta]/keyxchangev2data" -O /tmp/keyxchangev2data
+		wget -T15 -t5 "http://[fe80::1%w2sta]/keyxchangev2data" -O "$hoodfile"
 	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
+		wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$hoodfile"
 	fi
 fi
 
-if [ -s /tmp/keyxchangev2data ]; then
+if [ -s "$hoodfile" ]; 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!
 
-	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/')"
+	catnew="$(cat "$hoodfile" | sed 's/"timestamp":[0-9]*/"timestamp":0/')"
+	catold="$(cat "$hoodfilecopy" 2>/dev/null | sed 's/"timestamp":[0-9]*/"timestamp":0/')"
 	sumnew=$(echo "$catnew" | sha256sum | cut -f1 -d " ")
 	sumold=$(echo "$catold" | sha256sum | cut -f1 -d " ")
 
-	json_load "$(cat /tmp/keyxchangev2data)"
+	json_load "$(cat "$hoodfile")"
 
 	if [ "$sumnew" != "$sumold" ]; then
 		echo "New file detect, we reconfigure the Node";
@@ -164,7 +165,7 @@ if [ -s /tmp/keyxchangev2data ]; then
 			fi
 
 			# here we set a bit for add hidden AP
-			touch /tmp/hiddenapflag
+			touch "$hiddenapfile"
 
 			# add 802.11s mesh if type == "802.11s"
 			if ( [ -n "$radio5" ] && [ "$mesh_type5" == "802.11s" ] ) || [ "$mesh_type2" == "802.11s" ]; then
@@ -192,7 +193,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 "$hoodfile" "$hoodfilecopy"
 
 	else
 		echo "We have no new file. We do nothing. We try it again in 5 minutes...";
diff --git a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
index 150efe2..85930a8 100755
--- a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
+++ b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
@@ -1,5 +1,6 @@
 #!/bin/sh
 
+. /lib/functions/fff/keyxchange
 . /usr/share/libubox/jshn.sh
 
 make_config() {
@@ -8,7 +9,7 @@ make_config() {
 rm /tmp/fastd_fff_peers/*
 count=0
 Index=1
-json_load "$(cat /tmp/keyxchangev2data)"
+json_load "$(cat "$hoodfile")"
 json_select vpn
 # get fastd peers
 while json_select "$Index" > /dev/null
@@ -53,7 +54,7 @@ json_select ".." # back to root
 # main
 
 # Only do something when file is here and greater 0 byte
-if [ -s /tmp/keyxchangev2data ]; then
+if [ -s "$hoodfile" ]; then
 	# set some vars
 	hostname=$(cat /proc/sys/kernel/hostname)
 	mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null)
diff --git a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
index d859ad4..395e490 100755
--- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
+++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
@@ -1,11 +1,13 @@
 #!/usr/bin/haserl
 
 <%
+. /lib/functions/fff/keyxchange
+
 # prepare
 if [ "$REQUEST_METHOD" == "POST" ] ; then
 	if [ "$POST_resethood" != "" ] ; then
 		# reset hood
-		rm /www/public/keyxchangev2data 2> /dev/null
+		rm "$hoodfilecopy" 2> /dev/null
 		MSG='<span class="green">Hood-Daten werden innerhalb von 5 Minuten neu prozessiert.</span>'
 	fi
 fi
-- 
2.7.4



Mehr Informationen über die Mailingliste franken-dev