mirror of
https://github.com/Ysurac/openmptcprouter-feeds.git
synced 2025-03-09 15:40:03 +00:00
Add SNAT support to firewall app*
This commit is contained in:
parent
0efde1e48a
commit
243b7bf087
38 changed files with 28128 additions and 0 deletions
312
luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js
Normal file
312
luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js
Normal file
|
@ -0,0 +1,312 @@
|
|||
'use strict';
|
||||
'require ui';
|
||||
'require uci';
|
||||
'require form';
|
||||
'require network';
|
||||
'require firewall';
|
||||
'require tools.prng as random';
|
||||
|
||||
var protocols = [
|
||||
'ip', 0, 'IP',
|
||||
'hopopt', 0, 'HOPOPT',
|
||||
'icmp', 1, 'ICMP',
|
||||
'igmp', 2, 'IGMP',
|
||||
'ggp', 3 , 'GGP',
|
||||
'ipencap', 4, 'IP-ENCAP',
|
||||
'st', 5, 'ST',
|
||||
'tcp', 6, 'TCP',
|
||||
'egp', 8, 'EGP',
|
||||
'igp', 9, 'IGP',
|
||||
'pup', 12, 'PUP',
|
||||
'udp', 17, 'UDP',
|
||||
'hmp', 20, 'HMP',
|
||||
'xns-idp', 22, 'XNS-IDP',
|
||||
'rdp', 27, 'RDP',
|
||||
'iso-tp4', 29, 'ISO-TP4',
|
||||
'dccp', 33, 'DCCP',
|
||||
'xtp', 36, 'XTP',
|
||||
'ddp', 37, 'DDP',
|
||||
'idpr-cmtp', 38, 'IDPR-CMTP',
|
||||
'ipv6', 41, 'IPv6',
|
||||
'ipv6-route', 43, 'IPv6-Route',
|
||||
'ipv6-frag', 44, 'IPv6-Frag',
|
||||
'idrp', 45, 'IDRP',
|
||||
'rsvp', 46, 'RSVP',
|
||||
'gre', 47, 'GRE',
|
||||
'esp', 50, 'IPSEC-ESP',
|
||||
'ah', 51, 'IPSEC-AH',
|
||||
'skip', 57, 'SKIP',
|
||||
'ipv6-icmp', 58, 'IPv6-ICMP',
|
||||
'ipv6-nonxt', 59, 'IPv6-NoNxt',
|
||||
'ipv6-opts', 60, 'IPv6-Opts',
|
||||
'rspf', 73, 'RSPF', 'CPHB',
|
||||
'vmtp', 81, 'VMTP',
|
||||
'eigrp', 88, 'EIGRP',
|
||||
'ospf', 89, 'OSPFIGP',
|
||||
'ax.25', 93, 'AX.25',
|
||||
'ipip', 94, 'IPIP',
|
||||
'etherip', 97, 'ETHERIP',
|
||||
'encap', 98, 'ENCAP',
|
||||
'pim', 103, 'PIM',
|
||||
'ipcomp', 108, 'IPCOMP',
|
||||
'vrrp', 112, 'VRRP',
|
||||
'l2tp', 115, 'L2TP',
|
||||
'isis', 124, 'ISIS',
|
||||
'sctp', 132, 'SCTP',
|
||||
'fc', 133, 'FC',
|
||||
'mobility-header', 135, 'Mobility-Header',
|
||||
'udplite', 136, 'UDPLite',
|
||||
'mpls-in-ip', 137, 'MPLS-in-IP',
|
||||
'manet', 138, 'MANET',
|
||||
'hip', 139, 'HIP',
|
||||
'shim6', 140, 'Shim6',
|
||||
'wesp', 141, 'WESP',
|
||||
'rohc', 142, 'ROHC',
|
||||
];
|
||||
|
||||
function lookupProto(x) {
|
||||
if (x == null || x == '')
|
||||
return null;
|
||||
|
||||
var s = String(x).toLowerCase();
|
||||
|
||||
for (var i = 0; i < protocols.length; i += 3)
|
||||
if (s == protocols[i] || s == protocols[i+1])
|
||||
return [ protocols[i+1], protocols[i+2] ];
|
||||
|
||||
return [ -1, x ];
|
||||
}
|
||||
|
||||
|
||||
return L.Class.extend({
|
||||
fmt_neg: function(x) {
|
||||
var rv = E([]),
|
||||
v = (typeof(x) == 'string') ? x.replace(/^ *! */, '') : '';
|
||||
|
||||
L.dom.append(rv, (v != '' && v != x) ? [ _('not') + ' ', v ] : [ '', x ]);
|
||||
return rv;
|
||||
},
|
||||
|
||||
fmt_mac: function(x) {
|
||||
var rv = E([]), l = L.toArray(x);
|
||||
|
||||
if (l.length == 0)
|
||||
return null;
|
||||
|
||||
L.dom.append(rv, [ _('MAC') + ' ' ]);
|
||||
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
var n = this.fmt_neg(l[i]);
|
||||
L.dom.append(rv, (i > 0) ? [ ', ', n ] : n);
|
||||
}
|
||||
|
||||
if (rv.childNodes.length > 2)
|
||||
rv.firstChild.data = _('MACs') + ' ';
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
fmt_port: function(x, d) {
|
||||
var rv = E([]), l = L.toArray(x);
|
||||
|
||||
if (l.length == 0) {
|
||||
if (d) {
|
||||
L.dom.append(rv, E('var', {}, d));
|
||||
return rv;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
L.dom.append(rv, [ _('port') + ' ' ]);
|
||||
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
var n = this.fmt_neg(l[i]),
|
||||
m = n.lastChild.data.match(/^(\d+)\D+(\d+)$/);
|
||||
|
||||
if (i > 0)
|
||||
L.dom.append(rv, [ ', ' ]);
|
||||
|
||||
if (m) {
|
||||
rv.firstChild.data = _('ports') + ' ';
|
||||
L.dom.append(rv, E('var', [ n.firstChild, m[1], '-', m[2] ]));
|
||||
}
|
||||
else {
|
||||
L.dom.append(rv, E('var', {}, n));
|
||||
}
|
||||
}
|
||||
|
||||
if (rv.childNodes.length > 2)
|
||||
rv.firstChild.data = _('ports') + ' ';
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
fmt_ip: function(x, d) {
|
||||
var rv = E([]), l = L.toArray(x);
|
||||
|
||||
if (l.length == 0) {
|
||||
if (d) {
|
||||
L.dom.append(rv, E('var', {}, d));
|
||||
return rv;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
L.dom.append(rv, [ _('IP') + ' ' ]);
|
||||
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
var n = this.fmt_neg(l[i]),
|
||||
m = n.lastChild.data.match(/^(\S+)\/(\d+\.\S+)$/);
|
||||
|
||||
if (i > 0)
|
||||
L.dom.append(rv, [ ', ' ]);
|
||||
|
||||
if (m)
|
||||
rv.firstChild.data = _('IP range') + ' ';
|
||||
else if (n.lastChild.data.match(/^[a-zA-Z0-9_]+$/))
|
||||
rv.firstChild.data = _('Network') + ' ';
|
||||
|
||||
L.dom.append(rv, E('var', {}, n));
|
||||
}
|
||||
|
||||
if (rv.childNodes.length > 2)
|
||||
rv.firstChild.data = _('IPs') + ' ';
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
fmt_zone: function(x, d) {
|
||||
if (x == '*')
|
||||
return E('var', _('any zone'));
|
||||
else if (x != null && x != '')
|
||||
return E('var', {}, [ x ]);
|
||||
else if (d != null && d != '')
|
||||
return E('var', {}, d);
|
||||
else
|
||||
return null;
|
||||
},
|
||||
|
||||
fmt_icmp_type: function(x) {
|
||||
var rv = E([]), l = L.toArray(x);
|
||||
|
||||
if (l.length == 0)
|
||||
return null;
|
||||
|
||||
L.dom.append(rv, [ _('type') + ' ' ]);
|
||||
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
var n = this.fmt_neg(l[i]);
|
||||
|
||||
if (i > 0)
|
||||
L.dom.append(rv, [ ', ' ]);
|
||||
|
||||
L.dom.append(rv, E('var', {}, n));
|
||||
}
|
||||
|
||||
if (rv.childNodes.length > 2)
|
||||
rv.firstChild.data = _('types') + ' ';
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
fmt_family: function(family) {
|
||||
if (family == 'ipv4')
|
||||
return _('IPv4');
|
||||
else if (family == 'ipv6')
|
||||
return _('IPv6');
|
||||
else
|
||||
return _('IPv4 and IPv6');
|
||||
},
|
||||
|
||||
fmt_proto: function(x, icmp_types) {
|
||||
var rv = E([]), l = L.toArray(x);
|
||||
|
||||
if (l.length == 0)
|
||||
return null;
|
||||
|
||||
var t = this.fmt_icmp_type(icmp_types);
|
||||
|
||||
for (var i = 0; i < l.length; i++) {
|
||||
var n = this.fmt_neg(l[i]),
|
||||
p = lookupProto(n.lastChild.data);
|
||||
|
||||
if (n.lastChild.data == 'all')
|
||||
continue;
|
||||
|
||||
if (i > 0)
|
||||
L.dom.append(rv, [ ', ' ]);
|
||||
|
||||
if (t && (p[0] == 1 || p[0] == 58))
|
||||
L.dom.append(rv, [ _('%s%s with %s').format(n.firstChild.data, p[1], ''), t ]);
|
||||
else
|
||||
L.dom.append(rv, [ n.firstChild.data, p[1] ]);
|
||||
}
|
||||
|
||||
return rv;
|
||||
},
|
||||
|
||||
fmt_limit: function(limit, burst) {
|
||||
if (limit == null || limit == '')
|
||||
return null;
|
||||
|
||||
var m = String(limit).match(/^(\d+)\/(\w+)$/),
|
||||
u = m[2] || 'second',
|
||||
l = +(m[1] || limit),
|
||||
b = +burst;
|
||||
|
||||
if (!isNaN(l)) {
|
||||
if (u.match(/^s/))
|
||||
u = _('second');
|
||||
else if (u.match(/^m/))
|
||||
u = _('minute');
|
||||
else if (u.match(/^h/))
|
||||
u = _('hour');
|
||||
else if (u.match(/^d/))
|
||||
u = _('day');
|
||||
|
||||
if (!isNaN(b) && b > 0)
|
||||
return E('<span>' +
|
||||
_('<var>%d</var> pkts. per <var>%s</var>, burst <var>%d</var> pkts.').format(l, u, b) +
|
||||
'</span>');
|
||||
else
|
||||
return E('<span>' +
|
||||
_('<var>%d</var> pkts. per <var>%s</var>').format(l, u) +
|
||||
'</span>');
|
||||
}
|
||||
},
|
||||
|
||||
fmt_target: function(x, src, dest) {
|
||||
if (src == null || src == '') {
|
||||
if (x == 'ACCEPT')
|
||||
return _('Accept output');
|
||||
else if (x == 'REJECT')
|
||||
return _('Refuse output');
|
||||
else if (x == 'NOTRACK')
|
||||
return _('Do not track output');
|
||||
else /* if (x == 'DROP') */
|
||||
return _('Discard output');
|
||||
}
|
||||
else if (dest != null && dest != '') {
|
||||
if (x == 'ACCEPT')
|
||||
return _('Accept forward');
|
||||
else if (x == 'REJECT')
|
||||
return _('Refuse forward');
|
||||
else if (x == 'NOTRACK')
|
||||
return _('Do not track forward');
|
||||
else /* if (x == 'DROP') */
|
||||
return _('Discard forward');
|
||||
}
|
||||
else {
|
||||
if (x == 'ACCEPT')
|
||||
return _('Accept input');
|
||||
else if (x == 'REJECT' )
|
||||
return _('Refuse input');
|
||||
else if (x == 'NOTRACK')
|
||||
return _('Do not track input');
|
||||
else /* if (x == 'DROP') */
|
||||
return _('Discard input');
|
||||
}
|
||||
}
|
||||
});
|
|
@ -0,0 +1,32 @@
|
|||
'use strict';
|
||||
'require fs';
|
||||
'require ui';
|
||||
|
||||
return L.view.extend({
|
||||
load: function() {
|
||||
return L.resolveDefault(fs.read('/etc/firewall.user'), '');
|
||||
},
|
||||
|
||||
handleSave: function(ev) {
|
||||
var value = (document.querySelector('textarea').value || '').trim().replace(/\r\n/g, '\n') + '\n';
|
||||
|
||||
return fs.write('/etc/firewall.user', value).then(function(rc) {
|
||||
document.querySelector('textarea').value = value;
|
||||
ui.addNotification(null, E('p', _('Contents have been saved.')), 'info');
|
||||
fs.exec('/etc/init.d/firewall', ['restart']);
|
||||
}).catch(function(e) {
|
||||
ui.addNotification(null, E('p', _('Unable to save contents: %s').format(e.message)));
|
||||
});
|
||||
},
|
||||
|
||||
render: function(fwuser) {
|
||||
return E([
|
||||
E('h2', _('Firewall - Custom Rules')),
|
||||
E('p', {}, _('Custom rules allow you to execute arbitrary iptables commands which are not otherwise covered by the firewall framework. The commands are executed after each firewall restart, right after the default ruleset has been loaded.')),
|
||||
E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 10 }, [ fwuser != null ? fwuser : '' ]))
|
||||
]);
|
||||
},
|
||||
|
||||
handleSaveApply: null,
|
||||
handleReset: null
|
||||
});
|
|
@ -0,0 +1,274 @@
|
|||
'use strict';
|
||||
'require ui';
|
||||
'require rpc';
|
||||
'require uci';
|
||||
'require form';
|
||||
'require tools.firewall as fwtool';
|
||||
'require tools.widgets as widgets';
|
||||
|
||||
function fmt(fmt /*, ...*/) {
|
||||
var repl = [], wrap = false;
|
||||
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
if (L.dom.elem(arguments[i])) {
|
||||
switch (arguments[i].nodeType) {
|
||||
case 1:
|
||||
repl.push(arguments[i].outerHTML);
|
||||
wrap = true;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
repl.push(arguments[i].data);
|
||||
break;
|
||||
|
||||
case 11:
|
||||
var span = E('span');
|
||||
span.appendChild(arguments[i]);
|
||||
repl.push(span.innerHTML);
|
||||
wrap = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
repl.push('');
|
||||
}
|
||||
}
|
||||
else {
|
||||
repl.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var rv = fmt.format.apply(fmt, repl);
|
||||
return wrap ? E('span', rv) : rv;
|
||||
}
|
||||
|
||||
function forward_proto_txt(s) {
|
||||
return fmt('%s-%s',
|
||||
fwtool.fmt_family(uci.get('firewall', s, 'family')),
|
||||
fwtool.fmt_proto(uci.get('firewall', s, 'proto'),
|
||||
uci.get('firewall', s, 'icmp_type')) || 'TCP+UDP');
|
||||
}
|
||||
|
||||
function forward_src_txt(s) {
|
||||
var z = fwtool.fmt_zone(uci.get('firewall', s, 'src'), _('any zone')),
|
||||
a = fwtool.fmt_ip(uci.get('firewall', s, 'src_ip'), _('any host')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'src_port')),
|
||||
m = fwtool.fmt_mac(uci.get('firewall', s, 'src_mac'));
|
||||
|
||||
if (p && m)
|
||||
return fmt(_('From %s in %s with source %s and %s'), a, z, p, m);
|
||||
else if (p || m)
|
||||
return fmt(_('From %s in %s with source %s'), a, z, p || m);
|
||||
else
|
||||
return fmt(_('From %s in %s'), a, z);
|
||||
}
|
||||
|
||||
function forward_via_txt(s) {
|
||||
var a = fwtool.fmt_ip(uci.get('firewall', s, 'src_dip'), _('any router IP')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'src_dport'));
|
||||
|
||||
if (p)
|
||||
return fmt(_('Via %s at %s'), a, p);
|
||||
else
|
||||
return fmt(_('Via %s'), a);
|
||||
}
|
||||
|
||||
return L.view.extend({
|
||||
callHostHints: rpc.declare({
|
||||
object: 'luci-rpc',
|
||||
method: 'getHostHints',
|
||||
expect: { '': {} }
|
||||
}),
|
||||
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
this.callHostHints()
|
||||
]);
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
var hosts = data[0],
|
||||
m, s, o;
|
||||
|
||||
m = new form.Map('firewall', _('Firewall - Port Forwards'),
|
||||
_('Port forwarding allows remote computers on the Internet to connect to a specific computer or service within the private LAN.'));
|
||||
|
||||
s = m.section(form.GridSection, 'redirect', _('Port Forwards'));
|
||||
s.addremove = true;
|
||||
s.anonymous = true;
|
||||
s.sortable = true;
|
||||
|
||||
s.tab('general', _('General Settings'));
|
||||
s.tab('advanced', _('Advanced Settings'));
|
||||
|
||||
s.filter = function(section_id) {
|
||||
return (uci.get('firewall', section_id, 'target') != 'SNAT');
|
||||
};
|
||||
|
||||
s.sectiontitle = function(section_id) {
|
||||
return uci.get('firewall', section_id, 'name') || _('Unnamed forward');
|
||||
};
|
||||
|
||||
s.handleAdd = function(ev) {
|
||||
var config_name = this.uciconfig || this.map.config,
|
||||
section_id = uci.add(config_name, this.sectiontype);
|
||||
|
||||
uci.set(config_name, section_id, 'target', 'DNAT');
|
||||
|
||||
this.addedSection = section_id;
|
||||
this.renderMoreOptionsModal(section_id);
|
||||
};
|
||||
|
||||
o = s.taboption('general', form.Value, 'name', _('Name'));
|
||||
o.placeholder = _('Unnamed forward');
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.option(form.DummyValue, '_match', _('Match'));
|
||||
o.modalonly = false;
|
||||
o.textvalue = function(s) {
|
||||
return E('small', [
|
||||
forward_proto_txt(s), E('br'),
|
||||
forward_src_txt(s), E('br'),
|
||||
forward_via_txt(s)
|
||||
]);
|
||||
};
|
||||
|
||||
o = s.option(form.ListValue, '_dest', _('Forward to'));
|
||||
o.modalonly = false;
|
||||
o.textvalue = function(s) {
|
||||
var z = fwtool.fmt_zone(uci.get('firewall', s, 'dest'), _('any zone')),
|
||||
a = fwtool.fmt_ip(uci.get('firewall', s, 'dest_ip'), _('any host')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'dest_port')) ||
|
||||
fwtool.fmt_port(uci.get('firewall', s, 'src_dport'));
|
||||
|
||||
if (p)
|
||||
return fmt(_('%s, %s in %s'), a, p, z);
|
||||
else
|
||||
return fmt(_('%s in %s'), a, z);
|
||||
};
|
||||
|
||||
o = s.option(form.Flag, 'enabled', _('Enable'));
|
||||
o.modalonly = false;
|
||||
o.default = o.enabled;
|
||||
o.editable = true;
|
||||
|
||||
o = s.taboption('general', form.Value, 'proto', _('Protocol'));
|
||||
o.modalonly = true;
|
||||
o.default = 'tcp udp';
|
||||
o.value('tcp udp', 'TCP+UDP');
|
||||
o.value('tcp', 'TCP');
|
||||
o.value('udp', 'UDP');
|
||||
o.value('icmp', 'ICMP');
|
||||
|
||||
o.cfgvalue = function(/* ... */) {
|
||||
var v = this.super('cfgvalue', arguments);
|
||||
return (v == 'tcpudp') ? 'tcp udp' : v;
|
||||
};
|
||||
|
||||
o = s.taboption('general', widgets.ZoneSelect, 'src', _('Source zone'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.nocreate = true;
|
||||
o.default = 'wan';
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'src_mac', _('Source MAC address'),
|
||||
_('Only match incoming traffic from these MACs.'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'neg(macaddr)';
|
||||
o.placeholder = E('em', _('any'));
|
||||
L.sortedKeys(hosts).forEach(function(mac) {
|
||||
o.value(mac, '%s (%s)'.format(
|
||||
mac,
|
||||
hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?'
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'src_ip', _('Source IP address'),
|
||||
_('Only match incoming traffic from this IP or range.'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'neg(ipmask4)';
|
||||
o.placeholder = E('em', _('any'));
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'src_port', _('Source port'),
|
||||
_('Only match incoming traffic originating from the given source port or port range on the client host'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'neg(portrange)';
|
||||
o.placeholder = _('any');
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'src_dip', _('External IP address'),
|
||||
_('Only match incoming traffic directed at the given IP address.'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'neg(ipmask4)';
|
||||
o.placeholder = E('em', _('any'));
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('general', form.Value, 'src_dport', _('External port'),
|
||||
_('Match incoming traffic directed at the given destination port or port range on this host'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.datatype = 'neg(portrange)';
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
o = s.taboption('general', widgets.ZoneSelect, 'dest', _('Internal zone'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.nocreate = true;
|
||||
o.default = 'lan';
|
||||
|
||||
o = s.taboption('general', form.Value, 'dest_ip', _('Internal IP address'),
|
||||
_('Redirect matched incoming traffic to the specified internal host'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'ipmask4';
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('general', form.Value, 'dest_port', _('Internal port'),
|
||||
_('Redirect matched incoming traffic to the given port on the internal host'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.placeholder = _('any');
|
||||
o.datatype = 'portrange';
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
o = s.taboption('advanced', form.Flag, 'reflection', _('Enable NAT Loopback'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.default = o.enabled;
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'extra', _('Extra arguments'),
|
||||
_('Passes additional arguments to iptables. Use with care!'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,383 @@
|
|||
'use strict';
|
||||
'require ui';
|
||||
'require rpc';
|
||||
'require uci';
|
||||
'require form';
|
||||
'require tools.firewall as fwtool';
|
||||
'require tools.widgets as widgets';
|
||||
|
||||
function fmt(fmt /*, ...*/) {
|
||||
var repl = [], wrap = false;
|
||||
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
if (L.dom.elem(arguments[i])) {
|
||||
switch (arguments[i].nodeType) {
|
||||
case 1:
|
||||
repl.push(arguments[i].outerHTML);
|
||||
wrap = true;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
repl.push(arguments[i].data);
|
||||
break;
|
||||
|
||||
case 11:
|
||||
var span = E('span');
|
||||
span.appendChild(arguments[i]);
|
||||
repl.push(span.innerHTML);
|
||||
wrap = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
repl.push('');
|
||||
}
|
||||
}
|
||||
else {
|
||||
repl.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var rv = fmt.format.apply(fmt, repl);
|
||||
return wrap ? E('span', rv) : rv;
|
||||
}
|
||||
|
||||
function forward_proto_txt(s) {
|
||||
return fmt('%s-%s',
|
||||
fwtool.fmt_family(uci.get('firewall', s, 'family')),
|
||||
fwtool.fmt_proto(uci.get('firewall', s, 'proto'),
|
||||
uci.get('firewall', s, 'icmp_type')) || 'TCP+UDP');
|
||||
}
|
||||
|
||||
function rule_src_txt(s) {
|
||||
var z = fwtool.fmt_zone(uci.get('firewall', s, 'src')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'src_port')),
|
||||
m = fwtool.fmt_mac(uci.get('firewall', s, 'src_mac'));
|
||||
|
||||
// Forward/Input
|
||||
if (z) {
|
||||
var a = fwtool.fmt_ip(uci.get('firewall', s, 'src_ip'), _('any host'));
|
||||
if (p && m)
|
||||
return fmt(_('From %s in %s with source %s and %s'), a, z, p, m);
|
||||
else if (p || m)
|
||||
return fmt(_('From %s in %s with source %s'), a, z, p || m);
|
||||
else
|
||||
return fmt(_('From %s in %s'), a, z);
|
||||
}
|
||||
|
||||
// Output
|
||||
else {
|
||||
var a = fwtool.fmt_ip(uci.get('firewall', s, 'src_ip'), _('any router IP'));
|
||||
if (p && m)
|
||||
return fmt(_('From %s on <var>this device</var> with source %s and %s'), a, p, m);
|
||||
else if (p || m)
|
||||
return fmt(_('From %s on <var>this device</var> with source %s'), a, p || m);
|
||||
else
|
||||
return fmt(_('From %s on <var>this device</var>'), a);
|
||||
}
|
||||
}
|
||||
|
||||
function rule_dest_txt(s) {
|
||||
var z = fwtool.fmt_zone(uci.get('firewall', s, 'dest')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'dest_port'));
|
||||
|
||||
// Forward
|
||||
if (z) {
|
||||
var a = fwtool.fmt_ip(uci.get('firewall', s, 'dest_ip'), _('any host'));
|
||||
if (p)
|
||||
return fmt(_('To %s, %s in %s'), a, p, z);
|
||||
else
|
||||
return fmt(_('To %s in %s'), a, z);
|
||||
}
|
||||
|
||||
// Input
|
||||
else {
|
||||
var a = fwtool.fmt_ip(uci.get('firewall', s, 'dest_ip'), _('any router IP'));
|
||||
if (p)
|
||||
return fmt(_('To %s at %s on <var>this device</var>'), a, p);
|
||||
else
|
||||
return fmt(_('To %s on <var>this device</var>'), a);
|
||||
}
|
||||
}
|
||||
|
||||
function rule_target_txt(s) {
|
||||
var t = fwtool.fmt_target(uci.get('firewall', s, 'target'), uci.get('firewall', s, 'src'), uci.get('firewall', s, 'dest')),
|
||||
l = fwtool.fmt_limit(uci.get('firewall', s, 'limit'), uci.get('firewall', s, 'limit_burst'));
|
||||
|
||||
if (l)
|
||||
return fmt(_('<var>%s</var> and limit to %s'), t, l);
|
||||
else
|
||||
return fmt('<var>%s</var>', t);
|
||||
}
|
||||
|
||||
return L.view.extend({
|
||||
callHostHints: rpc.declare({
|
||||
object: 'luci-rpc',
|
||||
method: 'getHostHints',
|
||||
expect: { '': {} }
|
||||
}),
|
||||
|
||||
load: function() {
|
||||
return this.callHostHints().catch(function(e) {
|
||||
console.debug('load fail', e);
|
||||
});
|
||||
},
|
||||
|
||||
render: function(hosts) {
|
||||
var m, s, o;
|
||||
|
||||
m = new form.Map('firewall', _('Firewall - Traffic Rules'),
|
||||
_('Traffic rules define policies for packets traveling between different zones, for example to reject traffic between certain hosts or to open WAN ports on the router.'));
|
||||
|
||||
s = m.section(form.GridSection, 'rule', _('Traffic Rules'));
|
||||
s.addremove = true;
|
||||
s.anonymous = true;
|
||||
s.sortable = true;
|
||||
|
||||
s.tab('general', _('General Settings'));
|
||||
s.tab('advanced', _('Advanced Settings'));
|
||||
s.tab('timed', _('Time Restrictions'));
|
||||
|
||||
s.filter = function(section_id) {
|
||||
return (uci.get('firewall', section_id, 'target') != 'SNAT');
|
||||
};
|
||||
|
||||
s.sectiontitle = function(section_id) {
|
||||
return uci.get('firewall', section_id, 'name') || _('Unnamed rule');
|
||||
};
|
||||
|
||||
s.handleAdd = function(ev) {
|
||||
var config_name = this.uciconfig || this.map.config,
|
||||
section_id = uci.add(config_name, this.sectiontype),
|
||||
opt1, opt2;
|
||||
|
||||
for (var i = 0; i < this.children.length; i++)
|
||||
if (this.children[i].option == 'src')
|
||||
opt1 = this.children[i];
|
||||
else if (this.children[i].option == 'dest')
|
||||
opt2 = this.children[i];
|
||||
|
||||
opt1.default = 'wan';
|
||||
opt2.default = 'lan';
|
||||
|
||||
this.addedSection = section_id;
|
||||
this.renderMoreOptionsModal(section_id);
|
||||
|
||||
delete opt1.default;
|
||||
delete opt2.default;
|
||||
};
|
||||
|
||||
o = s.taboption('general', form.Value, 'name', _('Name'));
|
||||
o.placeholder = _('Unnamed rule');
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.option(form.DummyValue, '_match', _('Match'));
|
||||
o.modalonly = false;
|
||||
o.textvalue = function(s) {
|
||||
return E('small', [
|
||||
forward_proto_txt(s), E('br'),
|
||||
rule_src_txt(s), E('br'),
|
||||
rule_dest_txt(s)
|
||||
]);
|
||||
};
|
||||
|
||||
o = s.option(form.ListValue, '_target', _('Action'));
|
||||
o.modalonly = false;
|
||||
o.textvalue = function(s) {
|
||||
return rule_target_txt(s);
|
||||
};
|
||||
|
||||
o = s.option(form.Flag, 'enabled', _('Enable'));
|
||||
o.modalonly = false;
|
||||
o.default = o.enabled;
|
||||
o.editable = true;
|
||||
|
||||
//ft.opt_enabled(s, Button);
|
||||
//ft.opt_name(s, Value, _('Name'));
|
||||
|
||||
|
||||
o = s.taboption('advanced', form.ListValue, 'family', _('Restrict to address family'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.value('', _('IPv4 and IPv6'));
|
||||
o.value('ipv4', _('IPv4 only'));
|
||||
o.value('ipv6', _('IPv6 only'));
|
||||
|
||||
o = s.taboption('general', form.Value, 'proto', _('Protocol'));
|
||||
o.modalonly = true;
|
||||
o.default = 'tcp udp';
|
||||
o.value('all', _('Any'));
|
||||
o.value('tcp udp', 'TCP+UDP');
|
||||
o.value('tcp', 'TCP');
|
||||
o.value('udp', 'UDP');
|
||||
o.value('icmp', 'ICMP');
|
||||
o.cfgvalue = function(/* ... */) {
|
||||
var v = this.super('cfgvalue', arguments);
|
||||
return (v == 'tcpudp') ? 'tcp udp' : v;
|
||||
};
|
||||
|
||||
o = s.taboption('advanced', form.MultiValue, 'icmp_type', _('Match ICMP type'));
|
||||
o.modalonly = true;
|
||||
o.multiple = true;
|
||||
o.custom = true;
|
||||
o.cast = 'table';
|
||||
o.placeholder = _('any');
|
||||
o.value('', 'any');
|
||||
o.value('address-mask-reply');
|
||||
o.value('address-mask-request');
|
||||
o.value('communication-prohibited');
|
||||
o.value('destination-unreachable');
|
||||
o.value('echo-reply');
|
||||
o.value('echo-request');
|
||||
o.value('fragmentation-needed');
|
||||
o.value('host-precedence-violation');
|
||||
o.value('host-prohibited');
|
||||
o.value('host-redirect');
|
||||
o.value('host-unknown');
|
||||
o.value('host-unreachable');
|
||||
o.value('ip-header-bad');
|
||||
o.value('neighbour-advertisement');
|
||||
o.value('neighbour-solicitation');
|
||||
o.value('network-prohibited');
|
||||
o.value('network-redirect');
|
||||
o.value('network-unknown');
|
||||
o.value('network-unreachable');
|
||||
o.value('parameter-problem');
|
||||
o.value('port-unreachable');
|
||||
o.value('precedence-cutoff');
|
||||
o.value('protocol-unreachable');
|
||||
o.value('redirect');
|
||||
o.value('required-option-missing');
|
||||
o.value('router-advertisement');
|
||||
o.value('router-solicitation');
|
||||
o.value('source-quench');
|
||||
o.value('source-route-failed');
|
||||
o.value('time-exceeded');
|
||||
o.value('timestamp-reply');
|
||||
o.value('timestamp-request');
|
||||
o.value('TOS-host-redirect');
|
||||
o.value('TOS-host-unreachable');
|
||||
o.value('TOS-network-redirect');
|
||||
o.value('TOS-network-unreachable');
|
||||
o.value('ttl-zero-during-reassembly');
|
||||
o.value('ttl-zero-during-transit');
|
||||
o.depends('proto', 'icmp');
|
||||
|
||||
o = s.taboption('general', widgets.ZoneSelect, 'src', _('Source zone'));
|
||||
o.modalonly = true;
|
||||
o.nocreate = true;
|
||||
o.allowany = true;
|
||||
o.allowlocal = 'src';
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'src_mac', _('Source MAC address'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'list(macaddr)';
|
||||
o.placeholder = _('any');
|
||||
L.sortedKeys(hosts).forEach(function(mac) {
|
||||
o.value(mac, '%s (%s)'.format(
|
||||
mac,
|
||||
hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?'
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('general', form.Value, 'src_ip', _('Source address'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'list(neg(ipmask))';
|
||||
o.placeholder = _('any');
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('general', form.Value, 'src_port', _('Source port'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'list(neg(portrange))';
|
||||
o.placeholder = _('any');
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
o = s.taboption('general', widgets.ZoneSelect, 'dest', _('Destination zone'));
|
||||
o.modalonly = true;
|
||||
o.nocreate = true;
|
||||
o.allowany = true;
|
||||
o.allowlocal = true;
|
||||
|
||||
o = s.taboption('general', form.Value, 'dest_ip', _('Destination address'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'list(neg(ipmask))';
|
||||
o.placeholder = _('any');
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('general', form.Value, 'dest_port', _('Destination port'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'list(neg(portrange))';
|
||||
o.placeholder = _('any');
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
o = s.taboption('general', form.ListValue, 'target', _('Action'));
|
||||
o.modalonly = true;
|
||||
o.default = 'ACCEPT';
|
||||
o.value('DROP', _('drop'));
|
||||
o.value('ACCEPT', _('accept'));
|
||||
o.value('REJECT', _('reject'));
|
||||
o.value('NOTRACK', _("don't track"));
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'extra', _('Extra arguments'),
|
||||
_('Passes additional arguments to iptables. Use with care!'));
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('timed', form.MultiValue, 'weekdays', _('Week Days'));
|
||||
o.modalonly = true;
|
||||
o.multiple = true;
|
||||
o.display = 5;
|
||||
o.placeholder = _('Any day');
|
||||
o.value('Sun', _('Sunday'));
|
||||
o.value('Mon', _('Monday'));
|
||||
o.value('Tue', _('Tuesday'));
|
||||
o.value('Wed', _('Wednesday'));
|
||||
o.value('Thu', _('Thursday'));
|
||||
o.value('Fri', _('Friday'));
|
||||
o.value('Sat', _('Saturday'));
|
||||
|
||||
o = s.taboption('timed', form.MultiValue, 'monthdays', _('Month Days'));
|
||||
o.modalonly = true;
|
||||
o.multiple = true;
|
||||
o.display_size = 15;
|
||||
o.placeholder = _('Any day');
|
||||
for (var i = 1; i <= 31; i++)
|
||||
o.value(i);
|
||||
|
||||
o = s.taboption('timed', form.Value, 'start_time', _('Start Time (hh.mm.ss)'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'timehhmmss';
|
||||
|
||||
o = s.taboption('timed', form.Value, 'stop_time', _('Stop Time (hh.mm.ss)'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'timehhmmss';
|
||||
|
||||
o = s.taboption('timed', form.Value, 'start_date', _('Start Date (yyyy-mm-dd)'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'dateyyyymmdd';
|
||||
|
||||
o = s.taboption('timed', form.Value, 'stop_date', _('Stop Date (yyyy-mm-dd)'));
|
||||
o.modalonly = true;
|
||||
o.datatype = 'dateyyyymmdd';
|
||||
|
||||
o = s.taboption('timed', form.Flag, 'utc_time', _('Time in UTC'));
|
||||
o.modalonly = true;
|
||||
o.default = o.disabled;
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,256 @@
|
|||
'use strict';
|
||||
'require ui';
|
||||
'require rpc';
|
||||
'require uci';
|
||||
'require form';
|
||||
'require tools.firewall as fwtool';
|
||||
'require tools.widgets as widgets';
|
||||
|
||||
function fmt(fmt /*, ...*/) {
|
||||
var repl = [], wrap = false;
|
||||
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
if (L.dom.elem(arguments[i])) {
|
||||
switch (arguments[i].nodeType) {
|
||||
case 1:
|
||||
repl.push(arguments[i].outerHTML);
|
||||
wrap = true;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
repl.push(arguments[i].data);
|
||||
break;
|
||||
|
||||
case 11:
|
||||
var span = E('span');
|
||||
span.appendChild(arguments[i]);
|
||||
repl.push(span.innerHTML);
|
||||
wrap = true;
|
||||
break;
|
||||
|
||||
default:
|
||||
repl.push('');
|
||||
}
|
||||
}
|
||||
else {
|
||||
repl.push(arguments[i]);
|
||||
}
|
||||
}
|
||||
|
||||
var rv = fmt.format.apply(fmt, repl);
|
||||
return wrap ? E('span', rv) : rv;
|
||||
}
|
||||
|
||||
function snat_proto_txt(s) {
|
||||
return fmt('%s-%s',
|
||||
fwtool.fmt_family(uci.get('firewall', s, 'family')),
|
||||
fwtool.fmt_proto(uci.get('firewall', s, 'proto'),
|
||||
uci.get('firewall', s, 'icmp_type')) || 'TCP+UDP');
|
||||
}
|
||||
|
||||
function snat_src_txt(s) {
|
||||
var z = fwtool.fmt_zone(uci.get('firewall', s, 'src'), _('any zone')),
|
||||
a = fwtool.fmt_ip(uci.get('firewall', s, 'src_ip'), _('any host')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'src_port')),
|
||||
m = fwtool.fmt_mac(uci.get('firewall', s, 'src_mac'));
|
||||
|
||||
if (p && m)
|
||||
return fmt(_('From %s in %s with source %s and %s'), a, z, p, m);
|
||||
else if (p || m)
|
||||
return fmt(_('From %s in %s with source %s'), a, z, p || m);
|
||||
else
|
||||
return fmt(_('From %s in %s'), a, z);
|
||||
}
|
||||
|
||||
function snat_via_txt(s) {
|
||||
var a = fwtool.fmt_ip(uci.get('firewall', s, 'src_dip'), _('any router IP')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'src_dport'));
|
||||
|
||||
if (p)
|
||||
return fmt(_('Via %s at %s'), a, p);
|
||||
else
|
||||
return fmt(_('Via %s'), a);
|
||||
}
|
||||
|
||||
return L.view.extend({
|
||||
callHostHints: rpc.declare({
|
||||
object: 'luci-rpc',
|
||||
method: 'getHostHints',
|
||||
expect: { '': {} }
|
||||
}),
|
||||
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
this.callHostHints()
|
||||
]);
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
var hosts = data[0],
|
||||
m, s, o;
|
||||
|
||||
m = new form.Map('firewall', _('Firewall - Source NAT'),
|
||||
_('Source NAT is a specific form of masquerading which allows fine grained control over the source IP used for outgoing traffic, for example to map multiple WAN addresses to internal subnets.'));
|
||||
|
||||
s = m.section(form.GridSection, 'snat', _('Port SNAT'));
|
||||
s.addremove = true;
|
||||
s.anonymous = true;
|
||||
s.sortable = true;
|
||||
|
||||
s.tab('general', _('General Settings'));
|
||||
s.tab('advanced', _('Advanced Settings'));
|
||||
|
||||
s.filter = function(section_id) {
|
||||
return (uci.get('firewall', section_id, 'target') != 'DNAT');
|
||||
};
|
||||
|
||||
s.sectiontitle = function(section_id) {
|
||||
return uci.get('firewall', section_id, 'name') || _('Unnamed snat');
|
||||
};
|
||||
|
||||
s.handleAdd = function(ev) {
|
||||
var config_name = this.uciconfig || this.map.config,
|
||||
section_id = uci.add(config_name, this.sectiontype);
|
||||
|
||||
uci.set(config_name, section_id, 'target', 'SNAT');
|
||||
|
||||
this.addedSection = section_id;
|
||||
this.renderMoreOptionsModal(section_id);
|
||||
};
|
||||
|
||||
o = s.taboption('general', form.Value, 'name', _('Name'));
|
||||
o.placeholder = _('Unnamed snat');
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.option(form.DummyValue, '_match', _('Match'));
|
||||
o.modalonly = false;
|
||||
o.textvalue = function(s) {
|
||||
return E('small', [
|
||||
snat_proto_txt(s), E('br'),
|
||||
snat_src_txt(s), E('br'),
|
||||
snat_via_txt(s)
|
||||
]);
|
||||
};
|
||||
|
||||
o = s.option(form.ListValue, '_dest', _('snat to'));
|
||||
o.modalonly = false;
|
||||
o.textvalue = function(s) {
|
||||
var z = fwtool.fmt_zone(uci.get('firewall', s, 'dest'), _('any zone')),
|
||||
a = fwtool.fmt_ip(uci.get('firewall', s, 'dest_ip'), _('any host')),
|
||||
p = fwtool.fmt_port(uci.get('firewall', s, 'dest_port')) ||
|
||||
fwtool.fmt_port(uci.get('firewall', s, 'src_dport'));
|
||||
|
||||
if (p)
|
||||
return fmt(_('%s, %s in %s'), a, p, z);
|
||||
else
|
||||
return fmt(_('%s in %s'), a, z);
|
||||
};
|
||||
|
||||
o = s.option(form.Flag, 'enabled', _('Enable'));
|
||||
o.modalonly = false;
|
||||
o.default = o.enabled;
|
||||
o.editable = true;
|
||||
|
||||
o = s.taboption('general', form.Value, 'proto', _('Protocol'));
|
||||
o.modalonly = true;
|
||||
o.default = 'tcp udp';
|
||||
o.value('tcp udp', 'TCP+UDP');
|
||||
o.value('tcp', 'TCP');
|
||||
o.value('udp', 'UDP');
|
||||
o.value('icmp', 'ICMP');
|
||||
|
||||
o.cfgvalue = function(/* ... */) {
|
||||
var v = this.super('cfgvalue', arguments);
|
||||
return (v == 'tcpudp') ? 'tcp udp' : v;
|
||||
};
|
||||
|
||||
o = s.taboption('general', widgets.ZoneSelect, 'src', _('Source zone'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.nocreate = true;
|
||||
o.default = 'wan';
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'src_ip', _('Source IP address'),
|
||||
_('Only match incoming traffic from this IP or range.'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'neg(ipmask4)';
|
||||
o.placeholder = E('em', _('any'));
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'src_port', _('Source port'),
|
||||
_('Only match incoming traffic originating from the given source port or port range on the client host'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'neg(portrange)';
|
||||
o.placeholder = _('any');
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
o = s.taboption('general', widgets.ZoneSelect, 'dest', _('Destination zone'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.nocreate = true;
|
||||
o.default = 'lan';
|
||||
|
||||
o = s.taboption('general', form.Value, 'dest_ip', _('Destination IP address'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'ipmask4';
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('general', form.Value, 'dest_port', _('Destination port'),
|
||||
_('Match forwarded traffic to the given destination or port range'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.placeholder = _('any');
|
||||
o.datatype = 'portrange';
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
o = s.taboption('general', form.Value, 'src_dip', _('SNAT IP address'),
|
||||
_('Rewrite matched traffic to the given address'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.datatype = 'ipmask4';
|
||||
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
|
||||
o.value(hosts[mac].ipv4, '%s (%s)'.format(
|
||||
hosts[mac].ipv4,
|
||||
hosts[mac].name || mac
|
||||
));
|
||||
});
|
||||
|
||||
o = s.taboption('general', form.Value, 'src_dport', _('SNAT port'),
|
||||
_('Rewrite matched traffic to the given source port. May be left empty to only rewrite the IP address'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
o.placeholder = _('Do not rewrite');
|
||||
o.datatype = 'portrange';
|
||||
o.depends('proto', 'tcp');
|
||||
o.depends('proto', 'udp');
|
||||
o.depends('proto', 'tcp udp');
|
||||
o.depends('proto', 'tcpudp');
|
||||
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'extra', _('Extra arguments'),
|
||||
_('Passes additional arguments to iptables. Use with care!'));
|
||||
o.modalonly = true;
|
||||
o.rmempty = true;
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
|
@ -0,0 +1,318 @@
|
|||
'use strict';
|
||||
'require rpc';
|
||||
'require uci';
|
||||
'require form';
|
||||
'require network';
|
||||
'require firewall';
|
||||
'require tools.widgets as widgets';
|
||||
|
||||
return L.view.extend({
|
||||
callConntrackHelpers: rpc.declare({
|
||||
object: 'luci',
|
||||
method: 'getConntrackHelpers',
|
||||
expect: { result: [] }
|
||||
}),
|
||||
|
||||
load: function() {
|
||||
return Promise.all([
|
||||
this.callConntrackHelpers(),
|
||||
firewall.getDefaults()
|
||||
]);
|
||||
},
|
||||
|
||||
render: function(data) {
|
||||
var ctHelpers = data[0],
|
||||
fwDefaults = data[1],
|
||||
m, s, o, inp, out;
|
||||
|
||||
m = new form.Map('firewall', _('Firewall - Zone Settings'),
|
||||
_('The firewall creates zones over your network interfaces to control network traffic flow.'));
|
||||
|
||||
s = m.section(form.TypedSection, 'defaults', _('General Settings'));
|
||||
s.anonymous = true;
|
||||
s.addremove = false;
|
||||
|
||||
o = s.option(form.Flag, 'syn_flood', _('Enable SYN-flood protection'));
|
||||
o = s.option(form.Flag, 'drop_invalid', _('Drop invalid packets'));
|
||||
|
||||
var p = [
|
||||
s.option(form.ListValue, 'input', _('Input')),
|
||||
s.option(form.ListValue, 'output', _('Output')),
|
||||
s.option(form.ListValue, 'forward', _('Forward'))
|
||||
];
|
||||
|
||||
for (var i = 0; i < p.length; i++) {
|
||||
p[i].value('REJECT', _('reject'));
|
||||
p[i].value('DROP', _('drop'));
|
||||
p[i].value('ACCEPT', _('accept'));
|
||||
}
|
||||
|
||||
/* Netfilter flow offload support */
|
||||
|
||||
if (L.hasSystemFeature('offloading')) {
|
||||
s = m.section(form.TypedSection, 'defaults', _('Routing/NAT Offloading'),
|
||||
_('Experimental feature. Not fully compatible with QoS/SQM.'));
|
||||
|
||||
s.anonymous = true;
|
||||
s.addremove = false;
|
||||
|
||||
o = s.option(form.Flag, 'flow_offloading',
|
||||
_('Software flow offloading'),
|
||||
_('Software based offloading for routing/NAT'));
|
||||
o.optional = true;
|
||||
|
||||
o = s.option(form.Flag, 'flow_offloading_hw',
|
||||
_('Hardware flow offloading'),
|
||||
_('Requires hardware NAT support. Implemented at least for mt7621'));
|
||||
o.optional = true;
|
||||
o.depends('flow_offloading', '1');
|
||||
}
|
||||
|
||||
|
||||
s = m.section(form.GridSection, 'zone', _('Zones'));
|
||||
s.addremove = true;
|
||||
s.anonymous = true;
|
||||
s.sortable = true;
|
||||
|
||||
s.tab('general', _('General Settings'));
|
||||
s.tab('advanced', _('Advanced Settings'));
|
||||
s.tab('conntrack', _('Conntrack Settings'));
|
||||
s.tab('extra', _('Extra iptables arguments'));
|
||||
|
||||
o = s.taboption('general', form.DummyValue, '_generalinfo');
|
||||
o.rawhtml = true;
|
||||
o.modalonly = true;
|
||||
o.cfgvalue = function(section_id) {
|
||||
var name = uci.get('firewall', section_id, 'name');
|
||||
if (name == null)
|
||||
name = _("this new zone");
|
||||
return _('This section defines common properties of %q. The <em>input</em> and <em>output</em> options set the default policies for traffic entering and leaving this zone while the <em>forward</em> option describes the policy for forwarded traffic between different networks within the zone. <em>Covered networks</em> specifies which available networks are members of this zone.')
|
||||
.replace(/%s/g, name).replace(/%q/g, '"' + name + '"');
|
||||
};
|
||||
|
||||
o = s.taboption('general', form.Value, 'name', _('Name'));
|
||||
o.placeholder = _('Unnamed zone');
|
||||
o.modalonly = true;
|
||||
o.rmempty = false;
|
||||
o.datatype = 'and(uciname,maxlength(11))';
|
||||
o.write = function(section_id, formvalue) {
|
||||
var cfgvalue = this.cfgvalue(section_id);
|
||||
|
||||
if (cfgvalue == null || cfgvalue == '')
|
||||
return uci.set('firewall', section_id, 'name', formvalue);
|
||||
else if (cfgvalue != formvalue)
|
||||
return firewall.renameZone(cfgvalue, formvalue);
|
||||
};
|
||||
|
||||
o = s.option(widgets.ZoneForwards, '_info', _('Zone ⇒ Forwardings'));
|
||||
o.editable = true;
|
||||
o.modalonly = false;
|
||||
o.cfgvalue = function(section_id) {
|
||||
return uci.get('firewall', section_id, 'name');
|
||||
};
|
||||
|
||||
var p = [
|
||||
s.taboption('general', form.ListValue, 'input', _('Input')),
|
||||
s.taboption('general', form.ListValue, 'output', _('Output')),
|
||||
s.taboption('general', form.ListValue, 'forward', _('Forward'))
|
||||
];
|
||||
|
||||
for (var i = 0; i < p.length; i++) {
|
||||
p[i].value('REJECT', _('reject'));
|
||||
p[i].value('DROP', _('drop'));
|
||||
p[i].value('ACCEPT', _('accept'));
|
||||
p[i].editable = true;
|
||||
}
|
||||
|
||||
p[0].default = fwDefaults.getInput();
|
||||
p[1].default = fwDefaults.getOutput();
|
||||
p[2].default = fwDefaults.getForward();
|
||||
|
||||
o = s.taboption('general', form.Flag, 'masq', _('Masquerading'));
|
||||
o.editable = true;
|
||||
|
||||
o = s.taboption('general', form.Flag, 'mtu_fix', _('MSS clamping'));
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('general', widgets.NetworkSelect, 'network', _('Covered networks'));
|
||||
o.modalonly = true;
|
||||
o.multiple = true;
|
||||
o.write = function(section_id, formvalue) {
|
||||
var name = uci.get('firewall', section_id, 'name'),
|
||||
cfgvalue = this.cfgvalue(section_id);
|
||||
|
||||
if (typeof(cfgvalue) == 'string' && Array.isArray(formvalue) && (cfgvalue == formvalue.join(' ')))
|
||||
return;
|
||||
|
||||
var tasks = [ firewall.getZone(name) ];
|
||||
|
||||
if (Array.isArray(formvalue))
|
||||
for (var i = 0; i < formvalue.length; i++) {
|
||||
var netname = formvalue[i];
|
||||
tasks.push(network.getNetwork(netname).then(function(net) {
|
||||
return net || network.addNetwork(netname, { 'proto': 'none' });
|
||||
}));
|
||||
}
|
||||
|
||||
return Promise.all(tasks).then(function(zone_networks) {
|
||||
if (zone_networks[0])
|
||||
for (var i = 1; i < zone_networks.length; i++)
|
||||
zone_networks[0].addNetwork(zone_networks[i].getName());
|
||||
});
|
||||
};
|
||||
o.remove = function(section_id) {
|
||||
return uci.set('firewall', section_id, 'network', ' ');
|
||||
};
|
||||
|
||||
o = s.taboption('advanced', form.DummyValue, '_advancedinfo');
|
||||
o.rawhtml = true;
|
||||
o.modalonly = true;
|
||||
o.cfgvalue = function(section_id) {
|
||||
var name = uci.get('firewall', section_id, 'name');
|
||||
if (name == null)
|
||||
name = _("this new zone");
|
||||
return _('The options below control the forwarding policies between this zone (%s) and other zones. <em>Destination zones</em> cover forwarded traffic <strong>originating from %q</strong>. <em>Source zones</em> match forwarded traffic from other zones <strong>targeted at %q</strong>. The forwarding rule is <em>unidirectional</em>, e.g. a forward from lan to wan does <em>not</em> imply a permission to forward from wan to lan as well.')
|
||||
.format(name);
|
||||
};
|
||||
|
||||
o = s.taboption('advanced', widgets.DeviceSelect, 'device', _('Covered devices'), _('Use this option to classify zone traffic by raw, non-<em>uci</em> managed network devices.'));
|
||||
o.modalonly = true;
|
||||
o.noaliases = true;
|
||||
o.multiple = true;
|
||||
|
||||
o = s.taboption('advanced', form.DynamicList, 'subnet', _('Covered subnets'), _('Use this option to classify zone traffic by source or destination subnet instead of networks or devices.'));
|
||||
o.datatype = 'neg(cidr)';
|
||||
o.modalonly = true;
|
||||
o.multiple = true;
|
||||
|
||||
o = s.taboption('advanced', form.ListValue, 'family', _('Restrict to address family'));
|
||||
o.value('', _('IPv4 and IPv6'));
|
||||
o.value('ipv4', _('IPv4 only'));
|
||||
o.value('ipv6', _('IPv6 only'));
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('advanced', form.DynamicList, 'masq_src', _('Restrict Masquerading to given source subnets'));
|
||||
o.depends('family', '');
|
||||
o.depends('family', 'ipv4');
|
||||
o.datatype = 'list(neg(or(uciname,hostname,ipmask4)))';
|
||||
o.placeholder = '0.0.0.0/0';
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('advanced', form.DynamicList, 'masq_dest', _('Restrict Masquerading to given destination subnets'));
|
||||
o.depends('family', '');
|
||||
o.depends('family', 'ipv4');
|
||||
o.datatype = 'list(neg(or(uciname,hostname,ipmask4)))';
|
||||
o.placeholder = '0.0.0.0/0';
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('conntrack', form.Flag, 'masq_allow_invalid', _('Allow "invalid" traffic'), _('Do not install extra rules to reject forwarded traffic with conntrack state <em>invalid</em>. This may be required for complex asymmetric route setups.'));
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('conntrack', form.Flag, 'auto_helper', _('Automatic helper assignment'), _('Automatically assign conntrack helpers based on traffic protocol and port'));
|
||||
o.default = o.enabled;
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('conntrack', form.MultiValue, 'helper', _('Conntrack helpers'), _('Explicitly choses allowed connection tracking helpers for zone traffic'));
|
||||
o.depends('auto_helper', '0');
|
||||
o.modalonly = true;
|
||||
for (var i = 0; i < ctHelpers.length; i++)
|
||||
o.value(ctHelpers[i].name, '<span class="hide-close">%s (%s)</span><span class="hide-open">%s</span>'.format(ctHelpers[i].description, ctHelpers[i].name.toUpperCase(), ctHelpers[i].name.toUpperCase()));
|
||||
|
||||
o = s.taboption('advanced', form.Flag, 'log', _('Enable logging on this zone'));
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('advanced', form.Value, 'log_limit', _('Limit log messages'));
|
||||
o.depends('log', '1');
|
||||
o.placeholder = '10/minute';
|
||||
o.modalonly = true;
|
||||
|
||||
o = s.taboption('extra', form.DummyValue, '_extrainfo');
|
||||
o.rawhtml = true;
|
||||
o.modalonly = true;
|
||||
o.cfgvalue = function(section_id) {
|
||||
return _('Passing raw iptables arguments to source and destination traffic classification rules allows to match packets based on other criteria than interfaces or subnets. These options should be used with extreme care as invalid values could render the firewall ruleset broken, completely exposing all services.');
|
||||
};
|
||||
|
||||
o = s.taboption('extra', form.Value, 'extra_src', _('Extra source arguments'), _('Additional raw <em>iptables</em> arguments to classify zone source traffic, e.g. <code>-p tcp --sport 443</code> to only match inbound HTTPS traffic.'));
|
||||
o.modalonly = true;
|
||||
o.cfgvalue = function(section_id) {
|
||||
return uci.get('firewall', section_id, 'extra_src') || uci.get('firewall', section_id, 'extra');
|
||||
};
|
||||
o.write = function(section_id, value) {
|
||||
uci.unset('firewall', section_id, 'extra');
|
||||
uci.set('firewall', section_id, 'extra_src', value);
|
||||
};
|
||||
|
||||
o = s.taboption('extra', form.Value, 'extra_dest', _('Extra destination arguments'), _('Additional raw <em>iptables</em> arguments to classify zone destination traffic, e.g. <code>-p tcp --dport 443</code> to only match outbound HTTPS traffic.'));
|
||||
o.modalonly = true;
|
||||
o.cfgvalue = function(section_id) {
|
||||
return uci.get('firewall', section_id, 'extra_dest') || uci.get('firewall', section_id, 'extra_src') || uci.get('firewall', section_id, 'extra');
|
||||
};
|
||||
o.write = function(section_id, value) {
|
||||
uci.unset('firewall', section_id, 'extra');
|
||||
uci.set('firewall', section_id, 'extra_dest', value);
|
||||
};
|
||||
|
||||
o = s.taboption('general', form.DummyValue, '_forwardinfo');
|
||||
o.rawhtml = true;
|
||||
o.modalonly = true;
|
||||
o.cfgvalue = function(section_id) {
|
||||
var name = uci.get('firewall', section_id, 'name');
|
||||
if (name == null)
|
||||
name = _("this new zone");
|
||||
return _('The options below control the forwarding policies between this zone (%s) and other zones. <em>Destination zones</em> cover forwarded traffic <strong>originating from %q</strong>. <em>Source zones</em> match forwarded traffic from other zones <strong>targeted at %q</strong>. The forwarding rule is <em>unidirectional</em>, e.g. a forward from lan to wan does <em>not</em> imply a permission to forward from wan to lan as well.')
|
||||
.format(name);
|
||||
};
|
||||
|
||||
out = o = s.taboption('general', widgets.ZoneSelect, 'out', _('Allow forward to <em>destination zones</em>:'));
|
||||
o.nocreate = true;
|
||||
o.multiple = true;
|
||||
o.modalonly = true;
|
||||
o.filter = function(section_id, value) {
|
||||
return (uci.get('firewall', section_id, 'name') != value);
|
||||
};
|
||||
o.cfgvalue = function(section_id) {
|
||||
var out = (this.option == 'out'),
|
||||
zone = this.lookupZone(uci.get('firewall', section_id, 'name')),
|
||||
fwds = zone ? zone.getForwardingsBy(out ? 'src' : 'dest') : [],
|
||||
value = [];
|
||||
|
||||
for (var i = 0; i < fwds.length; i++)
|
||||
value.push(out ? fwds[i].getDestination() : fwds[i].getSource());
|
||||
|
||||
return value;
|
||||
};
|
||||
o.write = o.remove = function(section_id, formvalue) {
|
||||
var out = (this.option == 'out'),
|
||||
zone = this.lookupZone(uci.get('firewall', section_id, 'name')),
|
||||
fwds = zone ? zone.getForwardingsBy(out ? 'src' : 'dest') : [];
|
||||
|
||||
if (formvalue == null)
|
||||
formvalue = [];
|
||||
|
||||
if (Array.isArray(formvalue)) {
|
||||
for (var i = 0; i < fwds.length; i++) {
|
||||
var cmp = out ? fwds[i].getDestination() : fwds[i].getSource();
|
||||
if (!formvalue.filter(function(d) { return d == cmp }).length)
|
||||
zone.deleteForwarding(fwds[i]);
|
||||
}
|
||||
|
||||
for (var i = 0; i < formvalue.length; i++)
|
||||
if (out)
|
||||
zone.addForwardingTo(formvalue[i]);
|
||||
else
|
||||
zone.addForwardingFrom(formvalue[i]);
|
||||
}
|
||||
};
|
||||
|
||||
inp = o = s.taboption('general', widgets.ZoneSelect, 'in', _('Allow forward from <em>source zones</em>:'));
|
||||
o.nocreate = true;
|
||||
o.multiple = true;
|
||||
o.modalonly = true;
|
||||
o.write = o.remove = out.write;
|
||||
o.filter = out.filter;
|
||||
o.cfgvalue = out.cfgvalue;
|
||||
|
||||
return m.render();
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue