summaryrefslogtreecommitdiff
path: root/files/common/www/service/cgi-bin/cfg_client.json
blob: fc74393a7e7c4cb5faec891ab06d1134d1649978 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh -e
. /www/service/cgi-bin/common.sh

# 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\": \"$cname\",
 \"client_splash\": [$csplash],
 \"client_access\": [\"$cmode\"]
}"

exec_lazy
contact: Jan Huwald // Impressum