diff options
author | Jan Huwald <jh@sotun.de> | 2012-03-30 11:36:54 (GMT) |
---|---|---|
committer | Jan Huwald <jh@sotun.de> | 2012-03-30 11:36:54 (GMT) |
commit | 3b6087ca7056114c1f7badbd996970186545861e (patch) | |
tree | 3d65e3a10bdcb4dfe136678e2593db0d149601f0 | |
parent | fd1227d5b01381fc448e7459082bbbdfd8ee0e7f (diff) |
webif: add geolocation api
-rwxr-xr-x | files/common/www/service/cgi-bin/node_position.json | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/files/common/www/service/cgi-bin/node_position.json b/files/common/www/service/cgi-bin/node_position.json new file mode 100755 index 0000000..3fe3680 --- /dev/null +++ b/files/common/www/service/cgi-bin/node_position.json @@ -0,0 +1,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\" +}" +}
\ No newline at end of file |