diff options
Diffstat (limited to 'modules/luci-base/luasrc/model')
-rw-r--r-- | modules/luci-base/luasrc/model/cbi/admin_network/proto_dhcp.lua | 1 | ||||
-rw-r--r-- | modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua | 91 | ||||
-rw-r--r-- | modules/luci-base/luasrc/model/ipkg.lua | 247 | ||||
-rw-r--r-- | modules/luci-base/luasrc/model/ipkg.luadoc | 125 | ||||
-rw-r--r-- | modules/luci-base/luasrc/model/network.lua | 18 | ||||
-rw-r--r-- | modules/luci-base/luasrc/model/uci.lua | 2 | ||||
-rw-r--r-- | modules/luci-base/luasrc/model/uci.luadoc | 6 |
7 files changed, 107 insertions, 383 deletions
diff --git a/modules/luci-base/luasrc/model/cbi/admin_network/proto_dhcp.lua b/modules/luci-base/luasrc/model/cbi/admin_network/proto_dhcp.lua index dc702e4a95..6e04465ac9 100644 --- a/modules/luci-base/luasrc/model/cbi/admin_network/proto_dhcp.lua +++ b/modules/luci-base/luasrc/model/cbi/admin_network/proto_dhcp.lua @@ -53,6 +53,7 @@ metric.datatype = "uinteger" clientid = section:taboption("advanced", Value, "clientid", translate("Client ID to send when requesting DHCP")) +clientid.datatype = "hexstring" vendorclass = section:taboption("advanced", Value, "vendorid", diff --git a/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua b/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua index 3f8b091cf3..246d2c0ed5 100644 --- a/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua +++ b/modules/luci-base/luasrc/model/cbi/admin_network/proto_static.lua @@ -4,17 +4,93 @@ local map, section, net = ... local ifc = net:get_interface() -local ipaddr, netmask, gateway, broadcast, dns, accept_ra, send_rs, ip6addr, ip6gw -local mtu, metric +local netmask, gateway, broadcast, dns, accept_ra, send_rs, ip6addr, ip6gw +local mtu, metric, usecidr, ipaddr_single, ipaddr_multi -ipaddr = section:taboption("general", Value, "ipaddr", translate("IPv4 address")) -ipaddr.datatype = "ip4addr" +local function is_cidr(s) + return (type(s) == "string" and luci.ip.IPv4(s) and s:find("/")) +end + +usecidr = section:taboption("general", Value, "ipaddr_usecidr") +usecidr.forcewrite = true + +usecidr.cfgvalue = function(self, section) + local cfgvalue = self.map:get(section, "ipaddr") + return (type(cfgvalue) == "table" or is_cidr(cfgvalue)) and "1" or "0" +end + +usecidr.render = function(self, section, scope) + luci.template.Template(nil, [[ + <input type="hidden"<%= attr("id", cbid) .. attr("name", cbid) .. attr("value", value) %> /> + ]]):render({ + cbid = self:cbid(section), + value = self:cfgvalue(section) + }) +end + +usecidr.write = function(self, section) + local cfgvalue = self.map:get(section, "ipaddr") + local formvalue = (self:formvalue(section) == "1") and ipaddr_multi:formvalue(section) or ipaddr_single:formvalue(section) + local equal = (cfgvalue == formvalue) + + if not equal and type(cfgvalue) == "table" and type(formvalue) == "table" and #cfgvalue == #formvalue then + equal = true + + local _, v + for _, v in ipairs(cfgvalue) do + if v ~= formvalue[_] then + equal = false + break + end + end + end + + if not equal then + self.map:set(section, "ipaddr", formvalue or "") + end + + return not equal +end + + +ipaddr_multi = section:taboption("general", DynamicList, "ipaddrs", translate("IPv4 address")) +ipaddr_multi:depends("ipaddr_usecidr", "1") +ipaddr_multi.datatype = "or(cidr4,ipnet4)" +ipaddr_multi.placeholder = translate("Add IPv4 address…") + +ipaddr_multi.alias = "ipaddr" +ipaddr_multi.write = function() end +ipaddr_multi.remove = function() end +ipaddr_multi.cfgvalue = function(self, section) + local addr = self.map:get(section, "ipaddr") + local mask = self.map:get(section, "netmask") + + if is_cidr(addr) then + return { addr } + elseif type(addr) == "string" and + type(mask) == "string" and + #addr > 0 and #mask > 0 + then + return { "%s/%s" %{ addr, mask } } + elseif type(addr) == "table" then + return addr + else + return {} + end +end + +ipaddr_single = section:taboption("general", Value, "ipaddr", translate("IPv4 address")) +ipaddr_single:depends("ipaddr_usecidr", "0") +ipaddr_single.datatype = "ip4addr" +ipaddr_single.template = "cbi/ipaddr" +ipaddr_single.write = function() end +ipaddr_single.remove = function() end -netmask = section:taboption("general", Value, "netmask", - translate("IPv4 netmask")) +netmask = section:taboption("general", Value, "netmask", translate("IPv4 netmask")) +netmask:depends("ipaddr_usecidr", "0") netmask.datatype = "ip4addr" netmask:value("255.255.255.0") netmask:value("255.255.0.0") @@ -48,8 +124,9 @@ if luci.model.network:has_ipv6() then translate("Assign prefix parts using this hexadecimal subprefix ID for this interface.")) for i=33,64 do ip6hint:depends("ip6assign", i) end - ip6addr = section:taboption("general", Value, "ip6addr", translate("IPv6 address")) + ip6addr = section:taboption("general", DynamicList, "ip6addr", translate("IPv6 address")) ip6addr.datatype = "ip6addr" + ip6addr.placeholder = translate("Add IPv6 address…") ip6addr:depends("ip6assign", "") diff --git a/modules/luci-base/luasrc/model/ipkg.lua b/modules/luci-base/luasrc/model/ipkg.lua deleted file mode 100644 index e27ea52895..0000000000 --- a/modules/luci-base/luasrc/model/ipkg.lua +++ /dev/null @@ -1,247 +0,0 @@ --- Copyright 2008-2011 Jo-Philipp Wich <jow@openwrt.org> --- Copyright 2008 Steven Barth <steven@midlink.org> --- Licensed to the public under the Apache License 2.0. - -local os = require "os" -local io = require "io" -local fs = require "nixio.fs" -local util = require "luci.util" - -local type = type -local pairs = pairs -local error = error -local table = table - -local ipkg = "opkg --force-removal-of-dependent-packages --force-overwrite --nocase" -local icfg = "/etc/opkg.conf" - -module "luci.model.ipkg" - - --- Internal action function -local function _action(cmd, ...) - local cmdline = { ipkg, cmd } - - local k, v - for k, v in pairs({...}) do - cmdline[#cmdline+1] = util.shellquote(v) - end - - local c = "%s >/tmp/opkg.stdout 2>/tmp/opkg.stderr" % table.concat(cmdline, " ") - local r = os.execute(c) - local e = fs.readfile("/tmp/opkg.stderr") - local o = fs.readfile("/tmp/opkg.stdout") - - fs.unlink("/tmp/opkg.stderr") - fs.unlink("/tmp/opkg.stdout") - - return r, o or "", e or "" -end - --- Internal parser function -local function _parselist(rawdata) - if type(rawdata) ~= "function" then - error("OPKG: Invalid rawdata given") - end - - local data = {} - local c = {} - local l = nil - - for line in rawdata do - if line:sub(1, 1) ~= " " then - local key, val = line:match("(.-): ?(.*)%s*") - - if key and val then - if key == "Package" then - c = {Package = val} - data[val] = c - elseif key == "Status" then - c.Status = {} - for j in val:gmatch("([^ ]+)") do - c.Status[j] = true - end - else - c[key] = val - end - l = key - end - else - -- Multi-line field - c[l] = c[l] .. "\n" .. line - end - end - - return data -end - --- Internal lookup function -local function _lookup(cmd, pkg) - local cmdline = { ipkg, cmd } - if pkg then - cmdline[#cmdline+1] = util.shellquote(pkg) - end - - -- OPKG sometimes kills the whole machine because it sucks - -- Therefore we have to use a sucky approach too and use - -- tmpfiles instead of directly reading the output - local tmpfile = os.tmpname() - os.execute("%s >%s 2>/dev/null" %{ table.concat(cmdline, " "), tmpfile }) - - local data = _parselist(io.lines(tmpfile)) - os.remove(tmpfile) - return data -end - - -function info(pkg) - return _lookup("info", pkg) -end - -function status(pkg) - return _lookup("status", pkg) -end - -function install(...) - return _action("install", ...) -end - -function installed(pkg) - local p = status(pkg)[pkg] - return (p and p.Status and p.Status.installed) -end - -function remove(...) - return _action("remove", ...) -end - -function update() - return _action("update") -end - -function upgrade() - return _action("upgrade") -end - --- List helper -local function _list(action, pat, cb) - local cmdline = { ipkg, action } - if pat then - cmdline[#cmdline+1] = util.shellquote(pat) - end - - local fd = io.popen(table.concat(cmdline, " ")) - if fd then - local name, version, sz, desc - while true do - local line = fd:read("*l") - if not line then break end - - name, version, sz, desc = line:match("^(.-) %- (.-) %- (.-) %- (.+)") - - if not name then - name, version, sz = line:match("^(.-) %- (.-) %- (.+)") - desc = "" - end - - if name and version then - if #version > 26 then - version = version:sub(1,21) .. ".." .. version:sub(-3,-1) - end - - cb(name, version, sz, desc) - end - - name = nil - version = nil - sz = nil - desc = nil - end - - fd:close() - end -end - -function list_all(pat, cb) - _list("list --size", pat, cb) -end - -function list_installed(pat, cb) - _list("list_installed --size", pat, cb) -end - -function find(pat, cb) - _list("find --size", pat, cb) -end - - -function overlay_root() - local od = "/" - local fd = io.open(icfg, "r") - - if fd then - local ln - - repeat - ln = fd:read("*l") - if ln and ln:match("^%s*option%s+overlay_root%s+") then - od = ln:match("^%s*option%s+overlay_root%s+(%S+)") - - local s = fs.stat(od) - if not s or s.type ~= "dir" then - od = "/" - end - - break - end - until not ln - - fd:close() - end - - return od -end - -function compare_versions(ver1, comp, ver2) - if not ver1 or not ver2 - or not comp or not (#comp > 0) then - error("Invalid parameters") - return nil - end - -- correct compare string - if comp == "<>" or comp == "><" or comp == "!=" or comp == "~=" then comp = "~=" - elseif comp == "<=" or comp == "<" or comp == "=<" then comp = "<=" - elseif comp == ">=" or comp == ">" or comp == "=>" then comp = ">=" - elseif comp == "=" or comp == "==" then comp = "==" - elseif comp == "<<" then comp = "<" - elseif comp == ">>" then comp = ">" - else - error("Invalid compare string") - return nil - end - - local av1 = util.split(ver1, "[%.%-]", nil, true) - local av2 = util.split(ver2, "[%.%-]", nil, true) - - local max = table.getn(av1) - if (table.getn(av1) < table.getn(av2)) then - max = table.getn(av2) - end - - for i = 1, max, 1 do - local s1 = av1[i] or "" - local s2 = av2[i] or "" - - -- first "not equal" found return true - if comp == "~=" and (s1 ~= s2) then return true end - -- first "lower" found return true - if (comp == "<" or comp == "<=") and (s1 < s2) then return true end - -- first "greater" found return true - if (comp == ">" or comp == ">=") and (s1 > s2) then return true end - -- not equal then return false - if (s1 ~= s2) then return false end - end - - -- all equal and not compare greater or lower then true - return not (comp == "<" or comp == ">") -end diff --git a/modules/luci-base/luasrc/model/ipkg.luadoc b/modules/luci-base/luasrc/model/ipkg.luadoc deleted file mode 100644 index 4e1548dda6..0000000000 --- a/modules/luci-base/luasrc/model/ipkg.luadoc +++ /dev/null @@ -1,125 +0,0 @@ ----[[ -LuCI OPKG call abstraction library -]] -module "luci.model.ipkg" - ----[[ -Return information about installed and available packages. - -@class function -@name info -@param pkg Limit output to a (set of) packages -@return Table containing package information -]] - ----[[ -Return the package status of one or more packages. - -@class function -@name status -@param pkg Limit output to a (set of) packages -@return Table containing package status information -]] - ----[[ -Install one or more packages. - -@class function -@name install -@param ... List of packages to install -@return Boolean indicating the status of the action -@return OPKG return code, STDOUT and STDERR -]] - ----[[ -Determine whether a given package is installed. - -@class function -@name installed -@param pkg Package -@return Boolean -]] - ----[[ -Remove one or more packages. - -@class function -@name remove -@param ... List of packages to install -@return Boolean indicating the status of the action -@return OPKG return code, STDOUT and STDERR -]] - ----[[ -Update package lists. - -@class function -@name update -@return Boolean indicating the status of the action -@return OPKG return code, STDOUT and STDERR -]] - ----[[ -Upgrades all installed packages. - -@class function -@name upgrade -@return Boolean indicating the status of the action -@return OPKG return code, STDOUT and STDERR -]] - ----[[ -List all packages known to opkg. - -@class function -@name list_all -@param pat Only find packages matching this pattern, nil lists all packages -@param cb Callback function invoked for each package, receives name, version and description as arguments -@return nothing -]] - ----[[ -List installed packages. - -@class function -@name list_installed -@param pat Only find packages matching this pattern, nil lists all packages -@param cb Callback function invoked for each package, receives name, version and description as arguments -@return nothing -]] - ----[[ -Find packages that match the given pattern. - -@class function -@name find -@param pat Find packages whose names or descriptions match this pattern, nil results in zero results -@param cb Callback function invoked for each patckage, receives name, version and description as arguments -@return nothing -]] - ----[[ -Determines the overlay root used by opkg. - -@class function -@name overlay_root -@return String containing the directory path of the overlay root. -]] - ----[[ -lua version of opkg compare-versions - -@class function -@name compare_versions -@param ver1 string version 1 -@param ver2 string version 2 -@param comp string compare versions using - "<=" or "<" lower-equal - ">" or ">=" greater-equal - "=" equal - "<<" lower - ">>" greater - "~=" not equal -@return Boolean indicating the status of the compare -]] - diff --git a/modules/luci-base/luasrc/model/network.lua b/modules/luci-base/luasrc/model/network.lua index 7f7397032f..a36a23f321 100644 --- a/modules/luci-base/luasrc/model/network.lua +++ b/modules/luci-base/luasrc/model/network.lua @@ -622,6 +622,12 @@ function del_network(self, n) _uci:delete("wireless", s['.name'], "network") end end) + + local ok, fw = pcall(require, "luci.model.firewall") + if ok then + fw.init() + fw:del_network(n) + end end return r end @@ -855,6 +861,14 @@ function get_status_by_address(self, addr) end end end + if s and s['ipv6-prefix-assignment'] then + local a + for _, a in ipairs(s['ipv6-prefix-assignment']) do + if a and a['local-address'] and a['local-address'].address == addr then + return net, s + end + end + end end end end @@ -1151,6 +1165,10 @@ function protocol.is_dynamic(self) return (self:_ubus("dynamic") == true) end +function protocol.is_auto(self) + return (self:_get("auto") ~= "0") +end + function protocol.is_alias(self) local ifn, parent = nil, nil diff --git a/modules/luci-base/luasrc/model/uci.lua b/modules/luci-base/luasrc/model/uci.lua index 2119a210bb..a50e28a871 100644 --- a/modules/luci-base/luasrc/model/uci.lua +++ b/modules/luci-base/luasrc/model/uci.lua @@ -15,7 +15,7 @@ local type, tostring, tonumber, unpack = type, tostring, tonumber, unpack -- cursor factory, modify data (via Cursor.add, Cursor.delete, etc.), -- save the changes to the staging area via Cursor.save and finally -- Cursor.commit the data to the actual config files. --- LuCI then needs to Cursor.apply the changes so deamons etc. are +-- LuCI then needs to Cursor.apply the changes so daemons etc. are -- reloaded. module "luci.model.uci" diff --git a/modules/luci-base/luasrc/model/uci.luadoc b/modules/luci-base/luasrc/model/uci.luadoc index d798b00338..0189d49aa1 100644 --- a/modules/luci-base/luasrc/model/uci.luadoc +++ b/modules/luci-base/luasrc/model/uci.luadoc @@ -5,7 +5,7 @@ The typical workflow for UCI is: Get a cursor instance from the cursor factory, modify data (via Cursor.add, Cursor.delete, etc.), save the changes to the staging area via Cursor.save and finally Cursor.commit the data to the actual config files. -LuCI then needs to Cursor.apply the changes so deamons etc. are +LuCI then needs to Cursor.apply the changes so daemons etc. are reloaded. @cstyle instance ]] @@ -172,7 +172,7 @@ has the same effect as deleting the option. ---[[ Create a sub-state of this cursor. -The sub-state is tied to the parent curser, means it the parent unloads or +The sub-state is tied to the parent cursor, means it the parent unloads or loads configs, the sub state will do so as well. @class function @@ -339,7 +339,7 @@ Set the configuration directory. ]] ---[[ -Set the directory for uncommited changes. +Set the directory for uncommitted changes. @class function @name Cursor.set_savedir |