[v10,4/4] Add fff-hoods

Submitted by Adrian Schmutzler on Oct. 1, 2017, 1:48 p.m.

Details

Message ID 1506865735-2334-4-git-send-email-freifunk@adrianschmutzler.de
State Superseded
Headers show

Commit Message

Adrian Schmutzler Oct. 1, 2017, 1:48 p.m.
From: Christian Dresel <fff@chrisi01.de>

this packages connect to keyxchangev2
after review we must change the serveradress! This is only a example

Signed-off-by: Christian Dresel <fff@chrisi01.de>
Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>

Update in v2:
 - clean tabstops
 - move the json vpn out of the if because we need this after reboot

Update in v5:
	!!UNTESTED!!
 - change hidden AP ip to locallink
 - Open hidden AP after more checks
 - Load json File from Gateway if Gateway in Batman in Range

Update in v6:
	!!UNTESTED!!
 - fix hidden station v6
 - fix -n to -f if
 - Add function to check for a gateway and use this
 - remove /etc/community.cfg and variables
 - send fewer infos to keyxchangev2
 - add a check if /tmp/keyxchangev2 not downloadable and edit a bit  on the wgets
 - change the position from json_load and do this only 1 times

Update in v7:
	!!UNTESTED!!
 - delete keyxchangev2data at start of the script
 - do only things with keyxchangev2data if available
 - change keyxchangev2 url

Update in v8/v9:
 - rebase onto 20170918-beta

Update in v10:
 - Minor code fixes
 - Added fff-hoods to fff-base Makefile
 - Removed trailing whitespaces and harmonized tabs
 - Fixed some comments spelling
 - Added mac for hostname rewrite
 - Removed redundant check for /tmp/keyxchangev2data
---
 src/packages/fff/fff-hoods/Makefile                |  39 ++++
 .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
 .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
 .../fff/fff-hoods/files/usr/sbin/configurehood     | 206 +++++++++++++++++++++
 src/packages/fff/fff/Makefile                      |   3 +-
 5 files changed, 253 insertions(+), 1 deletion(-)
 create mode 100644 src/packages/fff/fff-hoods/Makefile
 create mode 100644 src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
 create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
 create mode 100755 src/packages/fff/fff-hoods/files/usr/sbin/configurehood

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
new file mode 100644
index 0000000..f85178d
--- /dev/null
+++ b/src/packages/fff/fff-hoods/Makefile
@@ -0,0 +1,39 @@ 
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=fff-hoods
+PKG_VERSION:=0.0.1
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/fff-hoods
+    SECTION:=base
+    CATEGORY:=Freifunk
+    TITLE:= Freifunk-Franken hoods
+    URL:=http://www.freifunk-franken.de
+    DEPENDS:=+fff-network
+endef
+
+define Package/fff-hoods/description
+    This package load and configures the current hood
+endef
+
+define Build/Prepare
+	echo "all: " > $(PKG_BUILD_DIR)/Makefile
+endef
+
+define Build/Configure
+	# nothing
+endef
+
+define Build/Compile
+	# nothing
+endef
+
+define Package/fff-hoods/install
+	$(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,fff-hoods))
diff --git a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
new file mode 100644
index 0000000..49f53e3
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
@@ -0,0 +1,5 @@ 
+#!/bin/sh 
+[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
+       sleep 3
+       /usr/sbin/configurehood
+}
diff --git a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
new file mode 100644
index 0000000..ca8d798
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
@@ -0,0 +1 @@ 
+*/5 * * * * /usr/sbin/configurehood
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
new file mode 100755
index 0000000..ad316f8
--- /dev/null
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -0,0 +1,206 @@ 
+#!/bin/sh
+
+. /usr/share/libubox/jshn.sh
+. /lib/functions/fff/wireless
+
+rm /tmp/keyxchangev2data
+
+# Gatewaycheck function
+isGatewayAvailable() {
+	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
+		return true;
+	else
+		return false;
+	fi
+}
+
+
+# Hidden AP check
+
+if [ -f /tmp/hiddenapflag ]; then
+	if [ isGatewayAvailable ]; then
+		if ! wifiAddAP "$radio" "config.franken.freifunk.net" "configap" "configap" "1"; then
+			echo "Can't add AP interface on $radio."
+			exit 1
+		else
+			# We must set a fixed ip address here
+			uci set network.configap=interface
+			uci set network.configap.proto='static'
+			uci set network.configap.ip6addr='fe80::1/64'
+			uci commit network
+		fi
+	else
+		rm /tmp/hiddenapflag
+	fi
+fi
+
+
+lat=$(uci get system.@system[0].latitude)
+long=$(uci get system.@system[0].longitude)
+hostname=$(cat /proc/sys/kernel/hostname)
+mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null)
+[ "$hostname" = "OpenWrt" ] && hostname=""
+[ "$hostname" = "" ] &&  hostname="$mac"
+
+test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken keyserver
+test_ipv4_host2="8.8.8.8"        # Google DNS
+test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
+
+# if we have Internet, we download the Hoodfile from the keyxchangev2
+if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
+	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
+	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
+	wget -T15 -t5 "http://keyserver.freifunk-franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
+	#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
+	# Only do that, when we have no gateway in range. If the Uplinkrouter changed the hood, we lost the GW and do this automatically again, I think! Nice idea?
+	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
+		if ! wifiDelAll; then
+			echo "Can't delete current wifi setup"
+			exit 1
+		fi
+		#now we look for phy and add this
+		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
+			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
+				echo "$phy is 2.4 GHz"
+				radio=$(wifiAddPhy "$phy" "$BATMAN_CHANNEL")
+				if [ -z "$radio" ]; then
+					echo "Can't create radio for $phy"
+					exit 1
+				fi
+			fi
+			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
+				echo "$phy is 5 GHz"
+				radio=$(wifiAddPhy "$phy" "$BATMAN_CHANNEL_5GHZ")
+				if [ -z "$radio" ]; then
+					echo "Can't create radio for $phy"
+					exit 1
+				fi
+			fi
+			#and here we add the station
+			if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta"; then
+				echo "Can't add Sta interface on $radio."
+				exit 1
+			fi
+			
+		done
+		
+		wifi
+		# 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
+	else
+		echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1"
+		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data" -O /tmp/keyxchangev2data
+	fi
+
+fi
+
+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!
+
+	json_load "$(cat /tmp/keyxchangev2data)"
+	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
+	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null | cut -f1 -d " ")
+	if [ "$sumnew" != "$sumold" ]; then
+		echo "New file detect, we reconfigure the Node";
+
+		# copy the file to webroot so that other Meshrouter can download it
+		cp /tmp/keyxchangev2data /www/public/
+
+		json_select hood
+
+		json_get_var hood name
+		json_get_var mesh_bssid mesh_bssid
+		json_get_var mesh_essid mesh_essid
+		json_get_var essid essid
+		# i think the next things we don't active this in the first version! we can do it later
+		#json_get_var channel2 channel2
+		#json_get_var mode2 mode2
+		#json_get_var type2 type2
+		#json_get_var channel5 channel5
+		#json_get_var mode5 mode5
+		#json_get_var type5 type5
+		#json_get_var protocol protocol
+
+		echo "Setting hood name: $hood"
+		uci set "system.@system[0].hood=$hood"
+
+		if ! wifiDelAll; then
+			echo "Can't delete current wifi setup"
+			exit 1
+		fi
+
+		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
+			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
+				echo "$phy is 2.4 GHz"
+				radio=$(wifiAddPhy "$phy" "1")
+				if [ -z "$radio" ]; then
+					echo "Can't create radio for $phy"
+					exit 1
+				fi
+			fi
+			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
+				echo "$phy is 5 GHz"
+				radio=$(wifiAddPhy "$phy" "13")
+				if [ -z "$radio" ]; then
+					echo "Can't create radio for $phy"
+					exit 1
+				fi
+			fi
+
+			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0"; then
+				echo "Can't add AP interface on $radio."
+				exit 1
+			fi
+
+			# here we set a bit for add hidden AP
+			touch /tmp/hiddenapflag
+
+			if ! wifiAddAdHocMesh "$radio" "$mesh_essid" "$mesh_bssid"; then
+				echo "Can't add AP interface on $radio."
+				exit 1
+			fi
+		done
+
+		echo "Loading wifi"
+		wifi
+
+	else
+		echo "We have no new file or we haven't got a file. We do nothing. We try it again in 5 minutes...";
+	fi
+
+	# and now we read the VPN Data and give this data to fff-vpn
+	json_load "$(cat /tmp/keyxchangev2data)"
+	
+	json_select vpn
+	Index="1"
+	rm /tmp/fastd_fff_output
+	touch /tmp/fastd_fff_output
+	while json_select $Index > /dev/null
+	do
+		json_get_var protocol protocol
+		if [ "$protocol" == "fastd" ]; then
+			json_get_var servername name
+			echo "####${servername}.conf" >> /tmp/fastd_fff_output
+			echo "#name \"${servername}\";" >> /tmp/fastd_fff_output
+			json_get_var key key
+			echo "key \"${key}\";" >> /tmp/fastd_fff_output
+			json_get_var address address
+			json_get_var port port
+			echo "remote ipv4 \"${address}\" port $port float;" >> /tmp/fastd_fff_output
+		fi
+		echo "" >> /tmp/fastd_fff_output
+		echo "###" >> /tmp/fastd_fff_output
+	done
+	#this we do every 5 minutes, because it can change the VPN Protocol
+	#and now we get to vpn-select Script and load VPNs
+	sh /usr/sbin/vpn-select
+fi
diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
index 166d423..305ab8d 100644
--- a/src/packages/fff/fff/Makefile
+++ b/src/packages/fff/fff/Makefile
@@ -29,7 +29,8 @@  define Package/fff-base
              +fff-wireless \
              +fff-timeserver \
              +fff-vpn-select \
-             +simple-tc
+             +simple-tc \
+             +fff-hoods
 endef
 
 define Package/fff-base/description

Comments

Adrian Schmutzler Oct. 1, 2017, 2:05 p.m.
Hallo,

eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen aufgefallen
sind.

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Adrian Schmutzler
> Sent: Sonntag, 1. Oktober 2017 15:49
> To: franken-dev@freifunk.net
> Cc: Jan Kraus <mayosemmel@gmail.com>
> Subject: [PATCH v10 4/4] Add fff-hoods
> 
> From: Christian Dresel <fff@chrisi01.de>
> 
> this packages connect to keyxchangev2
> after review we must change the serveradress! This is only a example
> 
> Signed-off-by: Christian Dresel <fff@chrisi01.de>
> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> 
> Update in v2:
>  - clean tabstops
>  - move the json vpn out of the if because we need this after reboot
> 
> Update in v5:
> 	!!UNTESTED!!
>  - change hidden AP ip to locallink
>  - Open hidden AP after more checks
>  - Load json File from Gateway if Gateway in Batman in Range
> 
> Update in v6:
> 	!!UNTESTED!!
>  - fix hidden station v6
>  - fix -n to -f if
>  - Add function to check for a gateway and use this
>  - remove /etc/community.cfg and variables
>  - send fewer infos to keyxchangev2
>  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit  on
the
> wgets
>  - change the position from json_load and do this only 1 times
> 
> Update in v7:
> 	!!UNTESTED!!
>  - delete keyxchangev2data at start of the script
>  - do only things with keyxchangev2data if available
>  - change keyxchangev2 url
> 
> Update in v8/v9:
>  - rebase onto 20170918-beta
> 
> Update in v10:
>  - Minor code fixes
>  - Added fff-hoods to fff-base Makefile
>  - Removed trailing whitespaces and harmonized tabs
>  - Fixed some comments spelling
>  - Added mac for hostname rewrite
>  - Removed redundant check for /tmp/keyxchangev2data
> ---
>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
> +++++++++++++++++++++
>  src/packages/fff/fff/Makefile                      |   3 +-
>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
> src/packages/fff/fff-hoods/Makefile
>  create mode 100644 src/packages/fff/fff-
> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>  create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
> hoods
>  create mode 100755 src/packages/fff/fff-
> hoods/files/usr/sbin/configurehood
> 
> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-
> hoods/Makefile
> new file mode 100644
> index 0000000..f85178d
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/Makefile
> @@ -0,0 +1,39 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=fff-hoods
> +PKG_VERSION:=0.0.1
> +PKG_RELEASE:=1
> +
> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/fff-hoods
> +    SECTION:=base
> +    CATEGORY:=Freifunk
> +    TITLE:= Freifunk-Franken hoods
> +    URL:=http://www.freifunk-franken.de
> +    DEPENDS:=+fff-network
> +endef
> +
> +define Package/fff-hoods/description
> +    This package load and configures the current hood endef
> +
> +define Build/Prepare
> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
> +
> +define Build/Configure
> +	# nothing
> +endef
> +
> +define Build/Compile
> +	# nothing
> +endef
> +
> +define Package/fff-hoods/install
> +	$(CP) ./files/* $(1)/
> +endef
> +
> +$(eval $(call BuildPackage,fff-hoods))
> diff --git
a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> new file mode 100644
> index 0000000..49f53e3
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> @@ -0,0 +1,5 @@
> +#!/bin/sh
> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
> +       sleep 3
> +       /usr/sbin/configurehood
> +}
> diff --git a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> new file mode 100644
> index 0000000..ca8d798
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> @@ -0,0 +1 @@
> +*/5 * * * * /usr/sbin/configurehood
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> new file mode 100755
> index 0000000..ad316f8
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -0,0 +1,206 @@
> +#!/bin/sh
> +
> +. /usr/share/libubox/jshn.sh
> +. /lib/functions/fff/wireless
> +
> +rm /tmp/keyxchangev2data
> +
> +# Gatewaycheck function
> +isGatewayAvailable() {
> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
> +		return true;
> +	else
> +		return false;
> +	fi
> +}
> +
> +
> +# Hidden AP check
> +
> +if [ -f /tmp/hiddenapflag ]; then
> +	if [ isGatewayAvailable ]; then
> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
> "configap" "configap" "1"; then
> +			echo "Can't add AP interface on $radio."
> +			exit 1
> +		else
> +			# We must set a fixed ip address here
> +			uci set network.configap=interface
> +			uci set network.configap.proto='static'
> +			uci set network.configap.ip6addr='fe80::1/64'
> +			uci commit network
> +		fi
> +	else
> +		rm /tmp/hiddenapflag
> +	fi
> +fi

Warum steht dieser ganze Block am Anfang und nicht am Schluss des Skripts?
Hat das einen Grund, dass der immer einen Zyklus warten soll?



> +
> +
> +lat=$(uci get system.@system[0].latitude) long=$(uci get
> +system.@system[0].longitude) hostname=$(cat
> /proc/sys/kernel/hostname)
> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'

Hier hab ich die Mac ergänzt.

> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = "OpenWrt" ]
> && hostname=""
> +[ "$hostname" = "" ] &&  hostname="$mac"

Wozu ist das gut? Sollte man das auf LEDE ändern?

> +
> +test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken
> keyserver
> +test_ipv4_host2="8.8.8.8"        # Google DNS
> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
> +
> +# if we have Internet, we download the Hoodfile from the keyxchangev2
> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
> +	wget -T15 -t5 "http://keyserver.freifunk-
> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
> +	#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
> +	# Only do that, when we have no gateway in range. If the
> Uplinkrouter changed the hood, we lost the GW and do this automatically
> again, I think! Nice idea?
> +	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
> +		if ! wifiDelAll; then
> +			echo "Can't delete current wifi setup"
> +			exit 1
> +		fi
> +		#now we look for phy and add this
> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> +				echo "$phy is 2.4 GHz"
> +				radio=$(wifiAddPhy "$phy"
> "$BATMAN_CHANNEL")
> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi
> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> +				echo "$phy is 5 GHz"
> +				radio=$(wifiAddPhy "$phy"
> "$BATMAN_CHANNEL_5GHZ")
> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi

Hier werden Variablen aus der community.cfg verwendet ($BATMAN...), unten
ist hardgecodet. Das hier auch hardcoden?


> +			#and here we add the station
> +			if ! wifiAddSta "$radio"
"config.franken.freifunk.net"
> "configSta"; then
> +				echo "Can't add Sta interface on $radio."
> +				exit 1
> +			fi
> +
> +		done
> +
> +		wifi
> +		# 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
> +	else
> +		echo "We have a Gateway in Range, we load the
> keyxchangev2data from fe80::1"
> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
> -O /tmp/keyxchangev2data
> +	fi
> +
> +fi
> +
> +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!
> +
> +	json_load "$(cat /tmp/keyxchangev2data)"
> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
> | cut -f1 -d " ")
> +	if [ "$sumnew" != "$sumold" ]; then

Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht irgendwie keinen
Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon geprüft haben?!


> +		echo "New file detect, we reconfigure the Node";
> +
> +		# copy the file to webroot so that other Meshrouter can
> download it
> +		cp /tmp/keyxchangev2data /www/public/
> +
> +		json_select hood
> +
> +		json_get_var hood name
> +		json_get_var mesh_bssid mesh_bssid
> +		json_get_var mesh_essid mesh_essid
> +		json_get_var essid essid
> +		# i think the next things we don't active this in the first
> version! we can do it later
> +		#json_get_var channel2 channel2
> +		#json_get_var mode2 mode2
> +		#json_get_var type2 type2
> +		#json_get_var channel5 channel5
> +		#json_get_var mode5 mode5
> +		#json_get_var type5 type5
> +		#json_get_var protocol protocol
> +
> +		echo "Setting hood name: $hood"
> +		uci set "system.@system[0].hood=$hood"
> +
> +		if ! wifiDelAll; then
> +			echo "Can't delete current wifi setup"
> +			exit 1
> +		fi
> +
> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> +				echo "$phy is 2.4 GHz"
> +				radio=$(wifiAddPhy "$phy" "1")

Hier ist jetzt hardgecodet ... "1"


> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi
> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> +				echo "$phy is 5 GHz"
> +				radio=$(wifiAddPhy "$phy" "13")
> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi
> +
> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
then
> +				echo "Can't add AP interface on $radio."
> +				exit 1
> +			fi
> +
> +			# here we set a bit for add hidden AP
> +			touch /tmp/hiddenapflag
> +
> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
> "$mesh_bssid"; then
> +				echo "Can't add AP interface on $radio."
> +				exit 1
> +			fi
> +		done
> +
> +		echo "Loading wifi"
> +		wifi
> +
> +	else
> +		echo "We have no new file or we haven't got a file. We do
> nothing. We try it again in 5 minutes...";

Meines Erachtens ist hier nur "We have no new file" erfüllt. Der andere Fall
wäre eine if weiter außen. Siehe [ ! -f /tmp/keyxchangev2data] ...


> +	fi
> +
> +	# and now we read the VPN Data and give this data to fff-vpn
> +	json_load "$(cat /tmp/keyxchangev2data)"
> +
> +	json_select vpn
> +	Index="1"
> +	rm /tmp/fastd_fff_output
> +	touch /tmp/fastd_fff_output
> +	while json_select $Index > /dev/null

Wieso while wenn nur ein Element "1"?


> +	do
> +		json_get_var protocol protocol
> +		if [ "$protocol" == "fastd" ]; then
> +			json_get_var servername name
> +			echo "####${servername}.conf" >>
> /tmp/fastd_fff_output
> +			echo "#name \"${servername}\";" >>
> /tmp/fastd_fff_output
> +			json_get_var key key
> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
> +			json_get_var address address
> +			json_get_var port port
> +			echo "remote ipv4 \"${address}\" port $port float;"
> >> /tmp/fastd_fff_output
> +		fi
> +		echo "" >> /tmp/fastd_fff_output
> +		echo "###" >> /tmp/fastd_fff_output

Die beiden kommen ja nur einmal am Schluss, also müssen sie aus dem while
raus, oder?

Grüße

Adrian


> +	done
> +	#this we do every 5 minutes, because it can change the VPN Protocol
> +	#and now we get to vpn-select Script and load VPNs
> +	sh /usr/sbin/vpn-select
> +fi
> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
> index 166d423..305ab8d 100644
> --- a/src/packages/fff/fff/Makefile
> +++ b/src/packages/fff/fff/Makefile
> @@ -29,7 +29,8 @@ define Package/fff-base
>               +fff-wireless \
>               +fff-timeserver \
>               +fff-vpn-select \
> -             +simple-tc
> +             +simple-tc \
> +             +fff-hoods
>  endef
> 
>  define Package/fff-base/description
> --
> 2.7.4
> 
> --
> franken-dev mailing list
> franken-dev@freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Adrian Schmutzler Oct. 1, 2017, 2:09 p.m.
Hallo nochmal,

der Shellchecker bringt mir das hier:

Line 11:
                return true;
                       ^-- SC2152: Can only return 0-255. Other data should
be written to stdout.
 
Line 13:
                return false;
                       ^-- SC2152: Can only return 0-255. Other data should
be written to stdout.
 
Line 21:
        if [ isGatewayAvailable ]; then
             ^-- SC2078: This expression is constant. Did you forget a $
somewhere?


Sollte man die Funktion vll. auf 0 und 1 umschreiben?

Grüße

Adrian

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Adrian Schmutzler
> Sent: Sonntag, 1. Oktober 2017 15:49
> To: franken-dev@freifunk.net
> Cc: Jan Kraus <mayosemmel@gmail.com>
> Subject: [PATCH v10 4/4] Add fff-hoods
> 
> From: Christian Dresel <fff@chrisi01.de>
> 
> this packages connect to keyxchangev2
> after review we must change the serveradress! This is only a example
> 
> Signed-off-by: Christian Dresel <fff@chrisi01.de>
> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> 
> Update in v2:
>  - clean tabstops
>  - move the json vpn out of the if because we need this after reboot
> 
> Update in v5:
> 	!!UNTESTED!!
>  - change hidden AP ip to locallink
>  - Open hidden AP after more checks
>  - Load json File from Gateway if Gateway in Batman in Range
> 
> Update in v6:
> 	!!UNTESTED!!
>  - fix hidden station v6
>  - fix -n to -f if
>  - Add function to check for a gateway and use this
>  - remove /etc/community.cfg and variables
>  - send fewer infos to keyxchangev2
>  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit  on
the
> wgets
>  - change the position from json_load and do this only 1 times
> 
> Update in v7:
> 	!!UNTESTED!!
>  - delete keyxchangev2data at start of the script
>  - do only things with keyxchangev2data if available
>  - change keyxchangev2 url
> 
> Update in v8/v9:
>  - rebase onto 20170918-beta
> 
> Update in v10:
>  - Minor code fixes
>  - Added fff-hoods to fff-base Makefile
>  - Removed trailing whitespaces and harmonized tabs
>  - Fixed some comments spelling
>  - Added mac for hostname rewrite
>  - Removed redundant check for /tmp/keyxchangev2data
> ---
>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
> +++++++++++++++++++++
>  src/packages/fff/fff/Makefile                      |   3 +-
>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
> src/packages/fff/fff-hoods/Makefile
>  create mode 100644 src/packages/fff/fff-
> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>  create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
> hoods
>  create mode 100755 src/packages/fff/fff-
> hoods/files/usr/sbin/configurehood
> 
> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-
> hoods/Makefile
> new file mode 100644
> index 0000000..f85178d
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/Makefile
> @@ -0,0 +1,39 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=fff-hoods
> +PKG_VERSION:=0.0.1
> +PKG_RELEASE:=1
> +
> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/fff-hoods
> +    SECTION:=base
> +    CATEGORY:=Freifunk
> +    TITLE:= Freifunk-Franken hoods
> +    URL:=http://www.freifunk-franken.de
> +    DEPENDS:=+fff-network
> +endef
> +
> +define Package/fff-hoods/description
> +    This package load and configures the current hood endef
> +
> +define Build/Prepare
> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
> +
> +define Build/Configure
> +	# nothing
> +endef
> +
> +define Build/Compile
> +	# nothing
> +endef
> +
> +define Package/fff-hoods/install
> +	$(CP) ./files/* $(1)/
> +endef
> +
> +$(eval $(call BuildPackage,fff-hoods))
> diff --git
a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> new file mode 100644
> index 0000000..49f53e3
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> @@ -0,0 +1,5 @@
> +#!/bin/sh
> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
> +       sleep 3
> +       /usr/sbin/configurehood
> +}
> diff --git a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> new file mode 100644
> index 0000000..ca8d798
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> @@ -0,0 +1 @@
> +*/5 * * * * /usr/sbin/configurehood
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> new file mode 100755
> index 0000000..ad316f8
> --- /dev/null
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -0,0 +1,206 @@
> +#!/bin/sh
> +
> +. /usr/share/libubox/jshn.sh
> +. /lib/functions/fff/wireless
> +
> +rm /tmp/keyxchangev2data
> +
> +# Gatewaycheck function
> +isGatewayAvailable() {
> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
> +		return true;
> +	else
> +		return false;
> +	fi
> +}
> +
> +
> +# Hidden AP check
> +
> +if [ -f /tmp/hiddenapflag ]; then
> +	if [ isGatewayAvailable ]; then
> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
> "configap" "configap" "1"; then
> +			echo "Can't add AP interface on $radio."
> +			exit 1
> +		else
> +			# We must set a fixed ip address here
> +			uci set network.configap=interface
> +			uci set network.configap.proto='static'
> +			uci set network.configap.ip6addr='fe80::1/64'
> +			uci commit network
> +		fi
> +	else
> +		rm /tmp/hiddenapflag
> +	fi
> +fi
> +
> +
> +lat=$(uci get system.@system[0].latitude) long=$(uci get
> +system.@system[0].longitude) hostname=$(cat
> /proc/sys/kernel/hostname)
> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = "OpenWrt" ]
> && hostname=""
> +[ "$hostname" = "" ] &&  hostname="$mac"
> +
> +test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken
> keyserver
> +test_ipv4_host2="8.8.8.8"        # Google DNS
> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
> +
> +# if we have Internet, we download the Hoodfile from the keyxchangev2
> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
> +	wget -T15 -t5 "http://keyserver.freifunk-
> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
> +	#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
> +	# Only do that, when we have no gateway in range. If the
> Uplinkrouter changed the hood, we lost the GW and do this automatically
> again, I think! Nice idea?
> +	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
> +		if ! wifiDelAll; then
> +			echo "Can't delete current wifi setup"
> +			exit 1
> +		fi
> +		#now we look for phy and add this
> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> +				echo "$phy is 2.4 GHz"
> +				radio=$(wifiAddPhy "$phy"
> "$BATMAN_CHANNEL")
> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi
> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> +				echo "$phy is 5 GHz"
> +				radio=$(wifiAddPhy "$phy"
> "$BATMAN_CHANNEL_5GHZ")
> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi
> +			#and here we add the station
> +			if ! wifiAddSta "$radio"
"config.franken.freifunk.net"
> "configSta"; then
> +				echo "Can't add Sta interface on $radio."
> +				exit 1
> +			fi
> +
> +		done
> +
> +		wifi
> +		# 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
> +	else
> +		echo "We have a Gateway in Range, we load the
> keyxchangev2data from fe80::1"
> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
> -O /tmp/keyxchangev2data
> +	fi
> +
> +fi
> +
> +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!
> +
> +	json_load "$(cat /tmp/keyxchangev2data)"
> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
> | cut -f1 -d " ")
> +	if [ "$sumnew" != "$sumold" ]; then
> +		echo "New file detect, we reconfigure the Node";
> +
> +		# copy the file to webroot so that other Meshrouter can
> download it
> +		cp /tmp/keyxchangev2data /www/public/
> +
> +		json_select hood
> +
> +		json_get_var hood name
> +		json_get_var mesh_bssid mesh_bssid
> +		json_get_var mesh_essid mesh_essid
> +		json_get_var essid essid
> +		# i think the next things we don't active this in the first
> version! we can do it later
> +		#json_get_var channel2 channel2
> +		#json_get_var mode2 mode2
> +		#json_get_var type2 type2
> +		#json_get_var channel5 channel5
> +		#json_get_var mode5 mode5
> +		#json_get_var type5 type5
> +		#json_get_var protocol protocol
> +
> +		echo "Setting hood name: $hood"
> +		uci set "system.@system[0].hood=$hood"
> +
> +		if ! wifiDelAll; then
> +			echo "Can't delete current wifi setup"
> +			exit 1
> +		fi
> +
> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> +				echo "$phy is 2.4 GHz"
> +				radio=$(wifiAddPhy "$phy" "1")
> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi
> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> +				echo "$phy is 5 GHz"
> +				radio=$(wifiAddPhy "$phy" "13")
> +				if [ -z "$radio" ]; then
> +					echo "Can't create radio for $phy"
> +					exit 1
> +				fi
> +			fi
> +
> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
then
> +				echo "Can't add AP interface on $radio."
> +				exit 1
> +			fi
> +
> +			# here we set a bit for add hidden AP
> +			touch /tmp/hiddenapflag
> +
> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
> "$mesh_bssid"; then
> +				echo "Can't add AP interface on $radio."
> +				exit 1
> +			fi
> +		done
> +
> +		echo "Loading wifi"
> +		wifi
> +
> +	else
> +		echo "We have no new file or we haven't got a file. We do
> nothing. We try it again in 5 minutes...";
> +	fi
> +
> +	# and now we read the VPN Data and give this data to fff-vpn
> +	json_load "$(cat /tmp/keyxchangev2data)"
> +
> +	json_select vpn
> +	Index="1"
> +	rm /tmp/fastd_fff_output
> +	touch /tmp/fastd_fff_output
> +	while json_select $Index > /dev/null
> +	do
> +		json_get_var protocol protocol
> +		if [ "$protocol" == "fastd" ]; then
> +			json_get_var servername name
> +			echo "####${servername}.conf" >>
> /tmp/fastd_fff_output
> +			echo "#name \"${servername}\";" >>
> /tmp/fastd_fff_output
> +			json_get_var key key
> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
> +			json_get_var address address
> +			json_get_var port port
> +			echo "remote ipv4 \"${address}\" port $port float;"
> >> /tmp/fastd_fff_output
> +		fi
> +		echo "" >> /tmp/fastd_fff_output
> +		echo "###" >> /tmp/fastd_fff_output
> +	done
> +	#this we do every 5 minutes, because it can change the VPN Protocol
> +	#and now we get to vpn-select Script and load VPNs
> +	sh /usr/sbin/vpn-select
> +fi
> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
> index 166d423..305ab8d 100644
> --- a/src/packages/fff/fff/Makefile
> +++ b/src/packages/fff/fff/Makefile
> @@ -29,7 +29,8 @@ define Package/fff-base
>               +fff-wireless \
>               +fff-timeserver \
>               +fff-vpn-select \
> -             +simple-tc
> +             +simple-tc \
> +             +fff-hoods
>  endef
> 
>  define Package/fff-base/description
> --
> 2.7.4
> 
> --
> franken-dev mailing list
> franken-dev@freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Adrian Schmutzler Oct. 1, 2017, 5:29 p.m.
Hallo,

hab jetzt ein Testsetup, aber mein zweiter Router scheitert beim Zugriff
über w2sta:

Connecting to [fe80::1%w2sta] ([fe80::1%w2sta]:80)
wget: can't connect to remote host: Permission denied

Beim pingen kommt die gleiche Meldung.

Grüße

Adrian


> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of mail@adrianschmutzler.de
> Sent: Sonntag, 1. Oktober 2017 16:10
> To: franken-dev@freifunk.net
> Subject: RE: [PATCH v10 4/4] Add fff-hoods
> 
> Hallo nochmal,
> 
> der Shellchecker bringt mir das hier:
> 
> Line 11:
>                 return true;
>                        ^-- SC2152: Can only return 0-255. Other data
should be written to
> stdout.
> 
> Line 13:
>                 return false;
>                        ^-- SC2152: Can only return 0-255. Other data
should be written to
> stdout.
> 
> Line 21:
>         if [ isGatewayAvailable ]; then
>              ^-- SC2078: This expression is constant. Did you forget a $
somewhere?
> 
> 
> Sollte man die Funktion vll. auf 0 und 1 umschreiben?
> 
> Grüße
> 
> Adrian
> 
> > -----Original Message-----
> > From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> > Of Adrian Schmutzler
> > Sent: Sonntag, 1. Oktober 2017 15:49
> > To: franken-dev@freifunk.net
> > Cc: Jan Kraus <mayosemmel@gmail.com>
> > Subject: [PATCH v10 4/4] Add fff-hoods
> >
> > From: Christian Dresel <fff@chrisi01.de>
> >
> > this packages connect to keyxchangev2
> > after review we must change the serveradress! This is only a example
> >
> > Signed-off-by: Christian Dresel <fff@chrisi01.de>
> > Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
> > Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> >
> > Update in v2:
> >  - clean tabstops
> >  - move the json vpn out of the if because we need this after reboot
> >
> > Update in v5:
> > 	!!UNTESTED!!
> >  - change hidden AP ip to locallink
> >  - Open hidden AP after more checks
> >  - Load json File from Gateway if Gateway in Batman in Range
> >
> > Update in v6:
> > 	!!UNTESTED!!
> >  - fix hidden station v6
> >  - fix -n to -f if
> >  - Add function to check for a gateway and use this
> >  - remove /etc/community.cfg and variables
> >  - send fewer infos to keyxchangev2
> >  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit
> > on
> the
> > wgets
> >  - change the position from json_load and do this only 1 times
> >
> > Update in v7:
> > 	!!UNTESTED!!
> >  - delete keyxchangev2data at start of the script
> >  - do only things with keyxchangev2data if available
> >  - change keyxchangev2 url
> >
> > Update in v8/v9:
> >  - rebase onto 20170918-beta
> >
> > Update in v10:
> >  - Minor code fixes
> >  - Added fff-hoods to fff-base Makefile
> >  - Removed trailing whitespaces and harmonized tabs
> >  - Fixed some comments spelling
> >  - Added mac for hostname rewrite
> >  - Removed redundant check for /tmp/keyxchangev2data
> > ---
> >  src/packages/fff/fff-hoods/Makefile                |  39 ++++
> >  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
> >  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
> >  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
> > +++++++++++++++++++++
> >  src/packages/fff/fff/Makefile                      |   3 +-
> >  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
> > src/packages/fff/fff-hoods/Makefile
> >  create mode 100644 src/packages/fff/fff-
> > hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >  create mode 100644
> > src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
> > hoods
> >  create mode 100755 src/packages/fff/fff-
> > hoods/files/usr/sbin/configurehood
> >
> > diff --git a/src/packages/fff/fff-hoods/Makefile
> > b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index
> > 0000000..f85178d
> > --- /dev/null
> > +++ b/src/packages/fff/fff-hoods/Makefile
> > @@ -0,0 +1,39 @@
> > +include $(TOPDIR)/rules.mk
> > +
> > +PKG_NAME:=fff-hoods
> > +PKG_VERSION:=0.0.1
> > +PKG_RELEASE:=1
> > +
> > +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
> > +
> > +include $(INCLUDE_DIR)/package.mk
> > +
> > +define Package/fff-hoods
> > +    SECTION:=base
> > +    CATEGORY:=Freifunk
> > +    TITLE:= Freifunk-Franken hoods
> > +    URL:=http://www.freifunk-franken.de
> > +    DEPENDS:=+fff-network
> > +endef
> > +
> > +define Package/fff-hoods/description
> > +    This package load and configures the current hood endef
> > +
> > +define Build/Prepare
> > +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
> > +
> > +define Build/Configure
> > +	# nothing
> > +endef
> > +
> > +define Build/Compile
> > +	# nothing
> > +endef
> > +
> > +define Package/fff-hoods/install
> > +	$(CP) ./files/* $(1)/
> > +endef
> > +
> > +$(eval $(call BuildPackage,fff-hoods))
> > diff --git
> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> > b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> > new file mode 100644
> > index 0000000..49f53e3
> > --- /dev/null
> > +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
> > +++ s
> > @@ -0,0 +1,5 @@
> > +#!/bin/sh
> > +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
> > +       sleep 3
> > +       /usr/sbin/configurehood
> > +}
> > diff --git
> > a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > new file mode 100644
> > index 0000000..ca8d798
> > --- /dev/null
> > +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > @@ -0,0 +1 @@
> > +*/5 * * * * /usr/sbin/configurehood
> > diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > new file mode 100755
> > index 0000000..ad316f8
> > --- /dev/null
> > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > @@ -0,0 +1,206 @@
> > +#!/bin/sh
> > +
> > +. /usr/share/libubox/jshn.sh
> > +. /lib/functions/fff/wireless
> > +
> > +rm /tmp/keyxchangev2data
> > +
> > +# Gatewaycheck function
> > +isGatewayAvailable() {
> > +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
> > +		return true;
> > +	else
> > +		return false;
> > +	fi
> > +}
> > +
> > +
> > +# Hidden AP check
> > +
> > +if [ -f /tmp/hiddenapflag ]; then
> > +	if [ isGatewayAvailable ]; then
> > +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
> > "configap" "configap" "1"; then
> > +			echo "Can't add AP interface on $radio."
> > +			exit 1
> > +		else
> > +			# We must set a fixed ip address here
> > +			uci set network.configap=interface
> > +			uci set network.configap.proto='static'
> > +			uci set network.configap.ip6addr='fe80::1/64'
> > +			uci commit network
> > +		fi
> > +	else
> > +		rm /tmp/hiddenapflag
> > +	fi
> > +fi
> > +
> > +
> > +lat=$(uci get system.@system[0].latitude) long=$(uci get
> > +system.@system[0].longitude) hostname=$(cat
> > /proc/sys/kernel/hostname)
> > +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
> > +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" =
> "OpenWrt"
> > +]
> > && hostname=""
> > +[ "$hostname" = "" ] &&  hostname="$mac"
> > +
> > +test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken
> > keyserver
> > +test_ipv4_host2="8.8.8.8"        # Google DNS
> > +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
> > +
> > +# if we have Internet, we download the Hoodfile from the keyxchangev2
> > +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
> > +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
> > +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
> > +	wget -T15 -t5 "http://keyserver.freifunk-
> > franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
> > +	#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
> > +	# Only do that, when we have no gateway in range. If the
> > Uplinkrouter changed the hood, we lost the GW and do this
> > automatically again, I think! Nice idea?
> > +	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
> > +		if ! wifiDelAll; then
> > +			echo "Can't delete current wifi setup"
> > +			exit 1
> > +		fi
> > +		#now we look for phy and add this
> > +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> > +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> > +				echo "$phy is 2.4 GHz"
> > +				radio=$(wifiAddPhy "$phy"
> > "$BATMAN_CHANNEL")
> > +				if [ -z "$radio" ]; then
> > +					echo "Can't create radio for $phy"
> > +					exit 1
> > +				fi
> > +			fi
> > +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> > +				echo "$phy is 5 GHz"
> > +				radio=$(wifiAddPhy "$phy"
> > "$BATMAN_CHANNEL_5GHZ")
> > +				if [ -z "$radio" ]; then
> > +					echo "Can't create radio for $phy"
> > +					exit 1
> > +				fi
> > +			fi
> > +			#and here we add the station
> > +			if ! wifiAddSta "$radio"
> "config.franken.freifunk.net"
> > "configSta"; then
> > +				echo "Can't add Sta interface on $radio."
> > +				exit 1
> > +			fi
> > +
> > +		done
> > +
> > +		wifi
> > +		# 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
> > +	else
> > +		echo "We have a Gateway in Range, we load the
> > keyxchangev2data from fe80::1"
> > +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
> > -O /tmp/keyxchangev2data
> > +	fi
> > +
> > +fi
> > +
> > +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!
> > +
> > +	json_load "$(cat /tmp/keyxchangev2data)"
> > +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
> > +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
> > | cut -f1 -d " ")
> > +	if [ "$sumnew" != "$sumold" ]; then
> > +		echo "New file detect, we reconfigure the Node";
> > +
> > +		# copy the file to webroot so that other Meshrouter can
> > download it
> > +		cp /tmp/keyxchangev2data /www/public/
> > +
> > +		json_select hood
> > +
> > +		json_get_var hood name
> > +		json_get_var mesh_bssid mesh_bssid
> > +		json_get_var mesh_essid mesh_essid
> > +		json_get_var essid essid
> > +		# i think the next things we don't active this in the first
> > version! we can do it later
> > +		#json_get_var channel2 channel2
> > +		#json_get_var mode2 mode2
> > +		#json_get_var type2 type2
> > +		#json_get_var channel5 channel5
> > +		#json_get_var mode5 mode5
> > +		#json_get_var type5 type5
> > +		#json_get_var protocol protocol
> > +
> > +		echo "Setting hood name: $hood"
> > +		uci set "system.@system[0].hood=$hood"
> > +
> > +		if ! wifiDelAll; then
> > +			echo "Can't delete current wifi setup"
> > +			exit 1
> > +		fi
> > +
> > +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> > +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> > +				echo "$phy is 2.4 GHz"
> > +				radio=$(wifiAddPhy "$phy" "1")
> > +				if [ -z "$radio" ]; then
> > +					echo "Can't create radio for $phy"
> > +					exit 1
> > +				fi
> > +			fi
> > +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> > +				echo "$phy is 5 GHz"
> > +				radio=$(wifiAddPhy "$phy" "13")
> > +				if [ -z "$radio" ]; then
> > +					echo "Can't create radio for $phy"
> > +					exit 1
> > +				fi
> > +			fi
> > +
> > +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
> then
> > +				echo "Can't add AP interface on $radio."
> > +				exit 1
> > +			fi
> > +
> > +			# here we set a bit for add hidden AP
> > +			touch /tmp/hiddenapflag
> > +
> > +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
> > "$mesh_bssid"; then
> > +				echo "Can't add AP interface on $radio."
> > +				exit 1
> > +			fi
> > +		done
> > +
> > +		echo "Loading wifi"
> > +		wifi
> > +
> > +	else
> > +		echo "We have no new file or we haven't got a file. We do
> > nothing. We try it again in 5 minutes...";
> > +	fi
> > +
> > +	# and now we read the VPN Data and give this data to fff-vpn
> > +	json_load "$(cat /tmp/keyxchangev2data)"
> > +
> > +	json_select vpn
> > +	Index="1"
> > +	rm /tmp/fastd_fff_output
> > +	touch /tmp/fastd_fff_output
> > +	while json_select $Index > /dev/null
> > +	do
> > +		json_get_var protocol protocol
> > +		if [ "$protocol" == "fastd" ]; then
> > +			json_get_var servername name
> > +			echo "####${servername}.conf" >>
> > /tmp/fastd_fff_output
> > +			echo "#name \"${servername}\";" >>
> > /tmp/fastd_fff_output
> > +			json_get_var key key
> > +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
> > +			json_get_var address address
> > +			json_get_var port port
> > +			echo "remote ipv4 \"${address}\" port $port float;"
> > >> /tmp/fastd_fff_output
> > +		fi
> > +		echo "" >> /tmp/fastd_fff_output
> > +		echo "###" >> /tmp/fastd_fff_output
> > +	done
> > +	#this we do every 5 minutes, because it can change the VPN Protocol
> > +	#and now we get to vpn-select Script and load VPNs
> > +	sh /usr/sbin/vpn-select
> > +fi
> > diff --git a/src/packages/fff/fff/Makefile
> > b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
> > --- a/src/packages/fff/fff/Makefile
> > +++ b/src/packages/fff/fff/Makefile
> > @@ -29,7 +29,8 @@ define Package/fff-base
> >               +fff-wireless \
> >               +fff-timeserver \
> >               +fff-vpn-select \
> > -             +simple-tc
> > +             +simple-tc \
> > +             +fff-hoods
> >  endef
> >
> >  define Package/fff-base/description
> > --
> > 2.7.4
> >
> > --
> > franken-dev mailing list
> > franken-dev@freifunk.net
> > http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
> 
> --
> franken-dev mailing list
> franken-dev@freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Christian Dresel Oct. 1, 2017, 5:48 p.m.
Hi

gibt es das hidden Netz wirklich bereits (da war in der letzten Version
ein Bug drinnen, das er das Radio nicht dran hängt)? Kannst du dich mit
Laptop verbinden? Ist das Interface am Uplinkrouter da und hat es dort
auch die fe80::1?

Bei mir hat es bis v4 oder so geklappt, danach hab ich es nicht mehr
getestet.

mfg

Christian

On 01.10.2017 19:29, mail@adrianschmutzler.de wrote:
> Hallo,
>
> hab jetzt ein Testsetup, aber mein zweiter Router scheitert beim Zugriff
> über w2sta:
>
> Connecting to [fe80::1%w2sta] ([fe80::1%w2sta]:80)
> wget: can't connect to remote host: Permission denied
>
> Beim pingen kommt die gleiche Meldung.
>
> Grüße
>
> Adrian
>
>
>> -----Original Message-----
>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
>> Of mail@adrianschmutzler.de
>> Sent: Sonntag, 1. Oktober 2017 16:10
>> To: franken-dev@freifunk.net
>> Subject: RE: [PATCH v10 4/4] Add fff-hoods
>>
>> Hallo nochmal,
>>
>> der Shellchecker bringt mir das hier:
>>
>> Line 11:
>>                 return true;
>>                        ^-- SC2152: Can only return 0-255. Other data
> should be written to
>> stdout.
>>
>> Line 13:
>>                 return false;
>>                        ^-- SC2152: Can only return 0-255. Other data
> should be written to
>> stdout.
>>
>> Line 21:
>>         if [ isGatewayAvailable ]; then
>>              ^-- SC2078: This expression is constant. Did you forget a $
> somewhere?
>>
>> Sollte man die Funktion vll. auf 0 und 1 umschreiben?
>>
>> Grüße
>>
>> Adrian
>>
>>> -----Original Message-----
>>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
>>> Of Adrian Schmutzler
>>> Sent: Sonntag, 1. Oktober 2017 15:49
>>> To: franken-dev@freifunk.net
>>> Cc: Jan Kraus <mayosemmel@gmail.com>
>>> Subject: [PATCH v10 4/4] Add fff-hoods
>>>
>>> From: Christian Dresel <fff@chrisi01.de>
>>>
>>> this packages connect to keyxchangev2
>>> after review we must change the serveradress! This is only a example
>>>
>>> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>>> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>>
>>> Update in v2:
>>>  - clean tabstops
>>>  - move the json vpn out of the if because we need this after reboot
>>>
>>> Update in v5:
>>> 	!!UNTESTED!!
>>>  - change hidden AP ip to locallink
>>>  - Open hidden AP after more checks
>>>  - Load json File from Gateway if Gateway in Batman in Range
>>>
>>> Update in v6:
>>> 	!!UNTESTED!!
>>>  - fix hidden station v6
>>>  - fix -n to -f if
>>>  - Add function to check for a gateway and use this
>>>  - remove /etc/community.cfg and variables
>>>  - send fewer infos to keyxchangev2
>>>  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit
>>> on
>> the
>>> wgets
>>>  - change the position from json_load and do this only 1 times
>>>
>>> Update in v7:
>>> 	!!UNTESTED!!
>>>  - delete keyxchangev2data at start of the script
>>>  - do only things with keyxchangev2data if available
>>>  - change keyxchangev2 url
>>>
>>> Update in v8/v9:
>>>  - rebase onto 20170918-beta
>>>
>>> Update in v10:
>>>  - Minor code fixes
>>>  - Added fff-hoods to fff-base Makefile
>>>  - Removed trailing whitespaces and harmonized tabs
>>>  - Fixed some comments spelling
>>>  - Added mac for hostname rewrite
>>>  - Removed redundant check for /tmp/keyxchangev2data
>>> ---
>>>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>>>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>>>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>>>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>>> +++++++++++++++++++++
>>>  src/packages/fff/fff/Makefile                      |   3 +-
>>>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
>>> src/packages/fff/fff-hoods/Makefile
>>>  create mode 100644 src/packages/fff/fff-
>>> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>>  create mode 100644
>>> src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>>> hoods
>>>  create mode 100755 src/packages/fff/fff-
>>> hoods/files/usr/sbin/configurehood
>>>
>>> diff --git a/src/packages/fff/fff-hoods/Makefile
>>> b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index
>>> 0000000..f85178d
>>> --- /dev/null
>>> +++ b/src/packages/fff/fff-hoods/Makefile
>>> @@ -0,0 +1,39 @@
>>> +include $(TOPDIR)/rules.mk
>>> +
>>> +PKG_NAME:=fff-hoods
>>> +PKG_VERSION:=0.0.1
>>> +PKG_RELEASE:=1
>>> +
>>> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>>> +
>>> +include $(INCLUDE_DIR)/package.mk
>>> +
>>> +define Package/fff-hoods
>>> +    SECTION:=base
>>> +    CATEGORY:=Freifunk
>>> +    TITLE:= Freifunk-Franken hoods
>>> +    URL:=http://www.freifunk-franken.de
>>> +    DEPENDS:=+fff-network
>>> +endef
>>> +
>>> +define Package/fff-hoods/description
>>> +    This package load and configures the current hood endef
>>> +
>>> +define Build/Prepare
>>> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>>> +
>>> +define Build/Configure
>>> +	# nothing
>>> +endef
>>> +
>>> +define Build/Compile
>>> +	# nothing
>>> +endef
>>> +
>>> +define Package/fff-hoods/install
>>> +	$(CP) ./files/* $(1)/
>>> +endef
>>> +
>>> +$(eval $(call BuildPackage,fff-hoods))
>>> diff --git
>> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>> new file mode 100644
>>> index 0000000..49f53e3
>>> --- /dev/null
>>> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
>>> +++ s
>>> @@ -0,0 +1,5 @@
>>> +#!/bin/sh
>>> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>>> +       sleep 3
>>> +       /usr/sbin/configurehood
>>> +}
>>> diff --git
>>> a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>> new file mode 100644
>>> index 0000000..ca8d798
>>> --- /dev/null
>>> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>> @@ -0,0 +1 @@
>>> +*/5 * * * * /usr/sbin/configurehood
>>> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>> new file mode 100755
>>> index 0000000..ad316f8
>>> --- /dev/null
>>> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>> @@ -0,0 +1,206 @@
>>> +#!/bin/sh
>>> +
>>> +. /usr/share/libubox/jshn.sh
>>> +. /lib/functions/fff/wireless
>>> +
>>> +rm /tmp/keyxchangev2data
>>> +
>>> +# Gatewaycheck function
>>> +isGatewayAvailable() {
>>> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>>> +		return true;
>>> +	else
>>> +		return false;
>>> +	fi
>>> +}
>>> +
>>> +
>>> +# Hidden AP check
>>> +
>>> +if [ -f /tmp/hiddenapflag ]; then
>>> +	if [ isGatewayAvailable ]; then
>>> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
>>> "configap" "configap" "1"; then
>>> +			echo "Can't add AP interface on $radio."
>>> +			exit 1
>>> +		else
>>> +			# We must set a fixed ip address here
>>> +			uci set network.configap=interface
>>> +			uci set network.configap.proto='static'
>>> +			uci set network.configap.ip6addr='fe80::1/64'
>>> +			uci commit network
>>> +		fi
>>> +	else
>>> +		rm /tmp/hiddenapflag
>>> +	fi
>>> +fi
>>> +
>>> +
>>> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>>> +system.@system[0].longitude) hostname=$(cat
>>> /proc/sys/kernel/hostname)
>>> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
>>> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" =
>> "OpenWrt"
>>> +]
>>> && hostname=""
>>> +[ "$hostname" = "" ] &&  hostname="$mac"
>>> +
>>> +test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken
>>> keyserver
>>> +test_ipv4_host2="8.8.8.8"        # Google DNS
>>> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
>>> +
>>> +# if we have Internet, we download the Hoodfile from the keyxchangev2
>>> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>>> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>>> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>>> +	wget -T15 -t5 "http://keyserver.freifunk-
>>> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
>>> +	#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
>>> +	# Only do that, when we have no gateway in range. If the
>>> Uplinkrouter changed the hood, we lost the GW and do this
>>> automatically again, I think! Nice idea?
>>> +	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
>>> +		if ! wifiDelAll; then
>>> +			echo "Can't delete current wifi setup"
>>> +			exit 1
>>> +		fi
>>> +		#now we look for phy and add this
>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>> +				echo "$phy is 2.4 GHz"
>>> +				radio=$(wifiAddPhy "$phy"
>>> "$BATMAN_CHANNEL")
>>> +				if [ -z "$radio" ]; then
>>> +					echo "Can't create radio for $phy"
>>> +					exit 1
>>> +				fi
>>> +			fi
>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>> +				echo "$phy is 5 GHz"
>>> +				radio=$(wifiAddPhy "$phy"
>>> "$BATMAN_CHANNEL_5GHZ")
>>> +				if [ -z "$radio" ]; then
>>> +					echo "Can't create radio for $phy"
>>> +					exit 1
>>> +				fi
>>> +			fi
>>> +			#and here we add the station
>>> +			if ! wifiAddSta "$radio"
>> "config.franken.freifunk.net"
>>> "configSta"; then
>>> +				echo "Can't add Sta interface on $radio."
>>> +				exit 1
>>> +			fi
>>> +
>>> +		done
>>> +
>>> +		wifi
>>> +		# 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
>>> +	else
>>> +		echo "We have a Gateway in Range, we load the
>>> keyxchangev2data from fe80::1"
>>> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
>>> -O /tmp/keyxchangev2data
>>> +	fi
>>> +
>>> +fi
>>> +
>>> +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!
>>> +
>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
>>> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
>>> | cut -f1 -d " ")
>>> +	if [ "$sumnew" != "$sumold" ]; then
>>> +		echo "New file detect, we reconfigure the Node";
>>> +
>>> +		# copy the file to webroot so that other Meshrouter can
>>> download it
>>> +		cp /tmp/keyxchangev2data /www/public/
>>> +
>>> +		json_select hood
>>> +
>>> +		json_get_var hood name
>>> +		json_get_var mesh_bssid mesh_bssid
>>> +		json_get_var mesh_essid mesh_essid
>>> +		json_get_var essid essid
>>> +		# i think the next things we don't active this in the first
>>> version! we can do it later
>>> +		#json_get_var channel2 channel2
>>> +		#json_get_var mode2 mode2
>>> +		#json_get_var type2 type2
>>> +		#json_get_var channel5 channel5
>>> +		#json_get_var mode5 mode5
>>> +		#json_get_var type5 type5
>>> +		#json_get_var protocol protocol
>>> +
>>> +		echo "Setting hood name: $hood"
>>> +		uci set "system.@system[0].hood=$hood"
>>> +
>>> +		if ! wifiDelAll; then
>>> +			echo "Can't delete current wifi setup"
>>> +			exit 1
>>> +		fi
>>> +
>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>> +				echo "$phy is 2.4 GHz"
>>> +				radio=$(wifiAddPhy "$phy" "1")
>>> +				if [ -z "$radio" ]; then
>>> +					echo "Can't create radio for $phy"
>>> +					exit 1
>>> +				fi
>>> +			fi
>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>> +				echo "$phy is 5 GHz"
>>> +				radio=$(wifiAddPhy "$phy" "13")
>>> +				if [ -z "$radio" ]; then
>>> +					echo "Can't create radio for $phy"
>>> +					exit 1
>>> +				fi
>>> +			fi
>>> +
>>> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
>> then
>>> +				echo "Can't add AP interface on $radio."
>>> +				exit 1
>>> +			fi
>>> +
>>> +			# here we set a bit for add hidden AP
>>> +			touch /tmp/hiddenapflag
>>> +
>>> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
>>> "$mesh_bssid"; then
>>> +				echo "Can't add AP interface on $radio."
>>> +				exit 1
>>> +			fi
>>> +		done
>>> +
>>> +		echo "Loading wifi"
>>> +		wifi
>>> +
>>> +	else
>>> +		echo "We have no new file or we haven't got a file. We do
>>> nothing. We try it again in 5 minutes...";
>>> +	fi
>>> +
>>> +	# and now we read the VPN Data and give this data to fff-vpn
>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>> +
>>> +	json_select vpn
>>> +	Index="1"
>>> +	rm /tmp/fastd_fff_output
>>> +	touch /tmp/fastd_fff_output
>>> +	while json_select $Index > /dev/null
>>> +	do
>>> +		json_get_var protocol protocol
>>> +		if [ "$protocol" == "fastd" ]; then
>>> +			json_get_var servername name
>>> +			echo "####${servername}.conf" >>
>>> /tmp/fastd_fff_output
>>> +			echo "#name \"${servername}\";" >>
>>> /tmp/fastd_fff_output
>>> +			json_get_var key key
>>> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
>>> +			json_get_var address address
>>> +			json_get_var port port
>>> +			echo "remote ipv4 \"${address}\" port $port float;"
>>>>> /tmp/fastd_fff_output
>>> +		fi
>>> +		echo "" >> /tmp/fastd_fff_output
>>> +		echo "###" >> /tmp/fastd_fff_output
>>> +	done
>>> +	#this we do every 5 minutes, because it can change the VPN Protocol
>>> +	#and now we get to vpn-select Script and load VPNs
>>> +	sh /usr/sbin/vpn-select
>>> +fi
>>> diff --git a/src/packages/fff/fff/Makefile
>>> b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
>>> --- a/src/packages/fff/fff/Makefile
>>> +++ b/src/packages/fff/fff/Makefile
>>> @@ -29,7 +29,8 @@ define Package/fff-base
>>>               +fff-wireless \
>>>               +fff-timeserver \
>>>               +fff-vpn-select \
>>> -             +simple-tc
>>> +             +simple-tc \
>>> +             +fff-hoods
>>>  endef
>>>
>>>  define Package/fff-base/description
>>> --
>>> 2.7.4
>>>
>>> --
>>> franken-dev mailing list
>>> franken-dev@freifunk.net
>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>> --
>> franken-dev mailing list
>> franken-dev@freifunk.net
>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Christian Dresel Oct. 1, 2017, 5:57 p.m.
hi

hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert daher bin
ich die Mail mal eben überflogen und paar Kommentare Inline.

On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
> Hallo,
>
> eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen aufgefallen
> sind.
>
>> -----Original Message-----
>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
>> Of Adrian Schmutzler
>> Sent: Sonntag, 1. Oktober 2017 15:49
>> To: franken-dev@freifunk.net
>> Cc: Jan Kraus <mayosemmel@gmail.com>
>> Subject: [PATCH v10 4/4] Add fff-hoods
>>
>> From: Christian Dresel <fff@chrisi01.de>
>>
>> this packages connect to keyxchangev2
>> after review we must change the serveradress! This is only a example
>>
>> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>
>> Update in v2:
>>  - clean tabstops
>>  - move the json vpn out of the if because we need this after reboot
>>
>> Update in v5:
>> 	!!UNTESTED!!
>>  - change hidden AP ip to locallink
>>  - Open hidden AP after more checks
>>  - Load json File from Gateway if Gateway in Batman in Range
>>
>> Update in v6:
>> 	!!UNTESTED!!
>>  - fix hidden station v6
>>  - fix -n to -f if
>>  - Add function to check for a gateway and use this
>>  - remove /etc/community.cfg and variables
>>  - send fewer infos to keyxchangev2
>>  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit  on
> the
>> wgets
>>  - change the position from json_load and do this only 1 times
>>
>> Update in v7:
>> 	!!UNTESTED!!
>>  - delete keyxchangev2data at start of the script
>>  - do only things with keyxchangev2data if available
>>  - change keyxchangev2 url
>>
>> Update in v8/v9:
>>  - rebase onto 20170918-beta
>>
>> Update in v10:
>>  - Minor code fixes
>>  - Added fff-hoods to fff-base Makefile
>>  - Removed trailing whitespaces and harmonized tabs
>>  - Fixed some comments spelling
>>  - Added mac for hostname rewrite
>>  - Removed redundant check for /tmp/keyxchangev2data
>> ---
>>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>> +++++++++++++++++++++
>>  src/packages/fff/fff/Makefile                      |   3 +-
>>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
>> src/packages/fff/fff-hoods/Makefile
>>  create mode 100644 src/packages/fff/fff-
>> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>  create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>> hoods
>>  create mode 100755 src/packages/fff/fff-
>> hoods/files/usr/sbin/configurehood
>>
>> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-
>> hoods/Makefile
>> new file mode 100644
>> index 0000000..f85178d
>> --- /dev/null
>> +++ b/src/packages/fff/fff-hoods/Makefile
>> @@ -0,0 +1,39 @@
>> +include $(TOPDIR)/rules.mk
>> +
>> +PKG_NAME:=fff-hoods
>> +PKG_VERSION:=0.0.1
>> +PKG_RELEASE:=1
>> +
>> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>> +
>> +include $(INCLUDE_DIR)/package.mk
>> +
>> +define Package/fff-hoods
>> +    SECTION:=base
>> +    CATEGORY:=Freifunk
>> +    TITLE:= Freifunk-Franken hoods
>> +    URL:=http://www.freifunk-franken.de
>> +    DEPENDS:=+fff-network
>> +endef
>> +
>> +define Package/fff-hoods/description
>> +    This package load and configures the current hood endef
>> +
>> +define Build/Prepare
>> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>> +
>> +define Build/Configure
>> +	# nothing
>> +endef
>> +
>> +define Build/Compile
>> +	# nothing
>> +endef
>> +
>> +define Package/fff-hoods/install
>> +	$(CP) ./files/* $(1)/
>> +endef
>> +
>> +$(eval $(call BuildPackage,fff-hoods))
>> diff --git
> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>> new file mode 100644
>> index 0000000..49f53e3
>> --- /dev/null
>> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>> @@ -0,0 +1,5 @@
>> +#!/bin/sh
>> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>> +       sleep 3
>> +       /usr/sbin/configurehood
>> +}
>> diff --git a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>> new file mode 100644
>> index 0000000..ca8d798
>> --- /dev/null
>> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>> @@ -0,0 +1 @@
>> +*/5 * * * * /usr/sbin/configurehood
>> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>> new file mode 100755
>> index 0000000..ad316f8
>> --- /dev/null
>> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>> @@ -0,0 +1,206 @@
>> +#!/bin/sh
>> +
>> +. /usr/share/libubox/jshn.sh
>> +. /lib/functions/fff/wireless
>> +
>> +rm /tmp/keyxchangev2data
>> +
>> +# Gatewaycheck function
>> +isGatewayAvailable() {
>> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>> +		return true;
>> +	else
>> +		return false;
>> +	fi
>> +}
>> +
>> +
>> +# Hidden AP check
>> +
>> +if [ -f /tmp/hiddenapflag ]; then
>> +	if [ isGatewayAvailable ]; then
>> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
>> "configap" "configap" "1"; then
>> +			echo "Can't add AP interface on $radio."
>> +			exit 1
>> +		else
>> +			# We must set a fixed ip address here
>> +			uci set network.configap=interface
>> +			uci set network.configap.proto='static'
>> +			uci set network.configap.ip6addr='fe80::1/64'
>> +			uci commit network
>> +		fi
>> +	else
>> +		rm /tmp/hiddenapflag
>> +	fi
>> +fi
> Warum steht dieser ganze Block am Anfang und nicht am Schluss des Skripts?
> Hat das einen Grund, dass der immer einen Zyklus warten soll?
genau, Batman hat ein Timeout das wollen wir damit abfangen damit erst
im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss also 5min
eine Verbindung zum GW bestehen.
>
>
>
>> +
>> +
>> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>> +system.@system[0].longitude) hostname=$(cat
>> /proc/sys/kernel/hostname)
>> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
> Hier hab ich die Mac ergänzt.
das war einfach nur C&P
>
>> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = "OpenWrt" ]
>> && hostname=""
>> +[ "$hostname" = "" ] &&  hostname="$mac"
> Wozu ist das gut? Sollte man das auf LEDE ändern?
hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht unsicher
wofür es nötig ist.
>
>> +
>> +test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken
>> keyserver
>> +test_ipv4_host2="8.8.8.8"        # Google DNS
>> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
>> +
>> +# if we have Internet, we download the Hoodfile from the keyxchangev2
>> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>> +	wget -T15 -t5 "http://keyserver.freifunk-
>> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
>> +	#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
>> +	# Only do that, when we have no gateway in range. If the
>> Uplinkrouter changed the hood, we lost the GW and do this automatically
>> again, I think! Nice idea?
>> +	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
>> +		if ! wifiDelAll; then
>> +			echo "Can't delete current wifi setup"
>> +			exit 1
>> +		fi
>> +		#now we look for phy and add this
>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>> +				echo "$phy is 2.4 GHz"
>> +				radio=$(wifiAddPhy "$phy"
>> "$BATMAN_CHANNEL")
>> +				if [ -z "$radio" ]; then
>> +					echo "Can't create radio for $phy"
>> +					exit 1
>> +				fi
>> +			fi
>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>> +				echo "$phy is 5 GHz"
>> +				radio=$(wifiAddPhy "$phy"
>> "$BATMAN_CHANNEL_5GHZ")
>> +				if [ -z "$radio" ]; then
>> +					echo "Can't create radio for $phy"
>> +					exit 1
>> +				fi
>> +			fi
> Hier werden Variablen aus der community.cfg verwendet ($BATMAN...), unten
> ist hardgecodet. Das hier auch hardcoden?
macht vermutlich Sinn, weil wir die /etc/community.cfg eh abschaffen wollen.
>
>
>> +			#and here we add the station
>> +			if ! wifiAddSta "$radio"
> "config.franken.freifunk.net"
>> "configSta"; then
>> +				echo "Can't add Sta interface on $radio."
>> +				exit 1
>> +			fi
>> +
>> +		done
>> +
>> +		wifi
>> +		# 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
>> +	else
>> +		echo "We have a Gateway in Range, we load the
>> keyxchangev2data from fe80::1"
>> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
>> -O /tmp/keyxchangev2data
>> +	fi
>> +
>> +fi
>> +
>> +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!
>> +
>> +	json_load "$(cat /tmp/keyxchangev2data)"
>> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
>> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
>> | cut -f1 -d " ")
>> +	if [ "$sumnew" != "$sumold" ]; then
> Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht irgendwie keinen
> Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon geprüft haben?!
das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich mal
zurück.
>
>
>> +		echo "New file detect, we reconfigure the Node";
>> +
>> +		# copy the file to webroot so that other Meshrouter can
>> download it
>> +		cp /tmp/keyxchangev2data /www/public/
>> +
>> +		json_select hood
>> +
>> +		json_get_var hood name
>> +		json_get_var mesh_bssid mesh_bssid
>> +		json_get_var mesh_essid mesh_essid
>> +		json_get_var essid essid
>> +		# i think the next things we don't active this in the first
>> version! we can do it later
>> +		#json_get_var channel2 channel2
>> +		#json_get_var mode2 mode2
>> +		#json_get_var type2 type2
>> +		#json_get_var channel5 channel5
>> +		#json_get_var mode5 mode5
>> +		#json_get_var type5 type5
>> +		#json_get_var protocol protocol
>> +
>> +		echo "Setting hood name: $hood"
>> +		uci set "system.@system[0].hood=$hood"
>> +
>> +		if ! wifiDelAll; then
>> +			echo "Can't delete current wifi setup"
>> +			exit 1
>> +		fi
>> +
>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>> +				echo "$phy is 2.4 GHz"
>> +				radio=$(wifiAddPhy "$phy" "1")
> Hier ist jetzt hardgecodet ... "1"
interessant, vermutlich hab ich es oben einfach vergessen und wollt es
wirklich überall hard coden weil eben /etc/community.cfg weg fällt.
>
>
>> +				if [ -z "$radio" ]; then
>> +					echo "Can't create radio for $phy"
>> +					exit 1
>> +				fi
>> +			fi
>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>> +				echo "$phy is 5 GHz"
>> +				radio=$(wifiAddPhy "$phy" "13")
>> +				if [ -z "$radio" ]; then
>> +					echo "Can't create radio for $phy"
>> +					exit 1
>> +				fi
>> +			fi
>> +
>> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
> then
>> +				echo "Can't add AP interface on $radio."
>> +				exit 1
>> +			fi
>> +
>> +			# here we set a bit for add hidden AP
>> +			touch /tmp/hiddenapflag
>> +
>> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
>> "$mesh_bssid"; then
>> +				echo "Can't add AP interface on $radio."
>> +				exit 1
>> +			fi
>> +		done
>> +
>> +		echo "Loading wifi"
>> +		wifi
>> +
>> +	else
>> +		echo "We have no new file or we haven't got a file. We do
>> nothing. We try it again in 5 minutes...";
> Meines Erachtens ist hier nur "We have no new file" erfüllt. Der andere Fall
> wäre eine if weiter außen. Siehe [ ! -f /tmp/keyxchangev2data] ...
muss ich mir auch mal in Ruhe angucken...
>
>
>> +	fi
>> +
>> +	# and now we read the VPN Data and give this data to fff-vpn
>> +	json_load "$(cat /tmp/keyxchangev2data)"
>> +
>> +	json_select vpn
>> +	Index="1"
>> +	rm /tmp/fastd_fff_output
>> +	touch /tmp/fastd_fff_output
>> +	while json_select $Index > /dev/null
> Wieso while wenn nur ein Element "1"?
es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit einer
Schleife durchgehen oder?
>
>
>> +	do
>> +		json_get_var protocol protocol
>> +		if [ "$protocol" == "fastd" ]; then
>> +			json_get_var servername name
>> +			echo "####${servername}.conf" >>
>> /tmp/fastd_fff_output
>> +			echo "#name \"${servername}\";" >>
>> /tmp/fastd_fff_output
>> +			json_get_var key key
>> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
>> +			json_get_var address address
>> +			json_get_var port port
>> +			echo "remote ipv4 \"${address}\" port $port float;"
>>>> /tmp/fastd_fff_output
>> +		fi
>> +		echo "" >> /tmp/fastd_fff_output
>> +		echo "###" >> /tmp/fastd_fff_output
> Die beiden kommen ja nur einmal am Schluss, also müssen sie aus dem while
> raus, oder?
oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab ich das
ganze noch nicht getestet, RedDog wollte das aber eh relativ zügig
umbauen weil das Format einfach sh*t ist, besser ist wenn fff-vpn die
json direkt ausliest.

mfg

Christian
>
> Grüße
>
> Adrian
>
>
>> +	done
>> +	#this we do every 5 minutes, because it can change the VPN Protocol
>> +	#and now we get to vpn-select Script and load VPNs
>> +	sh /usr/sbin/vpn-select
>> +fi
>> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
>> index 166d423..305ab8d 100644
>> --- a/src/packages/fff/fff/Makefile
>> +++ b/src/packages/fff/fff/Makefile
>> @@ -29,7 +29,8 @@ define Package/fff-base
>>               +fff-wireless \
>>               +fff-timeserver \
>>               +fff-vpn-select \
>> -             +simple-tc
>> +             +simple-tc \
>> +             +fff-hoods
>>  endef
>>
>>  define Package/fff-base/description
>> --
>> 2.7.4
>>
>> --
>> franken-dev mailing list
>> franken-dev@freifunk.net
>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Tim Niemeyer Oct. 2, 2017, 2:19 p.m.
Hi


Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
> hi
> 
> hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert daher bin
> ich die Mail mal eben überflogen und paar Kommentare Inline.
> 
> On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
> > Hallo,
> >
> > eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen aufgefallen
> > sind.
> >
> >> -----Original Message-----
> >> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> >> Of Adrian Schmutzler
> >> Sent: Sonntag, 1. Oktober 2017 15:49
> >> To: franken-dev@freifunk.net
> >> Cc: Jan Kraus <mayosemmel@gmail.com>
> >> Subject: [PATCH v10 4/4] Add fff-hoods
> >>
> >> From: Christian Dresel <fff@chrisi01.de>
> >>
> >> this packages connect to keyxchangev2
> >> after review we must change the serveradress! This is only a example
> >>
> >> Signed-off-by: Christian Dresel <fff@chrisi01.de>
> >> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
> >> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> >>
> >> Update in v2:
> >>  - clean tabstops
> >>  - move the json vpn out of the if because we need this after reboot
> >>
> >> Update in v5:
> >> 	!!UNTESTED!!
> >>  - change hidden AP ip to locallink
> >>  - Open hidden AP after more checks
> >>  - Load json File from Gateway if Gateway in Batman in Range
> >>
> >> Update in v6:
> >> 	!!UNTESTED!!
> >>  - fix hidden station v6
> >>  - fix -n to -f if
> >>  - Add function to check for a gateway and use this
> >>  - remove /etc/community.cfg and variables
> >>  - send fewer infos to keyxchangev2
> >>  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit  on
> > the
> >> wgets
> >>  - change the position from json_load and do this only 1 times
> >>
> >> Update in v7:
> >> 	!!UNTESTED!!
> >>  - delete keyxchangev2data at start of the script
> >>  - do only things with keyxchangev2data if available
> >>  - change keyxchangev2 url
> >>
> >> Update in v8/v9:
> >>  - rebase onto 20170918-beta
> >>
> >> Update in v10:
> >>  - Minor code fixes
> >>  - Added fff-hoods to fff-base Makefile
> >>  - Removed trailing whitespaces and harmonized tabs
> >>  - Fixed some comments spelling
> >>  - Added mac for hostname rewrite
> >>  - Removed redundant check for /tmp/keyxchangev2data
> >> ---
> >>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
> >>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
> >>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
> >>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
> >> +++++++++++++++++++++
> >>  src/packages/fff/fff/Makefile                      |   3 +-
> >>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
> >> src/packages/fff/fff-hoods/Makefile
> >>  create mode 100644 src/packages/fff/fff-
> >> hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >>  create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
> >> hoods
> >>  create mode 100755 src/packages/fff/fff-
> >> hoods/files/usr/sbin/configurehood
> >>
> >> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-
> >> hoods/Makefile
> >> new file mode 100644
> >> index 0000000..f85178d
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/Makefile
> >> @@ -0,0 +1,39 @@
> >> +include $(TOPDIR)/rules.mk
> >> +
> >> +PKG_NAME:=fff-hoods
> >> +PKG_VERSION:=0.0.1
> >> +PKG_RELEASE:=1
> >> +
> >> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
> >> +
> >> +include $(INCLUDE_DIR)/package.mk
> >> +
> >> +define Package/fff-hoods
> >> +    SECTION:=base
> >> +    CATEGORY:=Freifunk
> >> +    TITLE:= Freifunk-Franken hoods
> >> +    URL:=http://www.freifunk-franken.de
> >> +    DEPENDS:=+fff-network
> >> +endef
> >> +
> >> +define Package/fff-hoods/description
> >> +    This package load and configures the current hood endef
> >> +
> >> +define Build/Prepare
> >> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
> >> +
> >> +define Build/Configure
> >> +	# nothing
> >> +endef
> >> +
> >> +define Build/Compile
> >> +	# nothing
> >> +endef
> >> +
> >> +define Package/fff-hoods/install
> >> +	$(CP) ./files/* $(1)/
> >> +endef
> >> +
> >> +$(eval $(call BuildPackage,fff-hoods))
> >> diff --git
> > a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >> new file mode 100644
> >> index 0000000..49f53e3
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >> @@ -0,0 +1,5 @@
> >> +#!/bin/sh
> >> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
> >> +       sleep 3
> >> +       /usr/sbin/configurehood
> >> +}
> >> diff --git a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> >> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> >> new file mode 100644
> >> index 0000000..ca8d798
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> >> @@ -0,0 +1 @@
> >> +*/5 * * * * /usr/sbin/configurehood
> >> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> >> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> >> new file mode 100755
> >> index 0000000..ad316f8
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> >> @@ -0,0 +1,206 @@
> >> +#!/bin/sh
> >> +
> >> +. /usr/share/libubox/jshn.sh
> >> +. /lib/functions/fff/wireless
> >> +
> >> +rm /tmp/keyxchangev2data
> >> +
> >> +# Gatewaycheck function
> >> +isGatewayAvailable() {
> >> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
> >> +		return true;
> >> +	else
> >> +		return false;
> >> +	fi
> >> +}
> >> +
> >> +
> >> +# Hidden AP check
> >> +
> >> +if [ -f /tmp/hiddenapflag ]; then
> >> +	if [ isGatewayAvailable ]; then
> >> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
> >> "configap" "configap" "1"; then
> >> +			echo "Can't add AP interface on $radio."
> >> +			exit 1
> >> +		else
> >> +			# We must set a fixed ip address here
> >> +			uci set network.configap=interface
> >> +			uci set network.configap.proto='static'
> >> +			uci set network.configap.ip6addr='fe80::1/64'
> >> +			uci commit network
> >> +		fi
> >> +	else
> >> +		rm /tmp/hiddenapflag
> >> +	fi
> >> +fi
> > Warum steht dieser ganze Block am Anfang und nicht am Schluss des Skripts?
> > Hat das einen Grund, dass der immer einen Zyklus warten soll?
> genau, Batman hat ein Timeout das wollen wir damit abfangen damit erst
> im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss also 5min
> eine Verbindung zum GW bestehen.
> >
> >
> >
> >> +
> >> +
> >> +lat=$(uci get system.@system[0].latitude) long=$(uci get
> >> +system.@system[0].longitude) hostname=$(cat
> >> /proc/sys/kernel/hostname)
> >> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
> > Hier hab ich die Mac ergänzt.
> das war einfach nur C&P
> >
> >> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = "OpenWrt" ]
> >> && hostname=""
> >> +[ "$hostname" = "" ] &&  hostname="$mac"
> > Wozu ist das gut? Sollte man das auf LEDE ändern?
> hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht unsicher
> wofür es nötig ist.

Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.

Ja, das sollte man ändern. :) Good Catch!

> >
> >> +
> >> +test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken
> >> keyserver
> >> +test_ipv4_host2="8.8.8.8"        # Google DNS
> >> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
> >> +
> >> +# if we have Internet, we download the Hoodfile from the keyxchangev2
> >> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
> >> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
> >> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
> >> +	wget -T15 -t5 "http://keyserver.freifunk-
> >> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
> >> +	#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
> >> +	# Only do that, when we have no gateway in range. If the
> >> Uplinkrouter changed the hood, we lost the GW and do this automatically
> >> again, I think! Nice idea?
> >> +	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
> >> +		if ! wifiDelAll; then
> >> +			echo "Can't delete current wifi setup"
> >> +			exit 1
> >> +		fi
> >> +		#now we look for phy and add this
> >> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> >> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> >> +				echo "$phy is 2.4 GHz"
> >> +				radio=$(wifiAddPhy "$phy"
> >> "$BATMAN_CHANNEL")
> >> +				if [ -z "$radio" ]; then
> >> +					echo "Can't create radio for $phy"
> >> +					exit 1
> >> +				fi
> >> +			fi
> >> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> >> +				echo "$phy is 5 GHz"
> >> +				radio=$(wifiAddPhy "$phy"
> >> "$BATMAN_CHANNEL_5GHZ")
> >> +				if [ -z "$radio" ]; then
> >> +					echo "Can't create radio for $phy"
> >> +					exit 1
> >> +				fi
> >> +			fi
> > Hier werden Variablen aus der community.cfg verwendet ($BATMAN...), unten
> > ist hardgecodet. Das hier auch hardcoden?
> macht vermutlich Sinn, weil wir die /etc/community.cfg eh abschaffen wollen.

Richtig. Die Daten kommen ja (später mal) aus dem json hood file. Bis
dahin sind sie halt hart kodiert. Um einen Übergang leichter zu machen
könnte man überlegen, on man die Werte vielleicht einer Konstangen
zuweist und diesen dann entsprechend verwendet. Das hätte den Vorteil,
dass die Umstellung dann später einfacher wird.

> >
> >
> >> +			#and here we add the station
> >> +			if ! wifiAddSta "$radio"
> > "config.franken.freifunk.net"
> >> "configSta"; then
> >> +				echo "Can't add Sta interface on $radio."
> >> +				exit 1
> >> +			fi
> >> +
> >> +		done
> >> +
> >> +		wifi
> >> +		# 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
> >> +	else
> >> +		echo "We have a Gateway in Range, we load the
> >> keyxchangev2data from fe80::1"
> >> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
> >> -O /tmp/keyxchangev2data
> >> +	fi
> >> +
> >> +fi
> >> +
> >> +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!
> >> +
> >> +	json_load "$(cat /tmp/keyxchangev2data)"
> >> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
> >> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
> >> | cut -f1 -d " ")
> >> +	if [ "$sumnew" != "$sumold" ]; then
> > Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht irgendwie keinen
> > Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon geprüft haben?!
> das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich mal
> zurück.
> >
> >
> >> +		echo "New file detect, we reconfigure the Node";
> >> +
> >> +		# copy the file to webroot so that other Meshrouter can
> >> download it
> >> +		cp /tmp/keyxchangev2data /www/public/
> >> +
> >> +		json_select hood
> >> +
> >> +		json_get_var hood name
> >> +		json_get_var mesh_bssid mesh_bssid
> >> +		json_get_var mesh_essid mesh_essid
> >> +		json_get_var essid essid
> >> +		# i think the next things we don't active this in the first
> >> version! we can do it later
> >> +		#json_get_var channel2 channel2
> >> +		#json_get_var mode2 mode2
> >> +		#json_get_var type2 type2
> >> +		#json_get_var channel5 channel5
> >> +		#json_get_var mode5 mode5
> >> +		#json_get_var type5 type5
> >> +		#json_get_var protocol protocol
> >> +
> >> +		echo "Setting hood name: $hood"
> >> +		uci set "system.@system[0].hood=$hood"
> >> +
> >> +		if ! wifiDelAll; then
> >> +			echo "Can't delete current wifi setup"
> >> +			exit 1
> >> +		fi
> >> +
> >> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> >> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> >> +				echo "$phy is 2.4 GHz"
> >> +				radio=$(wifiAddPhy "$phy" "1")
> > Hier ist jetzt hardgecodet ... "1"
> interessant, vermutlich hab ich es oben einfach vergessen und wollt es
> wirklich überall hard coden weil eben /etc/community.cfg weg fällt.
> >
> >
> >> +				if [ -z "$radio" ]; then
> >> +					echo "Can't create radio for $phy"
> >> +					exit 1
> >> +				fi
> >> +			fi
> >> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> >> +				echo "$phy is 5 GHz"
> >> +				radio=$(wifiAddPhy "$phy" "13")
> >> +				if [ -z "$radio" ]; then
> >> +					echo "Can't create radio for $phy"
> >> +					exit 1
> >> +				fi
> >> +			fi
> >> +
> >> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
> > then
> >> +				echo "Can't add AP interface on $radio."
> >> +				exit 1
> >> +			fi
> >> +
> >> +			# here we set a bit for add hidden AP
> >> +			touch /tmp/hiddenapflag
> >> +
> >> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
> >> "$mesh_bssid"; then
> >> +				echo "Can't add AP interface on $radio."
> >> +				exit 1
> >> +			fi
> >> +		done
> >> +
> >> +		echo "Loading wifi"
> >> +		wifi
> >> +
> >> +	else
> >> +		echo "We have no new file or we haven't got a file. We do
> >> nothing. We try it again in 5 minutes...";
> > Meines Erachtens ist hier nur "We have no new file" erfüllt. Der andere Fall
> > wäre eine if weiter außen. Siehe [ ! -f /tmp/keyxchangev2data] ...
> muss ich mir auch mal in Ruhe angucken...
> >
> >
> >> +	fi
> >> +
> >> +	# and now we read the VPN Data and give this data to fff-vpn
> >> +	json_load "$(cat /tmp/keyxchangev2data)"
> >> +
> >> +	json_select vpn
> >> +	Index="1"
> >> +	rm /tmp/fastd_fff_output
> >> +	touch /tmp/fastd_fff_output
> >> +	while json_select $Index > /dev/null
> > Wieso while wenn nur ein Element "1"?
> es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit einer
> Schleife durchgehen oder?
> >
> >
> >> +	do
> >> +		json_get_var protocol protocol
> >> +		if [ "$protocol" == "fastd" ]; then
> >> +			json_get_var servername name
> >> +			echo "####${servername}.conf" >>
> >> /tmp/fastd_fff_output
> >> +			echo "#name \"${servername}\";" >>
> >> /tmp/fastd_fff_output
> >> +			json_get_var key key
> >> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
> >> +			json_get_var address address
> >> +			json_get_var port port
> >> +			echo "remote ipv4 \"${address}\" port $port float;"
> >>>> /tmp/fastd_fff_output
> >> +		fi
> >> +		echo "" >> /tmp/fastd_fff_output
> >> +		echo "###" >> /tmp/fastd_fff_output
> > Die beiden kommen ja nur einmal am Schluss, also müssen sie aus dem while
> > raus, oder?
> oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab ich das
> ganze noch nicht getestet, RedDog wollte das aber eh relativ zügig
> umbauen weil das Format einfach sh*t ist, besser ist wenn fff-vpn die
> json direkt ausliest.

Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder
tunneldigger genommen wird auch nicht an einer per http download'baren
Datei festmachen, sondern hier nach dem json file entsprechend machen.

Tim


> mfg
> 
> Christian
> >
> > Grüße
> >
> > Adrian
> >
> >
> >> +	done
> >> +	#this we do every 5 minutes, because it can change the VPN Protocol
> >> +	#and now we get to vpn-select Script and load VPNs
> >> +	sh /usr/sbin/vpn-select
> >> +fi
> >> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
> >> index 166d423..305ab8d 100644
> >> --- a/src/packages/fff/fff/Makefile
> >> +++ b/src/packages/fff/fff/Makefile
> >> @@ -29,7 +29,8 @@ define Package/fff-base
> >>               +fff-wireless \
> >>               +fff-timeserver \
> >>               +fff-vpn-select \
> >> -             +simple-tc
> >> +             +simple-tc \
> >> +             +fff-hoods
> >>  endef
> >>
> >>  define Package/fff-base/description
> >> --
> >> 2.7.4
> >>
> >> --
> >> franken-dev mailing list
> >> franken-dev@freifunk.net
> >> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
> 
> 
> -- 
> franken-dev mailing list
> franken-dev@freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Mister Crumble Oct. 2, 2017, 2:33 p.m.
hallo, sehe ich das richtig und ihr habt gerade dafür gesorgt, das neue
router nicht immer nur stumpd openwrt/lede heissen?

wenn ja, DANKE! dann brauche ich mir nicht mehr überlegen wie das geht ;-)

2017-10-02 16:19 GMT+02:00 Tim Niemeyer <tim@tn-x.org>:

> Hi
>
>
> Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
> > hi
> >
> > hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert daher bin
> > ich die Mail mal eben überflogen und paar Kommentare Inline.
> >
> > On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
> > > Hallo,
> > >
> > > eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen
> aufgefallen
> > > sind.
> > >
> > >> -----Original Message-----
> > >> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> > >> Of Adrian Schmutzler
> > >> Sent: Sonntag, 1. Oktober 2017 15:49
> > >> To: franken-dev@freifunk.net
> > >> Cc: Jan Kraus <mayosemmel@gmail.com>
> > >> Subject: [PATCH v10 4/4] Add fff-hoods
> > >>
> > >> From: Christian Dresel <fff@chrisi01.de>
> > >>
> > >> this packages connect to keyxchangev2
> > >> after review we must change the serveradress! This is only a example
> > >>
> > >> Signed-off-by: Christian Dresel <fff@chrisi01.de>
> > >> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
> > >> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > >>
> > >> Update in v2:
> > >>  - clean tabstops
> > >>  - move the json vpn out of the if because we need this after reboot
> > >>
> > >> Update in v5:
> > >>    !!UNTESTED!!
> > >>  - change hidden AP ip to locallink
> > >>  - Open hidden AP after more checks
> > >>  - Load json File from Gateway if Gateway in Batman in Range
> > >>
> > >> Update in v6:
> > >>    !!UNTESTED!!
> > >>  - fix hidden station v6
> > >>  - fix -n to -f if
> > >>  - Add function to check for a gateway and use this
> > >>  - remove /etc/community.cfg and variables
> > >>  - send fewer infos to keyxchangev2
> > >>  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit
> on
> > > the
> > >> wgets
> > >>  - change the position from json_load and do this only 1 times
> > >>
> > >> Update in v7:
> > >>    !!UNTESTED!!
> > >>  - delete keyxchangev2data at start of the script
> > >>  - do only things with keyxchangev2data if available
> > >>  - change keyxchangev2 url
> > >>
> > >> Update in v8/v9:
> > >>  - rebase onto 20170918-beta
> > >>
> > >> Update in v10:
> > >>  - Minor code fixes
> > >>  - Added fff-hoods to fff-base Makefile
> > >>  - Removed trailing whitespaces and harmonized tabs
> > >>  - Fixed some comments spelling
> > >>  - Added mac for hostname rewrite
> > >>  - Removed redundant check for /tmp/keyxchangev2data
> > >> ---
> > >>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
> > >>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
> > >>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
> > >>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
> > >> +++++++++++++++++++++
> > >>  src/packages/fff/fff/Makefile                      |   3 +-
> > >>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
> > >> src/packages/fff/fff-hoods/Makefile
> > >>  create mode 100644 src/packages/fff/fff-
> > >> hoods/files/etc/hotplug.d/iface/50-fff-hoods
> > >>  create mode 100644 src/packages/fff/fff-hoods/
> files/usr/lib/micron.d/fff-
> > >> hoods
> > >>  create mode 100755 src/packages/fff/fff-
> > >> hoods/files/usr/sbin/configurehood
> > >>
> > >> diff --git a/src/packages/fff/fff-hoods/Makefile
> b/src/packages/fff/fff-
> > >> hoods/Makefile
> > >> new file mode 100644
> > >> index 0000000..f85178d
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/Makefile
> > >> @@ -0,0 +1,39 @@
> > >> +include $(TOPDIR)/rules.mk
> > >> +
> > >> +PKG_NAME:=fff-hoods
> > >> +PKG_VERSION:=0.0.1
> > >> +PKG_RELEASE:=1
> > >> +
> > >> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
> > >> +
> > >> +include $(INCLUDE_DIR)/package.mk
> > >> +
> > >> +define Package/fff-hoods
> > >> +    SECTION:=base
> > >> +    CATEGORY:=Freifunk
> > >> +    TITLE:= Freifunk-Franken hoods
> > >> +    URL:=http://www.freifunk-franken.de
> > >> +    DEPENDS:=+fff-network
> > >> +endef
> > >> +
> > >> +define Package/fff-hoods/description
> > >> +    This package load and configures the current hood endef
> > >> +
> > >> +define Build/Prepare
> > >> +  echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
> > >> +
> > >> +define Build/Configure
> > >> +  # nothing
> > >> +endef
> > >> +
> > >> +define Build/Compile
> > >> +  # nothing
> > >> +endef
> > >> +
> > >> +define Package/fff-hoods/install
> > >> +  $(CP) ./files/* $(1)/
> > >> +endef
> > >> +
> > >> +$(eval $(call BuildPackage,fff-hoods))
> > >> diff --git
> > > a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> > >> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> > >> new file mode 100644
> > >> index 0000000..49f53e3
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-
> fff-hoods
> > >> @@ -0,0 +1,5 @@
> > >> +#!/bin/sh
> > >> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
> > >> +       sleep 3
> > >> +       /usr/sbin/configurehood
> > >> +}
> > >> diff --git a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
> hoods
> > >> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > >> new file mode 100644
> > >> index 0000000..ca8d798
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > >> @@ -0,0 +1 @@
> > >> +*/5 * * * * /usr/sbin/configurehood
> > >> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > >> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > >> new file mode 100755
> > >> index 0000000..ad316f8
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > >> @@ -0,0 +1,206 @@
> > >> +#!/bin/sh
> > >> +
> > >> +. /usr/share/libubox/jshn.sh
> > >> +. /lib/functions/fff/wireless
> > >> +
> > >> +rm /tmp/keyxchangev2data
> > >> +
> > >> +# Gatewaycheck function
> > >> +isGatewayAvailable() {
> > >> +  if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
> > >> +          return true;
> > >> +  else
> > >> +          return false;
> > >> +  fi
> > >> +}
> > >> +
> > >> +
> > >> +# Hidden AP check
> > >> +
> > >> +if [ -f /tmp/hiddenapflag ]; then
> > >> +  if [ isGatewayAvailable ]; then
> > >> +          if ! wifiAddAP "$radio" "config.franken.freifunk.net"
> > >> "configap" "configap" "1"; then
> > >> +                  echo "Can't add AP interface on $radio."
> > >> +                  exit 1
> > >> +          else
> > >> +                  # We must set a fixed ip address here
> > >> +                  uci set network.configap=interface
> > >> +                  uci set network.configap.proto='static'
> > >> +                  uci set network.configap.ip6addr='fe80::1/64'
> > >> +                  uci commit network
> > >> +          fi
> > >> +  else
> > >> +          rm /tmp/hiddenapflag
> > >> +  fi
> > >> +fi
> > > Warum steht dieser ganze Block am Anfang und nicht am Schluss des
> Skripts?
> > > Hat das einen Grund, dass der immer einen Zyklus warten soll?
> > genau, Batman hat ein Timeout das wollen wir damit abfangen damit erst
> > im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss also 5min
> > eine Verbindung zum GW bestehen.
> > >
> > >
> > >
> > >> +
> > >> +
> > >> +lat=$(uci get system.@system[0].latitude) long=$(uci get
> > >> +system.@system[0].longitude) hostname=$(cat
> > >> /proc/sys/kernel/hostname)
> > >> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
> > > Hier hab ich die Mac ergänzt.
> > das war einfach nur C&P
> > >
> > >> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" =
> "OpenWrt" ]
> > >> && hostname=""
> > >> +[ "$hostname" = "" ] &&  hostname="$mac"
> > > Wozu ist das gut? Sollte man das auf LEDE ändern?
> > hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht unsicher
> > wofür es nötig ist.
>
> Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.
>
> Ja, das sollte man ändern. :) Good Catch!
>
> > >
> > >> +
> > >> +test_ipv4_host1="keyserver.freifunk-franken.de" # Freifunk-Franken
> > >> keyserver
> > >> +test_ipv4_host2="8.8.8.8"        # Google DNS
> > >> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
> > >> +
> > >> +# if we have Internet, we download the Hoodfile from the keyxchangev2
> > >> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
> > >> +  ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
> > >> +  ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
> > >> +  wget -T15 -t5 "http://keyserver.freifunk-
> > >> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
> > >> +  #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
> > >> +  # Only do that, when we have no gateway in range. If the
> > >> Uplinkrouter changed the hood, we lost the GW and do this
> automatically
> > >> again, I think! Nice idea?
> > >> +  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
> > >> +          if ! wifiDelAll; then
> > >> +                  echo "Can't delete current wifi setup"
> > >> +                  exit 1
> > >> +          fi
> > >> +          #now we look for phy and add this
> > >> +          for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> > >> +                  if iw phy "$phy" info | grep -q -m1 "2... MHz";
> then
> > >> +                          echo "$phy is 2.4 GHz"
> > >> +                          radio=$(wifiAddPhy "$phy"
> > >> "$BATMAN_CHANNEL")
> > >> +                          if [ -z "$radio" ]; then
> > >> +                                  echo "Can't create radio for $phy"
> > >> +                                  exit 1
> > >> +                          fi
> > >> +                  fi
> > >> +                  if iw phy "$phy" info | grep -q -m1 "5... MHz";
> then
> > >> +                          echo "$phy is 5 GHz"
> > >> +                          radio=$(wifiAddPhy "$phy"
> > >> "$BATMAN_CHANNEL_5GHZ")
> > >> +                          if [ -z "$radio" ]; then
> > >> +                                  echo "Can't create radio for $phy"
> > >> +                                  exit 1
> > >> +                          fi
> > >> +                  fi
> > > Hier werden Variablen aus der community.cfg verwendet ($BATMAN...),
> unten
> > > ist hardgecodet. Das hier auch hardcoden?
> > macht vermutlich Sinn, weil wir die /etc/community.cfg eh abschaffen
> wollen.
>
> Richtig. Die Daten kommen ja (später mal) aus dem json hood file. Bis
> dahin sind sie halt hart kodiert. Um einen Übergang leichter zu machen
> könnte man überlegen, on man die Werte vielleicht einer Konstangen
> zuweist und diesen dann entsprechend verwendet. Das hätte den Vorteil,
> dass die Umstellung dann später einfacher wird.
>
> > >
> > >
> > >> +                  #and here we add the station
> > >> +                  if ! wifiAddSta "$radio"
> > > "config.franken.freifunk.net"
> > >> "configSta"; then
> > >> +                          echo "Can't add Sta interface on $radio."
> > >> +                          exit 1
> > >> +                  fi
> > >> +
> > >> +          done
> > >> +
> > >> +          wifi
> > >> +          # 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
> > >> +  else
> > >> +          echo "We have a Gateway in Range, we load the
> > >> keyxchangev2data from fe80::1"
> > >> +          wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
> > >> -O /tmp/keyxchangev2data
> > >> +  fi
> > >> +
> > >> +fi
> > >> +
> > >> +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!
> > >> +
> > >> +  json_load "$(cat /tmp/keyxchangev2data)"
> > >> +  sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
> > >> +  sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
> > >> | cut -f1 -d " ")
> > >> +  if [ "$sumnew" != "$sumold" ]; then
> > > Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht irgendwie
> keinen
> > > Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon geprüft haben?!
> > das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich mal
> > zurück.
> > >
> > >
> > >> +          echo "New file detect, we reconfigure the Node";
> > >> +
> > >> +          # copy the file to webroot so that other Meshrouter can
> > >> download it
> > >> +          cp /tmp/keyxchangev2data /www/public/
> > >> +
> > >> +          json_select hood
> > >> +
> > >> +          json_get_var hood name
> > >> +          json_get_var mesh_bssid mesh_bssid
> > >> +          json_get_var mesh_essid mesh_essid
> > >> +          json_get_var essid essid
> > >> +          # i think the next things we don't active this in the first
> > >> version! we can do it later
> > >> +          #json_get_var channel2 channel2
> > >> +          #json_get_var mode2 mode2
> > >> +          #json_get_var type2 type2
> > >> +          #json_get_var channel5 channel5
> > >> +          #json_get_var mode5 mode5
> > >> +          #json_get_var type5 type5
> > >> +          #json_get_var protocol protocol
> > >> +
> > >> +          echo "Setting hood name: $hood"
> > >> +          uci set "system.@system[0].hood=$hood"
> > >> +
> > >> +          if ! wifiDelAll; then
> > >> +                  echo "Can't delete current wifi setup"
> > >> +                  exit 1
> > >> +          fi
> > >> +
> > >> +          for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> > >> +                  if iw phy "$phy" info | grep -q -m1 "2... MHz";
> then
> > >> +                          echo "$phy is 2.4 GHz"
> > >> +                          radio=$(wifiAddPhy "$phy" "1")
> > > Hier ist jetzt hardgecodet ... "1"
> > interessant, vermutlich hab ich es oben einfach vergessen und wollt es
> > wirklich überall hard coden weil eben /etc/community.cfg weg fällt.
> > >
> > >
> > >> +                          if [ -z "$radio" ]; then
> > >> +                                  echo "Can't create radio for $phy"
> > >> +                                  exit 1
> > >> +                          fi
> > >> +                  fi
> > >> +                  if iw phy "$phy" info | grep -q -m1 "5... MHz";
> then
> > >> +                          echo "$phy is 5 GHz"
> > >> +                          radio=$(wifiAddPhy "$phy" "13")
> > >> +                          if [ -z "$radio" ]; then
> > >> +                                  echo "Can't create radio for $phy"
> > >> +                                  exit 1
> > >> +                          fi
> > >> +                  fi
> > >> +
> > >> +                  if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
> > > then
> > >> +                          echo "Can't add AP interface on $radio."
> > >> +                          exit 1
> > >> +                  fi
> > >> +
> > >> +                  # here we set a bit for add hidden AP
> > >> +                  touch /tmp/hiddenapflag
> > >> +
> > >> +                  if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
> > >> "$mesh_bssid"; then
> > >> +                          echo "Can't add AP interface on $radio."
> > >> +                          exit 1
> > >> +                  fi
> > >> +          done
> > >> +
> > >> +          echo "Loading wifi"
> > >> +          wifi
> > >> +
> > >> +  else
> > >> +          echo "We have no new file or we haven't got a file. We do
> > >> nothing. We try it again in 5 minutes...";
> > > Meines Erachtens ist hier nur "We have no new file" erfüllt. Der
> andere Fall
> > > wäre eine if weiter außen. Siehe [ ! -f /tmp/keyxchangev2data] ...
> > muss ich mir auch mal in Ruhe angucken...
> > >
> > >
> > >> +  fi
> > >> +
> > >> +  # and now we read the VPN Data and give this data to fff-vpn
> > >> +  json_load "$(cat /tmp/keyxchangev2data)"
> > >> +
> > >> +  json_select vpn
> > >> +  Index="1"
> > >> +  rm /tmp/fastd_fff_output
> > >> +  touch /tmp/fastd_fff_output
> > >> +  while json_select $Index > /dev/null
> > > Wieso while wenn nur ein Element "1"?
> > es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit einer
> > Schleife durchgehen oder?
> > >
> > >
> > >> +  do
> > >> +          json_get_var protocol protocol
> > >> +          if [ "$protocol" == "fastd" ]; then
> > >> +                  json_get_var servername name
> > >> +                  echo "####${servername}.conf" >>
> > >> /tmp/fastd_fff_output
> > >> +                  echo "#name \"${servername}\";" >>
> > >> /tmp/fastd_fff_output
> > >> +                  json_get_var key key
> > >> +                  echo "key \"${key}\";" >> /tmp/fastd_fff_output
> > >> +                  json_get_var address address
> > >> +                  json_get_var port port
> > >> +                  echo "remote ipv4 \"${address}\" port $port float;"
> > >>>> /tmp/fastd_fff_output
> > >> +          fi
> > >> +          echo "" >> /tmp/fastd_fff_output
> > >> +          echo "###" >> /tmp/fastd_fff_output
> > > Die beiden kommen ja nur einmal am Schluss, also müssen sie aus dem
> while
> > > raus, oder?
> > oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab ich das
> > ganze noch nicht getestet, RedDog wollte das aber eh relativ zügig
> > umbauen weil das Format einfach sh*t ist, besser ist wenn fff-vpn die
> > json direkt ausliest.
>
> Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder
> tunneldigger genommen wird auch nicht an einer per http download'baren
> Datei festmachen, sondern hier nach dem json file entsprechend machen.
>
> Tim
>
>
> > mfg
> >
> > Christian
> > >
> > > Grüße
> > >
> > > Adrian
> > >
> > >
> > >> +  done
> > >> +  #this we do every 5 minutes, because it can change the VPN Protocol
> > >> +  #and now we get to vpn-select Script and load VPNs
> > >> +  sh /usr/sbin/vpn-select
> > >> +fi
> > >> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/
> Makefile
> > >> index 166d423..305ab8d 100644
> > >> --- a/src/packages/fff/fff/Makefile
> > >> +++ b/src/packages/fff/fff/Makefile
> > >> @@ -29,7 +29,8 @@ define Package/fff-base
> > >>               +fff-wireless \
> > >>               +fff-timeserver \
> > >>               +fff-vpn-select \
> > >> -             +simple-tc
> > >> +             +simple-tc \
> > >> +             +fff-hoods
> > >>  endef
> > >>
> > >>  define Package/fff-base/description
> > >> --
> > >> 2.7.4
> > >>
> > >> --
> > >> franken-dev mailing list
> > >> franken-dev@freifunk.net
> > >> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
> >
> >
> > --
> > franken-dev mailing list
> > franken-dev@freifunk.net
> > http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>
>
> --
> franken-dev mailing list
> franken-dev@freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>
>
Adrian Schmutzler Oct. 2, 2017, 2:39 p.m.
Ja und nein.

 

Ich habe gerade festgestellt, das $hostname nie ausgewertet wird ….

 

Aber man kann sowas ja in den nodewatcher reinschreiben (werde ich mal prüfen), dann hätte das den gewünschten Effekt!

 

Grüße

 

Adrian

 

From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf Of Mister Crumble
Sent: Montag, 2. Oktober 2017 16:34
To: Tim Niemeyer <tim@tn-x.org>; franken-dev <franken-dev@freifunk.net>
Subject: Re: [PATCH v10 4/4] Add fff-hoods

 

hallo, sehe ich das richtig und ihr habt gerade dafür gesorgt, das neue router nicht immer nur stumpd openwrt/lede heissen?

 

wenn ja, DANKE! dann brauche ich mir nicht mehr überlegen wie das geht ;-)

 

2017-10-02 16:19 GMT+02:00 Tim Niemeyer <tim@tn-x.org <mailto:tim@tn-x.org> >:

