blob: d251f2baeea66791e0b9f221afcdfc456509e2da (
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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)
/usr/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 667>>/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
|