luci-app-firewall: honour global default policies in per-zone settings

Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
Jo-Philipp Wich 2019-08-14 17:07:55 +02:00
parent 7610f1d9cf
commit ed8f1c4c1c
10 changed files with 99 additions and 81 deletions

View file

@ -75,7 +75,8 @@ function forward_via_txt(s) {
return L.view.extend({ return L.view.extend({
callHostHints: rpc.declare({ callHostHints: rpc.declare({
object: 'luci', object: 'luci',
method: 'host_hints' method: 'getHostHints',
expect: { '': {} }
}), }),
load: function() { load: function() {

View file

@ -112,7 +112,8 @@ function rule_target_txt(s) {
return L.view.extend({ return L.view.extend({
callHostHints: rpc.declare({ callHostHints: rpc.declare({
object: 'luci', object: 'luci',
method: 'host_hints' method: 'getHostHints',
expect: { '': {} }
}), }),
load: function() { load: function() {

View file

@ -15,12 +15,14 @@ return L.view.extend({
load: function() { load: function() {
return Promise.all([ return Promise.all([
this.callConntrackHelpers() this.callConntrackHelpers(),
firewall.getDefaults()
]); ]);
}, },
render: function(data) { render: function(data) {
var ctHelpers = data[0], var ctHelpers = data[0],
fwDefaults = data[1],
m, s, o, inp, out; m, s, o, inp, out;
m = new form.Map('firewall', _('Firewall - Zone Settings'), m = new form.Map('firewall', _('Firewall - Zone Settings'),
@ -118,6 +120,10 @@ return L.view.extend({
p[i].editable = true; 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 = s.taboption('general', form.Flag, 'masq', _('Masquerading'));
o.editable = true; o.editable = true;

View file

@ -51,18 +51,19 @@ var callNetworkWirelessStatus = rpc.declare({
var callLuciNetdevs = rpc.declare({ var callLuciNetdevs = rpc.declare({
object: 'luci', object: 'luci',
method: 'netdevs' method: 'getNetworkDevices',
expect: { '': {} }
}); });
var callLuciIfaddrs = rpc.declare({ var callLuciIfaddrs = rpc.declare({
object: 'luci', object: 'luci',
method: 'ifaddrs', method: 'getIfaddrs',
expect: { result: [] } expect: { result: [] }
}); });
var callLuciBoardjson = rpc.declare({ var callLuciBoardjson = rpc.declare({
object: 'luci', object: 'luci',
method: 'boardjson' method: 'getBoardJSON'
}); });
var callIwinfoInfo = rpc.declare({ var callIwinfoInfo = rpc.declare({

View file

@ -9,7 +9,7 @@ local function readfile(path)
end end
local methods = { local methods = {
initList = { getInitList = {
args = { name = "name" }, args = { name = "name" },
call = function(args) call = function(args)
local sys = require "luci.sys" local sys = require "luci.sys"
@ -22,11 +22,11 @@ local methods = {
return { error = "No such init script" } return { error = "No such init script" }
end end
end end
return { result = scripts } return scripts
end end
}, },
initCall = { setInitAction = {
args = { name = "name", action = "action" }, args = { name = "name", action = "action" },
call = function(args) call = function(args)
local sys = require "luci.sys" local sys = require "luci.sys"
@ -39,7 +39,7 @@ local methods = {
getLocaltime = { getLocaltime = {
call = function(args) call = function(args)
return { localtime = os.time() } return { result = os.time() }
end end
}, },
@ -52,11 +52,11 @@ local methods = {
sys.call("date -s '%04d-%02d-%02d %02d:%02d:%02d' >/dev/null" %{ date.year, date.month, date.day, date.hour, date.min, date.sec }) sys.call("date -s '%04d-%02d-%02d %02d:%02d:%02d' >/dev/null" %{ date.year, date.month, date.day, date.hour, date.min, date.sec })
sys.call("/etc/init.d/sysfixtime restart >/dev/null") sys.call("/etc/init.d/sysfixtime restart >/dev/null")
end end
return { localtime = args.localtime } return { result = args.localtime }
end end
}, },
timezone = { getTimezones = {
call = function(args) call = function(args)
local util = require "luci.util" local util = require "luci.util"
local zones = require "luci.sys.zoneinfo" local zones = require "luci.sys.zoneinfo"
@ -76,11 +76,11 @@ local methods = {
active = (res and res.value == zone[1]) and true or nil active = (res and res.value == zone[1]) and true or nil
} }
end end
return { result = result } return result
end end
}, },
leds = { getLEDs = {
call = function() call = function()
local iter = fs.dir("/sys/class/leds") local iter = fs.dir("/sys/class/leds")
local result = { } local result = { }
@ -115,7 +115,7 @@ local methods = {
end end
}, },
usb = { getUSBDevices = {
call = function() call = function()
local fs = require "nixio.fs" local fs = require "nixio.fs"
local iter = fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer") local iter = fs.glob("/sys/bus/usb/devices/[0-9]*/manufacturer")
@ -126,7 +126,7 @@ local methods = {
local p local p
for p in iter do for p in iter do
local id = p:match("%d+-%d+") local id = p:match("/([^/]+)/manufacturer$")
result.devices[#result.devices+1] = { result.devices[#result.devices+1] = {
id = id, id = id,
@ -139,18 +139,19 @@ local methods = {
end end
end end
iter = fs.glob("/sys/bus/usb/devices/*/usb[0-9]*-port[0-9]*") iter = fs.glob("/sys/bus/usb/devices/*/*-port[0-9]*")
if iter then if iter then
result.ports = {} result.ports = {}
local p local p
for p in iter do for p in iter do
local bus, port = p:match("usb(%d+)-port(%d+)") local port = p:match("([^/]+)$")
local link = fs.readlink(p.."/device")
result.ports[#result.ports+1] = { result.ports[#result.ports+1] = {
hub = tonumber(bus), port = port,
port = tonumber(port) device = link and fs.basename(link)
} }
end end
end end
@ -159,20 +160,20 @@ local methods = {
end end
}, },
ifaddrs = { getIfaddrs = {
call = function() call = function()
return { result = nixio.getifaddrs() } return { result = nixio.getifaddrs() }
end end
}, },
host_hints = { getHostHints = {
call = function() call = function()
local sys = require "luci.sys" local sys = require "luci.sys"
return sys.net.host_hints() return sys.net.host_hints()
end end
}, },
duid_hints = { getDUIDHints = {
call = function() call = function()
local fp = io.open('/var/hosts/odhcpd') local fp = io.open('/var/hosts/odhcpd')
local result = { } local result = { }
@ -192,7 +193,7 @@ local methods = {
end end
}, },
leases = { getDHCPLeases = {
args = { family = 0 }, args = { family = 0 },
call = function(args) call = function(args)
local s = require "luci.tools.status" local s = require "luci.tools.status"
@ -210,7 +211,7 @@ local methods = {
end end
}, },
netdevs = { getNetworkDevices = {
call = function(args) call = function(args)
local dir = fs.dir("/sys/class/net") local dir = fs.dir("/sys/class/net")
local result = { } local result = { }
@ -273,21 +274,23 @@ local methods = {
end end
}, },
boardjson = { getBoardJSON = {
call = function(args) call = function(args)
local jsc = require "luci.jsonc" local jsc = require "luci.jsonc"
return jsc.parse(fs.readfile("/etc/board.json") or "") return jsc.parse(fs.readfile("/etc/board.json") or "")
end end
}, },
conntrack_helpers = { getConntrackHelpers = {
call = function() call = function()
local fd = io.open("/usr/share/fw3/helpers.conf", "r") local ok, fd = pcall(io.open, "/usr/share/fw3/helpers.conf", "r")
local rv = {} local rv = {}
local line, entry if ok then
local entry
while true do while true do
line = fd:read("*l") local line = fd:read("*l")
if not line then if not line then
break break
end end
@ -311,7 +314,10 @@ local methods = {
rv[#rv+1] = entry rv[#rv+1] = entry
end end
return { helpers = rv } fd:close()
end
return { result = rv }
end end
}, },

View file

@ -22,7 +22,7 @@
"read": { "read": {
"ubus": { "ubus": {
"iwinfo": [ "info" ], "iwinfo": [ "info" ],
"luci": [ "boardjson", "duid_hints", "host_hints", "ifaddrs", "initList", "getLocaltime", "leases", "leds", "netdevs", "usb" ], "luci": [ "getBoardJSON", "getDUIDHints", "getHostHints", "getIfaddrs", "getInitList", "getLocaltime", "getTimezones", "getDHCPLeases", "getLEDs", "getNetworkDevices", "getUSBDevices" ],
"network.device": [ "status" ], "network.device": [ "status" ],
"network.interface": [ "dump" ], "network.interface": [ "dump" ],
"network.wireless": [ "status" ], "network.wireless": [ "status" ],
@ -33,7 +33,7 @@
}, },
"write": { "write": {
"ubus": { "ubus": {
"luci": [ "initCall", "setLocaltime", "timezone" ], "luci": [ "setInitAction", "setLocaltime" ],
"uci": [ "add", "apply", "confirm", "delete", "order", "set" ] "uci": [ "add", "apply", "confirm", "delete", "order", "set" ]
}, },
"uci": [ "*" ] "uci": [ "*" ]
@ -43,7 +43,7 @@
"description": "Grant access to firewall procedures", "description": "Grant access to firewall procedures",
"read": { "read": {
"ubus": { "ubus": {
"luci": [ "conntrack_helpers" ] "luci": [ "getConntrackHelpers" ]
}, },
"uci": [ "firewall" ] "uci": [ "firewall" ]
}, },

View file

@ -7,17 +7,19 @@ var callHostHints, callDUIDHints, callDHCPLeases, CBILeaseStatus;
callHostHints = rpc.declare({ callHostHints = rpc.declare({
object: 'luci', object: 'luci',
method: 'host_hints' method: 'getHostHints',
expect: { '': {} }
}); });
callDUIDHints = rpc.declare({ callDUIDHints = rpc.declare({
object: 'luci', object: 'luci',
method: 'duid_hints' method: 'getDUIDHints',
expect: { '': {} }
}); });
callDHCPLeases = rpc.declare({ callDHCPLeases = rpc.declare({
object: 'luci', object: 'luci',
method: 'leases', method: 'getDHCPLeases',
params: [ 'family' ], params: [ 'family' ],
expect: { dhcp_leases: [] } expect: { dhcp_leases: [] }
}); });
@ -57,7 +59,6 @@ return L.view.extend({
m, s, o, ss, so; m, s, o, ss, so;
m = new form.Map('dhcp', _('DHCP and DNS'), _('Dnsmasq is a combined <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>-Server and <abbr title="Domain Name System">DNS</abbr>-Forwarder for <abbr title="Network Address Translation">NAT</abbr> firewalls')); m = new form.Map('dhcp', _('DHCP and DNS'), _('Dnsmasq is a combined <abbr title="Dynamic Host Configuration Protocol">DHCP</abbr>-Server and <abbr title="Domain Name System">DNS</abbr>-Forwarder for <abbr title="Network Address Translation">NAT</abbr> firewalls'));
m.tabbed = true;
s = m.section(form.TypedSection, 'dnsmasq', _('Server Settings')); s = m.section(form.TypedSection, 'dnsmasq', _('Server Settings'));
s.anonymous = true; s.anonymous = true;

View file

@ -5,7 +5,8 @@
return L.view.extend({ return L.view.extend({
callHostHints: rpc.declare({ callHostHints: rpc.declare({
object: 'luci', object: 'luci',
method: 'host_hints' method: 'getHostHints',
expect: { '': {} }
}), }),
load: function() { load: function() {

View file

@ -3,28 +3,23 @@
'require rpc'; 'require rpc';
'require form'; 'require form';
var callInitAction, callLeds, callUSB, callNetdevs; var callLeds, callUSB, callNetdevs;
callInitAction = rpc.declare({
object: 'luci',
method: 'initCall',
params: [ 'name', 'action' ],
expect: { result: false }
});
callLeds = rpc.declare({ callLeds = rpc.declare({
object: 'luci', object: 'luci',
method: 'leds' method: 'getLEDs',
expect: { '': {} }
}); });
callUSB = rpc.declare({ callUSB = rpc.declare({
object: 'luci', object: 'luci',
method: 'usb' method: 'getUSBDevices',
expect: { '': {} }
}); });
callNetdevs = rpc.declare({ callNetdevs = rpc.declare({
object: 'luci', object: 'luci',
method: 'ifaddrs', method: 'getIfaddrs',
expect: { result: [] }, expect: { result: [] },
filter: function(res) { filter: function(res) {
var devs = {}; var devs = {};
@ -130,16 +125,23 @@ return L.view.extend({
value = String(value || '').split(/\s+/); value = String(value || '').split(/\s+/);
for (var i = 0; i < value.length; i++) for (var i = 0; i < value.length; i++)
if (value[i].match(/^usb(\d+)-port(\d+)$/)) if (value[i].match(/^(\d+)-(\d+)$/))
ports.push(value[i]);
else if (value[i].match(/^(\d+)-(\d+)$/))
ports.push('usb%d-port%d'.format(Regexp.$1, Regexp.$2)); ports.push('usb%d-port%d'.format(Regexp.$1, Regexp.$2));
else
ports.push(value[i]);
return ports; return ports;
}; };
usb.ports.forEach(function(usbport) { usb.ports.forEach(function(usbport) {
o.value('usb%d-port%d'.format(usbport.hub, usbport.port), var dev = (usbport.device && Array.isArray(usb.devices))
'Hub %d, Port %d'.format(usbport.hub, usbport.port)); ? usb.devices.filter(function(d) { return d.id == usbport.device })[0] : null;
var label = _('Port %s').format(usbport.port);
if (dev)
label += ' (%s - %s)'.format(dev.vendor || '?', dev.product || '?');
o.value(usbport.port, label);
}); });
} }

View file

@ -8,9 +8,9 @@ var callInitList, callInitAction, callTimezone,
callInitList = rpc.declare({ callInitList = rpc.declare({
object: 'luci', object: 'luci',
method: 'initList', method: 'getInitList',
params: [ 'name' ], params: [ 'name' ],
expect: { result: {} }, expect: { '': {} },
filter: function(res) { filter: function(res) {
for (var k in res) for (var k in res)
return +res[k].enabled; return +res[k].enabled;
@ -20,7 +20,7 @@ callInitList = rpc.declare({
callInitAction = rpc.declare({ callInitAction = rpc.declare({
object: 'luci', object: 'luci',
method: 'initCall', method: 'setInitAction',
params: [ 'name', 'action' ], params: [ 'name', 'action' ],
expect: { result: false } expect: { result: false }
}); });
@ -28,20 +28,20 @@ callInitAction = rpc.declare({
callGetLocaltime = rpc.declare({ callGetLocaltime = rpc.declare({
object: 'luci', object: 'luci',
method: 'getLocaltime', method: 'getLocaltime',
expect: { localtime: 0 } expect: { result: 0 }
}); });
callSetLocaltime = rpc.declare({ callSetLocaltime = rpc.declare({
object: 'luci', object: 'luci',
method: 'setLocaltime', method: 'setLocaltime',
params: [ 'localtime' ], params: [ 'localtime' ],
expect: { localtime: 0 } expect: { result: 0 }
}); });
callTimezone = rpc.declare({ callTimezone = rpc.declare({
object: 'luci', object: 'luci',
method: 'timezone', method: 'getTimezones',
expect: { result: {} } expect: { '': {} }
}); });
CBILocalTime = form.DummyValue.extend({ CBILocalTime = form.DummyValue.extend({
@ -103,7 +103,6 @@ return L.view.extend({
_('Here you can configure the basic aspects of your device like its hostname or the timezone.')); _('Here you can configure the basic aspects of your device like its hostname or the timezone.'));
m.chain('luci'); m.chain('luci');
m.tabbed = true;
s = m.section(form.TypedSection, 'system', _('System Properties')); s = m.section(form.TypedSection, 'system', _('System Properties'));
s.anonymous = true; s.anonymous = true;