diff options
-rw-r--r-- | files/common/etc/crontabs/root | 14 | ||||
-rwxr-xr-x | files/common/etc/fsm/inetable/trans/queen.enter | 2 | ||||
l--------- | files/common/hbbp/p2ptbl/ccfg_wifi | 2 | ||||
l--------- | files/common/hbbp/p2ptbl/gwip | 2 | ||||
l--------- | files/common/hbbp/p2ptbl/splash | 2 | ||||
l--------- | files/common/hbbp/p2ptbl/test | 2 | ||||
l--------- | files/common/hbbp/p2ptbl/update | 2 | ||||
-rwxr-xr-x | files/common/sbin/fsm | 107 | ||||
-rwxr-xr-x | files/common/sbin/geolocate | 59 | ||||
-rwxr-xr-x | files/common/sbin/p2ptbl | 158 | ||||
-rwxr-xr-x | files/common/sbin/p2ptbl-recv | 12 | ||||
-rwxr-xr-x | files/common/sbin/shuf | 16 | ||||
-rw-r--r-- | files/common/www/service/cgi-bin/cfg_router.commit | 2 |
13 files changed, 14 insertions, 366 deletions
diff --git a/files/common/etc/crontabs/root b/files/common/etc/crontabs/root index 3a902c5..4aebd21 100644 --- a/files/common/etc/crontabs/root +++ b/files/common/etc/crontabs/root @@ -1,7 +1,7 @@ -* * * * */10 /sbin/p2ptbl gossip /tmp/p2ptbl/ccfg_wifi 500 br-mesh -* * * * * /sbin/p2ptbl gossip /tmp/p2ptbl/gwip 500 br-mesh -* * * * * /sbin/p2ptbl gossip /tmp/p2ptbl/splash 500 br-mesh -* * * * * /sbin/p2ptbl gossip /tmp/p2ptbl/update 500 br-mesh -* * * * * /sbin/fsm watch inetable -* * * * * /sbin/fsm watch update -* * * * * /sbin/splash_sync +* * * * */10 /usr/sbin/p2ptbl gossip /tmp/p2ptbl/ccfg_wifi 500 br-mesh +* * * * * /usr/sbin/p2ptbl gossip /tmp/p2ptbl/gwip 500 br-mesh +* * * * * /usr/sbin/p2ptbl gossip /tmp/p2ptbl/splash 500 br-mesh +* * * * * /usr/sbin/p2ptbl gossip /tmp/p2ptbl/update 500 br-mesh +* * * * * /usr/sbin/fsm watch inetable +* * * * * /usr/sbin/fsm watch update +* * * * * /usr/sbin/splash_sync diff --git a/files/common/etc/fsm/inetable/trans/queen.enter b/files/common/etc/fsm/inetable/trans/queen.enter index 404b0f2..8bcf968 100755 --- a/files/common/etc/fsm/inetable/trans/queen.enter +++ b/files/common/etc/fsm/inetable/trans/queen.enter @@ -54,7 +54,7 @@ set dhcp.mesh.end_ip=$dhcp_end ## set splash # start redirection httpd (for splash), add GW IP to the addrs service # httpd listens on -echo "http://$gwip/cgi-bin/splash.html? /sbin/urlencode" > /tmp/redirection_target +echo "http://$gwip/cgi-bin/splash.html? /usr/sbin/urlencode" > /tmp/redirection_target enable_httpd redirection $gwip:81 change_service_httpd_listen $gwip:80 /etc/init.d/uhttpd restart diff --git a/files/common/hbbp/p2ptbl/ccfg_wifi b/files/common/hbbp/p2ptbl/ccfg_wifi index 7d15fc0..8cac192 120000 --- a/files/common/hbbp/p2ptbl/ccfg_wifi +++ b/files/common/hbbp/p2ptbl/ccfg_wifi @@ -1 +1 @@ -/sbin/p2ptbl-recv
\ No newline at end of file +/usr/sbin/p2ptbl-recv
\ No newline at end of file diff --git a/files/common/hbbp/p2ptbl/gwip b/files/common/hbbp/p2ptbl/gwip index 7d15fc0..8cac192 120000 --- a/files/common/hbbp/p2ptbl/gwip +++ b/files/common/hbbp/p2ptbl/gwip @@ -1 +1 @@ -/sbin/p2ptbl-recv
\ No newline at end of file +/usr/sbin/p2ptbl-recv
\ No newline at end of file diff --git a/files/common/hbbp/p2ptbl/splash b/files/common/hbbp/p2ptbl/splash index 7d15fc0..8cac192 120000 --- a/files/common/hbbp/p2ptbl/splash +++ b/files/common/hbbp/p2ptbl/splash @@ -1 +1 @@ -/sbin/p2ptbl-recv
\ No newline at end of file +/usr/sbin/p2ptbl-recv
\ No newline at end of file diff --git a/files/common/hbbp/p2ptbl/test b/files/common/hbbp/p2ptbl/test index 7d15fc0..8cac192 120000 --- a/files/common/hbbp/p2ptbl/test +++ b/files/common/hbbp/p2ptbl/test @@ -1 +1 @@ -/sbin/p2ptbl-recv
\ No newline at end of file +/usr/sbin/p2ptbl-recv
\ No newline at end of file diff --git a/files/common/hbbp/p2ptbl/update b/files/common/hbbp/p2ptbl/update index 7d15fc0..8cac192 120000 --- a/files/common/hbbp/p2ptbl/update +++ b/files/common/hbbp/p2ptbl/update @@ -1 +1 @@ -/sbin/p2ptbl-recv
\ No newline at end of file +/usr/sbin/p2ptbl-recv
\ No newline at end of file diff --git a/files/common/sbin/fsm b/files/common/sbin/fsm deleted file mode 100755 index 177d0c7..0000000 --- a/files/common/sbin/fsm +++ /dev/null @@ -1,107 +0,0 @@ -#!/bin/sh -e - -# paths to state file and definition dir -PState=/var/fsm/$2 -PDef=/etc/fsm/$2 - -watch () { - SO=$(cat $PState) - SN=$(callOne $PDef/watch $SO "xxx" \ - "./$SO - ./default - /bin/false") || fail "watch script failed or missing" - [ -n "$SN" ] || fail "watch script $S0 returned empty state name" - change $SN -} - -change () { - SO=$(cat $PState) - SN=$1 - if [ "$SO" != "$SN" ]; then - if [ -x $PDef/trans/$SO-$SN.trans ]; then - # one script to handle whole transition - callOne $PDef/trans $SO $SN \ - "./$SO-$SN.trans" \ - || fail "state transition script failed" - else - # seperate scripts for leaving and entering states - callOne $PDef/trans $SO $SN \ - "./$SO.leave - ./default.leave - /bin/true" \ - || fail "state leave script failed" - callOne $PDef/trans $SO $SN \ - "./$SN.enter - ./default.enter - /bin/true" \ - || fail "state enter script failed" - - fi - echo $SN > $PState - fi -} - -callOne () { # args: cwd arg1 arg2 cmdlist - echo "$4" | sed 's/ *//' | ( - set -e - cd $1 - while read cmd; do - if [ -x "$cmd" ]; then - $cmd $2 $3 666<&- - exit $? - fi - done ) -} - -lockState () { - # lock state file (neccessary also for watch, as it calls scripts - # that assume a certain state as active during their whole - # execution time) - exec 666<$1 - flock -x 666 -} - -fail() { - echo "$1" 1>&2 - exit 1 -} - -printArgs () { - fail "Usage: -$0 get fsm -$0 watch fsm -$0 change fsm state" -} - -[ $# -lt 2 ] && printArgs - -# check for minimal FSM definition -if [ -f $PDef/initial_state \ - -a -d $PDef/watch \ - -a -d $PDef/trans ]; then - if [ ! -f $PState ]; then - mkdir -p $(dirname $PState) - S=$(cat $PDef/initial_state) - [ -n "$S" ] || fail "initial state must not be empty" - echo $S >$PState - fi -else - fail "FSM $2 does not exist" -fi - -case "$1" in - get) - cat $PState - ;; - watch) - lockState $PState - watch - ;; - change) - [ -n "$3" ] || printArgs - lockState $PState - change $3 - ;; - *) - printArgs -esac
\ No newline at end of file diff --git a/files/common/sbin/geolocate b/files/common/sbin/geolocate deleted file mode 100755 index c07cce3..0000000 --- a/files/common/sbin/geolocate +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh -ex - -device=wlan0-1 -tmp=/tmp/geolocate_scratch - -# obtain an exclusive lock -exec 666>>/tmp/lock/geolocate -flock -w 5 -x 666; - -# list neighbour wifis -iw dev $device scan >$tmp.scan - -# construct HTTP request -( echo -n '{"request_address": true, "version": "1.1.0", "wifi_towers": [' - egrep <$tmp.scan -o -e '^BSS [0-9a-f:]{17}' -e '^[[:space:]]SSID.*' -e '^[[:space:]]signal: [0-9.-]*' \ - | tr "\n\t" " " \ - | sed 's/BSS /\n/g' \ - | tail -n +2 \ - | cut -d' ' -f1,4,7- \ - | sed 's/^\([^ ]*\) \([^ ]*\) \(.*\) $/{"mac_address":"\1", "signal_strength":"\2", "ssid":"\3"}/' \ - | tr "\n" , \ - | sed 's/,$//' - echo ']}' -) >$tmp.json -( echo "POST /loc/json HTTP/1.0 -Content-length: $(wc -c <$tmp.json) -" - cat $tmp.json -) >$tmp.request - -# consult the ooracle -nc www.google.com 80 <$tmp.request >$tmp.response - -# parse the response -tail -n1 $tmp.response \ - | tr , "\n" \ - | egrep -o -e '"latitude":[0-9.]*' -e '"longitude":[0-9.]*' -e '"street":"[^"]*' \ - | sort \ - | egrep -o '[^:"]*$' \ - | { - read lon - read lat - read street - -# store result - cat <<EOF -set system.position.lon=$lon -set system.position.lat=$lat -set system.position.street="$street" -EOF - uci batch <<EOF -set system.position.lon=$lon -set system.position.lat=$lat -set system.position.street="$street" -EOF -} - -# clean up -rm $tmp*
\ No newline at end of file diff --git a/files/common/sbin/p2ptbl b/files/common/sbin/p2ptbl deleted file mode 100755 index 341cecd..0000000 --- a/files/common/sbin/p2ptbl +++ /dev/null @@ -1,158 +0,0 @@ -#!/bin/sh -e - -init () { - [ -n "$1" ] || printArgs - mkdir -p "$(dirname $1)" - [ -f "$1" ] || cat >"$1" </dev/null -} - -get () { - [ -n "$2" ] || printArgs - grep "^$2"$'\t' "$1" | cut -f3- -} - -show () { - cut -f1,3- "$1" -} - -filter () { - tbl="$1" - shift 1 - cut -f1,2 "$tbl" \ - | while read key version; do - echo -e "$key\t$(($version+$RANDOM))" - done > "$tbl".ver - cut -f1,3- "$tbl" \ - | "$@" \ - | join -t$'\t' "$tbl".ver - \ - > "$tbl"~ - mv "$tbl"~ "$tbl" - rm "$tbl".ver -} - -update () { - [ -n "$2" -a -n "$3" ] || printArgs - oldversion=$(grep "^$2"$'\t' "$1" | cut -f2) - tmpfile="$1.update" - echo -e "$2\t$(($oldversion + 1 + $RANDOM))\t$3" > "$tmpfile" - merge "$1" "$tmpfile" - if [ -n "$4" ]; then - # broadcast update - gzip <"$tmpfile" >"$tmpfile.gz" - hbbpc $4 p2ptbl/$(basename "$1") - <"$tmpfile.gz" - rm "$tmpfile.gz" - fi - rm "$tmpfile" -} - -merge () { - # we use sort instead of merge here to be robust in case the rows - # are not sorted - sort "$1" "$2" \ - | { - oldkey="" - oldversion=0 - oldval="" - while read key version val; do - if [ "$key" == "$oldkey" ]; then - if [ "$version" -gt "$oldversion" ]; then - oldversion="$version" - oldval="$val" - fi - else - [ -n "$oldkey" ] && echo -e "$oldkey\t$oldversion\t$oldval" - oldkey="$key" - oldversion="$version" - oldval="$val" - fi - done - [ -n "$oldkey" ] && echo -e "$oldkey\t$oldversion\t$oldval" - } > "$1~" - mv "$1~" "$1" -} - -gossip() { - tgts="$2" - if="$3" - [ "$tgts" -gt 0 -a -n "$if" ] 2>/dev/null || printArgs - - # binary search over number of sent lines until size is maximized - # and below target size - lc=$(wc -l <"$1") - [ $lc == 0 ] && return - shuf -v seed=$RANDOM <"$1" >"$1.gossip" - while [ $lc -ge 1 ]; do - head -n$lc "$1.gossip" | gzip >"$1.gossip.gz" - if [ $tgts -ge $(wc -c <"$1.gossip.gz") ]; then - hbbpc $if p2ptbl/$(basename "$1") - <"$1.gossip.gz" - rm "$1.gossip" "$1.gossip.gz" - return; - fi - lc=$(($lc / 2)) - done - rm "$1.gossip" "$1.gossip.gz" - echo "$1 has rows bigger then requested packet size" - exit 1 -} - -printArgs () { - echo -e >&2 "Usage: -$0 init table -$0 get table key -$0 show table -$0 update table key value [interface] -$0 filter table program [args] -$0 merge table foreign-table -$0 gossip table target-size interface" - exit 1 -} - -checkTable () { - [ -n "$1" ] || printArgs; - [ -f "$1" ] || { - echo >&2 "$1 is no P2P table"; - printArgs; - } -} - -lockTable () { - checkTable "$2" - exec 666<"$2" - flock "$1" 666 -} - -case "$1" in - init) - init "$2" - ;; - get) - lockTable -s "$2" - get "$2" "$3" - ;; - show) - lockTable -s "$2" - show "$2" - ;; - filter) - tbl="$2" - shift 2 - lockTable -x "$tbl" - filter "$tbl" "$@" - ;; - update) - lockTable -s "$2" - update "$2" "$3" "$4" "$5" - ;; - merge) - lockTable -x "$2" - checkTable "$3" - merge "$2" "$3" - ;; - gossip) - lockTable -s "$2" - gossip "$2" "$3" "$4" - ;; - *) - printArgs - ;; -esac
\ No newline at end of file diff --git a/files/common/sbin/p2ptbl-recv b/files/common/sbin/p2ptbl-recv deleted file mode 100755 index f10fa39..0000000 --- a/files/common/sbin/p2ptbl-recv +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -set -e - -tbldir=/tmp/p2ptbl -tbl=$tbldir/$(basename $0) - -[ -f $tbl ] || p2ptbl init $tbl - -gunzip > $tbl.recv -p2ptbl merge $tbl $tbl.recv -rm $tbl.recv
\ No newline at end of file diff --git a/files/common/sbin/shuf b/files/common/sbin/shuf deleted file mode 100755 index 8d82d4d..0000000 --- a/files/common/sbin/shuf +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/awk -f -BEGIN{ - srand() # seed by time - srand(seed+srand()) # allow additional external seed -} -{ lines[++d]=$0 } -END{ - while (d > 0) { - if (e==d) {break} - r = int(1 + rand() * d) - print lines[r] - lines[r] = lines[d] - delete lines[d] - --d - } -} diff --git a/files/common/www/service/cgi-bin/cfg_router.commit b/files/common/www/service/cgi-bin/cfg_router.commit index e4f62b7..d251f2b 100644 --- a/files/common/www/service/cgi-bin/cfg_router.commit +++ b/files/common/www/service/cgi-bin/cfg_router.commit @@ -21,7 +21,7 @@ EOF if $auto && have_internet; then # geolocate may fail (e.g. if another instance was running or # the position could not be determined) - /sbin/geolocate || true + /usr/sbin/geolocate || true # close previously aquired lock exec 667>&- fi |