Hi



Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
> hi
>
> hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert daher bin
> ich die Mail mal eben überflogen und paar Kommentare Inline.
>
> On 01.10.2017 16:05, mail@adrianschmutzler.de <mailto:mail@adrianschmutzler.de>  wrote:
> > Hallo,
> >
> > eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen aufgefallen
> > sind.
> >
> >> -----Original Message-----
> >> From: franken-dev [mailto:franken-dev-bounces@freifunk.net <mailto:franken-dev-bounces@freifunk.net> ] On Behalf
> >> Of Adrian Schmutzler
> >> Sent: Sonntag, 1. Oktober 2017 15:49
> >> To: franken-dev@freifunk.net <mailto:franken-dev@freifunk.net> 
> >> Cc: Jan Kraus <mayosemmel@gmail.com <mailto:mayosemmel@gmail.com> >
> >> Subject: [PATCH v10 4/4] Add fff-hoods
> >>
> >> From: Christian Dresel <fff@chrisi01.de <mailto:fff@chrisi01.de> >
> >>
> >> this packages connect to keyxchangev2
> >> after review we must change the serveradress! This is only a example
> >>
> >> Signed-off-by: Christian Dresel <fff@chrisi01.de <mailto:fff@chrisi01.de> >
> >> Signed-off-by: Jan Kraus <mayosemmel@gmail.com <mailto:mayosemmel@gmail.com> >
> >> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de <mailto:freifunk@adrianschmutzler.de> >
> >>
> >> Update in v2:
> >>  - clean tabstops
> >>  - move the json vpn out of the if because we need this after reboot
> >>
> >> Update in v5:
> >>    !!UNTESTED!!
> >>  - change hidden AP ip to locallink
> >>  - Open hidden AP after more checks
> >>  - Load json File from Gateway if Gateway in Batman in Range
> >>
> >> Update in v6:
> >>    !!UNTESTED!!
> >>  - fix hidden station v6
> >>  - fix -n to -f if
> >>  - Add function to check for a gateway and use this
> >>  - remove /etc/community.cfg and variables
> >>  - send fewer infos to keyxchangev2
> >>  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit  on
> > the
> >> wgets
> >>  - change the position from json_load and do this only 1 times
> >>
> >> Update in v7:
> >>    !!UNTESTED!!
> >>  - delete keyxchangev2data at start of the script
> >>  - do only things with keyxchangev2data if available
> >>  - change keyxchangev2 url
> >>
> >> Update in v8/v9:
> >>  - rebase onto 20170918-beta
> >>
> >> Update in v10:
> >>  - Minor code fixes
> >>  - Added fff-hoods to fff-base Makefile
> >>  - Removed trailing whitespaces and harmonized tabs
> >>  - Fixed some comments spelling
> >>  - Added mac for hostname rewrite
> >>  - Removed redundant check for /tmp/keyxchangev2data
> >> ---
> >>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
> >>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
> >>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
> >>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
> >> +++++++++++++++++++++
> >>  src/packages/fff/fff/Makefile                      |   3 +-
> >>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode 100644
> >> src/packages/fff/fff-hoods/Makefile
> >>  create mode 100644 src/packages/fff/fff-
> >> hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >>  create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
> >> hoods
> >>  create mode 100755 src/packages/fff/fff-
> >> hoods/files/usr/sbin/configurehood
> >>
> >> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-
> >> hoods/Makefile
> >> new file mode 100644
> >> index 0000000..f85178d
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/Makefile
> >> @@ -0,0 +1,39 @@
> >> +include $(TOPDIR)/rules.mk <http://rules.mk> 
> >> +
> >> +PKG_NAME:=fff-hoods
> >> +PKG_VERSION:=0.0.1
> >> +PKG_RELEASE:=1
> >> +
> >> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
> >> +
> >> +include $(INCLUDE_DIR)/package.mk <http://package.mk> 
> >> +
> >> +define Package/fff-hoods
> >> +    SECTION:=base
> >> +    CATEGORY:=Freifunk
> >> +    TITLE:= Freifunk-Franken hoods
> >> +    URL:=http://www.freifunk-franken.de
> >> +    DEPENDS:=+fff-network
> >> +endef
> >> +
> >> +define Package/fff-hoods/description
> >> +    This package load and configures the current hood endef
> >> +
> >> +define Build/Prepare
> >> +  echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
> >> +
> >> +define Build/Configure
> >> +  # nothing
> >> +endef
> >> +
> >> +define Build/Compile
> >> +  # nothing
> >> +endef
> >> +
> >> +define Package/fff-hoods/install
> >> +  $(CP) ./files/* $(1)/
> >> +endef
> >> +
> >> +$(eval $(call BuildPackage,fff-hoods))
> >> diff --git
> > a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >> new file mode 100644
> >> index 0000000..49f53e3
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
> >> @@ -0,0 +1,5 @@
> >> +#!/bin/sh
> >> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
> >> +       sleep 3
> >> +       /usr/sbin/configurehood
> >> +}
> >> diff --git a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> >> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> >> new file mode 100644
> >> index 0000000..ca8d798
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> >> @@ -0,0 +1 @@
> >> +*/5 * * * * /usr/sbin/configurehood
> >> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> >> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> >> new file mode 100755
> >> index 0000000..ad316f8
> >> --- /dev/null
> >> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> >> @@ -0,0 +1,206 @@
> >> +#!/bin/sh
> >> +
> >> +. /usr/share/libubox/jshn.sh
> >> +. /lib/functions/fff/wireless
> >> +
> >> +rm /tmp/keyxchangev2data
> >> +
> >> +# Gatewaycheck function
> >> +isGatewayAvailable() {
> >> +  if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
> >> +          return true;
> >> +  else
> >> +          return false;
> >> +  fi
> >> +}
> >> +
> >> +
> >> +# Hidden AP check
> >> +
> >> +if [ -f /tmp/hiddenapflag ]; then
> >> +  if [ isGatewayAvailable ]; then
> >> +          if ! wifiAddAP "$radio" "config.franken.freifunk.net <http://config.franken.freifunk.net> "
> >> "configap" "configap" "1"; then
> >> +                  echo "Can't add AP interface on $radio."
> >> +                  exit 1
> >> +          else
> >> +                  # We must set a fixed ip address here
> >> +                  uci set network.configap=interface
> >> +                  uci set network.configap.proto='static'
> >> +                  uci set network.configap.ip6addr='fe80::1/64'
> >> +                  uci commit network
> >> +          fi
> >> +  else
> >> +          rm /tmp/hiddenapflag
> >> +  fi
> >> +fi
> > Warum steht dieser ganze Block am Anfang und nicht am Schluss des Skripts?
> > Hat das einen Grund, dass der immer einen Zyklus warten soll?
> genau, Batman hat ein Timeout das wollen wir damit abfangen damit erst
> im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss also 5min
> eine Verbindung zum GW bestehen.
> >
> >
> >
> >> +
> >> +
> >> +lat=$(uci get system.@system[0].latitude <mailto:system.@system[0].latitude> ) long=$(uci get
> >> +system.@system[0].longitude <mailto:+system.@system[0].longitude> ) hostname=$(cat
> >> /proc/sys/kernel/hostname)
> >> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
> > Hier hab ich die Mac ergänzt.
> das war einfach nur C&P
> >
> >> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = "OpenWrt" ]
> >> && hostname=""
> >> +[ "$hostname" = "" ] &&  hostname="$mac"
> > Wozu ist das gut? Sollte man das auf LEDE ändern?
> hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht unsicher
> wofür es nötig ist.

Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.

Ja, das sollte man ändern. :) Good Catch!


> >
> >> +
> >> +test_ipv4_host1="keyserver.freifunk-franken.de <http://keyserver.freifunk-franken.de> " # Freifunk-Franken
> >> keyserver
> >> +test_ipv4_host2="8.8.8.8"        # Google DNS
> >> +test_ipv6_host1="heise.de <http://heise.de> "       # heise Zeitschriftenverlag
> >> +
> >> +# if we have Internet, we download the Hoodfile from the keyxchangev2
> >> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
> >> +  ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
> >> +  ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
> >> +  wget -T15 -t5 "http://keyserver.freifunk-
> >> franken.de/v2/?lat=$lat <http://franken.de/v2/?lat=$lat&long=$long> &long=$long" -O /tmp/keyxchangev2data
> >> +  #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
> >> +  # Only do that, when we have no gateway in range. If the
> >> Uplinkrouter changed the hood, we lost the GW and do this automatically
> >> again, I think! Nice idea?
> >> +  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
> >> +          if ! wifiDelAll; then
> >> +                  echo "Can't delete current wifi setup"
> >> +                  exit 1
> >> +          fi
> >> +          #now we look for phy and add this
> >> +          for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> >> +                  if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> >> +                          echo "$phy is 2.4 GHz"
> >> +                          radio=$(wifiAddPhy "$phy"
> >> "$BATMAN_CHANNEL")
> >> +                          if [ -z "$radio" ]; then
> >> +                                  echo "Can't create radio for $phy"
> >> +                                  exit 1
> >> +                          fi
> >> +                  fi
> >> +                  if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> >> +                          echo "$phy is 5 GHz"
> >> +                          radio=$(wifiAddPhy "$phy"
> >> "$BATMAN_CHANNEL_5GHZ")
> >> +                          if [ -z "$radio" ]; then
> >> +                                  echo "Can't create radio for $phy"
> >> +                                  exit 1
> >> +                          fi
> >> +                  fi
> > Hier werden Variablen aus der community.cfg verwendet ($BATMAN...), unten
> > ist hardgecodet. Das hier auch hardcoden?
> macht vermutlich Sinn, weil wir die /etc/community.cfg eh abschaffen wollen.

Richtig. Die Daten kommen ja (später mal) aus dem json hood file. Bis
dahin sind sie halt hart kodiert. Um einen Übergang leichter zu machen
könnte man überlegen, on man die Werte vielleicht einer Konstangen
zuweist und diesen dann entsprechend verwendet. Das hätte den Vorteil,
dass die Umstellung dann später einfacher wird.


> >
> >
> >> +                  #and here we add the station
> >> +                  if ! wifiAddSta "$radio"
> > "config.franken.freifunk.net <http://config.franken.freifunk.net> "
> >> "configSta"; then
> >> +                          echo "Can't add Sta interface on $radio."
> >> +                          exit 1
> >> +                  fi
> >> +
> >> +          done
> >> +
> >> +          wifi
> >> +          # 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 <http://[fe80::1%25w2sta]/keyxchangev2data> " -O
> >> /tmp/keyxchangev2data
> >> +  else
> >> +          echo "We have a Gateway in Range, we load the
> >> keyxchangev2data from fe80::1"
> >> +          wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data <http://[fe80::1%25br-mesh]/keyxchangev2data> "
> >> -O /tmp/keyxchangev2data
> >> +  fi
> >> +
> >> +fi
> >> +
> >> +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!
> >> +
> >> +  json_load "$(cat /tmp/keyxchangev2data)"
> >> +  sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
> >> +  sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
> >> | cut -f1 -d " ")
> >> +  if [ "$sumnew" != "$sumold" ]; then
> > Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht irgendwie keinen
> > Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon geprüft haben?!
> das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich mal
> zurück.
> >
> >
> >> +          echo "New file detect, we reconfigure the Node";
> >> +
> >> +          # copy the file to webroot so that other Meshrouter can
> >> download it
> >> +          cp /tmp/keyxchangev2data /www/public/
> >> +
> >> +          json_select hood
> >> +
> >> +          json_get_var hood name
> >> +          json_get_var mesh_bssid mesh_bssid
> >> +          json_get_var mesh_essid mesh_essid
> >> +          json_get_var essid essid
> >> +          # i think the next things we don't active this in the first
> >> version! we can do it later
> >> +          #json_get_var channel2 channel2
> >> +          #json_get_var mode2 mode2
> >> +          #json_get_var type2 type2
> >> +          #json_get_var channel5 channel5
> >> +          #json_get_var mode5 mode5
> >> +          #json_get_var type5 type5
> >> +          #json_get_var protocol protocol
> >> +
> >> +          echo "Setting hood name: $hood"
> >> +          uci set "system.@system[0].hood=$hood <mailto:system.@system[0].hood=$hood> "
> >> +
> >> +          if ! wifiDelAll; then
> >> +                  echo "Can't delete current wifi setup"
> >> +                  exit 1
> >> +          fi
> >> +
> >> +          for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> >> +                  if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> >> +                          echo "$phy is 2.4 GHz"
> >> +                          radio=$(wifiAddPhy "$phy" "1")
> > Hier ist jetzt hardgecodet ... "1"
> interessant, vermutlich hab ich es oben einfach vergessen und wollt es
> wirklich überall hard coden weil eben /etc/community.cfg weg fällt.
> >
> >
> >> +                          if [ -z "$radio" ]; then
> >> +                                  echo "Can't create radio for $phy"
> >> +                                  exit 1
> >> +                          fi
> >> +                  fi
> >> +                  if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> >> +                          echo "$phy is 5 GHz"
> >> +                          radio=$(wifiAddPhy "$phy" "13")
> >> +                          if [ -z "$radio" ]; then
> >> +                                  echo "Can't create radio for $phy"
> >> +                                  exit 1
> >> +                          fi
> >> +                  fi
> >> +
> >> +                  if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
> > then
> >> +                          echo "Can't add AP interface on $radio."
> >> +                          exit 1
> >> +                  fi
> >> +
> >> +                  # here we set a bit for add hidden AP
> >> +                  touch /tmp/hiddenapflag
> >> +
> >> +                  if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
> >> "$mesh_bssid"; then
> >> +                          echo "Can't add AP interface on $radio."
> >> +                          exit 1
> >> +                  fi
> >> +          done
> >> +
> >> +          echo "Loading wifi"
> >> +          wifi
> >> +
> >> +  else
> >> +          echo "We have no new file or we haven't got a file. We do
> >> nothing. We try it again in 5 minutes...";
> > Meines Erachtens ist hier nur "We have no new file" erfüllt. Der andere Fall
> > wäre eine if weiter außen. Siehe [ ! -f /tmp/keyxchangev2data] ...
> muss ich mir auch mal in Ruhe angucken...
> >
> >
> >> +  fi
> >> +
> >> +  # and now we read the VPN Data and give this data to fff-vpn
> >> +  json_load "$(cat /tmp/keyxchangev2data)"
> >> +
> >> +  json_select vpn
> >> +  Index="1"
> >> +  rm /tmp/fastd_fff_output
> >> +  touch /tmp/fastd_fff_output
> >> +  while json_select $Index > /dev/null
> > Wieso while wenn nur ein Element "1"?
> es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit einer
> Schleife durchgehen oder?
> >
> >
> >> +  do
> >> +          json_get_var protocol protocol
> >> +          if [ "$protocol" == "fastd" ]; then
> >> +                  json_get_var servername name
> >> +                  echo "####${servername}.conf" >>
> >> /tmp/fastd_fff_output
> >> +                  echo "#name \"${servername}\";" >>
> >> /tmp/fastd_fff_output
> >> +                  json_get_var key key
> >> +                  echo "key \"${key}\";" >> /tmp/fastd_fff_output
> >> +                  json_get_var address address
> >> +                  json_get_var port port
> >> +                  echo "remote ipv4 \"${address}\" port $port float;"
> >>>> /tmp/fastd_fff_output
> >> +          fi
> >> +          echo "" >> /tmp/fastd_fff_output
> >> +          echo "###" >> /tmp/fastd_fff_output
> > Die beiden kommen ja nur einmal am Schluss, also müssen sie aus dem while
> > raus, oder?
> oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab ich das
> ganze noch nicht getestet, RedDog wollte das aber eh relativ zügig
> umbauen weil das Format einfach sh*t ist, besser ist wenn fff-vpn die
> json direkt ausliest.

Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder
tunneldigger genommen wird auch nicht an einer per http download'baren
Datei festmachen, sondern hier nach dem json file entsprechend machen.

Tim



> mfg
>
> Christian
> >
> > Grüße
> >
> > Adrian
> >
> >
> >> +  done
> >> +  #this we do every 5 minutes, because it can change the VPN Protocol
> >> +  #and now we get to vpn-select Script and load VPNs
> >> +  sh /usr/sbin/vpn-select
> >> +fi
> >> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile
> >> index 166d423..305ab8d 100644
> >> --- a/src/packages/fff/fff/Makefile
> >> +++ b/src/packages/fff/fff/Makefile
> >> @@ -29,7 +29,8 @@ define Package/fff-base
> >>               +fff-wireless \
> >>               +fff-timeserver \
> >>               +fff-vpn-select \
> >> -             +simple-tc
> >> +             +simple-tc \
> >> +             +fff-hoods
> >>  endef
> >>
> >>  define Package/fff-base/description
> >> --
> >> 2.7.4
> >>
> >> --
> >> franken-dev mailing list
> >> franken-dev@freifunk.net <mailto:franken-dev@freifunk.net> 
> >> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>
>
> --
> franken-dev mailing list
> franken-dev@freifunk.net <mailto:franken-dev@freifunk.net> 
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net


--
franken-dev mailing list
franken-dev@freifunk.net <mailto:franken-dev@freifunk.net> 
http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Tim Niemeyer Oct. 2, 2017, 2:43 p.m.
Hi

Am Montag, den 02.10.2017, 16:33 +0200 schrieb Mister Crumble:
> hallo, sehe ich das richtig und ihr habt gerade dafür gesorgt, das
> neue router nicht immer nur stumpd openwrt/lede heissen?
> 
> 
> wenn ja, DANKE! dann brauche ich mir nicht mehr überlegen wie das
> geht ;-)

Nein, das ist etwas anderes. Hier geht es nur um den Hostname der an den
KeyXchange gemeldet wird.

Tim

> 
> 2017-10-02 16:19 GMT+02:00 Tim Niemeyer <tim@tn-x.org>:
>         Hi
>         
>         
>         Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian
>         Dresel:
>         > hi
>         >
>         > hab grad recht wenig Zeit aber hier wird grad $Kram
>         diskutiert daher bin
>         > ich die Mail mal eben überflogen und paar Kommentare Inline.
>         >
>         > On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
>         > > Hallo,
>         > >
>         > > eine Fragen und Anmerkungen inline, die mir beim
>         Ändern/Lesen aufgefallen
>         > > sind.
>         > >
>         > >> -----Original Message-----
>         > >> From: franken-dev
>         [mailto:franken-dev-bounces@freifunk.net] On Behalf
>         > >> Of Adrian Schmutzler
>         > >> Sent: Sonntag, 1. Oktober 2017 15:49
>         > >> To: franken-dev@freifunk.net
>         > >> Cc: Jan Kraus <mayosemmel@gmail.com>
>         > >> Subject: [PATCH v10 4/4] Add fff-hoods
>         > >>
>         > >> From: Christian Dresel <fff@chrisi01.de>
>         > >>
>         > >> this packages connect to keyxchangev2
>         > >> after review we must change the serveradress! This is
>         only a example
>         > >>
>         > >> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>         > >> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>         > >> Signed-off-by: Adrian Schmutzler
>         <freifunk@adrianschmutzler.de>
>         > >>
>         > >> Update in v2:
>         > >>  - clean tabstops
>         > >>  - move the json vpn out of the if because we need this
>         after reboot
>         > >>
>         > >> Update in v5:
>         > >>    !!UNTESTED!!
>         > >>  - change hidden AP ip to locallink
>         > >>  - Open hidden AP after more checks
>         > >>  - Load json File from Gateway if Gateway in Batman in
>         Range
>         > >>
>         > >> Update in v6:
>         > >>    !!UNTESTED!!
>         > >>  - fix hidden station v6
>         > >>  - fix -n to -f if
>         > >>  - Add function to check for a gateway and use this
>         > >>  - remove /etc/community.cfg and variables
>         > >>  - send fewer infos to keyxchangev2
>         > >>  - add a check if /tmp/keyxchangev2 not downloadable and
>         edit a bit  on
>         > > the
>         > >> wgets
>         > >>  - change the position from json_load and do this only 1
>         times
>         > >>
>         > >> Update in v7:
>         > >>    !!UNTESTED!!
>         > >>  - delete keyxchangev2data at start of the script
>         > >>  - do only things with keyxchangev2data if available
>         > >>  - change keyxchangev2 url
>         > >>
>         > >> Update in v8/v9:
>         > >>  - rebase onto 20170918-beta
>         > >>
>         > >> Update in v10:
>         > >>  - Minor code fixes
>         > >>  - Added fff-hoods to fff-base Makefile
>         > >>  - Removed trailing whitespaces and harmonized tabs
>         > >>  - Fixed some comments spelling
>         > >>  - Added mac for hostname rewrite
>         > >>  - Removed redundant check for /tmp/keyxchangev2data
>         > >> ---
>         > >>  src/packages/fff/fff-hoods/Makefile                |  39
>         ++++
>         > >>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5
>         +
>         > >>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1
>         +
>         > >>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>         > >> +++++++++++++++++++++
>         > >>  src/packages/fff/fff/Makefile                      |   3
>         +-
>         > >>  5 files changed, 253 insertions(+), 1 deletion(-)
>         create mode 100644
>         > >> src/packages/fff/fff-hoods/Makefile
>         > >>  create mode 100644 src/packages/fff/fff-
>         > >> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>         > >>  create mode 100644
>         src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>         > >> hoods
>         > >>  create mode 100755 src/packages/fff/fff-
>         > >> hoods/files/usr/sbin/configurehood
>         > >>
>         > >> diff --git a/src/packages/fff/fff-hoods/Makefile
>         b/src/packages/fff/fff-
>         > >> hoods/Makefile
>         > >> new file mode 100644
>         > >> index 0000000..f85178d
>         > >> --- /dev/null
>         > >> +++ b/src/packages/fff/fff-hoods/Makefile
>         > >> @@ -0,0 +1,39 @@
>         > >> +include $(TOPDIR)/rules.mk
>         > >> +
>         > >> +PKG_NAME:=fff-hoods
>         > >> +PKG_VERSION:=0.0.1
>         > >> +PKG_RELEASE:=1
>         > >> +
>         > >> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>         > >> +
>         > >> +include $(INCLUDE_DIR)/package.mk
>         > >> +
>         > >> +define Package/fff-hoods
>         > >> +    SECTION:=base
>         > >> +    CATEGORY:=Freifunk
>         > >> +    TITLE:= Freifunk-Franken hoods
>         > >> +    URL:=http://www.freifunk-franken.de
>         > >> +    DEPENDS:=+fff-network
>         > >> +endef
>         > >> +
>         > >> +define Package/fff-hoods/description
>         > >> +    This package load and configures the current hood
>         endef
>         > >> +
>         > >> +define Build/Prepare
>         > >> +  echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>         > >> +
>         > >> +define Build/Configure
>         > >> +  # nothing
>         > >> +endef
>         > >> +
>         > >> +define Build/Compile
>         > >> +  # nothing
>         > >> +endef
>         > >> +
>         > >> +define Package/fff-hoods/install
>         > >> +  $(CP) ./files/* $(1)/
>         > >> +endef
>         > >> +
>         > >> +$(eval $(call BuildPackage,fff-hoods))
>         > >> diff --git
>         > >
>         a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>         > >>
>         b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>         > >> new file mode 100644
>         > >> index 0000000..49f53e3
>         > >> --- /dev/null
>         > >> +++
>         b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoods
>         > >> @@ -0,0 +1,5 @@
>         > >> +#!/bin/sh
>         > >> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>         > >> +       sleep 3
>         > >> +       /usr/sbin/configurehood
>         > >> +}
>         > >> diff --git
>         a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>         > >>
>         b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>         > >> new file mode 100644
>         > >> index 0000000..ca8d798
>         > >> --- /dev/null
>         > >> +++
>         b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>         > >> @@ -0,0 +1 @@
>         > >> +*/5 * * * * /usr/sbin/configurehood
>         > >> diff --git
>         a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>         > >> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>         > >> new file mode 100755
>         > >> index 0000000..ad316f8
>         > >> --- /dev/null
>         > >> +++
>         b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>         > >> @@ -0,0 +1,206 @@
>         > >> +#!/bin/sh
>         > >> +
>         > >> +. /usr/share/libubox/jshn.sh
>         > >> +. /lib/functions/fff/wireless
>         > >> +
>         > >> +rm /tmp/keyxchangev2data
>         > >> +
>         > >> +# Gatewaycheck function
>         > >> +isGatewayAvailable() {
>         > >> +  if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>         > >> +          return true;
>         > >> +  else
>         > >> +          return false;
>         > >> +  fi
>         > >> +}
>         > >> +
>         > >> +
>         > >> +# Hidden AP check
>         > >> +
>         > >> +if [ -f /tmp/hiddenapflag ]; then
>         > >> +  if [ isGatewayAvailable ]; then
>         > >> +          if ! wifiAddAP "$radio"
>         "config.franken.freifunk.net"
>         > >> "configap" "configap" "1"; then
>         > >> +                  echo "Can't add AP interface on
>         $radio."
>         > >> +                  exit 1
>         > >> +          else
>         > >> +                  # We must set a fixed ip address here
>         > >> +                  uci set network.configap=interface
>         > >> +                  uci set
>         network.configap.proto='static'
>         > >> +                  uci set
>         network.configap.ip6addr='fe80::1/64'
>         > >> +                  uci commit network
>         > >> +          fi
>         > >> +  else
>         > >> +          rm /tmp/hiddenapflag
>         > >> +  fi
>         > >> +fi
>         > > Warum steht dieser ganze Block am Anfang und nicht am
>         Schluss des Skripts?
>         > > Hat das einen Grund, dass der immer einen Zyklus warten
>         soll?
>         > genau, Batman hat ein Timeout das wollen wir damit abfangen
>         damit erst
>         > im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss
>         also 5min
>         > eine Verbindung zum GW bestehen.
>         > >
>         > >
>         > >
>         > >> +
>         > >> +
>         > >> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>         > >> +system.@system[0].longitude) hostname=$(cat
>         > >> /proc/sys/kernel/hostname)
>         > >> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print
>         mac }'
>         > > Hier hab ich die Mac ergänzt.
>         > das war einfach nur C&P
>         > >
>         > >> +/sys/class/net/br-mesh/address 2>/dev/null)
>         [ "$hostname" = "OpenWrt" ]
>         > >> && hostname=""
>         > >> +[ "$hostname" = "" ] &&  hostname="$mac"
>         > > Wozu ist das gut? Sollte man das auf LEDE ändern?
>         > hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht
>         unsicher
>         > wofür es nötig ist.
>         
>         
>         Das ist damit nicht alle Knoten am KeyXchange "OpenWRT"
>         heißen.
>         
>         Ja, das sollte man ändern. :) Good Catch!
>         
>         > >
>         > >> +
>         > >> +test_ipv4_host1="keyserver.freifunk-franken.de" #
>         Freifunk-Franken
>         > >> keyserver
>         > >> +test_ipv4_host2="8.8.8.8"        # Google DNS
>         > >> +test_ipv6_host1="heise.de"       # heise
>         Zeitschriftenverlag
>         > >> +
>         > >> +# if we have Internet, we download the Hoodfile from the
>         keyxchangev2
>         > >> +if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>         > >> +  ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>         > >> +  ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>         > >> +  wget -T15 -t5 "http://keyserver.freifunk-
>         > >> franken.de/v2/?lat=$lat&long=$long"
>         -O /tmp/keyxchangev2data
>         > >> +  #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
>         > >> +  # Only do that, when we have no gateway in range. If
>         the
>         > >> Uplinkrouter changed the hood, we lost the GW and do this
>         automatically
>         > >> again, I think! Nice idea?
>         > >> +  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
>         > >> +          if ! wifiDelAll; then
>         > >> +                  echo "Can't delete current wifi setup"
>         > >> +                  exit 1
>         > >> +          fi
>         > >> +          #now we look for phy and add this
>         > >> +          for phy in $(iw phy | awk '/^Wiphy/{ print
>         $2 }'); do
>         > >> +                  if iw phy "$phy" info | grep -q -m1
>         "2... MHz"; then
>         > >> +                          echo "$phy is 2.4 GHz"
>         > >> +                          radio=$(wifiAddPhy "$phy"
>         > >> "$BATMAN_CHANNEL")
>         > >> +                          if [ -z "$radio" ]; then
>         > >> +                                  echo "Can't create
>         radio for $phy"
>         > >> +                                  exit 1
>         > >> +                          fi
>         > >> +                  fi
>         > >> +                  if iw phy "$phy" info | grep -q -m1
>         "5... MHz"; then
>         > >> +                          echo "$phy is 5 GHz"
>         > >> +                          radio=$(wifiAddPhy "$phy"
>         > >> "$BATMAN_CHANNEL_5GHZ")
>         > >> +                          if [ -z "$radio" ]; then
>         > >> +                                  echo "Can't create
>         radio for $phy"
>         > >> +                                  exit 1
>         > >> +                          fi
>         > >> +                  fi
>         > > Hier werden Variablen aus der community.cfg verwendet
>         ($BATMAN...), unten
>         > > ist hardgecodet. Das hier auch hardcoden?
>         > macht vermutlich Sinn, weil wir die /etc/community.cfg eh
>         abschaffen wollen.
>         
>         
>         Richtig. Die Daten kommen ja (später mal) aus dem json hood
>         file. Bis
>         dahin sind sie halt hart kodiert. Um einen Übergang leichter
>         zu machen
>         könnte man überlegen, on man die Werte vielleicht einer
>         Konstangen
>         zuweist und diesen dann entsprechend verwendet. Das hätte den
>         Vorteil,
>         dass die Umstellung dann später einfacher wird.
>         
>         > >
>         > >
>         > >> +                  #and here we add the station
>         > >> +                  if ! wifiAddSta "$radio"
>         > > "config.franken.freifunk.net"
>         > >> "configSta"; then
>         > >> +                          echo "Can't add Sta interface
>         on $radio."
>         > >> +                          exit 1
>         > >> +                  fi
>         > >> +
>         > >> +          done
>         > >> +
>         > >> +          wifi
>         > >> +          # 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
>         > >> +  else
>         > >> +          echo "We have a Gateway in Range, we load the
>         > >> keyxchangev2data from fe80::1"
>         > >> +          wget -T15 -t5 "http://[fe80::1%
>         br-mesh]/keyxchangev2data"
>         > >> -O /tmp/keyxchangev2data
>         > >> +  fi
>         > >> +
>         > >> +fi
>         > >> +
>         > >> +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!
>         > >> +
>         > >> +  json_load "$(cat /tmp/keyxchangev2data)"
>         > >> +  sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d
>         " ")
>         > >> +  sumold=$(sha256sum /www/public/keyxchangev2data
>         &>/dev/null
>         > >> | cut -f1 -d " ")
>         > >> +  if [ "$sumnew" != "$sumold" ]; then
>         > > Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht
>         irgendwie keinen
>         > > Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon
>         geprüft haben?!
>         > das muss ich mir in Ruhe angucken, grad nicht viel Zeit
>         stell ich mal
>         > zurück.
>         > >
>         > >
>         > >> +          echo "New file detect, we reconfigure the
>         Node";
>         > >> +
>         > >> +          # copy the file to webroot so that other
>         Meshrouter can
>         > >> download it
>         > >> +          cp /tmp/keyxchangev2data /www/public/
>         > >> +
>         > >> +          json_select hood
>         > >> +
>         > >> +          json_get_var hood name
>         > >> +          json_get_var mesh_bssid mesh_bssid
>         > >> +          json_get_var mesh_essid mesh_essid
>         > >> +          json_get_var essid essid
>         > >> +          # i think the next things we don't active this
>         in the first
>         > >> version! we can do it later
>         > >> +          #json_get_var channel2 channel2
>         > >> +          #json_get_var mode2 mode2
>         > >> +          #json_get_var type2 type2
>         > >> +          #json_get_var channel5 channel5
>         > >> +          #json_get_var mode5 mode5
>         > >> +          #json_get_var type5 type5
>         > >> +          #json_get_var protocol protocol
>         > >> +
>         > >> +          echo "Setting hood name: $hood"
>         > >> +          uci set "system.@system[0].hood=$hood"
>         > >> +
>         > >> +          if ! wifiDelAll; then
>         > >> +                  echo "Can't delete current wifi setup"
>         > >> +                  exit 1
>         > >> +          fi
>         > >> +
>         > >> +          for phy in $(iw phy | awk '/^Wiphy/{ print
>         $2 }'); do
>         > >> +                  if iw phy "$phy" info | grep -q -m1
>         "2... MHz"; then
>         > >> +                          echo "$phy is 2.4 GHz"
>         > >> +                          radio=$(wifiAddPhy "$phy" "1")
>         > > Hier ist jetzt hardgecodet ... "1"
>         > interessant, vermutlich hab ich es oben einfach vergessen
>         und wollt es
>         > wirklich überall hard coden weil eben /etc/community.cfg weg
>         fällt.
>         > >
>         > >
>         > >> +                          if [ -z "$radio" ]; then
>         > >> +                                  echo "Can't create
>         radio for $phy"
>         > >> +                                  exit 1
>         > >> +                          fi
>         > >> +                  fi
>         > >> +                  if iw phy "$phy" info | grep -q -m1
>         "5... MHz"; then
>         > >> +                          echo "$phy is 5 GHz"
>         > >> +                          radio=$(wifiAddPhy "$phy"
>         "13")
>         > >> +                          if [ -z "$radio" ]; then
>         > >> +                                  echo "Can't create
>         radio for $phy"
>         > >> +                                  exit 1
>         > >> +                          fi
>         > >> +                  fi
>         > >> +
>         > >> +                  if ! wifiAddAP "$radio" "$essid"
>         "mesh" "ap" "0";
>         > > then
>         > >> +                          echo "Can't add AP interface
>         on $radio."
>         > >> +                          exit 1
>         > >> +                  fi
>         > >> +
>         > >> +                  # here we set a bit for add hidden AP
>         > >> +                  touch /tmp/hiddenapflag
>         > >> +
>         > >> +                  if ! wifiAddAdHocMesh "$radio"
>         "$mesh_essid"
>         > >> "$mesh_bssid"; then
>         > >> +                          echo "Can't add AP interface
>         on $radio."
>         > >> +                          exit 1
>         > >> +                  fi
>         > >> +          done
>         > >> +
>         > >> +          echo "Loading wifi"
>         > >> +          wifi
>         > >> +
>         > >> +  else
>         > >> +          echo "We have no new file or we haven't got a
>         file. We do
>         > >> nothing. We try it again in 5 minutes...";
>         > > Meines Erachtens ist hier nur "We have no new file"
>         erfüllt. Der andere Fall
>         > > wäre eine if weiter außen. Siehe [ !
>         -f /tmp/keyxchangev2data] ...
>         > muss ich mir auch mal in Ruhe angucken...
>         > >
>         > >
>         > >> +  fi
>         > >> +
>         > >> +  # and now we read the VPN Data and give this data to
>         fff-vpn
>         > >> +  json_load "$(cat /tmp/keyxchangev2data)"
>         > >> +
>         > >> +  json_select vpn
>         > >> +  Index="1"
>         > >> +  rm /tmp/fastd_fff_output
>         > >> +  touch /tmp/fastd_fff_output
>         > >> +  while json_select $Index > /dev/null
>         > > Wieso while wenn nur ein Element "1"?
>         > es kann auch 2 oder 3 Gateways geben, deshalb muss man alle
>         mit einer
>         > Schleife durchgehen oder?
>         > >
>         > >
>         > >> +  do
>         > >> +          json_get_var protocol protocol
>         > >> +          if [ "$protocol" == "fastd" ]; then
>         > >> +                  json_get_var servername name
>         > >> +                  echo "####${servername}.conf" >>
>         > >> /tmp/fastd_fff_output
>         > >> +                  echo "#name \"${servername}\";" >>
>         > >> /tmp/fastd_fff_output
>         > >> +                  json_get_var key key
>         > >> +                  echo "key \"${key}\";"
>         >> /tmp/fastd_fff_output
>         > >> +                  json_get_var address address
>         > >> +                  json_get_var port port
>         > >> +                  echo "remote ipv4 \"${address}\" port
>         $port float;"
>         > >>>> /tmp/fastd_fff_output
>         > >> +          fi
>         > >> +          echo "" >> /tmp/fastd_fff_output
>         > >> +          echo "###" >> /tmp/fastd_fff_output
>         > > Die beiden kommen ja nur einmal am Schluss, also müssen
>         sie aus dem while
>         > > raus, oder?
>         > oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs
>         hab ich das
>         > ganze noch nicht getestet, RedDog wollte das aber eh relativ
>         zügig
>         > umbauen weil das Format einfach sh*t ist, besser ist wenn
>         fff-vpn die
>         > json direkt ausliest.
>         
>         
>         Genau, ich würde ja auch lieber die Entscheidung, ob fastd
>         oder
>         tunneldigger genommen wird auch nicht an einer per http
>         download'baren
>         Datei festmachen, sondern hier nach dem json file entsprechend
>         machen.
>         
>         Tim
>         
>         
>         > mfg
>         >
>         > Christian
>         > >
>         > > Grüße
>         > >
>         > > Adrian
>         > >
>         > >
>         > >> +  done
>         > >> +  #this we do every 5 minutes, because it can change the
>         VPN Protocol
>         > >> +  #and now we get to vpn-select Script and load VPNs
>         > >> +  sh /usr/sbin/vpn-select
>         > >> +fi
>         > >> diff --git a/src/packages/fff/fff/Makefile
>         b/src/packages/fff/fff/Makefile
>         > >> index 166d423..305ab8d 100644
>         > >> --- a/src/packages/fff/fff/Makefile
>         > >> +++ b/src/packages/fff/fff/Makefile
>         > >> @@ -29,7 +29,8 @@ define Package/fff-base
>         > >>               +fff-wireless \
>         > >>               +fff-timeserver \
>         > >>               +fff-vpn-select \
>         > >> -             +simple-tc
>         > >> +             +simple-tc \
>         > >> +             +fff-hoods
>         > >>  endef
>         > >>
>         > >>  define Package/fff-base/description
>         > >> --
>         > >> 2.7.4
>         > >>
>         > >> --
>         > >> franken-dev mailing list
>         > >> franken-dev@freifunk.net
>         > >>
>         http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>         >
>         >
>         > --
>         > franken-dev mailing list
>         > franken-dev@freifunk.net
>         >
>         http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>         
>         
>         
>         --
>         franken-dev mailing list
>         franken-dev@freifunk.net
>         http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>         
> 
>
Adrian Schmutzler Oct. 4, 2017, 9:29 a.m.
Hallo Tim,

