diff options
-rw-r--r-- | files/common/etc/config/system | 6 | ||||
-rw-r--r-- | files/common/www/service/cgi-bin/cfg_router.commit | 99 | ||||
-rwxr-xr-x | files/common/www/service/cgi-bin/cfg_router.json | 33 |
3 files changed, 138 insertions, 0 deletions
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 <<EOF +set system.position.automatic=$auto +set system.position.public=$public +EOF + if $del; then + uci -q batch <<EOF +delete system.position.lon +delete system.position.lat +delete system.position.street +EOF + fi + if $auto && have_internet; then + # geolocate may fail (e.g. if another instance was running or + # the position could not be determined) + /sbin/geolocate || true + # close previously aquired lock + exec 667>&- + 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 <<EOF +$(tr '=&' ' \n' | sort) +EOF diff --git a/files/common/www/service/cgi-bin/cfg_router.json b/files/common/www/service/cgi-bin/cfg_router.json new file mode 100755 index 0000000..3315cc3 --- /dev/null +++ b/files/common/www/service/cgi-bin/cfg_router.json @@ -0,0 +1,33 @@ +#!/bin/sh -e + +. /www/service/cgi-bin/common.sh +check_node_auth + +# parse changes +if [ $REQUEST_METHOD == POST ]; then + . /www/service/cgi-bin/cfg_router.commit +fi + +# compute geo mode value (if not changed during this request) +if [ -z "$router_geo" ]; then + if [ "$(uci get system.position.public)" == 'false' ]; then + router_geo=private + elif [ "$(uci get system.position.automatic)" == 'false' ]; then + router_geo=manual + else + router_geo=automatic + fi +fi + +echo -e "Status: 200 OK\r +Content-Type: application/json\r +\r +{\"router_name\": \"${router_name-$( uci get system.@system[0].hostname)}\", + \"router_password\": \"${router_password-$( uci get system.mesh.webif_password)}\", + \"router_qos\": [${router_qos-$( uci get system.mesh.qos)}], + \"router_vpn\": [${router_vpn-$( uci get system.mesh.vpn)}], + \"router_filter_wan\": [${router_filter_wan-$(uci get system.mesh.filter_wan)}], + \"router_geo\": [\"$router_geo\"] +}" + +exec_lazy
\ No newline at end of file |