/
omr-bypass.js
302 lines (243 loc) · 8.63 KB
/
omr-bypass.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
'use strict';
'require rpc';
'require form';
'require fs';
'require uci';
'require tools.widgets as widgets';
var callHostHints;
return L.view.extend({
callHostHints: rpc.declare({
object: 'luci-rpc',
method: 'getHostHints',
expect: { '': {} }
}),
load: function() {
return Promise.all([
L.resolveDefault(fs.stat('/proc/net/xt_ndpi/proto'), null),
this.callHostHints()
]);
},
render: function(testhosts) {
var m, s, o, hosts;
hosts = testhosts[1];
m = new form.Map('omr-bypass', _('OMR-Bypass'),_('OpenMPTCProuter IP must be used as DNS.'));
/*
s = m.section(form.TypedSection, 'global', _('Global settings'));
s.addremove = false;
s.anonymous = true;
o = s.option(form.Flag, 'noipv6', _('Disable IPv6 AAAA DNS results for bypassed domains'));
o.default = o.disabled;
o.optional = true;
*/
s = m.section(form.GridSection, 'domains', _('Domains'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.Value, 'name', _('Domain'));
o.rmempty = false;
o = s.option(form.Flag, 'vpn', _('VPN on server'),_('Bypass using VPN configured on server.'));
o.modalonly = true
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used.'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o.depends('vpn', '0');
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
o = s.option(form.ListValue, 'family', _('Restrict to address family'));
o.value('ipv4ipv6', _('IPv4 and IPv6'));
o.value('ipv4', _('IPv4 only'));
o.value('ipv6', _('IPv6 only'));
o.default = 'ipv4ipv6';
o.modalonly = true
o = s.option(form.Flag, 'noipv6', _('Disable AAAA IPv6 DNS'));
o.default = o.enabled;
o.modalonly = true
s = m.section(form.GridSection, 'ips', _('IPs and Networks'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.Value, 'ip', _('IP'));
o.rmempty = false;
o = s.option(form.Flag, 'vpn', _('VPN on server'),_('Bypass using VPN configured on server.'));
o.modalonly = true
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used.'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o.depends('vpn', '0');
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
s = m.section(form.GridSection, 'dest_port', _('Ports destination'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.Value, 'dport', _('port'));
o.rmempty = false;
o = s.option(form.ListValue, 'proto', _('protocol'));
o.default = 'tcp';
o.rmempty = false;
o.value('tcp');
o.value('udp');
o.value('icmp');
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used.'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
s = m.section(form.GridSection, 'src_port', _('Ports source'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.Value, 'sport', _('port'));
o.rmempty = false;
o = s.option(form.ListValue, 'proto', _('protocol'));
o.default = 'tcp';
o.rmempty = false;
o.value('tcp');
o.value('udp');
o.value('icmp');
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used.'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
s = m.section(form.GridSection, 'macs', _('MAC-Address'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.Value, 'mac', _('source MAC-Address'));
o.datatype = 'list(unique(macaddr))';
o.rmempty = false;
Object.keys(hosts).forEach(function(mac) {
var hint = hosts[mac].name || hosts[mac].ipv4;
o.value(mac, hint ? '%s (%s)'.format(mac, hint) : mac);
});
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used.'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
s = m.section(form.GridSection, 'lan_ip', _('Source lan IP address or network'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.Value, 'ip', _('IP Address'));
o.datatype = 'or(ip4addr,ip6addr)';
o.rmempty = false;
Object.keys(hosts).forEach(function(mac) {
if (hosts[mac].ipv4) {
var hint = hosts[mac].name;
o.value(hosts[mac].ipv4, hint ? '%s (%s)'.format(hosts[mac].ipv4, hint) : hosts[mac].ipv4);
}
});
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used.'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
s = m.section(form.GridSection, 'asns', _('ASN'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.Value, 'asn', _('ASN'));
o.rmempty = false;
o = s.option(form.Flag, 'vpn', _('VPN on server'),_('Bypass using VPN configured on server.'));
o.modalonly = true
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used.'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o.depends('vpn', '0');
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
s = m.section(form.GridSection, 'dpis', _('Protocols and services'));
s.addremove = true;
s.anonymous = true;
s.nodescriptions = true;
o = s.option(form.Flag, 'enabled', _('Enabled'));
o.default = o.enabled;
o = s.option(form.ListValue, 'proto', _('Protocol/Service'));
o.rmempty = false;
o.load = function(section_id) {
return Promise.all([
L.resolveDefault(fs.read_direct('/proc/net/xt_ndpi/proto'), ''),
L.resolveDefault(fs.read_direct('/proc/net/xt_ndpi/host_proto'), ''),
fs.read_direct('/usr/share/omr-bypass/omr-bypass-proto.lst')
]).then(L.bind(function(filesi) {
var proto = filesi[0].split(/\n/),
host = filesi[1].split(/\n/),
protofile = filesi[2].split(/\n/),
name = [];
if (proto.length > 2) {
for (var i = 0; i < proto.length; i++) {
var m = proto[i].split(/\s+/);
if (m && m[0] != "#id" && m[1] != "disabled")
name.push(m[2]);
}
}
if (host.length > 2) {
for (var i = 0; i < host.length; i++) {
var m = host[i].split(/:/);
if (m && m[0] != "#Proto")
name.push(m[0].toLowerCase());
}
}
if (proto.length == 1 && host.length == 1) {
for (var i = 0; i < protofile.length; i++) {
var m = protofile[i];
name.push(m);
}
}
name = Array.from(new Set(name)).sort(function (a, b) { return a.toLowerCase().localeCompare(b.toLowerCase())}).reduce(function(a, b){ if (a.slice(-1)[0] !== b) a.push(b);return a;},[]);
for (var i = 0; i < name.length; i++) {
this.value(name[i]);
}
return this.super('load', [section_id]);
},this));
};
o = s.option(form.Flag, 'vpn', _('VPN on server'),_('Bypass using VPN configured on server.'));
o.modalonly = true
o = s.option(widgets.DeviceSelect, 'interface', _('Interface'),_('When none selected, MPTCP master interface is used (or an other interface if master is down).'));
o.noaliases = true;
o.noinactive = true;
o.nocreate = true;
o.depends('vpn', '0');
o = s.option(form.Value, 'note', _('Note'));
o.rmempty = true;
o = s.option(form.ListValue, 'family', _('Restrict to address family'));
o.value('ipv4ipv6', _('IPv4 and IPv6'));
o.value('ipv4', _('IPv4 only'));
o.value('ipv6', _('IPv6 only'));
o.default = 'ipv4ipv6';
o.modalonly = true
o = s.option(form.Flag, 'noipv6', _('Disable AAAA IPv6 DNS'));
o.default = o.enabled;
o.modalonly = true
if (testhosts[0]) {
o = s.option(form.Flag, 'ndpi', _('Enable ndpi'));
o.default = o.enabled;
o.modalonly = true
o.depends('vpn', '0');
}
return m.render();
}
});