summaryrefslogtreecommitdiff
path: root/files/common/www/service/cgi-bin/node_position.json
blob: 3fe3680d44fc76f9c567e9f5acde56c745eb58b7 (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
#!/bin/sh -e

. /www/service/cgi-bin/common.sh

# try to get a lock within 3 seconds, get info without lock otherwise
exec 666>>/tmp/lock/geolocate
flock -w 3 -s 666 || true

uci batch <<EOF 2>&1 | tee /tmp/www.foo | {
get system.position.public
get system.position.lon
get system.position.lat
get system.position.street
EOF
    read_uci public
    read_uci lon
    read_uci lat
    read_uci street

    if ! $public; then
	fail 403 'Geolokation deaktiviert'
    fi
    if [ -z "$lon" -o -z "$lat" ]; then
	fail 503 'Position noch nicht ermittelt'
    fi

    echo -e "Status: 200 OK\r
Content-Type: application/json\r
\r
{\"router_pos_lon\": $lon,
 \"router_pos_lat\": $lat,
 \"router_pos_street\": \"$street\"
}"
}
contact: Jan Huwald // Impressum