From 34fa5122f98af4ac635dfc26a64f6d2d3e4fafcb Mon Sep 17 00:00:00 2001 From: Ansuel Smith Date: Wed, 6 Nov 2019 01:33:53 +0100 Subject: [PATCH] luci-app-ddns: convert to client side implementation Signed-off-by: Ansuel Smith --- applications/luci-app-ddns/Makefile | 20 +- .../resources/view/ddns/overview.js | 994 +++++++++++ .../resources/view/status/include/70_ddns.js | 46 + .../luci-app-ddns/luasrc/controller/ddns.lua | 330 +--- .../luasrc/model/cbi/ddns/detail.lua | 1504 ----------------- .../luasrc/model/cbi/ddns/global.lua | 121 -- .../luasrc/model/cbi/ddns/hints.lua | 166 -- .../luasrc/model/cbi/ddns/overview.lua | 249 --- .../luci-app-ddns/luasrc/tools/ddns.lua | 429 ----- .../luasrc/view/admin_status/index/ddns.htm | 1 - .../luasrc/view/ddns/detail_logview.htm | 56 - .../luasrc/view/ddns/detail_lvalue.htm | 23 - .../luasrc/view/ddns/detail_value.htm | 9 - .../luasrc/view/ddns/global_value.htm | 33 - .../luasrc/view/ddns/overview_doubleline.htm | 10 - .../luasrc/view/ddns/overview_enabled.htm | 16 - .../luasrc/view/ddns/overview_startstop.htm | 17 - .../luasrc/view/ddns/overview_status.htm | 180 -- .../luasrc/view/ddns/system_status.htm | 60 - .../root/usr/libexec/rpcd/luci.ddns | 321 ++++ .../usr/share/rpcd/acl.d/luci-app-ddns.json | 17 + 21 files changed, 1380 insertions(+), 3222 deletions(-) create mode 100644 applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js create mode 100644 applications/luci-app-ddns/htdocs/luci-static/resources/view/status/include/70_ddns.js delete mode 100644 applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua delete mode 100644 applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua delete mode 100644 applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua delete mode 100644 applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua delete mode 100755 applications/luci-app-ddns/luasrc/tools/ddns.lua delete mode 100644 applications/luci-app-ddns/luasrc/view/admin_status/index/ddns.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/detail_logview.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/detail_lvalue.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/detail_value.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/global_value.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/overview_doubleline.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/overview_enabled.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/overview_startstop.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/overview_status.htm delete mode 100644 applications/luci-app-ddns/luasrc/view/ddns/system_status.htm create mode 100644 applications/luci-app-ddns/root/usr/libexec/rpcd/luci.ddns create mode 100644 applications/luci-app-ddns/root/usr/share/rpcd/acl.d/luci-app-ddns.json diff --git a/applications/luci-app-ddns/Makefile b/applications/luci-app-ddns/Makefile index 5084c88e42..3fe679d9cb 100644 --- a/applications/luci-app-ddns/Makefile +++ b/applications/luci-app-ddns/Makefile @@ -8,30 +8,12 @@ include $(TOPDIR)/rules.mk -# PKG_NAME:=luci-app-ddns - -# Version == major.minor.patch -# increase on new functionality (minor) or patches (patch) -PKG_VERSION:=2.4.9 - -# Release == build -# increase on changes of translation files -PKG_RELEASE:=7 - PKG_LICENSE:=Apache-2.0 PKG_MAINTAINER:=Ansuel Smith -# LuCI specific settings LUCI_TITLE:=LuCI Support for Dynamic DNS Client (ddns-scripts) LUCI_DEPENDS:=+luci-compat +luci-lib-ipkg +luci-mod-admin-full +ddns-scripts -# LUCI_PKGARCH:=all - -define Package/$(PKG_NAME)/config -# shown in make menuconfig -help - $(LUCI_TITLE) - Version: $(PKG_VERSION)-$(PKG_RELEASE) -endef +LUCI_PKGARCH:=all include ../../luci.mk diff --git a/applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js b/applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js new file mode 100644 index 0000000000..f19445366c --- /dev/null +++ b/applications/luci-app-ddns/htdocs/luci-static/resources/view/ddns/overview.js @@ -0,0 +1,994 @@ +'use strict'; +'require uci'; +'require rpc'; +'require fs'; +'require form'; +'require tools.widgets as widgets'; + +var callGetLogServices, callInitAction, callDDnsGetStatus; + +var NextUpdateStrings = {}; + +NextUpdateStrings = { + 'Verify' : _("Verify"), + 'Run once' : _("Run once"), + 'Disabled' : _("Disabled"), + 'Stopped' : _("Stopped") +} + +var time_res = {}; +time_res['seconds'] = 1; +time_res['minutes'] = 60; +time_res['hours'] = 3600; + +callGetLogServices = rpc.declare({ + object: 'luci.ddns', + method: 'get_services_log', + params: [ 'service_name' ], + expect: { }, +}); + +callInitAction = rpc.declare({ + object: 'luci', + method: 'setInitAction', + params: [ 'name', 'action' ], + expect: { result: false } +}); + +callDDnsGetStatus = rpc.declare({ + object: 'luci.ddns', + method: 'get_ddns_state', + expect: { } +}); + +return L.view.extend({ + + callDDnsGetEnv: rpc.declare({ + object: 'luci.ddns', + method: 'get_env', + expect: { } + }), + + callDDnsGetServicesStatus: rpc.declare({ + object: 'luci.ddns', + method: 'get_services_status', + expect: { } + }), + + poll_status: function(map, data) { + var status = data[1] || [], service = data[0] || [], rows = map.querySelectorAll('.cbi-section-table-row[data-sid]'), + section_id, cfg_detail_ip, cfg_update, cfg_status, host, ip, last_update, + next_update, service_status, reload, cfg_enabled, stop, + ddns_enabled = map.querySelector('[data-name="_enabled"]').querySelector('.cbi-value-field'), + ddns_toggle = map.querySelector('[data-name="_toggle"]').querySelector('button'); + + ddns_toggle.innerHTML = status['_enabled'] ? _('Stop DDNS') : _('Start DDNS') + + L.dom.content(ddns_enabled, function() { + return E([], [ + E('div', {}, status['_enabled'] ? _('DDNS Autostart enabled') : [ + _('DDNS Autostart disabled'), + E('div', { 'class' : 'cbi-value-description' }, + _("Currently DDNS updates are not started at boot or on interface events.") + "
" + + _("This is the default if you run DDNS scripts by yourself (i.e. via cron with force_interval set to '0')")) + ]),]); + }); + + for (var i = 0; i < rows.length; i++) { + section_id = rows[i].getAttribute('data-sid'); + cfg_detail_ip = rows[i].querySelector('[data-name="_cfg_detail_ip"]'); + cfg_update = rows[i].querySelector('[data-name="_cfg_update"]'); + cfg_status = rows[i].querySelector('[data-name="_cfg_status"]'); + reload = rows[i].querySelector('.cbi-section-actions .reload'); + stop = rows[i].querySelector('.cbi-section-actions .stop'); + cfg_enabled = uci.get('ddns', section_id, 'enabled'); + + reload.disabled = (status['_enabled'] == 0 || cfg_enabled == 0); + + host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error'); + ip = _('No Data'); + last_update = _('Never'); + next_update = _('Unknown'); + service_status = '' + _('Not Running') + ''; + + if (service[section_id]) { + stop.disabled = (!service[section_id].pid || (service[section_id].pid && cfg_enabled == '1')); + if (service[section_id].ip) + ip = service[section_id].ip; + if (service[section_id].last_update) + last_update = service[section_id].last_update; + if (service[section_id].next_update) + next_update = NextUpdateStrings[service[section_id].next_update] || service[section_id].next_update; + if (service[section_id].pid) + service_status = '' + _('Running') + ' : ' + service[section_id].pid; + } + + cfg_detail_ip.innerHTML = host + '
' + ip; + cfg_update.innerHTML = last_update + '
' + next_update; + cfg_status.innerHTML = service_status; + } + + return; + }, + + load: function() { + return Promise.all([ + this.callDDnsGetServicesStatus(), + callDDnsGetStatus(), + this.callDDnsGetEnv(), + fs.lines('/etc/ddns/services'), + fs.lines('/etc/ddns/services_ipv6'), + uci.load('ddns') + ]); + }, + + render: function(data) { + var resolved = data[0] || []; + var status = data[1] || []; + var env = data[2] || []; + var logdir = uci.get('ddns', 'global', 'ddns_logdir') || "/var/log/ddns"; + + var services4 = []; + var services6 = []; + + data[3].forEach(function(item) { + if (!item.startsWith("#")) { + services4.push(item.split('\t')[0].slice(1,-1)); + } + }); + + data[4].forEach(function(item) { + if (!item.startsWith("#")) { + services6.push(item.split('\t')[0].slice(1,-1)); + } + }); + + var m, s, o; + + m = new form.Map('ddns', _('Dynamic DNS'),); + + var is = m.section(form.NamedSection, 'global', 'ddns', _('Information')); + + s = is; + + o = s.option(form.DummyValue, '_version', _('Dynamic DNS Version')); + o.cfgvalue = function() { + return status[this.option]; + }; + + o = s.option(form.DummyValue, '_enabled', _('State')); + o.cfgvalue = function() { + var res = status[this.option]; + if (!res) { + this.description = _("Currently DDNS updates are not started at boot or on interface events.") + "
" + + _("This is the default if you run DDNS scripts by yourself (i.e. via cron with force_interval set to '0')") + } + return res ? _('DDNS Autostart enabled') : _('DDNS Autostart disabled') + }; + + o = s.option(form.DummyValue, '_toggle', ' '); + o.cfgvalue = function() { + var action = status['_enabled'] ? 'stop' : 'start'; + return E([], [ + E('button', { + 'class': 'cbi-button cbi-button-apply', + 'click': L.ui.createHandlerFn(this, function() { + return callDDnsGetStatus().then(L.bind(function(data) { + return callInitAction('ddns', action == 'stop' ? 'disable' : 'enable').then(function() { + return callInitAction('ddns', action); + }); + }, this)).then(L.bind(m.render, m)); + }) + }, _(action.toUpperCase() + ' DDns'))]); + }; + + o = s.option(form.DummyValue, '_restart', ' '); + o.cfgvalue = function() { + return E([], [ + E('button', { + 'class': 'cbi-button cbi-button-apply', + 'click': L.ui.createHandlerFn(this, function() { + return callInitAction('ddns', 'restart').then(L.bind(m.render, m)); + }) + }, _('Restart DDns'))]); + }; + + // DDns hints + + if (!env['has_ipv6']) { + o = s.option(form.DummyValue, '_no_ipv6'); + o.rawhtml = true; + o.title = '' + _("IPv6 not supported") + ''; + o.cfgvalue = function() { return _("IPv6 is currently not (fully) supported by this system") + "
" + + _("Please follow the instructions on OpenWrt's homepage to enable IPv6 support") + "
" + + _("or update your system to the latest OpenWrt Release")}; + } + + if (!env['has_ssl']) { + o = s.option(form.DummyValue, '_no_https'); + o.titleref = L.url("admin", "system", "opkg") + o.rawhtml = true; + o.title = '' + _("HTTPS not supported") + ''; + o.cfgvalue = function() { return _("Neither GNU Wget with SSL nor cURL installed to support secure updates via HTTPS protocol.") + + "
- " + + _("You should install 'wget' or 'curl' or 'uclient-fetch' with 'libustream-*ssl' package.") + + "
- " + + _("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.")}; + } + + if (!env['has_bindnet']) { + o = s.option(form.DummyValue, '_no_bind_network'); + o.titleref = L.url("admin", "system", "opkg") + o.rawhtml = true; + o.title = '' + _("Binding to a specific network not supported") + ''; + o.cfgvalue = function() { return _("Neither GNU Wget with SSL nor cURL installed to select a network to use for communication.") + + "
- " + + _("You should install 'wget' or 'curl' package.") + + "
- " + + _("GNU Wget will use the IP of given network, cURL will use the physical interface.") + + "
- " + + _("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.")}; + } + + if (!env['has_proxy']) { + o = s.option(form.DummyValue, '_no_proxy'); + o.titleref = L.url("admin", "system", "opkg") + o.rawhtml = true; + o.title = '' + _("cURL without Proxy Support") + ''; + o.cfgvalue = function() { return _("cURL is installed, but libcurl was compiled without proxy support.") + + "
- " + + _("You should install 'wget' or 'uclient-fetch' package or replace libcurl.") + + "
- " + + _("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.")}; + } + + if (!env['has_forceip']) { + o = s.option(form.DummyValue, '_no_force_ip'); + o.titleref = L.url("admin", "system", "opkg") + o.rawhtml = true; + o.title = '' + _("Force IP Version not supported") + ''; + o.cfgvalue = function() { return _("BusyBox's nslookup and Wget do not support to specify " + + "the IP version to use for communication with DDNS Provider!") + + "
- " + _("You should install 'wget' or 'curl' or 'uclient-fetch' package.") + }; + } + + if (!env['has_bindhost']) { + o = s.option(form.DummyValue, '_no_dnstcp'); + o.titleref = L.url("admin", "system", "opkg") + o.rawhtml = true; + o.title = '' + _("DNS requests via TCP not supported") + ''; + o.cfgvalue = function() { return _("BusyBox's nslookup and hostip do not support to specify to use TCP " + + "instead of default UDP when requesting DNS server!") + + "
- " + + _("You should install 'bind-host' or 'knot-host' or 'drill' package for DNS requests.")}; + } + + if (!env['has_dnsserver']) { + o = s.option(form.DummyValue, '_no_dnsserver'); + o.titleref = L.url("admin", "system", "opkg") + o.rawhtml = true; + o.title = '' + _("Using specific DNS Server not supported") + ''; + o.cfgvalue = function() { return _("BusyBox's nslookup in the current compiled version " + + "does not handle given DNS Servers correctly!") + + "
- " + + _("You should install 'bind-host' or 'knot-host' or 'drill' or 'hostip' package, " + + "if you need to specify a DNS server to detect your registered IP.")}; + } + + if (env['has_ssl'] && !env['has_cacerts']) { + o = s.option(form.DummyValue, '_no_certs'); + o.titleref = L.url("admin", "system", "opkg") + o.rawhtml = true; + o.title = '' + _("No certificates found") + ''; + o.cfgvalue = function() { return _("If using secure communication you should verify server certificates!") + + "
- " + + _("Install 'ca-certificates' package or needed certificates " + + "by hand into /etc/ssl/certs default directory")}; + } + + // DDns services + s = m.section(form.GridSection, 'service', _('Services')); + s.anonymous = true; + s.addremove = true; + s.addbtntitle = _('Add new services...'); + + s.anonymous = true; + s.addremove = true; + s.sortable = true; + + s.handleAdd = function(ev) { + var m2 = new form.Map('ddns'), + s2 = m2.section(form.NamedSection, '_new_'); + + s2.render = function() { + return Promise.all([ + {}, + this.renderUCISection('_new_') + ]).then(this.renderContents.bind(this)); + }; + + name = s2.option(form.Value, 'name', _('Name')); + name.rmempty = false; + name.datatype = 'uciname'; + name.placeholder = _('New DDns Service…'); + name.validate = function(section_id, value) { + if (uci.get('ddns', value) != null) + return _('The service name is already used'); + + return true; + }; + + m2.render().then(L.bind(function(nodes) { + L.ui.showModal(_('Add new services...'), [ + nodes, + E('div', { 'class': 'right' }, [ + E('button', { + 'class': 'btn', + 'click': L.ui.hideModal + }, _('Cancel')), ' ', + E('button', { + 'class': 'cbi-button cbi-button-positive important', + 'click': L.ui.createHandlerFn(this, function(ev) { + var nameval = name.isValid('_new_') ? name.formvalue('_new_') : null; + + if (nameval == null || nameval == '') + return; + + return m.save(function() { + uci.add('ddns', 'service', nameval); + }).then(L.bind(m.children[1].renderMoreOptionsModal, m.children[1], nameval)); + }) + }, _('Create service')) + ]) + ], 'cbi-modal'); + + nodes.querySelector('[id="%s"] input[type="text"]'.format(name.cbid('_new_'))).focus(); + }, this)); + }; + + s.renderRowActions = function(section_id) { + var tdEl = this.super('renderRowActions', [ section_id, _('Edit') ]), + cfg_enabled = uci.get('ddns', section_id, 'enabled'), + reload_opt = { + 'class': 'cbi-button cbi-button-neutral reload', + 'click': L.ui.createHandlerFn(this, function() { + return fs.exec('/usr/lib/ddns/dynamic_dns_lucihelper.sh', + [ '-S', section_id, '--', 'start' ]).then(L.bind(m.render, m)); + }), + 'title': _('Reload this service'), + }, + stop_opt = { + 'class': 'cbi-button cbi-button-neutral stop', + 'click': L.ui.createHandlerFn(this, function() { + return fs.exec('/usr/lib/ddns/dynamic_dns_lucihelper.sh', + [ '-S', section_id, '--', 'start' ]).then(L.bind(m.render, m)); + }), + 'title': _('Stop this service'), + }; + + if (status['_enabled'] == 0 || cfg_enabled == 0) + reload_opt['disabled'] = 'disabled'; + + if (!resolved[section_id] || !resolved[section_id].pid || + (resolved[section_id].pid && cfg_enabled == '1')) + stop_opt['disabled'] = 'disabled'; + + L.dom.content(tdEl.lastChild, [ + E('button', stop_opt, _('Stop')), + E('button', reload_opt, _('Reload')), + tdEl.lastChild.childNodes[0], + tdEl.lastChild.childNodes[1], + tdEl.lastChild.childNodes[2] + ]); + + return tdEl; + }; + + o = s.option(form.DummyValue, '_cfg_name', _('Name')); + o.modalonly = false; + o.textvalue = function(section_id) { + return '' + section_id + ''; + } + + o = s.option(form.DummyValue, '_cfg_detail_ip', _('Lookup Hostname') + "
" + _('Registered IP')); + o.rawhtml = true; + o.modalonly = false; + o.textvalue = function(section_id) { + var host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error'), + ip = _('No Data'); + if (resolved[section_id] && resolved[section_id].ip) + ip = resolved[section_id].ip; + + return host + '
' + ip; + }; + + o = s.option(form.Flag, 'enabled', _('Enabled')); + o.rmempty = false; + o.editable = true; + o.modalonly = false; + + o = s.option(form.DummyValue, '_cfg_update', _('Last Update') + "
" + _('Next Update')); + o.rawhtml = true; + o.modalonly = false; + o.textvalue = function(section_id) { + var last_update = _('Never'), next_update = _('Unknown'); + if (resolved[section_id]) { + if (resolved[section_id].last_update) + last_update = resolved[section_id].last_update; + if (resolved[section_id].next_update) + next_update = NextUpdateStrings[resolved[section_id].next_update] || resolved[section_id].next_update; + } + + return last_update + '
' + next_update; + }; + + s.modaltitle = function(section_id) { + return _('DDns Service') + ' » ' + section_id; + }; + + o = s.option(form.DummyValue, '_cfg_status', _('Status')); + o.modalonly = false; + o.textvalue = function(section_id) { + var text = '' + _('Not Running') + ''; + + if (resolved[section_id] && resolved[section_id].pid) + text = '' + _('Running') + ' : ' + resolved[section_id].pid; + + return text; + } + + + s.tab('basic', _('Basic Settings')); + s.tab('advanced', _('Advanced Settings')); + s.tab('timer', _('Timer Settings')); + s.tab('logview', _('Log File Viewer')); + + // TAB: BASIC + + // enabled + o = s.taboption('basic', form.Flag, 'enabled', _('Enabled'),_("If this service section is disabled it could not be started." + "
" + + "Neither from LuCI interface nor from console")); + o.modalonly = true; + o.rmempty = false; + o.default = '1'; + + // lookup_host + + o = s.taboption('basic', form.Value, 'lookup_host', _("Lookup Hostname"), + _("Hostname/FQDN to validate, if IP update happen or necessary") ); + o.rmempty = false; + o.placeholder = "myhost.example.com"; + o.datatype = 'and(minlength(3),hostname("strict"))'; + o.modalonly = true; + + // use_ipv6 + + o = s.taboption('basic', form.ListValue, 'use_ipv6', _("IP address version"), + _("Defines which IP address 'IPv4/IPv6' is send to the DDNS provider")); + o.default = '0'; + o.modalonly = true; + o.rmempty = false; + + o.value("0", _("IPv4-Address")) + if (env["has_ipv6"]) + o.value("1", _("IPv6-Address")) + + // service_name + + o = s.taboption('basic', form.ListValue, 'ipv4_service_name', _("DDNS Service provider") + " [IPv4]"); + o.depends("use_ipv6", "0") + o.modalonly = true; + + for (var i = 0; i < services4.length; i++) + o.value(services4[i]); + + o.value('-',"-- " + _("custom") + " --"); + + o.cfgvalue = function(section_id) { + return uci.get('ddns', section_id, 'service_name'); + } + + o.write = function(section_id, formvalue) { + if (formvalue != '-') { + uci.set('ddns', section_id, 'update_url', null); + uci.set('ddns', section_id, 'update_script', null); + return uci.set('ddns', section_id, 'service_name', formvalue); + } + return uci.set('ddns', section_id, 'service_name', null); + }; + + o = s.taboption('basic', form.ListValue, 'ipv6_service_name', _("DDNS Service provider") + " [IPv6]"); + o.depends("use_ipv6", "1") + o.modalonly = true; + + for (var i = 0; i < services6.length; i++) + o.value(services6[i]); + + o.value('-',"-- " + _("custom") + " --"); + + o.cfgvalue = function(section_id) { + return uci.get('ddns', section_id, 'service_name'); + } + + o.write = function(section_id, formvalue) { + if (formvalue != '-') { + uci.set('ddns', section_id, 'update_url', null); + uci.set('ddns', section_id, 'update_script', null); + return uci.set('ddns', section_id, 'service_name', formvalue); + } + return uci.set('ddns', section_id, 'service_name', null); + }; + + // update_url + + o = s.taboption('basic', form.Value, 'update_url', _("Custom update-URL"), + _("Update URL to be used for updating your DDNS Provider." + "
" + + "Follow instructions you will find on their WEB page.")); + o.modalonly = true; + o.rmempty = false; + o.depends("ipv6_service_name","-"); + o.depends("ipv4_service_name","-"); + + // update_script + + o = s.taboption('basic', form.Value, 'update_script', _("Custom update-script"), + _("Custom update script to be used for updating your DDNS Provider.")); + o.modalonly = true; + o.rmempty = false; + o.depends("ipv6_service_name","-"); + o.depends("ipv4_service_name","-"); + + // domain + + o = s.taboption('basic', form.Value, 'domain', _("Domain"), + _("Replaces [USERNAME] in Update-URL (URL-encoded)")); + o.modalonly = true; + o.rmempty = false; + + // username + + o = s.taboption('basic', form.Value, 'username', _("Username"), + _("Replaces [USERNAME] in Update-URL (URL-encoded)")); + o.modalonly = true; + o.rmempty = false; + + // password + + + o = s.taboption('basic', form.Value, 'password', _("Password"), + _("Replaces [PASSWORD] in Update-URL (URL-encoded)")); + o.password = true; + o.modalonly = true; + o.rmempty = false; + + // param_enc + + o = s.taboption('basic', form.Value, 'param_enc', _("Optional Encoded Parameter"), + _("Optional: Replaces [PARAMENC] in Update-URL (URL-encoded)")); + o.optional = true; + o.modalonly = true; + + // param_opt + + o = s.taboption('basic', form.Value, 'param_opt', _("Optional Parameter"), + _("Optional: Replaces [PARAMOPT] in Update-URL (NOT URL-encoded)")); + o.optional = true; + o.modalonly = true; + + // use_https + + if (env['has_ssl']) { + o = s.taboption('basic', form.Flag, 'use_https', _("Use HTTP Secure"), + _("Enable secure communication with DDNS provider")); + o.optional = true; + o.modalonly = true; + + o = s.taboption('basic', form.Value, 'cacert', + _("Path to CA-Certificate"), + _("directory or path/file") + "
" + + _("or") + '' + " IGNORE " + '' + + _("to run HTTPS without verification of server certificates (insecure)")); + o.modalonly = true; + o.depends("use_https", "1"); + o.placeholder = "/etc/ssl/certs"; + o.rmempty = false; + }; + + // TAB Advanced + + // ip_source + + o = s.taboption('advanced', form.ListValue, 'ip_source', _("IP address source"), + _("Defines the source to read systems IP-Address from, that will be send to the DDNS provider")); + + o.modalonly = true; + o.default = "network"; + o.value("network", _("Network")); + o.value("web", _("URL")); + o.value("interface", _("Interface")); + o.value("script", _("Script")); + + o.write = function(section_id, formvalue) { + switch(formvalue) { + case 'network': + uci.set('ddns', section_id, "ip_url",null); + uci.set('ddns', section_id, "ip_interface",null); + uci.set('ddns', section_id, "ip_script",null); + break; + case 'web': + uci.set('ddns', section_id, "ip_network",null); + uci.set('ddns', section_id, "ip_interface",null); + uci.set('ddns', section_id, "ip_script",null); + break; + case 'interface': + uci.set('ddns', section_id, "ip_network",null); + uci.set('ddns', section_id, "ip_url",null); + uci.set('ddns', section_id, "ip_script",null); + break; + case 'script': + uci.set('ddns', section_id, "ip_network",null); + uci.set('ddns', section_id, "ip_url",null); + uci.set('ddns', section_id, "ip_interface",null); + break; + default: + break; + }; + + return uci.set('ddns', section_id, 'ip_source', formvalue ) + }; + + // ip_network + + o = s.taboption('advanced', widgets.ZoneSelect, 'ip_network', _("Network"), + _("Defines the network to read systems IP-Address from")); + o.depends('ip_source','network'); + o.modalonly = true; + o.default = 'wan'; + o.multiple = false; + + // ip_url + + o = s.taboption('advanced', form.Value, 'ip_url', _("URL to detect"), + _("Defines the Web page to read systems IP-Address from" + '
' + + _('Example for IPv4' + ': http://checkip.dyndns.com') + '
' + + _('Example for IPv6' + ': http://checkipv6.dyndns.com'))); + o.depends("ip_source", "web") + + o.modalonly = true; + + // ip_interface + + o = s.taboption('advanced', widgets.ZoneSelect, 'ip_interface', _("Interface"), + _("Defines the interface to read systems IP-Address from")); + + o.modalonly = true; + o.depends("ip_source", "interface") + o.multiple = false; + o.default = 'wan'; + + // ip_script + + o = s.taboption('advanced', form.Value, 'ip_script', _("Script"), + _("User defined script to read systems IP-Address")); + + o.modalonly = true; + o.depends("ip_source", "script") + o.placeholder = "/path/to/script.sh" + + // interface + + o = s.taboption('advanced', widgets.ZoneSelect, 'interface', _("Event Network"), + _("Network on which the ddns-updater scripts will be started")); + + o.modalonly = true; + o.multiple = false; + o.default = 'wan'; + o.depends("ip_source", "web"); + o.depends("ip_source", "script"); + + // interface_show + + o = s.taboption('advanced', form.DummyValue, '_interface', _("Event Network"), + _("Network on which the ddns-updater scripts will be started")); + o.depends("ip_source", "interface"); + o.depends("ip_source", "network"); + o.forcewrite = true; + o.modalonly = true; + o.cfgvalue = function(section_id) { + return uci.get('ddns', section_id, 'interface') || _('This will be autoset to the selected interface'); + }; + o.write = function(section_id) { + var opt = this.section.children.filter(function(o) { return o.option == 'ip_source' })[0].formvalue(section_id); + var val = this.section.children.filter(function(o) { return o.option == 'ip_'+opt })[0].formvalue(section_id); + return uci.set('ddns', section_id, 'interface', val); + }; + + // bind_network + + if (env['has_bindnet']) { + o = s.taboption('advanced', widgets.ZoneSelect, 'bind_network', _("Bind Network"), + _('OPTIONAL: Network to use for communication') + '
' + + _("Network on which the ddns-updater scripts will be started")); + o.depends("ip_source", "web"); + o.optional = true; + o.rmempty = true; + o.modalonly = true; + } + + // force_ipversion + + if (env['has_forceip']) { + o = s.taboption('advanced', form.Flag, 'force_ipversion', _("Force IP Version"), + _('OPTIONAL: Force the usage of pure IPv4/IPv6 only communication.')); + o.optional = true; + o.rmempty = true; + o.modalonly = true; + } + + // dns_server + + if (env['has_dnsserver']) { + o = s.taboption("advanced", form.Value, "dns_server", + _("DNS-Server"), + _("OPTIONAL: Use non-default DNS-Server to detect 'Registered IP'.") + "
" + + _("Format: IP or FQDN")); + o.placeholder = "mydns.lan" + o.optional = true; + o.rmempty = true; + o.modalonly = true; + } + + // force_dnstcp + + if (env['has_bindhost']) { + o = s.taboption("advanced", form.Flag, "force_dnstcp", + _("Force TCP on DNS"), + _("OPTIONAL: Force the use of TCP instead of default UDP on DNS requests.")); + o.optional = true; + o.rmempty = true; + o.modalonly = true; + } + + // proxy + + if (env['has_proxy']) { + o = s.taboption("advanced", form.Value, "proxy", _("PROXY-Server"), + _("OPTIONAL: Proxy-Server for detection and updates.") + "
" + + _("Format") + ": " + '' + "[user:password@]proxyhost:port" + '' + "
" + + _("IPv6 address must be given in square brackets") + ": " + + '' + " [2001:db8::1]:8080" + ''); + o.optional = true; + o.rmempty = true; + o.modalonly = true; + } + + // use_syslog + + o = s.taboption("advanced", form.ListValue, "use_syslog", _("Log to syslog"), + _("Writes log messages to syslog. Critical Errors will always be written to syslog.")); + o.modalonly = true; + o.placeholder = "2" + o.optional = true; + o.value("0", _("No logging")) + o.value("1", _("Info")) + o.value("2", _("Notice")) + o.value("3", _("Warning")) + o.value("4", _("Error")) + + // use_logfile + + o = s.taboption("advanced", form.Flag, "use_logfile", _("Log to file")); + o.default = '1'; + o.optional = true; + o.modalonly = true; + o.cfgvalue = function(section_id) { + this.description = _("Writes detailed messages to log file. File will be truncated automatically.") + "
" + + _("File") + ': "' + logdir + '/' + section_id + '.log"'; + return uci.get('ddns', section_id, 'use_logfile'); + }; + + // TAB Timer + + // check_interval + o = s.taboption("timer", form.Value, "check_interval", _("Check Interval")); + o.placeholder = "30"; + o.modalonly = true; + o.datatype = 'uinteger'; + + o.validate = function(section_id, formvalue) { + var unit = this.section.children.filter(function(o) { return o.option == 'check_unit' })[0].formvalue(section_id), + time_to_sec = time_res[unit || 'minutes'] * formvalue; + + if (formvalue && time_to_sec < 300) + return _('Values below 5 minutes == 300 seconds are not supported'); + + return true; + + }; + + // check_interval + o = s.taboption("timer", form.ListValue, "check_unit",'Check Unit'); + o.description = _("Interval unit to check for changed IP"); + o.modalonly = true; + o.default = "minutes" + o.value("seconds", _("seconds")); + o.value("minutes", _("minutes")); + o.value("hours", _("hours")); + + // force_interval + + o = s.taboption("timer", form.Value, "force_interval", _("Force Interval")); + o.description = _("Interval to force updates send to DDNS Provider" + "
" + + "Setting this parameter to 0 will force the script to only run once"); + o.placeholder = "72"; + o.optional = true; + o.modalonly = true; + o.datatype = 'uinteger'; + + o.validate = function(section_id, formvalue) { + + if (!formvalue) + return true; + + var check_unit = this.section.children.filter(function(o) { return o.option == 'check_unit' })[0].formvalue(section_id), + check_val = this.section.children.filter(function(o) { return o.option == 'check_interval' })[0].formvalue(section_id), + force_unit = this.section.children.filter(function(o) { return o.option == 'force_unit' })[0].formvalue(section_id), + check_to_sec = time_res[check_unit || 'minutes'] * ( check_val || '30'), + force_to_sec = time_res[force_unit || 'minutes'] * formvalue; + + if (force_to_sec != 0 && force_to_sec < check_to_sec) + return _("Values lower 'Check Interval' except '0' are not supported"); + + return true; + }; + + // force_unit + + o = s.taboption("timer", form.ListValue, "force_unit",'Force Unit'); + o.description = _("Interval unit to force updates send to DDNS Provider"); + o.modalonly = true; + o.optional = true; + o.default = "minutes" + o.value("minutes", _("minutes")); + o.value("hours", _("hours")); + o.value("hours", _("days")); + + // retry_count + + o = s.taboption("timer", form.Value, "retry_count", _("Error Retry Counter")); + o.description = _("On Error the script will stop execution after given number of retrys") + + "
" + + _("The default setting of '0' will retry infinite."); + o.placeholder = "0"; + o.optional = true; + o.modalonly = true; + o.datatype = 'uinteger'; + + // retry_interval + + o = s.taboption("timer", form.Value, "retry_interval", _("Error Retry Interval")); + o.description = _("On Error the script will stop execution after given number of retrys") + + "
" + + _("The default setting of '0' will retry infinite."); + o.placeholder = "60"; + o.optional = true; + o.modalonly = true; + o.datatype = 'uinteger'; + + // retry_unit + + o = s.taboption("timer", form.ListValue, "retry_unit",'Retry Unit'); + o.description = _("On Error the script will retry the failed action after given time"); + o.modalonly = true; + o.optional = true; + o.default = "seconds" + o.value("seconds", _("seconds")); + o.value("minutes", _("minutes")); + + // TAB logview + + o = s.taboption("logview", form.DummyValue, '_read_log', ''); + o.depends('use_logfile','1'); + o.modalonly = true; + o.cfgvalue = function(section_id) { + return E([], [ + E('button', { + 'class': 'cbi-button cbi-button-apply', + 'click': L.ui.createHandlerFn(this, function() { + var o = this.section.children.filter(function(o) { return o.option == '_logview' })[0]; + return callGetLogServices(section_id).then(L.bind(o.update_log, o)); + }) + }, _('Read / Reread log file'))]); + }; + + o = s.taboption("logview", form.DummyValue, "_logview"); + o.depends('use_logfile','1'); + o.modalonly = true; + + o.update_log = L.bind(function(view, log_data) { + return document.getElementById('log_area').innerHTML = log_data.result; + }, o, this) + + o.render = L.bind(function() { + return E([ + E('p', {}, _('This is the current content of the log file in ') + logdir + ' for this service.'), + E('p', {}, E('textarea', { 'style': 'width:100%', 'rows': 20, 'readonly' : 'readonly', 'id' : 'log_area' }, _('Please press [Read] button') )) + ]); + }, o, this) + + + // Advanced Configuration Section + + s = m.section(form.NamedSection, 'global', 'ddns', _('Global Configuration')); + s.description = _('Configure here the details for all Dynamic DNS services including this LuCI application.') + + '
' + + _("It is NOT recommended for casual users to change settings on this page.") + + '
' + + '' + + _('For detailed information about parameter settings look here.') + + ''; + s.addremove = false; + + o = s.option(form.Flag, 'upd_privateip', _("Allow non-public IP's")); + o.description = _("Non-public and by default blocked IP's") + ':' + + '
IPv4: ' + + '0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16' + + '
IPv6: ' + + '::/32, f000::/4"'; + o.default = "0"; + o.optional = true; + + o = s.option(form.Value, 'ddns_dateformat', _('Date format')); + o.description = '' + + _("For supported codes look here") + + '
' + + _('Current setting: ') + '' + status['_curr_dateformat'] + ''; + o.default = "%F %R" + o.optional = true; + o.rmempty = true; + + o = s.option(form.Value, 'ddns_rundir', _('Status directory')); + o.description = _('Directory contains PID and other status information for each running section.'); + o.default = "/var/run/ddns"; + o.optional = true; + o.rmempty = true; + + o = s.option(form.Value, 'ddns_logdir', _('Log directory')); + o.description = _('Directory contains Log files for each running section.'); + o.default = "/var/log/ddns"; + o.optional = true; + o.rmempty = true; + o.validate = function(section_id, formvalue) { + if (formvalue.indexOf('../') !== -1) + return _('"../" not allowed in path for Security Reason.') + + return true; + } + + o = s.option(form.Value, 'ddns_loglines', _('Log length')); + o.description = _('Number of last lines stored in log files'); + o.datatype = 'min(1)'; + o.default = '250'; + + if (env['has_wget'] && env['has_curl']) { + + o = s.option(form.Flag, 'use_curl', _('Use cURL')); + o.description = _('If Wget and cURL package are installed, Wget is used for communication by default.'); + o.default = "0"; + o.optional = true; + o.rmempty = true; + + } + + return m.render().then(L.bind(function(m, nodes) { + L.Poll.add(L.bind(function() { + return Promise.all([ + this.callDDnsGetServicesStatus(), + callDDnsGetStatus() + ]).then(L.bind(this.poll_status, this, nodes)); + }, this), 5); + return nodes; + }, this, m)); + } +}); diff --git a/applications/luci-app-ddns/htdocs/luci-static/resources/view/status/include/70_ddns.js b/applications/luci-app-ddns/htdocs/luci-static/resources/view/status/include/70_ddns.js new file mode 100644 index 0000000000..698cf8d254 --- /dev/null +++ b/applications/luci-app-ddns/htdocs/luci-static/resources/view/status/include/70_ddns.js @@ -0,0 +1,46 @@ +'use strict'; +'require rpc'; +'require uci'; + +return L.Class.extend({ + title: _('Dynamic DNS'), + + callDDnsGetServicesStatus: rpc.declare({ + object: 'luci.ddns', + method: 'get_services_status', + expect: { } + }), + + load: function() { + return Promise.all([ + this.callDDnsGetServicesStatus(), + uci.load('ddns') + ]); + }, + + render: function(data) { + var services = data[0]; + + var table = E('div', { 'class': 'table' }, [ + E('div', { 'class': 'tr table-titles' }, [ + E('div', { 'class': 'th' }, _('Configuration')), + E('div', { 'class': 'th' }, _('Next Update')), + E('div', { 'class': 'th' }, _('Lookup Hostname')), + E('div', { 'class': 'th' }, _('Registered IP')), + E('div', { 'class': 'th' }, _('Network')) + ]) + ]); + + cbi_update_table(table, Object.keys(services).map(function(key, index) { + return [ + key, + services[key].next_update ? _(services[key].next_update) : _('Unknown'), + uci.get('ddns',key,'lookup_host'), + services[key].ip ? services[key].ip : _('No Data'), + (uci.get('ddns',key,'use_ipv6') == '1' ? 'IPv6' : 'IPv4') + ' / ' + uci.get('ddns',key,'interface') + ]; + }), E('em', _('There is no service configured.'))); + + return E([table]); + } +}); diff --git a/applications/luci-app-ddns/luasrc/controller/ddns.lua b/applications/luci-app-ddns/luasrc/controller/ddns.lua index 24735289e0..247edef321 100755 --- a/applications/luci-app-ddns/luasrc/controller/ddns.lua +++ b/applications/luci-app-ddns/luasrc/controller/ddns.lua @@ -6,334 +6,6 @@ module("luci.controller.ddns", package.seeall) -local NX = require "nixio" -local NXFS = require "nixio.fs" -local DISP = require "luci.dispatcher" -local HTTP = require "luci.http" -local I18N = require "luci.i18n" -- not globally avalible here -local IPKG = require "luci.model.ipkg" -local SYS = require "luci.sys" -local UCI = require "luci.model.uci" -local UTIL = require "luci.util" -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.7" -- minimum version of service required -local app_name = "luci-app-ddns" -local app_title = "Dynamic DNS" -local app_version = "2.4.9-1" - -local translate = I18N.translate - function index() - local nxfs = require "nixio.fs" -- global definitions not available - local sys = require "luci.sys" -- in function index() - local muci = require "luci.model.uci" - - -- no config create an empty one - if not nxfs.access("/etc/config/ddns") then - nxfs.writefile("/etc/config/ddns", "") - end - - -- preset new option "lookup_host" if not already defined - local uci = muci.cursor() - local commit = false - uci:foreach("ddns", "service", function (s) - if not s["lookup_host"] and s["domain"] then - uci:set("ddns", s[".name"], "lookup_host", s["domain"]) - commit = true - end - end) - if commit then uci:commit("ddns") end - uci:unload("ddns") - - entry( {"admin", "services", "ddns"}, cbi("ddns/overview"), _("Dynamic DNS"), 59) - entry( {"admin", "services", "ddns", "detail"}, cbi("ddns/detail"), nil ).leaf = true - entry( {"admin", "services", "ddns", "hints"}, cbi("ddns/hints", - {hideapplybtn=true, hidesavebtn=true, hideresetbtn=true}), nil ).leaf = true - entry( {"admin", "services", "ddns", "global"}, cbi("ddns/global"), nil ).leaf = true - entry( {"admin", "services", "ddns", "logview"}, call("logread") ).leaf = true - entry( {"admin", "services", "ddns", "startstop"}, post("startstop") ).leaf = true - entry( {"admin", "services", "ddns", "status"}, call("status") ).leaf = true -end - --- Application specific information functions -function app_description() - local tmp = {} - tmp[#tmp+1] = translate("Dynamic DNS allows that your router can be reached with \ - a fixed hostname while having a dynamically changing IP address.") - tmp[#tmp+1] = [[
]] - tmp[#tmp+1] = translate("OpenWrt Wiki") .. ": " - tmp[#tmp+1] = [[]] - tmp[#tmp+1] = translate("DDNS Client Documentation") - tmp[#tmp+1] = [[]] - tmp[#tmp+1] = " --- " - tmp[#tmp+1] = [[]] - tmp[#tmp+1] = translate("DDNS Client Configuration") - tmp[#tmp+1] = [[]] - - return table.concat(tmp) -end -function app_title_back() - local tmp = {} - tmp[#tmp+1] = [[]] - tmp[#tmp+1] = translate(app_title) - tmp[#tmp+1] = [[]] - return table.concat(tmp) -end - --- Standardized application/service functions -function app_title_main() - local tmp = {} - tmp[#tmp+1] = [[]] - tmp[#tmp+1] = translate(app_title) - tmp[#tmp+1] = [[]] - - return table.concat(tmp) -end - -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 - --- internal function to read all sections status and return data array -local function _get_status() - local uci = UCI.cursor() - local service = SYS.init.enabled("ddns") and 1 or 0 - local url_start = DISP.build_url("admin", "system", "startup") - local data = {} -- Array to transfer data to javascript - - data[#data+1] = { - enabled = service, -- service enabled - url_up = url_start, -- link to enable DDS (System-Startup) - } - - uci:foreach("ddns", "service", function (s) - - -- Get section we are looking at - -- and enabled state - local section = s[".name"] - local enabled = tonumber(s["enabled"]) or 0 - local datelast = "_empty_" -- formatted date of last update - local datenext = "_empty_" -- formatted date of next update - local datenextstat = nil - - -- get force seconds - local force_seconds = DDNS.calc_seconds( - tonumber(s["force_interval"]) or 72 , - s["force_unit"] or "hours" ) - -- get/validate pid and last update - local pid = DDNS.get_pid(section) - local uptime = SYS.uptime() - local lasttime = DDNS.get_lastupd(section) - if lasttime > uptime then -- /var might not be linked to /tmp - lasttime = 0 -- and/or not cleared on reboot - end - - -- no last update happen - if lasttime == 0 then - datelast = "_never_" - - -- we read last update - else - -- calc last update - -- sys.epoch - sys uptime + lastupdate(uptime) - local epoch = os.time() - uptime + lasttime - -- use linux date to convert epoch - datelast = DDNS.epoch2date(epoch) - -- calc and fill next update - datenext = DDNS.epoch2date(epoch + force_seconds) - end - - -- process running but update needs to happen - -- problems if force_seconds > uptime - force_seconds = (force_seconds > uptime) and uptime or force_seconds - if pid > 0 and ( lasttime + force_seconds - uptime ) <= 0 then - datenext = "_verify_" - datenextstat = translate("Verify") - - -- run once - elseif force_seconds == 0 then - datenext = "_runonce_" - datenextstat = translate("Run once") - - -- no process running and NOT enabled - elseif pid == 0 and enabled == 0 then - datenext = "_disabled_" - datenextstat = translate("Disabled") - - -- no process running and enabled - elseif pid == 0 and enabled ~= 0 then - datenext = "_stopped_" - datenextstat = translate("Stopped") - end - - -- get/set monitored interface and IP version - local iface = s["interface"] or "wan" - local use_ipv6 = tonumber(s["use_ipv6"]) or 0 - 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 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 - - -- fill transfer array - data[#data+1] = { - section = section, - enabled = enabled, - iface = iface, - lookup = lookup_host, - reg_ip = reg_ip, - pid = pid, - datelast = datelast, - datenext = datenext, - datenextstat = datenextstat - } - end) - - uci:unload("ddns") - return data -end - --- called by XHR.get from detail_logview.htm -function logread(section) - -- read application settings - local uci = UCI.cursor() - local ldir = uci:get("ddns", "global", "ddns_logdir") or "/var/log/ddns" - local lfile = ldir .. "/" .. section .. ".log" - local ldata = NXFS.readfile(lfile) - - if not ldata or #ldata == 0 then - ldata="_nodata_" - end - uci:unload("ddns") - HTTP.write(ldata) -end - --- called by XHR.get from overview_status.htm -function startstop(section, enabled) - local uci = UCI.cursor() - local pid = DDNS.get_pid(section) - local data = {} -- Array to transfer data to javascript - - -- if process running we want to stop and return - if pid > 0 then - local tmp = NX.kill(pid, 15) -- terminate - NX.nanosleep(2) -- 2 second "show time" - -- status changed so return full status - data = _get_status() - HTTP.prepare_content("application/json") - HTTP.write_json(data) - return - end - - -- read uncommitted changes - -- we don't save and commit data from other section or other options - -- only enabled will be done - local exec = true - local changed = uci:changes("ddns") - for k_config, v_section in pairs(changed) do - -- security check because uci.changes only gets our config - if k_config ~= "ddns" then - exec = false - break - end - for k_section, v_option in pairs(v_section) do - -- check if only section of button was changed - if k_section ~= section then - exec = false - break - end - for k_option, v_value in pairs(v_option) do - -- check if only enabled was changed - if k_option ~= "enabled" then - exec = false - break - end - end - end - end - - -- we can not execute because other - -- uncommitted changes pending, so exit here - if not exec then - HTTP.write("_uncommitted_") - return - end - - -- save enable state - uci:set("ddns", section, "enabled", ( (enabled == "true") and "1" or "0") ) - uci:save("ddns") - uci:commit("ddns") - uci:unload("ddns") - - -- start ddns-updater for section - local command = "%s -S %s -- start" %{ luci_helper, UTIL.shellquote(section) } - os.execute(command) - NX.nanosleep(3) -- 3 seconds "show time" - - -- status changed so return full status - data = _get_status() - HTTP.prepare_content("application/json") - HTTP.write_json(data) + entry( {"admin", "services", "ddns"}, view("ddns/overview"), _("Dynamic DNS"), 59) end - --- called by XHR.poll from overview_status.htm -function status() - local data = _get_status() - HTTP.prepare_content("application/json") - HTTP.write_json(data) -end - diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua deleted file mode 100644 index ecabec4e22..0000000000 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/detail.lua +++ /dev/null @@ -1,1504 +0,0 @@ --- Copyright 2008 Steven Barth --- Copyright 2008 Jo-Philipp Wich --- Copyright 2013 Manuel Munz --- Copyright 2014-2016 Christian Schoenebeck --- Licensed to the public under the Apache License 2.0. - -local NX = require "nixio" -local NXFS = require "nixio.fs" -local SYS = require "luci.sys" -local UTIL = require "luci.util" -local HTTP = require "luci.http" -local DISP = require "luci.dispatcher" -local WADM = require "luci.tools.webadmin" -local DTYP = require "luci.cbi.datatypes" -local CTRL = require "luci.controller.ddns" -- this application's controller -local DDNS = require "luci.tools.ddns" -- ddns multiused functions - --- takeover arguments -- ####################################################### -local section = arg[1] - --- html constants -- ########################################################### -local font_red = "" -local font_off = "" -local bold_on = "" -local bold_off = "" - --- error text constants -- ##################################################### -local err_ipv6_plain = translate("IPv6 not supported") .. " - " .. - translate("please select 'IPv4' address version") -local err_ipv6_basic = bold_on .. - font_red .. - translate("IPv6 not supported") .. - font_off .. - "
" .. translate("please select 'IPv4' address version") .. - bold_off -local err_ipv6_other = bold_on .. - font_red .. - translate("IPv6 not supported") .. - font_off .. - "
" .. translate("please select 'IPv4' address version in") .. " " .. - [[]] .. - translate("Basic Settings") .. - [[]] .. - bold_off - -function err_tab_basic(self) - return translate("Basic Settings") .. " - " .. self.title .. ": " -end -function err_tab_adv(self) - return translate("Advanced Settings") .. " - " .. self.title .. ": " -end -function err_tab_timer(self) - return translate("Timer Settings") .. " - " .. self.title .. ": " -end - --- read services/services_ipv6 files -- ######################################## -local services4 = { } -- IPv4 -- -local fd4 = io.open("/etc/ddns/services", "r") -if fd4 then - local ln, s, t - repeat - ln = fd4:read("*l") - s = ln and ln:match('^%s*".*') -- only handle lines beginning with " - s = s and s:gsub('"','') -- remove " - t = s and UTIL.split(s,"(%s+)",nil,true) -- split on whitespaces - if t then services4[t[1]]=t[2] end - until not ln - fd4:close() -end - -local services6 = { } -- IPv6 -- -local fd6 = io.open("/etc/ddns/services_ipv6", "r") -if fd6 then - local ln, s, t - repeat - ln = fd6:read("*l") - s = ln and ln:match('^%s*".*') -- only handle lines beginning with " - s = s and s:gsub('"','') -- remove " - t = s and UTIL.split(s,"(%s+)",nil,true) -- split on whitespaces - if t then services6[t[1]]=t[2] end - until not ln - fd6:close() -end - --- multi-used functions -- #################################################### --- function to verify settings around ip_source --- will use dynamic_dns_lucihelper to check if --- local IP can be read -local function _verify_ip_source() - -- section is globally defined here be calling argument (see above) - local _arg - - local _ipv6 = usev6:formvalue(section) - local _source = (_ipv6 == "1") - and src6:formvalue(section) - or src4:formvalue(section) - - local command = CTRL.luci_helper .. [[ -]] - if (_ipv6 == "1") then command = command .. [[6]] end - - if _source == "network" then - _arg = (_ipv6 == "1") - and ipn6:formvalue(section) - or ipn4:formvalue(section) - command = command .. [[n ]] .. _arg - elseif _source == "web" then - _arg = (_ipv6 == "1") - and iurl6:formvalue(section) - or iurl4:formvalue(section) - command = command .. [[u ]] .. _arg - - -- proxy only needed for checking url - _arg = (pxy) and pxy:formvalue(section) or "" - if (_arg and #_arg > 0) then - command = command .. [[ -p ]] .. _arg - end - elseif _source == "interface" then - command = command .. [[i ]] .. ipi:formvalue(section) - elseif _source == "script" then - command = command .. [[s ]] .. ips:formvalue(section) - end - command = command .. [[ -- get_local_ip]] - return (SYS.call(command) == 0) -end - --- function to check if option is used inside url or script --- return -1 on error, 0 NOT required, 1 required -local function _option_used(option, urlscript) - local surl -- search string for url - local ssh -- search string for script - local required -- option used inside url or script - - if option == "domain" then surl, ssh = '%[DOMAIN%]', '%$domain' - elseif option == "username" then surl, ssh = '%[USERNAME%]', '%$username' - elseif option == "password" then surl, ssh = '%[PASSWORD%]', '%$password' - elseif option == "param_enc" then surl, ssh = '%[PARAMENC%]', '%$param_enc' - elseif option == "param_opt" then surl, ssh = '%[PARAMOPT%]', '%$param_opt' - else - error("undefined option") - return -1 -- return on error - end - - local required = false - -- handle url - if urlscript:find('http') then - required = ( urlscript:find(surl) ) - -- handle script - else - if not urlscript:find("/") then - -- might be inside ddns-scripts directory - urlscript = "/usr/lib/ddns/" .. urlscript - end - -- problem with script exit here - if not NXFS.access(urlscript) then return -1 end - - local f = io.input(urlscript) - -- still problem with script exit here - if not f then return -1 end - for l in f:lines() do - repeat - if l:find('^#') then break end -- continue on comment lines - required = ( l:find(surl) or l:find(ssh) ) - until true - if required then break end - end - f:close() - end - return (required and 1 or 0) -end - --- function to verify if option is valid -local function _option_validate(self, value, optional) - -- section is globally defined here be calling argument (see above) - local fusev6 = usev6:formvalue(section) or "0" - local fsvc4 = svc4:formvalue(section) or "-" - local fsvc6 = svc6:formvalue(section) or "-" - local urlsh, used - - -- IP-Version dependent custom service selected - if (fusev6 == "0" and fsvc4 == "-") or - (fusev6 == "1" and fsvc6 == "-") then - -- read custom url - urlsh = uurl:formvalue(section) or "" - -- no url then read custom script - if (#urlsh == 0) then - urlsh = ush:formvalue(section) or "" - end - -- IPv4 read from services4 table - elseif (fusev6 == "0") then - urlsh = services4[fsvc4] or "" - -- IPv6 read from services6 table - else - urlsh = services6[fsvc6] or "" - end - -- problem with url or script exit here - -- error handled somewhere else - if (#urlsh == 0) then return "" end - - used = _option_used(self.option, urlsh) - -- on error or not used return empty string - if used < 1 then return "" end - -- needed but no data then return error - if not value or (#value == 0) then - if optional then return nil end - return nil, err_tab_basic(self) .. translate("missing / required") - end - return value -end - --- cbi-map definition -- ####################################################### -local m = Map("ddns") -m.title = CTRL.app_title_back() -m.description = CTRL.app_description() -m.redirect = DISP.build_url("admin", "services", "ddns") - -m.on_after_commit = function(self) - if self.changed then -- changes ? - local pid = DDNS.get_pid(section) - if pid > 0 then -- running ? - local tmp = NX.kill(pid, 1) -- send SIGHUP - end - end -end - --- provider switch was requested, save and reload page -if m:formvalue("cbid.ddns.%s._switch" % section) then -- section == arg[1] - local fsvc - local fusev6 = m:formvalue("cbid.ddns.%s.use_ipv6" % section) or "0" - if fusev6 == "1" then - fsvc = m:formvalue("cbid.ddns.%s.ipv6_service_name" % section) or "" - else - fsvc = m:formvalue("cbid.ddns.%s.ipv4_service_name" % section) or "" - end - - if fusev6 ~= (m:get(section, "use_ipv6") or "0") then -- IPv6 was changed - m:set(section, "use_ipv6", fusev6) -- save it - end - - if fsvc ~= "-" then -- NOT "custom" - m:set(section, "service_name", fsvc) -- save it - else -- else - m:del(section, "service_name") -- delete it - end - m.uci:save(m.config) - - -- reload page - HTTP.redirect( DISP.build_url("admin", "services", "ddns", "detail", section) ) - return -end - --- read application settings -- ################################################ --- log directory -local logdir = m.uci:get(m.config, "global", "ddns_logdir") or "/var/log/ddns" - --- cbi-section definition -- ################################################### -local ns = m:section( NamedSection, section, "service", - translate("Details for") .. ([[: %s]] % section), - translate("Configure here the details for selected Dynamic DNS service.") ) -ns.instance = section -- arg [1] -ns:tab("basic", translate("Basic Settings"), nil ) -ns:tab("advanced", translate("Advanced Settings"), nil ) -ns:tab("timer", translate("Timer Settings"), nil ) -ns:tab("logview", translate("Log File Viewer"), nil ) - --- TAB: Basic ##################################################################################### --- enabled -- ################################################################# -en = ns:taboption("basic", Flag, "enabled", - translate("Enabled"), - translate("If this service section is disabled it could not be started." .. "
" .. - "Neither from LuCI interface nor from console") ) -en.orientation = "horizontal" - --- IPv4/IPv6 - lookup_host -- ################################################# -luh = ns:taboption("basic", Value, "lookup_host", - translate("Lookup Hostname"), - translate("Hostname/FQDN to validate, if IP update happen or necessary") ) -luh.rmempty = false -luh.placeholder = "myhost.example.com" -function luh.validate(self, value) - if not value - or not (#value > 0) - or not DTYP.hostname(value) then - return nil, err_tab_basic(self) .. translate("invalid FQDN / required - Sample") .. ": 'myhost.example.com'" - else - return UTIL.trim(value) - end -end -function luh.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- use_ipv6 -- ################################################################ - ---We call it globally as it's called 11 times even outside specific function, saves 11 os.execute slow command! -local has_ipv6 = DDNS.env_info("has_ipv6") - -usev6 = ns:taboption("basic", ListValue, "use_ipv6", - translate("IP address version"), - translate("Defines which IP address 'IPv4/IPv6' is send to the DDNS provider") ) -usev6.widget = "radio" -usev6.default = "0" -usev6:value("0", translate("IPv4-Address") ) -function usev6.cfgvalue(self, section) - local value = AbstractValue.cfgvalue(self, section) or "0" - if has_ipv6 or (value == "1" and not has_ipv6) then - self:value("1", translate("IPv6-Address") ) - end - if value == "1" and not has_ipv6 then - self.description = err_ipv6_basic - end - return value -end -function usev6.validate(self, value) - if (value == "1" and has_ipv6) or value == "0" then - return value - end - return nil, err_tab_basic(self) .. err_ipv6_plain -end -function usev6.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4 - service_name -- ##################################################### -svc4 = ns:taboption("basic", ListValue, "ipv4_service_name", - translate("DDNS Service provider") .. " [IPv4]" ) -svc4.default = "-" -svc4:depends("use_ipv6", "0") -- only show on IPv4 -function svc4.cfgvalue(self, section) - local v = DDNS.read_value(self, section, "service_name") - if v and (#v > 0) then - for s, u in UTIL.kspairs(services4) do - if v == s then return v end - end - end - return "-" -end -function svc4.validate(self, value) - if usev6:formvalue(section) ~= "1" then -- do only on IPv4 - return value - else - return "" -- suppress validate error - end -end -function svc4.write(self, section, value) - if usev6:formvalue(section) ~= "1" then -- do only IPv4 here - self.map:del(section, self.option) -- to be shure - if value ~= "-" then -- and write "service_name - self.map:del(section, "update_url") -- delete update_url - self.map:del(section, "update_script") -- delete update_script - return self.map:set(section, "service_name", value) - else - return self.map:del(section, "service_name") - end - end -end -function svc4.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv6 - service_name -- ##################################################### -svc6 = ns:taboption("basic", ListValue, "ipv6_service_name", - translate("DDNS Service provider") .. " [IPv6]" ) -svc6.default = "-" -svc6:depends("use_ipv6", "1") -- only show on IPv6 -if not has_ipv6 then - svc6.description = err_ipv6_basic -end -function svc6.cfgvalue(self, section) - local v = DDNS.read_value(self, section, "service_name") - if v and (#v > 0) then - for s, u in UTIL.kspairs(services4) do - if v == s then return v end - end - end - return "-" -end -function svc6.validate(self, value) - if usev6:formvalue(section) == "1" then -- do only on IPv6 - if has_ipv6 then return value end - return nil, err_tab_basic(self) .. err_ipv6_plain - else - return "" -- suppress validate error - end -end -function svc6.write(self, section, value) - if usev6:formvalue(section) == "1" then -- do only when IPv6 - self.map:del(section, self.option) -- delete "ipv6_service_name" helper - if value ~= "-" then -- and write "service_name - self.map:del(section, "update_url") -- delete update_url - self.map:del(section, "update_script") -- delete update_script - return self.map:set(section, "service_name", value) - else - return self.map:del(section, "service_name") - end - end -end -function svc6.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - change Provider -- ############################################# -svs = ns:taboption("basic", Button, "_switch") -svs.title = translate("Really change DDNS provider?") -svs.inputtitle = translate("Change provider") -svs.inputstyle = "apply" - --- IPv4/IPv6 - update_url -- ################################################## -uurl = ns:taboption("basic", Value, "update_url", - translate("Custom update-URL"), - translate("Update URL to be used for updating your DDNS Provider." .. "
" .. - "Follow instructions you will find on their WEB page.") ) -function uurl.validate(self, value) - local fush = ush:formvalue(section) - local fusev6 = usev6:formvalue(section) - - if (fusev6 ~= "1" and svc4:formvalue(section) ~= "-") or - (fusev6 == "1" and svc6:formvalue(section) ~= "-") then - return "" -- suppress validate error - elseif not value or (#value == 0) then - if not fush or (#fush == 0) then - return nil, err_tab_basic(self) .. translate("missing / required") - else - return "" -- suppress validate error / update_script is given - end - elseif (#fush > 0) then - return nil, err_tab_basic(self) .. translate("either url or script could be set") - end - - local url = DDNS.parse_url(value) - if not url.scheme == "http" then - return nil, err_tab_basic(self) .. translate("must start with 'http://'") - elseif not url.query then - return nil, err_tab_basic(self) .. " " .. translate("missing / required") - elseif not url.host then - return nil, err_tab_basic(self) .. " " .. translate("missing / required") - elseif SYS.call([[nslookup ]] .. url.host .. [[ >/dev/null 2>&1]]) ~= 0 then - return nil, err_tab_basic(self) .. translate("can not resolve host: ") .. url.host - end - - return value -end -function uurl.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - update_script -- ############################################### -ush = ns:taboption("basic", Value, "update_script", - translate("Custom update-script"), - translate("Custom update script to be used for updating your DDNS Provider.") ) -function ush.validate(self, value) - local fuurl = uurl:formvalue(section) - local fusev6 = usev6:formvalue(section) - - if (fusev6 ~= "1" and svc4:formvalue(section) ~= "-") or - (fusev6 == "1" and svc6:formvalue(section) ~= "-") then - return "" -- suppress validate error - elseif not value or (#value == 0) then - if not fuurl or (#fuurl == 0) then - return nil, err_tab_basic(self) .. translate("missing / required") - else - return "" -- suppress validate error / update_url is given - end - elseif (#fuurl > 0) then - return nil, err_tab_basic(self) .. translate("either url or script could be set") - elseif not NXFS.access(value) then - return nil, err_tab_basic(self) .. translate("File not found") - end - return value -end -function ush.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - domain -- ###################################################### -dom = ns:taboption("basic", Value, "domain", - translate("Domain"), - translate("Replaces [DOMAIN] in Update-URL") ) -dom.placeholder = "myhost.example.com" -function dom.validate(self, value) - return _option_validate(self, value) -end -function dom.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - username -- #################################################### -user = ns:taboption("basic", Value, "username", - translate("Username"), - translate("Replaces [USERNAME] in Update-URL (URL-encoded)") ) -function user.validate(self, value) - return _option_validate(self, value) -end -function user.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - password -- #################################################### -pw = ns:taboption("basic", Value, "password", - translate("Password"), - translate("Replaces [PASSWORD] in Update-URL (URL-encoded)") ) -pw.password = true -function pw.validate(self, value) - return _option_validate(self, value) -end -function pw.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - param_enc -- ################################################### -pe = ns:taboption("basic", Value, "param_enc", - translate("Optional Encoded Parameter"), - translate("Optional: Replaces [PARAMENC] in Update-URL (URL-encoded)") ) -function pe.validate(self, value) - return _option_validate(self, value, true) -end -function pe.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - param_opt -- ################################################### -po = ns:taboption("basic", Value, "param_opt", - translate("Optional Parameter"), - translate("Optional: Replaces [PARAMOPT] in Update-URL (NOT URL-encoded)") ) -function po.validate(self, value) - return _option_validate(self, value, true) -end -function po.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- handled service dependent show/display -- ################################## --- IPv4 -- -local cv4 = svc4:cfgvalue(section) -if cv4 ~= "-" then - svs:depends ("ipv4_service_name", "-" ) -- show only if "-" - ush:depends ("ipv4_service_name", "?") - uurl:depends("ipv4_service_name", "?") -else - uurl:depends("ipv4_service_name", "-") - ush:depends ("ipv4_service_name", "-") - dom:depends("ipv4_service_name", "-" ) - user:depends("ipv4_service_name", "-" ) - pw:depends("ipv4_service_name", "-" ) - pe:depends("ipv4_service_name", "-" ) - po:depends("ipv4_service_name", "-" ) -end -for s, u in UTIL.kspairs(services4) do - svc4:value(s) -- fill DropDown-List - if cv4 ~= s then - svs:depends("ipv4_service_name", s ) - else - dom:depends ("ipv4_service_name", ((_option_used(dom.option, u) == 1) and s or "?") ) - user:depends("ipv4_service_name", ((_option_used(user.option, u) == 1) and s or "?") ) - pw:depends ("ipv4_service_name", ((_option_used(pw.option, u) == 1) and s or "?") ) - pe:depends ("ipv4_service_name", ((_option_used(pe.option, u) == 1) and s or "?") ) - po:depends ("ipv4_service_name", ((_option_used(po.option, u) == 1) and s or "?") ) - end -end -svc4:value("-", translate("-- custom --") ) - --- IPv6 -- -local cv6 = svc6:cfgvalue(section) -if cv6 ~= "-" then - svs:depends ("ipv6_service_name", "-" ) - uurl:depends("ipv6_service_name", "?") - ush:depends ("ipv6_service_name", "?") -else - uurl:depends("ipv6_service_name", "-") - ush:depends ("ipv6_service_name", "-") - dom:depends("ipv6_service_name", "-" ) - user:depends("ipv6_service_name", "-" ) - pw:depends("ipv6_service_name", "-" ) - pe:depends("ipv6_service_name", "-" ) - po:depends("ipv6_service_name", "-" ) -end -for s, u in UTIL.kspairs(services6) do - svc6:value(s) -- fill DropDown-List - if cv6 ~= s then - svs:depends("ipv6_service_name", s ) - else - dom:depends ("ipv6_service_name", ((_option_used(dom.option, u) == 1) and s or "?") ) - user:depends("ipv6_service_name", ((_option_used(user.option, u) == 1) and s or "?") ) - pw:depends ("ipv6_service_name", ((_option_used(pw.option, u) == 1) and s or "?") ) - pe:depends ("ipv6_service_name", ((_option_used(pe.option, u) == 1) and s or "?") ) - po:depends ("ipv6_service_name", ((_option_used(po.option, u) == 1) and s or "?") ) - end -end -svc6:value("-", translate("-- custom --") ) - --- IPv4/IPv6 - use_https -- ################################################### - ---We call it globally as it's called 4 times outside specific function. -local has_ssl = DDNS.env_info("has_ssl") - -if has_ssl or ( ( m:get(section, "use_https") or "0" ) == "1" ) then - https = ns:taboption("basic", Flag, "use_https", - translate("Use HTTP Secure") ) - https.orientation = "horizontal" - function https.cfgvalue(self, section) - local value = AbstractValue.cfgvalue(self, section) - if not has_ssl and value == "1" then - self.description = bold_on .. font_red .. - translate("HTTPS not supported") .. font_off .. "
" .. - translate("please disable") .. " !" .. bold_off - else - self.description = translate("Enable secure communication with DDNS provider") - end - return value - end - function https.validate(self, value) - if (value == "1" and has_ssl ) or value == "0" then return value end - return nil, err_tab_basic(self) .. translate("HTTPS not supported") .. " !" - end - function https.write(self, section, value) - if value == "1" then - return self.map:set(section, self.option, value) - else - self.map:del(section, "cacert") - return self.map:del(section, self.option) - end - end -end - --- IPv4/IPv6 - cacert -- ###################################################### -if has_ssl then - cert = ns:taboption("basic", Value, "cacert", - translate("Path to CA-Certificate"), - translate("directory or path/file") .. "
" .. - translate("or") .. bold_on .. " IGNORE " .. bold_off .. - translate("to run HTTPS without verification of server certificates (insecure)") ) - cert:depends("use_https", "1") - cert.placeholder = "/etc/ssl/certs" - cert.forcewrite = true - function cert.validate(self, value) - if https:formvalue(section) ~= "1" then - return "" -- suppress validate error if NOT https - end - if value then -- otherwise errors in datatype check - if DTYP.directory(value) - or DTYP.file(value) - or (value == "IGNORE") - or (#value == 0) then - return value - end - end - return nil, err_tab_basic(self) .. - translate("file or directory not found or not 'IGNORE'") .. " !" - end - function cert.parse(self, section, novld) - DDNS.value_parse(self, section, novld) - end -end - --- TAB: Advanced ################################################################################# --- IPv4 - ip_source -- ######################################################## -src4 = ns:taboption("advanced", ListValue, "ipv4_source", - translate("IP address source") .. " [IPv4]", - translate("Defines the source to read systems IPv4-Address from, that will be send to the DDNS provider") ) -src4:depends("use_ipv6", "0") -- IPv4 selected -src4.default = "network" -src4:value("network", translate("Network")) -src4:value("web", translate("URL")) -src4:value("interface", translate("Interface")) -src4:value("script", translate("Script")) -function src4.cfgvalue(self, section) - return DDNS.read_value(self, section, "ip_source") -end -function src4.validate(self, value) - if usev6:formvalue(section) == "1" then - return "" -- ignore on IPv6 selected - elseif not _verify_ip_source() then - return nil, err_tab_adv(self) .. - translate("can not detect local IP. Please select a different Source combination") - else - return value - end -end -function src4.write(self, section, value) - if usev6:formvalue(section) == "1" then - return true -- ignore on IPv6 selected - elseif value == "network" then - self.map:del(section, "ip_url") -- delete not need parameters - self.map:del(section, "ip_interface") - self.map:del(section, "ip_script") - elseif value == "web" then - self.map:del(section, "ip_network") -- delete not need parameters - self.map:del(section, "ip_interface") - self.map:del(section, "ip_script") - elseif value == "interface" then - self.map:del(section, "ip_network") -- delete not need parameters - self.map:del(section, "ip_url") - self.map:del(section, "ip_script") - elseif value == "script" then - self.map:del(section, "ip_network") - self.map:del(section, "ip_url") -- delete not need parameters - self.map:del(section, "ip_interface") - end - self.map:del(section, self.option) -- delete "ipv4_source" helper - return self.map:set(section, "ip_source", value) -- and write "ip_source -end -function src4.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv6 - ip_source -- ######################################################## -src6 = ns:taboption("advanced", ListValue, "ipv6_source", - translate("IP address source") .. " [IPv6]", - translate("Defines the source to read systems IPv6-Address from, that will be send to the DDNS provider") ) -src6:depends("use_ipv6", 1) -- IPv6 selected -src6.default = "network" -src6:value("network", translate("Network")) -src6:value("web", translate("URL")) -src6:value("interface", translate("Interface")) -src6:value("script", translate("Script")) -if not has_ipv6 then - src6.description = err_ipv6_other -end -function src6.cfgvalue(self, section) - return DDNS.read_value(self, section, "ip_source") -end -function src6.validate(self, value) - if usev6:formvalue(section) ~= "1" then - return "" -- ignore on IPv4 selected - elseif not has_ipv6 then - return nil, err_tab_adv(self) .. err_ipv6_plain - elseif not _verify_ip_source() then - return nil, err_tab_adv(self) .. - translate("can not detect local IP. Please select a different Source combination") - else - return value - end -end -function src6.write(self, section, value) - if usev6:formvalue(section) ~= "1" then - return true -- ignore on IPv4 selected - elseif value == "network" then - self.map:del(section, "ip_url") -- delete not need parameters - self.map:del(section, "ip_interface") - self.map:del(section, "ip_script") - elseif value == "web" then - self.map:del(section, "ip_network") -- delete not need parameters - self.map:del(section, "ip_interface") - self.map:del(section, "ip_script") - elseif value == "interface" then - self.map:del(section, "ip_network") -- delete not need parameters - self.map:del(section, "ip_url") - self.map:del(section, "ip_script") - elseif value == "script" then - self.map:del(section, "ip_network") - self.map:del(section, "ip_url") -- delete not need parameters - self.map:del(section, "ip_interface") - end - self.map:del(section, self.option) -- delete "ipv4_source" helper - return self.map:set(section, "ip_source", value) -- and write "ip_source -end -function src6.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4 - ip_network (default "wan") -- ####################################### -ipn4 = ns:taboption("advanced", ListValue, "ipv4_network", - translate("Network") .. " [IPv4]", - translate("Defines the network to read systems IPv4-Address from") ) -ipn4:depends("ipv4_source", "network") -ipn4.default = "wan" -WADM.cbi_add_networks(ipn4) -function ipn4.cfgvalue(self, section) - return DDNS.read_value(self, section, "ip_network") -end -function ipn4.validate(self, value) - if usev6:formvalue(section) == "1" - or src4:formvalue(section) ~= "network" then - -- ignore if IPv6 selected OR - -- ignore everything except "network" - return "" - else - return value - end -end -function ipn4.write(self, section, value) - if usev6:formvalue(section) == "1" - or src4:formvalue(section) ~= "network" then - -- ignore if IPv6 selected OR - -- ignore everything except "network" - return true - else - -- set also as "interface" for monitoring events changes/hot-plug - self.map:set(section, "interface", value) - self.map:del(section, self.option) -- delete "ipv4_network" helper - return self.map:set(section, "ip_network", value) -- and write "ip_network" - end -end -function ipn4.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv6 - ip_network (default "wan6") -- ###################################### -ipn6 = ns:taboption("advanced", ListValue, "ipv6_network", - translate("Network") .. " [IPv6]" ) -ipn6:depends("ipv6_source", "network") -ipn6.default = "wan6" -WADM.cbi_add_networks(ipn6) -if has_ipv6 then - ipn6.description = translate("Defines the network to read systems IPv6-Address from") -else - ipn6.description = err_ipv6_other -end -function ipn6.cfgvalue(self, section) - return DDNS.read_value(self, section, "ip_network") -end -function ipn6.validate(self, value) - if usev6:formvalue(section) ~= "1" - or src6:formvalue(section) ~= "network" then - -- ignore if IPv4 selected OR - -- ignore everything except "network" - return "" - elseif has_ipv6 then - return value - else - return nil, err_tab_adv(self) .. err_ipv6_plain - end -end -function ipn6.write(self, section, value) - if usev6:formvalue(section) ~= "1" - or src6:formvalue(section) ~= "network" then - -- ignore if IPv4 selected OR - -- ignore everything except "network" - return true - else - -- set also as "interface" for monitoring events changes/hotplug - self.map:set(section, "interface", value) - self.map:del(section, self.option) -- delete "ipv6_network" helper - return self.map:set(section, "ip_network", value) -- and write "ip_network" - end -end -function ipn6.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4 - ip_url (default "checkip.dyndns.com") -- ############################ -iurl4 = ns:taboption("advanced", Value, "ipv4_url", - translate("URL to detect") .. " [IPv4]", - translate("Defines the Web page to read systems IPv4-Address from") ) -iurl4:depends("ipv4_source", "web") -iurl4.default = "http://checkip.dyndns.com" -function iurl4.cfgvalue(self, section) - return DDNS.read_value(self, section, "ip_url") -end -function iurl4.validate(self, value) - if usev6:formvalue(section) == "1" - or src4:formvalue(section) ~= "web" then - -- ignore if IPv6 selected OR - -- ignore everything except "web" - return "" - elseif not value or #value == 0 then - return nil, err_tab_adv(self) .. translate("missing / required") - end - - local url = DDNS.parse_url(value) - if not (url.scheme == "http" or url.scheme == "https") then - return nil, err_tab_adv(self) .. translate("must start with 'http://'") - elseif not url.host then - return nil, err_tab_adv(self) .. " " .. translate("missing / required") - elseif SYS.call([[nslookup ]] .. url.host .. [[>/dev/null 2>&1]]) ~= 0 then - return nil, err_tab_adv(self) .. translate("can not resolve host: ") .. url.host - else - return value - end -end -function iurl4.write(self, section, value) - if usev6:formvalue(section) == "1" - or src4:formvalue(section) ~= "web" then - -- ignore if IPv6 selected OR - -- ignore everything except "web" - return true - else - self.map:del(section, self.option) -- delete "ipv4_url" helper - return self.map:set(section, "ip_url", value) -- and write "ip_url" - end -end -function iurl4.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv6 - ip_url (default "checkipv6.dyndns.com") -- ########################## -iurl6 = ns:taboption("advanced", Value, "ipv6_url", - translate("URL to detect") .. " [IPv6]" ) -iurl6:depends("ipv6_source", "web") -iurl6.default = "http://checkipv6.dyndns.com" -if has_ipv6 then - iurl6.description = translate("Defines the Web page to read systems IPv6-Address from") -else - iurl6.description = err_ipv6_other -end -function iurl6.cfgvalue(self, section) - return DDNS.read_value(self, section, "ip_url") -end -function iurl6.validate(self, value) - if usev6:formvalue(section) ~= "1" - or src6:formvalue(section) ~= "web" then - -- ignore if IPv4 selected OR - -- ignore everything except "web" - return "" - elseif not has_ipv6 then - return nil, err_tab_adv(self) .. err_ipv6_plain - elseif not value or #value == 0 then - return nil, err_tab_adv(self) .. translate("missing / required") - end - - local url = DDNS.parse_url(value) - if not (url.scheme == "http" or url.scheme == "https") then - return nil, err_tab_adv(self) .. translate("must start with 'http://'") - elseif not url.host then - return nil, err_tab_adv(self) .. " " .. translate("missing / required") - elseif SYS.call([[nslookup ]] .. url.host .. [[>/dev/null 2>&1]]) ~= 0 then - return nil, err_tab_adv(self) .. translate("can not resolve host: ") .. url.host - else - return value - end -end -function iurl6.write(self, section, value) - if usev6:formvalue(section) ~= "1" - or src6:formvalue(section) ~= "web" then - -- ignore if IPv4 selected OR - -- ignore everything except "web" - return true - else - self.map:del(section, self.option) -- delete "ipv6_url" helper - return self.map:set(section, "ip_url", value) -- and write "ip_url" - end -end -function iurl6.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4 + IPv6 - ip_interface -- ############################################## -ipi = ns:taboption("advanced", ListValue, "ip_interface", - translate("Interface"), - translate("Defines the interface to read systems IP-Address from") ) -ipi:depends("ipv4_source", "interface") -- IPv4 -ipi:depends("ipv6_source", "interface") -- or IPv6 -for _, v in pairs(SYS.net.devices()) do - -- show only interface set to a network - -- and ignore loopback - net = WADM.iface_get_network(v) - if net and net ~= "loopback" then - ipi:value(v) - end -end -function ipi.validate(self, value) - local fusev6 = usev6:formvalue(section) - if (fusev6 ~= "1" and src4:formvalue(section) ~= "interface") - or (fusev6 == "1" and src6:formvalue(section) ~= "interface") then - return "" - else - return value - end -end -function ipi.write(self, section, value) - local fusev6 = usev6:formvalue(section) - if (fusev6 ~= "1" and src4:formvalue(section) ~= "interface") - or (fusev6 == "1" and src6:formvalue(section) ~= "interface") then - return true - else - -- get network from device to - -- set also as "interface" for monitoring events changes/hotplug - local net = WADM.iface_get_network(value) - self.map:set(section, "interface", net) - return self.map:set(section, self.option, value) - end -end -function ipi.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4 + IPv6 - ip_script -- ################################################# -ips = ns:taboption("advanced", Value, "ip_script", - translate("Script"), - translate("User defined script to read systems IP-Address") ) -ips:depends("ipv4_source", "script") -- IPv4 -ips:depends("ipv6_source", "script") -- or IPv6 -ips.placeholder = "/path/to/script.sh" -function ips.validate(self, value) - local fusev6 = usev6:formvalue(section) - local split - if value then split = UTIL.split(value, " ") end - - if (fusev6 ~= "1" and src4:formvalue(section) ~= "script") - or (fusev6 == "1" and src6:formvalue(section) ~= "script") then - return "" - elseif not value or not (#value > 0) or not NXFS.access(split[1], "x") then - return nil, err_tab_adv(self) .. - translate("not found or not executable - Sample: '/path/to/script.sh'") - else - return value - end -end -function ips.write(self, section, value) - local fusev6 = usev6:formvalue(section) - if (fusev6 ~= "1" and src4:formvalue(section) ~= "script") - or (fusev6 == "1" and src6:formvalue(section) ~= "script") then - return true - else - return self.map:set(section, self.option, value) - end -end -function ips.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4 - interface - default "wan" -- ######################################## --- event network to monitor changes/hotplug/dynamic_dns_updater.sh --- only needs to be set if "ip_source"="web" or "script" --- if "ip_source"="network" or "interface" we use their network -eif4 = ns:taboption("advanced", ListValue, "ipv4_interface", - translate("Event Network") .. " [IPv4]", - translate("Network on which the ddns-updater scripts will be started") ) -eif4:depends("ipv4_source", "web") -eif4:depends("ipv4_source", "script") -eif4.default = "wan" -WADM.cbi_add_networks(eif4) -function eif4.cfgvalue(self, section) - return DDNS.read_value(self, section, "interface") -end -function eif4.validate(self, value) - local fsrc4 = src4:formvalue(section) or "" - if usev6:formvalue(section) == "1" - or fsrc4 == "network" - or fsrc4 == "interface" then - return "" -- ignore IPv6, network, interface - else - return value - end -end -function eif4.write(self, section, value) - local fsrc4 = src4:formvalue(section) or "" - if usev6:formvalue(section) == "1" - or fsrc4 == "network" - or fsrc4 == "interface" then - return true -- ignore IPv6, network, interface - else - self.map:del(section, self.option) -- delete "ipv4_interface" helper - return self.map:set(section, "interface", value) -- and write "interface" - end -end -function eif4.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv6 - interface - default "wan6" -- ####################################### --- event network to monitor changes/hotplug --- only needs to be set if "ip_source"="web" or "script" --- if "ip_source"="network" or "interface" we use their network -eif6 = ns:taboption("advanced", ListValue, "ipv6_interface", - translate("Event Network") .. " [IPv6]" ) -eif6:depends("ipv6_source", "web") -eif6:depends("ipv6_source", "script") -eif6.default = "wan6" -WADM.cbi_add_networks(eif6) -if not has_ipv6 then - eif6.description = err_ipv6_other -else - eif6.description = translate("Network on which the ddns-updater scripts will be started") -end -function eif6.cfgvalue(self, section) - return DDNS.read_value(self, section, "interface") -end -function eif6.validate(self, value) - local fsrc6 = src6:formvalue(section) or "" - if usev6:formvalue(section) ~= "1" - or fsrc6 == "network" - or fsrc6 == "interface" then - return "" -- ignore IPv4, network, interface - elseif not has_ipv6 then - return nil, err_tab_adv(self) .. err_ipv6_plain - else - return value - end -end -function eif6.write(self, section, value) - local fsrc6 = src6:formvalue(section) or "" - if usev6:formvalue(section) ~= "1" - or fsrc6 == "network" - or fsrc6 == "interface" then - return true -- ignore IPv4, network, interface - else - self.map:del(section, self.option) -- delete "ipv6_interface" helper - return self.map:set(section, "interface", value) -- and write "interface" - end -end -function eif6.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- IPv4/IPv6 - bind_network -- ################################################ - -local has_bindnet = DDNS.env_info("has_bindnet") - -if has_bindnet or ( ( m:get(section, "bind_network") or "" ) ~= "" ) then - bnet = ns:taboption("advanced", ListValue, "bind_network", - translate("Bind Network") ) - bnet:depends("ipv4_source", "web") - bnet:depends("ipv6_source", "web") - bnet.default = "" - bnet:value("", translate("-- default --")) - WADM.cbi_add_networks(bnet) - function bnet.cfgvalue(self, section) - local value = AbstractValue.cfgvalue(self, section) - if not has_bindnet and value ~= "" then - self.description = bold_on .. font_red .. - translate("Binding to a specific network not supported") .. font_off .. "
" .. - translate("please set to 'default'") .. " !" .. bold_off - else - self.description = translate("OPTIONAL: Network to use for communication") .. - "
" .. translate("Casual users should not change this setting") - end - return value - end - function bnet.validate(self, value) - if ( (value ~= "") and has_bindnet ) or (value == "") then return value end - return nil, err_tab_adv(self) .. translate("Binding to a specific network not supported") .. " !" - end - function bnet.parse(self, section, novld) - DDNS.value_parse(self, section, novld) - end -end - --- IPv4 + IPv6 - force_ipversion -- ########################################### --- optional to force wget/curl and host to use only selected IP version --- command parameter "-4" or "-6" - -local has_forceip = DDNS.env_info("has_forceip") - -if has_forceip or ( ( m:get(section, "force_ipversion") or "0" ) ~= "0" ) then - fipv = ns:taboption("advanced", Flag, "force_ipversion", - translate("Force IP Version") ) - fipv.orientation = "horizontal" - function fipv.cfgvalue(self, section) - local value = AbstractValue.cfgvalue(self, section) - if not has_forceip and value ~= "0" then - self.description = bold_on .. font_red .. - translate("Force IP Version not supported") .. font_off .. "
" .. - translate("please disable") .. " !" .. bold_off - else - self.description = translate("OPTIONAL: Force the usage of pure IPv4/IPv6 only communication.") - end - return value - end - function fipv.validate(self, value) - if (value == "1" and has_forceip) or value == "0" then return value end - return nil, err_tab_adv(self) .. translate("Force IP Version not supported") - end -end - --- IPv4 + IPv6 - dns_server -- ################################################ --- optional DNS Server to use resolving my IP - -local has_dnsserver = DDNS.env_info("has_dnsserver") - -if has_dnsserver or ( ( m:get(section, "dns_server") or "" ) ~= "" ) then - dns = ns:taboption("advanced", Value, "dns_server", - translate("DNS-Server"), - translate("OPTIONAL: Use non-default DNS-Server to detect 'Registered IP'.") .. "
" .. - translate("Format: IP or FQDN")) - dns.placeholder = "mydns.lan" - function dns.validate(self, value) - -- if .datatype is set, then it is checked before calling this function - if not value or (#value == 0) then - return "" -- ignore on empty - elseif not has_dnsserver then - return nil, err_tab_adv(self) .. translate("Specifying a DNS-Server is not supported") - elseif not DTYP.host(value) then - return nil, err_tab_adv(self) .. translate("use hostname, FQDN, IPv4- or IPv6-Address") - else - local ipv6 = usev6:formvalue(section) or "0" - local force = fipv:formvalue(section) or "0" - local command = CTRL.luci_helper .. [[ -]] - if (ipv6 == 1) then command = command .. [[6]] end - if (force == 1) then command = command .. [[f]] end - command = command .. [[d ]] .. value .. [[ -- verify_dns]] - - local ret = SYS.call(command) - if ret == 0 then return value -- everything OK - elseif ret == 2 then return nil, err_tab_adv(self) .. translate("nslookup can not resolve host") - elseif ret == 3 then return nil, err_tab_adv(self) .. translate("nc (netcat) can not connect") - elseif ret == 4 then return nil, err_tab_adv(self) .. translate("Forced IP Version don't matched") - else return nil, err_tab_adv(self) .. translate("unspecific error") - end - end - end - function dns.parse(self, section, novld) - DDNS.value_parse(self, section, novld) - end -end - --- IPv4 + IPv6 - force_dnstcp -- ############################################## - -local has_bindhost = DDNS.env_info("has_bindhost") - -if has_bindhost or ( ( m:get(section, "force_dnstcp") or "0" ) ~= "0" ) then - tcp = ns:taboption("advanced", Flag, "force_dnstcp", - translate("Force TCP on DNS") ) - tcp.orientation = "horizontal" - function tcp.cfgvalue(self, section) - local value = AbstractValue.cfgvalue(self, section) - if not has_bindhost and value ~= "0" then - self.description = bold_on .. font_red .. - translate("DNS requests via TCP not supported") .. font_off .. "
" .. - translate("please disable") .. " !" .. bold_off - else - self.description = translate("OPTIONAL: Force the use of TCP instead of default UDP on DNS requests.") - end - return value - end - function tcp.validate(self, value) - if (value == "1" and has_bindhost ) or value == "0" then - return value - end - return nil, err_tab_adv(self) .. translate("DNS requests via TCP not supported") - end -end - --- IPv4 + IPv6 - proxy -- ##################################################### --- optional Proxy to use for http/https requests [user:password@]proxyhost[:port] - -local has_proxy = DDNS.env_info("has_proxy") - -if has_proxy or ( ( m:get(section, "proxy") or "" ) ~= "" ) then - pxy = ns:taboption("advanced", Value, "proxy", - translate("PROXY-Server") ) - pxy.placeholder="user:password@myproxy.lan:8080" - function pxy.cfgvalue(self, section) - local value = AbstractValue.cfgvalue(self, section) - if not has_proxy and value ~= "" then - self.description = bold_on .. font_red .. - translate("PROXY-Server not supported") .. font_off .. "
" .. - translate("please remove entry") .. "!" .. bold_off - else - self.description = translate("OPTIONAL: Proxy-Server for detection and updates.") .. "
" .. - translate("Format") .. ": " .. bold_on .. "[user:password@]proxyhost:port" .. bold_off .. "
" .. - translate("IPv6 address must be given in square brackets") .. ": " .. - bold_on .. " [2001:db8::1]:8080" .. bold_off - end - return value - end - function pxy.validate(self, value) - -- if .datatype is set, then it is checked before calling this function - if not value or (#value == 0) then - return "" -- ignore on empty - elseif has_proxy then - local ipv6 = usev6:formvalue(section) or "0" - local force = fipv:formvalue(section) or "0" - local command = CTRL.luci_helper .. [[ -]] - if (ipv6 == 1) then command = command .. [[6]] end - if (force == 1) then command = command .. [[f]] end - command = command .. [[p ]] .. value .. [[ -- verify_proxy]] - local ret = SYS.call(command) - if ret == 0 then return value - elseif ret == 2 then return nil, err_tab_adv(self) .. translate("nslookup can not resolve host") - elseif ret == 3 then return nil, err_tab_adv(self) .. translate("nc (netcat) can not connect") - elseif ret == 4 then return nil, err_tab_adv(self) .. translate("Forced IP Version don't matched") - elseif ret == 5 then return nil, err_tab_adv(self) .. translate("proxy port missing") - else return nil, err_tab_adv(self) .. translate("unspecific error") - end - else - return nil, err_tab_adv(self) .. translate("PROXY-Server not supported") - end - end - function pxy.parse(self, section, novld) - DDNS.value_parse(self, section, novld) - end -end - --- use_syslog -- ############################################################## -slog = ns:taboption("advanced", ListValue, "use_syslog", - translate("Log to syslog"), - translate("Writes log messages to syslog. Critical Errors will always be written to syslog.") ) -slog.default = "2" -slog:value("0", translate("No logging")) -slog:value("1", translate("Info")) -slog:value("2", translate("Notice")) -slog:value("3", translate("Warning")) -slog:value("4", translate("Error")) -function slog.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- use_logfile -- ############################################################# -logf = ns:taboption("advanced", Flag, "use_logfile", - translate("Log to file"), - translate("Writes detailed messages to log file. File will be truncated automatically.") .. "
" .. - translate("File") .. [[: "]] .. logdir .. [[/]] .. section .. [[.log"]] ) -logf.orientation = "horizontal" -logf.default = "1" -- if not defined write to log by default - --- TAB: Timer #################################################################################### --- check_interval -- ########################################################## -ci = ns:taboption("timer", Value, "check_interval", - translate("Check Interval") ) -ci.template = "ddns/detail_value" -ci.default = "10" -function ci.validate(self, value) - if not DTYP.uinteger(value) - or tonumber(value) < 1 then - return nil, err_tab_timer(self) .. translate("minimum value 5 minutes == 300 seconds") - end - - local secs = DDNS.calc_seconds(value, cu:formvalue(section)) - if secs >= 300 then - return value - else - return nil, err_tab_timer(self) .. translate("minimum value 5 minutes == 300 seconds") - end -end -function ci.write(self, section, value) - -- remove when default - local secs = DDNS.calc_seconds(value, cu:formvalue(section)) - if secs ~= 600 then --default 10 minutes - return self.map:set(section, self.option, value) - else - self.map:del(section, "check_unit") - return self.map:del(section, self.option) - end -end -function ci.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- check_unit -- ############################################################## -cu = ns:taboption("timer", ListValue, "check_unit", "not displayed, but needed otherwise error", - translate("Interval to check for changed IP" .. "
" .. - "Values below 5 minutes == 300 seconds are not supported") ) -cu.template = "ddns/detail_lvalue" -cu.default = "minutes" -cu:value("seconds", translate("seconds")) -cu:value("minutes", translate("minutes")) -cu:value("hours", translate("hours")) ---cu:value("days", translate("days")) -function cu.write(self, section, value) - -- remove when default - local secs = DDNS.calc_seconds(ci:formvalue(section), value) - if secs ~= 600 then --default 10 minutes - return self.map:set(section, self.option, value) - else - return true - end -end -function cu.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- force_interval (modified) -- ############################################### -fi = ns:taboption("timer", Value, "force_interval", - translate("Force Interval") ) -fi.template = "ddns/detail_value" -fi.default = "72" -- see dynamic_dns_updater.sh script ---fi.rmempty = false -- validate ourselves for translatable error messages -function fi.validate(self, value) - if not DTYP.uinteger(value) - or tonumber(value) < 0 then - return nil, err_tab_timer(self) .. translate("minimum value '0'") - end - - local force_s = DDNS.calc_seconds(value, fu:formvalue(section)) - if force_s == 0 then - return value - end - - local ci_value = ci:formvalue(section) - if not DTYP.uinteger(ci_value) then - return "" -- ignore because error in check_interval above - end - - local check_s = DDNS.calc_seconds(ci_value, cu:formvalue(section)) - if force_s >= check_s then - return value - end - - return nil, err_tab_timer(self) .. translate("must be greater or equal 'Check Interval'") -end -function fi.write(self, section, value) - -- simulate rmempty=true remove default - local secs = DDNS.calc_seconds(value, fu:formvalue(section)) - if secs ~= 259200 then --default 72 hours == 3 days - return self.map:set(section, self.option, value) - else - self.map:del(section, "force_unit") - return self.map:del(section, self.option) - end -end -function fi.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- force_unit -- ############################################################## -fu = ns:taboption("timer", ListValue, "force_unit", "not displayed, but needed otherwise error", - translate("Interval to force updates send to DDNS Provider" .. "
" .. - "Setting this parameter to 0 will force the script to only run once" .. "
" .. - "Values lower 'Check Interval' except '0' are not supported") ) -fu.template = "ddns/detail_lvalue" -fu.default = "hours" ---fu.rmempty = false -- want to control write process ---fu:value("seconds", translate("seconds")) -fu:value("minutes", translate("minutes")) -fu:value("hours", translate("hours")) -fu:value("days", translate("days")) -function fu.write(self, section, value) - -- simulate rmempty=true remove default - local secs = DDNS.calc_seconds(fi:formvalue(section), value) - if secs ~= 259200 and secs ~= 0 then --default 72 hours == 3 days - return self.map:set(section, self.option, value) - else - return true - end -end -function fu.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- retry_count -- ############################################################# -rc = ns:taboption("timer", Value, "retry_count") -rc.title = translate("Error Retry Counter") -rc.description = translate("On Error the script will stop execution after given number of retrys") - .. "
" - .. translate("The default setting of '0' will retry infinite.") -rc.default = "0" -function rc.validate(self, value) - if not DTYP.uinteger(value) then - return nil, err_tab_timer(self) .. translate("minimum value '0'") - else - return value - end -end -function rc.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- retry_interval -- ########################################################## -ri = ns:taboption("timer", Value, "retry_interval", - translate("Error Retry Interval") ) -ri.template = "ddns/detail_value" -ri.default = "60" -function ri.validate(self, value) - if not DTYP.uinteger(value) - or tonumber(value) < 1 then - return nil, err_tab_timer(self) .. translate("minimum value '1'") - else - return value - end -end -function ri.write(self, section, value) - -- simulate rmempty=true remove default - local secs = DDNS.calc_seconds(value, ru:formvalue(section)) - if secs ~= 60 then --default 60seconds - return self.map:set(section, self.option, value) - else - self.map:del(section, "retry_unit") - return self.map:del(section, self.option) - end -end -function ri.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- retry_unit -- ############################################################## -ru = ns:taboption("timer", ListValue, "retry_unit", "not displayed, but needed otherwise error", - translate("On Error the script will retry the failed action after given time") ) -ru.template = "ddns/detail_lvalue" -ru.default = "seconds" ---ru.rmempty = false -- want to control write process -ru:value("seconds", translate("seconds")) -ru:value("minutes", translate("minutes")) ---ru:value("hours", translate("hours")) ---ru:value("days", translate("days")) -function ru.write(self, section, value) - -- simulate rmempty=true remove default - local secs = DDNS.calc_seconds(ri:formvalue(section), value) - if secs ~= 60 then --default 60seconds - return self.map:set(section, self.option, value) - else - return true -- will be deleted by retry_interval - end -end -function ru.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- TAB: LogView ################################################################################## -lv = ns:taboption("logview", DummyValue, "_logview") -lv.template = "ddns/detail_logview" -lv.inputtitle = translate("Read / Reread log file") -lv.rows = 50 -function lv.cfgvalue(self, section) - local lfile=logdir .. "/" .. section .. ".log" - if NXFS.access(lfile) then - return lfile .. "\n" .. translate("Please press [Read] button") - end - return lfile .. "\n" .. translate("File not found or empty") -end - -return m diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua deleted file mode 100644 index 2f06200146..0000000000 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/global.lua +++ /dev/null @@ -1,121 +0,0 @@ --- Copyright 2014 Christian Schoenebeck --- Licensed to the public under the Apache License 2.0. - -local NX = require "nixio" -local NXFS = require "nixio.fs" -local DISP = require "luci.dispatcher" -local SYS = require "luci.sys" -local CTRL = require "luci.controller.ddns" -- this application's controller -local DDNS = require "luci.tools.ddns" -- ddns multiused functions - --- cbi-map definition -- ####################################################### -local m = Map("ddns") -m.title = CTRL.app_title_back() -m.description = CTRL.app_description() -m.redirect = DISP.build_url("admin", "services", "ddns") - -function m.commit_handler(self) - if self.changed then -- changes ? - local command = CTRL.luci_helper .. " -- reload" - os.execute(command) -- reload configuration - end -end - --- cbi-section definition -- ################################################### -local ns = m:section( NamedSection, "global", "ddns", - translate("Global Settings"), - translate("Configure here the details for all Dynamic DNS services including this LuCI application.") - .. [[
]] - .. translate("It is NOT recommended for casual users to change settings on this page.") - .. [[
]] - .. [[]] - .. translate("For detailed information about parameter settings look here.") - .. [[]] - ) - --- section might not exist -function ns.cfgvalue(self, section) - if not self.map:get(section) then - self.map:set(section, nil, self.sectiontype) - end - return self.map:get(section) -end - --- upd_privateip -- ########################################################### -local ali = ns:option(Flag, "upd_privateip") -ali.title = translate("Allow non-public IP's") -ali.description = translate("Non-public and by default blocked IP's") .. ":" - .. [[
IPv4: ]] - .. "0/8, 10/8, 100.64/10, 127/8, 169.254/16, 172.16/12, 192.168/16" - .. [[
IPv6: ]] - .. "::/32, f000::/4" -ali.default = "0" - --- ddns_dateformat -- ######################################################### -local df = ns:option(Value, "ddns_dateformat") -df.title = translate("Date format") -df.description = [[]] - .. translate("For supported codes look here") - .. [[]] -df.template = "ddns/global_value" -df.default = "%F %R" -df.date_string = "" -function df.cfgvalue(self, section) - local value = AbstractValue.cfgvalue(self, section) or self.default - local epoch = os.time() - self.date_string = DDNS.epoch2date(epoch, value) - return value -end -function df.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- ddns_rundir -- ############################################################# -local rd = ns:option(Value, "ddns_rundir") -rd.title = translate("Status directory") -rd.description = translate("Directory contains PID and other status information for each running section") -rd.default = "/var/run/ddns" --- no need to validate. if empty default is used everything else created by dns-scripts -function rd.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- ddns_logdir -- ############################################################# -local ld = ns:option(Value, "ddns_logdir") -ld.title = translate("Log directory") -ld.description = translate("Directory contains Log files for each running section") -ld.default = "/var/log/ddns" --- no need to validate. if empty default is used everything else created by dns-scripts -function ld.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- ddns_loglines -- ########################################################### -local ll = ns:option(Value, "ddns_loglines") -ll.title = translate("Log length") -ll.description = translate("Number of last lines stored in log files") -ll.default = "250" -function ll.validate(self, value) - local n = tonumber(value) - if not n or math.floor(n) ~= n or n < 1 then - return nil, self.title .. ": " .. translate("minimum value '1'") - end - return value -end -function ll.parse(self, section, novld) - DDNS.value_parse(self, section, novld) -end - --- use_curl -- ################################################################ -if (SYS.call([[ grep -i "\+ssl" /usr/bin/wget >/dev/null 2>&1 ]]) == 0) -and NXFS.access("/usr/bin/curl") then - local pc = ns:option(Flag, "use_curl") - pc.title = translate("Use cURL") - pc.description = translate("If both cURL and GNU Wget are installed, Wget is used by default.") - .. [[
]] - .. translate("To use cURL activate this option.") - pc.orientation = "horizontal" - pc.default = "0" -end - -return m diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua deleted file mode 100644 index 290ef516ad..0000000000 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/hints.lua +++ /dev/null @@ -1,166 +0,0 @@ --- Copyright 2014-2016 Christian Schoenebeck --- Licensed to the public under the Apache License 2.0. - -local DISP = require "luci.dispatcher" -local SYS = require "luci.sys" -local CTRL = require "luci.controller.ddns" -- this application's controller -local DDNS = require "luci.tools.ddns" -- ddns multiused functions - --- html constants -font_red = [[]] -font_off = [[]] -bold_on = [[]] -bold_off = [[]] - --- cbi-map definition -- ####################################################### -m = Map("ddns") -m.title = CTRL.app_title_back() -m.description = CTRL.app_description() -m.redirect = DISP.build_url("admin", "services", "ddns") - --- SimpleSection definition -- ################################################# --- show Hints to optimize installation and script usage -s = m:section( SimpleSection, - translate("Hints"), - translate("Below a list of configuration tips for your system to run Dynamic DNS updates without limitations") ) - --- ddns-scripts needs to be updated for full functionality -if not CTRL.service_ok() then - local so = s:option(DummyValue, "_update_needed") - so.titleref = DISP.build_url("admin", "system", "opkg") - so.rawhtml = true - so.title = font_red .. bold_on .. - translate("Software update required") .. bold_off .. font_off - so.value = translate("The currently installed 'ddns-scripts' package did not support all available settings.") .. - "
" .. - translate("Please update to the current version!") -end - --- DDNS Service disabled -if not SYS.init.enabled("ddns") then - local se = s:option(DummyValue, "_not_enabled") - se.titleref = DISP.build_url("admin", "system", "startup") - se.rawhtml = true - se.title = bold_on .. - translate("DDNS Autostart disabled") .. bold_off - se.value = translate("Currently DDNS updates are not started at boot or on interface events." .. "
" .. - "This is the default if you run DDNS scripts by yourself (i.e. via cron with force_interval set to '0')" ) -end - --- No IPv6 support -if not DDNS.env_info("has_ipv6") then - local v6 = s:option(DummyValue, "_no_ipv6") - v6.titleref = 'http://www.openwrt.org" target="_blank' - v6.rawhtml = true - v6.title = bold_on .. - translate("IPv6 not supported") .. bold_off - v6.value = translate("IPv6 is currently not (fully) supported by this system" .. "
" .. - "Please follow the instructions on OpenWrt's homepage to enable IPv6 support" .. "
" .. - "or update your system to the latest OpenWrt Release") -end - --- No HTTPS support -if not DDNS.env_info("has_ssl") then - local sl = s:option(DummyValue, "_no_https") - sl.titleref = DISP.build_url("admin", "system", "opkg") - sl.rawhtml = true - sl.title = bold_on .. - translate("HTTPS not supported") .. bold_off - sl.value = translate("Neither GNU Wget with SSL nor cURL installed to support secure updates via HTTPS protocol.") .. - "
- " .. - translate("You should install 'wget' or 'curl' or 'uclient-fetch' with 'libustream-*ssl' package.") .. - "
- " .. - translate("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.") -end - --- No bind_network -if not DDNS.env_info("has_bindnet") then - local bn = s:option(DummyValue, "_no_bind_network") - bn.titleref = DISP.build_url("admin", "system", "opkg") - bn.rawhtml = true - bn.title = bold_on .. - translate("Binding to a specific network not supported") .. bold_off - bn.value = translate("Neither GNU Wget with SSL nor cURL installed to select a network to use for communication.") .. - "
- " .. - translate("You should install 'wget' or 'curl' package.") .. - "
- " .. - translate("GNU Wget will use the IP of given network, cURL will use the physical interface.") .. - "
- " .. - translate("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.") -end - --- currently only cURL possibly without proxy support -if not DDNS.env_info("has_proxy") then - local px = s:option(DummyValue, "_no_proxy") - px.titleref = DISP.build_url("admin", "system", "opkg") - px.rawhtml = true - px.title = bold_on .. - translate("cURL without Proxy Support") .. bold_off - px.value = translate("cURL is installed, but libcurl was compiled without proxy support.") .. - "
- " .. - translate("You should install 'wget' or 'uclient-fetch' package or replace libcurl.") .. - "
- " .. - translate("In some versions cURL/libcurl in OpenWrt is compiled without proxy support.") -end - --- "Force IP Version not supported" -if not DDNS.env_info("has_forceip") then - local fi = s:option(DummyValue, "_no_force_ip") - fi.titleref = DISP.build_url("admin", "system", "opkg") - fi.rawhtml = true - fi.title = bold_on .. - translate("Force IP Version not supported") .. bold_off - local value = translate("BusyBox's nslookup and Wget do not support to specify " .. - "the IP version to use for communication with DDNS Provider!") - if not (DDNS.env_info("has_wgetssl") or DDNS.env_info("has_curl") or DDNS.env_info("has_fetch")) then - value = value .. "
- " .. - translate("You should install 'wget' or 'curl' or 'uclient-fetch' package.") - end - if not DDNS.env_info("has_bindhost") then - value = value .. "
- " .. - translate("You should install 'bind-host' or 'knot-host' or 'drill' package for DNS requests.") - end - fi.value = value -end - --- "DNS requests via TCP not supported" -if not DDNS.env_info("has_bindhost") then - local dt = s:option(DummyValue, "_no_dnstcp") - dt.titleref = DISP.build_url("admin", "system", "opkg") - dt.rawhtml = true - dt.title = bold_on .. - translate("DNS requests via TCP not supported") .. bold_off - dt.value = translate("BusyBox's nslookup and hostip do not support to specify to use TCP " .. - "instead of default UDP when requesting DNS server!") .. - "
- " .. - translate("You should install 'bind-host' or 'knot-host' or 'drill' package for DNS requests.") -end - --- nslookup compiled with musl produce problems when using -if not DDNS.env_info("has_dnsserver") then - local ds = s:option(DummyValue, "_no_dnsserver") - ds.titleref = DISP.build_url("admin", "system", "opkg") - ds.rawhtml = true - ds.title = bold_on .. - translate("Using specific DNS Server not supported") .. bold_off - ds.value = translate("BusyBox's nslookup in the current compiled version " .. - "does not handle given DNS Servers correctly!") .. - "
- " .. - translate("You should install 'bind-host' or 'knot-host' or 'drill' or 'hostip' package, " .. - "if you need to specify a DNS server to detect your registered IP.") -end - --- certificates installed -if DDNS.env_info("has_ssl") and not DDNS.env_info("has_cacerts") then - local ca = s:option(DummyValue, "_no_certs") - ca.titleref = DISP.build_url("admin", "system", "opkg") - ca.rawhtml = true - ca.title = bold_on .. - translate("No certificates found") .. bold_off - ca.value = translate("If using secure communication you should verify server certificates!") .. - "
- " .. - translate("Install 'ca-certificates' package or needed certificates " .. - "by hand into /etc/ssl/certs default directory") -end - -return m diff --git a/applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua b/applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua deleted file mode 100644 index 11f73800ea..0000000000 --- a/applications/luci-app-ddns/luasrc/model/cbi/ddns/overview.lua +++ /dev/null @@ -1,249 +0,0 @@ --- Copyright 2014-2018 Christian Schoenebeck --- Licensed to the public under the Apache License 2.0. - -local DISP = require "luci.dispatcher" -local HTTP = require "luci.http" -local SYS = require "luci.sys" -local CTRL = require "luci.controller.ddns" -- this application's controller -local DDNS = require "luci.tools.ddns" -- ddns multiused functions - -local show_hints = not (DDNS.env_info("has_ipv6") -- IPv6 support - and DDNS.env_info("has_ssl") -- HTTPS support - and DDNS.env_info("has_proxy") -- Proxy support - and DDNS.env_info("has_bindhost") -- DNS TCP support - and DDNS.env_info("has_forceip") -- Force IP version - and DDNS.env_info("has_dnsserver") -- DNS server support - and DDNS.env_info("has_bindnet") -- Bind to network/interface - and DDNS.env_info("has_cacerts") -- certificates installed at /etc/ssl/certs - ) -local not_enabled = not SYS.init.enabled("ddns") -local need_update = not CTRL.service_ok() - --- html constants -font_red = [[]] -font_off = [[]] -bold_on = [[]] -bold_off = [[]] - --- cbi-map definition -- ####################################################### -m = Map("ddns") -m.title = CTRL.app_title_main() -m.description = CTRL.app_description() - -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 - command = command .. " -- restart" - os.execute(command) - else -- ddns service disabled, send SIGHUP to running - command = command .. " -- reload" - os.execute(command) - end - end -end - --- 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 -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 - if need_update then - local dv = s:option(DummyValue, "_update_needed") - dv.titleref = DISP.build_url("admin", "system", "packages") - dv.rawhtml = true - dv.title = font_red .. bold_on .. - translate("Software update required") .. bold_off .. font_off - dv.value = translate("The currently installed 'ddns-scripts' package did not support all available settings.") .. - "
" .. - translate("Please update to the current version!") - end - - -- DDNS Service disabled - if not_enabled then - local dv = s:option(DummyValue, "_not_enabled") - dv.titleref = DISP.build_url("admin", "system", "startup") - dv.rawhtml = true - dv.title = bold_on .. - translate("DDNS Autostart disabled") .. bold_off - dv.value = translate("Currently DDNS updates are not started at boot or on interface events." .. "
" .. - "You can start/stop each configuration here. It will run until next reboot.") - end - - -- Show more hints on a separate page - if show_hints then - local dv = s:option(DummyValue, "_separate") - dv.titleref = DISP.build_url("admin", "services", "ddns", "hints") - dv.rawhtml = true - dv.title = bold_on .. - translate("Show more") .. bold_off - dv.value = translate("Follow this link" .. "
" .. - "You will find more hints to optimize your system to run DDNS scripts with all options") - end -end - --- TableSection definition -- ################################################## -ts = m:section( TypedSection, "service", - translate("Overview"), - translate("Below is a list of configured DDNS configurations and their current state.") - .. "
" - .. 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'") - .. "
" - .. [[]] - .. translate("To change global settings click here") .. [[]] ) -ts.sectionhead = translate("Configuration") -ts.template = "cbi/tblsection" -ts.addremove = true -ts.extedit = DISP.build_url("admin", "services", "ddns", "detail", "%s") -function ts.create(self, name) - AbstractSection.create(self, name) - HTTP.redirect( self.extedit:format(name) ) -end - --- Lookup_Host and registered IP -- ################################################# -dom = ts:option(DummyValue, "_lookupIP", - translate("Lookup Hostname") .. "
" .. translate("Registered IP") ) -dom.template = "ddns/overview_doubleline" -function dom.set_one(self, section) - local lookup = self.map:get(section, "lookup_host") or "" - if lookup ~= "" then - return lookup - else - return [[]] .. translate("config error") .. [[]] - end -end -function dom.set_two(self, section) - local chk_sec = DDNS.calc_seconds( - tonumber(self.map:get(section, "check_interval")) or 10, - self.map:get(section, "check_unit") or "minutes" ) - local ip = DDNS.get_regip(section, chk_sec) - if ip == "NOFILE" then - 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 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 - command = command .. [[ -S ]] .. section - if (#dnsserver > 0) then command = command .. [[ -d ]] .. dnsserver end - command = command .. [[ -- get_registered_ip]] - ip = SYS.exec(command) - end - if ip == "" then ip = translate("no data") end - return ip -end - --- enabled -ena = ts:option( Flag, "enabled", - translate("Enabled")) -ena.template = "ddns/overview_enabled" -ena.rmempty = false - --- show PID and next update -upd = ts:option( DummyValue, "_update", - translate("Last Update") .. "
" .. translate("Next Update")) -upd.template = "ddns/overview_doubleline" -function upd.set_one(self, section) -- fill Last Update - -- get/validate last update - local uptime = SYS.uptime() - local lasttime = DDNS.get_lastupd(section) - if lasttime > uptime then -- /var might not be linked to /tmp and cleared on reboot - lasttime = 0 - end - - -- no last update happen - if lasttime == 0 then - return translate("never") - - -- we read last update - else - -- calc last update - -- os.epoch - sys.uptime + lastupdate(uptime) - local epoch = os.time() - uptime + lasttime - -- use linux date to convert epoch - return DDNS.epoch2date(epoch) - end -end -function upd.set_two(self, section) -- fill Next Update - -- get enabled state - local enabled = tonumber(self.map:get(section, "enabled") or 0) - local datenext = translate("unknown error") -- formatted date of next update - - -- get force seconds - local force_interval = tonumber(self.map:get(section, "force_interval") or 72) - local force_unit = self.map:get(section, "force_unit") or "hours" - local force_seconds = DDNS.calc_seconds(force_interval, force_unit) - - -- get last update and get/validate PID - local uptime = SYS.uptime() - local lasttime = DDNS.get_lastupd(section) - if lasttime > uptime then -- /var might not be linked to /tmp and cleared on reboot - lasttime = 0 - end - local pid = DDNS.get_pid(section) - - -- calc next update - if lasttime > 0 then - local epoch = os.time() - uptime + lasttime + force_seconds - -- use linux date to convert epoch - datelast = DDNS.epoch2date(epoch) - end - - -- process running but update needs to happen - if pid > 0 and ( lasttime + force_seconds - uptime ) < 0 then - datenext = translate("Verify") - - -- run once - elseif force_seconds == 0 then - datenext = translate("Run once") - - -- no process running and NOT enabled - elseif pid == 0 and enabled == 0 then - datenext = translate("Disabled") - - -- no process running and NOT - elseif pid == 0 and enabled ~= 0 then - datenext = translate("Stopped") - end - - return datenext -end - --- start/stop button -btn = ts:option( Button, "_startstop", - translate("Process ID") .. "
" .. translate("Start / Stop") ) -btn.template = "ddns/overview_startstop" -function btn.cfgvalue(self, section) - local pid = DDNS.get_pid(section) - if pid > 0 then - btn.inputtitle = "PID: " .. pid - btn.inputstyle = "reset" - btn.disabled = false - elseif (self.map:get(section, "enabled") or "0") ~= "0" then - btn.inputtitle = translate("Start") - btn.inputstyle = "apply" - btn.disabled = false - else - btn.inputtitle = "----------" - btn.inputstyle = "button" - btn.disabled = true - end - return true -end - -return m diff --git a/applications/luci-app-ddns/luasrc/tools/ddns.lua b/applications/luci-app-ddns/luasrc/tools/ddns.lua deleted file mode 100755 index be7f3eeff4..0000000000 --- a/applications/luci-app-ddns/luasrc/tools/ddns.lua +++ /dev/null @@ -1,429 +0,0 @@ --- Copyright 2014-2018 Christian Schoenebeck --- Licensed to the public under the Apache License 2.0. - -module("luci.tools.ddns", package.seeall) - -local NX = require "nixio" -local NXFS = require "nixio.fs" -local UCI = require "luci.model.uci" -local SYS = require "luci.sys" - -function env_info(type) - - if ( type == "has_ssl" ) or ( type == "has_proxy" ) or ( type == "has_forceip" ) - or ( type == "has_bindnet" ) or ( type == "has_fetch" ) - or ( type == "has_wgetssl" ) or ( type == "has_curl" ) - or ( type == "has_curlssl" ) or ( type == "has_curlpxy" ) - or ( type == "has_fetchssl" ) or ( type == "has_bbwget" ) then - - local function has_wgetssl() - return (SYS.call( [[which wget-ssl >/dev/null 2>&1]] ) == 0) -- and true or nil - end - - local function has_curlssl() - return (SYS.call( [[$(which curl) -V 2>&1 | grep -qF "https"]] ) == 0) - end - - local function has_fetch() - return (SYS.call( [[which uclient-fetch >/dev/null 2>&1]] ) == 0) - end - - local function has_fetchssl() - return NXFS.access("/lib/libustream-ssl.so") - end - - local function has_curl() - return (SYS.call( [[which curl >/dev/null 2>&1]] ) == 0) - end - - local function has_curlpxy() - return (SYS.call( [[grep -i "all_proxy" /usr/lib/libcurl.so* >/dev/null 2>&1]] ) == 0) - end - - local function has_bbwget() - return (SYS.call( [[$(which wget) -V 2>&1 | grep -iqF "busybox"]] ) == 0) - end - - if type == "has_wgetssl" then - return has_wgetssl() - - elseif type == "has_curl" then - return has_curl() - - elseif type == "has_curlssl" then - return has_curlssl() - - elseif type == "has_curlpxy" then - return has_curlpxy() - - elseif type == "has_fetch" then - return has_fetch() - - elseif type == "has_fetchssl" then - return has_fetchssl() - - elseif type == "has_bbwget" then - return has_bbwget() - - elseif type == "has_ssl" then - if has_wgetssl() then return true end - if has_curlssl() then return true end - if (has_fetch() and has_fetchssl()) then return true end - return false - - elseif type == "has_proxy" then - if has_wgetssl() then return true end - if has_curlpxy() then return true end - if has_fetch() then return true end - if has_bbwget() then return true end - return false - - elseif type == "has_forceip" then - if has_wgetssl() then return true end - if has_curl() then return true end - if has_fetch() then return true end -- only really needed for transfer - return false - - elseif type == "has_bindnet" then - if has_curl() then return true end - if has_wgetssl() then return true end - return false - end - - elseif ( type == "has_dnsserver" ) or ( type == "has_bindhost" ) or ( type == "has_hostip" ) or ( type == "has_nslookup" ) then - local function has_bindhost() - if (SYS.call( [[which host >/dev/null 2>&1]] ) == 0) then return true end - if (SYS.call( [[which khost >/dev/null 2>&1]] ) == 0) then return true end - if (SYS.call( [[which drill >/dev/null 2>&1]] ) == 0) then return true end - return false - end - - local function has_hostip() - return (SYS.call( [[which hostip >/dev/null 2>&1]] ) == 0) - end - - local function has_nslookup() - return (SYS.call( [[which nslookup >/dev/null 2>&1]] ) == 0) - end - - if type == "has_bindhost" then - return has_bindhost() - elseif type == "has_hostip" then - return has_hostip() - elseif type == "has_nslookup" then - return has_nslookup() - elseif type == "has_dnsserver" then - if has_bindhost() then return true end - if has_hostip() then return true end - if has_nslookup() then return true end - return false - end - - elseif type == "has_ipv6" then - return (NXFS.access("/proc/net/ipv6_route") and NXFS.access("/usr/sbin/ip6tables")) - - elseif type == "has_cacerts" then - --old _check_certs() local function - local _, v = NXFS.glob("/etc/ssl/certs/*.crt") - if ( v == 0 ) then _, v = NXFS.glob("/etc/ssl/certs/*.pem") end - return (v > 0) - else - return - end - -end - --- function to calculate seconds from given interval and unit -function calc_seconds(interval, unit) - if not tonumber(interval) then - return nil - elseif unit == "days" then - return (tonumber(interval) * 86400) -- 60 sec * 60 min * 24 h - elseif unit == "hours" then - return (tonumber(interval) * 3600) -- 60 sec * 60 min - elseif unit == "minutes" then - return (tonumber(interval) * 60) -- 60 sec - elseif unit == "seconds" then - return tonumber(interval) - else - return nil - end -end - --- convert epoch date to given format -function epoch2date(epoch, format) - if not format or #format < 2 then - local uci = UCI.cursor() - format = uci:get("ddns", "global", "ddns_dateformat") or "%F %R" - uci:unload("ddns") - end - format = format:gsub("%%n", "
") -- replace newline - format = format:gsub("%%t", " ") -- replace tab - return os.date(format, epoch) -end - --- read lastupdate from [section].update file -function get_lastupd(section) - 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 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 - uci:unload("ddns") - return pid -end - --- replacement of build-in read of UCI option --- modified AbstractValue.cfgvalue(self, section) from cbi.lua --- needed to read from other option then current value definition -function read_value(self, section, option) - local value - if self.tag_error[section] then - value = self:formvalue(section) - else - value = self.map:get(section, option) - end - - if not value then - return nil - elseif not self.cast or self.cast == type(value) then - return value - elseif self.cast == "string" then - if type(value) == "table" then - return value[1] - end - elseif self.cast == "table" then - return { value } - end -end - --- replacement of build-in parse of "Value" --- modified AbstractValue.parse(self, section, novld) from cbi.lua --- validate is called if rmempty/optional true or false --- before write check if forcewrite, value eq default, and more -function value_parse(self, section, novld) - local fvalue = self:formvalue(section) - local fexist = ( fvalue and (#fvalue > 0) ) -- not "nil" and "not empty" - local cvalue = self:cfgvalue(section) - local rm_opt = ( self.rmempty or self.optional ) - local eq_cfg -- flag: equal cfgvalue - - -- If favlue and cvalue are both tables and have the same content - -- make them identical - if type(fvalue) == "table" and type(cvalue) == "table" then - eq_cfg = (#fvalue == #cvalue) - if eq_cfg then - for i=1, #fvalue do - if cvalue[i] ~= fvalue[i] then - eq_cfg = false - end - end - end - if eq_cfg then - fvalue = cvalue - end - end - - -- removed parameter "section" from function call because used/accepted nowhere - -- also removed call to function "transfer" - local vvalue, errtxt = self:validate(fvalue) - - -- error handling; validate return "nil" - if not vvalue then - if novld then -- and "novld" set - return -- then exit without raising an error - end - - if fexist then -- and there is a formvalue - self:add_error(section, "invalid", errtxt or self.title .. ": invalid") - return -- so data are invalid - elseif not rm_opt then -- and empty formvalue but NOT (rmempty or optional) set - self:add_error(section, "missing", errtxt or self.title .. ": missing") - return -- so data is missing - elseif errtxt then - self:add_error(section, "invalid", errtxt) - return - end --- error ("\n option: " .. self.option .. --- "\n fvalue: " .. tostring(fvalue) .. --- "\n fexist: " .. tostring(fexist) .. --- "\n cvalue: " .. tostring(cvalue) .. --- "\n vvalue: " .. tostring(vvalue) .. --- "\n vexist: " .. tostring(vexist) .. --- "\n rm_opt: " .. tostring(rm_opt) .. --- "\n eq_cfg: " .. tostring(eq_cfg) .. --- "\n eq_def: " .. tostring(eq_def) .. --- "\n novld : " .. tostring(novld) .. --- "\n errtxt: " .. tostring(errtxt) ) - end - - -- lets continue with value returned from validate - eq_cfg = ( vvalue == cvalue ) -- update equal_config flag - local vexist = ( vvalue and (#vvalue > 0) ) and true or false -- not "nil" and "not empty" - local eq_def = ( vvalue == self.default ) -- equal_default flag - - -- (rmempty or optional) and (no data or equal_default) - if rm_opt and (not vexist or eq_def) then - if self:remove(section) then -- remove data from UCI - self.section.changed = true -- and push events - end - return - end - - -- not forcewrite and no changes, so nothing to write - if not self.forcewrite and eq_cfg then - return - end - - -- we should have a valid value here - assert (vvalue, "\n option: " .. self.option .. - "\n fvalue: " .. tostring(fvalue) .. - "\n fexist: " .. tostring(fexist) .. - "\n cvalue: " .. tostring(cvalue) .. - "\n vvalue: " .. tostring(vvalue) .. - "\n vexist: " .. tostring(vexist) .. - "\n rm_opt: " .. tostring(rm_opt) .. - "\n eq_cfg: " .. tostring(eq_cfg) .. - "\n eq_def: " .. tostring(eq_def) .. - "\n errtxt: " .. tostring(errtxt) ) - - -- write data to UCI; raise event only on changes - if self:write(section, vvalue) and not eq_cfg then - self.section.changed = true - end -end - ------------------------------------------------------------------------------ --- copied from https://svn.nmap.org/nmap/nselib/url.lua --- @author Diego Nehab --- @author Eddie Bell ---[[ - URI parsing, composition and relative URL resolution - LuaSocket toolkit. - Author: Diego Nehab - RCS ID: $Id: url.lua,v 1.37 2005/11/22 08:33:29 diego Exp $ - parse_query and build_query added For nmap (Eddie Bell ) -]]-- ---- --- Parses a URL and returns a table with all its parts according to RFC 2396. --- --- The following grammar describes the names given to the URL parts. --- --- ::= :///;?# --- ::= @: --- ::= [:] --- :: = {/} --- --- --- The leading / in / is considered part of --- . --- @param url URL of request. --- @param default Table with default values for each field. --- @return A table with the following fields, where RFC naming conventions have --- been preserved: --- scheme, authority, userinfo, --- user, password, host, --- port, path, params, --- query, and fragment. ------------------------------------------------------------------------------ -function parse_url(url) --, default) - -- initialize default parameters - local parsed = {} --- for i,v in base.pairs(default or parsed) do --- parsed[i] = v --- end - - -- remove whitespace --- url = string.gsub(url, "%s", "") - -- get fragment - url = string.gsub(url, "#(.*)$", - function(f) - parsed.fragment = f - return "" - end) - -- get scheme. Lower-case according to RFC 3986 section 3.1. - url = string.gsub(url, "^([%w][%w%+%-%.]*)%:", - function(s) - parsed.scheme = string.lower(s); - return "" - end) - -- get authority - url = string.gsub(url, "^//([^/]*)", - function(n) - parsed.authority = n - return "" - end) - -- get query stringing - url = string.gsub(url, "%?(.*)", - function(q) - parsed.query = q - return "" - end) - -- get params - url = string.gsub(url, "%;(.*)", - function(p) - parsed.params = p - return "" - end) - -- path is whatever was left - parsed.path = url - - local authority = parsed.authority - if not authority then - return parsed - end - authority = string.gsub(authority,"^([^@]*)@", - function(u) - parsed.userinfo = u; - return "" - end) - authority = string.gsub(authority, ":([0-9]*)$", - function(p) - if p ~= "" then - parsed.port = p - end; - return "" - end) - if authority ~= "" then - parsed.host = authority - end - - local userinfo = parsed.userinfo - if not userinfo then - return parsed - end - userinfo = string.gsub(userinfo, ":([^:]*)$", - function(p) - parsed.password = p; - return "" - end) - parsed.user = userinfo - return parsed -end diff --git a/applications/luci-app-ddns/luasrc/view/admin_status/index/ddns.htm b/applications/luci-app-ddns/luasrc/view/admin_status/index/ddns.htm deleted file mode 100644 index 9791065083..0000000000 --- a/applications/luci-app-ddns/luasrc/view/admin_status/index/ddns.htm +++ /dev/null @@ -1 +0,0 @@ -<%+ddns/system_status%> diff --git a/applications/luci-app-ddns/luasrc/view/ddns/detail_logview.htm b/applications/luci-app-ddns/luasrc/view/ddns/detail_logview.htm deleted file mode 100644 index fd1d5be268..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/detail_logview.htm +++ /dev/null @@ -1,56 +0,0 @@ - - - - -<%+cbi/valueheader%> - -
- -<% --- one button on top, one at the buttom -%> - /> - -

- -<% --- set a readable style taken from openwrt theme for textarea#syslog --- in openwrt theme there are problems with a width of 100 so we check for theme and set to lower value -%> - -

- -<% --- one button on top, one at the buttom -%> - /> - -<%+cbi/valuefooter%> - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/detail_lvalue.htm b/applications/luci-app-ddns/luasrc/view/ddns/detail_lvalue.htm deleted file mode 100644 index b69d780ea9..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/detail_lvalue.htm +++ /dev/null @@ -1,23 +0,0 @@ - - - -  -<% if self.widget == "select" then %> - -<% elseif self.widget == "radio" then - local c = 0 - for i, key in pairs(self.keylist) do - c = c + 1 -%> - /> - > - ><%=self.vallist[i]%> -<% if c == self.size then c = 0 %><% if self.orientation == "horizontal" then %> <% else %>
<% end %> -<% end end %> -<% end %> -<%+cbi/valuefooter%> - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/detail_value.htm b/applications/luci-app-ddns/luasrc/view/ddns/detail_value.htm deleted file mode 100644 index cbe76abc6e..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/detail_value.htm +++ /dev/null @@ -1,9 +0,0 @@ - - -<%+cbi/valueheader%> - /> - - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/global_value.htm b/applications/luci-app-ddns/luasrc/view/ddns/global_value.htm deleted file mode 100644 index 3cbb66b4bf..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/global_value.htm +++ /dev/null @@ -1,33 +0,0 @@ - - -<%+cbi/valueheader%> - - - -/> -
-
- <%:help%><%=self.description%> -
<%:Current setting%>: <%=self.date_string%> -
- - - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/overview_doubleline.htm b/applications/luci-app-ddns/luasrc/view/ddns/overview_doubleline.htm deleted file mode 100644 index 1d1b4be019..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/overview_doubleline.htm +++ /dev/null @@ -1,10 +0,0 @@ - - -<%+cbi/valueheader%> - -<%=self:set_one(section)%> -
-<%=self:set_two(section)%> - -<%+cbi/valuefooter%> - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/overview_enabled.htm b/applications/luci-app-ddns/luasrc/view/ddns/overview_enabled.htm deleted file mode 100644 index 2efc125fcc..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/overview_enabled.htm +++ /dev/null @@ -1,16 +0,0 @@ - - -<%+cbi/valueheader%> - - /> - - /> -> - -<%+cbi/valuefooter%> - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/overview_startstop.htm b/applications/luci-app-ddns/luasrc/view/ddns/overview_startstop.htm deleted file mode 100644 index 327028cbea..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/overview_startstop.htm +++ /dev/null @@ -1,17 +0,0 @@ - - -<%+cbi/valueheader%> - -<% if self:cfgvalue(section) ~= false then --- We need to garantie that function cfgvalue run first to set missing parameters -%> - - - " style="font-size: 100%;" type="button" onclick="onclick_startstop(this.id)" - <%= - attr("name", section) .. attr("id", cbid) .. attr("value", self.inputtitle) .. ifattr(self.disabled, "disabled") - %> /> -<% end %> - -<%+cbi/valuefooter%> - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/overview_status.htm b/applications/luci-app-ddns/luasrc/view/ddns/overview_status.htm deleted file mode 100644 index b6e89775c3..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/overview_status.htm +++ /dev/null @@ -1,180 +0,0 @@ - - - - - - diff --git a/applications/luci-app-ddns/luasrc/view/ddns/system_status.htm b/applications/luci-app-ddns/luasrc/view/ddns/system_status.htm deleted file mode 100644 index 41799cd4da..0000000000 --- a/applications/luci-app-ddns/luasrc/view/ddns/system_status.htm +++ /dev/null @@ -1,60 +0,0 @@ - - - -
- <%:Dynamic DNS%> -
-
-
-
<%:Configuration%>
-
<%:Next Update%>
-
<%:Lookup Hostname%>
-
<%:Registered IP%>
-
<%:Network%>
-
-
-

<%:Collecting data...%>
-
-
-
-
- diff --git a/applications/luci-app-ddns/root/usr/libexec/rpcd/luci.ddns b/applications/luci-app-ddns/root/usr/libexec/rpcd/luci.ddns new file mode 100644 index 0000000000..46209b9082 --- /dev/null +++ b/applications/luci-app-ddns/root/usr/libexec/rpcd/luci.ddns @@ -0,0 +1,321 @@ +#!/usr/bin/env lua + +local json = require "luci.jsonc" +local nixio = require "nixio" +local fs = require "nixio.fs" +local UCI = require "luci.model.uci" +local sys = require "luci.sys" +local util = require "luci.util" + +local luci_helper = "/usr/lib/ddns/dynamic_dns_lucihelper.sh" +local srv_name = "ddns-scripts" + +-- convert epoch date to given format +local function epoch2date(epoch, format) + if not format or #format < 2 then + local uci = UCI.cursor() + format = uci:get("ddns", "global", "ddns_dateformat") or "%F %R" + uci:unload("ddns") + end + format = format:gsub("%%n", "
") -- replace newline + format = format:gsub("%%t", " ") -- replace tab + return os.date(format, epoch) +end + +-- function to calculate seconds from given interval and unit +local function calc_seconds(interval, unit) + if not tonumber(interval) then + return nil + elseif unit == "days" then + return (tonumber(interval) * 86400) -- 60 sec * 60 min * 24 h + elseif unit == "hours" then + return (tonumber(interval) * 3600) -- 60 sec * 60 min + elseif unit == "minutes" then + return (tonumber(interval) * 60) -- 60 sec + elseif unit == "seconds" then + return tonumber(interval) + else + return nil + end +end + +local methods = { + get_services_log = { + args = { service_name = "service_name" }, + call = function(args) + local result = "File not found or empty" + local uci = UCI.cursor() + + local dirlog = uci:get('ddns', 'global', 'ddns_logdir') or "/var/log/ddns" + + -- Fallback to default logdir with unsecure path + if dirlog:match('%.%.%/') then dirlog = "/var/log/ddns" end + + if args and args.service_name and fs.access("%s/%s.log" % { dirlog, args.service_name }) then + result = fs.readfile("%s/%s.log" % { dirlog, args.service_name }) + end + + uci.unload() + + return { result = result } + end + }, + get_services_status = { + call = function() + local uci = UCI.cursor() + + local rundir = uci:get("ddns", "global", "ddns_rundir") or "/var/run/ddns" + local date_format = uci:get("ddns", "global", "ddns_dateformat") + local res = {} + + uci:foreach("ddns", "service", function (s) + local ip, last_update, next_update + local section = s[".name"] + if fs.access("%s/%s.ip" % { rundir, section }) then + ip = fs.readfile("%s/%s.ip" % { rundir, section }) + else + 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 , [[ -]] } + local lookup_host = s["lookup_host"] or "_nolookup_" + + if (use_ipv6 == 1) then command[#command+1] = [[6]] end + if (force_ipversion == 1) then command[#command+1] = [[f]] end + if (force_dnstcp == 1) then command[#command+1] = [[t]] end + if (is_glue == 1) then command[#command+1] = [[g]] end + command[#command+1] = [[l ]] + command[#command+1] = lookup_host + command[#command+1] = [[ -S ]] + command[#command+1] = section + if (#dnsserver > 0) then command[#command+1] = [[ -d ]] .. dnsserver end + command[#command+1] = [[ -- get_registered_ip]] + line = util.exec(table.concat(command)) + end + + local last_update = tonumber(fs.readfile("%s/%s.update" % { rundir, section } ) or 0) + local next_update, converted_last_update + local pid = tonumber(fs.readfile("%s/%s.pid" % { rundir, section } ) or 0) + + if pid > 0 and not nixio.kill(pid, 0) then + pid = 0 + end + + local uptime = sys.uptime() + + local force_seconds = calc_seconds( + tonumber(s["force_interval"]) or 72, + s["force_unit"] or "hours" ) + + -- process running but update needs to happen + -- problems if force_seconds > uptime + force_seconds = (force_seconds > uptime) and uptime or force_seconds + + if last_update > 0 then + local epoch = os.time() - uptime + last_update + force_seconds + -- use linux date to convert epoch + converted_last_update = epoch2date(epoch,date_format) + next_update = epoch2date(epoch + force_seconds) + end + + if pid > 0 and ( last_update + force_seconds - uptime ) <= 0 then + next_update = "Verify" + + -- run once + elseif force_seconds == 0 then + next_update = "Run once" + + -- no process running and NOT enabled + elseif pid == 0 and s['enabled'] == '0' then + next_update = "Disabled" + + -- no process running and enabled + elseif pid == 0 and s['enabled'] ~= '0' then + next_update = "Stopped" + end + + res[section] = { + ip = ip and ip:gsub("\n","") or nil, + last_update = last_update ~= 0 and converted_last_update or nil, + next_update = next_update or nil, + pid = pid or nil, + } + end + ) + + uci:unload("ddns") + + return res + + end + }, + get_ddns_state = { + call = function() + local ipkg = require "luci.model.ipkg" + local uci = UCI.cursor() + local dateformat = uci:get("ddns", "global", "ddns_dateformat") or "%F %R" + uci:unload("ddns") + local ver, srv_ver_cmd + local res = {} + + if ipkg then + ver = ipkg.info(srv_name)[srv_name].Version + else + srv_ver_cmd = luci_helper .. " -V | awk {'print $2'} " + ver = util.exec(srv_ver_cmd) + end + + res['_version'] = ver and #ver > 0 and ver or nil + res['_enabled'] = sys.init.enabled("ddns") + res['_curr_dateformat'] = os.date(dateformat) + + return res + end + }, + get_env = { + call = function() + local res = {} + local cache = {} + + local function has_wget() + return (sys.call( [[which wget >/dev/null 2>&1]] ) == 0) + end + + local function has_wgetssl() + if cache['has_wgetssl'] then return cache['has_wgetssl'] end + local res = (sys.call( [[which wget-ssl >/dev/null 2>&1]] ) == 0) + cache['has_wgetssl'] = res + return res + end + + local function has_curlssl() + return (sys.call( [[$(which curl) -V 2>&1 | grep -qF "https"]] ) == 0) + end + + local function has_fetch() + if cache['has_fetch'] then return cache['has_fetch'] end + local res = (sys.call( [[which uclient-fetch >/dev/null 2>&1]] ) == 0) + cache['has_fetch'] = res + return res + end + + local function has_fetchssl() + return fs.access("/lib/libustream-ssl.so") + end + + local function has_curl() + if cache['has_curl'] then return cache['has_curl'] end + local res = (sys.call( [[which curl >/dev/null 2>&1]] ) == 0) + cache['has_curl'] = res + return res + end + + local function has_curlpxy() + return (sys.call( [[grep -i "all_proxy" /usr/lib/libcurl.so* >/dev/null 2>&1]] ) == 0) + end + + local function has_bbwget() + return (sys.call( [[$(which wget) -V 2>&1 | grep -iqF "busybox"]] ) == 0) + end + + res['has_wget'] = has_wget() or false + res['has_curl'] = has_curl() or false + + res['has_ssl'] = has_wgetssl() or has_curlssl() or (has_fetch() and has_fetchssl()) or false + res['has_proxy'] = has_wgetssl() or has_curlpxy() or has_fetch() or has_bbwget or false + res['has_forceip'] = has_wgetssl() or has_curl() or has_fetch() or false + res['has_bindnet'] = has_curl() or has_wgetssl() or false + + local function has_bindhost() + if (sys.call( [[which host >/dev/null 2>&1]] ) == 0) then return true end + if (sys.call( [[which khost >/dev/null 2>&1]] ) == 0) then return true end + if (sys.call( [[which drill >/dev/null 2>&1]] ) == 0) then return true end + return false + end + + local function has_hostip() + return (sys.call( [[which hostip >/dev/null 2>&1]] ) == 0) + end + + local function has_nslookup() + return (sys.call( [[which nslookup >/dev/null 2>&1]] ) == 0) + end + + res['has_dnsserver'] = has_bindhost() or has_hostip() or has_nslookup() or false + + local function check_certs() + local _, v = fs.glob("/etc/ssl/certs/*.crt") + if ( v == 0 ) then _, v = NXFS.glob("/etc/ssl/certs/*.pem") end + return (v > 0) + end + + res['has_cacerts'] = check_certs() or false + + res['has_ipv6'] = (fs.access("/proc/net/ipv6_route") and fs.access("/usr/sbin/ip6tables")) + + return res + end + } +} + +local function parseInput() + local parse = json.new() + local done, err + + while true do + local chunk = io.read(4096) + if not chunk then + break + elseif not done and not err then + done, err = parse:parse(chunk) + end + end + + if not done then + print(json.stringify({ error = err or "Incomplete input" })) + os.exit(1) + end + + return parse:get() +end + +local function validateArgs(func, uargs) + local method = methods[func] + if not method then + print(json.stringify({ error = "Method not found" })) + os.exit(1) + end + + if type(uargs) ~= "table" then + print(json.stringify({ error = "Invalid arguments" })) + os.exit(1) + end + + uargs.ubus_rpc_session = nil + + local k, v + local margs = method.args or {} + for k, v in pairs(uargs) do + if margs[k] == nil or + (v ~= nil and type(v) ~= type(margs[k])) + then + print(json.stringify({ error = "Invalid arguments" })) + os.exit(1) + end + end + + return method +end + +if arg[1] == "list" then + local _, method, rv = nil, nil, {} + for _, method in pairs(methods) do rv[_] = method.args or {} end + print((json.stringify(rv):gsub(":%[%]", ":{}"))) +elseif arg[1] == "call" then + local args = parseInput() + local method = validateArgs(arg[2], args) + local result, code = method.call(args) + print((json.stringify(result):gsub("^%[%]$", "{}"))) + os.exit(code or 0) +end diff --git a/applications/luci-app-ddns/root/usr/share/rpcd/acl.d/luci-app-ddns.json b/applications/luci-app-ddns/root/usr/share/rpcd/acl.d/luci-app-ddns.json new file mode 100644 index 0000000000..aa68bdf03c --- /dev/null +++ b/applications/luci-app-ddns/root/usr/share/rpcd/acl.d/luci-app-ddns.json @@ -0,0 +1,17 @@ +{ + "luci-app-ddns": { + "description": "Grant access to ddns procedures", + "read": { + "ubus": { + "luci.ddns": [ "get_services_status", "get_ddns_state", "get_env", "get_services_log" ], + "luci": [ "setInitAction" ], + }, + "file": { + "/etc/ddns/services": [ "read" ], + "/etc/ddns/services_ipv6": [ "read" ], + "/usr/lib/ddns/dynamic_dns_lucihelper.sh": [ "exec" ] + }, + "uci": [ "ddns" ] + } + } +} -- 2.30.2