für mich, der ich eigtl ein OOP Programmierer bin, hat der Vorschlag mit der Library natürlich sehr viel Charme.

Folgende Überlegungen:
1. Im Moment würde ich das erstmal hintanstellen, da Zeit
2. Da im Moment fastd und tunneldigger ja nicht parallel, sondern hierarchisch ineinander aufgerufen werden, müsste man glaube ich erst deine Diskussion diesbezüglich mit Christian auflösen, bevor man das "ordentlich" machen kann.
3. Irgendwann könnte der "Stumpf" von vpn-select in die fff-hoods mit rein wandern, da erstere nichts mehr sonst in der Package hat und eh nur von fff-hoods gecallt wird.

Grüße

Adrian

-----Original Message-----
From: Tim Niemeyer [mailto:tim@tn-x.org] 
Sent: Montag, 2. Oktober 2017 16:29
To: Adrian Schmutzler <mail@adrianschmutzler.de>
Subject: Re: [PATCH v10 4/4] Add fff-hoods

Am Montag, den 02.10.2017, 16:23 +0200 schrieb Adrian Schmutzler:
> Hallo,
> 
> danke für die Hinweise. Ein Teil ist schon im neuen v11 Patch drin.
Habs grad gesehen. Prima! :)

> 
> Bin grade selber dabei, das vpn-select auf json umzustellen.
Ah.. Haha.. :)

Dann is Christian ja Overruled.. :P

Wie genau planst du das? Ich muss mir das nochmal kurz angucken.

Eigentlich braucht man das vpn-select ja dann gar nicht mehr, weil das "select" macht ja dann fff-hoods (basierend auf dem json).

Ich fänd es schön, wenn es unter /lib/wtf/functions pro VPN eine entsprechende "library" gibt, womit dann die jeweiligen VPNs hinzugefügt werden.

Die stellen dann quasi eine Funktion wie:
add_fastd "$serverip" "$param2" ...
add_l2tpv3 "$serverip" "..."

Das fff-hoods benutzt diese dann nur noch, je nach Inhalt der json Datei.

Was denkst du?

Tim


> Grüße
> 
> Adrian
> 
> -----Original Message-----
> From: Tim Niemeyer [mailto:tim@tn-x.org]
> Sent: Montag, 2. Oktober 2017 16:20
> To: Christian Dresel <fff@chrisi01.de>; franken-dev@freifunk.net
> Cc: mail@adrianschmutzler.de
> Subject: Re: [PATCH v10 4/4] Add fff-hoods
> 
> Hi
> 
> 
> Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
> > hi
> > 
> > hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert daher 
> > bin ich die Mail mal eben überflogen und paar Kommentare Inline.
> > 
> > On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
> > > Hallo,
> > >
> > > eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen 
> > > aufgefallen sind.
> > >
> > >> -----Original Message-----
> > >> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On 
> > >> Behalf Of Adrian Schmutzler
> > >> Sent: Sonntag, 1. Oktober 2017 15:49
> > >> To: franken-dev@freifunk.net
> > >> Cc: Jan Kraus <mayosemmel@gmail.com>
> > >> Subject: [PATCH v10 4/4] Add fff-hoods
> > >>
> > >> From: Christian Dresel <fff@chrisi01.de>
> > >>
> > >> this packages connect to keyxchangev2 after review we must change 
> > >> the serveradress! This is only a example
> > >>
> > >> Signed-off-by: Christian Dresel <fff@chrisi01.de>
> > >> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
> > >> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> > >>
> > >> Update in v2:
> > >>  - clean tabstops
> > >>  - move the json vpn out of the if because we need this after 
> > >> reboot
> > >>
> > >> Update in v5:
> > >> 	!!UNTESTED!!
> > >>  - change hidden AP ip to locallink
> > >>  - Open hidden AP after more checks
> > >>  - Load json File from Gateway if Gateway in Batman in Range
> > >>
> > >> Update in v6:
> > >> 	!!UNTESTED!!
> > >>  - fix hidden station v6
> > >>  - fix -n to -f if
> > >>  - Add function to check for a gateway and use this
> > >>  - remove /etc/community.cfg and variables
> > >>  - send fewer infos to keyxchangev2
> > >>  - add a check if /tmp/keyxchangev2 not downloadable and edit a 
> > >> bit on
> > > the
> > >> wgets
> > >>  - change the position from json_load and do this only 1 times
> > >>
> > >> Update in v7:
> > >> 	!!UNTESTED!!
> > >>  - delete keyxchangev2data at start of the script
> > >>  - do only things with keyxchangev2data if available
> > >>  - change keyxchangev2 url
> > >>
> > >> Update in v8/v9:
> > >>  - rebase onto 20170918-beta
> > >>
> > >> Update in v10:
> > >>  - Minor code fixes
> > >>  - Added fff-hoods to fff-base Makefile
> > >>  - Removed trailing whitespaces and harmonized tabs
> > >>  - Fixed some comments spelling
> > >>  - Added mac for hostname rewrite
> > >>  - Removed redundant check for /tmp/keyxchangev2data
> > >> ---
> > >>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
> > >>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
> > >>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
> > >>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
> > >> +++++++++++++++++++++
> > >>  src/packages/fff/fff/Makefile                      |   3 +-
> > >>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode
> > >> 100644 src/packages/fff/fff-hoods/Makefile
> > >>  create mode 100644 src/packages/fff/fff- 
> > >> hoods/files/etc/hotplug.d/iface/50-fff-hoods
> > >>  create mode 100644
> > >> src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
> > >> hoods
> > >>  create mode 100755 src/packages/fff/fff- 
> > >> hoods/files/usr/sbin/configurehood
> > >>
> > >> diff --git a/src/packages/fff/fff-hoods/Makefile
> > >> b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index 
> > >> 0000000..f85178d
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/Makefile
> > >> @@ -0,0 +1,39 @@
> > >> +include $(TOPDIR)/rules.mk
> > >> +
> > >> +PKG_NAME:=fff-hoods
> > >> +PKG_VERSION:=0.0.1
> > >> +PKG_RELEASE:=1
> > >> +
> > >> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
> > >> +
> > >> +include $(INCLUDE_DIR)/package.mk
> > >> +
> > >> +define Package/fff-hoods
> > >> +    SECTION:=base
> > >> +    CATEGORY:=Freifunk
> > >> +    TITLE:= Freifunk-Franken hoods
> > >> +    URL:=http://www.freifunk-franken.de
> > >> +    DEPENDS:=+fff-network
> > >> +endef
> > >> +
> > >> +define Package/fff-hoods/description
> > >> +    This package load and configures the current hood endef
> > >> +
> > >> +define Build/Prepare
> > >> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
> > >> +
> > >> +define Build/Configure
> > >> +	# nothing
> > >> +endef
> > >> +
> > >> +define Build/Compile
> > >> +	# nothing
> > >> +endef
> > >> +
> > >> +define Package/fff-hoods/install
> > >> +	$(CP) ./files/* $(1)/
> > >> +endef
> > >> +
> > >> +$(eval $(call BuildPackage,fff-hoods))
> > >> diff --git
> > > a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
> > > s
> > >> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoo
> > >> ds
> > >> new file mode 100644
> > >> index 0000000..49f53e3
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff
> > >> +++ -h
> > >> +++ oods
> > >> @@ -0,0 +1,5 @@
> > >> +#!/bin/sh
> > >> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
> > >> +       sleep 3
> > >> +       /usr/sbin/configurehood
> > >> +}
> > >> diff --git
> > >> a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > >> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > >> new file mode 100644
> > >> index 0000000..ca8d798
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
> > >> @@ -0,0 +1 @@
> > >> +*/5 * * * * /usr/sbin/configurehood
> > >> diff --git
> > >> a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > >> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > >> new file mode 100755
> > >> index 0000000..ad316f8
> > >> --- /dev/null
> > >> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > >> @@ -0,0 +1,206 @@
> > >> +#!/bin/sh
> > >> +
> > >> +. /usr/share/libubox/jshn.sh
> > >> +. /lib/functions/fff/wireless
> > >> +
> > >> +rm /tmp/keyxchangev2data
> > >> +
> > >> +# Gatewaycheck function
> > >> +isGatewayAvailable() {
> > >> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
> > >> +		return true;
> > >> +	else
> > >> +		return false;
> > >> +	fi
> > >> +}
> > >> +
> > >> +
> > >> +# Hidden AP check
> > >> +
> > >> +if [ -f /tmp/hiddenapflag ]; then
> > >> +	if [ isGatewayAvailable ]; then
> > >> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
> > >> "configap" "configap" "1"; then
> > >> +			echo "Can't add AP interface on $radio."
> > >> +			exit 1
> > >> +		else
> > >> +			# We must set a fixed ip address here
> > >> +			uci set network.configap=interface
> > >> +			uci set network.configap.proto='static'
> > >> +			uci set network.configap.ip6addr='fe80::1/64'
> > >> +			uci commit network
> > >> +		fi
> > >> +	else
> > >> +		rm /tmp/hiddenapflag
> > >> +	fi
> > >> +fi
> > > Warum steht dieser ganze Block am Anfang und nicht am Schluss des Skripts?
> > > Hat das einen Grund, dass der immer einen Zyklus warten soll?
> > genau, Batman hat ein Timeout das wollen wir damit abfangen damit 
> > erst im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss also 
> > 5min eine Verbindung zum GW bestehen.
> > >
> > >
> > >
> > >> +
> > >> +
> > >> +lat=$(uci get system.@system[0].latitude) long=$(uci get
> > >> +system.@system[0].longitude) hostname=$(cat
> > >> /proc/sys/kernel/hostname)
> > >> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
> > > Hier hab ich die Mac ergänzt.
> > das war einfach nur C&P
> > >
> > >> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = 
> > >> +"OpenWrt" ]
> > >> && hostname=""
> > >> +[ "$hostname" = "" ] &&  hostname="$mac"
> > > Wozu ist das gut? Sollte man das auf LEDE ändern?
> > hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht unsicher 
> > wofür es nötig ist.
> 
> Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.
> 
> Ja, das sollte man ändern. :) Good Catch!
> 
> > >
> > >> +
> > >> +test_ipv4_host1="keyserver.freifunk-franken.de" # 
> > >> +Freifunk-Franken
> > >> keyserver
> > >> +test_ipv4_host2="8.8.8.8"        # Google DNS
> > >> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
> > >> +
> > >> +# if we have Internet, we download the Hoodfile from the
> > >> +keyxchangev2 if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
> > >> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
> > >> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
> > >> +	wget -T15 -t5 "http://keyserver.freifunk-
> > >> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
> > >> +	#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
> > >> +	# Only do that, when we have no gateway in range. If the
> > >> Uplinkrouter changed the hood, we lost the GW and do this 
> > >> automatically again, I think! Nice idea?
> > >> +	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
> > >> +		if ! wifiDelAll; then
> > >> +			echo "Can't delete current wifi setup"
> > >> +			exit 1
> > >> +		fi
> > >> +		#now we look for phy and add this
> > >> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> > >> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> > >> +				echo "$phy is 2.4 GHz"
> > >> +				radio=$(wifiAddPhy "$phy"
> > >> "$BATMAN_CHANNEL")
> > >> +				if [ -z "$radio" ]; then
> > >> +					echo "Can't create radio for $phy"
> > >> +					exit 1
> > >> +				fi
> > >> +			fi
> > >> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> > >> +				echo "$phy is 5 GHz"
> > >> +				radio=$(wifiAddPhy "$phy"
> > >> "$BATMAN_CHANNEL_5GHZ")
> > >> +				if [ -z "$radio" ]; then
> > >> +					echo "Can't create radio for $phy"
> > >> +					exit 1
> > >> +				fi
> > >> +			fi
> > > Hier werden Variablen aus der community.cfg verwendet 
> > > ($BATMAN...), unten ist hardgecodet. Das hier auch hardcoden?
> > macht vermutlich Sinn, weil wir die /etc/community.cfg eh abschaffen wollen.
> 
> Richtig. Die Daten kommen ja (später mal) aus dem json hood file. Bis dahin sind sie halt hart kodiert. Um einen Übergang leichter zu machen könnte man überlegen, on man die Werte vielleicht einer Konstangen zuweist und diesen dann entsprechend verwendet. Das hätte den Vorteil, dass die Umstellung dann später einfacher wird.
> 
> > >
> > >
> > >> +			#and here we add the station
> > >> +			if ! wifiAddSta "$radio"
> > > "config.franken.freifunk.net"
> > >> "configSta"; then
> > >> +				echo "Can't add Sta interface on $radio."
> > >> +				exit 1
> > >> +			fi
> > >> +
> > >> +		done
> > >> +
> > >> +		wifi
> > >> +		# 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
> > >> +	else
> > >> +		echo "We have a Gateway in Range, we load the
> > >> keyxchangev2data from fe80::1"
> > >> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
> > >> -O /tmp/keyxchangev2data
> > >> +	fi
> > >> +
> > >> +fi
> > >> +
> > >> +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!
> > >> +
> > >> +	json_load "$(cat /tmp/keyxchangev2data)"
> > >> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
> > >> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
> > >> | cut -f1 -d " ")
> > >> +	if [ "$sumnew" != "$sumold" ]; then
> > > Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht 
> > > irgendwie keinen Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon geprüft haben?!
> > das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich 
> > mal zurück.
> > >
> > >
> > >> +		echo "New file detect, we reconfigure the Node";
> > >> +
> > >> +		# copy the file to webroot so that other Meshrouter can
> > >> download it
> > >> +		cp /tmp/keyxchangev2data /www/public/
> > >> +
> > >> +		json_select hood
> > >> +
> > >> +		json_get_var hood name
> > >> +		json_get_var mesh_bssid mesh_bssid
> > >> +		json_get_var mesh_essid mesh_essid
> > >> +		json_get_var essid essid
> > >> +		# i think the next things we don't active this in the first
> > >> version! we can do it later
> > >> +		#json_get_var channel2 channel2
> > >> +		#json_get_var mode2 mode2
> > >> +		#json_get_var type2 type2
> > >> +		#json_get_var channel5 channel5
> > >> +		#json_get_var mode5 mode5
> > >> +		#json_get_var type5 type5
> > >> +		#json_get_var protocol protocol
> > >> +
> > >> +		echo "Setting hood name: $hood"
> > >> +		uci set "system.@system[0].hood=$hood"
> > >> +
> > >> +		if ! wifiDelAll; then
> > >> +			echo "Can't delete current wifi setup"
> > >> +			exit 1
> > >> +		fi
> > >> +
> > >> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
> > >> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
> > >> +				echo "$phy is 2.4 GHz"
> > >> +				radio=$(wifiAddPhy "$phy" "1")
> > > Hier ist jetzt hardgecodet ... "1"
> > interessant, vermutlich hab ich es oben einfach vergessen und wollt 
> > es wirklich überall hard coden weil eben /etc/community.cfg weg fällt.
> > >
> > >
> > >> +				if [ -z "$radio" ]; then
> > >> +					echo "Can't create radio for $phy"
> > >> +					exit 1
> > >> +				fi
> > >> +			fi
> > >> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
> > >> +				echo "$phy is 5 GHz"
> > >> +				radio=$(wifiAddPhy "$phy" "13")
> > >> +				if [ -z "$radio" ]; then
> > >> +					echo "Can't create radio for $phy"
> > >> +					exit 1
> > >> +				fi
> > >> +			fi
> > >> +
> > >> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
> > > then
> > >> +				echo "Can't add AP interface on $radio."
> > >> +				exit 1
> > >> +			fi
> > >> +
> > >> +			# here we set a bit for add hidden AP
> > >> +			touch /tmp/hiddenapflag
> > >> +
> > >> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
> > >> "$mesh_bssid"; then
> > >> +				echo "Can't add AP interface on $radio."
> > >> +				exit 1
> > >> +			fi
> > >> +		done
> > >> +
> > >> +		echo "Loading wifi"
> > >> +		wifi
> > >> +
> > >> +	else
> > >> +		echo "We have no new file or we haven't got a file. We do
> > >> nothing. We try it again in 5 minutes...";
> > > Meines Erachtens ist hier nur "We have no new file" erfüllt. Der 
> > > andere Fall wäre eine if weiter außen. Siehe [ ! -f /tmp/keyxchangev2data] ...
> > muss ich mir auch mal in Ruhe angucken...
> > >
> > >
> > >> +	fi
> > >> +
> > >> +	# and now we read the VPN Data and give this data to fff-vpn
> > >> +	json_load "$(cat /tmp/keyxchangev2data)"
> > >> +
> > >> +	json_select vpn
> > >> +	Index="1"
> > >> +	rm /tmp/fastd_fff_output
> > >> +	touch /tmp/fastd_fff_output
> > >> +	while json_select $Index > /dev/null
> > > Wieso while wenn nur ein Element "1"?
> > es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit 
> > einer Schleife durchgehen oder?
> > >
> > >
> > >> +	do
> > >> +		json_get_var protocol protocol
> > >> +		if [ "$protocol" == "fastd" ]; then
> > >> +			json_get_var servername name
> > >> +			echo "####${servername}.conf" >>
> > >> /tmp/fastd_fff_output
> > >> +			echo "#name \"${servername}\";" >>
> > >> /tmp/fastd_fff_output
> > >> +			json_get_var key key
> > >> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
> > >> +			json_get_var address address
> > >> +			json_get_var port port
> > >> +			echo "remote ipv4 \"${address}\" port $port float;"
> > >>>> /tmp/fastd_fff_output
> > >> +		fi
> > >> +		echo "" >> /tmp/fastd_fff_output
> > >> +		echo "###" >> /tmp/fastd_fff_output
> > > Die beiden kommen ja nur einmal am Schluss, also müssen sie aus 
> > > dem while raus, oder?
> > oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab ich 
> > das ganze noch nicht getestet, RedDog wollte das aber eh relativ 
> > zügig umbauen weil das Format einfach sh*t ist, besser ist wenn 
> > fff-vpn die json direkt ausliest.
> 
> Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder tunneldigger genommen wird auch nicht an einer per http download'baren Datei festmachen, sondern hier nach dem json file entsprechend machen.
> 
> Tim
> 
> 
> > mfg
> > 
> > Christian
> > >
> > > Grüße
> > >
> > > Adrian
> > >
> > >
> > >> +	done
> > >> +	#this we do every 5 minutes, because it can change the VPN Protocol
> > >> +	#and now we get to vpn-select Script and load VPNs
> > >> +	sh /usr/sbin/vpn-select
> > >> +fi
> > >> diff --git a/src/packages/fff/fff/Makefile 
> > >> b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
> > >> --- a/src/packages/fff/fff/Makefile
> > >> +++ b/src/packages/fff/fff/Makefile
> > >> @@ -29,7 +29,8 @@ define Package/fff-base
> > >>               +fff-wireless \
> > >>               +fff-timeserver \
> > >>               +fff-vpn-select \
> > >> -             +simple-tc
> > >> +             +simple-tc \
> > >> +             +fff-hoods
> > >>  endef
> > >>
> > >>  define Package/fff-base/description
> > >> --
> > >> 2.7.4
> > >>
> > >> --
> > >> franken-dev mailing list
> > >> franken-dev@freifunk.net
> > >> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.n
> > >> et
> > 
> > 
> > --
> > franken-dev mailing list
> > franken-dev@freifunk.net
> > http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
> 
>
Robert Langhammer Oct. 4, 2017, 10:09 a.m.
Hallo,

mir gefaellt das auch sehr gut. Es bleibt noch die Frage, woher bekommt
man die VPN Zugangsdaten, damit man am Gateway flexibel bleibt?

Ich faende es schoen, wenn ich am Gateway den Zugang festlegen koennte.
Aktuell koennen die Ropter fastd und l2tp. Da koennen auch noch welche
dazu kommen. Und am Gateway entscheide ich dann, was ich anbieten
moechte. Das bedeutet, der Uplinkrouter bekommt vom KeyX nur die IPs der
GWs und erfragt bei denen die VPN Daten.

So wird es dann auch recht einfach neue VPN Varianten zu integrieren.

Was meint Ihr?

Robert


Am 04.10.2017 um 11:29 schrieb Adrian Schmutzler:
> Hallo Tim,
>
> für mich, der ich eigtl ein OOP Programmierer bin, hat der Vorschlag mit der Library natürlich sehr viel Charme.
>
> Folgende Überlegungen:
> 1. Im Moment würde ich das erstmal hintanstellen, da Zeit
> 2. Da im Moment fastd und tunneldigger ja nicht parallel, sondern hierarchisch ineinander aufgerufen werden, müsste man glaube ich erst deine Diskussion diesbezüglich mit Christian auflösen, bevor man das "ordentlich" machen kann.
> 3. Irgendwann könnte der "Stumpf" von vpn-select in die fff-hoods mit rein wandern, da erstere nichts mehr sonst in der Package hat und eh nur von fff-hoods gecallt wird.
>
> Grüße
>
> Adrian
>
> -----Original Message-----
> From: Tim Niemeyer [mailto:tim@tn-x.org] 
> Sent: Montag, 2. Oktober 2017 16:29
> To: Adrian Schmutzler <mail@adrianschmutzler.de>
> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>
> Am Montag, den 02.10.2017, 16:23 +0200 schrieb Adrian Schmutzler:
>> Hallo,
>>
>> danke für die Hinweise. Ein Teil ist schon im neuen v11 Patch drin.
> Habs grad gesehen. Prima! :)
>
>> Bin grade selber dabei, das vpn-select auf json umzustellen.
> Ah.. Haha.. :)
>
> Dann is Christian ja Overruled.. :P
>
> Wie genau planst du das? Ich muss mir das nochmal kurz angucken.
>
> Eigentlich braucht man das vpn-select ja dann gar nicht mehr, weil das "select" macht ja dann fff-hoods (basierend auf dem json).
>
> Ich fänd es schön, wenn es unter /lib/wtf/functions pro VPN eine entsprechende "library" gibt, womit dann die jeweiligen VPNs hinzugefügt werden.
>
> Die stellen dann quasi eine Funktion wie:
> add_fastd "$serverip" "$param2" ...
> add_l2tpv3 "$serverip" "..."
>
> Das fff-hoods benutzt diese dann nur noch, je nach Inhalt der json Datei.
>
> Was denkst du?
>
> Tim
>
>
>> Grüße
>>
>> Adrian
>>
>> -----Original Message-----
>> From: Tim Niemeyer [mailto:tim@tn-x.org]
>> Sent: Montag, 2. Oktober 2017 16:20
>> To: Christian Dresel <fff@chrisi01.de>; franken-dev@freifunk.net
>> Cc: mail@adrianschmutzler.de
>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>
>> Hi
>>
>>
>> Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
>>> hi
>>>
>>> hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert daher 
>>> bin ich die Mail mal eben überflogen und paar Kommentare Inline.
>>>
>>> On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
>>>> Hallo,
>>>>
>>>> eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen 
>>>> aufgefallen sind.
>>>>
>>>>> -----Original Message-----
>>>>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On 
>>>>> Behalf Of Adrian Schmutzler
>>>>> Sent: Sonntag, 1. Oktober 2017 15:49
>>>>> To: franken-dev@freifunk.net
>>>>> Cc: Jan Kraus <mayosemmel@gmail.com>
>>>>> Subject: [PATCH v10 4/4] Add fff-hoods
>>>>>
>>>>> From: Christian Dresel <fff@chrisi01.de>
>>>>>
>>>>> this packages connect to keyxchangev2 after review we must change 
>>>>> the serveradress! This is only a example
>>>>>
>>>>> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>>>>> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>>>>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>>>>
>>>>> Update in v2:
>>>>>  - clean tabstops
>>>>>  - move the json vpn out of the if because we need this after 
>>>>> reboot
>>>>>
>>>>> Update in v5:
>>>>> 	!!UNTESTED!!
>>>>>  - change hidden AP ip to locallink
>>>>>  - Open hidden AP after more checks
>>>>>  - Load json File from Gateway if Gateway in Batman in Range
>>>>>
>>>>> Update in v6:
>>>>> 	!!UNTESTED!!
>>>>>  - fix hidden station v6
>>>>>  - fix -n to -f if
>>>>>  - Add function to check for a gateway and use this
>>>>>  - remove /etc/community.cfg and variables
>>>>>  - send fewer infos to keyxchangev2
>>>>>  - add a check if /tmp/keyxchangev2 not downloadable and edit a 
>>>>> bit on
>>>> the
>>>>> wgets
>>>>>  - change the position from json_load and do this only 1 times
>>>>>
>>>>> Update in v7:
>>>>> 	!!UNTESTED!!
>>>>>  - delete keyxchangev2data at start of the script
>>>>>  - do only things with keyxchangev2data if available
>>>>>  - change keyxchangev2 url
>>>>>
>>>>> Update in v8/v9:
>>>>>  - rebase onto 20170918-beta
>>>>>
>>>>> Update in v10:
>>>>>  - Minor code fixes
>>>>>  - Added fff-hoods to fff-base Makefile
>>>>>  - Removed trailing whitespaces and harmonized tabs
>>>>>  - Fixed some comments spelling
>>>>>  - Added mac for hostname rewrite
>>>>>  - Removed redundant check for /tmp/keyxchangev2data
>>>>> ---
>>>>>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>>>>>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>>>>>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>>>>>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>>>>> +++++++++++++++++++++
>>>>>  src/packages/fff/fff/Makefile                      |   3 +-
>>>>>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode
>>>>> 100644 src/packages/fff/fff-hoods/Makefile
>>>>>  create mode 100644 src/packages/fff/fff- 
>>>>> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>>>>  create mode 100644
>>>>> src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>>>>> hoods
>>>>>  create mode 100755 src/packages/fff/fff- 
>>>>> hoods/files/usr/sbin/configurehood
>>>>>
>>>>> diff --git a/src/packages/fff/fff-hoods/Makefile
>>>>> b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index 
>>>>> 0000000..f85178d
>>>>> --- /dev/null
>>>>> +++ b/src/packages/fff/fff-hoods/Makefile
>>>>> @@ -0,0 +1,39 @@
>>>>> +include $(TOPDIR)/rules.mk
>>>>> +
>>>>> +PKG_NAME:=fff-hoods
>>>>> +PKG_VERSION:=0.0.1
>>>>> +PKG_RELEASE:=1
>>>>> +
>>>>> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>>>>> +
>>>>> +include $(INCLUDE_DIR)/package.mk
>>>>> +
>>>>> +define Package/fff-hoods
>>>>> +    SECTION:=base
>>>>> +    CATEGORY:=Freifunk
>>>>> +    TITLE:= Freifunk-Franken hoods
>>>>> +    URL:=http://www.freifunk-franken.de
>>>>> +    DEPENDS:=+fff-network
>>>>> +endef
>>>>> +
>>>>> +define Package/fff-hoods/description
>>>>> +    This package load and configures the current hood endef
>>>>> +
>>>>> +define Build/Prepare
>>>>> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>>>>> +
>>>>> +define Build/Configure
>>>>> +	# nothing
>>>>> +endef
>>>>> +
>>>>> +define Build/Compile
>>>>> +	# nothing
>>>>> +endef
>>>>> +
>>>>> +define Package/fff-hoods/install
>>>>> +	$(CP) ./files/* $(1)/
>>>>> +endef
>>>>> +
>>>>> +$(eval $(call BuildPackage,fff-hoods))
>>>>> diff --git
>>>> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
>>>> s
>>>>> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoo
>>>>> ds
>>>>> new file mode 100644
>>>>> index 0000000..49f53e3
>>>>> --- /dev/null
>>>>> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff
>>>>> +++ -h
>>>>> +++ oods
>>>>> @@ -0,0 +1,5 @@
>>>>> +#!/bin/sh
>>>>> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>>>>> +       sleep 3
>>>>> +       /usr/sbin/configurehood
>>>>> +}
>>>>> diff --git
>>>>> a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>> new file mode 100644
>>>>> index 0000000..ca8d798
>>>>> --- /dev/null
>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>> @@ -0,0 +1 @@
>>>>> +*/5 * * * * /usr/sbin/configurehood
>>>>> diff --git
>>>>> a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>> new file mode 100755
>>>>> index 0000000..ad316f8
>>>>> --- /dev/null
>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>> @@ -0,0 +1,206 @@
>>>>> +#!/bin/sh
>>>>> +
>>>>> +. /usr/share/libubox/jshn.sh
>>>>> +. /lib/functions/fff/wireless
>>>>> +
>>>>> +rm /tmp/keyxchangev2data
>>>>> +
>>>>> +# Gatewaycheck function
>>>>> +isGatewayAvailable() {
>>>>> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>>>>> +		return true;
>>>>> +	else
>>>>> +		return false;
>>>>> +	fi
>>>>> +}
>>>>> +
>>>>> +
>>>>> +# Hidden AP check
>>>>> +
>>>>> +if [ -f /tmp/hiddenapflag ]; then
>>>>> +	if [ isGatewayAvailable ]; then
>>>>> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
>>>>> "configap" "configap" "1"; then
>>>>> +			echo "Can't add AP interface on $radio."
>>>>> +			exit 1
>>>>> +		else
>>>>> +			# We must set a fixed ip address here
>>>>> +			uci set network.configap=interface
>>>>> +			uci set network.configap.proto='static'
>>>>> +			uci set network.configap.ip6addr='fe80::1/64'
>>>>> +			uci commit network
>>>>> +		fi
>>>>> +	else
>>>>> +		rm /tmp/hiddenapflag
>>>>> +	fi
>>>>> +fi
>>>> Warum steht dieser ganze Block am Anfang und nicht am Schluss des Skripts?
>>>> Hat das einen Grund, dass der immer einen Zyklus warten soll?
>>> genau, Batman hat ein Timeout das wollen wir damit abfangen damit 
>>> erst im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss also 
>>> 5min eine Verbindung zum GW bestehen.
>>>>
>>>>
>>>>> +
>>>>> +
>>>>> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>>>>> +system.@system[0].longitude) hostname=$(cat
>>>>> /proc/sys/kernel/hostname)
>>>>> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
>>>> Hier hab ich die Mac ergänzt.
>>> das war einfach nur C&P
>>>>> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = 
>>>>> +"OpenWrt" ]
>>>>> && hostname=""
>>>>> +[ "$hostname" = "" ] &&  hostname="$mac"
>>>> Wozu ist das gut? Sollte man das auf LEDE ändern?
>>> hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht unsicher 
>>> wofür es nötig ist.
>> Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.
>>
>> Ja, das sollte man ändern. :) Good Catch!
>>
>>>>> +
>>>>> +test_ipv4_host1="keyserver.freifunk-franken.de" # 
>>>>> +Freifunk-Franken
>>>>> keyserver
>>>>> +test_ipv4_host2="8.8.8.8"        # Google DNS
>>>>> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
>>>>> +
>>>>> +# if we have Internet, we download the Hoodfile from the
>>>>> +keyxchangev2 if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>>>>> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>>>>> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>>>>> +	wget -T15 -t5 "http://keyserver.freifunk-
>>>>> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
>>>>> +	#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
>>>>> +	# Only do that, when we have no gateway in range. If the
>>>>> Uplinkrouter changed the hood, we lost the GW and do this 
>>>>> automatically again, I think! Nice idea?
>>>>> +	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
>>>>> +		if ! wifiDelAll; then
>>>>> +			echo "Can't delete current wifi setup"
>>>>> +			exit 1
>>>>> +		fi
>>>>> +		#now we look for phy and add this
>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>> +				echo "$phy is 2.4 GHz"
>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>> "$BATMAN_CHANNEL")
>>>>> +				if [ -z "$radio" ]; then
>>>>> +					echo "Can't create radio for $phy"
>>>>> +					exit 1
>>>>> +				fi
>>>>> +			fi
>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>> +				echo "$phy is 5 GHz"
>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>> "$BATMAN_CHANNEL_5GHZ")
>>>>> +				if [ -z "$radio" ]; then
>>>>> +					echo "Can't create radio for $phy"
>>>>> +					exit 1
>>>>> +				fi
>>>>> +			fi
>>>> Hier werden Variablen aus der community.cfg verwendet 
>>>> ($BATMAN...), unten ist hardgecodet. Das hier auch hardcoden?
>>> macht vermutlich Sinn, weil wir die /etc/community.cfg eh abschaffen wollen.
>> Richtig. Die Daten kommen ja (später mal) aus dem json hood file. Bis dahin sind sie halt hart kodiert. Um einen Übergang leichter zu machen könnte man überlegen, on man die Werte vielleicht einer Konstangen zuweist und diesen dann entsprechend verwendet. Das hätte den Vorteil, dass die Umstellung dann später einfacher wird.
>>
>>>>
>>>>> +			#and here we add the station
>>>>> +			if ! wifiAddSta "$radio"
>>>> "config.franken.freifunk.net"
>>>>> "configSta"; then
>>>>> +				echo "Can't add Sta interface on $radio."
>>>>> +				exit 1
>>>>> +			fi
>>>>> +
>>>>> +		done
>>>>> +
>>>>> +		wifi
>>>>> +		# 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
>>>>> +	else
>>>>> +		echo "We have a Gateway in Range, we load the
>>>>> keyxchangev2data from fe80::1"
>>>>> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
>>>>> -O /tmp/keyxchangev2data
>>>>> +	fi
>>>>> +
>>>>> +fi
>>>>> +
>>>>> +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!
>>>>> +
>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
>>>>> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
>>>>> | cut -f1 -d " ")
>>>>> +	if [ "$sumnew" != "$sumold" ]; then
>>>> Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht 
>>>> irgendwie keinen Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ] schon geprüft haben?!
>>> das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich 
>>> mal zurück.
>>>>
>>>>> +		echo "New file detect, we reconfigure the Node";
>>>>> +
>>>>> +		# copy the file to webroot so that other Meshrouter can
>>>>> download it
>>>>> +		cp /tmp/keyxchangev2data /www/public/
>>>>> +
>>>>> +		json_select hood
>>>>> +
>>>>> +		json_get_var hood name
>>>>> +		json_get_var mesh_bssid mesh_bssid
>>>>> +		json_get_var mesh_essid mesh_essid
>>>>> +		json_get_var essid essid
>>>>> +		# i think the next things we don't active this in the first
>>>>> version! we can do it later
>>>>> +		#json_get_var channel2 channel2
>>>>> +		#json_get_var mode2 mode2
>>>>> +		#json_get_var type2 type2
>>>>> +		#json_get_var channel5 channel5
>>>>> +		#json_get_var mode5 mode5
>>>>> +		#json_get_var type5 type5
>>>>> +		#json_get_var protocol protocol
>>>>> +
>>>>> +		echo "Setting hood name: $hood"
>>>>> +		uci set "system.@system[0].hood=$hood"
>>>>> +
>>>>> +		if ! wifiDelAll; then
>>>>> +			echo "Can't delete current wifi setup"
>>>>> +			exit 1
>>>>> +		fi
>>>>> +
>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>> +				echo "$phy is 2.4 GHz"
>>>>> +				radio=$(wifiAddPhy "$phy" "1")
>>>> Hier ist jetzt hardgecodet ... "1"
>>> interessant, vermutlich hab ich es oben einfach vergessen und wollt 
>>> es wirklich überall hard coden weil eben /etc/community.cfg weg fällt.
>>>>
>>>>> +				if [ -z "$radio" ]; then
>>>>> +					echo "Can't create radio for $phy"
>>>>> +					exit 1
>>>>> +				fi
>>>>> +			fi
>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>> +				echo "$phy is 5 GHz"
>>>>> +				radio=$(wifiAddPhy "$phy" "13")
>>>>> +				if [ -z "$radio" ]; then
>>>>> +					echo "Can't create radio for $phy"
>>>>> +					exit 1
>>>>> +				fi
>>>>> +			fi
>>>>> +
>>>>> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
>>>> then
>>>>> +				echo "Can't add AP interface on $radio."
>>>>> +				exit 1
>>>>> +			fi
>>>>> +
>>>>> +			# here we set a bit for add hidden AP
>>>>> +			touch /tmp/hiddenapflag
>>>>> +
>>>>> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
>>>>> "$mesh_bssid"; then
>>>>> +				echo "Can't add AP interface on $radio."
>>>>> +				exit 1
>>>>> +			fi
>>>>> +		done
>>>>> +
>>>>> +		echo "Loading wifi"
>>>>> +		wifi
>>>>> +
>>>>> +	else
>>>>> +		echo "We have no new file or we haven't got a file. We do
>>>>> nothing. We try it again in 5 minutes...";
>>>> Meines Erachtens ist hier nur "We have no new file" erfüllt. Der 
>>>> andere Fall wäre eine if weiter außen. Siehe [ ! -f /tmp/keyxchangev2data] ...
>>> muss ich mir auch mal in Ruhe angucken...
>>>>
>>>>> +	fi
>>>>> +
>>>>> +	# and now we read the VPN Data and give this data to fff-vpn
>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>> +
>>>>> +	json_select vpn
>>>>> +	Index="1"
>>>>> +	rm /tmp/fastd_fff_output
>>>>> +	touch /tmp/fastd_fff_output
>>>>> +	while json_select $Index > /dev/null
>>>> Wieso while wenn nur ein Element "1"?
>>> es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit 
>>> einer Schleife durchgehen oder?
>>>>
>>>>> +	do
>>>>> +		json_get_var protocol protocol
>>>>> +		if [ "$protocol" == "fastd" ]; then
>>>>> +			json_get_var servername name
>>>>> +			echo "####${servername}.conf" >>
>>>>> /tmp/fastd_fff_output
>>>>> +			echo "#name \"${servername}\";" >>
>>>>> /tmp/fastd_fff_output
>>>>> +			json_get_var key key
>>>>> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
>>>>> +			json_get_var address address
>>>>> +			json_get_var port port
>>>>> +			echo "remote ipv4 \"${address}\" port $port float;"
>>>>>>> /tmp/fastd_fff_output
>>>>> +		fi
>>>>> +		echo "" >> /tmp/fastd_fff_output
>>>>> +		echo "###" >> /tmp/fastd_fff_output
>>>> Die beiden kommen ja nur einmal am Schluss, also müssen sie aus 
>>>> dem while raus, oder?
>>> oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab ich 
>>> das ganze noch nicht getestet, RedDog wollte das aber eh relativ 
>>> zügig umbauen weil das Format einfach sh*t ist, besser ist wenn 
>>> fff-vpn die json direkt ausliest.
>> Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder tunneldigger genommen wird auch nicht an einer per http download'baren Datei festmachen, sondern hier nach dem json file entsprechend machen.
>>
>> Tim
>>
>>
>>> mfg
>>>
>>> Christian
>>>> Grüße
>>>>
>>>> Adrian
>>>>
>>>>
>>>>> +	done
>>>>> +	#this we do every 5 minutes, because it can change the VPN Protocol
>>>>> +	#and now we get to vpn-select Script and load VPNs
>>>>> +	sh /usr/sbin/vpn-select
>>>>> +fi
>>>>> diff --git a/src/packages/fff/fff/Makefile 
>>>>> b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
>>>>> --- a/src/packages/fff/fff/Makefile
>>>>> +++ b/src/packages/fff/fff/Makefile
>>>>> @@ -29,7 +29,8 @@ define Package/fff-base
>>>>>               +fff-wireless \
>>>>>               +fff-timeserver \
>>>>>               +fff-vpn-select \
>>>>> -             +simple-tc
>>>>> +             +simple-tc \
>>>>> +             +fff-hoods
>>>>>  endef
>>>>>
>>>>>  define Package/fff-base/description
>>>>> --
>>>>> 2.7.4
>>>>>
>>>>> --
>>>>> franken-dev mailing list
>>>>> franken-dev@freifunk.net
>>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.n
>>>>> et
>>>
>>> --
>>> franken-dev mailing list
>>> franken-dev@freifunk.net
>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>>
>
Tim Niemeyer Oct. 4, 2017, 10:21 a.m.
Hi

