[PATCH v2] fff-hoods: Introduce sector files for custom settings

mail at adrianschmutzler.de mail at adrianschmutzler.de
Sa Okt 28 12:30:43 CEST 2017


Tested-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>

Getestet mit jeweils einem Uplink- und Meshrouter. Tut wie es soll.

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces at freifunk.net] On Behalf
> Of Adrian Schmutzler
> Sent: Donnerstag, 26. Oktober 2017 19:39
> To: franken-dev at freifunk.net
> Subject: [PATCH v2] fff-hoods: Introduce sector files for custom settings
> 
> Untested, but should be testable.
> 
> 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 <freifunk at adrianschmutzler.de>
> ---
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 67
> ++++++++++++++++++++--
>  .../fff/fff-web/files/www/public/cgi-bin/fdff.html | 10 ++++
>  2 files changed, 71 insertions(+), 6 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..84e7b25 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. 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
> +	if uci -q get "system. at system[0].uplink" ; then
> +		uci -q delete "system. at system[0].uplink"
> +		uci -q commit system
> +	fi
> +	[ -s "$sectorlocal" ] || rm -f "$sectorcopy" # If internet present,
no
> custom config should be distributed, except when local file is present
> +	#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" # always delete: no broadcast for
isolated
> device
> +		if uci -q get "system. at system[0].uplink" ; then
> +			uci -q delete "system. at system[0].uplink"
> +			uci -q commit system
> +		fi
> 
>  		if ! wifiDelAll; then
>  			echo "Can't delete current wifi setup"
> @@ -100,9 +116,24 @@ 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:
> +		if [ -s /tmp/keyxchangev2data ]; then
> +			if wget -T15 -t5 "http://[fe80::1%w2sta]/sectorfile"
-O
> "$sectortmp" &&
> +				wget -T15 -t5 "http://[fe80::1%w2sta]/cgi-
> bin/fdff.html" -O /tmp/uplinkmac ; then
> +				[ -s /tmp/uplinkmac ] && uplink="$(cat
> /tmp/uplinkmac)"
> +				if [ -n "$uplink" ] ; then
> +					uci -q set
> "system. at system[0].uplink=$uplink"
> +					uci -q commit system
> +				fi
> +				rm -f /tmp/uplinkmac
> +			fi
> +		fi
>  	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. at system[0].uplink")"
> +		[ -n "$uplink" ] && wget -T15 -t5
> "http://[${uplink}]/sectorfile" -O "$sectortmp"
>  	fi
>  fi
> 
> @@ -111,16 +142,33 @@ 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 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
> -		echo "New file detect, we reconfigure the Node";
> +	if [ "$sumnew" != "$sumold" ] || [ "$sumsnew" != "$sumsold" ] ;
> then
> +		echo "New file detected, we reconfigure the Node";
> 
>  		json_select hood
> 
> @@ -140,9 +188,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" ] && chan2ghz="$s_chan2ghz"
> +		[ -n "$s_mesh_type2" ] && mesh_type2="$s_mesh_type2"
> +		[ -n "$s_chan5ghz" ] && chan5ghz="$s_chan5ghz"
> +		[ -n "$s_mesh_type5" ] && mesh_type5="$s_mesh_type5"
> 
>  		echo "Setting hood name: $hood"
>  		uci set "system. at system[0].hood=$hood"
> @@ -189,9 +243,10 @@ if [ -s /tmp/keyxchangev2data ]; then
>  		newntp="${ntpip}" # requires routable address, no link-local
>  		[ "$newntp" = "$oldntp" ] || setTimeserver "${newntp}" #
> only rewrite if changed
> 
> -		# copy the file to webroot so that other Meshrouter can
> download it;
> +		# 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 /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..dc21198
> --- /dev/null
> +++ b/src/packages/fff/fff-web/files/www/public/cgi-bin/fdff.html
> @@ -0,0 +1,10 @@
> +#!/usr/bin/haserl
> +
> +<%
> +echo -en "Content-Type: text/plain\r\n\r\n"
> +
> +prefix="fdff::"
> +suffix=$(awk -F: '{ print $1$2":"$3$4":"$5$6 }'
> +/sys/class/net/br-mesh/address) addr="$(echo "$prefix$suffix")"
> +echo "$addr"
> +%>
> --
> 2.7.4
> 
> --
> franken-dev mailing list
> franken-dev at freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net



Mehr Informationen über die Mailingliste franken-dev