diff options
Diffstat (limited to 'applications/luci-app-ddns/luasrc/controller/ddns.lua')
-rwxr-xr-x | applications/luci-app-ddns/luasrc/controller/ddns.lua | 106 |
1 files changed, 58 insertions, 48 deletions
diff --git a/applications/luci-app-ddns/luasrc/controller/ddns.lua b/applications/luci-app-ddns/luasrc/controller/ddns.lua index 63bb8bf4be..e152bb0d98 100755 --- a/applications/luci-app-ddns/luasrc/controller/ddns.lua +++ b/applications/luci-app-ddns/luasrc/controller/ddns.lua @@ -1,7 +1,7 @@ -- Copyright 2008 Steven Barth <steven@midlink.org> -- Copyright 2008 Jo-Philipp Wich <jow@openwrt.org> -- Copyright 2013 Manuel Munz <freifunk at somakoma dot de> --- Copyright 2014-2016 Christian Schoenebeck <christian dot schoenebeck at gmail dot com> +-- Copyright 2014-2018 Christian Schoenebeck <christian dot schoenebeck at gmail dot com> -- Licensed to the public under the Apache License 2.0. module("luci.controller.ddns", package.seeall) @@ -20,16 +20,14 @@ local DDNS = require "luci.tools.ddns" -- ddns multiused functions luci_helper = "/usr/lib/ddns/dynamic_dns_lucihelper.sh" local srv_name = "ddns-scripts" -local srv_ver_min = "2.7.6" -- minimum version of service required -local srv_ver_cmd = luci_helper .. [[ -V | awk {'print $2'}]] +local srv_ver_min = "2.7.7" -- minimum version of service required local app_name = "luci-app-ddns" local app_title = "Dynamic DNS" -local app_version = "2.4.8-1" +local app_version = "2.4.9-1" function index() local nxfs = require "nixio.fs" -- global definitions not available local sys = require "luci.sys" -- in function index() - local ddns = require "luci.tools.ddns" -- ddns multiused functions local muci = require "luci.model.uci" -- no config create an empty one @@ -81,33 +79,40 @@ end -- Standardized application/service functions function app_title_main() - return [[<a href="javascript:alert(']] - .. I18N.translate("Version Information") - .. [[\n\n]] .. app_name - .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] .. app_version - .. [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("required") .. [[:]] - .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] - .. srv_ver_min .. [[ ]] .. I18N.translate("or higher") - .. [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("installed") .. [[:]] - .. [[\n\t]] .. I18N.translate("Version") .. [[:\t]] - .. (service_version() or I18N.translate("NOT installed")) - .. [[\n\n]] - .. [[')">]] - .. I18N.translate(app_title) - .. [[</a>]] + tmp = {} + tmp[#tmp+1] = [[<a href="javascript:alert(']] + tmp[#tmp+1] = I18N.translate("Version Information") + tmp[#tmp+1] = [[\n\n]] .. app_name + tmp[#tmp+1] = [[\n]] .. I18N.translate("Version") .. [[: ]] .. app_version + tmp[#tmp+1] = [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("required") .. [[:]] + tmp[#tmp+1] = [[\n]] .. I18N.translate("Version") .. [[: ]] + tmp[#tmp+1] = srv_ver_min .. [[ ]] .. I18N.translate("or higher") + tmp[#tmp+1] = [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("installed") .. [[:]] + tmp[#tmp+1] = [[\n]] .. I18N.translate("Version") .. [[: ]] + tmp[#tmp+1] = (service_version() or I18N.translate("NOT installed")) + tmp[#tmp+1] = [[\n\n]] + tmp[#tmp+1] = [[')">]] + tmp[#tmp+1] = I18N.translate(app_title) + tmp[#tmp+1] = [[</a>]] + + return table.concat(tmp) end -function service_version() - local ver = nil - ver = UTIL.exec(srv_ver_cmd) - if #ver > 0 then return ver end - - IPKG.list_installed(srv_name, function(n, v, d) - if v and (#v > 0) then ver = v end - end - ) - return ver +function service_version() + + local srv_ver_cmd = luci_helper .. " -V | awk {'print $2'} " + local ver + + if IPKG then + ver = IPKG.info(srv_name)[srv_name].Version + else + ver = UTIL.exec(srv_ver_cmd) + end + + if ver and #ver > 0 then return ver or nil end + end + function service_ok() return IPKG.compare_versions((service_version() or "0"), ">=", srv_ver_min) end @@ -180,28 +185,33 @@ local function _get_status() end -- get/set monitored interface and IP version - local iface = s["interface"] or "_nonet_" + local iface = s["interface"] or "wan" local use_ipv6 = tonumber(s["use_ipv6"]) or 0 - if iface ~= "_nonet_" then - local ipv = (use_ipv6 == 1) and "IPv6" or "IPv4" - iface = ipv .. " / " .. iface - end + local ipv = (use_ipv6 == 1) and "IPv6" or "IPv4" + iface = ipv .. " / " .. iface -- try to get registered IP local lookup_host = s["lookup_host"] or "_nolookup_" - local dnsserver = s["dns_server"] or "" - local force_ipversion = tonumber(s["force_ipversion"] or 0) - local force_dnstcp = tonumber(s["force_dnstcp"] or 0) - local is_glue = tonumber(s["is_glue"] or 0) - local command = luci_helper .. [[ -]] - if (use_ipv6 == 1) then command = command .. [[6]] end - if (force_ipversion == 1) then command = command .. [[f]] end - if (force_dnstcp == 1) then command = command .. [[t]] end - if (is_glue == 1) then command = command .. [[g]] end - command = command .. [[l ]] .. lookup_host - if (#dnsserver > 0) then command = command .. [[ -d ]] .. dnsserver end - command = command .. [[ -- get_registered_ip]] - local reg_ip = SYS.exec(command) + local chk_sec = DDNS.calc_seconds( + tonumber(s["check_interval"]) or 10, + s["check_unit"] or "minutes" ) + local reg_ip = DDNS.get_regip(section, chk_sec) + if reg_ip == "NOFILE" then + local dnsserver = s["dns_server"] or "" + local force_ipversion = tonumber(s["force_ipversion"] or 0) + local force_dnstcp = tonumber(s["force_dnstcp"] or 0) + local is_glue = tonumber(s["is_glue"] or 0) + local command = luci_helper .. [[ -]] + if (use_ipv6 == 1) then command = command .. [[6]] end + if (force_ipversion == 1) then command = command .. [[f]] end + if (force_dnstcp == 1) then command = command .. [[t]] end + if (is_glue == 1) then command = command .. [[g]] end + command = command .. [[l ]] .. lookup_host + command = command .. [[ -S ]] .. section + if (#dnsserver > 0) then command = command .. [[ -d ]] .. dnsserver end + command = command .. [[ -- get_registered_ip]] + reg_ip = SYS.exec(command) + end if reg_ip == "" then reg_ip = "_nodata_" end @@ -296,7 +306,7 @@ function startstop(section, enabled) uci:unload("ddns") -- start ddns-updater for section - local command = luci_helper .. [[ -S ]] .. section .. [[ -- start]] + local command = "%s -S %s -- start" %{ luci_helper, UTIL.shellquote(section) } os.execute(command) NX.nanosleep(3) -- 3 seconds "show time" |