Am 4. Oktober 2017 12:09:53 MESZ schrieb robert <rlanghammer@web.de>:
>Hallo,
>
>mir gefaellt das auch sehr gut. Es bleibt noch die Frage, woher bekommt
>man die VPN Zugangsdaten, damit man am Gateway flexibel bleibt?

Die Knoten bekommen sie vom zentralen keyXchangeV2 oder durch den configAP ihres Nachbarn. Die Gateways sollen jede Verbindung annehmen, sofern sie nicht blacklisted ist.


>Ich faende es schoen, wenn ich am Gateway den Zugang festlegen koennte.
>Aktuell koennen die Ropter fastd und l2tp. Da koennen auch noch welche
>dazu kommen. Und am Gateway entscheide ich dann, was ich anbieten
>moechte. Das bedeutet, der Uplinkrouter bekommt vom KeyX nur die IPs
>der
>GWs und erfragt bei denen die VPN Daten.

Ich bin eher dagegen, dass die GWs erst befragt werden müssen. Das steht ja schon in der Hoodfile drin was für das Gateway zu nehmen ist. Wenn ein Knoten später mal ein Hoodfile hat, was er nicht unterstützt kann er so einfach das nächste nehmen.


>So wird es dann auch recht einfach neue VPN Varianten zu integrieren.

Ne, eben nicht. Denn die alten Knoten würden das Angebot einer Hood vielleicht nicht unterstützten und könnten dann keine Alternative wählen.

>Was meint Ihr?
Ich denke immer noch, dass es reichen sollte wenn die Knoten sich eine Hood auswählen, und dann das Gateway wählen was sie mögen. Sollte dann mal ein Knoten die angebotenen VPNs nicht unterstützten, kann er einfach die nächste Hood wählen.

Tim


>
>Robert
>
>
>Am 04.10.2017 um 11:29 schrieb Adrian Schmutzler:
>> Hallo Tim,
>>
>> für mich, der ich eigtl ein OOP Programmierer bin, hat der Vorschlag
>mit der Library natürlich sehr viel Charme.
>>
>> Folgende Überlegungen:
>> 1. Im Moment würde ich das erstmal hintanstellen, da Zeit
>> 2. Da im Moment fastd und tunneldigger ja nicht parallel, sondern
>hierarchisch ineinander aufgerufen werden, müsste man glaube ich erst
>deine Diskussion diesbezüglich mit Christian auflösen, bevor man das
>"ordentlich" machen kann.
>> 3. Irgendwann könnte der "Stumpf" von vpn-select in die fff-hoods mit
>rein wandern, da erstere nichts mehr sonst in der Package hat und eh
>nur von fff-hoods gecallt wird.
>>
>> Grüße
>>
>> Adrian
>>
>> -----Original Message-----
>> From: Tim Niemeyer [mailto:tim@tn-x.org] 
>> Sent: Montag, 2. Oktober 2017 16:29
>> To: Adrian Schmutzler <mail@adrianschmutzler.de>
>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>
>> Am Montag, den 02.10.2017, 16:23 +0200 schrieb Adrian Schmutzler:
>>> Hallo,
>>>
>>> danke für die Hinweise. Ein Teil ist schon im neuen v11 Patch drin.
>> Habs grad gesehen. Prima! :)
>>
>>> Bin grade selber dabei, das vpn-select auf json umzustellen.
>> Ah.. Haha.. :)
>>
>> Dann is Christian ja Overruled.. :P
>>
>> Wie genau planst du das? Ich muss mir das nochmal kurz angucken.
>>
>> Eigentlich braucht man das vpn-select ja dann gar nicht mehr, weil
>das "select" macht ja dann fff-hoods (basierend auf dem json).
>>
>> Ich fänd es schön, wenn es unter /lib/wtf/functions pro VPN eine
>entsprechende "library" gibt, womit dann die jeweiligen VPNs
>hinzugefügt werden.
>>
>> Die stellen dann quasi eine Funktion wie:
>> add_fastd "$serverip" "$param2" ...
>> add_l2tpv3 "$serverip" "..."
>>
>> Das fff-hoods benutzt diese dann nur noch, je nach Inhalt der json
>Datei.
>>
>> Was denkst du?
>>
>> Tim
>>
>>
>>> Grüße
>>>
>>> Adrian
>>>
>>> -----Original Message-----
>>> From: Tim Niemeyer [mailto:tim@tn-x.org]
>>> Sent: Montag, 2. Oktober 2017 16:20
>>> To: Christian Dresel <fff@chrisi01.de>; franken-dev@freifunk.net
>>> Cc: mail@adrianschmutzler.de
>>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>>
>>> Hi
>>>
>>>
>>> Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
>>>> hi
>>>>
>>>> hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert
>daher 
>>>> bin ich die Mail mal eben überflogen und paar Kommentare Inline.
>>>>
>>>> On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
>>>>> Hallo,
>>>>>
>>>>> eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen 
>>>>> aufgefallen sind.
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On 
>>>>>> Behalf Of Adrian Schmutzler
>>>>>> Sent: Sonntag, 1. Oktober 2017 15:49
>>>>>> To: franken-dev@freifunk.net
>>>>>> Cc: Jan Kraus <mayosemmel@gmail.com>
>>>>>> Subject: [PATCH v10 4/4] Add fff-hoods
>>>>>>
>>>>>> From: Christian Dresel <fff@chrisi01.de>
>>>>>>
>>>>>> this packages connect to keyxchangev2 after review we must change
>
>>>>>> the serveradress! This is only a example
>>>>>>
>>>>>> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>>>>>> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>>>>>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>>>>>
>>>>>> Update in v2:
>>>>>>  - clean tabstops
>>>>>>  - move the json vpn out of the if because we need this after 
>>>>>> reboot
>>>>>>
>>>>>> Update in v5:
>>>>>> 	!!UNTESTED!!
>>>>>>  - change hidden AP ip to locallink
>>>>>>  - Open hidden AP after more checks
>>>>>>  - Load json File from Gateway if Gateway in Batman in Range
>>>>>>
>>>>>> Update in v6:
>>>>>> 	!!UNTESTED!!
>>>>>>  - fix hidden station v6
>>>>>>  - fix -n to -f if
>>>>>>  - Add function to check for a gateway and use this
>>>>>>  - remove /etc/community.cfg and variables
>>>>>>  - send fewer infos to keyxchangev2
>>>>>>  - add a check if /tmp/keyxchangev2 not downloadable and edit a 
>>>>>> bit on
>>>>> the
>>>>>> wgets
>>>>>>  - change the position from json_load and do this only 1 times
>>>>>>
>>>>>> Update in v7:
>>>>>> 	!!UNTESTED!!
>>>>>>  - delete keyxchangev2data at start of the script
>>>>>>  - do only things with keyxchangev2data if available
>>>>>>  - change keyxchangev2 url
>>>>>>
>>>>>> Update in v8/v9:
>>>>>>  - rebase onto 20170918-beta
>>>>>>
>>>>>> Update in v10:
>>>>>>  - Minor code fixes
>>>>>>  - Added fff-hoods to fff-base Makefile
>>>>>>  - Removed trailing whitespaces and harmonized tabs
>>>>>>  - Fixed some comments spelling
>>>>>>  - Added mac for hostname rewrite
>>>>>>  - Removed redundant check for /tmp/keyxchangev2data
>>>>>> ---
>>>>>>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>>>>>>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>>>>>>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>>>>>>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>>>>>> +++++++++++++++++++++
>>>>>>  src/packages/fff/fff/Makefile                      |   3 +-
>>>>>>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode
>>>>>> 100644 src/packages/fff/fff-hoods/Makefile
>>>>>>  create mode 100644 src/packages/fff/fff- 
>>>>>> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>>>>>  create mode 100644
>>>>>> src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>>>>>> hoods
>>>>>>  create mode 100755 src/packages/fff/fff- 
>>>>>> hoods/files/usr/sbin/configurehood
>>>>>>
>>>>>> diff --git a/src/packages/fff/fff-hoods/Makefile
>>>>>> b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index
>
>>>>>> 0000000..f85178d
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/Makefile
>>>>>> @@ -0,0 +1,39 @@
>>>>>> +include $(TOPDIR)/rules.mk
>>>>>> +
>>>>>> +PKG_NAME:=fff-hoods
>>>>>> +PKG_VERSION:=0.0.1
>>>>>> +PKG_RELEASE:=1
>>>>>> +
>>>>>> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>>>>>> +
>>>>>> +include $(INCLUDE_DIR)/package.mk
>>>>>> +
>>>>>> +define Package/fff-hoods
>>>>>> +    SECTION:=base
>>>>>> +    CATEGORY:=Freifunk
>>>>>> +    TITLE:= Freifunk-Franken hoods
>>>>>> +    URL:=http://www.freifunk-franken.de
>>>>>> +    DEPENDS:=+fff-network
>>>>>> +endef
>>>>>> +
>>>>>> +define Package/fff-hoods/description
>>>>>> +    This package load and configures the current hood endef
>>>>>> +
>>>>>> +define Build/Prepare
>>>>>> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>>>>>> +
>>>>>> +define Build/Configure
>>>>>> +	# nothing
>>>>>> +endef
>>>>>> +
>>>>>> +define Build/Compile
>>>>>> +	# nothing
>>>>>> +endef
>>>>>> +
>>>>>> +define Package/fff-hoods/install
>>>>>> +	$(CP) ./files/* $(1)/
>>>>>> +endef
>>>>>> +
>>>>>> +$(eval $(call BuildPackage,fff-hoods))
>>>>>> diff --git
>>>>> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
>>>>> s
>>>>>> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoo
>>>>>> ds
>>>>>> new file mode 100644
>>>>>> index 0000000..49f53e3
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff
>>>>>> +++ -h
>>>>>> +++ oods
>>>>>> @@ -0,0 +1,5 @@
>>>>>> +#!/bin/sh
>>>>>> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>>>>>> +       sleep 3
>>>>>> +       /usr/sbin/configurehood
>>>>>> +}
>>>>>> diff --git
>>>>>> a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>> new file mode 100644
>>>>>> index 0000000..ca8d798
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>> @@ -0,0 +1 @@
>>>>>> +*/5 * * * * /usr/sbin/configurehood
>>>>>> diff --git
>>>>>> a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>> new file mode 100755
>>>>>> index 0000000..ad316f8
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>> @@ -0,0 +1,206 @@
>>>>>> +#!/bin/sh
>>>>>> +
>>>>>> +. /usr/share/libubox/jshn.sh
>>>>>> +. /lib/functions/fff/wireless
>>>>>> +
>>>>>> +rm /tmp/keyxchangev2data
>>>>>> +
>>>>>> +# Gatewaycheck function
>>>>>> +isGatewayAvailable() {
>>>>>> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>>>>>> +		return true;
>>>>>> +	else
>>>>>> +		return false;
>>>>>> +	fi
>>>>>> +}
>>>>>> +
>>>>>> +
>>>>>> +# Hidden AP check
>>>>>> +
>>>>>> +if [ -f /tmp/hiddenapflag ]; then
>>>>>> +	if [ isGatewayAvailable ]; then
>>>>>> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
>>>>>> "configap" "configap" "1"; then
>>>>>> +			echo "Can't add AP interface on $radio."
>>>>>> +			exit 1
>>>>>> +		else
>>>>>> +			# We must set a fixed ip address here
>>>>>> +			uci set network.configap=interface
>>>>>> +			uci set network.configap.proto='static'
>>>>>> +			uci set network.configap.ip6addr='fe80::1/64'
>>>>>> +			uci commit network
>>>>>> +		fi
>>>>>> +	else
>>>>>> +		rm /tmp/hiddenapflag
>>>>>> +	fi
>>>>>> +fi
>>>>> Warum steht dieser ganze Block am Anfang und nicht am Schluss des
>Skripts?
>>>>> Hat das einen Grund, dass der immer einen Zyklus warten soll?
>>>> genau, Batman hat ein Timeout das wollen wir damit abfangen damit 
>>>> erst im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss
>also 
>>>> 5min eine Verbindung zum GW bestehen.
>>>>>
>>>>>
>>>>>> +
>>>>>> +
>>>>>> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>>>>>> +system.@system[0].longitude) hostname=$(cat
>>>>>> /proc/sys/kernel/hostname)
>>>>>> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
>>>>> Hier hab ich die Mac ergänzt.
>>>> das war einfach nur C&P
>>>>>> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = 
>>>>>> +"OpenWrt" ]
>>>>>> && hostname=""
>>>>>> +[ "$hostname" = "" ] &&  hostname="$mac"
>>>>> Wozu ist das gut? Sollte man das auf LEDE ändern?
>>>> hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht
>unsicher 
>>>> wofür es nötig ist.
>>> Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.
>>>
>>> Ja, das sollte man ändern. :) Good Catch!
>>>
>>>>>> +
>>>>>> +test_ipv4_host1="keyserver.freifunk-franken.de" # 
>>>>>> +Freifunk-Franken
>>>>>> keyserver
>>>>>> +test_ipv4_host2="8.8.8.8"        # Google DNS
>>>>>> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
>>>>>> +
>>>>>> +# if we have Internet, we download the Hoodfile from the
>>>>>> +keyxchangev2 if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>>>>>> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>>>>>> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>>>>>> +	wget -T15 -t5 "http://keyserver.freifunk-
>>>>>> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
>>>>>> +	#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
>>>>>> +	# Only do that, when we have no gateway in range. If the
>>>>>> Uplinkrouter changed the hood, we lost the GW and do this 
>>>>>> automatically again, I think! Nice idea?
>>>>>> +	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
>>>>>> +		if ! wifiDelAll; then
>>>>>> +			echo "Can't delete current wifi setup"
>>>>>> +			exit 1
>>>>>> +		fi
>>>>>> +		#now we look for phy and add this
>>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>>> +				echo "$phy is 2.4 GHz"
>>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>>> "$BATMAN_CHANNEL")
>>>>>> +				if [ -z "$radio" ]; then
>>>>>> +					echo "Can't create radio for $phy"
>>>>>> +					exit 1
>>>>>> +				fi
>>>>>> +			fi
>>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>>> +				echo "$phy is 5 GHz"
>>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>>> "$BATMAN_CHANNEL_5GHZ")
>>>>>> +				if [ -z "$radio" ]; then
>>>>>> +					echo "Can't create radio for $phy"
>>>>>> +					exit 1
>>>>>> +				fi
>>>>>> +			fi
>>>>> Hier werden Variablen aus der community.cfg verwendet 
>>>>> ($BATMAN...), unten ist hardgecodet. Das hier auch hardcoden?
>>>> macht vermutlich Sinn, weil wir die /etc/community.cfg eh
>abschaffen wollen.
>>> Richtig. Die Daten kommen ja (später mal) aus dem json hood file.
>Bis dahin sind sie halt hart kodiert. Um einen Übergang leichter zu
>machen könnte man überlegen, on man die Werte vielleicht einer
>Konstangen zuweist und diesen dann entsprechend verwendet. Das hätte
>den Vorteil, dass die Umstellung dann später einfacher wird.
>>>
>>>>>
>>>>>> +			#and here we add the station
>>>>>> +			if ! wifiAddSta "$radio"
>>>>> "config.franken.freifunk.net"
>>>>>> "configSta"; then
>>>>>> +				echo "Can't add Sta interface on $radio."
>>>>>> +				exit 1
>>>>>> +			fi
>>>>>> +
>>>>>> +		done
>>>>>> +
>>>>>> +		wifi
>>>>>> +		# 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
>>>>>> +	else
>>>>>> +		echo "We have a Gateway in Range, we load the
>>>>>> keyxchangev2data from fe80::1"
>>>>>> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
>>>>>> -O /tmp/keyxchangev2data
>>>>>> +	fi
>>>>>> +
>>>>>> +fi
>>>>>> +
>>>>>> +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!
>>>>>> +
>>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>>> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
>>>>>> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
>>>>>> | cut -f1 -d " ")
>>>>>> +	if [ "$sumnew" != "$sumold" ]; then
>>>>> Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht 
>>>>> irgendwie keinen Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ]
>schon geprüft haben?!
>>>> das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich 
>>>> mal zurück.
>>>>>
>>>>>> +		echo "New file detect, we reconfigure the Node";
>>>>>> +
>>>>>> +		# copy the file to webroot so that other Meshrouter can
>>>>>> download it
>>>>>> +		cp /tmp/keyxchangev2data /www/public/
>>>>>> +
>>>>>> +		json_select hood
>>>>>> +
>>>>>> +		json_get_var hood name
>>>>>> +		json_get_var mesh_bssid mesh_bssid
>>>>>> +		json_get_var mesh_essid mesh_essid
>>>>>> +		json_get_var essid essid
>>>>>> +		# i think the next things we don't active this in the first
>>>>>> version! we can do it later
>>>>>> +		#json_get_var channel2 channel2
>>>>>> +		#json_get_var mode2 mode2
>>>>>> +		#json_get_var type2 type2
>>>>>> +		#json_get_var channel5 channel5
>>>>>> +		#json_get_var mode5 mode5
>>>>>> +		#json_get_var type5 type5
>>>>>> +		#json_get_var protocol protocol
>>>>>> +
>>>>>> +		echo "Setting hood name: $hood"
>>>>>> +		uci set "system.@system[0].hood=$hood"
>>>>>> +
>>>>>> +		if ! wifiDelAll; then
>>>>>> +			echo "Can't delete current wifi setup"
>>>>>> +			exit 1
>>>>>> +		fi
>>>>>> +
>>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>>> +				echo "$phy is 2.4 GHz"
>>>>>> +				radio=$(wifiAddPhy "$phy" "1")
>>>>> Hier ist jetzt hardgecodet ... "1"
>>>> interessant, vermutlich hab ich es oben einfach vergessen und wollt
>
>>>> es wirklich überall hard coden weil eben /etc/community.cfg weg
>fällt.
>>>>>
>>>>>> +				if [ -z "$radio" ]; then
>>>>>> +					echo "Can't create radio for $phy"
>>>>>> +					exit 1
>>>>>> +				fi
>>>>>> +			fi
>>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>>> +				echo "$phy is 5 GHz"
>>>>>> +				radio=$(wifiAddPhy "$phy" "13")
>>>>>> +				if [ -z "$radio" ]; then
>>>>>> +					echo "Can't create radio for $phy"
>>>>>> +					exit 1
>>>>>> +				fi
>>>>>> +			fi
>>>>>> +
>>>>>> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
>>>>> then
>>>>>> +				echo "Can't add AP interface on $radio."
>>>>>> +				exit 1
>>>>>> +			fi
>>>>>> +
>>>>>> +			# here we set a bit for add hidden AP
>>>>>> +			touch /tmp/hiddenapflag
>>>>>> +
>>>>>> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
>>>>>> "$mesh_bssid"; then
>>>>>> +				echo "Can't add AP interface on $radio."
>>>>>> +				exit 1
>>>>>> +			fi
>>>>>> +		done
>>>>>> +
>>>>>> +		echo "Loading wifi"
>>>>>> +		wifi
>>>>>> +
>>>>>> +	else
>>>>>> +		echo "We have no new file or we haven't got a file. We do
>>>>>> nothing. We try it again in 5 minutes...";
>>>>> Meines Erachtens ist hier nur "We have no new file" erfüllt. Der 
>>>>> andere Fall wäre eine if weiter außen. Siehe [ ! -f
>/tmp/keyxchangev2data] ...
>>>> muss ich mir auch mal in Ruhe angucken...
>>>>>
>>>>>> +	fi
>>>>>> +
>>>>>> +	# and now we read the VPN Data and give this data to fff-vpn
>>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>>> +
>>>>>> +	json_select vpn
>>>>>> +	Index="1"
>>>>>> +	rm /tmp/fastd_fff_output
>>>>>> +	touch /tmp/fastd_fff_output
>>>>>> +	while json_select $Index > /dev/null
>>>>> Wieso while wenn nur ein Element "1"?
>>>> es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit 
>>>> einer Schleife durchgehen oder?
>>>>>
>>>>>> +	do
>>>>>> +		json_get_var protocol protocol
>>>>>> +		if [ "$protocol" == "fastd" ]; then
>>>>>> +			json_get_var servername name
>>>>>> +			echo "####${servername}.conf" >>
>>>>>> /tmp/fastd_fff_output
>>>>>> +			echo "#name \"${servername}\";" >>
>>>>>> /tmp/fastd_fff_output
>>>>>> +			json_get_var key key
>>>>>> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
>>>>>> +			json_get_var address address
>>>>>> +			json_get_var port port
>>>>>> +			echo "remote ipv4 \"${address}\" port $port float;"
>>>>>>>> /tmp/fastd_fff_output
>>>>>> +		fi
>>>>>> +		echo "" >> /tmp/fastd_fff_output
>>>>>> +		echo "###" >> /tmp/fastd_fff_output
>>>>> Die beiden kommen ja nur einmal am Schluss, also müssen sie aus 
>>>>> dem while raus, oder?
>>>> oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab
>ich 
>>>> das ganze noch nicht getestet, RedDog wollte das aber eh relativ 
>>>> zügig umbauen weil das Format einfach sh*t ist, besser ist wenn 
>>>> fff-vpn die json direkt ausliest.
>>> Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder
>tunneldigger genommen wird auch nicht an einer per http download'baren
>Datei festmachen, sondern hier nach dem json file entsprechend machen.
>>>
>>> Tim
>>>
>>>
>>>> mfg
>>>>
>>>> Christian
>>>>> Grüße
>>>>>
>>>>> Adrian
>>>>>
>>>>>
>>>>>> +	done
>>>>>> +	#this we do every 5 minutes, because it can change the VPN
>Protocol
>>>>>> +	#and now we get to vpn-select Script and load VPNs
>>>>>> +	sh /usr/sbin/vpn-select
>>>>>> +fi
>>>>>> diff --git a/src/packages/fff/fff/Makefile 
>>>>>> b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
>>>>>> --- a/src/packages/fff/fff/Makefile
>>>>>> +++ b/src/packages/fff/fff/Makefile
>>>>>> @@ -29,7 +29,8 @@ define Package/fff-base
>>>>>>               +fff-wireless \
>>>>>>               +fff-timeserver \
>>>>>>               +fff-vpn-select \
>>>>>> -             +simple-tc
>>>>>> +             +simple-tc \
>>>>>> +             +fff-hoods
>>>>>>  endef
>>>>>>
>>>>>>  define Package/fff-base/description
>>>>>> --
>>>>>> 2.7.4
>>>>>>
>>>>>> --
>>>>>> franken-dev mailing list
>>>>>> franken-dev@freifunk.net
>>>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.n
>>>>>> et
>>>>
>>>> --
>>>> franken-dev mailing list
>>>> franken-dev@freifunk.net
>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>>>
>>
Alex Gutfried Oct. 4, 2017, 10:50 a.m.
Am 04.10.2017 12:22 schrieb "Tim Niemeyer" <tim@tn-x.org>:

Hi

Am 4. Oktober 2017 12:09:53 MESZ schrieb robert <rlanghammer@web.de>:
>Hallo,
>
>mir gefaellt das auch sehr gut. Es bleibt noch die Frage, woher bekommt
>man die VPN Zugangsdaten, damit man am Gateway flexibel bleibt?

Die Knoten bekommen sie vom zentralen keyXchangeV2 oder durch den configAP
ihres Nachbarn. Die Gateways sollen jede Verbindung annehmen, sofern sie
nicht blacklisted ist.


>Ich faende es schoen, wenn ich am Gateway den Zugang festlegen koennte.
>Aktuell koennen die Ropter fastd und l2tp. Da koennen auch noch welche
>dazu kommen. Und am Gateway entscheide ich dann, was ich anbieten
>moechte. Das bedeutet, der Uplinkrouter bekommt vom KeyX nur die IPs
>der
>GWs und erfragt bei denen die VPN Daten.

Ich bin eher dagegen, dass die GWs erst befragt werden müssen. Das steht ja
schon in der Hoodfile drin was für das Gateway zu nehmen ist. Wenn ein
Knoten später mal ein Hoodfile hat, was er nicht unterstützt kann er so
einfach das nächste nehmen.


Also entweder hab ich's noch nicht ganz verstanden oder ich bin eher RoLa's
Meinung.

Momentan biete ich fastd und Tunneldigger an. Also veröffentliche ich eine
File mit.

Has, l2tp:"Port", fastd:"Port"
Hassued, l2tp:"Port", fastd:"Port"

... Oder wie auch immer das Mal aussehen mag. Kann natürlich auch der keyex.

Wenn ich morgen allerdings beschließe kein fastd mehr anzubieten nehme ich
einfach den entsprechenden Absatz raus ohne mir erst lang nen keyex2 Admin
suchen zu müssen.

LG Alex



>So wird es dann auch recht einfach neue VPN Varianten zu integrieren.

Ne, eben nicht. Denn die alten Knoten würden das Angebot einer Hood
vielleicht nicht unterstützten und könnten dann keine Alternative wählen.

>Was meint Ihr?
Ich denke immer noch, dass es reichen sollte wenn die Knoten sich eine Hood
auswählen, und dann das Gateway wählen was sie mögen. Sollte dann mal ein
Knoten die angebotenen VPNs nicht unterstützten, kann er einfach die
nächste Hood wählen.

Tim


