summaryrefslogtreecommitdiffhomepage
path: root/contrib/package
diff options
context:
space:
mode:
authorManuel Munz <freifunk@somakoma.de>2011-06-23 15:52:00 +0000
committerManuel Munz <freifunk@somakoma.de>2011-06-23 15:52:00 +0000
commitab87896104be09072ccccad305588d46370ab5ad (patch)
treefc3c5a5db319668cf1185c671268bc8cdae7316b /contrib/package
parente88fd858a1c0d3dbac4703224dc63cb498839432 (diff)
Add new meshwizard (WIP)
Diffstat (limited to 'contrib/package')
-rw-r--r--contrib/package/luci/Makefile7
-rw-r--r--contrib/package/meshwizard/Makefile39
-rw-r--r--contrib/package/meshwizard/files/etc/config/meshwizard7
-rw-r--r--contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh63
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/check-range-in-range.sh31
-rw-r--r--contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/common.awk20
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_bssid.sh33
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_dhcp_ip.sh6
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh59
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/ipcalc-cidr.sh41
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh20
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh43
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh33
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dnsmasq.sh31
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh156
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh91
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh126
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh32
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh107
-rwxr-xr-xcontrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh96
20 files changed, 1038 insertions, 3 deletions
diff --git a/contrib/package/luci/Makefile b/contrib/package/luci/Makefile
index 8f2f909c3..3965e51a9 100644
--- a/contrib/package/luci/Makefile
+++ b/contrib/package/luci/Makefile
@@ -197,9 +197,7 @@ define Package/luci-mod-freifunk-community
SUBMENU:=Freifunk
TITLE:=Freifunk Community Meta-Package
DEPENDS+= \
- +luci-lib-web +luci-app-splash \
- +luci-app-ffwizard \
- +luci-i18n-german \
+ +luci-lib-web +luci-app-splash +luci-i18n-german \
+PACKAGE_luci-mod-freifunk-community:olsrd +PACKAGE_luci-mod-freifunk-community:olsrd-mod-dyn-gw-plain \
+PACKAGE_luci-mod-freifunk-community:olsrd-mod-txtinfo +PACKAGE_luci-mod-freifunk-community:olsrd-mod-nameservice \
+PACKAGE_luci-mod-freifunk-community:olsrd-mod-watchdog +PACKAGE_luci-mod-freifunk-community:kmod-tun \
@@ -309,6 +307,9 @@ $(eval $(call application,firewall,Firmware and Portforwarding application,\
$(eval $(call application,freifunk-policyrouting,Policy routing for mesh traffic,\
+PACKAGE_luci-app-freifunk-policyrouting:freifunk-policyrouting +luci-mod-freifunk))
+$(eval $(call application,meshwizard, Shellscript based wizard to setup mesh networks,\
+ +meshwizard +luci-mod-freifunk))
+
$(eval $(call application,olsr,OLSR configuration and status module,\
+luci-mod-admin-full +PACKAGE_luci-app-olsr:olsrd +PACKAGE_luci-app-olsr:olsrd-mod-txtinfo))
diff --git a/contrib/package/meshwizard/Makefile b/contrib/package/meshwizard/Makefile
new file mode 100644
index 000000000..d665b46a4
--- /dev/null
+++ b/contrib/package/meshwizard/Makefile
@@ -0,0 +1,39 @@
+# Copyright (C) 2011 Manuel Munz <freifunk at somakoma de>
+# This is free software, licensed under the Apache 2.0 license.
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=meshwizard
+PKG_RELEASE:=1
+
+PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)
+
+include $(INCLUDE_DIR)/package.mk
+
+define Package/meshwizard
+ SECTION:=luci
+ CATEGORY:=LuCI
+ SUBMENU:=Freifunk
+ TITLE:=Shell script based wizard for Mesh networks
+ DEPENDS:=+firewall
+endef
+
+define Package/meshwizard/description
+ A shellscript based wizard to simplify the setup of a typical mesh node (e.g. for Freifunk.net)
+endef
+
+define Build/Prepare
+ mkdir -p $(PKG_BUILD_DIR)
+endef
+
+define Build/Configure
+endef
+
+define Build/Compile
+endef
+
+define Package/meshwizard/install
+ $(CP) ./files/* $(1)/
+endef
+
+$(eval $(call BuildPackage,meshwizard))
diff --git a/contrib/package/meshwizard/files/etc/config/meshwizard b/contrib/package/meshwizard/files/etc/config/meshwizard
new file mode 100644
index 000000000..a60b0cc44
--- /dev/null
+++ b/contrib/package/meshwizard/files/etc/config/meshwizard
@@ -0,0 +1,7 @@
+config 'netconfig' 'netconfig'
+
+config 'general' 'general'
+ option 'sharenet' '0'
+ option 'local_restrict' '1'
+ option 'cleanup' '1'
+
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh
new file mode 100644
index 000000000..5e0e19418
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/functions.sh
@@ -0,0 +1,63 @@
+uci_remove_list_element() {
+ local option="$1"
+ local value="$2"
+ local list="$(uci get $option)"
+ local elem
+
+ uci delete $option
+ for elem in $list; do
+ if [ "$elem" != "$value" ]; then
+ uci add_list $option=$elem
+ fi
+ done
+}
+
+set_defaults() {
+ for def in $(env |grep "^$1"); do
+ option=${def/$1/}
+ uci set $2.$option
+ echo " ${option/=/: }"
+ done
+}
+
+# 1 argument: section to remove
+section_cleanup() {
+ uci -q delete $1 && msg_cleanup $1 || msg_cleanup_error $1
+}
+
+# 3 arguements: 1=config name 2=oldname 3=newname
+section_rename() {
+ uci -q rename $1.$2=$3 && msg_rename $1.$2 $1.$3 || msg_rename_error $1.2 $1.$3
+}
+
+msg_start() {
+ echo " Starting configuration of $1"
+}
+
+msg_cleanup() {
+ echo " Cleanup: Removed section $1."
+}
+
+msg_cleanup_error() {
+ echo -e " \033[1mWarning:\033[0m Cleanup of $1 failed."
+}
+
+msg_missing_value() {
+ echo -e " \033[1mWarning:\033[0m Configuration option for $2 is missing in $1."
+}
+
+msg_success() {
+ echo " Finished."
+}
+
+msg_error() {
+ echo " \033[1mError: \033[0mThere was a problem."
+}
+
+msg_rename() {
+ echo " Renamed unnamed section $1 to $2."
+}
+
+msg_rename_error() {
+ echo " \033[1mWarning:\033[0m Could not rename $1 to $2."
+}
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/check-range-in-range.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/check-range-in-range.sh
new file mode 100755
index 000000000..c889c55ed
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/check-range-in-range.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# Checks whether a netrange is inside another netrange, returns 1 if true
+# Takes two arguments: $1: net from which we want to know if it is inside $2
+# nets need to be given in CIDR notation
+
+dir=$(dirname $0)
+
+awk -f $dir/common.awk -f - $* <<EOF
+BEGIN {
+
+ slpos=index(ARGV[1],"/")
+ ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
+ netmask=compl(2**(32-int(substr(ARGV[1],slpos+1)))-1)
+ network=and(ipaddr,netmask)
+ broadcast=or(network,compl(netmask))
+
+ slpos2=index(ARGV[2],"/")
+ ipaddr2=ip2int(substr(ARGV[2],0,slpos2-1))
+ netmask2=compl(2**(32-int(substr(ARGV[2],slpos2+1)))-1)
+ network2=and(ipaddr2,netmask2)
+ broadcast2=or(network2,compl(netmask2))
+
+ if (network >= network2) {
+ if (network <= broadcast2) {
+ if (broadcast <= broadcast2) {
+ print "1"
+ }
+ }
+ }
+}
+EOF
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/common.awk b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/common.awk
new file mode 100644
index 000000000..5b03d06be
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/common.awk
@@ -0,0 +1,20 @@
+function bitcount(c) {
+ c=and(rshift(c, 1),0x55555555)+and(c,0x55555555)
+ c=and(rshift(c, 2),0x33333333)+and(c,0x33333333)
+ c=and(rshift(c, 4),0x0f0f0f0f)+and(c,0x0f0f0f0f)
+ c=and(rshift(c, 8),0x00ff00ff)+and(c,0x00ff00ff)
+ c=and(rshift(c,16),0x0000ffff)+and(c,0x0000ffff)
+ return c
+}
+
+function ip2int(ip) {
+ for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x])
+ return ret
+}
+
+function int2ip(ip,ret,x) {
+ ret=and(ip,255)
+ ip=rshift(ip,8)
+ for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++);
+ return ret
+}
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_bssid.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_bssid.sh
new file mode 100755
index 000000000..fa042abae
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_bssid.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# create essid from channel, takes two args:
+# $1 = channel (integer)
+# $2 = community (optional)
+channel=$1
+community=$2
+
+. /etc/functions.sh
+
+
+# Try to get BSSID from profile first
+config_load profile_$community
+config_get bssid bssidscheme $channel
+
+if [ -z "$bssid" ]; then
+ case $channel in
+ [1-9])
+ bssid="$(printf "%X\n" $channel)2:CA:FF:EE:BA:BE"
+ ;;
+ 1[0-4])
+ bssid="$(printf "%X\n" $channel)2:CA:FF:EE:BA:BE"
+ ;;
+ [3-9][0-9])
+ bssid="00:$channel:CA:FF:EE:EE"
+ ;;
+ 1[0-9][0-9])
+ bssid="${channel/1/01:}:CA:FF:EE:EE"
+ ;;
+ *) bssid="02:CA:FF:EE:BA:BE"
+ ;;
+ esac
+fi
+echo $bssid
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_dhcp_ip.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_dhcp_ip.sh
new file mode 100755
index 000000000..e559166f4
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/gen_dhcp_ip.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+# generates a dhcp-ip and netrange from a given ip/subnet
+# takes 2 arguments:
+# $1: Ip Address (of the Interface for which we want to generate an ip)
+
+echo "$1" | awk 'BEGIN { FS = "." } ; { print "6."$3"."$4".1" }'
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh
new file mode 100755
index 000000000..a5f670dd5
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/initial_config.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# This is only run once (usually after flashing an image from the imagebuilder)
+# It sets up the initial config for this node.
+
+
+. /etc/functions.sh
+. $dir/functions.sh
+
+### System config
+
+config_load system
+
+# Rename system config
+handle_system() {
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename system $1 system
+ fi
+}
+config_foreach handle_system system
+
+if [ -n "$(uci -q get meshwizard.system)" ]; then
+ echo " + Setup system"
+ uci show meshwizard.system | sed 's/^meshwizard/uci set system/g' | while read line; do
+ eval $line
+ echo " $line"
+ done
+ uci -q delete meshwizard.system
+fi
+
+if [ -n "$(uci -q get meshwizard.community)" ]; then
+ echo " + Setup community"
+ uci show meshwizard.community | sed 's/^meshwizard/freifunk/g' | while read line; do
+ eval uci set $line
+ echo " $line"
+ done
+ uci -q delete meshwizard.community
+fi
+
+if [ -n "$(uci -q get meshwizard.contact)" ]; then
+ echo " + Setup contact"
+ uci show meshwizard.contact | sed 's/^meshwizard/freifunk/g' | while read line; do
+ eval uci set $line
+ echo " $line"
+ done
+ uci -q delete meshwizard.contact
+fi
+
+if [ -n "$(uci -q get meshwizard.luci_main)" ]; then
+ echo " + Setup luci"
+ uci show meshwizard.luci_main |sed -e 's/^meshwizard/luci/g' -e 's/luci_main/main/' | while read line; do
+ eval uci set $line
+ echo " $line"
+ done
+ uci -q delete meshwizard.luci_main
+fi
+
+uci commit
+
+
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/ipcalc-cidr.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/ipcalc-cidr.sh
new file mode 100755
index 000000000..39d051ec1
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/ipcalc-cidr.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+dir=$(dirname $0)
+awk -f $dir/common.awk -f - $* <<EOF
+BEGIN {
+ slpos=index(ARGV[1],"/")
+ if (slpos == 0) {
+ ipaddr=ip2int(ARGV[1])
+ netmask=ip2int(ARGV[2])
+ } else {
+ ipaddr=ip2int(substr(ARGV[1],0,slpos-1))
+ netmask=compl(2**(32-int(substr(ARGV[1],slpos+1)))-1)
+ ARGV[4]=ARGV[3]
+ ARGV[3]=ARGV[2]
+ }
+
+ network=and(ipaddr,netmask)
+ broadcast=or(network,compl(netmask))
+
+ start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
+ limit=network+1
+ if (start<limit) start=limit
+
+ end=start+ARGV[4]
+ limit=or(network,compl(netmask))-1
+ if (end>limit) end=limit
+
+ print "IP="int2ip(ipaddr)
+ print "NETMASK="int2ip(netmask)
+ print "BROADCAST="int2ip(broadcast)
+ print "NETWORK="int2ip(network)
+ print "PREFIX="32-bitcount(compl(netmask))
+
+ # range calculations:
+ # ipcalc <ip> <netmask> <start> <num>
+
+ if (ARGC > 3) {
+ print "START="int2ip(start)
+ print "END="int2ip(end)
+ }
+}
+EOF
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh
new file mode 100755
index 000000000..e20cc3827
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/read_defaults.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+# This reads the settings we need to have to configure everything
+# Argument $1: community
+
+community="$1"
+
+# reads variables from uci files, parameter $1 is the section
+get_var() {
+ uci -q show $1 | cut -d "." -f 2-100 |grep "\." | sed -e 's/^\([a-z_]*\)\./\1_/g' -e 's/=\(.*\)$/="\1"/g'
+}
+
+# read default values from /etc/config/freifunk
+for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults zone_freifunk include; do
+ get_var freifunk.$v
+done
+
+# now read all values from the selected community profile, will override some values from the defaults before
+for v in system wifi_device wifi_iface interface alias dhcp olsr_interface olsr_interfacedefaults profile zone_freifunk include; do
+ get_var profile_$community.$v
+done
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh
new file mode 100755
index 000000000..aee15f5b7
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# This script renames IB_wifi_ interface names into real interface names used on this system.
+# E.g. wireless.IB_wifi0 would become wireless.wifi0 on madwifi and wireless.radio0 on mac80211
+
+posIB=-1
+
+IBwifis="$(uci show meshwizard.netconfig | grep -v 'netconfig=netconfig' | sed 's/meshwizard.netconfig\.\(IB_wifi.*\)_.*/\1/' |uniq)"
+
+for w in $IBwifis; do
+ posIB=$(( $posIB + 1 ))
+ export IB_wifi$posIB="$w"
+done
+
+pos=0
+syswifis="$(uci show wireless |grep wifi-device | sed 's/wireless\.\(.*\)=.*/\1/' |uniq)"
+
+for s in $syswifis; do
+ export syswifi$pos="$s"
+ pos=$(( $pos + 1 ))
+done
+
+for i in `seq 0 $posIB`; do
+ IBwifi=$(eval echo \$IB_wifi$i)
+ syswifi=$(eval echo \$syswifi$i)
+
+ if [ -n "$syswifi" ]; then
+ case $IBwifi in
+ IB_wifi* )
+ # replace IB_wifi_* with actual wifi interface names, delete old ones first
+ uci show meshwizard.netconfig | grep $IBwifi | while read line; do
+ oldline=$(echo $line | cut -d "=" -f 1)
+ uci set $oldline=""
+ newline=$(echo $line |sed "s/$IBwifi/$syswifi/g")
+ uci set $newline
+ done
+ ;;
+ esac
+ unset IBwifi
+ unset syswifi
+ fi
+done
+
+uci commit
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh
new file mode 100755
index 000000000..4c7ea5afb
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dhcp.sh
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Sets up the dhcp part of dnsmasq
+
+. /etc/functions.sh
+. $dir/functions.sh
+
+net="$1"
+
+handle_dnsmasq() {
+ config_get interface "$1" interface
+ if [ "$interface" == "${netrenamed}dhcp" ]; then
+ if [ "$cleanup" == 1 ]; then
+ section_cleanup dhcp.$1
+ else
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename dhcp $1 ${netrenamed}dhcp
+ fi
+ fi
+ fi
+}
+config_load dhcp
+config_foreach handle_dnsmasq dhcp
+
+uci batch << EOF
+set dhcp.${netrenamed}dhcp="dhcp"
+set dhcp.${netrenamed}dhcp.leasetime="${dhcp_leasetime}"
+set dhcp.${netrenamed}dhcp.force="1"
+set dhcp.${netrenamed}dhcp.interface="${netrenamed}dhcp"
+EOF
+
+echo " leasetime: ${dhcp_leasetime}
+ interface: ${netrenamed}dhcp"
+
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dnsmasq.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dnsmasq.sh
new file mode 100755
index 000000000..517b4fd34
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_dnsmasq.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+
+. /etc/functions.sh
+. $dir/functions.sh
+
+# Set dnsmasq config
+handle_dhcp() {
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename dhcp $1 dnsmasq
+ fi
+}
+
+config_load dhcp
+config_foreach handle_dhcp dnsmasq
+
+echo " + Setup dnsmasq"
+
+uci set dhcp.dnsmasq.local="/$profile_suffix/"
+uci set dhcp.dnsmasq.domain="$profile_suffix"
+
+echo " local: /$profile_suffix/
+ domain: $profile_suffix"
+
+config_get addnhosts dnsmasq addnhosts
+if [ -z "${addnhosts/\var\/etc\/hosts.olsr/}" ]; then
+ uci add_list dhcp.dnsmasq.addnhosts="/var/etc/hosts.olsr"
+ echo " addnhosts: /var/etc/hosts.olsr"
+fi
+
+uci commit
+
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh
new file mode 100755
index 000000000..8399aef93
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_firewall.sh
@@ -0,0 +1,156 @@
+#!/bin/sh
+# This will add $net to the zone firewall (and remove it from other zones where it is referenced)
+# It will also setup rules defined in /etc/config/freifunk and /etc/config/profile_<community>
+# Arg $1 = $net
+
+net=$1
+. /etc/functions.sh
+. $dir/functions.sh
+config_load firewall
+
+# Get some variables
+type="$(uci -q get wireless.$net.type)"
+vap="$(uci -q get meshwizard.netconfig.$net\_vap)"
+lan_ip="$(uci -q get network.lan.ipaddr)"
+lan_mask="$(uci -q get network.lan.netmask)"
+
+# Delete old firewall zone for freifunk
+handle_fwzone() {
+ config_get name "$1" name
+ config_get network "$1" network
+
+ if [ "$2" == "zoneconf" ]; then
+ # clean zone
+ if [ "$name" == "freifunk" ]; then
+ if [ "$cleanup" == 1 ]; then
+ section_cleanup firewall.$1
+ else
+ # rename section if unnamed
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename firewall $1 zone_freifunk
+ fi
+ fi
+ else
+
+ if [ "$name" == "$netrenamed" ]; then
+ section_cleanup firewall.$1
+ fi
+ if [ -n "$netrenamed" -a -n "$(echo $network | grep $netrenamed)" ] && [ ! "$name" == "freifunk" ]; then
+ echo " Removed $netrenamed from firewall zone $name."
+ network_new=$(echo $network | sed -e 's/'$netrenamed'//' -e 's/^ //' -e 's/ / /' -e 's/ $//')
+ uci set firewall.$1.network="$network_new"
+ fi
+ fi
+ else
+ # clean fw_rule, fw_forwarding, include and advanced
+ for option in src tcp_ecn path; do
+ config_get $option $1 $option
+ done
+ if [ "$src" == "freifunk" -o "$path" == "/etc/firewall.freifunk" -o -n "$tcpecn" ]; then
+ section_cleanup firewall.$1
+ fi
+ fi
+}
+
+config_foreach handle_fwzone zone zoneconf
+
+if [ "$cleanup" == 1 ]; then
+ for target in include advanced rule forwarding; do
+ config_foreach handle_fwzone $target
+ done
+fi
+
+# setup freifunk firewall zone
+
+echo " + Setup firewall zone."
+
+# add $netrenamed and if needed ${netrenamed}dhcp to the networks for this zone
+config_get network zone_freifunk network
+
+# remove ${netrenamed}dhcp from networks list
+[ -n "$network" -a -n "$net" ] && network="${network/${netrenamed}dhcp/}"
+network=$(echo $network) # Removes leading and trailing whitespaces
+
+[ -n "$netrenamed" ] && [ -z "$(echo $network | grep $netrenamed)" ] && network="$network $netrenamed"
+
+if [ "$type" == "atheros" -a "$vap" == 1 ]; then
+ [ -n "$netrenamed" ] && [ "$network" == "${network/${netrenamed}dhcp/}" ] && network="$network ${netrenamed}dhcp"
+fi
+
+uci batch << EOF
+set firewall.zone_freifunk="zone"
+set firewall.zone_freifunk.name="freifunk"
+set firewall.zone_freifunk.network="$network"
+set firewall.zone_freifunk.input="$zone_freifunk_input"
+set firewall.zone_freifunk.forward="$zone_freifunk_forward"
+set firewall.zone_freifunk.output="$zone_freifunk_output"
+EOF
+
+echo " network: $network
+ input: $zone_freifunk_input
+ forward: $zone_freifunk_forward
+ output: $zone_freifunk_output"
+
+# Usually we need to setup masquerading for lan, except lan is an olsr interface or has an olsr hna
+
+echo " + Setup masquerading rules"
+
+eval $(ipcalc.sh $lan_ip $lan_mask)
+
+handle_interface() {
+ config_get interface "$1" interface
+ if [ "$interface" == "lan" ]; then
+ no_masq_lan=1
+ fi
+}
+config_load olsrd
+config_foreach handle_interface Interface
+
+handle_hna() {
+ config_get netaddr "$1" netaddr
+ if [ "$NETWORK" == "$netaddr" ]; then
+ no_masq_lan=1
+ fi
+}
+config_foreach handle_hna Hna4
+
+currms=$(uci -q get firewall.zone_freifunk.masq_src)
+if [ ! "$no_masq_lan" == "1" ]; then
+ uci set firewall.zone_freifunk.masq="1" && echo " Enabled masquerading." || echo -e "\033[1mWarning:\033[0m: Could not enable masquerading."
+ [ -z "$(echo $currms |grep $NETWORK/$PREFIX)" ] && uci add_list firewall.zone_freifunk.masq_src="$NETWORK/$PREFIX"
+fi
+
+# If wifi-interfaces are outside of the mesh network they should be natted
+for i in $networks; do
+ # Get dhcprange and meshnet
+ dhcprange=$(uci get meshwizard.netconfig.$i\_dhcprange)
+ meshnet="$(uci get profile_$community.profile.mesh_network)"
+ # check if the dhcprange is inside meshnet
+ dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)"
+ if [ ! "$dhcpinmesh" == 1 ]; then
+ [ -z "$(echo $currms |grep $dhcprange)" ] && uci add_list firewall.zone_freifunk.masq_src="$dhcprange"
+ fi
+done
+
+# Rules, Forwardings, advanced config and includes
+# Clear firewall configuration
+
+echo " + Setup rules, forwardings, advanced config and includes."
+
+for config in freifunk profile_$community; do
+
+ config_load $config
+
+ for section in advanced include fw_rule fw_forwarding; do
+ handle_firewall() {
+ local options=$(uci show $config."$1")
+ options=$(echo "$options" | sed -e "s/fw_//g" -e "s/^$config/firewall/g")
+ for o in $options; do
+ uci set $o
+ done
+ }
+ config_foreach handle_firewall $section
+ done
+done
+
+uci commit
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh
new file mode 100755
index 000000000..4f03d228c
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_network.sh
@@ -0,0 +1,91 @@
+# setup entry in /etc/config/network for a interface
+# Argument $1: network interface
+
+net="$1"
+. /etc/functions.sh
+. $dir/functions.sh
+
+# Delete the network interface section for $net
+if [ "$cleanup" == 1 ]; then
+ section_cleanup network.$netrenamed
+fi
+
+# Setup a (new) interface section for $net
+
+ipaddr=$(uci get meshwizard.netconfig.$net\_ip4addr)
+[ -z "$ipaddr" ] && msg_missing_value meshwizard $net\_ip4addr
+
+[ -z "$interface_netmask" ] && interface netmask="255.255.0.0"
+
+uci batch << EOF
+set network.$netrenamed="interface"
+set network.$netrenamed.proto="static"
+set network.$netrenamed.ipaddr="$ipaddr"
+set network.$netrenamed.netmask="$interface_netmask"
+set network.$netrenamed.dns="$interface_dns"
+EOF
+
+echo " IP address: $ipaddr"
+echo " Netmask : $interface_netmask"
+
+# setup dhcp alias/interface
+
+net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
+if [ "$net_dhcp" == 1 ]; then
+
+ # Load meshwizard_settings
+ dhcprange="$(uci -q get meshwizard.netconfig.${net}_dhcprange)"
+ interface_ip="$(uci -q get meshwizard.netconfig.${net}_ip4addr)"
+ vap=$(uci -q get meshwizard.netconfig.${net}_vap)
+
+ # Clean/rename config
+ handle_dhcpalias() {
+ config_get interface "$1" interface
+ if [ "$interface" == "$netrenamed" ]; then
+ if [ "$cleanup" == 1 ]; then
+ section_cleanup network.$1
+ else
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename network $1 ${netrenamed}dhcp
+ fi
+ fi
+ fi
+ }
+ config_load network
+ config_foreach handle_dhcpalias alias
+
+ # Get IP/netmask and start-ip for $net dhcp
+ # If no dhcprange is given in /etc/config/meshwizard we autogenerate one
+
+ if [ -z "$dhcprange" ]; then
+ dhcprange="$($dir/helpers/gen_dhcp_ip.sh $interface_ip)/24"
+ uci set meshwizard.netconfig.${net}_dhcprange="$dhcprange"
+ fi
+ eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange 1 0)
+
+ # setup wifi-dhcp interface or alias
+
+ # Setup alias for $net
+
+ if [ "$vap" == 1 ]; then
+ echo " + Setup interface ${netrenamed}dhcp."
+ uci set network.${netrenamed}dhcp=interface
+ else
+ echo " + Setup alias interface ${netrenamed}dhcp."
+ uci set network.${netrenamed}dhcp=alias
+ uci set network.${netrenamed}dhcp.interface="$netrenamed"
+ fi
+
+ uci batch << EOF
+set network.${netrenamed}dhcp.proto=static
+set network.${netrenamed}dhcp.ipaddr="$START"
+set network.${netrenamed}dhcp.netmask="$NETMASK"
+EOF
+
+ echo " interface: $net
+ ipaddr: $START
+ netmask: $NETMASK"
+
+fi
+
+uci commit
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh
new file mode 100755
index 000000000..d298828e3
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_olsrd.sh
@@ -0,0 +1,126 @@
+#!/bin/sh
+# Sets up olsrd
+# arg $1 = net
+
+net=$1
+
+. /etc/functions.sh
+
+. $dir/functions.sh
+
+# Clean or delete interface defaults
+handle_interfacedefaults() {
+ if [ "$cleanup" == 1 ]; then
+ section_cleanup olsrd.$1
+ else
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename olsrd $1 InterfaceDefaults
+ fi
+ fi
+}
+
+config_load olsrd
+config_foreach handle_interfacedefaults InterfaceDefaults
+
+# Setup new InterfaceDefaults
+
+echo " + Setup InterfaceDefaults"
+uci set olsrd.InterfaceDefaults=InterfaceDefaults
+set_defaults "olsr_interfacedefaults_" olsrd.InterfaceDefaults
+
+# Delete old interface for $netrenamed
+handle_interface() {
+ config_get interface "$1" Interface
+ if [ "$interface" == "$netrenamed" ]; then
+ if [ "$cleanup" == 1 ]; then
+ section_cleanup olsrd.$1
+ elif [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename olsrd $1 $netrenamed
+ fi
+ fi
+}
+
+config_foreach handle_interface Interface
+
+# Setup new interface for $netrenamed
+
+echo " + Setup Interface"
+
+uci set olsrd.$netrenamed=Interface
+
+set_defaults "olsr_interface_" olsrd.$net
+
+uci set olsrd.$netrenamed.interface="$netrenamed"
+echo " interface: $netrenamed"
+
+# If dhcp-network is inside the mesh_network then add HNA for it
+dhcprange=$(uci get meshwizard.netconfig.$net\_dhcprange)
+meshnet="$(uci get profile_$community.profile.mesh_network)"
+
+uci -q delete olsrd.${netrenamed}clients
+
+# check if the dhcprange is inside meshnet
+dhcpinmesh="$($dir/helpers/check-range-in-range.sh $dhcprange $meshnet)"
+
+if [ "$dhcpinmesh" == 1 ]; then
+ echo " + Setting up HNA"
+ uci set olsrd.${netrenamed}clients="Hna4"
+ eval $(sh $dir/helpers/ipcalc-cidr.sh $dhcprange)
+ uci set olsrd.${netrenamed}clients.netaddr="$NETWORK"
+ uci set olsrd.${netrenamed}clients.netmask="$NETMASK"
+ echo " netaddr: $NETWORK"
+ echo " natmask: $NETMASK"
+fi
+
+
+# Delete nameservice, dyngw and httpinfo plugins
+
+echo " + Configure Plugins"
+handle_plugin() {
+ config_get library "$1" library
+ if [ "$cleanup" == 1 ]; then
+ case library in
+ olsrd_*)
+ section_cleanup olsrd.$1
+ esac
+ elif [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ new="$(echo $library | cut -d '.' -f 1)"
+ section_rename olsrd $1 $new
+ fi
+}
+config_foreach handle_plugin LoadPlugin
+
+# Setup nameservice plugin
+if [ -n "$profile_suffix" ]; then
+ suffix=".$profile_suffix"
+else
+ suffix=".olsr"
+fi
+uci batch << EOF
+set olsrd.olsrd_nameservice=LoadPlugin
+set olsrd.olsrd_nameservice.library="olsrd_nameservice.so.0.3"
+set olsrd.olsrd_nameservice.latlon_file="/var/run/latlon.js"
+set olsrd.olsrd_nameservice.hosts_file="/var/etc/hosts.olsr"
+set olsrd.olsrd_nameservice.sighup_pid_file="/var/run/dnsmasq.pid"
+set olsrd.olsrd_nameservice.suffix="$suffix"
+EOF
+
+echo " Nameservice Plugin configured."
+
+# Setup dyngw_plain
+
+# If Sharing of Internet is enabled then enable dyngw_plain plugin
+sharenet=$(uci -q get meshwizard.general.sharenet)
+
+if [ -n "$(uci -q get olsrd.dyngw_plain.library)" ]; then
+ section_cleanup olsrd.dyngw_plain
+fi
+
+if [ "$sharenet" == 1 ]; then
+ echo " + Setup dyngw_plain"
+ uci set olsrd.dyngw_plain=LoadPlugin
+ uci set olsrd.dyngw_plain.ignore=0
+ uci set olsrd.dyngw_plain.library="olsrd_dyn_gw_plain.so.0.4"
+fi
+
+uci commit
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh
new file mode 100755
index 000000000..8e143d338
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_splash.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# Setup_splash, takes 1 argument: 1=net
+
+. /etc/functions.sh
+. $dir/functions.sh
+
+net=$1
+
+handle_splash() {
+ config_get network "$1" network
+ if [ "$network" == "${netrenamed}dhcp" ]; then
+ if [ "$cleanup" == 1 ]; then
+ section_cleanup luci_splash.$1
+ else
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename luci_splash $1 ${netrenamed}dhcp
+ fi
+ fi
+ fi
+}
+config_load luci_splash
+config_foreach handle_splash iface
+
+uci batch << EOF
+set luci_splash.${netrenamed}dhcp="iface"
+set luci_splash.${netrenamed}dhcp.network="${net}dhcp"
+set luci_splash.${netrenamed}dhcp.zone="freifunk"
+EOF
+
+echo " network: ${netrenamed}dhcp"
+
+uci commit \ No newline at end of file
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh
new file mode 100755
index 000000000..150e412de
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/setup_wifi.sh
@@ -0,0 +1,107 @@
+#!/bin/sh
+# sets up a wifi interface for meshing
+# Arguments: $1 = network interface
+
+net="$1"
+. /etc/functions.sh
+. $dir/functions.sh
+
+##### wifi-device #####
+
+echo " + Setup wifi-device"
+
+# Get the type before we delete the wifi-device
+config_load wireless
+config_get type $net type
+
+# Delete old wifi-device for $net
+
+handle_wifidevice() {
+ if [ "$1" == "$net" -a "$cleanup" == 1 ]; then
+ section_cleanup wireless.${net}
+ else
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename wireless $1 $net
+ fi
+ fi
+}
+config_foreach handle_wifidevice wifi-device
+
+# create new wifi-device for $net
+uci set wireless.${net}=wifi-device
+
+# get and set wifi-device defaults
+set_defaults "wifi_device_" wireless.${net}
+
+channel="$(uci -q get meshwizard.netconfig.$net\_channel)"
+vap="$(uci -q get meshwizard.netconfig.$net\_vap)"
+
+if [ -z "$channel" -o "$channel" == "default" ]; then
+ channel=$wifi_device_channel
+fi
+
+uci batch << EOF
+set wireless.${net}.type="$type"
+set wireless.${net}.channel="$channel"
+EOF
+
+echo " Type: $type"
+echo " Channel: $channel"
+
+##### wifi iface
+
+echo " + Setup wifi-iface"
+
+# Delete old wifi-iface for $net
+handle_interface() {
+ config_get device "$1" device
+ if [ "$device" == "$net" ]; then
+ if [ "$cleanup" == 1 ]; then
+ section_cleanup wireless.${net}_iface
+ else
+ if [ -z "${1/cfg[0-9a-fA-F]*/}" ]; then
+ section_rename wireless $1 ${net}_iface
+ fi
+ fi
+ fi
+}
+config_foreach handle_interface wifi-iface
+
+# create new wifi-device for $net
+uci set wireless.$net\_iface=wifi-iface
+
+# create new wifi-iface for $net from defaults
+set_defaults "wifi_iface_" wireless.$net\_iface
+
+# overwrite defaults
+bssid="$($dir/helpers/gen_bssid.sh $channel $community)"
+uci batch << EOF
+set wireless.$net\_iface.device="${net}"
+set wireless.$net\_iface.network="$netrenamed"
+set wireless.$net\_iface.ssid="$profile_ssid - ch$channel"
+set wireless.$net\_iface.bssid="$bssid"
+EOF
+
+echo " device: $net
+ network: $netrenamed
+ ssid: $profile_ssid - ch$channel
+ bssid: $bssid"
+
+## VAP
+ip4addr="$(uci get meshwizard.netconfig.$net\_ip4addr)"
+if [ "$type" == "atheros" -a "$vap" == 1 ]; then
+ uci batch << EOF
+set wireless.$net\_iface_dhcp="wifi-iface"
+set wireless.$net\_iface_dhcp.device="$net"
+set wireless.$net\_iface_dhcp.mode="ap"
+set wireless.$net\_iface_dhcp.encryption="none"
+set wireless.$net\_iface_dhcp.network="${netrenamed}dhcp"
+set wireless.$net\_iface_dhcp.ssid="FF-AP-$ip4addr"
+EOF
+ echo " + Setting up VAP interface for $net
+ device: $net
+ network: ${netrenamed}dhcp
+ ssid: AP-$profile_ssid-$ip4addr"
+fi
+
+uci commit
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh
new file mode 100755
index 000000000..56be8bc71
--- /dev/null
+++ b/contrib/package/meshwizard/files/usr/bin/meshwizard/wizard.sh
@@ -0,0 +1,96 @@
+#!/bin/sh
+# This script will take settings from /etc/config/meshwizard, /etc/config/freifunk and /etc/config/profile_<selected in freifunk>
+# and setup the router to participate in wireless mesh networks
+
+. /etc/functions.sh
+
+# config
+export dir="/usr/bin/meshwizard"
+. $dir/functions.sh
+debug=1
+
+# Rename wifi interfaces
+ echo "++++ Renaming wifi-devices in /etc/config/meshwizard"
+ $dir/helpers/rename-wifi.sh
+
+# Firstboot/initial config
+ echo "++++ Initial config"
+ $dir/helpers/initial_config.sh
+
+# Get community
+export community=$(uci get freifunk.community.name)
+[ -z "$community" ] && echo "Error: Community is not set in /etc/config/freifunk, aborting now." && exit 1
+
+# Check whether we want to cleanup uci config before setting new options or not
+cleanup=$(uci -q get meshwizard.general.cleanup)
+
+[ "$cleanup" == 1 ] && export cleanup=1
+
+# Get a list of networks we need to setup
+networks=$(uci show meshwizard.netconfig | grep -v "netconfig=" | sed -e 's/meshwizard.netconfig\.\(.*\)\_.*/\1/' |sort|uniq)
+export networks
+
+[ -z "$networks" ] && echo "Error: No networks to setup could be found in /etc/config/meshwizard, aborting now." && exit 1
+
+echo "+++ wizard 0.0.1 +++
+Community=$community
+Network(s)=$networks"
+
+# Read default values (first from /etc/config/freifunk, then from /etc/config/profile_$community,
+# last will overwrite first
+
+
+$dir/helpers/read_defaults.sh $community > /tmp/meshwizard.tmp
+while read line; do
+ export "${line//\"/}"
+done < /tmp/meshwizard.tmp
+
+# dnsmasq
+ echo "++++ dnsmasq config"
+ $dir/helpers/setup_dnsmasq.sh
+
+# Configure found networks
+for net in $networks; do
+
+ netrenamed="${net/radio/wireless}"
+ export netrenamed
+
+ echo "++++ Configure interface $net"
+
+ config="network"
+ echo "$(msg_start $config)"
+ $dir/helpers/setup_network.sh $net
+
+ config="wireless"
+ echo "$(msg_start $config)"
+ $dir/helpers/setup_wifi.sh $net
+
+ config="OLSRd"
+ echo "$(msg_start $config)"
+ $dir/helpers/setup_olsrd.sh $net
+
+ net_dhcp=$(uci -q get meshwizard.netconfig.${net}_dhcp)
+ if [ "$net_dhcp" == 1 ]; then
+ config="DHCP"
+ echo "$(msg_start $config)"
+ $dir/helpers/setup_dhcp.sh $net
+ fi
+
+ config="luci_splash"
+ echo "$(msg_start $config)"
+ $dir/helpers/setup_splash.sh $net
+
+ config="firewall"
+ echo "$(msg_start $config)"
+ $dir/helpers/setup_firewall.sh $net
+
+ echo " Configuration of $net finished."
+done
+
+##### Restart services
+services="network olsrd dnsmasq luci_splash"
+echo " Restarting services:"
+for s in $services; do
+ /etc/init.d/$s restart >/dev/null 2>&1
+ echo " * $s"
+done