diff options
author | Christian Schoenebeck <christian.schoenebeck@gmail.com> | 2015-02-10 21:49:57 +0100 |
---|---|---|
committer | Christian Schoenebeck <christian.schoenebeck@gmail.com> | 2015-02-10 21:49:57 +0100 |
commit | 8b0f83264a5d33078eaca1f15de226cc7f984f59 (patch) | |
tree | ed4dd88b5599c23c01988a549e27704f1a7930fa /applications/luci-app-ddns/luasrc/model/cbi | |
parent | 86c627224091bb4ea6df961470464f5ed1748d07 (diff) |
luci-app-ddns: update to version 2.2.0-1
- implement new option bind_interface
- fixes problems when updating status displays (i.e. showing Software update needed)
- new links to OpenWrt wiki
- new screen to set global settings
- implements global option use_curl
Signed-off-by: Christian Schoenebeck <christian.schoenebeck@gmail.com>
Diffstat (limited to 'applications/luci-app-ddns/luasrc/model/cbi')
4 files changed, 230 insertions, 21 deletions
diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua index 77753c03a7..602bc159af 100644 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua +++ b/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua @@ -5,7 +5,7 @@ -- Licensed to the public under the Apache License 2.0. local NX = require "nixio" -local FS = require "nixio.fs" +local NXFS = require "nixio.fs" local SYS = require "luci.sys" local UTIL = require "luci.util" local DISP = require "luci.dispatcher" @@ -14,21 +14,22 @@ local DTYP = require "luci.cbi.datatypes" local DDNS = require "luci.tools.ddns" -- ddns multiused functions -- takeover arguments -- ####################################################### -section = arg[1] +local section = arg[1] -- check supported options -- ################################################## -- saved to local vars here because doing multiple os calls slow down the system -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 +local has_ipv6 = DDNS.check_ipv6() -- IPv6 support +local has_ssl = DDNS.check_ssl() -- HTTPS support +local has_proxy = DDNS.check_proxy() -- Proxy support +local has_dnstcp = DDNS.check_bind_host() -- DNS TCP support +local has_force = has_ssl and has_dnstcp -- Force IP Protocoll -- html constants -- ########################################################### -font_red = "<font color='red'>" -font_off = "</font>" -bold_on = "<strong>" -bold_off = "</strong>" +local LFLF = (DDNS.get_theme() == "Bootstrap") and [[<br /><br />]] or [[]] +local font_red = "<font color='red'>" +local font_off = "</font>" +local bold_on = "<strong>" +local bold_off = "</strong>" -- error text constants -- ##################################################### err_ipv6_plain = translate("IPv6 not supported") .. " - " .. @@ -136,7 +137,10 @@ log_dir = m.uci:get(m.config, "global", "log_dir") or "/var/log/ddns" -- cbi-section definition -- ################################################### ns = m:section( NamedSection, section, "service", translate("Details for") .. ([[: <strong>%s</strong>]] % section), - translate("Configure here the details for selected Dynamic DNS service") ) + translate("Configure here the details for selected Dynamic DNS service.") + .. [[<br /><a href="http://wiki.openwrt.org/doc/uci/ddns#version_1x" target="_blank">]] + .. translate("For detailed information about parameter settings look here.") + .. [[</a>]] ) ns.instance = section -- arg [1] ns:tab("basic", translate("Basic Settings"), nil ) ns:tab("advanced", translate("Advanced Settings"), nil ) @@ -344,7 +348,7 @@ 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 FS.access(value) then + elseif not NXFS.access(value) then return nil, err_tab_basic(self) .. translate("File not found") end return value @@ -765,7 +769,7 @@ 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 (#value > 0) or not FS.access(split[1], "x") then + elseif not value or not (#value > 0) or not NXFS.access(split[1], "x") then return nil, err_tab_adv(self) .. translate("not found or not executable - Sample: '/path/to/script.sh'") else @@ -855,6 +859,34 @@ function eif6.write(self, section, value) end end +-- IPv4/IPv6 - bind_network -- ################################################# +if has_ssl or ( ( m:get(section, "bind_network") or "" ) ~= "" ) then + bnet = ns:taboption("advanced", ListValue, "bind_network", + translate("Bind Network") ) + bnet:depends("ipv4_source", "web") + bnet:depends("ipv6_source", "web") + bnet.rmempty = true + bnet.default = "" + bnet:value("", translate("-- default --")) + WADM.cbi_add_networks(bnet) + function bnet.cfgvalue(self, section) + local value = AbstractValue.cfgvalue(self, section) + if not has_ssl and value ~= "" then + self.description = bold_on .. font_red .. + translate("Binding to a specific network not supported") .. font_off .. "<br />" .. + translate("please set to 'default'") .. " !" .. bold_off + else + self.description = translate("OPTIONAL: Network to use for communication") .. + "<br />" .. translate("Casual users should not change this setting") + end + return value + end + function bnet.validate(self, value) + if (value ~= "" and has_ssl ) or value == "" then return value end + return nil, err_tab_adv(self) .. translate("Binding to a specific network not supported") .. " !" + end +end + -- IPv4 + IPv6 - force_ipversion (NEW) -- ###################################### -- optional to force wget/curl and host to use only selected IP version -- command parameter "-4" or "-6" @@ -1198,7 +1230,7 @@ lv.inputtitle = translate("Read / Reread log file") lv.rows = 50 function lv.cfgvalue(self, section) local lfile=log_dir .. "/" .. section .. ".log" - if FS.access(lfile) then + if NXFS.access(lfile) then return lfile .. "\n" .. translate("Please press [Read] button") end return lfile .. "\n" .. translate("File not found or empty") diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua new file mode 100644 index 0000000000..32ca5418ef --- /dev/null +++ b/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua @@ -0,0 +1,159 @@ +-- Copyright 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com> +-- Licensed to the public under the Apache License 2.0. + +local NX = require "nixio" +local NXFS = require "nixio.fs" +local DISP = require "luci.dispatcher" +local SYS = require "luci.sys" +local DDNS = require "luci.tools.ddns" -- ddns multiused functions + +-- Bootstrap theme needs 2 or 3 additional linefeeds for tab description for better optic +local LFLF = (DDNS.get_theme() == "Bootstrap") and [[<br /><br />]] or [[]] + +-- cbi-map definition -- ####################################################### +local m = Map("ddns") + +-- first need to close <a> from cbi map template our <a> closed by template +m.title = [[</a><a href="]] .. DISP.build_url("admin", "services", "ddns") .. [[">]] + .. 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 = DISP.build_url("admin", "services", "ddns") + +function m.commit_handler(self) + if self.changed then -- changes ? + os.execute("/etc/init.d/ddns reload &") -- reload configuration + end +end + +-- cbi-section definition -- ################################################### +local ns = m:section( NamedSection, "global", "ddns", + translate("Global Settings"), + translate("Configure here the details for all Dynamic DNS services including this LuCI application.") + .. [[<br /><strong>]] + .. translate("It is NOT recommended for casual users to change settings on this page.") + .. [[</strong><br />]] + .. [[<a href="http://wiki.openwrt.org/doc/uci/ddns#version_2x1" target="_blank">]] + .. translate("For detailed information about parameter settings look here.") + .. [[</a>]] + .. LFLF ) +-- section might not exist +function ns.cfgvalue(self, section) + if not self.map:get(section) then + self.map:set(section, nil, self.sectiontype) + end + return self.map:get(section) +end + +-- allow_local_ip -- ########################################################## +local ali = ns:option(Flag, "allow_local_ip") +ali.title = translate("Allow non-public IP's") +ali.description = translate("Non-public and by default blocked IP's") .. ":" + .. [[<br /><strong>IPv4: </strong>]] + .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16" + .. [[<br /><strong>IPv6: </strong>]] + .. "::/32, f000::/4" +ali.reempty = true +ali.default = "0" +function ali.parse(self, section) + DDNS.flag_parse(self, section) +end +function ali.validate(self, value) + if value == self.default then + return "" -- default = empty + end + return value +end + +-- date_format -- ############################################################# +local df = ns:option(Value, "date_format") +df.title = translate("Date format") +df.description = [[<a href="http://www.cplusplus.com/reference/ctime/strftime/" target="_blank">]] + .. translate("For supported codes look here") + .. [[</a>]] +df.template = "ddns/global_value" +df.rmempty = true +df.default = "%F %R" +df.date_string = "" +function df.cfgvalue(self, section) + local value = AbstractValue.cfgvalue(self, section) or self.default + local epoch = os.time() + self.date_string = DDNS.epoch2date(epoch, value) + return value +end +function df.validate(self, value) + if value == self.default then + return "" -- default = empty + end + return value +end + +-- run_dir -- ################################################################# +local rd = ns:option(Value, "run_dir") +rd.title = translate("Status directory") +rd.description = translate("Directory contains PID and other status information for each running section") +rd.rmempty = true +rd.default = "/var/run/ddns" +function rd.validate(self, value) + if value == self.default then + return "" -- default = empty + end + return value +end + +-- log_dir -- ################################################################# +local ld = ns:option(Value, "log_dir") +ld.title = translate("Log directory") +ld.description = translate("Directory contains Log files for each running section") +ld.rmempty = true +ld.default = "/var/log/ddns" +function ld.validate(self, value) + if value == self.default then + return "" -- default = empty + end + return value +end + +-- log_lines -- ############################################################### +local ll = ns:option(Value, "log_lines") +ll.title = translate("Log length") +ll.description = translate("Number of last lines stored in log files") +ll.rmempty = true +ll.default = "250" +ll.datatype = "and(uinteger,min(1))" +function ll.validate(self, value) + local n = tonumber(value) + if not n or math.floor(n) ~= n or n < 1 then + return nil, self.title .. ": " .. translate("minimum value '1'") + end + if value == self.default then + return "" -- default = empty + end + return value +end + +-- use_curl -- ################################################################ +if (SYS.call([[ grep -i "\+ssl" /usr/bin/wget >/dev/null 2>&1 ]]) == 0) +and NXFS.access("/usr/bin/curl") then + local pc = ns:option(Flag, "use_curl") + pc.title = translate("Use cURL") + pc.description = translate("If both cURL and GNU Wget are installed, Wget is used by default.") + .. [[<br />]] + .. translate("To use cURL activate this option.") + pc.orientation = "horizontal" + pc.rmempty = true + pc.default = "0" + function pc.parse(self, section) + DDNS.flag_parse(self, section) + end + function pc.validate(self, value) + if value == self.default then + return "" -- default = empty + end + return value + end +end + +return m diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua index 009ba99eb8..ff7aa7a41c 100644 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua +++ b/applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua @@ -8,7 +8,7 @@ local DDNS = require "luci.tools.ddns" -- ddns multiused functions -- check supported options -- ################################################## -- saved to local vars here because doing multiple os calls slow down the system -has_ssl = DDNS.check_ssl() -- HTTPS support +has_ssl = DDNS.check_ssl() -- HTTPS support and --bind-network / --interface has_proxy = DDNS.check_proxy() -- Proxy support has_dnstcp = DDNS.check_bind_host() -- DNS TCP support -- correct ddns-scripts version @@ -88,6 +88,22 @@ if not has_ssl then translate("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.") end +-- No bind_network +if not has_ssl then + local dv = s:option(DummyValue, "_no_bind_network") + dv.titleref = DISP.build_url("admin", "system", "packages") + dv.rawhtml = true + dv.title = bold_on .. + translate("Binding to a specific network not supported") .. bold_off + dv.value = translate("Neither GNU Wget with SSL nor cURL installed to select a network to use for communication.") .. + "<br />- " .. + translate("You should install GNU Wget with SSL or cURL package.") .. + "<br />- " .. + translate("GNU Wget will use the IP of given network, cURL will use the physical interface.") .. + "<br />- " .. + translate("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.") +end + -- cURL without proxy support if has_ssl and not has_proxy then local dv = s:option(DummyValue, "_no_proxy") diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua index 83b10e9366..9e8df2d089 100644 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua +++ b/applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua @@ -27,8 +27,6 @@ bold_off = [[</strong>]] m = Map("ddns") -- first need to close <a> from cbi map template our <a> closed by template ---m.title = [[</a><a href="javascript:alert(']] .. CTRL.show_versions() ..[[')">]] .. --- translate("Dynamic DNS") m.title = [[</a><a href="javascript:alert(']] .. translate("Version Information") .. [[\n\nluci-app-ddns]] @@ -109,9 +107,13 @@ end -- TableSection definition -- ################################################## ts = m:section( TypedSection, "service", translate("Overview"), - translate("Below is a list of configured DDNS configurations and their current state." .. "<br />" .. - "If you want to send updates for IPv4 and IPv6 you need to define two separate Configurations " .. - "i.e. 'myddns_ipv4' and 'myddns_ipv6'") ) + translate("Below is a list of configured DDNS configurations and their current state.") + .. "<br />" + .. translate("If you want to send updates for IPv4 and IPv6 you need to define two separate Configurations " + .. "i.e. 'myddns_ipv4' and 'myddns_ipv6'") + .. "<br />" + .. [[<a href="]] .. DISP.build_url("admin", "services", "ddns", "global") .. [[">]] + .. translate("To change global settings click here") .. [[</a>]] ) ts.sectionhead = translate("Configuration") ts.template = "cbi/tblsection" ts.addremove = true |