X-Git-Url: http://git.archive.openwrt.org/?a=blobdiff_plain;f=applications%2Fluci-app-ddns%2Fluasrc%2Ftools%2Fddns.lua;h=690b9b30ceb57d62a1ef3bce90917326e229d5ac;hb=e386d76d57f038b432d10f5caae450237b316ac1;hp=e55c673629b5734e249dd35b381e0533f7387afc;hpb=ddb98f186f2c63f7d5f48be6dc1d4d966a0adbab;p=project%2Fluci.git diff --git a/applications/luci-app-ddns/luasrc/tools/ddns.lua b/applications/luci-app-ddns/luasrc/tools/ddns.lua index e55c67362..690b9b30c 100755 --- a/applications/luci-app-ddns/luasrc/tools/ddns.lua +++ b/applications/luci-app-ddns/luasrc/tools/ddns.lua @@ -1,4 +1,4 @@ --- Copyright 2014-2016 Christian Schoenebeck +-- Copyright 2014-2018 Christian Schoenebeck -- Licensed to the public under the Apache License 2.0. module("luci.tools.ddns", package.seeall) @@ -57,7 +57,7 @@ end function epoch2date(epoch, format) if not format or #format < 2 then local uci = UCI.cursor() - format = uci:get("ddns", "global", "date_format") or "%F %R" + format = uci:get("ddns", "global", "ddns_dateformat") or "%F %R" uci:unload("ddns") end format = format:gsub("%%n", "
") -- replace newline @@ -67,18 +67,35 @@ end -- read lastupdate from [section].update file function get_lastupd(section) - local uci = UCI.cursor() - local run_dir = uci:get("ddns", "global", "run_dir") or "/var/run/ddns" - local etime = tonumber(NXFS.readfile("%s/%s.update" % { run_dir, section } ) or 0 ) + local uci = UCI.cursor() + local rdir = uci:get("ddns", "global", "ddns_rundir") or "/var/run/ddns" + local etime = tonumber(NXFS.readfile("%s/%s.update" % { rdir, section } ) or 0 ) uci:unload("ddns") return etime end +-- read registered IP from [section].ip file +function get_regip(section, chk_sec) + local uci = UCI.cursor() + local rdir = uci:get("ddns", "global", "ddns_rundir") or "/var/run/ddns" + local ip = "NOFILE" + if NXFS.access("%s/%s.ip" % { rdir, section }) then + local ftime = NXFS.stat("%s/%s.ip" % { rdir, section }, "ctime") or 0 + local otime = os.time() + -- give ddns-scripts time (9 sec) to update file + if otime < (ftime + chk_sec + 9) then + ip = NXFS.readfile("%s/%s.ip" % { rdir, section }) + end + end + uci:unload("ddns") + return ip +end + -- read PID from run file and verify if still running function get_pid(section) - local uci = UCI.cursor() - local run_dir = uci:get("ddns", "global", "run_dir") or "/var/run/ddns" - local pid = tonumber(NXFS.readfile("%s/%s.pid" % { run_dir, section } ) or 0 ) + local uci = UCI.cursor() + local rdir = uci:get("ddns", "global", "ddns_rundir") or "/var/run/ddns" + local pid = tonumber(NXFS.readfile("%s/%s.pid" % { rdir, section } ) or 0 ) if pid > 0 and not NX.kill(pid, 0) then pid = 0 end