luci-app-olsrd2: New Package for OLSR2 configuration and status visualisation'
[feed/routing.git] / luci-app-olsrd2 / root / usr / libexec / rpcd / status.olsrd2
1 #!/bin/sh
2 # Copyright (C) 2016 OpenWrt.org
3
4 . /lib/functions.sh
5 . /usr/share/libubox/jshn.sh
6 . /lib/functions/olsrd2.sh
7
8 case "$1" in
9 list)
10 json_init
11
12 json_add_object "getVersion"
13 json_close_object
14 json_add_object "getLan"
15 json_close_object
16 json_add_object "getNode"
17 json_close_object
18 json_add_object "getNeighbors"
19 json_close_object
20 json_add_object "getAttached_network"
21 json_close_object
22 json_add_object "getRoute"
23 json_close_object
24 json_add_object "getGraph"
25 json_close_object
26 json_add_object "getDomain"
27 json_close_object
28
29 json_dump
30 ;;
31 call)
32 case "$2" in
33 getVersion)
34 echo '/systeminfo json version /quit' | nc ::1 2009 2>/dev/null
35 ;;
36 getLan)
37 echo '/olsrv2info json lan /quit' | nc ::1 2009 2>/dev/null
38 ;;
39 getNode)
40 echo '/olsrv2info json node /quit' | nc ::1 2009 2>/dev/null
41 ;;
42 getNeighbors)
43 domain="$(uci_get luci_olsr2 general domain)"
44 [ -z "$domain" ] || domain=".$domain"
45 json_init
46 json_add_array "neighbors"
47 OLDIFS="$IFS"
48 IFS=$'\n'
49 neighbor_status="$(echo '/nhdpinfo neighbor /quit' | nc ::1 2009 | cut -f 1,9,10,11,12)"
50 for neighbor in $neighbor_status; do
51 json_add_object 0
52 IFS="$OLDIFS"
53 i=1
54 for value in $neighbor ; do
55 case $i in
56 1) json_add_string "originator" "${value}"
57 network_get_neighbour_by_ip "${value}"
58 json_add_string "lladdr" "${lladdr}"
59 json_add_string "hostname" "${hostname}${domain}"
60 network_get_name_by_device interface $dev
61 json_add_string "interface" "${interface}"
62 ;;
63 2) json_add_string "metric_in" "${value}";;
64 3) json_add_string "metric_in_raw" "${value}";;
65 4) json_add_string "metric_out" "${value}";;
66 5) json_add_string "metric_out_raw" "${value}";;
67 esac
68 i=$(( i + 1 ))
69 done
70 IFS=$'\n'
71 json_close_object
72 done
73 IFS="$OLDIFS"
74 json_close_array
75 json_dump
76 ;;
77 getAttached_network)
78 echo '/olsrv2info json attached_network /quit' | nc ::1 2009 2>/dev/null
79 ;;
80 getRoute)
81 echo '/netjsoninfo filter route ipv6_0' | nc ::1 2009 2>/dev/null
82 ;;
83 getGraph)
84 echo '/netjsoninfo filter graph ipv6_0' | nc ::1 2009 2>/dev/null
85 ;;
86 getDomain)
87 echo '/netjsoninfo domain' | nc ::1 2009 2>/dev/null
88 ;;
89 esac
90 ;;
91 esac