blob: 7463a15b7f81043637128e77cf47e349a25b5f71 (
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
#!/bin/sh
. /usr/share/libubox/jshn.sh
. /lib/functions.sh
HOSTSFILE="-1"
find_hosts_config() {
local cfg="$1"
config_get library "$cfg" library
if [ "$library" != "olsrd_nameservice" ]; then
return 1
fi
config_get hosts_file "$cfg" hosts_file
HOSTSFILE=$hosts_file
}
load_hosts() {
config_load olsrd
config_foreach find_hosts_config LoadPlugin
local hosts4=$(cat $HOSTSFILE)
HOSTSFILE=""
config_load olsrd6
config_foreach find_hosts_config LoadPlugin
if [ -f "$HOSTSFILE" ]; then
local hosts6=$(cat "$HOSTSFILE")
else
local hosts6=""
fi
local hosts="$hosts4$hosts6"
json_init
json_add_string hosts "$hosts"
json_dump
}
json_stringescape() {
awk '
NR>1 { r = r "\\n" }
{
gsub(/["\\]/, "\\\\&");
gsub(/\t/, "\\t");
gsub(/\r/, "\\r");
r = r $0
}
END { print r }
' | tr -d '\n'
}
case "$1" in
list)
json_init
json_add_object "getjsondata"
json_add_string 'otable' 'String'
json_add_int 'v4_port' 'Integer'
json_add_int 'v6_port' 'Integer'
json_close_object
json_add_object "hasipip"
json_close_object
json_add_object "hosts"
json_close_object
json_dump
;;
call)
case "$2" in
getjsondata)
json_init
json_load "$(cat)"
json_get_var otable otable
json_get_var v4_port v4_port
json_get_var v6_port v6_port
{
printf '{"jsonreq4":"'
echo "/${otable}" | nc 127.0.0.1 "${v4_port}" | sed -n '/^[}{ ]/p' | json_stringescape
printf '","jsonreq6":"'
echo "/${otable}" | nc ::1 "${v6_port}" | sed -n '/^[}{ ]/p' | json_stringescape
printf '"}\n'
} 2>/dev/null
;;
hasipip)
result=$(ls /etc/modules.d/ | grep -E "[0-9]*-ipip")
json_init
json_add_string "result" "$result"
json_dump
;;
hosts)
load_hosts
;;
esac
;;
esac
|