diff options
author | Hannu Nyman <hannu.nyman@iki.fi> | 2018-06-02 21:11:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-02 21:11:51 +0300 |
commit | 660e4f5504b91a7b5c51a6abb80d52c65b8528d2 (patch) | |
tree | eb3ee27c5b914723ce83c06a84254924e0a00a26 /applications/luci-app-ddns/luasrc/controller/ddns.lua | |
parent | 18b5b068c87104cb5997ba84133f6bdf2d136aaa (diff) | |
parent | 299121fc84b1e00650c9c976c0a847cd67e46eb0 (diff) |
Merge pull request #1819 from Ansuel/ddns-performance
luci-app-ddns: improve performance
Diffstat (limited to 'applications/luci-app-ddns/luasrc/controller/ddns.lua')
-rwxr-xr-x | applications/luci-app-ddns/luasrc/controller/ddns.lua | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/applications/luci-app-ddns/luasrc/controller/ddns.lua b/applications/luci-app-ddns/luasrc/controller/ddns.lua index 5f4a5118c3..bfd7a2a414 100755 --- a/applications/luci-app-ddns/luasrc/controller/ddns.lua +++ b/applications/luci-app-ddns/luasrc/controller/ddns.lua @@ -21,7 +21,6 @@ luci_helper = "/usr/lib/ddns/dynamic_dns_lucihelper.sh" local srv_name = "ddns-scripts" local srv_ver_min = "2.7.7" -- minimum version of service required -local srv_ver_cmd = luci_helper .. [[ -V | awk {'print $2'}]] local app_name = "luci-app-ddns" local app_title = "Dynamic DNS" local app_version = "2.4.9-1" @@ -29,7 +28,6 @@ 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,26 +79,41 @@ 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\t]] .. I18N.translate("Version") .. [[:\t]] .. app_version + tmp[#tmp+1] = [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("required") .. [[:]] + tmp[#tmp+1] = [[\n\t]] .. I18N.translate("Version") .. [[:\t]] + tmp[#tmp+1] = srv_ver_min .. [[ ]] .. I18N.translate("or higher") + tmp[#tmp+1] = [[\n\n]] .. srv_name .. [[ ]] .. I18N.translate("installed") .. [[:]] + tmp[#tmp+1] = [[\n\t]] .. I18N.translate("Version") .. [[:\t]] + 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 + local nxfs = require "nixio.fs" + + local ver = nil + local ver_helper + + if nxfs.access("/bin/opkg") then + ver_helper = "/bin/opkg info " .. srv_name .. " | grep 'Version'" + else + ver_helper = luci_helper .. " -V" + end + + local srv_ver_cmd = ver_helper .. " | awk {'print $2'} " + ver = UTIL.exec(srv_ver_cmd) - if #ver > 0 then return ver end + if ver and #ver > 0 then return ver end IPKG.list_installed(srv_name, function(n, v, d) if v and (#v > 0) then ver = v end @@ -108,6 +121,7 @@ function service_version() ) return ver end + function service_ok() return IPKG.compare_versions((service_version() or "0"), ">=", srv_ver_min) end |