>
>Robert
>
>
>Am 04.10.2017 um 11:29 schrieb Adrian Schmutzler:
>> Hallo Tim,
>>
>> für mich, der ich eigtl ein OOP Programmierer bin, hat der Vorschlag
>mit der Library natürlich sehr viel Charme.
>>
>> Folgende Überlegungen:
>> 1. Im Moment würde ich das erstmal hintanstellen, da Zeit
>> 2. Da im Moment fastd und tunneldigger ja nicht parallel, sondern
>hierarchisch ineinander aufgerufen werden, müsste man glaube ich erst
>deine Diskussion diesbezüglich mit Christian auflösen, bevor man das
>"ordentlich" machen kann.
>> 3. Irgendwann könnte der "Stumpf" von vpn-select in die fff-hoods mit
>rein wandern, da erstere nichts mehr sonst in der Package hat und eh
>nur von fff-hoods gecallt wird.
>>
>> Grüße
>>
>> Adrian
>>
>> -----Original Message-----
>> From: Tim Niemeyer [mailto:tim@tn-x.org]
>> Sent: Montag, 2. Oktober 2017 16:29
>> To: Adrian Schmutzler <mail@adrianschmutzler.de>
>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>
>> Am Montag, den 02.10.2017, 16:23 +0200 schrieb Adrian Schmutzler:
>>> Hallo,
>>>
>>> danke für die Hinweise. Ein Teil ist schon im neuen v11 Patch drin.
>> Habs grad gesehen. Prima! :)
>>
>>> Bin grade selber dabei, das vpn-select auf json umzustellen.
>> Ah.. Haha.. :)
>>
>> Dann is Christian ja Overruled.. :P
>>
>> Wie genau planst du das? Ich muss mir das nochmal kurz angucken.
>>
>> Eigentlich braucht man das vpn-select ja dann gar nicht mehr, weil
>das "select" macht ja dann fff-hoods (basierend auf dem json).
>>
>> Ich fänd es schön, wenn es unter /lib/wtf/functions pro VPN eine
>entsprechende "library" gibt, womit dann die jeweiligen VPNs
>hinzugefügt werden.
>>
>> Die stellen dann quasi eine Funktion wie:
>> add_fastd "$serverip" "$param2" ...
>> add_l2tpv3 "$serverip" "..."
>>
>> Das fff-hoods benutzt diese dann nur noch, je nach Inhalt der json
>Datei.
>>
>> Was denkst du?
>>
>> Tim
>>
>>
>>> Grüße
>>>
>>> Adrian
>>>
>>> -----Original Message-----
>>> From: Tim Niemeyer [mailto:tim@tn-x.org]
>>> Sent: Montag, 2. Oktober 2017 16:20
>>> To: Christian Dresel <fff@chrisi01.de>; franken-dev@freifunk.net
>>> Cc: mail@adrianschmutzler.de
>>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>>
>>> Hi
>>>
>>>
>>> Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
>>>> hi
>>>>
>>>> hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert
>daher
>>>> bin ich die Mail mal eben überflogen und paar Kommentare Inline.
>>>>
>>>> On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
>>>>> Hallo,
>>>>>
>>>>> eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen
>>>>> aufgefallen sind.
>>>>>
>>>>>> -----Original Message-----
>>>>>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On
>>>>>> Behalf Of Adrian Schmutzler
>>>>>> Sent: Sonntag, 1. Oktober 2017 15:49
>>>>>> To: franken-dev@freifunk.net
>>>>>> Cc: Jan Kraus <mayosemmel@gmail.com>
>>>>>> Subject: [PATCH v10 4/4] Add fff-hoods
>>>>>>
>>>>>> From: Christian Dresel <fff@chrisi01.de>
>>>>>>
>>>>>> this packages connect to keyxchangev2 after review we must change
>
>>>>>> the serveradress! This is only a example
>>>>>>
>>>>>> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>>>>>> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>>>>>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>>>>>
>>>>>> Update in v2:
>>>>>>  - clean tabstops
>>>>>>  - move the json vpn out of the if because we need this after
>>>>>> reboot
>>>>>>
>>>>>> Update in v5:
>>>>>>  !!UNTESTED!!
>>>>>>  - change hidden AP ip to locallink
>>>>>>  - Open hidden AP after more checks
>>>>>>  - Load json File from Gateway if Gateway in Batman in Range
>>>>>>
>>>>>> Update in v6:
>>>>>>  !!UNTESTED!!
>>>>>>  - fix hidden station v6
>>>>>>  - fix -n to -f if
>>>>>>  - Add function to check for a gateway and use this
>>>>>>  - remove /etc/community.cfg and variables
>>>>>>  - send fewer infos to keyxchangev2
>>>>>>  - add a check if /tmp/keyxchangev2 not downloadable and edit a
>>>>>> bit on
>>>>> the
>>>>>> wgets
>>>>>>  - change the position from json_load and do this only 1 times
>>>>>>
>>>>>> Update in v7:
>>>>>>  !!UNTESTED!!
>>>>>>  - delete keyxchangev2data at start of the script
>>>>>>  - do only things with keyxchangev2data if available
>>>>>>  - change keyxchangev2 url
>>>>>>
>>>>>> Update in v8/v9:
>>>>>>  - rebase onto 20170918-beta
>>>>>>
>>>>>> Update in v10:
>>>>>>  - Minor code fixes
>>>>>>  - Added fff-hoods to fff-base Makefile
>>>>>>  - Removed trailing whitespaces and harmonized tabs
>>>>>>  - Fixed some comments spelling
>>>>>>  - Added mac for hostname rewrite
>>>>>>  - Removed redundant check for /tmp/keyxchangev2data
>>>>>> ---
>>>>>>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>>>>>>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>>>>>>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>>>>>>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>>>>>> +++++++++++++++++++++
>>>>>>  src/packages/fff/fff/Makefile                      |   3 +-
>>>>>>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode
>>>>>> 100644 src/packages/fff/fff-hoods/Makefile
>>>>>>  create mode 100644 src/packages/fff/fff-
>>>>>> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>>>>>  create mode 100644
>>>>>> src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>>>>>> hoods
>>>>>>  create mode 100755 src/packages/fff/fff-
>>>>>> hoods/files/usr/sbin/configurehood
>>>>>>
>>>>>> diff --git a/src/packages/fff/fff-hoods/Makefile
>>>>>> b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index
>
>>>>>> 0000000..f85178d
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/Makefile
>>>>>> @@ -0,0 +1,39 @@
>>>>>> +include $(TOPDIR)/rules.mk
>>>>>> +
>>>>>> +PKG_NAME:=fff-hoods
>>>>>> +PKG_VERSION:=0.0.1
>>>>>> +PKG_RELEASE:=1
>>>>>> +
>>>>>> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>>>>>> +
>>>>>> +include $(INCLUDE_DIR)/package.mk
>>>>>> +
>>>>>> +define Package/fff-hoods
>>>>>> +    SECTION:=base
>>>>>> +    CATEGORY:=Freifunk
>>>>>> +    TITLE:= Freifunk-Franken hoods
>>>>>> +    URL:=http://www.freifunk-franken.de
>>>>>> +    DEPENDS:=+fff-network
>>>>>> +endef
>>>>>> +
>>>>>> +define Package/fff-hoods/description
>>>>>> +    This package load and configures the current hood endef
>>>>>> +
>>>>>> +define Build/Prepare
>>>>>> +        echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>>>>>> +
>>>>>> +define Build/Configure
>>>>>> +        # nothing
>>>>>> +endef
>>>>>> +
>>>>>> +define Build/Compile
>>>>>> +        # nothing
>>>>>> +endef
>>>>>> +
>>>>>> +define Package/fff-hoods/install
>>>>>> +        $(CP) ./files/* $(1)/
>>>>>> +endef
>>>>>> +
>>>>>> +$(eval $(call BuildPackage,fff-hoods))
>>>>>> diff --git
>>>>> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
>>>>> s
>>>>>> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoo
>>>>>> ds
>>>>>> new file mode 100644
>>>>>> index 0000000..49f53e3
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff
>>>>>> +++ -h
>>>>>> +++ oods
>>>>>> @@ -0,0 +1,5 @@
>>>>>> +#!/bin/sh
>>>>>> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>>>>>> +       sleep 3
>>>>>> +       /usr/sbin/configurehood
>>>>>> +}
>>>>>> diff --git
>>>>>> a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>> new file mode 100644
>>>>>> index 0000000..ca8d798
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>> @@ -0,0 +1 @@
>>>>>> +*/5 * * * * /usr/sbin/configurehood
>>>>>> diff --git
>>>>>> a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>> new file mode 100755
>>>>>> index 0000000..ad316f8
>>>>>> --- /dev/null
>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>> @@ -0,0 +1,206 @@
>>>>>> +#!/bin/sh
>>>>>> +
>>>>>> +. /usr/share/libubox/jshn.sh
>>>>>> +. /lib/functions/fff/wireless
>>>>>> +
>>>>>> +rm /tmp/keyxchangev2data
>>>>>> +
>>>>>> +# Gatewaycheck function
>>>>>> +isGatewayAvailable() {
>>>>>> +        if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>>>>>> +                return true;
>>>>>> +        else
>>>>>> +                return false;
>>>>>> +        fi
>>>>>> +}
>>>>>> +
>>>>>> +
>>>>>> +# Hidden AP check
>>>>>> +
>>>>>> +if [ -f /tmp/hiddenapflag ]; then
>>>>>> +        if [ isGatewayAvailable ]; then
>>>>>> +                if ! wifiAddAP "$radio" "config.franken.freifunk.net
"
>>>>>> "configap" "configap" "1"; then
>>>>>> +                        echo "Can't add AP interface on $radio."
>>>>>> +                        exit 1
>>>>>> +                else
>>>>>> +                        # We must set a fixed ip address here
>>>>>> +                        uci set network.configap=interface
>>>>>> +                        uci set network.configap.proto='static'
>>>>>> +                        uci set network.configap.ip6addr='
fe80::1/64'
>>>>>> +                        uci commit network
>>>>>> +                fi
>>>>>> +        else
>>>>>> +                rm /tmp/hiddenapflag
>>>>>> +        fi
>>>>>> +fi
>>>>> Warum steht dieser ganze Block am Anfang und nicht am Schluss des
>Skripts?
>>>>> Hat das einen Grund, dass der immer einen Zyklus warten soll?
>>>> genau, Batman hat ein Timeout das wollen wir damit abfangen damit
>>>> erst im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss
>also
>>>> 5min eine Verbindung zum GW bestehen.
>>>>>
>>>>>
>>>>>> +
>>>>>> +
>>>>>> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>>>>>> +system.@system[0].longitude) hostname=$(cat
>>>>>> /proc/sys/kernel/hostname)
>>>>>> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
>>>>> Hier hab ich die Mac ergänzt.
>>>> das war einfach nur C&P
>>>>>> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" =
>>>>>> +"OpenWrt" ]
>>>>>> && hostname=""
>>>>>> +[ "$hostname" = "" ] &&  hostname="$mac"
>>>>> Wozu ist das gut? Sollte man das auf LEDE ändern?
>>>> hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht
>unsicher
>>>> wofür es nötig ist.
>>> Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.
>>>
>>> Ja, das sollte man ändern. :) Good Catch!
>>>
>>>>>> +
>>>>>> +test_ipv4_host1="keyserver.freifunk-franken.de" #
>>>>>> +Freifunk-Franken
>>>>>> keyserver
>>>>>> +test_ipv4_host2="8.8.8.8"        # Google DNS
>>>>>> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
>>>>>> +
>>>>>> +# if we have Internet, we download the Hoodfile from the
>>>>>> +keyxchangev2 if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>>>>>> +        ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>>>>>> +        ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>>>>>> +        wget -T15 -t5 "http://keyserver.freifunk-
>>>>>> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
>>>>>> +        #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
>>>>>> +        # Only do that, when we have no gateway in range. If the
>>>>>> Uplinkrouter changed the hood, we lost the GW and do this
>>>>>> automatically again, I think! Nice idea?
>>>>>> +        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
>>>>>> +                if ! wifiDelAll; then
>>>>>> +                        echo "Can't delete current wifi setup"
>>>>>> +                        exit 1
>>>>>> +                fi
>>>>>> +                #now we look for phy and add this
>>>>>> +                for phy in $(iw phy | awk '/^Wiphy/{ print $2 }');
do
>>>>>> +                        if iw phy "$phy" info | grep -q -m1 "2...
MHz"; then
>>>>>> +                                echo "$phy is 2.4 GHz"
>>>>>> +                                radio=$(wifiAddPhy "$phy"
>>>>>> "$BATMAN_CHANNEL")
>>>>>> +                                if [ -z "$radio" ]; then
>>>>>> +                                        echo "Can't create radio
for $phy"
>>>>>> +                                        exit 1
>>>>>> +                                fi
>>>>>> +                        fi
>>>>>> +                        if iw phy "$phy" info | grep -q -m1 "5...
MHz"; then
>>>>>> +                                echo "$phy is 5 GHz"
>>>>>> +                                radio=$(wifiAddPhy "$phy"
>>>>>> "$BATMAN_CHANNEL_5GHZ")
>>>>>> +                                if [ -z "$radio" ]; then
>>>>>> +                                        echo "Can't create radio
for $phy"
>>>>>> +                                        exit 1
>>>>>> +                                fi
>>>>>> +                        fi
>>>>> Hier werden Variablen aus der community.cfg verwendet
>>>>> ($BATMAN...), unten ist hardgecodet. Das hier auch hardcoden?
>>>> macht vermutlich Sinn, weil wir die /etc/community.cfg eh
>abschaffen wollen.
>>> Richtig. Die Daten kommen ja (später mal) aus dem json hood file.
>Bis dahin sind sie halt hart kodiert. Um einen Übergang leichter zu
>machen könnte man überlegen, on man die Werte vielleicht einer
>Konstangen zuweist und diesen dann entsprechend verwendet. Das hätte
>den Vorteil, dass die Umstellung dann später einfacher wird.
>>>
>>>>>
>>>>>> +                        #and here we add the station
>>>>>> +                        if ! wifiAddSta "$radio"
>>>>> "config.franken.freifunk.net"
>>>>>> "configSta"; then
>>>>>> +                                echo "Can't add Sta interface on
$radio."
>>>>>> +                                exit 1
>>>>>> +                        fi
>>>>>> +
>>>>>> +                done
>>>>>> +
>>>>>> +                wifi
>>>>>> +                # 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
>>>>>> +        else
>>>>>> +                echo "We have a Gateway in Range, we load the
>>>>>> keyxchangev2data from fe80::1"
>>>>>> +                wget -T15 -t5 "http://[fe80::1%br-mesh]/
keyxchangev2data"
>>>>>> -O /tmp/keyxchangev2data
>>>>>> +        fi
>>>>>> +
>>>>>> +fi
>>>>>> +
>>>>>> +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!
>>>>>> +
>>>>>> +        json_load "$(cat /tmp/keyxchangev2data)"
>>>>>> +        sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
>>>>>> +        sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
>>>>>> | cut -f1 -d " ")
>>>>>> +        if [ "$sumnew" != "$sumold" ]; then
>>>>> Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht
>>>>> irgendwie keinen Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ]
>schon geprüft haben?!
>>>> das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich
>>>> mal zurück.
>>>>>
>>>>>> +                echo "New file detect, we reconfigure the Node";
>>>>>> +
>>>>>> +                # copy the file to webroot so that other Meshrouter
can
>>>>>> download it
>>>>>> +                cp /tmp/keyxchangev2data /www/public/
>>>>>> +
>>>>>> +                json_select hood
>>>>>> +
>>>>>> +                json_get_var hood name
>>>>>> +                json_get_var mesh_bssid mesh_bssid
>>>>>> +                json_get_var mesh_essid mesh_essid
>>>>>> +                json_get_var essid essid
>>>>>> +                # i think the next things we don't active this in
the first
>>>>>> version! we can do it later
>>>>>> +                #json_get_var channel2 channel2
>>>>>> +                #json_get_var mode2 mode2
>>>>>> +                #json_get_var type2 type2
>>>>>> +                #json_get_var channel5 channel5
>>>>>> +                #json_get_var mode5 mode5
>>>>>> +                #json_get_var type5 type5
>>>>>> +                #json_get_var protocol protocol
>>>>>> +
>>>>>> +                echo "Setting hood name: $hood"
>>>>>> +                uci set "system.@system[0].hood=$hood"
>>>>>> +
>>>>>> +                if ! wifiDelAll; then
>>>>>> +                        echo "Can't delete current wifi setup"
>>>>>> +                        exit 1
>>>>>> +                fi
>>>>>> +
>>>>>> +                for phy in $(iw phy | awk '/^Wiphy/{ print $2 }');
do
>>>>>> +                        if iw phy "$phy" info | grep -q -m1 "2...
MHz"; then
>>>>>> +                                echo "$phy is 2.4 GHz"
>>>>>> +                                radio=$(wifiAddPhy "$phy" "1")
>>>>> Hier ist jetzt hardgecodet ... "1"
>>>> interessant, vermutlich hab ich es oben einfach vergessen und wollt
>
>>>> es wirklich überall hard coden weil eben /etc/community.cfg weg
>fällt.
>>>>>
>>>>>> +                                if [ -z "$radio" ]; then
>>>>>> +                                        echo "Can't create radio
for $phy"
>>>>>> +                                        exit 1
>>>>>> +                                fi
>>>>>> +                        fi
>>>>>> +                        if iw phy "$phy" info | grep -q -m1 "5...
MHz"; then
>>>>>> +                                echo "$phy is 5 GHz"
>>>>>> +                                radio=$(wifiAddPhy "$phy" "13")
>>>>>> +                                if [ -z "$radio" ]; then
>>>>>> +                                        echo "Can't create radio
for $phy"
>>>>>> +                                        exit 1
>>>>>> +                                fi
>>>>>> +                        fi
>>>>>> +
>>>>>> +                        if ! wifiAddAP "$radio" "$essid" "mesh"
"ap" "0";
>>>>> then
>>>>>> +                                echo "Can't add AP interface on
$radio."
>>>>>> +                                exit 1
>>>>>> +                        fi
>>>>>> +
>>>>>> +                        # here we set a bit for add hidden AP
>>>>>> +                        touch /tmp/hiddenapflag
>>>>>> +
>>>>>> +                        if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
>>>>>> "$mesh_bssid"; then
>>>>>> +                                echo "Can't add AP interface on
$radio."
>>>>>> +                                exit 1
>>>>>> +                        fi
>>>>>> +                done
>>>>>> +
>>>>>> +                echo "Loading wifi"
>>>>>> +                wifi
>>>>>> +
>>>>>> +        else
>>>>>> +                echo "We have no new file or we haven't got a file.
We do
>>>>>> nothing. We try it again in 5 minutes...";
>>>>> Meines Erachtens ist hier nur "We have no new file" erfüllt. Der
>>>>> andere Fall wäre eine if weiter außen. Siehe [ ! -f
>/tmp/keyxchangev2data] ...
>>>> muss ich mir auch mal in Ruhe angucken...
>>>>>
>>>>>> +        fi
>>>>>> +
>>>>>> +        # and now we read the VPN Data and give this data to fff-vpn
>>>>>> +        json_load "$(cat /tmp/keyxchangev2data)"
>>>>>> +
>>>>>> +        json_select vpn
>>>>>> +        Index="1"
>>>>>> +        rm /tmp/fastd_fff_output
>>>>>> +        touch /tmp/fastd_fff_output
>>>>>> +        while json_select $Index > /dev/null
>>>>> Wieso while wenn nur ein Element "1"?
>>>> es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit
>>>> einer Schleife durchgehen oder?
>>>>>
>>>>>> +        do
>>>>>> +                json_get_var protocol protocol
>>>>>> +                if [ "$protocol" == "fastd" ]; then
>>>>>> +                        json_get_var servername name
>>>>>> +                        echo "####${servername}.conf" >>
>>>>>> /tmp/fastd_fff_output
>>>>>> +                        echo "#name \"${servername}\";" >>
>>>>>> /tmp/fastd_fff_output
>>>>>> +                        json_get_var key key
>>>>>> +                        echo "key \"${key}\";" >>
/tmp/fastd_fff_output
>>>>>> +                        json_get_var address address
>>>>>> +                        json_get_var port port
>>>>>> +                        echo "remote ipv4 \"${address}\" port $port
float;"
>>>>>>>> /tmp/fastd_fff_output
>>>>>> +                fi
>>>>>> +                echo "" >> /tmp/fastd_fff_output
>>>>>> +                echo "###" >> /tmp/fastd_fff_output
>>>>> Die beiden kommen ja nur einmal am Schluss, also müssen sie aus
>>>>> dem while raus, oder?
>>>> oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab
>ich
>>>> das ganze noch nicht getestet, RedDog wollte das aber eh relativ
>>>> zügig umbauen weil das Format einfach sh*t ist, besser ist wenn
>>>> fff-vpn die json direkt ausliest.
>>> Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder
>tunneldigger genommen wird auch nicht an einer per http download'baren
>Datei festmachen, sondern hier nach dem json file entsprechend machen.
>>>
>>> Tim
>>>
>>>
>>>> mfg
>>>>
>>>> Christian
>>>>> Grüße
>>>>>
>>>>> Adrian
>>>>>
>>>>>
>>>>>> +        done
>>>>>> +        #this we do every 5 minutes, because it can change the VPN
>Protocol
>>>>>> +        #and now we get to vpn-select Script and load VPNs
>>>>>> +        sh /usr/sbin/vpn-select
>>>>>> +fi
>>>>>> diff --git a/src/packages/fff/fff/Makefile
>>>>>> b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
>>>>>> --- a/src/packages/fff/fff/Makefile
>>>>>> +++ b/src/packages/fff/fff/Makefile
>>>>>> @@ -29,7 +29,8 @@ define Package/fff-base
>>>>>>               +fff-wireless \
>>>>>>               +fff-timeserver \
>>>>>>               +fff-vpn-select \
>>>>>> -             +simple-tc
>>>>>> +             +simple-tc \
>>>>>> +             +fff-hoods
>>>>>>  endef
>>>>>>
>>>>>>  define Package/fff-base/description
>>>>>> --
>>>>>> 2.7.4
>>>>>>
>>>>>> --
>>>>>> franken-dev mailing list
>>>>>> franken-dev@freifunk.net
>>>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.n
>>>>>> et
>>>>
>>>> --
>>>> franken-dev mailing list
>>>> franken-dev@freifunk.net
>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>>>
>>
--
franken-dev mailing list
franken-dev@freifunk.net
http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Robert Langhammer Oct. 4, 2017, 11 a.m.
Am 04.10.2017 um 12:21 schrieb Tim Niemeyer:
> Hi
>
> Am 4. Oktober 2017 12:09:53 MESZ schrieb robert <rlanghammer@web.de>:
>> Hallo,
>>
>> mir gefaellt das auch sehr gut. Es bleibt noch die Frage, woher bekommt
>> man die VPN Zugangsdaten, damit man am Gateway flexibel bleibt?
> Die Knoten bekommen sie vom zentralen keyXchangeV2 oder durch den configAP ihres Nachbarn. Die Gateways sollen jede Verbindung annehmen, sofern sie nicht blacklisted ist.
>
>
>> Ich faende es schoen, wenn ich am Gateway den Zugang festlegen koennte.
>> Aktuell koennen die Ropter fastd und l2tp. Da koennen auch noch welche
>> dazu kommen. Und am Gateway entscheide ich dann, was ich anbieten
>> moechte. Das bedeutet, der Uplinkrouter bekommt vom KeyX nur die IPs
>> der
>> GWs und erfragt bei denen die VPN Daten.
> Ich bin eher dagegen, dass die GWs erst befragt werden müssen. Das steht ja schon in der Hoodfile drin was für das Gateway zu nehmen ist. Wenn ein Knoten später mal ein Hoodfile hat, was er nicht unterstützt kann er so einfach das nächste nehmen.
Muss man sich jetzt fuer eine Variante entscheiden, wenn man das GW in
den Keyex eintragen laesst? Oder soll man beide anbieten und die Router
entscheiden was genommen wird?
Robert
>
>
>> So wird es dann auch recht einfach neue VPN Varianten zu integrieren.
> Ne, eben nicht. Denn die alten Knoten würden das Angebot einer Hood vielleicht nicht unterstützten und könnten dann keine Alternative wählen.
>
>> Was meint Ihr?
> Ich denke immer noch, dass es reichen sollte wenn die Knoten sich eine Hood auswählen, und dann das Gateway wählen was sie mögen. Sollte dann mal ein Knoten die angebotenen VPNs nicht unterstützten, kann er einfach die nächste Hood wählen.
>
> Tim
>
>
>> Robert
>>
>>
>> Am 04.10.2017 um 11:29 schrieb Adrian Schmutzler:
>>> Hallo Tim,
>>>
>>> für mich, der ich eigtl ein OOP Programmierer bin, hat der Vorschlag
>> mit der Library natürlich sehr viel Charme.
>>> Folgende Überlegungen:
>>> 1. Im Moment würde ich das erstmal hintanstellen, da Zeit
>>> 2. Da im Moment fastd und tunneldigger ja nicht parallel, sondern
>> hierarchisch ineinander aufgerufen werden, müsste man glaube ich erst
>> deine Diskussion diesbezüglich mit Christian auflösen, bevor man das
>> "ordentlich" machen kann.
>>> 3. Irgendwann könnte der "Stumpf" von vpn-select in die fff-hoods mit
>> rein wandern, da erstere nichts mehr sonst in der Package hat und eh
>> nur von fff-hoods gecallt wird.
>>> Grüße
>>>
>>> Adrian
>>>
>>> -----Original Message-----
>>> From: Tim Niemeyer [mailto:tim@tn-x.org] 
>>> Sent: Montag, 2. Oktober 2017 16:29
>>> To: Adrian Schmutzler <mail@adrianschmutzler.de>
>>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>>
>>> Am Montag, den 02.10.2017, 16:23 +0200 schrieb Adrian Schmutzler:
>>>> Hallo,
>>>>
>>>> danke für die Hinweise. Ein Teil ist schon im neuen v11 Patch drin.
>>> Habs grad gesehen. Prima! :)
>>>
>>>> Bin grade selber dabei, das vpn-select auf json umzustellen.
>>> Ah.. Haha.. :)
>>>
>>> Dann is Christian ja Overruled.. :P
>>>
>>> Wie genau planst du das? Ich muss mir das nochmal kurz angucken.
>>>
>>> Eigentlich braucht man das vpn-select ja dann gar nicht mehr, weil
>> das "select" macht ja dann fff-hoods (basierend auf dem json).
>>> Ich fänd es schön, wenn es unter /lib/wtf/functions pro VPN eine
>> entsprechende "library" gibt, womit dann die jeweiligen VPNs
>> hinzugefügt werden.
>>> Die stellen dann quasi eine Funktion wie:
>>> add_fastd "$serverip" "$param2" ...
>>> add_l2tpv3 "$serverip" "..."
>>>
>>> Das fff-hoods benutzt diese dann nur noch, je nach Inhalt der json
>> Datei.
>>> Was denkst du?
>>>
>>> Tim
>>>
>>>
>>>> Grüße
>>>>
>>>> Adrian
>>>>
>>>> -----Original Message-----
>>>> From: Tim Niemeyer [mailto:tim@tn-x.org]
>>>> Sent: Montag, 2. Oktober 2017 16:20
>>>> To: Christian Dresel <fff@chrisi01.de>; franken-dev@freifunk.net
>>>> Cc: mail@adrianschmutzler.de
>>>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>>>
>>>> Hi
>>>>
>>>>
>>>> Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
>>>>> hi
>>>>>
>>>>> hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert
>> daher 
>>>>> bin ich die Mail mal eben überflogen und paar Kommentare Inline.
>>>>>
>>>>> On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
>>>>>> Hallo,
>>>>>>
>>>>>> eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen 
>>>>>> aufgefallen sind.
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On 
>>>>>>> Behalf Of Adrian Schmutzler
>>>>>>> Sent: Sonntag, 1. Oktober 2017 15:49
>>>>>>> To: franken-dev@freifunk.net
>>>>>>> Cc: Jan Kraus <mayosemmel@gmail.com>
>>>>>>> Subject: [PATCH v10 4/4] Add fff-hoods
>>>>>>>
>>>>>>> From: Christian Dresel <fff@chrisi01.de>
>>>>>>>
>>>>>>> this packages connect to keyxchangev2 after review we must change
>>>>>>> the serveradress! This is only a example
>>>>>>>
>>>>>>> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>>>>>>> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>>>>>>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>>>>>>
>>>>>>> Update in v2:
>>>>>>>  - clean tabstops
>>>>>>>  - move the json vpn out of the if because we need this after 
>>>>>>> reboot
>>>>>>>
>>>>>>> Update in v5:
>>>>>>> 	!!UNTESTED!!
>>>>>>>  - change hidden AP ip to locallink
>>>>>>>  - Open hidden AP after more checks
>>>>>>>  - Load json File from Gateway if Gateway in Batman in Range
>>>>>>>
>>>>>>> Update in v6:
>>>>>>> 	!!UNTESTED!!
>>>>>>>  - fix hidden station v6
>>>>>>>  - fix -n to -f if
>>>>>>>  - Add function to check for a gateway and use this
>>>>>>>  - remove /etc/community.cfg and variables
>>>>>>>  - send fewer infos to keyxchangev2
>>>>>>>  - add a check if /tmp/keyxchangev2 not downloadable and edit a 
>>>>>>> bit on
>>>>>> the
>>>>>>> wgets
>>>>>>>  - change the position from json_load and do this only 1 times
>>>>>>>
>>>>>>> Update in v7:
>>>>>>> 	!!UNTESTED!!
>>>>>>>  - delete keyxchangev2data at start of the script
>>>>>>>  - do only things with keyxchangev2data if available
>>>>>>>  - change keyxchangev2 url
>>>>>>>
>>>>>>> Update in v8/v9:
>>>>>>>  - rebase onto 20170918-beta
>>>>>>>
>>>>>>> Update in v10:
>>>>>>>  - Minor code fixes
>>>>>>>  - Added fff-hoods to fff-base Makefile
>>>>>>>  - Removed trailing whitespaces and harmonized tabs
>>>>>>>  - Fixed some comments spelling
>>>>>>>  - Added mac for hostname rewrite
>>>>>>>  - Removed redundant check for /tmp/keyxchangev2data
>>>>>>> ---
>>>>>>>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>>>>>>>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>>>>>>>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>>>>>>>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>>>>>>> +++++++++++++++++++++
>>>>>>>  src/packages/fff/fff/Makefile                      |   3 +-
>>>>>>>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode
>>>>>>> 100644 src/packages/fff/fff-hoods/Makefile
>>>>>>>  create mode 100644 src/packages/fff/fff- 
>>>>>>> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>>>>>>  create mode 100644
>>>>>>> src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>>>>>>> hoods
>>>>>>>  create mode 100755 src/packages/fff/fff- 
>>>>>>> hoods/files/usr/sbin/configurehood
>>>>>>>
>>>>>>> diff --git a/src/packages/fff/fff-hoods/Makefile
>>>>>>> b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index
>>>>>>> 0000000..f85178d
>>>>>>> --- /dev/null
>>>>>>> +++ b/src/packages/fff/fff-hoods/Makefile
>>>>>>> @@ -0,0 +1,39 @@
>>>>>>> +include $(TOPDIR)/rules.mk
>>>>>>> +
>>>>>>> +PKG_NAME:=fff-hoods
>>>>>>> +PKG_VERSION:=0.0.1
>>>>>>> +PKG_RELEASE:=1
>>>>>>> +
>>>>>>> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>>>>>>> +
>>>>>>> +include $(INCLUDE_DIR)/package.mk
>>>>>>> +
>>>>>>> +define Package/fff-hoods
>>>>>>> +    SECTION:=base
>>>>>>> +    CATEGORY:=Freifunk
>>>>>>> +    TITLE:= Freifunk-Franken hoods
>>>>>>> +    URL:=http://www.freifunk-franken.de
>>>>>>> +    DEPENDS:=+fff-network
>>>>>>> +endef
>>>>>>> +
>>>>>>> +define Package/fff-hoods/description
>>>>>>> +    This package load and configures the current hood endef
>>>>>>> +
>>>>>>> +define Build/Prepare
>>>>>>> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>>>>>>> +
>>>>>>> +define Build/Configure
>>>>>>> +	# nothing
>>>>>>> +endef
>>>>>>> +
>>>>>>> +define Build/Compile
>>>>>>> +	# nothing
>>>>>>> +endef
>>>>>>> +
>>>>>>> +define Package/fff-hoods/install
>>>>>>> +	$(CP) ./files/* $(1)/
>>>>>>> +endef
>>>>>>> +
>>>>>>> +$(eval $(call BuildPackage,fff-hoods))
>>>>>>> diff --git
>>>>>> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
>>>>>> s
>>>>>>> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoo
>>>>>>> ds
>>>>>>> new file mode 100644
>>>>>>> index 0000000..49f53e3
>>>>>>> --- /dev/null
>>>>>>> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff
>>>>>>> +++ -h
>>>>>>> +++ oods
>>>>>>> @@ -0,0 +1,5 @@
>>>>>>> +#!/bin/sh
>>>>>>> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>>>>>>> +       sleep 3
>>>>>>> +       /usr/sbin/configurehood
>>>>>>> +}
>>>>>>> diff --git
>>>>>>> a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>>> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>>> new file mode 100644
>>>>>>> index 0000000..ca8d798
>>>>>>> --- /dev/null
>>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>>> @@ -0,0 +1 @@
>>>>>>> +*/5 * * * * /usr/sbin/configurehood
>>>>>>> diff --git
>>>>>>> a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>>> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>>> new file mode 100755
>>>>>>> index 0000000..ad316f8
>>>>>>> --- /dev/null
>>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>>> @@ -0,0 +1,206 @@
>>>>>>> +#!/bin/sh
>>>>>>> +
>>>>>>> +. /usr/share/libubox/jshn.sh
>>>>>>> +. /lib/functions/fff/wireless
>>>>>>> +
>>>>>>> +rm /tmp/keyxchangev2data
>>>>>>> +
>>>>>>> +# Gatewaycheck function
>>>>>>> +isGatewayAvailable() {
>>>>>>> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>>>>>>> +		return true;
>>>>>>> +	else
>>>>>>> +		return false;
>>>>>>> +	fi
>>>>>>> +}
>>>>>>> +
>>>>>>> +
>>>>>>> +# Hidden AP check
>>>>>>> +
>>>>>>> +if [ -f /tmp/hiddenapflag ]; then
>>>>>>> +	if [ isGatewayAvailable ]; then
>>>>>>> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
>>>>>>> "configap" "configap" "1"; then
>>>>>>> +			echo "Can't add AP interface on $radio."
>>>>>>> +			exit 1
>>>>>>> +		else
>>>>>>> +			# We must set a fixed ip address here
>>>>>>> +			uci set network.configap=interface
>>>>>>> +			uci set network.configap.proto='static'
>>>>>>> +			uci set network.configap.ip6addr='fe80::1/64'
>>>>>>> +			uci commit network
>>>>>>> +		fi
>>>>>>> +	else
>>>>>>> +		rm /tmp/hiddenapflag
>>>>>>> +	fi
>>>>>>> +fi
>>>>>> Warum steht dieser ganze Block am Anfang und nicht am Schluss des
>> Skripts?
>>>>>> Hat das einen Grund, dass der immer einen Zyklus warten soll?
>>>>> genau, Batman hat ein Timeout das wollen wir damit abfangen damit 
>>>>> erst im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss
>> also 
>>>>> 5min eine Verbindung zum GW bestehen.
>>>>>>
>>>>>>> +
>>>>>>> +
>>>>>>> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>>>>>>> +system.@system[0].longitude) hostname=$(cat
>>>>>>> /proc/sys/kernel/hostname)
>>>>>>> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
>>>>>> Hier hab ich die Mac ergänzt.
>>>>> das war einfach nur C&P
>>>>>>> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = 
>>>>>>> +"OpenWrt" ]
>>>>>>> && hostname=""
>>>>>>> +[ "$hostname" = "" ] &&  hostname="$mac"
>>>>>> Wozu ist das gut? Sollte man das auf LEDE ändern?
>>>>> hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht
>> unsicher 
>>>>> wofür es nötig ist.
>>>> Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.
>>>>
>>>> Ja, das sollte man ändern. :) Good Catch!
>>>>
>>>>>>> +
>>>>>>> +test_ipv4_host1="keyserver.freifunk-franken.de" # 
>>>>>>> +Freifunk-Franken
>>>>>>> keyserver
>>>>>>> +test_ipv4_host2="8.8.8.8"        # Google DNS
>>>>>>> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
>>>>>>> +
>>>>>>> +# if we have Internet, we download the Hoodfile from the
>>>>>>> +keyxchangev2 if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>>>>>>> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>>>>>>> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>>>>>>> +	wget -T15 -t5 "http://keyserver.freifunk-
>>>>>>> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
>>>>>>> +	#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
>>>>>>> +	# Only do that, when we have no gateway in range. If the
>>>>>>> Uplinkrouter changed the hood, we lost the GW and do this 
>>>>>>> automatically again, I think! Nice idea?
>>>>>>> +	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
>>>>>>> +		if ! wifiDelAll; then
>>>>>>> +			echo "Can't delete current wifi setup"
>>>>>>> +			exit 1
>>>>>>> +		fi
>>>>>>> +		#now we look for phy and add this
>>>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>>>> +				echo "$phy is 2.4 GHz"
>>>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>>>> "$BATMAN_CHANNEL")
>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>> +					exit 1
>>>>>>> +				fi
>>>>>>> +			fi
>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>>>> +				echo "$phy is 5 GHz"
>>>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>>>> "$BATMAN_CHANNEL_5GHZ")
>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>> +					exit 1
>>>>>>> +				fi
>>>>>>> +			fi
>>>>>> Hier werden Variablen aus der community.cfg verwendet 
>>>>>> ($BATMAN...), unten ist hardgecodet. Das hier auch hardcoden?
>>>>> macht vermutlich Sinn, weil wir die /etc/community.cfg eh
>> abschaffen wollen.
>>>> Richtig. Die Daten kommen ja (später mal) aus dem json hood file.
>> Bis dahin sind sie halt hart kodiert. Um einen Übergang leichter zu
>> machen könnte man überlegen, on man die Werte vielleicht einer
>> Konstangen zuweist und diesen dann entsprechend verwendet. Das hätte
>> den Vorteil, dass die Umstellung dann später einfacher wird.
>>>>>>> +			#and here we add the station
>>>>>>> +			if ! wifiAddSta "$radio"
>>>>>> "config.franken.freifunk.net"
>>>>>>> "configSta"; then
>>>>>>> +				echo "Can't add Sta interface on $radio."
>>>>>>> +				exit 1
>>>>>>> +			fi
>>>>>>> +
>>>>>>> +		done
>>>>>>> +
>>>>>>> +		wifi
>>>>>>> +		# 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
>>>>>>> +	else
>>>>>>> +		echo "We have a Gateway in Range, we load the
>>>>>>> keyxchangev2data from fe80::1"
>>>>>>> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
>>>>>>> -O /tmp/keyxchangev2data
>>>>>>> +	fi
>>>>>>> +
>>>>>>> +fi
>>>>>>> +
>>>>>>> +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!
>>>>>>> +
>>>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>>>> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
>>>>>>> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
>>>>>>> | cut -f1 -d " ")
>>>>>>> +	if [ "$sumnew" != "$sumold" ]; then
>>>>>> Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht 
>>>>>> irgendwie keinen Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ]
>> schon geprüft haben?!
>>>>> das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich 
>>>>> mal zurück.
>>>>>>> +		echo "New file detect, we reconfigure the Node";
>>>>>>> +
>>>>>>> +		# copy the file to webroot so that other Meshrouter can
>>>>>>> download it
>>>>>>> +		cp /tmp/keyxchangev2data /www/public/
>>>>>>> +
>>>>>>> +		json_select hood
>>>>>>> +
>>>>>>> +		json_get_var hood name
>>>>>>> +		json_get_var mesh_bssid mesh_bssid
>>>>>>> +		json_get_var mesh_essid mesh_essid
>>>>>>> +		json_get_var essid essid
>>>>>>> +		# i think the next things we don't active this in the first
>>>>>>> version! we can do it later
>>>>>>> +		#json_get_var channel2 channel2
>>>>>>> +		#json_get_var mode2 mode2
>>>>>>> +		#json_get_var type2 type2
>>>>>>> +		#json_get_var channel5 channel5
>>>>>>> +		#json_get_var mode5 mode5
>>>>>>> +		#json_get_var type5 type5
>>>>>>> +		#json_get_var protocol protocol
>>>>>>> +
>>>>>>> +		echo "Setting hood name: $hood"
>>>>>>> +		uci set "system.@system[0].hood=$hood"
>>>>>>> +
>>>>>>> +		if ! wifiDelAll; then
>>>>>>> +			echo "Can't delete current wifi setup"
>>>>>>> +			exit 1
>>>>>>> +		fi
>>>>>>> +
>>>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>>>> +				echo "$phy is 2.4 GHz"
>>>>>>> +				radio=$(wifiAddPhy "$phy" "1")
>>>>>> Hier ist jetzt hardgecodet ... "1"
>>>>> interessant, vermutlich hab ich es oben einfach vergessen und wollt
>>>>> es wirklich überall hard coden weil eben /etc/community.cfg weg
>> fällt.
>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>> +					exit 1
>>>>>>> +				fi
>>>>>>> +			fi
>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>>>> +				echo "$phy is 5 GHz"
>>>>>>> +				radio=$(wifiAddPhy "$phy" "13")
>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>> +					exit 1
>>>>>>> +				fi
>>>>>>> +			fi
>>>>>>> +
>>>>>>> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
>>>>>> then
>>>>>>> +				echo "Can't add AP interface on $radio."
>>>>>>> +				exit 1
>>>>>>> +			fi
>>>>>>> +
>>>>>>> +			# here we set a bit for add hidden AP
>>>>>>> +			touch /tmp/hiddenapflag
>>>>>>> +
>>>>>>> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
>>>>>>> "$mesh_bssid"; then
>>>>>>> +				echo "Can't add AP interface on $radio."
>>>>>>> +				exit 1
>>>>>>> +			fi
>>>>>>> +		done
>>>>>>> +
>>>>>>> +		echo "Loading wifi"
>>>>>>> +		wifi
>>>>>>> +
>>>>>>> +	else
>>>>>>> +		echo "We have no new file or we haven't got a file. We do
>>>>>>> nothing. We try it again in 5 minutes...";
>>>>>> Meines Erachtens ist hier nur "We have no new file" erfüllt. Der 
>>>>>> andere Fall wäre eine if weiter außen. Siehe [ ! -f
>> /tmp/keyxchangev2data] ...
>>>>> muss ich mir auch mal in Ruhe angucken...
>>>>>>> +	fi
>>>>>>> +
>>>>>>> +	# and now we read the VPN Data and give this data to fff-vpn
>>>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>>>> +
>>>>>>> +	json_select vpn
>>>>>>> +	Index="1"
>>>>>>> +	rm /tmp/fastd_fff_output
>>>>>>> +	touch /tmp/fastd_fff_output
>>>>>>> +	while json_select $Index > /dev/null
>>>>>> Wieso while wenn nur ein Element "1"?
>>>>> es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit 
>>>>> einer Schleife durchgehen oder?
>>>>>>> +	do
>>>>>>> +		json_get_var protocol protocol
>>>>>>> +		if [ "$protocol" == "fastd" ]; then
>>>>>>> +			json_get_var servername name
>>>>>>> +			echo "####${servername}.conf" >>
>>>>>>> /tmp/fastd_fff_output
>>>>>>> +			echo "#name \"${servername}\";" >>
>>>>>>> /tmp/fastd_fff_output
>>>>>>> +			json_get_var key key
>>>>>>> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
>>>>>>> +			json_get_var address address
>>>>>>> +			json_get_var port port
>>>>>>> +			echo "remote ipv4 \"${address}\" port $port float;"
>>>>>>>>> /tmp/fastd_fff_output
>>>>>>> +		fi
>>>>>>> +		echo "" >> /tmp/fastd_fff_output
>>>>>>> +		echo "###" >> /tmp/fastd_fff_output
>>>>>> Die beiden kommen ja nur einmal am Schluss, also müssen sie aus 
>>>>>> dem while raus, oder?
>>>>> oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab
>> ich 
>>>>> das ganze noch nicht getestet, RedDog wollte das aber eh relativ 
>>>>> zügig umbauen weil das Format einfach sh*t ist, besser ist wenn 
>>>>> fff-vpn die json direkt ausliest.
>>>> Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder
>> tunneldigger genommen wird auch nicht an einer per http download'baren
>> Datei festmachen, sondern hier nach dem json file entsprechend machen.
>>>> Tim
>>>>
>>>>
>>>>> mfg
>>>>>
>>>>> Christian
>>>>>> Grüße
>>>>>>
>>>>>> Adrian
>>>>>>
>>>>>>
>>>>>>> +	done
>>>>>>> +	#this we do every 5 minutes, because it can change the VPN
>> Protocol
>>>>>>> +	#and now we get to vpn-select Script and load VPNs
>>>>>>> +	sh /usr/sbin/vpn-select
>>>>>>> +fi
>>>>>>> diff --git a/src/packages/fff/fff/Makefile 
>>>>>>> b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
>>>>>>> --- a/src/packages/fff/fff/Makefile
>>>>>>> +++ b/src/packages/fff/fff/Makefile
>>>>>>> @@ -29,7 +29,8 @@ define Package/fff-base
>>>>>>>               +fff-wireless \
>>>>>>>               +fff-timeserver \
>>>>>>>               +fff-vpn-select \
>>>>>>> -             +simple-tc
>>>>>>> +             +simple-tc \
>>>>>>> +             +fff-hoods
>>>>>>>  endef
>>>>>>>
>>>>>>>  define Package/fff-base/description
>>>>>>> --
>>>>>>> 2.7.4
>>>>>>>
>>>>>>> --
>>>>>>> franken-dev mailing list
>>>>>>> franken-dev@freifunk.net
>>>>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.n
>>>>>>> et
>>>>> --
>>>>> franken-dev mailing list
>>>>> franken-dev@freifunk.net
>>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
Christian Dresel Oct. 4, 2017, 1 p.m.
hi

