From 28277700358c4385b88f8e79fb7cbb1668b9e8df Mon Sep 17 00:00:00 2001 From: Jan Huwald Date: Fri, 30 Mar 2012 11:37:35 +0000 Subject: webif: add router config api diff --git a/files/common/etc/config/system b/files/common/etc/config/system index c4e5bf3..80d6155 100644 --- a/files/common/etc/config/system +++ b/files/common/etc/config/system @@ -2,6 +2,12 @@ config system option hostname FFJ option timezone CET +config mesh mesh + option webif_password '' + option qos false + option vpn false + option filter_wan true + config position position option public true option automatic true diff --git a/files/common/www/service/cgi-bin/cfg_router.commit b/files/common/www/service/cgi-bin/cfg_router.commit new file mode 100644 index 0000000..4af1da7 --- /dev/null +++ b/files/common/www/service/cgi-bin/cfg_router.commit @@ -0,0 +1,99 @@ +update_hostname() { + uci set system.@system[0].hostname=$1 + echo $1 > /proc/sys/kernel/hostname +} + +update_geo() { + local auto=$1 + local public=$2 + local del=$3 + uci -q batch <&- + fi +} + +update_node_db() { + true # TODO +} + +use_router_pos=false +# the POST input is given to this loop via HEREDOC to allow +# manipulating variables in the current scope (especially for lazy +# execution) +while read key val; do + case "$key" in + router_name) + [ "$val" == "$(echo "$val" | tr -dc 'a-zA-Z0-9_')" ] \ + || fail 400 'Unerlaubte Zeichen verwendet' + router_name=$val + lazy 10 update_hostname $router_name + lazy 90 update_node_db + lazy 99 uci commit system + ;; + router_qos|router_vpn|router_filter_wan) + fail 403 'Diese Funktion ist noch nicht fertig' + ;; + router_password) + fail 403 'Diese Funktion ist noch nicht fertig' + ;; + router_geo) + router_geo="$val" + case "$router_geo" in + private) + lazy 00 update_geo false false true + ;; + manual) + lazy 00 update_geo false true false + use_router_pos=true + ;; + automatic) + # only delete current position if we have internet + # to immediately get the new position + if have_internet; then + lazy 00 update_geo true true true + # obtain writing lock until geolocate obtains + # the same lock to close race cond; ignore + # failure to lock (prefer to process the + # request instead (-:) + exec 666>>/tmp/lock/geolocate + flock -n -x 667 || true + else + lazy 00 update_geo true true false + fi + ;; + *) + fail + ;; + esac + lazy 90 update_node_db + lazy 99 uci commit system + ;; + router_pos_lon|router_pos_lat) + if $use_router_pos; then + true + fi + ;; + router_pos_street) + if $use_router_pos; then + true + fi + ;; + esac +done <