1
0
Fork 0
mirror of https://github.com/Ysurac/openmptcprouter-feeds.git synced 2025-03-09 15:40:03 +00:00

Update luci and theme

This commit is contained in:
Ycarus 2019-05-28 21:51:29 +02:00
parent fe03553aae
commit 4d7962337f
165 changed files with 74180 additions and 13802 deletions

View file

@ -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",

View file

@ -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
netmask = section:taboption("general", Value, "netmask",
translate("IPv4 netmask"))
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: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", "")
@ -83,14 +160,8 @@ mtu.placeholder = "1500"
mtu.datatype = "max(9200)"
--metric = section:taboption("advanced", Value, "metric",
-- translate("Use gateway metric"))
--metric.default = "1"
--metric.datatype = "uinteger"
metric = section:taboption("advanced", Value, "metric",
translate("Use gateway metric"))
--local nw = require "luci.model.network".init()
--for _, network in ipairs(nw:get_networks()) do
-- if network:proto() == "static" and network:type() == "macvlan" and tonumber(network:metric()) >= tonumber(metric.default) then
-- metric.default = network:metric() + 1
-- end
--end
metric.placeholder = "0"
metric.datatype = "uinteger"

View file

@ -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

View file

@ -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
]]

View file

@ -20,7 +20,7 @@ module "luci.model.network"
IFACE_PATTERNS_VIRTUAL = { }
IFACE_PATTERNS_IGNORE = { "^wmaster%d", "^wifi%d", "^hwsim%d", "^imq%d", "^ifb%d", "^mon%.wlan%d", "^sit%d", "^gre%d", "^gretap%d", "^ip6gre%d", "^ip6tnl%d", "^tunl%d", "^lo$" }
IFACE_PATTERNS_IGNORE = { "^wmaster%d", "^wifi%d", "^hwsim%d", "^imq%d", "^ifb%d", "^mon%.wlan%d", "^sit%d", "^gre%d", "^gretap%d", "^ip6gre%d", "^ip6tnl%d", "^tunl%d", "^lo$", "^teql%d" }
IFACE_PATTERNS_WIRELESS = { "^wlan%d", "^wl%d", "^ath%d", "^%w+%.network%d" }
IFACE_ERRORS = {
@ -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
@ -813,6 +819,7 @@ function del_wifinet(self, net)
end
function get_status_by_route(self, addr, mask)
local route_statuses = { }
local _, object
for _, object in ipairs(utl.ubus()) do
local net = object:match("^network%.interface%.(.+)")
@ -822,12 +829,14 @@ function get_status_by_route(self, addr, mask)
local rt
for _, rt in ipairs(s.route) do
if not rt.table and rt.target == addr and rt.mask == mask then
return net, s
route_statuses[net] = s
end
end
end
end
end
return route_statuses
end
function get_status_by_address(self, addr)
@ -852,28 +861,40 @@ 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
function get_wannet(self)
local net, stat = self:get_status_by_route("0.0.0.0", 0)
return net and network(net, stat.proto)
function get_wan_networks(self)
local k, v
local wan_nets = { }
local route_statuses = self:get_status_by_route("0.0.0.0", 0)
for k, v in pairs(route_statuses) do
wan_nets[#wan_nets+1] = network(k, v.proto)
end
return wan_nets
end
function get_wandev(self)
local _, stat = self:get_status_by_route("0.0.0.0", 0)
return stat and interface(stat.l3_device or stat.device)
end
function get_wan6_networks(self)
local k, v
local wan6_nets = { }
local route_statuses = self:get_status_by_route("::", 0)
function get_wan6net(self)
local net, stat = self:get_status_by_route("::", 0)
return net and network(net, stat.proto)
end
for k, v in pairs(route_statuses) do
wan6_nets[#wan6_nets+1] = network(k, v.proto)
end
function get_wan6dev(self)
local _, stat = self:get_status_by_route("::", 0)
return stat and interface(stat.l3_device or stat.device)
return wan6_nets
end
function get_switch_topologies(self)
@ -1144,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

View file

@ -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"
@ -95,41 +95,15 @@ end
function changes(self, config)
local rv = call("changes", { config = config })
local res = {}
local rv, err = call("changes", { config = config })
if type(rv) == "table" and type(rv.changes) == "table" then
local package, changes
for package, changes in pairs(rv.changes) do
res[package] = {}
local _, change
for _, change in ipairs(changes) do
local operation, section, option, value = unpack(change)
if option and operation ~= "add" then
res[package][section] = res[package][section] or { }
if operation == "list-add" then
local v = res[package][section][option]
if type(v) == "table" then
v[#v+1] = value or ""
elseif v ~= nil then
res[package][section][option] = { v, value }
else
res[package][section][option] = { value }
end
else
res[package][section][option] = value or ""
end
else
res[package][section] = res[package][section] or {}
res[package][section][".type"] = option or ""
end
end
end
return rv.changes
elseif err then
return nil, ERRSTR[err]
else
return { }
end
return res
end

View file

@ -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