[PATCH v2 2/2] adds some basic packages

Tim Niemeyer tim.niemeyer at mastersword.de
Di Jul 21 12:42:50 CEST 2015


Hallo Tobias,

Gibt es von dir ein Signed-of? Und welcher Bedeutung wollen wir das Flag
zukommen lassen?

* Tobias Klaus <tk+ff at meskal.net> [21-07-15 10:50]:
> Date: Tue, 21 Jul 2015 10:50:22 +0200
> From: Tobias Klaus <tk+ff at meskal.net>
> To: franken-dev at freifunk.net
> Subject: [PATCH v2 2/2] adds some basic packages
> X-Envelope-From: tk+ff at meskal.net
> X-Envelope-To: <franken-dev at freifunk.net>
> X-Mailer: git-send-email 2.4.6
> 
> Basically these are just copies of old ffff-next with some whitespace
> fixes.
> No real functionality at the moment.
> 
> Not yet included:
> * uci-defaults script to initialize openwrt during first boot
> * a lot of other stuff
> * everything else we talked about
> * ...

Reviewed-by: Tim Niemeyer <tim.niemeyer at mastersword.de>

Tim

> ---
>  README.md                                          |   6 +
>  package.config                                     |   1 +
>  packages/.keepdir                                  |   0
>  packages/fastdstart/Makefile                       |  34 ++++
>  packages/fastdstart/files/usr/sbin/fastdstart      |  96 ++++++++++
>  packages/freifunk-franken/Makefile                 |  60 ++++++
>  .../files/etc/hotplug.d/iface/30-fastd             |   5 +
>  .../freifunk-franken/uci-defaults/99_installcron   |   6 +
>  packages/nodewatcher/Makefile                      |  37 ++++
>  packages/nodewatcher/files/etc/config/configurator |  24 +++
>  packages/nodewatcher/files/etc/config/nodewatcher  |   6 +
>  packages/nodewatcher/files/usr/sbin/configurator   | 172 +++++++++++++++++
>  packages/nodewatcher/files/usr/sbin/nodewatcher    | 210 +++++++++++++++++++++
>  13 files changed, 657 insertions(+)
>  delete mode 100644 packages/.keepdir
>  create mode 100644 packages/fastdstart/Makefile
>  create mode 100755 packages/fastdstart/files/usr/sbin/fastdstart
>  create mode 100644 packages/freifunk-franken/Makefile
>  create mode 100644 packages/freifunk-franken/files/etc/hotplug.d/iface/30-fastd
>  create mode 100644 packages/freifunk-franken/uci-defaults/99_installcron
>  create mode 100644 packages/nodewatcher/Makefile
>  create mode 100644 packages/nodewatcher/files/etc/config/configurator
>  create mode 100644 packages/nodewatcher/files/etc/config/nodewatcher
>  create mode 100644 packages/nodewatcher/files/usr/sbin/configurator
>  create mode 100755 packages/nodewatcher/files/usr/sbin/nodewatcher
> 
> diff --git a/README.md b/README.md
> index e2f9d36..67acbf7 100644
> --- a/README.md
> +++ b/README.md
> @@ -65,6 +65,12 @@ make menuconfig
>  </pre>
>  
>  Now select the "Target System" and "Target Profile" for your AP model.
> +Make sure, that you include one of the freifunk franken packages:
> +
> +freifunk-franken-basic
> +or
> +freifunk-franken-debug
> +
>  
>  Finally start the build process
>  <pre>
> diff --git a/package.config b/package.config
> index e69de29..b03faa5 100644
> --- a/package.config
> +++ b/package.config
> @@ -0,0 +1 @@
> +CONFIG_PACKAGE_freifunk-franken-basic=y
> diff --git a/packages/.keepdir b/packages/.keepdir
> deleted file mode 100644
> index e69de29..0000000
> diff --git a/packages/fastdstart/Makefile b/packages/fastdstart/Makefile
> new file mode 100644
> index 0000000..3a8312c
> --- /dev/null
> +++ b/packages/fastdstart/Makefile
> @@ -0,0 +1,34 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=fastdstart
> +PKG_VERSION:=1.0.0
> +PKG_VERSION:=1
> +
> +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/fastdstart
> +  SECTION:=net
> +  CATEGORY:=Network
> +  TITLE:=fastd key exchange
> +  DEPENDS:=+fastd
> +endef
> +
> +define Package/fastdstart/description
> +	Simple script to exchange fastd keys and start fastd
> +endef
> +
> +define Build/Prepare
> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile
> +endef
> +
> +define Package/fastdstart/install
> +	$(CP) ./files/* $(1)/
> +	chmod +x $(1)/usr/sbin/fastdstart
> +	mkdir -p $(1)/lib/cron
> +	echo "#check for new vpn keys every 5 mins" >> $(1)/lib/cron/${PKG_NAME}
> +	echo "*/5 * * * * /usr/sbin/fastdstart" >> $(1)/lib/cron/${PKG_NAME}
> +endef
> +
> +$(eval $(call BuildPackage,fastdstart))
> diff --git a/packages/fastdstart/files/usr/sbin/fastdstart b/packages/fastdstart/files/usr/sbin/fastdstart
> new file mode 100755
> index 0000000..cc2fe91
> --- /dev/null
> +++ b/packages/fastdstart/files/usr/sbin/fastdstart
> @@ -0,0 +1,96 @@
> +#!/bin/sh
> +
> +test -f /tmp/fastdstart.lock && exit 1
> +
> +touch /tmp/fastdstart.lock
> +
> +SERVER="no"
> +#SERVERNAME="--servername--"
> +
> +project="fff2"
> +
> +test_ipv4_host1="mastersword.de" # Tims server
> +test_ipv4_host2="8.8.8.8"        # Google DNS
> +test_ipv6_host1="heise.de"       # heise Zeitschriftenverlag
> +
> +# Only do something with fastd when the router has internet connection
> +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
> +	mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-freifunk/address 2>/dev/null)
> +	if [ "$SERVER" = "no" ]; then
> +		hostname=$(cat /proc/sys/kernel/hostname)
> +
> +		if [ "$hostname" = "OpenWrt" ]; then
> +			hostname=""
> +		fi
> +
> +		if [ "$hostname" = "" ]; then
> +			hostname=$mac
> +		fi
> +	else
> +		hostname=$SERVERNAME
> +	fi
> +
> +	if [ ! -d /etc/fastd ]; then
> +		mkdir /etc/fastd
> +	fi
> +
> +	if [ ! -d /etc/fastd/$project ]; then
> +		mkdir /etc/fastd/$project
> +
> +		mkdir /tmp/fastd_${project}_peers
> +		ln -s /tmp/fastd_${project}_peers /etc/fastd/$project/peers
> +		echo "#!/bin/sh" > /etc/fastd/$project/up.sh
> +		echo "ip link set up dev ${project}VPN" >> /etc/fastd/$project/up.sh
> +		echo "echo enable > /sys/devices/virtual/net/${project}VPN/batman_adv/no_rebroadcast" >> /etc/fastd/$project/up.sh
> +		echo "batctl if add ${project}VPN" >> /etc/fastd/$project/up.sh
> +		chmod +x /etc/fastd/$project/up.sh
> +
> +		secret=$(fastd --generate-key 2>&1 | grep -i secret | awk '{ print $2 }')
> +		echo "include peers from \"/etc/fastd/$project/peers\";" >> /etc/fastd/${project}/${project}.conf
> +		echo "log to syslog level warn;" >> /etc/fastd/${project}/${project}.conf
> +		echo "method \"null\";" >> /etc/fastd/${project}/${project}.conf
> +#		http://lists.nord-west.net/pipermail/freifunk-ol-dev/2013-July/000322.html
> +#		echo "bind 0.0.0.0:10000;" >> /etc/fastd/${project}/${project}.conf
> +		echo "interface \"${project}VPN\";" >> /etc/fastd/${project}/${project}.conf
> +		echo "mtu 1426;" >> /etc/fastd/${project}/${project}.conf
> +		echo "secret \"$secret\";" >> /etc/fastd/${project}/${project}.conf
> +		echo "on up \"/etc/fastd/${project}/up.sh\";" >> /etc/fastd/${project}/${project}.conf
> +		echo "secure handshakes no;" >> /etc/fastd/${project}/${project}.conf
> +	fi
> +
> +	if [ ! -d /tmp/fastd_${project}_peers ]; then
> +		mkdir /tmp/fastd_${project}_peers
> +	fi
> +
> +	pubkey=$(fastd -c /etc/fastd/$project/$project.conf --show-key --machine-readable)
> +#	port=666
> +
> +
> +#	fire up
> +	if [ "$(/sbin/ifconfig -a | grep -i ethernet | grep $project)" = "" ]; then
> +		/bin/rm /var/run/fastd.$project.pid
> +		fastd -c /etc/fastd/$project/$project.conf -d --pid-file /var/run/fastd.$project.pid
> +	fi
> +
> +#	register
> +	wget -T15 "http://mastersword.de/~reddog/${project}/?mac=$mac&name=$hostname&port=$port&key=$pubkey" -O /tmp/fastd_${project}_output
> +
> +	filenames=$(awk '/^####/ { gsub(/^####/, "", $0); gsub(/.conf/, "", $0); print $0; }' /tmp/fastd_${project}_output)
> +	for file in $filenames; do
> +		awk "{ if(a) print }; /^####$file.conf$/{a=1}; /^$/{a=0};" /tmp/fastd_${project}_output | sed 's/ float;/;/g' > /etc/fastd/$project/peers/$file
> +		echo 'float yes;' >> /etc/fastd/$project/peers/$file
> +	done
> +
> +	#reload
> +	kill -HUP $(cat /var/run/fastd.$project.pid)
> +else
> +	echo "Der Router kann keine Verbindung zum Fastdserver aufbauen"
> +	echo "$0 macht nichts!"
> +fi
> +
> +/bin/rm /tmp/fastdstart.lock
> +
> +exit 0
> +# vim: noexpandtab
> diff --git a/packages/freifunk-franken/Makefile b/packages/freifunk-franken/Makefile
> new file mode 100644
> index 0000000..cad486a
> --- /dev/null
> +++ b/packages/freifunk-franken/Makefile
> @@ -0,0 +1,60 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=freifunk-franken
> +PKG_VERSION:=1.0.0
> +PKG_RELEASE:=1
> +
> +PKG_BUILD_DIR:=$(BUILD_DIR)/freifunk
> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/freifunk-franken-basic
> +	SECTION:=base
> +	CATEGORY:=Config
> +	DEFAULT:=n
> +	TITLE:= Freifunk-Franken Basic
> +	URL:=http://freifunk-franken.de
> +	DEPENDS:=+kmod-batman-adv     \
> +	         +batctl              \
> +	         +alfred              \
> +	         +fastd               \
> +	         +fastdstart          \
> +	         +ip                  \
> +	         +odhcpd              \
> +	         +dnsmasq-dhcpv6      \
> +	         +ebtables            \
> +	         +kmod-ebtables-ipv4  \
> +	         +kmod-ebtables-ipv6  \
> +	         +haveged             \
> +	         + at ATH_USER_REGD      \
> +	         +nodewatcher
> +endef
> +
> +define Build/Prepare
> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile
> +endef
> +
> +define Package/freifunk-franken-basic/install
> +	$(CP) ./files/* $(1)/
> +	mkdir -p $(1)/lib/cron
> +	echo "#reboot every 1 days at 04:05" >> $(1)/lib/cron/$(PKG_NAME)
> +	echo "1 4 */5 * * /sbin/reboot" >> $(1)/lib/cron/$(PKG_NAME)
> +endef
> +
> +define Package/freifunk-franken/conffiles
> +	/etc/config/freifunk
> +endef
> +
> +define Package/freifunk-franken-debug
> +	SECTION:=base
> +	CATEGORY:=Config
> +	DEFAULT:=n
> +	TITLE:=Freifunk-Franken with debug tools
> +	DEPENDS:=+freifunk-franken-basic     \
> +	         + at KMOD_BATMAN_ADV_DEBUG_LOG \
> +	         +iperf                      \
> +	         +tcpdump-mini
> +endef
> +
> +$(eval $(call BuildPackage,freifunk-franken-basic))
> +$(eval $(call BuildPackage,freifunk-franken-debug))
> diff --git a/packages/freifunk-franken/files/etc/hotplug.d/iface/30-fastd b/packages/freifunk-franken/files/etc/hotplug.d/iface/30-fastd
> new file mode 100644
> index 0000000..b1ea7bd
> --- /dev/null
> +++ b/packages/freifunk-franken/files/etc/hotplug.d/iface/30-fastd
> @@ -0,0 +1,5 @@
> +#!/bin/sh
> +
> +[ "$ACTION" = "ifup" -a "$DEVICE" = "br-wan" ] || exit 0
> +
> +/usr/sbin/fastdstart
> diff --git a/packages/freifunk-franken/uci-defaults/99_installcron b/packages/freifunk-franken/uci-defaults/99_installcron
> new file mode 100644
> index 0000000..33c7e46
> --- /dev/null
> +++ b/packages/freifunk-franken/uci-defaults/99_installcron
> @@ -0,0 +1,6 @@
> +#!/bin/bash
> +
> +cat /lib/cron/* /etc/crontabs/root
> +
> +#execute on every restart before initscripts
> +exit 1
> diff --git a/packages/nodewatcher/Makefile b/packages/nodewatcher/Makefile
> new file mode 100644
> index 0000000..fe4731e
> --- /dev/null
> +++ b/packages/nodewatcher/Makefile
> @@ -0,0 +1,37 @@
> +include $(TOPDIR)/rules.mk
> +
> +PKG_NAME:=nodewatcher
> +PKG_VERSION:=1.0.0
> +PKG_VERSION:=1
> +
> +PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
> +
> +include $(INCLUDE_DIR)/package.mk
> +
> +define Package/nodewatcher
> +  SECTION:=net
> +  CATEGORY:=Network
> +  TITLE:=Nodewatcher: client component for Netmon
> +  DEPENDS:=+uhttpd
> +endef
> +
> +define Package/nodewatcher/description
> +	Freifunk Oldenburg Nodewatcher used to provide status data for Netmon
> +endef
> +
> +define Build/Prepare
> +	echo "all: " > $(PKG_BUILD_DIR)/Makefile
> +endef
> +
> +define Package/nodewatcher/install
> +	$(CP) ./files/* $(1)/
> +	chmod +x $(1)/usr/sbin/nodewatcher
> +	chmod +x $(1)/usr/sbin/configurator
> +	mkdir -p $(1)/lib/cron
> +	echo "# netmon" >> $(1)/lib/cron/${PKG_NAME}
> +	echo "*/5 * * * * /usr/sbin/nodewatcher; /usr/sbin/configurator" >> $(1)/lib/cron/${PKG_NAME}
> +	mkdir -p $(1)/www/public
> +	ln -s ../../tmp/node.data $(1)/www/public/node.data
> +endef
> +
> +$(eval $(call BuildPackage,nodewatcher))
> diff --git a/packages/nodewatcher/files/etc/config/configurator b/packages/nodewatcher/files/etc/config/configurator
> new file mode 100644
> index 0000000..83a2879
> --- /dev/null
> +++ b/packages/nodewatcher/files/etc/config/configurator
> @@ -0,0 +1,24 @@
> +config 'script'
> +	option 'error_level' '0'
> +	option 'logfile' '/var/log/configurator.log'
> +	option 'version' '1'
> +	option 'sync_hostname' '1'
> +
> +config 'api'
> +	option 'ipv4_address' '1'
> +	option 'ipv6_interface' 'br-mesh'
> +	option 'ipv6_address' 'fd00:fff:2003::ff:feee:1'
> +	option 'timeout' '5'
> +	option 'retry' '5'
> +	option 'api_key' '1'
> +
> +config 'crawl'
> +	option 'method' 'hash'
> +	option 'nickname' '1'
> +	option 'password' '1'
> +	option 'login_string' '1'
> +	option 'router_id' '1'
> +	option 'update_hash' '1'
> +
> +config 'netmon'
> +	option 'autoadd_ipv6_address' '1'
> diff --git a/packages/nodewatcher/files/etc/config/nodewatcher b/packages/nodewatcher/files/etc/config/nodewatcher
> new file mode 100644
> index 0000000..dfbaa11
> --- /dev/null
> +++ b/packages/nodewatcher/files/etc/config/nodewatcher
> @@ -0,0 +1,6 @@
> +config 'script'
> +        option 'version' '25'
> +	option 'error_level' '0'
> +	option 'logfile' '/var/log/nodewatcher.log'
> +	option 'data_file' '/tmp/node.data'
> +
> diff --git a/packages/nodewatcher/files/usr/sbin/configurator b/packages/nodewatcher/files/usr/sbin/configurator
> new file mode 100644
> index 0000000..850bcf8
> --- /dev/null
> +++ b/packages/nodewatcher/files/usr/sbin/configurator
> @@ -0,0 +1,172 @@
> +#!/bin/sh
> +# Netmon Configurator (C) 2010-2012 Freifunk Oldenburg
> +# Lizenz: GPL v3
> +
> +#Get the configuration from the uci configuration file
> +#If it does not exists, then get it from a normal bash file with variables.
> +if [ -f /etc/config/configurator ];then
> +	API_IPV4_ADRESS=`uci get configurator. at api[0].ipv4_address`
> +	API_IPV6_ADRESS=`uci get configurator. at api[0].ipv6_address`
> +	API_IPV6_INTERFACE=`uci get configurator. at api[0].ipv6_interface`
> +	API_TIMEOUT=`uci get configurator. at api[0].timeout`
> +	API_RETRY=`uci get configurator. at api[0].retry`
> +	SCRIPT_VERSION=`uci get configurator. at script[0].version`
> +	SCRIPT_ERROR_LEVEL=`uci get configurator. at script[0].error_level`
> +	SCRIPT_LOGFILE=`uci get configurator. at script[0].logfile`
> +	SCRIPT_SYNC_HOSTNAME=`uci get configurator. at script[0].sync_hostname`
> +	CRAWL_METHOD=`uci get configurator. at crawl[0].method`
> +	CRAWL_ROUTER_ID=`uci get configurator. at crawl[0].router_id`
> +	CRAWL_UPDATE_HASH=`uci get configurator. at crawl[0].update_hash`
> +	CRAWL_NICKNAME=`uci get configurator. at crawl[0].nickname`
> +	CRAWL_PASSWORD=`uci get configurator. at crawl[0].password`
> +	AUTOADD_IPV6_ADDRESS=`uci get configurator. at netmon[0].autoadd_ipv6_address`
> +else
> +	. `dirname $0`/configurator_config
> +fi
> +
> +API_RETRY=$(($API_RETRY - 1))
> +
> +if [ "$API_IPV4_ADRESS" != "1" ]; then
> +	netmon_api=$API_IPV4_ADRESS
> +else
> +	netmon_api="[$API_IPV6_ADRESS"%"$API_IPV6_INTERFACE]"
> +fi
> +
> +if [ "$SCRIPT_ERROR_LEVEL" -gt "1" ]; then
> +	err() {
> +		echo "$(date) [configurator]: $1" >> $SCRIPT_LOGFILE
> +	}
> +else
> +	err() {
> +		:
> +	}
> +fi
> +
> +sync_hostname() {
> +	err "Syncing hostname"
> +	api_return=$(wget -T $API_TIMEOUT -q -O - "http://$netmon_api/api_csv_configurator.php?section=get_hostname&authentificationmethod=$CRAWL_METHOD&nickname=$CRAWL_NICKNAME&password=$CRAWL_PASSWORD&router_auto_update_hash=$CRAWL_UPDATE_HASH&router_id=$CRAWL_ROUTER_ID")
> +	ret=${api_return%%,*}
> +	if [ "$ret" != "success" ]; then
> +		err "Ther was an error fetching the hostname"
> +		exit 0
> +	elif [ "$ret" = "success" ]; then
> +		netmon_hostname=${api_return%,*}
> +		netmon_hostname=${netmon_hostname#*,}
> +
> +		#check for valid hostname as specified in rfc 1123
> +		#see http://stackoverflow.com/a/3824105
> +		regex='^([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])'
> +		regex=$regex'(\.([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}[a-zA-Z0-9]))*$'
> +		if [ "${#netmon_hostname}" -le "255" ]; then
> +			if echo -n $netmon_hostname | egrep -q "$regex"; then
> +				if [ "$netmon_hostname" != "`cat /proc/sys/kernel/hostname`" ]; then
> +					err "Setting new hostname: $netmon_hostname"
> +					uci set system. at system[0].hostname=$netmon_hostname
> +					uci commit
> +					echo $netmon_hostname > /proc/sys/kernel/hostname
> +				else
> +					err "Hostname is up to date"
> +				fi
> +			else
> +				err "Hostname ist malformed"
> +				exit 0
> +			fi
> +		else
> +			err "Hostname exceeds the maximum length of 255 characters"
> +			exit 0
> +		fi
> +	fi
> +}
> +
> +assign_router() {
> +	hostname=`cat /proc/sys/kernel/hostname`
> +
> +	#Choose right login String
> +	#Here maybe a ; to much at the end..??
> +	login_strings=$(awk '{ mac=toupper($1); gsub(":", "", mac); printf mac ";" }' /sys/class/net/br-mesh/address /sys/class/net/eth0/address /sys/class/net/ath0/address 2> /dev/null)
> +	ergebnis=$(wget -T $API_TIMEOUT -q -O - "http://$netmon_api/api_csv_configurator.php?section=test_login_strings&login_strings=$login_strings")
> +	router_auto_assign_login_string=${ergebnis#*;}
> +	ergebnis=${ergebnis%;*}
> +	if [ "$ergebnis" = "error" ]; then
> +		router_auto_assign_login_string=${login_strings%%;*}
> +		err "A router with this login string does not exist: $login_strings"
> +		err "Using $router_auto_assign_login_string as login string"
> +	fi
> +
> +	#Try to assign Router with choosen login string
> +	ergebnis=$(wget -T $API_TIMEOUT -q -O - "http://$netmon_api/api_csv_configurator.php?section=router_auto_assign&router_auto_assign_login_string=$router_auto_assign_login_string&hostname=$hostname")
> +	ret=${ergebnis%%;*}
> +	errstr=${ergebnis#*;}
> +	errstr=${errstr%%;*}
> +	if [ "$ret" != "success" ]; then
> +		err "The router has not been assigned to a router in Netmon"
> +		err "Failure on router_auto_assign: $errstr. Exiting"
> +		exit 0
> +	elif [ "$ret" = "success" ]; then
> +		update_hash=${ergebnis%;*;*}
> +		update_hash=${update_hash##*;}
> +		api_key=${ergebnis##*;}
> +		#write new config
> +		uci set configurator. at crawl[0].router_id=$errstr
> +		uci set configurator. at crawl[0].update_hash=$update_hash
> +		uci set configurator. at api[0].api_key=$api_key
> +		#set also new router id for nodewatcher
> +		#uci set nodewatcher. at crawl[0].router_id=$errstr
> +
> +		err "The router $errstr has been assigned with a router in Netmon"
> +		uci commit
> +
> +		CRAWL_METHOD=`uci get configurator. at crawl[0].method`
> +		CRAWL_ROUTER_ID=$errstr
> +		CRAWL_UPDATE_HASH=$update_hash
> +		CRAWL_NICKNAME=`uci get configurator. at crawl[0].nickname`
> +		CRAWL_PASSWORD=`uci get configurator. at crawl[0].password`
> +	fi
> +}
> +
> +autoadd_ipv6_address() {
> +	err "Doing IPv6 autoadd"
> +	ipv6_link_local_addr=$(ip addr show dev br-mesh scope link | awk '/inet6/{print $2}')
> +	ipv6_link_local_netmask=${ipv6_link_local_addr##*/}
> +	ipv6_link_local_addr=${ipv6_link_local_addr%%/*}
> +	ergebnis=$(wget -T $API_TIMEOUT -q -O - "http://$netmon_api/api_csv_configurator.php?section=autoadd_ipv6_address&authentificationmethod=$CRAWL_METHOD&nickname=$CRAWL_NICKNAME&password=$CRAWL_PASSWORD&router_auto_update_hash=$CRAWL_UPDATE_HASH&router_id=$CRAWL_ROUTER_ID&networkinterface_name=br-mesh&ip=$ipv6_link_local_addr&netmask=$ipv6_link_local_netmask&ipv=6")
> +	ret=${ergebnis%%,*}
> +	if [ "$ret" = "success" ]; then
> +		uci set configurator. at netmon[0].autoadd_ipv6_address='0'
> +		uci commit
> +		err "The IPv6 address of the router $CRAWL_ROUTER_ID has been added to the router in Netmon"
> +		err "IPv6 Autoadd has been disabled cause it is no longer necesarry"
> +	else
> +		routerid=${ergebnis##*,}
> +		if [ "$routerid" = "$CRAWL_ROUTER_ID" ]; then
> +			err "The IPv6 address already exists in Netmon on this router. Maybe because of a previos assignment"
> +			uci set configurator. at netmon[0].autoadd_ipv6_address='0'
> +			uci commit
> +			err "IPv6 Autoadd has been disabled cause it is no longer necesarry"
> +		else
> +			err "The IPv6 address already exists in Netmon on another router $routerid"
> +		fi
> +	fi
> +}
> +
> +if [ "$CRAWL_METHOD" = "login" ]; then
> +	err "Authentification method is: username and passwort"
> +elif [ "$CRAWL_METHOD" = "hash" ]; then
> +	err "Authentification method: autoassign and hash"
> +	err "Checking if the router is already assigned to a router in Netmon"
> +	if [ "$CRAWL_UPDATE_HASH" = "1" ]; then
> +		err "The router is not assigned to a router in Netmon"
> +		err "Trying to assign the router"
> +		assign_router
> +	else
> +		err "The router is already assigned to a router in Netmon"
> +	fi
> +fi
> +
> +if [ "$AUTOADD_IPV6_ADDRESS" = "1" ]; then
> +	autoadd_ipv6_address
> +fi
> +
> +if [ "$SCRIPT_SYNC_HOSTNAME" = "1" ]; then
> +	sync_hostname
> +fi
> diff --git a/packages/nodewatcher/files/usr/sbin/nodewatcher b/packages/nodewatcher/files/usr/sbin/nodewatcher
> new file mode 100755
> index 0000000..6406518
> --- /dev/null
> +++ b/packages/nodewatcher/files/usr/sbin/nodewatcher
> @@ -0,0 +1,210 @@
> +#!/bin/sh
> +# Netmon Nodewatcher (C) 2010-2012 Freifunk Oldenburg
> +# License; GPL v3
> +
> +SCRIPT_VERSION="30"
> +
> +#Get the configuration from the uci configuration file
> +#If it does not exists, then get it from a normal bash file with variables.
> +if [ -f /etc/config/nodewatcher ];then
> +	SCRIPT_ERROR_LEVEL=`uci get nodewatcher. at script[0].error_level`
> +	SCRIPT_LOGFILE=`uci get nodewatcher. at script[0].logfile`
> +	SCRIPT_DATA_FILE=`uci get nodewatcher. at script[0].data_file`
> +	CLIENT_INTERFACES=`uci get nodewatcher. at network[0].client_interfaces`
> +else
> +	. `dirname $0`/nodewatcher_config
> +fi
> +
> +if [ $SCRIPT_ERROR_LEVEL -gt "1" ]; then
> +    err() {
> +        echo $1 >> $SCRIPT_LOGFILE
> +    }
> +else
> +    err() {
> +        :
> +    }
> +fi
> +
> +#this method checks id the logfile has bekome too big and deletes the first X lines
> +delete_log() {
> +	if [ -f $SCRIPT_LOGFILE ]; then
> +		if [ `ls -la $SCRIPT_LOGFILE | awk '{ print $5 }'` -gt "6000" ]; then
> +			sed -i '1,60d' $SCRIPT_LOGFILE
> +            err "`date`: Logfile has been made smaller"
> +		fi
> +	fi
> +}
> +
> +#this method generates the crawl data xml file that is beeing fetched by netmon
> +#and provided by a small local httpd
> +crawl() {
> +	#Get system data from other locations
> +    err "`date`: Collecting basic system status data"
> +    hostname="$(cat /proc/sys/kernel/hostname)"
> +	uptime=$(awk '{ printf "<uptime>"$1"</uptime><idletime>"$2"</idletime>" }' /proc/uptime)
> +
> +    memory=$(awk '
> +        /^MemTotal/ { printf "<memory_total>"$2"</memory_total>" }
> +        /^Cached:/ { printf "<memory_caching>"$2"</memory_caching>" }
> +        /^Buffers/ { printf "<memory_buffering>"$2"</memory_buffering>" }
> +        /^MemFree/ { printf "<memory_free>"$2"</memory_free>" }
> +    ' /proc/meminfo)
> +	cpu=$(awk -F': ' '
> +        /model/ { printf "<cpu>"$2"</cpu>" }
> +        /system type/ { printf "<chipset>"$2"</chipset>" }
> +    ' /proc/cpuinfo)
> +	local_time="`date +%s`"
> +	load=$(awk '{ printf "<loadavg>"$3"</loadavg><processes>"$4"</processes>" }' /proc/loadavg)
> +
> +    err "`date`: Collecting version information"
> +
> +    batman_adv_version=$(cat /sys/module/batman_adv/version)
> +	kernel_version=$(uname -r)
> +	fastd_version=$(fastd -v | awk '{ print $2 }')
> +	nodewatcher_version=$SCRIPT_VERSION
> +
> +    # example for /etc/openwrt_release:
> +    #DISTRIB_ID="OpenWrt"
> +    #DISTRIB_RELEASE="Attitude Adjustment"
> +    #DISTRIB_REVISION="r35298"
> +    #DISTRIB_CODENAME="attitude_adjustment"
> +    #DISTRIB_TARGET="atheros/generic"
> +    #DISTRIB_DESCRIPTION="OpenWrt Attitude Adjustment 12.09-rc1"
> +	. /etc/openwrt_release
> +    distname=$DISTRIB_ID
> +    distversion=$DISTRIB_RELEASE
> +
> +    # example for /etc/firmware_release:
> +    #FIRMWARE_VERSION="95f36685e7b6cbf423f02cf5c7f1e785fd4ccdae-dirty"
> +    #RELEASE_DATE="build date: Di 29. Jan 19:33:34 CET 2013"
> +    #FIRMWARE_REVISION="build date: Di 29. Jan 19:33:34 CET 2013"
> +    #OPENWRT_CORE_REVISION="35298"
> +    #OPENWRT_FEEDS_PACKAGES_REVISION="35298"
> +	#. /etc/firmware_release
> +	SYSTEM_DATA="<status>online</status><hostname>$hostname</hostname><distname>$distname</distname><distversion>$distversion</distversion>$cpu$memory$load$uptime<local_time>$local_time</local_time><batman_advanced_version>$batman_adv_version</batman_advanced_version><kernel_version>$kernel_version</kernel_version><fastd_version>$fastd_version</fastd_version><nodewatcher_version>$nodewatcher_version</nodewatcher_version><firmware_version>$FIRMWARE_VERSION</firmware_version><firmware_revision>$FIRMWARE_REVISION</firmware_revision><openwrt_core_revision>$OPENWRT_CORE_REVISION</openwrt_core_revision><openwrt_feeds_packages_revision>$OPENWRT_FEEDS_PACKAGES_REVISION</openwrt_feeds_packages_revision>"
> +
> +    err "`date`: Collecting information from network interfaces"
> +
> +	#Get interfaces
> +	#IFACES=`cat /proc/net/dev | awk -F: '!/\|/ { gsub(/[[:space:]]*/, "", $1); split($2, a, " "); printf("%s=%s=%s ", $1, a[1], a[9]) }'`
> +
> +	interface_data=""
> +	#Loop interfaces
> +	#for entry in $IFACES; do
> +    for filename in `grep 'up\|unknown' /sys/class/net/*/operstate`; do
> +        ifpath=${filename%/operstate*}
> +        iface=${ifpath#/sys/class/net/}
> +		if [ "$iface" = "lo" ]; then
> +            continue
> +        fi
> +
> +        #Get interface data
> +        addrs="$(ip addr show dev ${iface} | awk '
> +            /ether/ { printf "<mac_addr>"$2"</mac_addr>" }
> +            /inet / { split($2, a, "/"); printf "<ipv4_addr>"a[1]"</ipv4_addr>" }
> +            /inet6/ && /scope global/ { printf "<ipv6_addr>"$2"</ipv6_addr>" }
> +            /inet6/ && /scope link/ { printf "<ipv6_link_local_addr>"$2"</ipv6_link_local_addr>"}
> +            /mtu/ { printf "<mtu>"$5"</mtu>" }
> +        ')"
> +        #mac_addr="`cat $ifpath/address`"
> +        #ipv4_addr="`ip addr show dev ${iface} | awk '/inet / { split($2, a, "/"); print a[1] }'`"
> +        #ipv6_addr="`ip addr show dev ${iface} scope global | awk '/inet6/ { print $2 }'`"
> +        #ipv6_link_local_addr="`ip addr show dev ${iface} scope link | awk '/inet6/ { print $2 }'`"
> +        #mtu=`cat $ifpath/mtu`
> +        traffic_rx=`cat $ifpath/statistics/rx_bytes`
> +        traffic_tx=`cat $ifpath/statistics/tx_bytes`
> +
> +        #interface_data=$interface_data"<$iface><name>$iface</name><mac_addr>$mac_addr</mac_addr><ipv4_addr>$ipv4_addr</ipv4_addr><ipv6_addr>$ipv6_addr</ipv6_addr><ipv6_link_local_addr>$ipv6_link_local_addr</ipv6_link_local_addr><traffic_rx>$traffic_rx</traffic_rx><traffic_tx>$traffic_tx</traffic_tx><mtu>$mtu</mtu>"
> +        interface_data=$interface_data"<$iface><name>$iface</name>$addrs<traffic_rx>$traffic_rx</traffic_rx><traffic_tx>$traffic_tx</traffic_tx>"
> +
> +
> +        interface_data=$interface_data$(iwconfig ${iface} 2>/dev/null | awk -F':' '
> +            /Mode/{ split($2, m, " "); printf "<wlan_mode>"m[1]"</wlan_mode>" }
> +            /Cell/{ split($0, c, " "); printf "<wlan_bssid>"c[5]"</wlan_bssid>" }
> +            /ESSID/ { split($0, e, "\""); printf "<wlan_essid>"e[2]"</wlan_essid>" }
> +            /Freq/{ split($3, f, " "); printf "<wlan_frequency>"f[1]f[2]"</wlan_frequency>" }
> +            /Tx-Power/{ split($0, p, "="); sub(/[[:space:]]*$/, "", p[2]); printf "<wlan_tx_power>"p[2]"</wlan_tx_power>" }
> +        ')"</$iface>"
> +
> +        #if [ "`iwconfig ${iface} 2>/dev/null | grep IEEE`" != "" ]; then
> +        #    wlan_mode="`iwconfig $iface | awk -F':' '/Mode/{ split($2, m, " "); print m[1] }'`"
> +        #
> +        #    if [ $wlan_mode = "Master" ]; then
> +        #        wlan_bssid="`iw $iface info | awk '/addr/{ print $2 }'`"
> +        #    elif [ $wlan_mode = "Ad-Hoc" ]; then
> +        #        wlan_bssid="`iwconfig $iface | awk '/Cell/{ print $5 }'`"
> +        #    fi
> +        #
> +        #    wlan_essid="`iwconfig ${iface} | awk -F'"' '/ESSID/ { print $2 }'`"
> +        #    wlan_frequency="`iwconfig $iface | awk -F':' '/Freq/{ split($3, f, " "); print f[1] }'`"
> +        #    wlan_tx_power="`iwconfig $iface | awk -F'=' '/Tx-Power/{ print $2 }'`"
> +        #
> +        #    interface_data=$interface_data"<wlan_mode>$wlan_mode</wlan_mode><wlan_frequency>$wlan_frequency</wlan_frequency><wlan_essid>$wlan_essid</wlan_essid><wlan_bssid>$wlan_bssid</wlan_bssid><wlan_tx_power>$wlan_tx_power</wlan_tx_power>"
> +        #fi
> +        #interface_data=$interface_data"</$iface>"
> +	done
> +
> +    err "`date`: Collecting information from batman advanced and it´s interfaces"
> +	#B.A.T.M.A.N. advanced
> +    if [ -f /sys/module/batman_adv/version ]; then
> +        for iface in $(grep active /sys/class/net/*/batman_adv/iface_status); do
> +            status=${iface#*:}
> +            iface=${iface%/batman_adv/iface_status:active}
> +            iface=${iface#/sys/class/net/}
> +            BATMAN_ADV_INTERFACES=$BATMAN_ADV_INTERFACES"<$iface><name>$iface</name><status>$status</status></$iface>"
> +        done
> +
> +        batman_adv_originators=$(awk \
> +            'BEGIN { FS=" "; i=0 }
> +            /O/ { next }
> +            /B/ { next }
> +            {   sub("\\(", "", $0)
> +                sub("\\)", "", $0)
> +                sub("\\[", "", $0)
> +                sub("\\]:", "", $0)
> +                sub("  ", " ", $0)
> +                printf "<originator_"i"><originator>"$1"</originator><link_quality>"$3"</link_quality><nexthop>"$4"</nexthop><last_seen>"$2"</last_seen><outgoing_interface>"$5"</outgoing_interface></originator_"i">"
> +                i++
> +            }' /sys/kernel/debug/batman_adv/bat0/originators)
> +
> +		batman_adv_gateway_mode=$(batctl gw)
> +
> +		batman_adv_gateway_list=$(awk \
> +			'BEGIN { FS=" "; i=0 }
> +			/Gateway/ { next }
> +			/No gateways/ { next }
> +			{	sub("=>", "true", $0)
> +				sub("  ", "false", $0)
> +				sub("\\(", "", $0)
> +				sub("\\)", "", $0)
> +				sub("\\[", "", $0)
> +				sub("\\]:", "", $0)
> +				sub("  ", " ", $0)
> +				printf "<gateway_"i"><selected>"$1"</selected><gateway>"$2"</gateway><link_quality>"$3"</link_quality><nexthop>"$4"</nexthop><outgoing_interface>"$5"</outgoing_interface><gw_class>"$6" "$7" "$8"</gw_class></gateway_"i">"
> +				i++
> +			}' /sys/kernel/debug/batman_adv/bat0/gateways)
> +    fi
> +    err "`date`: Collecting information about conected clients"
> +	#CLIENTS
> +
> +    client_count=$(batctl tl | tail -n+3 | grep -v -e "^[ ]*\*" | wc -l)
> +
> +    err "`date`: Putting all information into a XML-File and save it at "$SCRIPT_DATA_FILE
> +
> +	DATA="<?xml version='1.0' standalone='yes'?><data><system_data>$SYSTEM_DATA</system_data><interface_data>$interface_data</interface_data><batman_adv_interfaces>$BATMAN_ADV_INTERFACES</batman_adv_interfaces><batman_adv_originators>$batman_adv_originators</batman_adv_originators><batman_adv_gateway_mode>$batman_adv_gateway_mode</batman_adv_gateway_mode><batman_adv_gateway_list>$batman_adv_gateway_list</batman_adv_gateway_list><client_count>$client_count</client_count></data>"
> +
> +	#write data to hxml file that provides the data on httpd
> +	echo $DATA | gzip > $SCRIPT_DATA_FILE
> +}
> +
> +LANG=C
> +
> +#Prüft ob das logfile zu groß geworden ist
> +err "`date`: Check logfile"
> +delete_log
> +
> +#Erzeugt die statusdaten
> +err "`date`: Generate actual status data"
> +crawl
> +
> +exit 0
> -- 
> 2.4.6
> 
> -- 
> franken-dev mailing list
> franken-dev at freifunk.net
> http://lists.freifunk.net/mailman/listinfo/franken-dev-freifunk.net


Tim Niemeyer
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : signature.asc
Dateityp    : application/pgp-signature
Dateigröße  : 836 bytes
Beschreibung: Digital signature
URL         : <http://lists.freifunk.net/pipermail/franken-dev-freifunk.net/attachments/20150721/88fd7e4b/attachment-0002.sig>


Mehr Informationen über die Mailingliste franken-dev