On 04.10.2017 13:00, robert wrote:
> 
> 
> Am 04.10.2017 um 12:21 schrieb Tim Niemeyer:
>> Hi
>>
>> Am 4. Oktober 2017 12:09:53 MESZ schrieb robert <rlanghammer@web.de>:
>>> Hallo,
>>>
>>> mir gefaellt das auch sehr gut. Es bleibt noch die Frage, woher bekommt
>>> man die VPN Zugangsdaten, damit man am Gateway flexibel bleibt?
>> Die Knoten bekommen sie vom zentralen keyXchangeV2 oder durch den configAP ihres Nachbarn. Die Gateways sollen jede Verbindung annehmen, sofern sie nicht blacklisted ist.
>>
>>
>>> Ich faende es schoen, wenn ich am Gateway den Zugang festlegen koennte.
>>> Aktuell koennen die Ropter fastd und l2tp. Da koennen auch noch welche
>>> dazu kommen. Und am Gateway entscheide ich dann, was ich anbieten
>>> moechte. Das bedeutet, der Uplinkrouter bekommt vom KeyX nur die IPs
>>> der
>>> GWs und erfragt bei denen die VPN Daten.
>> Ich bin eher dagegen, dass die GWs erst befragt werden müssen. Das steht ja schon in der Hoodfile drin was für das Gateway zu nehmen ist. Wenn ein Knoten später mal ein Hoodfile hat, was er nicht unterstützt kann er so einfach das nächste nehmen.
> Muss man sich jetzt fuer eine Variante entscheiden, wenn man das GW in
> den Keyex eintragen laesst? Oder soll man beide anbieten und die Router
> entscheiden was genommen wird?
> Robert

so hat es sich für mich bisher angehört, Tim hatte da aber 2 Sachen die
mich langsam zum umdenken bewegen:

1) Man kann ja in der json sowohl fastd als auch l2tp eintragen, wenn
man was nicht anbietet versucht der Router zwar dorthin zu verbinden
findet aber keine Endstelle. Klingt irgendwie nicht sehr ellegant aber
machbar.

2) weiter unten

>>
>>
>>> So wird es dann auch recht einfach neue VPN Varianten zu integrieren.
>> Ne, eben nicht. Denn die alten Knoten würden das Angebot einer Hood vielleicht nicht unterstützten und könnten dann keine Alternative wählen.
>>
>>> Was meint Ihr?
>> Ich denke immer noch, dass es reichen sollte wenn die Knoten sich eine Hood auswählen, und dann das Gateway wählen was sie mögen. Sollte dann mal ein Knoten die angebotenen VPNs nicht unterstützten, kann er einfach die nächste Hood wählen.

Ist natürlich ein großer Vorteil und auf jeden Fall ein "Für json"
Argument. Einzige Rückfrage, brauchen wir das wirklich mal irgendwann
oder ist das eher so: "Naja 2027 vielleicht, wenn Batman 2027.13 die
kompatibilität bricht, sind wir schon sehr froh das eingeführt zu haben"
;) ?

mfg

Christian

>>
>> Tim
>>
>>
>>> Robert
>>>
>>>
>>> Am 04.10.2017 um 11:29 schrieb Adrian Schmutzler:
>>>> Hallo Tim,
>>>>
>>>> für mich, der ich eigtl ein OOP Programmierer bin, hat der Vorschlag
>>> mit der Library natürlich sehr viel Charme.
>>>> Folgende Überlegungen:
>>>> 1. Im Moment würde ich das erstmal hintanstellen, da Zeit
>>>> 2. Da im Moment fastd und tunneldigger ja nicht parallel, sondern
>>> hierarchisch ineinander aufgerufen werden, müsste man glaube ich erst
>>> deine Diskussion diesbezüglich mit Christian auflösen, bevor man das
>>> "ordentlich" machen kann.
>>>> 3. Irgendwann könnte der "Stumpf" von vpn-select in die fff-hoods mit
>>> rein wandern, da erstere nichts mehr sonst in der Package hat und eh
>>> nur von fff-hoods gecallt wird.
>>>> Grüße
>>>>
>>>> Adrian
>>>>
>>>> -----Original Message-----
>>>> From: Tim Niemeyer [mailto:tim@tn-x.org] 
>>>> Sent: Montag, 2. Oktober 2017 16:29
>>>> To: Adrian Schmutzler <mail@adrianschmutzler.de>
>>>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>>>
>>>> Am Montag, den 02.10.2017, 16:23 +0200 schrieb Adrian Schmutzler:
>>>>> Hallo,
>>>>>
>>>>> danke für die Hinweise. Ein Teil ist schon im neuen v11 Patch drin.
>>>> Habs grad gesehen. Prima! :)
>>>>
>>>>> Bin grade selber dabei, das vpn-select auf json umzustellen.
>>>> Ah.. Haha.. :)
>>>>
>>>> Dann is Christian ja Overruled.. :P
>>>>
>>>> Wie genau planst du das? Ich muss mir das nochmal kurz angucken.
>>>>
>>>> Eigentlich braucht man das vpn-select ja dann gar nicht mehr, weil
>>> das "select" macht ja dann fff-hoods (basierend auf dem json).
>>>> Ich fänd es schön, wenn es unter /lib/wtf/functions pro VPN eine
>>> entsprechende "library" gibt, womit dann die jeweiligen VPNs
>>> hinzugefügt werden.
>>>> Die stellen dann quasi eine Funktion wie:
>>>> add_fastd "$serverip" "$param2" ...
>>>> add_l2tpv3 "$serverip" "..."
>>>>
>>>> Das fff-hoods benutzt diese dann nur noch, je nach Inhalt der json
>>> Datei.
>>>> Was denkst du?
>>>>
>>>> Tim
>>>>
>>>>
>>>>> Grüße
>>>>>
>>>>> Adrian
>>>>>
>>>>> -----Original Message-----
>>>>> From: Tim Niemeyer [mailto:tim@tn-x.org]
>>>>> Sent: Montag, 2. Oktober 2017 16:20
>>>>> To: Christian Dresel <fff@chrisi01.de>; franken-dev@freifunk.net
>>>>> Cc: mail@adrianschmutzler.de
>>>>> Subject: Re: [PATCH v10 4/4] Add fff-hoods
>>>>>
>>>>> Hi
>>>>>
>>>>>
>>>>> Am Sonntag, den 01.10.2017, 19:57 +0200 schrieb Christian Dresel:
>>>>>> hi
>>>>>>
>>>>>> hab grad recht wenig Zeit aber hier wird grad $Kram diskutiert
>>> daher 
>>>>>> bin ich die Mail mal eben überflogen und paar Kommentare Inline.
>>>>>>
>>>>>> On 01.10.2017 16:05, mail@adrianschmutzler.de wrote:
>>>>>>> Hallo,
>>>>>>>
>>>>>>> eine Fragen und Anmerkungen inline, die mir beim Ändern/Lesen 
>>>>>>> aufgefallen sind.
>>>>>>>
>>>>>>>> -----Original Message-----
>>>>>>>> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On 
>>>>>>>> Behalf Of Adrian Schmutzler
>>>>>>>> Sent: Sonntag, 1. Oktober 2017 15:49
>>>>>>>> To: franken-dev@freifunk.net
>>>>>>>> Cc: Jan Kraus <mayosemmel@gmail.com>
>>>>>>>> Subject: [PATCH v10 4/4] Add fff-hoods
>>>>>>>>
>>>>>>>> From: Christian Dresel <fff@chrisi01.de>
>>>>>>>>
>>>>>>>> this packages connect to keyxchangev2 after review we must change
>>>>>>>> the serveradress! This is only a example
>>>>>>>>
>>>>>>>> Signed-off-by: Christian Dresel <fff@chrisi01.de>
>>>>>>>> Signed-off-by: Jan Kraus <mayosemmel@gmail.com>
>>>>>>>> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
>>>>>>>>
>>>>>>>> Update in v2:
>>>>>>>>  - clean tabstops
>>>>>>>>  - move the json vpn out of the if because we need this after 
>>>>>>>> reboot
>>>>>>>>
>>>>>>>> Update in v5:
>>>>>>>> 	!!UNTESTED!!
>>>>>>>>  - change hidden AP ip to locallink
>>>>>>>>  - Open hidden AP after more checks
>>>>>>>>  - Load json File from Gateway if Gateway in Batman in Range
>>>>>>>>
>>>>>>>> Update in v6:
>>>>>>>> 	!!UNTESTED!!
>>>>>>>>  - fix hidden station v6
>>>>>>>>  - fix -n to -f if
>>>>>>>>  - Add function to check for a gateway and use this
>>>>>>>>  - remove /etc/community.cfg and variables
>>>>>>>>  - send fewer infos to keyxchangev2
>>>>>>>>  - add a check if /tmp/keyxchangev2 not downloadable and edit a 
>>>>>>>> bit on
>>>>>>> the
>>>>>>>> wgets
>>>>>>>>  - change the position from json_load and do this only 1 times
>>>>>>>>
>>>>>>>> Update in v7:
>>>>>>>> 	!!UNTESTED!!
>>>>>>>>  - delete keyxchangev2data at start of the script
>>>>>>>>  - do only things with keyxchangev2data if available
>>>>>>>>  - change keyxchangev2 url
>>>>>>>>
>>>>>>>> Update in v8/v9:
>>>>>>>>  - rebase onto 20170918-beta
>>>>>>>>
>>>>>>>> Update in v10:
>>>>>>>>  - Minor code fixes
>>>>>>>>  - Added fff-hoods to fff-base Makefile
>>>>>>>>  - Removed trailing whitespaces and harmonized tabs
>>>>>>>>  - Fixed some comments spelling
>>>>>>>>  - Added mac for hostname rewrite
>>>>>>>>  - Removed redundant check for /tmp/keyxchangev2data
>>>>>>>> ---
>>>>>>>>  src/packages/fff/fff-hoods/Makefile                |  39 ++++
>>>>>>>>  .../files/etc/hotplug.d/iface/50-fff-hoods         |   5 +
>>>>>>>>  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +
>>>>>>>>  .../fff/fff-hoods/files/usr/sbin/configurehood     | 206
>>>>>>>> +++++++++++++++++++++
>>>>>>>>  src/packages/fff/fff/Makefile                      |   3 +-
>>>>>>>>  5 files changed, 253 insertions(+), 1 deletion(-)  create mode
>>>>>>>> 100644 src/packages/fff/fff-hoods/Makefile
>>>>>>>>  create mode 100644 src/packages/fff/fff- 
>>>>>>>> hoods/files/etc/hotplug.d/iface/50-fff-hoods
>>>>>>>>  create mode 100644
>>>>>>>> src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-
>>>>>>>> hoods
>>>>>>>>  create mode 100755 src/packages/fff/fff- 
>>>>>>>> hoods/files/usr/sbin/configurehood
>>>>>>>>
>>>>>>>> diff --git a/src/packages/fff/fff-hoods/Makefile
>>>>>>>> b/src/packages/fff/fff- hoods/Makefile new file mode 100644 index
>>>>>>>> 0000000..f85178d
>>>>>>>> --- /dev/null
>>>>>>>> +++ b/src/packages/fff/fff-hoods/Makefile
>>>>>>>> @@ -0,0 +1,39 @@
>>>>>>>> +include $(TOPDIR)/rules.mk
>>>>>>>> +
>>>>>>>> +PKG_NAME:=fff-hoods
>>>>>>>> +PKG_VERSION:=0.0.1
>>>>>>>> +PKG_RELEASE:=1
>>>>>>>> +
>>>>>>>> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods
>>>>>>>> +
>>>>>>>> +include $(INCLUDE_DIR)/package.mk
>>>>>>>> +
>>>>>>>> +define Package/fff-hoods
>>>>>>>> +    SECTION:=base
>>>>>>>> +    CATEGORY:=Freifunk
>>>>>>>> +    TITLE:= Freifunk-Franken hoods
>>>>>>>> +    URL:=http://www.freifunk-franken.de
>>>>>>>> +    DEPENDS:=+fff-network
>>>>>>>> +endef
>>>>>>>> +
>>>>>>>> +define Package/fff-hoods/description
>>>>>>>> +    This package load and configures the current hood endef
>>>>>>>> +
>>>>>>>> +define Build/Prepare
>>>>>>>> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile endef
>>>>>>>> +
>>>>>>>> +define Build/Configure
>>>>>>>> +	# nothing
>>>>>>>> +endef
>>>>>>>> +
>>>>>>>> +define Build/Compile
>>>>>>>> +	# nothing
>>>>>>>> +endef
>>>>>>>> +
>>>>>>>> +define Package/fff-hoods/install
>>>>>>>> +	$(CP) ./files/* $(1)/
>>>>>>>> +endef
>>>>>>>> +
>>>>>>>> +$(eval $(call BuildPackage,fff-hoods))
>>>>>>>> diff --git
>>>>>>> a/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hood
>>>>>>> s
>>>>>>>> b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff-hoo
>>>>>>>> ds
>>>>>>>> new file mode 100644
>>>>>>>> index 0000000..49f53e3
>>>>>>>> --- /dev/null
>>>>>>>> +++ b/src/packages/fff/fff-hoods/files/etc/hotplug.d/iface/50-fff
>>>>>>>> +++ -h
>>>>>>>> +++ oods
>>>>>>>> @@ -0,0 +1,5 @@
>>>>>>>> +#!/bin/sh
>>>>>>>> +[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && {
>>>>>>>> +       sleep 3
>>>>>>>> +       /usr/sbin/configurehood
>>>>>>>> +}
>>>>>>>> diff --git
>>>>>>>> a/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>>>> b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>>>> new file mode 100644
>>>>>>>> index 0000000..ca8d798
>>>>>>>> --- /dev/null
>>>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods
>>>>>>>> @@ -0,0 +1 @@
>>>>>>>> +*/5 * * * * /usr/sbin/configurehood
>>>>>>>> diff --git
>>>>>>>> a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>>>> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>>>> new file mode 100755
>>>>>>>> index 0000000..ad316f8
>>>>>>>> --- /dev/null
>>>>>>>> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
>>>>>>>> @@ -0,0 +1,206 @@
>>>>>>>> +#!/bin/sh
>>>>>>>> +
>>>>>>>> +. /usr/share/libubox/jshn.sh
>>>>>>>> +. /lib/functions/fff/wireless
>>>>>>>> +
>>>>>>>> +rm /tmp/keyxchangev2data
>>>>>>>> +
>>>>>>>> +# Gatewaycheck function
>>>>>>>> +isGatewayAvailable() {
>>>>>>>> +	if [ "$(batctl gwl | wc -l)" -gt 2 ]; then
>>>>>>>> +		return true;
>>>>>>>> +	else
>>>>>>>> +		return false;
>>>>>>>> +	fi
>>>>>>>> +}
>>>>>>>> +
>>>>>>>> +
>>>>>>>> +# Hidden AP check
>>>>>>>> +
>>>>>>>> +if [ -f /tmp/hiddenapflag ]; then
>>>>>>>> +	if [ isGatewayAvailable ]; then
>>>>>>>> +		if ! wifiAddAP "$radio" "config.franken.freifunk.net"
>>>>>>>> "configap" "configap" "1"; then
>>>>>>>> +			echo "Can't add AP interface on $radio."
>>>>>>>> +			exit 1
>>>>>>>> +		else
>>>>>>>> +			# We must set a fixed ip address here
>>>>>>>> +			uci set network.configap=interface
>>>>>>>> +			uci set network.configap.proto='static'
>>>>>>>> +			uci set network.configap.ip6addr='fe80::1/64'
>>>>>>>> +			uci commit network
>>>>>>>> +		fi
>>>>>>>> +	else
>>>>>>>> +		rm /tmp/hiddenapflag
>>>>>>>> +	fi
>>>>>>>> +fi
>>>>>>> Warum steht dieser ganze Block am Anfang und nicht am Schluss des
>>> Skripts?
>>>>>>> Hat das einen Grund, dass der immer einen Zyklus warten soll?
>>>>>> genau, Batman hat ein Timeout das wollen wir damit abfangen damit 
>>>>>> erst im 2. Zyklus wirklich der hidden AP geöffnet wird. Es muss
>>> also 
>>>>>> 5min eine Verbindung zum GW bestehen.
>>>>>>>
>>>>>>>> +
>>>>>>>> +
>>>>>>>> +lat=$(uci get system.@system[0].latitude) long=$(uci get
>>>>>>>> +system.@system[0].longitude) hostname=$(cat
>>>>>>>> /proc/sys/kernel/hostname)
>>>>>>>> +mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }'
>>>>>>> Hier hab ich die Mac ergänzt.
>>>>>> das war einfach nur C&P
>>>>>>>> +/sys/class/net/br-mesh/address 2>/dev/null) [ "$hostname" = 
>>>>>>>> +"OpenWrt" ]
>>>>>>>> && hostname=""
>>>>>>>> +[ "$hostname" = "" ] &&  hostname="$mac"
>>>>>>> Wozu ist das gut? Sollte man das auf LEDE ändern?
>>>>>> hab ich einfach nur C&P aus den fff-vpn. Bin mir grad recht
>>> unsicher 
>>>>>> wofür es nötig ist.
>>>>> Das ist damit nicht alle Knoten am KeyXchange "OpenWRT" heißen.
>>>>>
>>>>> Ja, das sollte man ändern. :) Good Catch!
>>>>>
>>>>>>>> +
>>>>>>>> +test_ipv4_host1="keyserver.freifunk-franken.de" # 
>>>>>>>> +Freifunk-Franken
>>>>>>>> keyserver
>>>>>>>> +test_ipv4_host2="8.8.8.8"        # Google DNS
>>>>>>>> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
>>>>>>>> +
>>>>>>>> +# if we have Internet, we download the Hoodfile from the
>>>>>>>> +keyxchangev2 if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||
>>>>>>>> +	ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||
>>>>>>>> +	ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null; then
>>>>>>>> +	wget -T15 -t5 "http://keyserver.freifunk-
>>>>>>>> franken.de/v2/?lat=$lat&long=$long" -O /tmp/keyxchangev2data
>>>>>>>> +	#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
>>>>>>>> +	# Only do that, when we have no gateway in range. If the
>>>>>>>> Uplinkrouter changed the hood, we lost the GW and do this 
>>>>>>>> automatically again, I think! Nice idea?
>>>>>>>> +	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
>>>>>>>> +		if ! wifiDelAll; then
>>>>>>>> +			echo "Can't delete current wifi setup"
>>>>>>>> +			exit 1
>>>>>>>> +		fi
>>>>>>>> +		#now we look for phy and add this
>>>>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>>>>> +				echo "$phy is 2.4 GHz"
>>>>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>>>>> "$BATMAN_CHANNEL")
>>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>>> +					exit 1
>>>>>>>> +				fi
>>>>>>>> +			fi
>>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>>>>> +				echo "$phy is 5 GHz"
>>>>>>>> +				radio=$(wifiAddPhy "$phy"
>>>>>>>> "$BATMAN_CHANNEL_5GHZ")
>>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>>> +					exit 1
>>>>>>>> +				fi
>>>>>>>> +			fi
>>>>>>> Hier werden Variablen aus der community.cfg verwendet 
>>>>>>> ($BATMAN...), unten ist hardgecodet. Das hier auch hardcoden?
>>>>>> macht vermutlich Sinn, weil wir die /etc/community.cfg eh
>>> abschaffen wollen.
>>>>> Richtig. Die Daten kommen ja (später mal) aus dem json hood file.
>>> Bis dahin sind sie halt hart kodiert. Um einen Übergang leichter zu
>>> machen könnte man überlegen, on man die Werte vielleicht einer
>>> Konstangen zuweist und diesen dann entsprechend verwendet. Das hätte
>>> den Vorteil, dass die Umstellung dann später einfacher wird.
>>>>>>>> +			#and here we add the station
>>>>>>>> +			if ! wifiAddSta "$radio"
>>>>>>> "config.franken.freifunk.net"
>>>>>>>> "configSta"; then
>>>>>>>> +				echo "Can't add Sta interface on $radio."
>>>>>>>> +				exit 1
>>>>>>>> +			fi
>>>>>>>> +
>>>>>>>> +		done
>>>>>>>> +
>>>>>>>> +		wifi
>>>>>>>> +		# 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
>>>>>>>> +	else
>>>>>>>> +		echo "We have a Gateway in Range, we load the
>>>>>>>> keyxchangev2data from fe80::1"
>>>>>>>> +		wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data"
>>>>>>>> -O /tmp/keyxchangev2data
>>>>>>>> +	fi
>>>>>>>> +
>>>>>>>> +fi
>>>>>>>> +
>>>>>>>> +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!
>>>>>>>> +
>>>>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>>>>> +	sumnew=$(sha256sum /tmp/keyxchangev2data | cut -f1 -d " ")
>>>>>>>> +	sumold=$(sha256sum /www/public/keyxchangev2data &>/dev/null
>>>>>>>> | cut -f1 -d " ")
>>>>>>>> +	if [ "$sumnew" != "$sumold" ]; then
>>>>>>> Die zweite Abfrage mit [ ! -f /tmp/keyxchangev2data] macht 
>>>>>>> irgendwie keinen Sinn, da wir ja oben [ -s /tmp/keyxchangev2data ]
>>> schon geprüft haben?!
>>>>>> das muss ich mir in Ruhe angucken, grad nicht viel Zeit stell ich 
>>>>>> mal zurück.
>>>>>>>> +		echo "New file detect, we reconfigure the Node";
>>>>>>>> +
>>>>>>>> +		# copy the file to webroot so that other Meshrouter can
>>>>>>>> download it
>>>>>>>> +		cp /tmp/keyxchangev2data /www/public/
>>>>>>>> +
>>>>>>>> +		json_select hood
>>>>>>>> +
>>>>>>>> +		json_get_var hood name
>>>>>>>> +		json_get_var mesh_bssid mesh_bssid
>>>>>>>> +		json_get_var mesh_essid mesh_essid
>>>>>>>> +		json_get_var essid essid
>>>>>>>> +		# i think the next things we don't active this in the first
>>>>>>>> version! we can do it later
>>>>>>>> +		#json_get_var channel2 channel2
>>>>>>>> +		#json_get_var mode2 mode2
>>>>>>>> +		#json_get_var type2 type2
>>>>>>>> +		#json_get_var channel5 channel5
>>>>>>>> +		#json_get_var mode5 mode5
>>>>>>>> +		#json_get_var type5 type5
>>>>>>>> +		#json_get_var protocol protocol
>>>>>>>> +
>>>>>>>> +		echo "Setting hood name: $hood"
>>>>>>>> +		uci set "system.@system[0].hood=$hood"
>>>>>>>> +
>>>>>>>> +		if ! wifiDelAll; then
>>>>>>>> +			echo "Can't delete current wifi setup"
>>>>>>>> +			exit 1
>>>>>>>> +		fi
>>>>>>>> +
>>>>>>>> +		for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do
>>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "2... MHz"; then
>>>>>>>> +				echo "$phy is 2.4 GHz"
>>>>>>>> +				radio=$(wifiAddPhy "$phy" "1")
>>>>>>> Hier ist jetzt hardgecodet ... "1"
>>>>>> interessant, vermutlich hab ich es oben einfach vergessen und wollt
>>>>>> es wirklich überall hard coden weil eben /etc/community.cfg weg
>>> fällt.
>>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>>> +					exit 1
>>>>>>>> +				fi
>>>>>>>> +			fi
>>>>>>>> +			if iw phy "$phy" info | grep -q -m1 "5... MHz"; then
>>>>>>>> +				echo "$phy is 5 GHz"
>>>>>>>> +				radio=$(wifiAddPhy "$phy" "13")
>>>>>>>> +				if [ -z "$radio" ]; then
>>>>>>>> +					echo "Can't create radio for $phy"
>>>>>>>> +					exit 1
>>>>>>>> +				fi
>>>>>>>> +			fi
>>>>>>>> +
>>>>>>>> +			if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0";
>>>>>>> then
>>>>>>>> +				echo "Can't add AP interface on $radio."
>>>>>>>> +				exit 1
>>>>>>>> +			fi
>>>>>>>> +
>>>>>>>> +			# here we set a bit for add hidden AP
>>>>>>>> +			touch /tmp/hiddenapflag
>>>>>>>> +
>>>>>>>> +			if ! wifiAddAdHocMesh "$radio" "$mesh_essid"
>>>>>>>> "$mesh_bssid"; then
>>>>>>>> +				echo "Can't add AP interface on $radio."
>>>>>>>> +				exit 1
>>>>>>>> +			fi
>>>>>>>> +		done
>>>>>>>> +
>>>>>>>> +		echo "Loading wifi"
>>>>>>>> +		wifi
>>>>>>>> +
>>>>>>>> +	else
>>>>>>>> +		echo "We have no new file or we haven't got a file. We do
>>>>>>>> nothing. We try it again in 5 minutes...";
>>>>>>> Meines Erachtens ist hier nur "We have no new file" erfüllt. Der 
>>>>>>> andere Fall wäre eine if weiter außen. Siehe [ ! -f
>>> /tmp/keyxchangev2data] ...
>>>>>> muss ich mir auch mal in Ruhe angucken...
>>>>>>>> +	fi
>>>>>>>> +
>>>>>>>> +	# and now we read the VPN Data and give this data to fff-vpn
>>>>>>>> +	json_load "$(cat /tmp/keyxchangev2data)"
>>>>>>>> +
>>>>>>>> +	json_select vpn
>>>>>>>> +	Index="1"
>>>>>>>> +	rm /tmp/fastd_fff_output
>>>>>>>> +	touch /tmp/fastd_fff_output
>>>>>>>> +	while json_select $Index > /dev/null
>>>>>>> Wieso while wenn nur ein Element "1"?
>>>>>> es kann auch 2 oder 3 Gateways geben, deshalb muss man alle mit 
>>>>>> einer Schleife durchgehen oder?
>>>>>>>> +	do
>>>>>>>> +		json_get_var protocol protocol
>>>>>>>> +		if [ "$protocol" == "fastd" ]; then
>>>>>>>> +			json_get_var servername name
>>>>>>>> +			echo "####${servername}.conf" >>
>>>>>>>> /tmp/fastd_fff_output
>>>>>>>> +			echo "#name \"${servername}\";" >>
>>>>>>>> /tmp/fastd_fff_output
>>>>>>>> +			json_get_var key key
>>>>>>>> +			echo "key \"${key}\";" >> /tmp/fastd_fff_output
>>>>>>>> +			json_get_var address address
>>>>>>>> +			json_get_var port port
>>>>>>>> +			echo "remote ipv4 \"${address}\" port $port float;"
>>>>>>>>>> /tmp/fastd_fff_output
>>>>>>>> +		fi
>>>>>>>> +		echo "" >> /tmp/fastd_fff_output
>>>>>>>> +		echo "###" >> /tmp/fastd_fff_output
>>>>>>> Die beiden kommen ja nur einmal am Schluss, also müssen sie aus 
>>>>>>> dem while raus, oder?
>>>>>> oh das muss ich mir auch nochmal in Ruhe angucken, mit 2 GWs hab
>>> ich 
>>>>>> das ganze noch nicht getestet, RedDog wollte das aber eh relativ 
>>>>>> zügig umbauen weil das Format einfach sh*t ist, besser ist wenn 
>>>>>> fff-vpn die json direkt ausliest.
>>>>> Genau, ich würde ja auch lieber die Entscheidung, ob fastd oder
>>> tunneldigger genommen wird auch nicht an einer per http download'baren
>>> Datei festmachen, sondern hier nach dem json file entsprechend machen.
>>>>> Tim
>>>>>
>>>>>
>>>>>> mfg
>>>>>>
>>>>>> Christian
>>>>>>> Grüße
>>>>>>>
>>>>>>> Adrian
>>>>>>>
>>>>>>>
>>>>>>>> +	done
>>>>>>>> +	#this we do every 5 minutes, because it can change the VPN
>>> Protocol
>>>>>>>> +	#and now we get to vpn-select Script and load VPNs
>>>>>>>> +	sh /usr/sbin/vpn-select
>>>>>>>> +fi
>>>>>>>> diff --git a/src/packages/fff/fff/Makefile 
>>>>>>>> b/src/packages/fff/fff/Makefile index 166d423..305ab8d 100644
>>>>>>>> --- a/src/packages/fff/fff/Makefile
>>>>>>>> +++ b/src/packages/fff/fff/Makefile
>>>>>>>> @@ -29,7 +29,8 @@ define Package/fff-base
>>>>>>>>               +fff-wireless \
>>>>>>>>               +fff-timeserver \
>>>>>>>>               +fff-vpn-select \
>>>>>>>> -             +simple-tc
>>>>>>>> +             +simple-tc \
>>>>>>>> +             +fff-hoods
>>>>>>>>  endef
>>>>>>>>
>>>>>>>>  define Package/fff-base/description
>>>>>>>> --
>>>>>>>> 2.7.4
>>>>>>>>
>>>>>>>> --
>>>>>>>> franken-dev mailing list
>>>>>>>> franken-dev@freifunk.net
>>>>>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.n
>>>>>>>> et
>>>>>> --
>>>>>> franken-dev mailing list
>>>>>> franken-dev@freifunk.net
>>>>>> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net
>