--- Copyright 2014 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
+-- Copyright 2014-2016 Christian Schoenebeck <christian dot schoenebeck at gmail dot com>
-- Licensed to the public under the Apache License 2.0.
local NXFS = require "nixio.fs"
local CTRL = require "luci.controller.ddns" -- this application's controller
local DDNS = require "luci.tools.ddns" -- ddns multiused functions
--- show hints ?
-show_hints = not (DDNS.check_ipv6() -- IPv6 support
- and DDNS.check_ssl() -- HTTPS support
- and DDNS.check_proxy() -- Proxy support
- and DDNS.check_bind_host() -- DNS TCP support
+local show_hints = not (DDNS.has_ipv6 -- IPv6 support
+ and DDNS.has_ssl -- HTTPS support
+ and DDNS.has_proxy -- Proxy support
+ and DDNS.has_bindhost -- DNS TCP support
+ and DDNS.has_forceip -- Force IP version
+ and DDNS.has_dnsserver -- DNS server support
+ and DDNS.has_bindnet -- Bind to network/interface
+ and DDNS.has_cacerts -- certificates installed at /etc/ssl/certs
)
--- correct ddns-scripts version
-need_update = not CTRL.service_ok()
+local not_enabled = not SYS.init.enabled("ddns")
+local need_update = not CTRL.service_ok()
-- html constants
font_red = [[<font color="red">]]
m.on_after_commit = function(self)
if self.changed then -- changes ?
+ local command = CTRL.luci_helper
if SYS.init.enabled("ddns") then -- ddns service enabled, restart all
- os.execute("/etc/init.d/ddns restart")
+ command = command .. " -- restart"
+ os.execute(command)
else -- ddns service disabled, send SIGHUP to running
- os.execute("killall -1 dynamic_dns_updater.sh")
+ command = command .. " -- reload"
+ os.execute(command)
end
end
end
--- SimpleSection definiton -- ##################################################
+-- SimpleSection definition -- ##################################################
-- with all the JavaScripts we need for "a good Show"
a = m:section( SimpleSection )
a.template = "ddns/overview_status"
-- SimpleSection definition -- #################################################
-- show Hints to optimize installation and script usage
--- only show if service not enabled
--- or no IPv6 support
--- or not GNU Wget and not cURL (for https support)
--- or not GNU Wget but cURL without proxy support
--- or not BIND's host
--- or ddns-scripts package need update
-if show_hints or need_update or not SYS.init.enabled("ddns") then
+if show_hints or need_update or not_enabled then
+
s = m:section( SimpleSection, translate("Hints") )
- -- ddns_scripts needs to be updated for full functionality
+ -- ddns-scripts needs to be updated for full functionality
if need_update then
local dv = s:option(DummyValue, "_update_needed")
dv.titleref = DISP.build_url("admin", "system", "packages")
end
-- DDNS Service disabled
- if not SYS.init.enabled("ddns") then
+ if not_enabled then
local dv = s:option(DummyValue, "_not_enabled")
dv.titleref = DISP.build_url("admin", "system", "startup")
dv.rawhtml = true
-- TableSection definition -- ##################################################
ts = m:section( TypedSection, "service",
translate("Overview"),
- 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 />"
+ 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")
end
end
function dom.set_two(self, section)
- local lookup = self.map:get(section, "lookup_host") or ""
- if lookup == "" then return "" end
+ local lookup_host = self.map:get(section, "lookup_host") or ""
+ if lookup_host == "" then return "" end
local dnsserver = self.map:get(section, "dnsserver") or ""
local use_ipv6 = tonumber(self.map:get(section, "use_ipv6") or 0)
local force_ipversion = tonumber(self.map:get(section, "force_ipversion") or 0)
local force_dnstcp = tonumber(self.map:get(section, "force_dnstcp") or 0)
- local command = [[/usr/lib/ddns/dynamic_dns_lucihelper.sh]]
- if not NXFS.access(command, "rwx", "rx", "rx") then
- NXFS.chmod(command, 755)
- end
- command = command .. [[ get_registered_ip ]] .. lookup .. [[ ]] .. use_ipv6 ..
- [[ ]] .. force_ipversion .. [[ ]] .. force_dnstcp .. [[ ]] .. dnsserver
+ local is_glue = tonumber(self.map:get(section, "is_glue") or 0)
+ local command = CTRL.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 ip = SYS.exec(command)
if ip == "" then ip = translate("no data") end
return ip