X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=applications%2Fluci-ddns%2Fluasrc%2Fmodel%2Fcbi%2Fddns%2Fdetail.lua;fp=applications%2Fluci-ddns%2Fluasrc%2Fmodel%2Fcbi%2Fddns%2Fdetail.lua;h=8619d449d5191b12c6be9416bed559bcb50e186a;hb=ee9fdba61744111d8f5d7f7d616992ac7135ac09;hp=c8d10f29b077ec64d42352c0b467cb8a0fd78c89;hpb=92bfcbbc3463cbb7f384d688cb5f1c7e4bed326c;p=project%2Fluci.git diff --git a/applications/luci-ddns/luasrc/model/cbi/ddns/detail.lua b/applications/luci-ddns/luasrc/model/cbi/ddns/detail.lua index c8d10f29b..8619d449d 100644 --- a/applications/luci-ddns/luasrc/model/cbi/ddns/detail.lua +++ b/applications/luci-ddns/luasrc/model/cbi/ddns/detail.lua @@ -21,50 +21,52 @@ You may obtain a copy of the License at $Id$ ]]-- -require "luci.dispatcher" -require "nixio.fs" -require "luci.sys" -require "luci.tools.webadmin" -require "luci.cbi.datatypes" -require "luci.tools.ddns" -- ddns multiused functions - --- takeover arguments +local NX = require "nixio" +local FS = require "nixio.fs" +local SYS = require "luci.sys" +local UTIL = require "luci.util" +local DISP = require "luci.dispatcher" +local WADM = require "luci.tools.webadmin" +local DTYP = require "luci.cbi.datatypes" +local DDNS = require "luci.tools.ddns" -- ddns multiused functions + +-- takeover arguments -- ####################################################### section = arg[1] --- check supported options +-- check supported options -- ################################################## -- saved to local vars here because doing multiple os calls slow down the system -has_ipv6 = luci.tools.ddns.check_ipv6() -- IPv6 support -has_ssl = luci.tools.ddns.check_ssl() -- HTTPS support -has_proxy = luci.tools.ddns.check_proxy() -- Proxy support -has_dnstcp = luci.tools.ddns.check_bind_host() -- DNS TCP support +has_ipv6 = DDNS.check_ipv6() -- IPv6 support +has_ssl = DDNS.check_ssl() -- HTTPS support +has_proxy = DDNS.check_proxy() -- Proxy support +has_dnstcp = DDNS.check_bind_host() -- DNS TCP support has_force = has_ssl and has_dnstcp -- Force IP Protocoll --- html constants +-- html constants -- ########################################################### font_red = "" font_off = "" bold_on = "" bold_off = "" --- error text constants +-- error text constants -- ##################################################### err_ipv6_plain = translate("IPv6 not supported") .. " - " .. translate("please select 'IPv4' address version") -err_ipv6_basic = bold_on .. +err_ipv6_basic = bold_on .. font_red .. - translate("IPv6 not supported") .. - font_off .. - "
" .. translate("please select 'IPv4' address version") .. + translate("IPv6 not supported") .. + font_off .. + "
" .. translate("please select 'IPv4' address version") .. bold_off -err_ipv6_other = bold_on .. - font_red .. - translate("IPv6 not supported") .. - font_off .. - "
" .. translate("please select 'IPv4' address version in") .. " " .. - [[" .. translate("please select 'IPv4' address version in") .. " " .. + [[]] .. - translate("Basic Settings") .. - [[]] .. + [[">]] .. + translate("Basic Settings") .. + [[]] .. bold_off function err_tab_basic(self) @@ -108,10 +110,10 @@ local function _verify_ip_source() _script = ips:formvalue(section) end - local command = [[/usr/lib/ddns/dynamic_dns_lucihelper.sh get_local_ip ]] .. - _ipv6 .. [[ ]] .. _source .. [[ ]] .. _network .. [[ ]] .. + local command = [[/usr/lib/ddns/dynamic_dns_lucihelper.sh get_local_ip ]] .. + _ipv6 .. [[ ]] .. _source .. [[ ]] .. _network .. [[ ]] .. _url .. [[ ]] .. _interface .. [[ ]] .. _script.. [[ ]] .. _proxy - local ret = luci.sys.call(command) + local ret = SYS.call(command) if ret == 0 then return true -- valid @@ -120,26 +122,36 @@ local function _verify_ip_source() end end --- cbi-map definition +-- cbi-map definition -- ####################################################### m = Map("ddns") -m.title = [[]] .. - translate("Dynamic DNS") .. [[]] +-- first need to close from cbi map template our closed by template +m.title = [[]] .. + translate("Dynamic DNS") m.description = translate("Dynamic DNS allows that your router can be reached with " .. "a fixed hostname while having a dynamically changing " .. "IP address.") -m.redirect = luci.dispatcher.build_url("admin", "services", "ddns") +m.redirect = DISP.build_url("admin", "services", "ddns") --- read application settings +m.on_after_commit = function(self) + if self.changed then -- changes ? + local pid = DDNS.get_pid(section) + if pid > 0 then -- running ? + local tmp = NX.kill(pid, 1) -- send SIGHUP + end + end +end + +-- read application settings -- ################################################ -- date format; if not set use ISO format date_format = m.uci:get(m.config, "global", "date_format") or "%F %R" -- log directory log_dir = m.uci:get(m.config, "global", "log_dir") or "/var/log/ddns" --- cbi-section definition -ns = m:section( NamedSection, section, "service", +-- cbi-section definition -- ################################################### +ns = m:section( NamedSection, section, "service", translate("Details for") .. ([[: %s]] % section), translate("Configure here the details for selected Dynamic DNS service") ) ns.instance = section -- arg [1] @@ -148,16 +160,19 @@ ns:tab("advanced", translate("Advanced Settings"), nil ) ns:tab("timer", translate("Timer Settings"), nil ) ns:tab("logview", translate("Log File Viewer"), nil ) --- TAB: Basic ################################################################## --- enabled -en = ns:taboption("basic", Flag, "enabled", +-- TAB: Basic ##################################################################################### +-- enabled -- ################################################################# +en = ns:taboption("basic", Flag, "enabled", translate("Enabled"), translate("If this service section is disabled it could not be started." .. "
" .. "Neither from LuCI interface nor from console") ) en.orientation = "horizontal" +function en.parse(self, section) + DDNS.flag_parse(self, section) +end --- use_ipv6 (NEW) -usev6 = ns:taboption("basic", ListValue, "use_ipv6", +-- use_ipv6 (NEW) -- ########################################################## +usev6 = ns:taboption("basic", ListValue, "use_ipv6", translate("IP address version"), translate("Defines which IP address 'IPv4/IPv6' is send to the DDNS provider") ) usev6.widget = "radio" @@ -187,8 +202,8 @@ function usev6.write(self, section, value) end end --- IPv4 - service_name -svc4 = ns:taboption("basic", ListValue, "ipv4_service_name", +-- IPv4 - service_name -- ###################################################### +svc4 = ns:taboption("basic", ListValue, "ipv4_service_name", translate("DDNS Service provider") .. " [IPv4]" ) svc4.default = "-" svc4:depends("use_ipv6", "0") -- only show on IPv4 @@ -206,11 +221,11 @@ if fd4 then fd4:close() end -for _, v in luci.util.vspairs(services4) do svc4:value(v) end +for _, v in UTIL.vspairs(services4) do svc4:value(v) end svc4:value("-", translate("-- custom --") ) function svc4.cfgvalue(self, section) - local v = luci.tools.ddns.read_value(self, section, "service_name") + local v = DDNS.read_value(self, section, "service_name") if not v or #v == 0 then return "-" else @@ -236,8 +251,8 @@ function svc4.write(self, section, value) end end --- IPv6 - service_name -svc6 = ns:taboption("basic", ListValue, "ipv6_service_name", +-- IPv6 - service_name -- ###################################################### +svc6 = ns:taboption("basic", ListValue, "ipv6_service_name", translate("DDNS Service provider") .. " [IPv6]" ) svc6.default = "-" svc6:depends("use_ipv6", "1") -- only show on IPv6 @@ -258,11 +273,11 @@ if fd6 then fd6:close() end -for _, v in luci.util.vspairs(services6) do svc6:value(v) end +for _, v in UTIL.vspairs(services6) do svc6:value(v) end svc6:value("-", translate("-- custom --") ) function svc6.cfgvalue(self, section) - local v = luci.tools.ddns.read_value(self, section, "service_name") + local v = DDNS.read_value(self, section, "service_name") if not v or #v == 0 then return "-" else @@ -289,8 +304,8 @@ function svc6.write(self, section, value) end end --- IPv4/IPv6 - update_url -uurl = ns:taboption("basic", Value, "update_url", +-- IPv4/IPv6 - update_url -- ################################################### +uurl = ns:taboption("basic", Value, "update_url", translate("Custom update-URL"), translate("Update URL to be used for updating your DDNS Provider." .. "
" .. "Follow instructions you will find on their WEB page.") ) @@ -312,22 +327,22 @@ function uurl.validate(self, value) return nil, err_tab_basic(self) .. translate("either url or script could be set") end - local url = luci.tools.ddns.parse_url(value) + local url = DDNS.parse_url(value) if not url.scheme == "http" then return nil, err_tab_basic(self) .. translate("must start with 'http://'") elseif not url.query then return nil, err_tab_basic(self) .. " " .. translate("missing / required") elseif not url.host then return nil, err_tab_basic(self) .. " " .. translate("missing / required") - elseif luci.sys.call([[nslookup ]] .. url.host .. [[ >/dev/null 2>&1]]) ~= 0 then + elseif SYS.call([[nslookup ]] .. url.host .. [[ >/dev/null 2>&1]]) ~= 0 then return nil, err_tab_basic(self) .. translate("can not resolve host: ") .. url.host end return value end --- IPv4/IPv6 - update_script -ush = ns:taboption("basic", Value, "update_script", +-- IPv4/IPv6 - update_script -- ################################################ +ush = ns:taboption("basic", Value, "update_script", translate("Custom update-script"), translate("Custom update script to be used for updating your DDNS Provider.") ) ush:depends("ipv4_service_name", "-") @@ -346,29 +361,29 @@ function ush.validate(self, value) end elseif (#url > 0) then return nil, err_tab_basic(self) .. translate("either url or script could be set") - elseif not nixio.fs.access(value) then + elseif not FS.access(value) then return nil, err_tab_basic(self) .. translate("File not found") end return value end --- IPv4/IPv6 - domain -dom = ns:taboption("basic", Value, "domain", +-- IPv4/IPv6 - domain -- ####################################################### +dom = ns:taboption("basic", Value, "domain", translate("Hostname/Domain"), translate("Replaces [DOMAIN] in Update-URL") ) dom.rmempty = false dom.placeholder = "mypersonaldomain.dyndns.org" function dom.validate(self, value) - if not value + if not value or not (#value > 0) - or not luci.cbi.datatypes.hostname(value) then + or not DTYP.hostname(value) then return nil, err_tab_basic(self) .. translate("invalid - Sample") .. ": 'mypersonaldomain.dyndns.org'" else return value end end --- IPv4/IPv6 - username +-- IPv4/IPv6 - username -- ##################################################### user = ns:taboption("basic", Value, "username", translate("Username"), translate("Replaces [USERNAME] in Update-URL") ) @@ -380,7 +395,7 @@ function user.validate(self, value) return value end --- IPv4/IPv6 - password +-- IPv4/IPv6 - password -- ##################################################### pw = ns:taboption("basic", Value, "password", translate("Password"), translate("Replaces [PASSWORD] in Update-URL") ) @@ -393,9 +408,9 @@ function pw.validate(self, value) return value end --- IPv4/IPv6 - use_https (NEW) +-- IPv4/IPv6 - use_https (NEW) -- ############################################## if has_ssl or ( ( m:get(section, "use_https") or "0" ) == "1" ) then - https = ns:taboption("basic", Flag, "use_https", + https = ns:taboption("basic", Flag, "use_https", translate("Use HTTP Secure") ) https.orientation = "horizontal" https.rmempty = false -- force validate function @@ -410,6 +425,9 @@ if has_ssl or ( ( m:get(section, "use_https") or "0" ) == "1" ) then end return value end + function https.parse(self, section) + DDNS.flag_parse(self, section) + end function https.validate(self, value) if (value == "1" and has_ssl ) or value == "0" then return value end return nil, err_tab_basic(self) .. translate("HTTPS not supported") .. " !" @@ -424,10 +442,10 @@ if has_ssl or ( ( m:get(section, "use_https") or "0" ) == "1" ) then end end --- IPv4/IPv6 - cacert (NEW) +-- IPv4/IPv6 - cacert (NEW) -- ################################################# if has_ssl then - cert = ns:taboption("basic", Value, "cacert", - translate("Path to CA-Certificate"), + cert = ns:taboption("basic", Value, "cacert", + translate("Path to CA-Certificate"), translate("directory or path/file") .. "
" .. translate("or") .. bold_on .. " IGNORE " .. bold_off .. translate("to run HTTPS without verification of server certificates (insecure)") ) @@ -439,8 +457,8 @@ if has_ssl then return "" -- supress validate error if NOT https end if value then -- otherwise errors in datatype check - if luci.cbi.datatypes.directory(value) - or luci.cbi.datatypes.file(value) + if DTYP.directory(value) + or DTYP.file(value) or value == "IGNORE" then return value end @@ -450,8 +468,8 @@ if has_ssl then end end --- use_syslog -slog = ns:taboption("basic", ListValue, "use_syslog", +-- use_syslog -- ############################################################### +slog = ns:taboption("basic", ListValue, "use_syslog", translate("Log to syslog"), translate("Writes log messages to syslog. Critical Errors will always be written to syslog.") ) slog.default = "0" @@ -461,18 +479,21 @@ slog:value("2", translate("Notice")) slog:value("3", translate("Warning")) slog:value("4", translate("Error")) --- use_logfile (NEW) -logf = ns:taboption("basic", Flag, "use_logfile", +-- use_logfile (NEW) -- ######################################################## +logf = ns:taboption("basic", Flag, "use_logfile", translate("Log to file"), translate("Writes detailed messages to log file. File will be truncated automatically.") .. "
" .. translate("File") .. [[: "]] .. log_dir .. [[/]] .. section .. [[.log"]] ) logf.orientation = "horizontal" logf.rmempty = false -- we want to save in /etc/config/ddns file on "0" because logf.default = "1" -- if not defined write to log by default +function logf.parse(self, section) + DDNS.flag_parse(self, section) +end --- TAB: Advanced ############################################################## --- IPv4 - ip_source -src4 = ns:taboption("advanced", ListValue, "ipv4_source", +-- TAB: Advanced ################################################################################## +-- IPv4 - ip_source -- ######################################################### +src4 = ns:taboption("advanced", ListValue, "ipv4_source", translate("IP address source") .. " [IPv4]", translate("Defines the source to read systems IPv4-Address from, that will be send to the DDNS provider") ) src4:depends("use_ipv6", "0") -- IPv4 selected @@ -481,11 +502,11 @@ src4:value("network", translate("Network")) src4:value("web", translate("URL")) src4:value("interface", translate("Interface")) src4:value("script", translate("Script")) -function src4.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "ip_source") +function src4.cfgvalue(self, section) + return DDNS.read_value(self, section, "ip_source") end function src4.validate(self, value) - if usev6:formvalue(section) == "1" then + if usev6:formvalue(section) == "1" then return "" -- ignore on IPv6 selected elseif not _verify_ip_source() then return nil, err_tab_adv(self) .. @@ -495,7 +516,7 @@ function src4.validate(self, value) end end function src4.write(self, section, value) - if usev6:formvalue(section) == "1" then + if usev6:formvalue(section) == "1" then return true -- ignore on IPv6 selected elseif value == "network" then self.map:del(section, "ip_url") -- delete not need parameters @@ -514,12 +535,12 @@ function src4.write(self, section, value) self.map:del(section, "ip_url") -- delete not need parameters self.map:del(section, "ip_interface") end - self.map:del(section, self.option) -- delete "ipv4_source" helper + self.map:del(section, self.option) -- delete "ipv4_source" helper return self.map:set(section, "ip_source", value) -- and write "ip_source end --- IPv6 - ip_source -src6 = ns:taboption("advanced", ListValue, "ipv6_source", +-- IPv6 - ip_source -- ######################################################### +src6 = ns:taboption("advanced", ListValue, "ipv6_source", translate("IP address source") .. " [IPv6]", translate("Defines the source to read systems IPv6-Address from, that will be send to the DDNS provider") ) src6:depends("use_ipv6", 1) -- IPv6 selected @@ -528,14 +549,14 @@ src6:value("network", translate("Network")) src6:value("web", translate("URL")) src6:value("interface", translate("Interface")) src6:value("script", translate("Script")) -if not has_ipv6 then - src6.description = err_ipv6_other +if not has_ipv6 then + src6.description = err_ipv6_other end function src6.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "ip_source") + return DDNS.read_value(self, section, "ip_source") end function src6.validate(self, value) - if usev6:formvalue(section) == "0" then + if usev6:formvalue(section) == "0" then return "" -- ignore on IPv4 selected elseif not has_ipv6 then return nil, err_tab_adv(self) .. err_ipv6_plain @@ -547,7 +568,7 @@ function src6.validate(self, value) end end function src6.write(self, section, value) - if usev6:formvalue(section) == "0" then + if usev6:formvalue(section) == "0" then return true -- ignore on IPv4 selected elseif value == "network" then self.map:del(section, "ip_url") -- delete not need parameters @@ -566,19 +587,19 @@ function src6.write(self, section, value) self.map:del(section, "ip_url") -- delete not need parameters self.map:del(section, "ip_interface") end - self.map:del(section, self.option) -- delete "ipv4_source" helper + self.map:del(section, self.option) -- delete "ipv4_source" helper return self.map:set(section, "ip_source", value) -- and write "ip_source end --- IPv4 - ip_network (default "wan") -ipn4 = ns:taboption("advanced", ListValue, "ipv4_network", +-- IPv4 - ip_network (default "wan") -- ######################################## +ipn4 = ns:taboption("advanced", ListValue, "ipv4_network", translate("Network") .. " [IPv4]", translate("Defines the network to read systems IPv4-Address from") ) ipn4:depends("ipv4_source", "network") ipn4.default = "wan" -luci.tools.webadmin.cbi_add_networks(ipn4) -function ipn4.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "ip_network") +WADM.cbi_add_networks(ipn4) +function ipn4.cfgvalue(self, section) + return DDNS.read_value(self, section, "ip_network") end function ipn4.validate(self, value) if usev6:formvalue(section) == "1" @@ -599,24 +620,24 @@ function ipn4.write(self, section, value) else -- set also as "interface" for monitoring events changes/hot-plug self.map:set(section, "interface", value) - self.map:del(section, self.option) -- delete "ipv4_network" helper + self.map:del(section, self.option) -- delete "ipv4_network" helper return self.map:set(section, "ip_network", value) -- and write "ip_network" end end --- IPv6 - ip_network (default "wan6") -ipn6 = ns:taboption("advanced", ListValue, "ipv6_network", +-- IPv6 - ip_network (default "wan6") -- ####################################### +ipn6 = ns:taboption("advanced", ListValue, "ipv6_network", translate("Network") .. " [IPv6]" ) ipn6:depends("ipv6_source", "network") ipn6.default = "wan6" -luci.tools.webadmin.cbi_add_networks(ipn6) +WADM.cbi_add_networks(ipn6) if has_ipv6 then ipn6.description = translate("Defines the network to read systems IPv6-Address from") else ipn6.description = err_ipv6_other end function ipn6.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "ip_network") + return DDNS.read_value(self, section, "ip_network") end function ipn6.validate(self, value) if usev6:formvalue(section) == "0" @@ -639,19 +660,19 @@ function ipn6.write(self, section, value) else -- set also as "interface" for monitoring events changes/hotplug self.map:set(section, "interface", value) - self.map:del(section, self.option) -- delete "ipv6_network" helper + self.map:del(section, self.option) -- delete "ipv6_network" helper return self.map:set(section, "ip_network", value) -- and write "ip_network" end end --- IPv4 - ip_url (default "checkip.dyndns.com") -iurl4 = ns:taboption("advanced", Value, "ipv4_url", +-- IPv4 - ip_url (default "checkip.dyndns.com") -- ############################# +iurl4 = ns:taboption("advanced", Value, "ipv4_url", translate("URL to detect") .. " [IPv4]", translate("Defines the Web page to read systems IPv4-Address from") ) iurl4:depends("ipv4_source", "web") iurl4.default = "http://checkip.dyndns.com" function iurl4.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "ip_url") + return DDNS.read_value(self, section, "ip_url") end function iurl4.validate(self, value) if usev6:formvalue(section) == "1" @@ -663,14 +684,12 @@ function iurl4.validate(self, value) return nil, err_tab_adv(self) .. translate("missing / required") end - local url = luci.tools.ddns.parse_url(value) + local url = DDNS.parse_url(value) if not (url.scheme == "http" or url.scheme == "https") then return nil, err_tab_adv(self) .. translate("must start with 'http://'") elseif not url.host then return nil, err_tab_adv(self) .. " " .. translate("missing / required") - elseif luci.sys.call([[nslookup ]] .. - url.host .. - [[>/dev/null 2>&1]]) ~= 0 then + elseif SYS.call([[nslookup ]] .. url.host .. [[>/dev/null 2>&1]]) ~= 0 then return nil, err_tab_adv(self) .. translate("can not resolve host: ") .. url.host else return value @@ -688,8 +707,8 @@ function iurl4.write(self, section, value) end end --- IPv6 - ip_url (default "checkipv6.dyndns.com") -iurl6 = ns:taboption("advanced", Value, "ipv6_url", +-- IPv6 - ip_url (default "checkipv6.dyndns.com") -- ########################### +iurl6 = ns:taboption("advanced", Value, "ipv6_url", translate("URL to detect") .. " [IPv6]" ) iurl6:depends("ipv6_source", "web") iurl6.default = "http://checkipv6.dyndns.com" @@ -699,7 +718,7 @@ else iurl6.description = err_ipv6_other end function iurl6.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "ip_url") + return DDNS.read_value(self, section, "ip_url") end function iurl6.validate(self, value) if usev6:formvalue(section) == "0" @@ -713,14 +732,12 @@ function iurl6.validate(self, value) return nil, err_tab_adv(self) .. translate("missing / required") end - local url = luci.tools.ddns.parse_url(value) + local url = DDNS.parse_url(value) if not (url.scheme == "http" or url.scheme == "https") then return nil, err_tab_adv(self) .. translate("must start with 'http://'") elseif not url.host then return nil, err_tab_adv(self) .. " " .. translate("missing / required") - elseif luci.sys.call([[nslookup ]] .. - url.host .. - [[>/dev/null 2>&1]]) ~= 0 then + elseif SYS.call([[nslookup ]] .. url.host .. [[>/dev/null 2>&1]]) ~= 0 then return nil, err_tab_adv(self) .. translate("can not resolve host: ") .. url.host else return value @@ -738,17 +755,17 @@ function iurl6.write(self, section, value) end end --- IPv4 + IPv6 - ip_interface -ipi = ns:taboption("advanced", ListValue, "ip_interface", +-- IPv4 + IPv6 - ip_interface -- ############################################### +ipi = ns:taboption("advanced", ListValue, "ip_interface", translate("Interface"), translate("Defines the interface to read systems IP-Address from") ) ipi:depends("ipv4_source", "interface") -- IPv4 ipi:depends("ipv6_source", "interface") -- or IPv6 -for _, v in pairs(luci.sys.net.devices()) do +for _, v in pairs(SYS.net.devices()) do -- show only interface set to a network -- and ignore loopback - net = luci.tools.webadmin.iface_get_network(v) - if net and net ~= "loopback" then + net = WADM.iface_get_network(v) + if net and net ~= "loopback" then ipi:value(v) end end @@ -767,14 +784,14 @@ function ipi.write(self, section, value) else -- get network from device to -- set also as "interface" for monitoring events changes/hotplug - local net = luci.tools.webadmin.iface_get_network(value) + local net = WADM.iface_get_network(value) self.map:set(section, "interface", net) return self.map:set(section, self.option, value) end end --- IPv4 + IPv6 - ip_script (NEW) -ips = ns:taboption("advanced", Value, "ip_script", +-- IPv4 + IPv6 - ip_script (NEW) -- ############################################ +ips = ns:taboption("advanced", Value, "ip_script", translate("Script"), translate("User defined script to read systems IP-Address") ) ips:depends("ipv4_source", "script") -- IPv4 @@ -784,8 +801,8 @@ function ips.validate(self, value) if (usev6:formvalue(section) == "0" and src4:formvalue(section) ~= "script") or (usev6:formvalue(section) == "1" and src6:formvalue(section) ~= "script") then return "" - elseif not value or not nixio.fs.access(value, "x") then - return nil, err_tab_adv(self) .. + elseif not value or not FS.access(value, "x") then + return nil, err_tab_adv(self) .. translate("not found or not executable - Sample: '/path/to/script.sh'") else return value @@ -800,19 +817,19 @@ function ips.write(self, section, value) end end --- IPv4 - interface - default "wan" +-- IPv4 - interface - default "wan" -- ######################################### -- event network to monitor changes/hotplug/dynamic_dns_updater.sh -- only needs to be set if "ip_source"="web" or "script" --- if "ip_source"="network" or "interface" we use their network -eif4 = ns:taboption("advanced", ListValue, "ipv4_interface", - translate("Event Network") .. " [IPv4]", +-- if "ip_source"="network" or "interface" we use their network +eif4 = ns:taboption("advanced", ListValue, "ipv4_interface", + translate("Event Network") .. " [IPv4]", translate("Network on which the ddns-updater scripts will be started") ) eif4:depends("ipv4_source", "web") eif4:depends("ipv4_source", "script") eif4.default = "wan" -luci.tools.webadmin.cbi_add_networks(eif4) +WADM.cbi_add_networks(eif4) function eif4.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "interface") + return DDNS.read_value(self, section, "interface") end function eif4.validate(self, value) if usev6:formvalue(section) == "1" @@ -829,35 +846,35 @@ function eif4.write(self, section, value) or src4:formvalue(section) == "interface" then return true -- ignore IPv6, network, interface else - self.map:del(section, self.option) -- delete "ipv4_interface" helper + self.map:del(section, self.option) -- delete "ipv4_interface" helper return self.map:set(section, "interface", value) -- and write "interface" end end --- IPv6 - interface (NEW) - default "wan6" +-- IPv6 - interface (NEW) - default "wan6" -- ################################## -- event network to monitor changes/hotplug (NEW) -- only needs to be set if "ip_source"="web" or "script" --- if "ip_source"="network" or "interface" we use their network -eif6 = ns:taboption("advanced", ListValue, "ipv6_interface", +-- if "ip_source"="network" or "interface" we use their network +eif6 = ns:taboption("advanced", ListValue, "ipv6_interface", translate("Event Network") .. " [IPv6]" ) eif6:depends("ipv6_source", "web") eif6:depends("ipv6_source", "script") eif6.default = "wan6" -luci.tools.webadmin.cbi_add_networks(eif6) -if not has_ipv6 then +WADM.cbi_add_networks(eif6) +if not has_ipv6 then eif6.description = err_ipv6_other else eif6.description = translate("Network on which the ddns-updater scripts will be started") end function eif6.cfgvalue(self, section) - return luci.tools.ddns.read_value(self, section, "interface") + return DDNS.read_value(self, section, "interface") end function eif6.validate(self, value) if usev6:formvalue(section) == "0" or src4:formvalue(section) == "network" or src4:formvalue(section) == "interface" then return "" -- ignore IPv4, network, interface - elseif not has_ipv6 then + elseif not has_ipv6 then return nil, err_tab_adv(self) .. err_ipv6_plain else return value @@ -869,12 +886,12 @@ function eif6.write(self, section, value) or src4:formvalue(section) == "interface" then return true -- ignore IPv4, network, interface else - self.map:del(section, self.option) -- delete "ipv6_interface" helper + self.map:del(section, self.option) -- delete "ipv6_interface" helper return self.map:set(section, "interface", value) -- and write "interface" end end --- IPv4 + IPv6 - force_ipversion (NEW) +-- IPv4 + IPv6 - force_ipversion (NEW) -- ###################################### -- optional to force wget/curl and host to use only selected IP version -- command parameter "-4" or "-6" if has_force or ( ( m:get(section, "force_ipversion") or "0" ) ~= "0" ) then @@ -896,6 +913,9 @@ if has_force or ( ( m:get(section, "force_ipversion") or "0" ) ~= "0" ) then if (value == "1" and has_force) or value == "0" then return value end return nil, err_tab_adv(self) .. translate("Force IP Version not supported") end + function fipv.parse(self, section) + DDNS.flag_parse(self, section) + end function fipv.write(self, section, value) if value == "1" then return self.map:set(section, self.option, value) @@ -905,9 +925,9 @@ if has_force or ( ( m:get(section, "force_ipversion") or "0" ) ~= "0" ) then end end --- IPv4 + IPv6 - dns_server (NEW) +-- IPv4 + IPv6 - dns_server (NEW) -- ########################################### -- optional DNS Server to use resolving my IP if "ip_source"="web" -dns = ns:taboption("advanced", Value, "dns_server", +dns = ns:taboption("advanced", Value, "dns_server", translate("DNS-Server"), translate("OPTIONAL: Use non-default DNS-Server to detect 'Registered IP'.") .. "
" .. translate("Format: IP or FQDN")) @@ -916,14 +936,14 @@ function dns.validate(self, value) -- if .datatype is set, then it is checked before calling this function if not value then return "" -- ignore on empty - elseif not luci.cbi.datatypes.hostname(value) then - return nil, err .. translate("use hostname, FQDN, IPv4- or IPv6-Address") + elseif not DTYP.host(value) then + return nil, err_tab_adv(self) .. translate("use hostname, FQDN, IPv4- or IPv6-Address") else local ipv6 = usev6:formvalue(section) local force = (fipv) and fipv:formvalue(section) or "0" - local command = [[/usr/lib/ddns/dynamic_dns_lucihelper.sh verify_dns ]] .. + local command = [[/usr/lib/ddns/dynamic_dns_lucihelper.sh verify_dns ]] .. value .. [[ ]] .. ipv6 .. [[ ]] .. force - local ret = luci.sys.call(command) + local ret = SYS.call(command) if ret == 0 then return value -- everything OK elseif ret == 2 then return nil, err_tab_adv(self) .. translate("nslookup can not resolve host") elseif ret == 3 then return nil, err_tab_adv(self) .. translate("nc (netcat) can not connect") @@ -933,7 +953,7 @@ function dns.validate(self, value) end end --- IPv4 + IPv6 - force_dnstcp (NEW) +-- IPv4 + IPv6 - force_dnstcp (NEW) -- ######################################### if has_dnstcp or ( ( m:get(section, "force_dnstcp") or "0" ) ~= "0" ) then tcp = ns:taboption("advanced", Flag, "force_dnstcp", translate("Force TCP on DNS") ) @@ -955,12 +975,15 @@ if has_dnstcp or ( ( m:get(section, "force_dnstcp") or "0" ) ~= "0" ) then end return nil, err_tab_adv(self) .. translate("DNS requests via TCP not supported") end + function tcp.parse(self, section) + DDNS.flag_parse(self, section) + end end --- IPv4 + IPv6 - proxy (NEW) +-- IPv4 + IPv6 - proxy (NEW) -- ################################################ -- optional Proxy to use for http/https requests [user:password@]proxyhost[:port] if has_proxy or ( ( m:get(section, "proxy") or "" ) ~= "" ) then - pxy = ns:taboption("advanced", Value, "proxy", + pxy = ns:taboption("advanced", Value, "proxy", translate("PROXY-Server") ) pxy.placeholder="user:password@myproxy.lan:8080" function pxy.cfgvalue(self, section) @@ -972,8 +995,8 @@ if has_proxy or ( ( m:get(section, "proxy") or "" ) ~= "" ) then else self.description = translate("OPTIONAL: Proxy-Server for detection and updates.") .. "
" .. translate("Format") .. ": " .. bold_on .. "[user:password@]proxyhost:port" .. bold_off .. "
" .. - translate("IPv6 address must be given in square brackets") .. ": " .. - bold_on .. " [2001:db8::1]:8080" .. bold_off + translate("IPv6 address must be given in square brackets") .. ": " .. + bold_on .. " [2001:db8::1]:8080" .. bold_off end return value end @@ -981,12 +1004,12 @@ if has_proxy or ( ( m:get(section, "proxy") or "" ) ~= "" ) then -- if .datatype is set, then it is checked before calling this function if not value then return "" -- ignore on empty - elseif has_proxy then + elseif has_proxy then local ipv6 = usev6:formvalue(section) or "0" local force = (fipv) and fipv:formvalue(section) or "0" - local command = [[/usr/lib/ddns/dynamic_dns_lucihelper.sh verify_proxy ]] .. + local command = [[/usr/lib/ddns/dynamic_dns_lucihelper.sh verify_proxy ]] .. value .. [[ ]] .. ipv6 .. [[ ]] .. force - local ret = luci.sys.call(command) + local ret = SYS.call(command) if ret == 0 then return value elseif ret == 2 then return nil, err_tab_adv(self) .. translate("nslookup can not resolve host") elseif ret == 3 then return nil, err_tab_adv(self) .. translate("nc (netcat) can not connect") @@ -1000,21 +1023,21 @@ if has_proxy or ( ( m:get(section, "proxy") or "" ) ~= "" ) then end end --- TAB: Timer ################################################################# --- check_interval -ci = ns:taboption("timer", Value, "check_interval", +-- TAB: Timer ##################################################################################### +-- check_interval -- ########################################################### +ci = ns:taboption("timer", Value, "check_interval", translate("Check Interval") ) ci.template = "ddns/detail_value" -ci.default = 10 +ci.default = 10 ci.rmempty = false -- validate ourselves for translatable error messages function ci.validate(self, value) - if not luci.cbi.datatypes.uinteger(value) + if not DTYP.uinteger(value) or tonumber(value) < 1 then return nil, err_tab_timer(self) .. translate("minimum value 5 minutes == 300 seconds") end - local secs = luci.tools.ddns.calc_seconds(value, cu:formvalue(section)) - if secs >= 300 then + local secs = DDNS.calc_seconds(value, cu:formvalue(section)) + if secs >= 300 then return value else return nil, err_tab_timer(self) .. translate("minimum value 5 minutes == 300 seconds") @@ -1022,7 +1045,7 @@ function ci.validate(self, value) end function ci.write(self, section, value) -- simulate rmempty=true remove default - local secs = luci.tools.ddns.calc_seconds(value, cu:formvalue(section)) + local secs = DDNS.calc_seconds(value, cu:formvalue(section)) if secs ~= 600 then --default 10 minutes return self.map:set(section, self.option, value) else @@ -1031,9 +1054,9 @@ function ci.write(self, section, value) end end --- check_unit +-- check_unit -- ############################################################### cu = ns:taboption("timer", ListValue, "check_unit", "not displayed, but needed otherwise error", - translate("Interval to check for changed IP" .. "
" .. + translate("Interval to check for changed IP" .. "
" .. "Values below 5 minutes == 300 seconds are not supported") ) cu.template = "ddns/detail_lvalue" cu.default = "minutes" @@ -1044,7 +1067,7 @@ cu:value("hours", translate("hours")) --cu:value("days", translate("days")) function cu.write(self, section, value) -- simulate rmempty=true remove default - local secs = luci.tools.ddns.calc_seconds(ci:formvalue(section), value) + local secs = DDNS.calc_seconds(ci:formvalue(section), value) if secs ~= 600 then --default 10 minutes return self.map:set(section, self.option, value) else @@ -1052,29 +1075,29 @@ function cu.write(self, section, value) end end --- force_interval (modified) -fi = ns:taboption("timer", Value, "force_interval", +-- force_interval (modified) -- ################################################ +fi = ns:taboption("timer", Value, "force_interval", translate("Force Interval") ) fi.template = "ddns/detail_value" fi.default = 72 -- see dynamic_dns_updater.sh script fi.rmempty = false -- validate ourselves for translatable error messages function fi.validate(self, value) - if not luci.cbi.datatypes.uinteger(value) + if not DTYP.uinteger(value) or tonumber(value) < 0 then return nil, err_tab_timer(self) .. translate("minimum value '0'") end - local force_s = luci.tools.ddns.calc_seconds(value, fu:formvalue(section)) - if force_s == 0 then + local force_s = DDNS.calc_seconds(value, fu:formvalue(section)) + if force_s == 0 then return value end local ci_value = ci:formvalue(section) - if not luci.cbi.datatypes.uinteger(ci_value) then + if not DTYP.uinteger(ci_value) then return "" -- ignore because error in check_interval above end - local check_s = luci.tools.ddns.calc_seconds(ci_value, cu:formvalue(section)) + local check_s = DDNS.calc_seconds(ci_value, cu:formvalue(section)) if force_s >= check_s then return value end @@ -1083,7 +1106,7 @@ function fi.validate(self, value) end function fi.write(self, section, value) -- simulate rmempty=true remove default - local secs = luci.tools.ddns.calc_seconds(value, fu:formvalue(section)) + local secs = DDNS.calc_seconds(value, fu:formvalue(section)) if secs ~= 259200 then --default 72 hours == 3 days return self.map:set(section, self.option, value) else @@ -1092,7 +1115,7 @@ function fi.write(self, section, value) end end --- force_unit +-- force_unit -- ############################################################### fu = ns:taboption("timer", ListValue, "force_unit", "not displayed, but needed otherwise error", translate("Interval to force updates send to DDNS Provider" .. "
" .. "Setting this parameter to 0 will force the script to only run once" .. "
" .. @@ -1106,7 +1129,7 @@ fu:value("hours", translate("hours")) fu:value("days", translate("days")) function fu.write(self, section, value) -- simulate rmempty=true remove default - local secs = luci.tools.ddns.calc_seconds(fi:formvalue(section), value) + local secs = DDNS.calc_seconds(fi:formvalue(section), value) if secs ~= 259200 and secs ~= 0 then --default 72 hours == 3 days return self.map:set(section, self.option, value) else @@ -1114,14 +1137,14 @@ function fu.write(self, section, value) end end --- retry_count (NEW) -rc = ns:taboption("timer", Value, "retry_count", +-- retry_count (NEW) -- ######################################################## +rc = ns:taboption("timer", Value, "retry_count", translate("Error Retry Counter"), translate("On Error the script will stop execution after given number of retrys") ) rc.default = 5 rc.rmempty = false -- validate ourselves for translatable error messages function rc.validate(self, value) - if not luci.cbi.datatypes.uinteger(value) + if not DTYP.uinteger(value) or tonumber(value) < 1 then return nil, err_tab_timer(self) .. translate("minimum value '1'") else @@ -1137,14 +1160,14 @@ function rc.write(self, section, value) end end --- retry_interval -ri = ns:taboption("timer", Value, "retry_interval", - translate("Error Retry Interval") ) +-- retry_interval -- ########################################################### +ri = ns:taboption("timer", Value, "retry_interval", + translate("Error Retry Interval") ) ri.template = "ddns/detail_value" ri.default = 60 ri.rmempty = false -- validate ourselves for translatable error messages function ri.validate(self, value) - if not luci.cbi.datatypes.uinteger(value) + if not DTYP.uinteger(value) or tonumber(value) < 1 then return nil, err_tab_timer(self) .. translate("minimum value '1'") else @@ -1153,7 +1176,7 @@ function ri.validate(self, value) end function ri.write(self, section, value) -- simulate rmempty=true remove default - local secs = luci.tools.ddns.calc_seconds(value, ru:formvalue(section)) + local secs = DDNS.calc_seconds(value, ru:formvalue(section)) if secs ~= 60 then --default 60seconds return self.map:set(section, self.option, value) else @@ -1162,7 +1185,7 @@ function ri.write(self, section, value) end end --- retry_unit +-- retry_unit -- ############################################################### ru = ns:taboption("timer", ListValue, "retry_unit", "not displayed, but needed otherwise error", translate("On Error the script will retry the failed action after given time") ) ru.template = "ddns/detail_lvalue" @@ -1174,7 +1197,7 @@ ru:value("minutes", translate("minutes")) --ru:value("days", translate("days")) function ru.write(self, section, value) -- simulate rmempty=true remove default - local secs = luci.tools.ddns.calc_seconds(ri:formvalue(section), value) + local secs = DDNS.calc_seconds(ri:formvalue(section), value) if secs ~= 60 then --default 60seconds return self.map:set(section, self.option, value) else @@ -1189,7 +1212,7 @@ lv.inputtitle = translate("Read / Reread log file") lv.rows = 50 function lv.cfgvalue(self, section) local lfile=log_dir .. "/" .. section .. ".log" - if nixio.fs.access(lfile) then + if FS.access(lfile) then return lfile .. "\n" .. translate("Please press [Read] button") end return lfile .. "\n" .. translate("File not found or empty")