From 8b0f83264a5d33078eaca1f15de226cc7f984f59 Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Tue, 10 Feb 2015 21:49:57 +0100 Subject: 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 --- .../luci-app-ddns/luasrc/model/cbi/ddns/detail.lua | 62 ++++++-- .../luci-app-ddns/luasrc/model/cbi/ddns/global.lua | 159 +++++++++++++++++++++ .../luci-app-ddns/luasrc/model/cbi/ddns/hints.lua | 18 ++- .../luasrc/model/cbi/ddns/overview.lua | 12 +- 4 files changed, 230 insertions(+), 21 deletions(-) create mode 100644 applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua (limited to 'applications/luci-app-ddns/luasrc/model') 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_off = "" -bold_on = "" -bold_off = "" +local LFLF = (DDNS.get_theme() == "Bootstrap") and [[

]] or [[]] +local font_red = "" +local font_off = "" +local bold_on = "" +local bold_off = "" -- 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") .. ([[: %s]] % section), - translate("Configure here the details for selected Dynamic DNS service") ) + translate("Configure here the details for selected Dynamic DNS service.") + .. [[
]] + .. translate("For detailed information about parameter settings look here.") + .. [[]] ) 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 .. "
" .. + translate("please set to 'default'") .. " !" .. bold_off + else + self.description = translate("OPTIONAL: Network to use for communication") .. + "
" .. 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 +-- 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 [[

]] or [[]] + +-- cbi-map definition -- ####################################################### +local m = Map("ddns") + +-- 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 = 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.") + .. [[
]] + .. translate("It is NOT recommended for casual users to change settings on this page.") + .. [[
]] + .. [[
]] + .. translate("For detailed information about parameter settings look here.") + .. [[]] + .. 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") .. ":" + .. [[
IPv4: ]] + .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16" + .. [[
IPv6: ]] + .. "::/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 = [[]] + .. translate("For supported codes look here") + .. [[]] +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.") + .. [[
]] + .. 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.") .. + "
- " .. + translate("You should install GNU Wget with SSL or cURL package.") .. + "
- " .. + translate("GNU Wget will use the IP of given network, cURL will use the physical interface.") .. + "
- " .. + 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 = [[]] m = Map("ddns") -- first need to close from cbi map template our closed by template ---m.title = [[]] .. --- translate("Dynamic DNS") m.title = [[" .. - "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.") + .. "
" + .. 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'") + .. "
" + .. [[
]] + .. translate("To change global settings click here") .. [[]] ) ts.sectionhead = translate("Configuration") ts.template = "cbi/tblsection" ts.addremove = true -- cgit v1.2.3 From df0590972345e6862817e53a38c73925596aaf63 Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Sun, 1 Mar 2015 20:08:45 +0100 Subject: luci-app-ddns: patches for #298 #334 #335 * remove usage of opkg via system call for version handling thanks to Jo-Philipp Wich #335 * remove special handling of bootstrap theme #298 #334 Signed-off-by: Christian Schoenebeck --- applications/luci-app-ddns/Makefile | 20 +++--- .../luci-app-ddns/luasrc/model/cbi/ddns/detail.lua | 3 +- .../luci-app-ddns/luasrc/model/cbi/ddns/global.lua | 5 +- applications/luci-app-ddns/luasrc/tools/ddns.lua | 82 +++++++++++++++------- 4 files changed, 67 insertions(+), 43 deletions(-) (limited to 'applications/luci-app-ddns/luasrc/model') diff --git a/applications/luci-app-ddns/Makefile b/applications/luci-app-ddns/Makefile index db1da2c7c7..f20b49e902 100644 --- a/applications/luci-app-ddns/Makefile +++ b/applications/luci-app-ddns/Makefile @@ -6,16 +6,11 @@ include $(TOPDIR)/rules.mk -# LuCI specific settings -LUCI_TITLE:=LuCI Support for Dynamic DNS Client (ddns-scripts) -LUCI_DEPENDS:=+luci-mod-admin-full +ddns-scripts -LUCI_PKGARCH:=all - PKG_NAME:=luci-app-ddns # Version == major.minor.patch # increase on new functionality (minor) or patches (patch) -PKG_VERSION:=2.2.0 +PKG_VERSION:=2.2.1 # Release == build # increase on changes of translation files @@ -24,15 +19,20 @@ PKG_RELEASE:=1 PKG_LICENSE:=Apache-2.0 PKG_MAINTAINER:=Christian Schoenebeck +# LuCI specific settings +LUCI_TITLE:=LuCI Support for Dynamic DNS Client (ddns-scripts) +LUCI_DEPENDS:=+luci-mod-admin-full +ddns-scripts +LUCI_PKGARCH:=all + define Package/$(PKG_NAME)/config # shown in make menuconfig help $(LUCI_TITLE) - - Version : $(PKG_VERSION)-$(PKG_RELEASE) - Maintainer: $(PKG_MAINTAINER) + . + Version: $(PKG_VERSION)-$(PKG_RELEASE) + $(PKG_MAINTAINER) endef -include ../../luci.mk +include $(TOPDIR)/feeds/luci/luci.mk # call BuildPackage - OpenWrt buildroot signature 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 602bc159af..40a66ef152 100644 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua +++ b/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua @@ -1,7 +1,7 @@ -- Copyright 2008 Steven Barth -- Copyright 2008 Jo-Philipp Wich -- Copyright 2013 Manuel Munz --- Copyright 2014 Christian Schoenebeck +-- Copyright 2014-2015 Christian Schoenebeck -- Licensed to the public under the Apache License 2.0. local NX = require "nixio" @@ -25,7 +25,6 @@ local has_dnstcp = DDNS.check_bind_host() -- DNS TCP support local has_force = has_ssl and has_dnstcp -- Force IP Protocoll -- html constants -- ########################################################### -local LFLF = (DDNS.get_theme() == "Bootstrap") and [[

]] or [[]] local font_red = "" local font_off = "" local bold_on = "" diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua index 32ca5418ef..e1718739f9 100644 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua +++ b/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua @@ -7,9 +7,6 @@ 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 [[

]] or [[]] - -- cbi-map definition -- ####################################################### local m = Map("ddns") @@ -38,7 +35,7 @@ local ns = m:section( NamedSection, "global", "ddns", .. [[]] .. translate("For detailed information about parameter settings look here.") .. [[]] - .. LFLF ) + -- section might not exist function ns.cfgvalue(self, section) if not self.map:get(section) then diff --git a/applications/luci-app-ddns/luasrc/tools/ddns.lua b/applications/luci-app-ddns/luasrc/tools/ddns.lua index e9c3fa936a..6d53931469 100644 --- a/applications/luci-app-ddns/luasrc/tools/ddns.lua +++ b/applications/luci-app-ddns/luasrc/tools/ddns.lua @@ -100,39 +100,67 @@ end function ipkg_ver_compare(ver1, comp, ver2) if not ver1 or not (#ver1 > 0) or not ver2 or not (#ver2 > 0) - or not comp or not (#comp > 0) then - return nil + or not comp or not (#comp > 0) then 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 return nil end + + local av1 = UTIL.split(ver1, "[%.%-]", nil, true) + local av2 = UTIL.split(ver2, "[%.%-]", nil, true) + + for i = 1, math.max(table.getn(av1),table.getn(av2)), 1 do + local s1 = av1[i] or "" + local s2 = av2[i] or "" + local n1 = tonumber(s1) + local n2 = tonumber(s2) + + -- one numeric and other empty string then set other to 0 + if n1 and not n2 and (not s2 or #s2 == 0) then n2 = 0 end + if n2 and not n1 and (not s1 or #s1 == 0) then n1 = 0 end + + local nc = (n1 and n2) -- numeric compare + + if nc then + -- first "not equal" found return true + if comp == "~=" and (n1 ~= n2) then return true end + -- first "lower" found return true + if (comp == "<" or comp == "<=") and (n1 < n2) then return true end + -- first "greater" found return true + if (comp == ">" or comp == ">=") and (n1 > n2) then return true end + -- not equal then return false + if (n1 ~= n2) then return false end + else + if comp == "~=" and (s1 ~= s2) then return true end + if (comp == "<" or comp == "<=") and (s1 < s2) then return true end + if (comp == ">" or comp == ">=") and (s1 > s2) then return true end + if (s1 ~= s2) then return false end + end end - return (tonumber(SYS.call( - [[opkg compare-versions "]] .. ver1 .. [[" "]] .. comp .. [[" "]] .. ver2 .. [["]] - )) == 1) + -- all equal then true + return true end -- read version information for given package if installed function ipkg_ver_installed(pkg) - if not pkg then - return nil - end - -- opkg list-installed [pkg] | cut -d " " -f 3 - return version as sting - local ver = SYS.exec([[opkg list-installed ]] .. pkg .. [[ | cut -d " " -f 3 ]]) - if (#ver > 0) then - return ver - end - return nil -end - --- get the "name" of the current active theme -function get_theme() - local _uci = UCI.cursor() - local _base = _uci:get("luci", "main", "mediaurlbase") -- only pathname - _uci:unload("luci") - - for k, v in pairs(luci.config.themes) do - if k:sub(1, 1) ~= "." and v == _base then - return k - end + local version = nil + local control = io.open("/usr/lib/opkg/info/%s.control" % pkg, "r") + if control then + local ln + repeat + ln = control:read("*l") + if ln and ln:match("^Version: ") then + version = ln:gsub("^Version: ", "") + break + end + until not ln + control:close() end - return nil + return version end -- replacement of build-in read of UCI option -- cgit v1.2.3 From 39029888782ce7ea6862cbdfd4322e8b6b14843e Mon Sep 17 00:00:00 2001 From: Christian Schoenebeck Date: Fri, 20 Mar 2015 09:06:11 +0100 Subject: luci-app-ddns: fix errors in global.lua fix dispatcher and validation errors in global.lua Signed-off-by: Christian Schoenebeck --- applications/luci-app-ddns/Makefile | 2 +- applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'applications/luci-app-ddns/luasrc/model') diff --git a/applications/luci-app-ddns/Makefile b/applications/luci-app-ddns/Makefile index f20b49e902..1bffcaa4b3 100644 --- a/applications/luci-app-ddns/Makefile +++ b/applications/luci-app-ddns/Makefile @@ -10,7 +10,7 @@ PKG_NAME:=luci-app-ddns # Version == major.minor.patch # increase on new functionality (minor) or patches (patch) -PKG_VERSION:=2.2.1 +PKG_VERSION:=2.2.2 # Release == build # increase on changes of translation files diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua index e1718739f9..fbd3cb3377 100644 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua +++ b/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua @@ -35,6 +35,7 @@ local ns = m:section( NamedSection, "global", "ddns", .. [[]] .. translate("For detailed information about parameter settings look here.") .. [[]] + ) -- section might not exist function ns.cfgvalue(self, section) @@ -119,7 +120,6 @@ 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 -- cgit v1.2.3