<html><head></head><body>Problem 2 und 3 entsprechen der Erwartung. Später mehr...<br><br><div class="gmail_quote">On October 4, 2017 6:01:55 PM GMT+02:00, Christian Dresel <fff@chrisi01.de> wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">hi<br /><br />beim testen auf folgende Probleme gestoßen die ich aber noch nicht<br />genauer analysiert habe (Zeit und so...):<br /><br />- fastd im Autostart (rc.local) braucht wieder ewig bis ein key<br />generiert wird, dadurch hängen Router mit Kabel am WAN Port eine lange<br />Zeit beim boot ohne das eine LED leuchtet bzw. nur die Power LED (wr1043v4)<br /><br />- auf einem c25 mit aktivierten 5GHz (geht bei mir) wird nur ein 5GHz<br />hiddenconfigap aufgemacht, kein 2,4GHZ hiddenconfigap<br /><br />- Die Router scheinen auf Kanal 1 zu bleiben obwohl im keyxchange 13<br />steht, fehlt das noch?<br /><br />mfg<br /><br />Christian<br /><br />On 03.10.2017 18:53, Adrian Schmutzler wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> From: Christian Dresel <fff@chrisi01.de><br /> <br /> This package connects to keyxchangev2<br /> <br /> Tested-by: Adrian Schmutzler <freifunk@adrianschmutzler.de><br /> <br /> Signed-off-by: Christian Dresel <fff@chrisi01.de><br /> Signed-off-by: Jan Kraus <mayosemmel@gmail.com><br /> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de><br /> <br /> Update in v2:<br />  - clean tabstops<br />  - move the json vpn out of the if because we need this after reboot<br /> <br /> Update in v5:<br />  !!UNTESTED!!<br />  - change hidden AP ip to locallink<br />  - Open hidden AP after more checks<br />  - Load json File from Gateway if Gateway in Batman in Range<br /> <br /> Update in v6:<br />  !!UNTESTED!!<br />  - fix hidden station v6<br />  - fix -n to -f if<br />  - Add function to check for a gateway and use this<br />  - remove /etc/community.cfg and variables<br />  - send fewer infos to keyxchangev2<br />  - add a check if /tmp/keyxchangev2 not downloadable and edit a bit  on the wgets<br />  - change the position from json_load and do this only 1 times<br /> <br /> Update in v7:<br />  !!UNTESTED!!<br />  - delete keyxchangev2data at start of the script<br />  - do only things with keyxchangev2data if available<br />  - change keyxchangev2 url<br /> <br /> Update in v8/v9:<br />  - rebase onto 20170918-beta<br /> <br /> Update in v10:<br />  - Minor code fixes<br />  - Added fff-hoods to fff-base Makefile<br />  - Removed trailing whitespaces and harmonized tabs<br />  - Fixed some comments spelling<br />  - Added mac for hostname rewrite<br />  - Removed redundant check for /tmp/keyxchangev2data<br /> <br /> Update in v11:<br />  - Changed isGatewayAvailable to return integers (bool is<br />    not valid) and removed brackets for evaluations<br />  - Added variables for channels as they are used twice<br />  - Fixed $radio not set at the beginning (WORKAROUND!)<br />  - Changed OpenWRT to LEDE<br />  - Correctly reset json_select before reuse<br />  - Some tidying-up of comments and quotes<br />  - Fixed vpn loop so it works for more than one host (TESTED)<br />  - Fixed "else" if no file received<br /> <br /> Changes in v12:<br />  - Removed obsolete hostname<br /> <br /> Changes in v14 (Tested, working Inet+mesh):<br />  - Fixed stderr redirect<br />  - Added call of configurehood to rc.local, so it is triggered<br />    if wan does not come up. To prevent race condition,<br />    hotplug.d is removed.<br />  - Added wifi call to configAP setup<br />  - Remove hiddenap flag after successful setup<br />  - Added -q to uci calls<br />  - Added network interface configSta<br />  - Substitute timestamp to enable SHA comparison<br />  - Removed started-check from vpn-select<br /> <br /> Changes in v15:<br />  - Fixed 5 GHz channel<br />  - Only start vpn-select if router has internet<br />  - Put ping into function since it is used twice<br />  - Check for started in micrond to prevent race condition<br />  - Moved copy of keyxchangev2data to the end<br /> ---<br />  bsp/default/root_file_system/etc/rc.local          |   4 +<br />  src/packages/fff/fff-hoods/Makefile                |  39 ++++<br />  .../fff/fff-hoods/files/usr/lib/micron.d/fff-hoods |   1 +<br />  .../fff/fff-hoods/files/usr/sbin/configurehood     | 232 +++++++++++++++++++++<br />  .../fff/fff-vpn-select/files/usr/sbin/vpn-select   |   2 -<br />  src/packages/fff/fff/Makefile                      |   3 +-<br />  6 files changed, 278 insertions(+), 3 deletions(-)<br />  create mode 100644 src/packages/fff/fff-hoods/Makefile<br />  create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods<br />  create mode 100755 src/packages/fff/fff-hoods/files/usr/sbin/configurehood<br /> <br /> diff --git a/bsp/default/root_file_system/etc/rc.local b/bsp/default/root_file_system/etc/rc.local<br /> index bd972fb..59042c3 100755<br /> --- a/bsp/default/root_file_system/etc/rc.local<br /> +++ b/bsp/default/root_file_system/etc/rc.local<br /> @@ -4,6 +4,10 @@<br />  <br />  /usr/sbin/configurenetwork<br />  <br /> +sleep 3<br /> +<br /> +/usr/sbin/configurehood<br /> +<br />  touch /tmp/started<br />  <br />  exit 0<br /> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile<br /> new file mode 100644<br /> index 0000000..f85178d<br /> --- /dev/null<br /> +++ b/src/packages/fff/fff-hoods/Makefile<br /> @@ -0,0 +1,39 @@<br /> +include $(TOPDIR)/<a href="http://rules.mk">rules.mk</a><br /> +<br /> +PKG_NAME:=fff-hoods<br /> +PKG_VERSION:=0.0.1<br /> +PKG_RELEASE:=1<br /> +<br /> +PKG_BUILD_DIR:=$(BUILD_DIR)/fff-hoods<br /> +<br /> +include $(INCLUDE_DIR)/<a href="http://package.mk">package.mk</a><br /> +<br /> +define Package/fff-hoods<br /> +    SECTION:=base<br /> +    CATEGORY:=Freifunk<br /> +    TITLE:= Freifunk-Franken hoods<br /> +    URL:=<a href="http://www.freifunk-franken.de">http://www.freifunk-franken.de</a><br /> +    DEPENDS:=+fff-network<br /> +endef<br /> +<br /> +define Package/fff-hoods/description<br /> +    This package load and configures the current hood<br /> +endef<br /> +<br /> +define Build/Prepare<br /> + echo "all: " > $(PKG_BUILD_DIR)/Makefile<br /> +endef<br /> +<br /> +define Build/Configure<br /> + # nothing<br /> +endef<br /> +<br /> +define Build/Compile<br /> + # nothing<br /> +endef<br /> +<br /> +define Package/fff-hoods/install<br /> + $(CP) ./files/* $(1)/<br /> +endef<br /> +<br /> +$(eval $(call BuildPackage,fff-hoods))<br /> 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<br /> new file mode 100644<br /> index 0000000..39e800e<br /> --- /dev/null<br /> +++ b/src/packages/fff/fff-hoods/files/usr/lib/micron.d/fff-hoods<br /> @@ -0,0 +1 @@<br /> +*/5 * * * * [ -f /tmp/started ] && /usr/sbin/configurehood<br /> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood<br /> new file mode 100755<br /> index 0000000..bf5058a<br /> --- /dev/null<br /> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood<br /> @@ -0,0 +1,232 @@<br /> +#!/bin/sh<br /> +<br /> +. /usr/share/libubox/<a href="http://jshn.sh">jshn.sh</a><br /> +. /lib/functions/fff/wireless<br /> +<br /> +rm /tmp/keyxchangev2data<br /> +<br /> +# Gatewaycheck function<br /> +isGatewayAvailable() {<br /> + if [ "$(batctl gwl | wc -l)" -gt 2 ]; then<br /> +  return 0<br /> + else<br /> +  return 1<br /> + fi<br /> +}<br /> +<br /> +# Ping test<br /> +hasInternet() {<br /> + test_ipv4_host1="<a href="http://keyserver.freifunk-franken.de">keyserver.freifunk-franken.de</a>" # Freifunk-Franken keyserver<br /> + test_ipv4_host2="<a href="http://8.8.8.8">8.8.8.8</a>"        # Google DNS<br /> + test_ipv6_host1="<a href="http://heise.de">heise.de</a>"       # heise Zeitschriftenverlag<br /> + if ping -w5 -c3 "$test_ipv4_host1" &>/dev/null ||<br /> +  ping -w5 -c3 "$test_ipv4_host2" &>/dev/null ||<br /> +  ping6 -w5 -c3 "$test_ipv6_host1" &>/dev/null ; then<br /> +  return 0<br /> + fi<br /> + return 1<br /> +}<br /> +<br /> +chan2ghz="1"<br /> +chan5ghz="36"<br /> +<br /> +# Hidden AP check<br /> +<br /> +radio="radio0"<br /> +if [ -f /tmp/hiddenapflag ]; then<br /> + if isGatewayAvailable ; then<br /> +  if ! wifiAddAP "$radio" "<a href="http://config.franken.freifunk.net">config.franken.freifunk.net</a>" "configap" "configap" "1"; then<br /> +   echo "Can't add AP interface on $radio."<br /> +   exit 1<br /> +  else<br /> +   # We must set a fixed ip address here<br /> +   uci set network.configap=interface<br /> +   uci set network.configap.proto='static'<br /> +   uci set network.configap.ip6addr='fe80::1/64'<br /> +   uci commit network<br /> +<br /> +   wifi<br /> +<br /> +   rm /tmp/hiddenapflag # only add once<br /> +  fi<br /> + else<br /> +  rm /tmp/hiddenapflag<br /> + fi<br /> +fi<br /> +<br /> +lat=$(uci -q get system.@system[0].latitude)<br /> +long=$(uci -q get system.@system[0].longitude)<br /> +<br /> +# if we have Internet, we download the Hoodfile from the keyxchangev2<br /> +if hasInternet ; then<br /> + wget -T15 -t5 "<a href="http://keyserver.freifunk-franken.de/v2/?lat">http://keyserver.freifunk-franken.de/v2/?lat</a>=$lat&long=$long" -O /tmp/keyxchangev2data<br /> + #if no Internet, we connect to the hidden AP and download the file from another Node in range<br /> +else<br /> + # connect to wireless hidden ap here and download the json File from the nearest router<br /> + # 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?<br /> + if ! isGatewayAvailable ; then<br /> +  #now we haven't a gateway in Range, we search for a hidden AP to get a keyxchangev2data file!<br /> +  #first we delete all wifi settings<br /> +  if ! wifiDelAll; then<br /> +   echo "Can't delete current wifi setup"<br /> +   exit 1<br /> +  fi<br /> +  #now we look for phy and add this<br /> +  for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do<br /> +   if iw phy "$phy" info | grep -q -m1 "2... MHz"; then<br /> +    echo "$phy is 2.4 GHz"<br /> +    radio="$(wifiAddPhy "$phy" "$chan2ghz")"<br /> +    if [ -z "$radio" ]; then<br /> +     echo "Can't create radio for $phy"<br /> +     exit 1<br /> +    fi<br /> +   fi<br /> +   if iw phy "$phy" info | grep -q -m1 "5... MHz"; then<br /> +    echo "$phy is 5 GHz"<br /> +    radio="$(wifiAddPhy "$phy" "$chan5ghz")"<br /> +    if [ -z "$radio" ]; then<br /> +     echo "Can't create radio for $phy"<br /> +     exit 1<br /> +    fi<br /> +   fi<br /> +   #and here we add the station<br /> +   if ! wifiAddSta "$radio" "<a href="http://config.franken.freifunk.net">config.franken.freifunk.net</a>" "configSta"; then<br /> +    echo "Can't add Sta interface on $radio."<br /> +    exit 1<br /> +   else<br /> +    uci -q set network.configSta=interface<br /> +    uci -q set network.configSta.proto='static'<br /> +    uci -q commit network<br /> +   fi<br /> +  done<br /> +  <br /> +  wifi<br /> +  # wait a moment to start the interface<br /> +  sleep 10;<br /> +  # and here we can download the Hoodfile from the other node<br /> +  wget -T15 -t5 "http://[fe80::1%w2sta]/keyxchangev2data" -O /tmp/keyxchangev2data<br /> + else<br /> +  echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1"<br /> +  wget -T15 -t5 "http://[fe80::1%br-mesh]/keyxchangev2data" -O /tmp/keyxchangev2data<br /> + fi<br /> +fi<br /> +<br /> +if [ -s /tmp/keyxchangev2data ]; then<br /> +<br /> + # we get a json file in this format: <br /> + # <a href="https://pw.freifunk-franken.de/patch/205">https://pw.freifunk-franken.de/patch/205</a>/<br /> + # but without signature, every hood file we get is valid!<br /> +<br /> + catnew="$(cat /tmp/keyxchangev2data | sed 's/"timestamp":[0-9]*/"timestamp":0/')"<br /> + catold="$(cat /www/public/keyxchangev2data 2>/dev/null | sed 's/"timestamp":[0-9]*/"timestamp":0/')"<br /> + sumnew=$(echo "$catnew" | sha256sum | cut -f1 -d " ")<br /> + sumold=$(echo "$catold" | sha256sum | cut -f1 -d " ")<br /> +<br /> + json_load "$(cat /tmp/keyxchangev2data)"<br /> +<br /> + if [ "$sumnew" != "$sumold" ]; then<br /> +  echo "New file detect, we reconfigure the Node";<br /> +<br /> +  json_select hood<br /> +<br /> +  json_get_var hood name<br /> +  json_get_var mesh_bssid mesh_bssid<br /> +  json_get_var mesh_essid mesh_essid<br /> +  json_get_var essid essid<br /> +  # i think the next things we don't active this in the first version! we can do it later<br /> +  #json_get_var channel2 channel2<br /> +  #json_get_var mode2 mode2<br /> +  #json_get_var type2 type2<br /> +  #json_get_var channel5 channel5<br /> +  #json_get_var mode5 mode5<br /> +  #json_get_var type5 type5<br /> +  #json_get_var protocol protocol<br /> +  <br /> +  json_select ".." # back to root<br /> +<br /> +  echo "Setting hood name: $hood"<br /> +  uci set "system.@system[0].hood=$hood"<br /> +<br /> +  if ! wifiDelAll; then<br /> +   echo "Can't delete current wifi setup"<br /> +   exit 1<br /> +  fi<br /> +<br /> +  for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do<br /> +   if iw phy "$phy" info | grep -q -m1 "2... MHz"; then<br /> +    echo "$phy is 2.4 GHz"<br /> +    radio="$(wifiAddPhy "$phy" "$chan2ghz")"<br /> +    if [ -z "$radio" ]; then<br /> +     echo "Can't create radio for $phy"<br /> +     exit 1<br /> +    fi<br /> +   fi<br /> +   if iw phy "$phy" info | grep -q -m1 "5... MHz"; then<br /> +    echo "$phy is 5 GHz"<br /> +    radio="$(wifiAddPhy "$phy" "$chan5ghz")"<br /> +    if [ -z "$radio" ]; then<br /> +     echo "Can't create radio for $phy"<br /> +     exit 1<br /> +    fi<br /> +   fi<br /> +<br /> +   if ! wifiAddAP "$radio" "$essid" "mesh" "ap" "0"; then<br /> +    echo "Can't add AP interface on $radio."<br /> +    exit 1<br /> +   fi<br /> +<br /> +   # here we set a bit for add hidden AP<br /> +   touch /tmp/hiddenapflag<br /> +<br /> +   if ! wifiAddAdHocMesh "$radio" "$mesh_essid" "$mesh_bssid"; then<br /> +    echo "Can't add AP interface on $radio."<br /> +    exit 1<br /> +   fi<br /> +  done<br /> +<br /> +  echo "Loading wifi"<br /> +  wifi<br /> +<br /> +  # copy the file to webroot so that other Meshrouter can download it;<br /> +  # copy only after all other steps so IF can be reentered if something goes wrong<br /> +  cp /tmp/keyxchangev2data /www/public/<br /> +<br /> + else<br /> +  echo "We have no new file. We do nothing. We try it again in 5 minutes...";<br /> +  exit 0<br /> + fi<br /> + <br /> + # and now we read the VPN Data and give this data to fff-vpn<br /> + json_select vpn<br /> + Index=1<br /> + rm /tmp/fastd_fff_output<br /> + touch /tmp/fastd_fff_output<br /> + while json_select "$Index" > /dev/null<br /> + do<br /> +  json_get_var protocol protocol<br /> +  if [ "$protocol" == "fastd" ]; then<br /> +   json_get_var servername name<br /> +   echo "####${servername}.conf" >> /tmp/fastd_fff_output<br /> +   echo "#name \"${servername}\";" >> /tmp/fastd_fff_output<br /> +   json_get_var key key<br /> +   echo "key \"${key}\";" >> /tmp/fastd_fff_output<br /> +   json_get_var address address<br /> +   json_get_var port port<br /> +   echo "remote ipv4 \"${address}\" port $port float;" >> /tmp/fastd_fff_output<br /> +  fi<br /> +  echo "" >> /tmp/fastd_fff_output<br /> +  json_select ".." # back to vpn<br /> +  Index=$(( Index + 1 ))<br /> + done<br /> + echo "###" >> /tmp/fastd_fff_output<br /> + json_select ".." # back to root<br /> + #this we do every 5 minutes, because it can change the VPN Protocol<br /> + #and now we get to vpn-select Script and load VPNs<br /> + <br /> + if hasInternet ; then<br /> +  sh /usr/sbin/vpn-select<br /> + fi<br /> +else<br /> + echo "We haven't got a file. We do nothing. We try it again in 5 minutes...";<br /> + exit 0<br /> +fi<br /> diff --git a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select<br /> index bb4c933..bbc87cc 100755<br /> --- a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select<br /> +++ b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select<br /> @@ -1,7 +1,5 @@<br />  #!/bin/sh<br />  <br /> -test -f /tmp/started || exit<br /> -<br />  make_config() {<br />  # remove old config<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;">/etc/config/tunneldigger<br /></blockquote> diff --git a/src/packages/fff/fff/Makefile b/src/packages/fff/fff/Makefile<br /> index 166d423..305ab8d 100644<br /> --- a/src/packages/fff/fff/Makefile<br /> +++ b/src/packages/fff/fff/Makefile<br /> @@ -29,7 +29,8 @@ define Package/fff-base<br />               +fff-wireless \<br />               +fff-timeserver \<br />               +fff-vpn-select \<br /> -             +simple-tc<br /> +             +simple-tc \<br /> +             +fff-hoods<br />  endef<br />  <br />  define Package/fff-base/description<br /> <br /></blockquote><br /></pre></blockquote></div></body></html>