-
Notifications
You must be signed in to change notification settings - Fork 73
/
update-dnsmasq
executable file
·101 lines (71 loc) · 1.73 KB
/
update-dnsmasq
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
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
. /lib/functions.sh
_json_push() {
export JSON_PATH="${JSON_PATH}/$1"
}
_json_pop() {
export JSON_PATH="${JSON_PATH%/*}"
}
json_init() {
export JSON_PATH=''
}
json_add_object() {
_json_push "$1"
}
json_close_object() {
_json_pop
}
json_add_array() {
_json_push "$1"
}
json_close_array() {
_json_pop
}
json_add_int() {
return
}
json_add_boolean() {
return
}
json_add_double() {
return
}
json_add_string() {
[ "$JSON_PATH" = '/inactive/dns_server' ] || return
echo "$2"
}
get_dns_server() {
eval `jshn -r "$(ubus call network.interface.wan status)"`
}
generate_dnsmasq_conf_remote() {
local remote="$1"; local servers="$2"
local hostname="$(echo "$remote" | awk -F \" '{print $2}')"
[ -n "$hostname" ] || return
for ns in $servers; do
echo "server=/$hostname/$ns"
done
}
generate_dnsmasq_conf_peer() {
local peer="$1"; local servers="$2"
local enabled; local net
config_get_bool enabled "$peer" 'enabled' 0
[ "$enabled" -gt 0 ] || return
config_get net "$peer" 'net'
[ "$net" = 'mesh_vpn' ] || return
config_list_foreach "$peer" 'remote' generate_dnsmasq_conf_remote "$servers"
}
generate_dnsmasq_conf() {
local servers="$1"
config_load fastd
config_foreach generate_dnsmasq_conf_peer 'peer' "$servers"
}
mkdir -p /var/gluon/mesh-vpn-fastd
generate_dnsmasq_conf "$(get_dns_server)" > /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$
lock /var/gluon/mesh-vpn-fastd/dnsmasq.conf.lock
if cmp -s /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$ /var/gluon/dnsmasq.d/mesh-vpn-fastd.conf; then
rm /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$
else
mv -f /var/gluon/mesh-vpn-fastd/dnsmasq.conf.$$ /var/gluon/dnsmasq.d/mesh-vpn-fastd.conf
/etc/init.d/dnsmasq restart
fi
lock -u /var/gluon/mesh-vpn-fastd/dnsmasq.conf.lock