Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync #579

Merged
merged 4 commits into from
Dec 11, 2024
Merged

sync #579

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions luci-app-firewall/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

include $(TOPDIR)/rules.mk

LUCI_TITLE:=Firewall and Portforwarding application
LUCI_DEPENDS:=+@LINUX_5_4:firewall +@(LINUX_5_15||LINUX_6_1||LINUX_6_6||LINUX_6_7):uci-firewall
LUCI_TITLE:=Firewall and port forwarding application
LUCI_DEPENDS:=+luci-base +uci-firewall

PKG_LICENSE:=Apache-2.0
#PKG_VERSION:=omr-202103
PKG_MAINTAINER:=Jo-Philipp Wich <[email protected]>

include $(TOPDIR)/feeds/luci/luci.mk

Expand Down
82 changes: 65 additions & 17 deletions luci-app-firewall/htdocs/luci-static/resources/tools/firewall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'require form';
'require network';
'require firewall';
'require validation';
'require tools.prng as random';

var protocols = [
Expand Down Expand Up @@ -392,22 +393,35 @@ return baseclass.extend({
},

transformHostHints: function(family, hosts) {
var choice_values = [], choice_labels = {};
var choice_values = [],
choice_labels = {},
ip6addrs = {},
ipaddrs = {};

for (var mac in hosts) {
L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4).forEach(function(ip) {
ipaddrs[ip] = mac;
});

L.toArray(hosts[mac].ip6addrs || hosts[mac].ipv6).forEach(function(ip) {
ip6addrs[ip] = mac;
});
}

if (!family || family == 'ipv4') {
L.sortedKeys(hosts, 'ipv4', 'addr').forEach(function(mac) {
var val = hosts[mac].ipv4,
txt = hosts[mac].name || mac;
L.sortedKeys(ipaddrs, null, 'addr').forEach(function(ip) {
var val = ip,
txt = hosts[ipaddrs[ip]].name || ipaddrs[ip];

choice_values.push(val);
choice_labels[val] = E([], [ val, ' (', E('strong', {}, [txt]), ')' ]);
});
}

if (!family || family == 'ipv6') {
L.sortedKeys(hosts, 'ipv6', 'addr').forEach(function(mac) {
var val = hosts[mac].ipv6,
txt = hosts[mac].name || mac;
L.sortedKeys(ip6addrs, null, 'addr').forEach(function(ip) {
var val = ip,
txt = hosts[ip6addrs[ip]].name || ip6addrs[ip];

choice_values.push(val);
choice_labels[val] = E([], [ val, ' (', E('strong', {}, [txt]), ')' ]);
Expand All @@ -425,11 +439,27 @@ return baseclass.extend({
opt.addChoices(choices[0], choices[1]);
},

CBIDynamicMultiValueList: form.DynamicList.extend({
renderWidget: function(/* ... */) {
var dl = form.DynamicList.prototype.renderWidget.apply(this, arguments),
inst = dom.findClassInstance(dl);

inst.addItem = function(dl, value, text, flash) {
var values = L.toArray(value);
for (var i = 0; i < values.length; i++)
ui.DynamicList.prototype.addItem.call(this, dl, values[i], null, true);
};

return dl;
}
}),

addIPOption: function(s, tab, name, label, description, family, hosts, multiple) {
var o = s.taboption(tab, multiple ? form.DynamicList : form.Value, name, label, description);
var o = s.taboption(tab, multiple ? this.CBIDynamicMultiValueList : form.Value, name, label, description);
var fw4 = L.hasSystemFeature('firewall4');

o.modalonly = true;
o.datatype = 'list(neg(ipmask))';
o.datatype = (fw4 && validation.types.iprange) ? 'list(neg(or(ipmask("true"),iprange)))' : 'list(neg(ipmask("true")))';
o.placeholder = multiple ? _('-- add IP --') : _('any');

if (family != null) {
Expand All @@ -449,40 +479,53 @@ return baseclass.extend({

addLocalIPOption: function(s, tab, name, label, description, devices) {
var o = s.taboption(tab, form.Value, name, label, description);
var fw4 = L.hasSystemFeature('firewall4');

o.modalonly = true;
o.datatype = 'ip4addr("nomask")';
o.datatype = !fw4?'ip4addr("nomask")':'ipaddr("nomask")';
o.placeholder = _('any');

L.sortedKeys(devices, 'name').forEach(function(dev) {
var ip4addrs = devices[dev].ipaddrs;
var ip6addrs = devices[dev].ip6addrs;

if (!L.isObject(devices[dev].flags) || !Array.isArray(ip4addrs) || devices[dev].flags.loopback)
if (!L.isObject(devices[dev].flags) || devices[dev].flags.loopback)
return;

for (var i = 0; i < ip4addrs.length; i++) {
for (var i = 0; Array.isArray(ip4addrs) && i < ip4addrs.length; i++) {
if (!L.isObject(ip4addrs[i]) || !ip4addrs[i].address)
continue;

o.value(ip4addrs[i].address, E([], [
ip4addrs[i].address, ' (', E('strong', {}, [dev]), ')'
]));
}
for (var i = 0; fw4 && Array.isArray(ip6addrs) && i < ip6addrs.length; i++) {
if (!L.isObject(ip6addrs[i]) || !ip6addrs[i].address)
continue;

o.value(ip6addrs[i].address, E([], [
ip6addrs[i].address, ' (', E('strong', {}, [dev]), ')'
]));
}
});

return o;
},

addMACOption: function(s, tab, name, label, description, hosts) {
var o = s.taboption(tab, form.DynamicList, name, label, description);
var o = s.taboption(tab, this.CBIDynamicMultiValueList, name, label, description);

o.modalonly = true;
o.datatype = 'list(macaddr)';
o.placeholder = _('-- add MAC --');

L.sortedKeys(hosts).forEach(function(mac) {
o.value(mac, E([], [ mac, ' (', E('strong', {}, [
hosts[mac].name || hosts[mac].ipv4 || hosts[mac].ipv6 || '?'
hosts[mac].name ||
L.toArray(hosts[mac].ipaddrs || hosts[mac].ipv4)[0] ||
L.toArray(hosts[mac].ip6addrs || hosts[mac].ipv6)[0] ||
'?'
]), ')' ]));
});

Expand Down Expand Up @@ -522,6 +565,9 @@ return baseclass.extend({
}
}, this));

if (cfgvalue == '*' || cfgvalue == 'any' || cfgvalue == 'all')
cfgvalue = 'all';

return cfgvalue;
},

Expand All @@ -537,6 +583,7 @@ return baseclass.extend({
display_items: 10,
dropdown_items: -1,
create: true,
disabled: (this.readonly != null) ? this.readonly : this.map.readonly,
validate: function(value) {
var v = L.toArray(value);

Expand All @@ -555,8 +602,7 @@ return baseclass.extend({
});

widget.createChoiceElement = function(sb, value) {
var m = value.match(/^(0x[0-9a-f]{1,2}|[0-9]{1,3})$/),
p = lookupProto(lookupProto(m ? +m[1] : value)[0]);
var p = lookupProto(value);

return ui.Dropdown.prototype.createChoiceElement.call(this, sb, p[2], p[1]);
};
Expand All @@ -566,9 +612,11 @@ return baseclass.extend({
var m = value.match(/^(0x[0-9a-f]{1,2}|[0-9]{1,3})$/),
p = lookupProto(m ? +m[1] : value);

return (p[0] > -1) ? p[2] : value;
return (p[0] > -1) ? p[2] : p[1];
});

values.sort();

return ui.Dropdown.prototype.createItems.call(this, sb, values.join(' '));
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ return view.extend({
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 : '' ]))
E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 25 }, [ fwuser != null ? fwuser : '' ]))
]);
},

Expand Down
Loading