diff --git a/bsp/default/root_file_system/etc/admin.sh b/bsp/default/root_file_system/etc/admin.sh new file mode 100755 index 0000000..1b53905 --- /dev/null +++ b/bsp/default/root_file_system/etc/admin.sh @@ -0,0 +1,98 @@ +#!/bin/ash + +# input check functions +check_hostname() { + local STRING="$@" + [ -n "$STRING" ] || return 1 + local STRING_VALID=$(echo -n "$STRING" | grep -E "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$") + [ "$STRING" == "$STRING_VALID" ] || return 1 +} + +check_integer() { + local STRING="$@" + [ -n "$STRING" ] || return 1 + local STRING_VALID=$(echo -n "$STRING" | grep -E "^[0-9]+$") + [ "$STRING" == "$STRING_VALID" ] || return 1 +} + +check_httpurl() { + local STRING="$@" + [ -n "$STRING" ] || return 1 + local STRING_VALID=$(echo -n "$STRING" | grep -E "http(s?):\/\/[^ \"\(\)\<\>]*") + [ "$STRING" == "$STRING_VALID" ] || return 1 +} + +check_contains() { + local STRING="$1" + local STRING2="$2" + local STRING_VALID=$(echo -n "$STRING" | grep -E "$STRING2") + [ "$STRING" == "$STRING_VALID" ] || return 1 +} + +# command implementations +set_hostname() { + local HOSTNAME="$1" + check_hostname "$HOSTNAME" || return 1 + uci set system.@system[0].hostname="$HOSTNAME" + uci commit + echo "$HOSTNAME" > /proc/sys/kernel/hostname +} + +set_wanratelimit() { + local UPLIMIT="$1" + local DOWNLIMIT="$2" + check_integer "$UPLIMIT" || return 1 + check_integer "$DOWNLIMIT" || return 1 + if [ "$UPLIMIT" -gt 0 ] && [ "$DOWNLIMIT" -gt 0 ]; then + uci set qos.wan.upload="$UPLIMIT" + uci set qos.wan.download="$DOWNLIMIT" + uci commit + /etc/init.d/qos stop + /etc/init.d/qos enable + /etc/init.d/qos start + else + /etc/init.d/qos stop + /etc/init.d/qos disable + fi +} + +upgrade_firmware() { + local URL="$1" + local MD5SUM="$2" + local BOARDNAME=$(uci get board.model.name) + [ -n "$BOARDNAME" ] || return 1 + if [ -z "$URL" ]; then + local UPGRADEPATH=$(uci get firmware.upgrade.path) + URL="${UPGRADEPATH}/${BOARDNAME}.bin" + fi + check_httpurl "$URL" || return 1 + check_contains "$URL" "$BOARDNAME" || return 1 + check_contains "$URL" "upgrade" || return 1 + [ -n "$MD5SUM" ] || MD5SUM=$(wget -q -O - --no-check-certificate "$URL.md5" | cut -d" " -f1) + [ -n "$MD5SUM" ] || return 1 + wget -q -O /tmp/firmware-sysupgrade.bin --no-check-certificate "$URL" || return 1 + local MD5SUM_VALID=$(md5sum /tmp/firmware-sysupgrade.bin | cut -d" " -f1) + [ "$MD5SUM" == "$MD5SUM_VALID" ] || return 1 + sysupgrade /tmp/firmware-sysupgrade.bin +} + +ACTION="$1" +shift + +case "$ACTION" in + hostname) + set_hostname $@ + ;; + + wanratelimit) + set_wanratelimit $@ + ;; + + upgrade) + upgrade_firmware $@ + ;; + + *) + echo "unknown action" + ;; +esac diff --git a/bsp/default/root_file_system/etc/config/firmware.tpl b/bsp/default/root_file_system/etc/config/firmware.tpl new file mode 100644 index 0000000..49c61bd --- /dev/null +++ b/bsp/default/root_file_system/etc/config/firmware.tpl @@ -0,0 +1,4 @@ +config upgrade 'upgrade' + option path '${UPGRADE_PATH}' + option auto 0 + option remote 1 diff --git a/bsp/dir300/root_file_system/etc/config/board b/bsp/dir300/root_file_system/etc/config/board new file mode 100644 index 0000000..fa81e38 --- /dev/null +++ b/bsp/dir300/root_file_system/etc/config/board @@ -0,0 +1,2 @@ +config model 'model' + option name 'dir300' diff --git a/bsp/fonera/root_file_system/etc/config/board b/bsp/fonera/root_file_system/etc/config/board new file mode 100644 index 0000000..3bd3d73 --- /dev/null +++ b/bsp/fonera/root_file_system/etc/config/board @@ -0,0 +1,2 @@ +config model 'model' + option name 'fonera' diff --git a/bsp/wr1043nd/root_file_system/etc/config/board b/bsp/wr1043nd/root_file_system/etc/config/board new file mode 100644 index 0000000..cecc593 --- /dev/null +++ b/bsp/wr1043nd/root_file_system/etc/config/board @@ -0,0 +1,2 @@ +config model 'model' + option name 'wr1043nd-v1' diff --git a/bsp/wr741nd2/root_file_system/etc/config/board b/bsp/wr741nd2/root_file_system/etc/config/board new file mode 100644 index 0000000..a2d8aa1 --- /dev/null +++ b/bsp/wr741nd2/root_file_system/etc/config/board @@ -0,0 +1,2 @@ +config model 'model' + option name 'tl-wr741nd-v2' diff --git a/bsp/wr741nd4/root_file_system/etc/config/board b/bsp/wr741nd4/root_file_system/etc/config/board new file mode 100644 index 0000000..7042079 --- /dev/null +++ b/bsp/wr741nd4/root_file_system/etc/config/board @@ -0,0 +1,2 @@ +config model 'model' + option name 'tl-wr741nd-v4' diff --git a/bsp/wr841n8/root_file_system/etc/config/board b/bsp/wr841n8/root_file_system/etc/config/board new file mode 100644 index 0000000..866597a --- /dev/null +++ b/bsp/wr841n8/root_file_system/etc/config/board @@ -0,0 +1,2 @@ +config model 'model' + option name 'tl-wr841n-v8' diff --git a/bsp/wr841nd7/root_file_system/etc/config/board b/bsp/wr841nd7/root_file_system/etc/config/board new file mode 100644 index 0000000..6f68f6b --- /dev/null +++ b/bsp/wr841nd7/root_file_system/etc/config/board @@ -0,0 +1,2 @@ +config model 'model' + option name 'tl-wr841nd-v7' diff --git a/community/franken.cfg b/community/franken.cfg index 6562afd..d446c31 100644 --- a/community/franken.cfg +++ b/community/franken.cfg @@ -5,4 +5,4 @@ BSSID_MESH=02:CA:FF:EE:BA:BE NETMON_IP=fe80::ff:feee:1 VPN_PROJECT=fff NTPD_IP=fe80::ff:feee:1%br-mesh - +UPGRADE_PATH=http://firmware.freifunk-franken.de/latest/upgrade/ diff --git a/community/oldenburg.cfg b/community/oldenburg.cfg index 309aabf..a4a95d6 100644 --- a/community/oldenburg.cfg +++ b/community/oldenburg.cfg @@ -5,4 +5,4 @@ BSSID_MESH=02:CA:FF:EE:BA:BE NETMON_IP=fe80::201:2ff:fe03:405 VPN_PROJECT=ffol NTPD_IP=fe80::201:2ff:fe03:405%br-mesh - +UPGRADE_PATH=http://firmware.freifunk-ol.de/latest/upgrade/