diff options
| -rw-r--r-- | files/common/www/service/cgi-bin/cfg_client.commit | 49 | ||||
| -rwxr-xr-x | files/common/www/service/cgi-bin/cfg_client.json | 62 | 
2 files changed, 105 insertions, 6 deletions
diff --git a/files/common/www/service/cgi-bin/cfg_client.commit b/files/common/www/service/cgi-bin/cfg_client.commit new file mode 100644 index 0000000..bf5d50c --- /dev/null +++ b/files/common/www/service/cgi-bin/cfg_client.commit @@ -0,0 +1,49 @@ +update_cfgtbl() { +    if [ "$cmode"   == $cmode_default ];   then cmode=;   fi +    if [ "$csplash" == $csplash_default ]; then csplash=; fi +    p2ptbl update  $tbl $mac "$cname,$cmode,$csplash,$cip" +} + +# parse changes +while read key val; do +    case "$key" in  +	client_access) +	    case "$val" in +		bridged|routed|isolated) cmode=$val;; +		*) fail;; +	    esac +	    lazy 20 splash_sync +	    ;; +	client_name) +	    [ -z "$(echo "$val" | tr -d '0-9a-z_')" ] \ +		|| fail 400 'Unerlaubte Zeichen verwendet' +	    [ "$val" != "$cname" ] \ +		|| continue +	    [ -z "$(p2ptbl show $tbl | cut -f2 | grep "^$val,")" ] \ +		|| fail 403 'Name bereits vergeben' +	    cname=$val +	    lazy 10 sync_dhcp +	    ;; +	# client_splash is send iff. it is checked; update_splash is +	# send in every case +	update_splash) +	    update_splash=${update_splash-false} +	    lazy 20 splash_sync +	    ;; +	client_splash) +	    update_splash=true +	    ;; +	*) +	    fail 400 "wtf is $key?" +	    ;; +    esac +done <<EOF +$(tr '=&' ' \n') +EOF + +if [ -n "$update_splash" ]; then +    csplash=$update_splash +fi + +# update p2ptbl entry +lazy 00 update_cfgtbl diff --git a/files/common/www/service/cgi-bin/cfg_client.json b/files/common/www/service/cgi-bin/cfg_client.json index dc675c9..fc74393 100755 --- a/files/common/www/service/cgi-bin/cfg_client.json +++ b/files/common/www/service/cgi-bin/cfg_client.json @@ -1,9 +1,59 @@ -#!/bin/sh +#!/bin/sh -e +. /www/service/cgi-bin/common.sh -echo -e 'Status: 200 OK\r +# determine for which mac we get/put +read mac iface <<EOF +$(grep ^$REMOTE_HOST </proc/net/arp \ +    | awk 'BEGIN { FS = " " } ; { print $4, $6 }') +EOF +[ -n "$mac" ] + +if [ -n "$QUERY_STRING" ]; then +    check_node_auth +    mac="$(echo "$QUERY_STRING" | tr -dc '0-9a-fA-F')" +fi + +# get current settings and default settings +case $iface in +    br-lan) +	tbl=/tmp/p2ptbl/ccfg_wire +	cmode_default=$(uci get system.mesh.lan_client_mode) +	;; +    br-mesh) +	tbl=/tmp/p2ptbl/ccfg_wire +	cmode_default=bridged +	;; +    *) fail;; +esac +csplash_default=false + +# get config from p2ptbl; parse it only if existent; hint: the default +# value for each config value is empty +cfg_line=$(p2ptbl get $tbl $mac) +if [ -n "$cfg_line" ]; then +    IFS="," read cname cmode csplash cip <<EOF +$cfg_line +EOF +fi +cmode=${cmode-$cmode_default} +csplash=${csplash-$csplash_default} + +if [ $REQUEST_METHOD == POST ]; then +    . /www/service/cgi-bin/cfg_client.commit +fi + +# set all empty variables to their default values +if [ "$csplash" != true ]; then +    csplash=false +fi + +# respond with [updated] settings +echo -e "Status: 200 OK\r  Content-Type: application/json\r  \r -{"client_name": "mobilaptop", - "client_splash": [false], - "client_access": ["bridged"] -}' +{\"client_name\": \"$cname\", + \"client_splash\": [$csplash], + \"client_access\": [\"$cmode\"] +}" + +exec_lazy  | 
