freifunk-common: neigh.sh - show hostnames
if nameservice-plugin is configured, we read in all locally known hostnames and show them in the output: root@stuttgarter-core:~# neigh.sh Local Remote vTime LQ NLQ Cost Host 10.230.105.241 10.230.105.246 138851 1.000000 1.000000 1024 stuttgarter-rhnk.olsr 10.230.105.241 10.230.105.247 135717 1.000000 1.000000 1024 stuttgarter-emma.olsr 10.230.105.241 10.230.105.244 138309 1.000000 1.000000 1024 stuttgarter-sued.olsr 10.230.105.241 10.230.105.245 136001 1.000000 1.000000 1024 stuttgarter-west.olsr 10.230.105.241 10.230.105.242 134818 1.000000 1.000000 1024 stuttgarter-nord.olsr 10.230.105.241 10.230.105.243 137187 1.000000 1.000000 1024 stuttgarter-ost.olsr 10.230.105.241 10.230.105.250 139984 1.000000 1.000000 1024 stuttgarter-hof2.olsr 10.230.105.241 10.230.105.251 138294 1.000000 1.000000 1024 stuttgarter-stra2.olsr Local Remote vTime LQ NLQ Cost Host 2001:bf7:820:901::1 2001:bf7:820:950::1 139703 1.000000 1.000000 1024 stuttgarter-rhnk.olsr 2001:bf7:820:901::1 2001:bf7:820:960::1 139541 1.000000 1.000000 1024 stuttgarter-emma.olsr 2001:bf7:820:901::1 2001:bf7:820:990::1 140415 1.000000 1.000000 1024 stuttgarter-hof2.olsr 2001:bf7:820:901::1 fde6:24f1:a388::1 141338 1.000000 1.000000 1024 the filenames for the olsrd hosts-file is taken from uci and falls back to sane defaults. Signed-off-by: Bastian Bittorf <bittorf@bluebottle.com>
This commit is contained in:
parent
8b08756d93
commit
e0bcfe82fb
1 changed files with 63 additions and 2 deletions
|
@ -2,9 +2,69 @@
|
||||||
|
|
||||||
. /usr/share/libubox/jshn.sh
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
VARS="localIP:Local remoteIP:Remote validityTime:vTime linkQuality:LQ neighborLinkQuality:NLQ linkCost:Cost"
|
hostsfile_getname()
|
||||||
|
{
|
||||||
|
local config="$1"
|
||||||
|
local i=0
|
||||||
|
local value file
|
||||||
|
|
||||||
for HOST in 127.0.0.1 ::1;do
|
while value="$( uci -q get $config.@LoadPlugin[$i].library )"; do {
|
||||||
|
case "$value" in
|
||||||
|
'olsrd_nameservice.so.'*)
|
||||||
|
file="$( uci -q get $config.@LoadPlugin[$i].hosts_file )"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
i=$(( i + 1 ))
|
||||||
|
} done
|
||||||
|
|
||||||
|
echo "${file:-/var/run/hosts_olsr}"
|
||||||
|
}
|
||||||
|
|
||||||
|
read_hostnames()
|
||||||
|
{
|
||||||
|
local file_list=" $( hostsfile_getname 'olsrd' ) $(hostsfile_getname 'olsrd6' ) "
|
||||||
|
local line ip hostname file file_list_uniq
|
||||||
|
|
||||||
|
for file in $file_list; do {
|
||||||
|
case " $file_list_uniq " in
|
||||||
|
*" $file "*)
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
file_list_uniq="$file_list_uniq $file"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
} done
|
||||||
|
|
||||||
|
for file in $file_list_uniq; do {
|
||||||
|
[ -e "$file" ] || continue
|
||||||
|
|
||||||
|
while read -r line; do {
|
||||||
|
case "$line" in
|
||||||
|
[0-9]*)
|
||||||
|
# 2001:bf7:820:901::1 stuttgarter-core.olsr # myself
|
||||||
|
# 10.63.160.161 AlexLaterne # 10.63.160.161
|
||||||
|
set -f
|
||||||
|
set +f -- $line
|
||||||
|
ip="$1"
|
||||||
|
hostname="$2"
|
||||||
|
|
||||||
|
# global vars, e.g.
|
||||||
|
# IP_1_2_3_4='foo' or IP_2001_bf7_820_901__1='bar'
|
||||||
|
eval IP_${ip//[.:]/_}="$hostname"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
} done <"$file"
|
||||||
|
} done
|
||||||
|
}
|
||||||
|
|
||||||
|
read_hostnames
|
||||||
|
|
||||||
|
VARS='localIP:Local remoteIP:Remote validityTime:vTime linkQuality:LQ'
|
||||||
|
VARS="$VARS neighborLinkQuality:NLQ linkCost:Cost remoteHostname:Host"
|
||||||
|
|
||||||
|
for HOST in '127.0.0.1' '::1';do
|
||||||
json_init
|
json_init
|
||||||
json_load "$(echo /links|nc ${HOST} 9090)"
|
json_load "$(echo /links|nc ${HOST} 9090)"
|
||||||
if json_is_a links array;then
|
if json_is_a links array;then
|
||||||
|
@ -29,6 +89,7 @@ for HOST in 127.0.0.1 ::1;do
|
||||||
;;*)
|
;;*)
|
||||||
for v in ${VARS};do
|
for v in ${VARS};do
|
||||||
eval printf \"%-\${_${v%:*}}s \" \$${v%:*}
|
eval printf \"%-\${_${v%:*}}s \" \$${v%:*}
|
||||||
|
eval remoteHostname="\$IP_${remoteIP//[.:]/_}"
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
;;esac
|
;;esac
|
||||||
|
|
Loading…
Reference in a new issue