luci-app-ddns: rework with new ddns changes

This commit rework the app with the new ddns changes. DDns services are now stored in a dedicated list and the service specific data is stored in a dedicated json. This json can both preinstalled with a companion package or be downloaded on demand. The new app now check if the script is present and give a button to install it if not present in the system.
The app now will search for all the available service in the services directory and optionally if present will include in the list the service not installed from a static list. Special service that use a separate script (for example cloudflare-v4) will install directly in the services directory and will be included automatically.
The app now reset the ddns rule settings on service change.
Also rework the app to drop any global function and rework the function to use more default way to get data.

Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com>
This commit is contained in:
Ansuel Smith 2020-09-30 13:40:06 +02:00
parent 1da9df8376
commit e478875c6c
No known key found for this signature in database
GPG key ID: AC001D09ADBFEAD7
3 changed files with 780 additions and 583 deletions

View file

@ -7,6 +7,7 @@ local UCI = require "luci.model.uci"
local sys = require "luci.sys"
local util = require "luci.util"
local ddns_package_path = "/usr/share/ddns"
local luci_helper = "/usr/lib/ddns/dynamic_dns_lucihelper.sh"
local srv_name = "ddns-scripts"
@ -155,6 +156,7 @@ local methods = {
local ipkg = require "luci.model.ipkg"
local uci = UCI.cursor()
local dateformat = uci:get("ddns", "global", "ddns_dateformat") or "%F %R"
local services_mtime = fs.stat(ddns_package_path .. "/list", 'mtime')
uci:unload("ddns")
local ver, srv_ver_cmd
local res = {}
@ -169,6 +171,7 @@ local methods = {
res['_version'] = ver and #ver > 0 and ver or nil
res['_enabled'] = sys.init.enabled("ddns")
res['_curr_dateformat'] = os.date(dateformat)
res['_services_list'] = services_mtime and os.date(dateformat, services_mtime) or 'NO_LIST'
return res
end

View file

@ -7,8 +7,12 @@
"luci": [ "setInitAction" ]
},
"file": {
"/etc/ddns/services": [ "read" ],
"/etc/ddns/services_ipv6": [ "read" ],
"/usr/share/ddns/default": [ "list" ],
"/usr/share/ddns/default/*": [ "read" ],
"/usr/share/ddns/custom": [ "list" ],
"/usr/share/ddns/custom/*": [ "read" ],
"/usr/share/ddns/list": [ "read" ],
"/usr/bin/ddns": [ "exec" ],
"/usr/lib/ddns/dynamic_dns_lucihelper.sh": [ "exec" ]
},
"uci": [ "ddns" ]