luci-app-ddns: improve accuracy of next update and check times

Depends on https://github.com/openwrt/packages/pull/27473

Refactor their display also.

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
Paul Donald
2025-09-23 14:42:35 +02:00
parent 7b07b93ff9
commit c74cf9f771
2 changed files with 33 additions and 46 deletions

View File

@@ -192,8 +192,6 @@ return view.extend({
poll_status: function(map, data) { poll_status: function(map, data) {
var status = data[1] || [], service = data[0] || [], rows = map.querySelectorAll('.cbi-section-table-row[data-sid]'), 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_enabled = map.querySelector('[data-name="_enabled"]').querySelector('.cbi-value-field'),
ddns_toggle = map.querySelector('[data-name="_toggle"]').querySelector('button'), ddns_toggle = map.querySelector('[data-name="_toggle"]').querySelector('button'),
services_list = map.querySelector('[data-name="_services_list"]').querySelector('.cbi-value-field'); services_list = map.querySelector('[data-name="_services_list"]').querySelector('.cbi-value-field');
@@ -212,36 +210,26 @@ return view.extend({
}); });
for (var i = 0; i < rows.length; i++) { for (var i = 0; i < rows.length; i++) {
section_id = rows[i].getAttribute('data-sid'); const section_id = rows[i].getAttribute('data-sid');
cfg_detail_ip = rows[i].querySelector('[data-name="_cfg_detail_ip"]'); const cfg_detail_ip = rows[i].querySelector('[data-name="_cfg_detail_ip"]');
cfg_update = rows[i].querySelector('[data-name="_cfg_update"]'); const cfg_update = rows[i].querySelector('[data-name="_cfg_update"]');
cfg_status = rows[i].querySelector('[data-name="_cfg_status"]'); const cfg_status = rows[i].querySelector('[data-name="_cfg_status"]');
reload = rows[i].querySelector('.cbi-section-actions .reload'); const reload = rows[i].querySelector('.cbi-section-actions .reload');
stop = rows[i].querySelector('.cbi-section-actions .stop'); const stop = rows[i].querySelector('.cbi-section-actions .stop');
cfg_enabled = uci.get('ddns', section_id, 'enabled'); const cfg_enabled = uci.get('ddns', section_id, 'enabled');
reload.disabled = (status['_enabled'] == 0 || cfg_enabled == 0); 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 = '<b>' + _('Not Running') + '</b>';
if (service[section_id]) {
stop.disabled = (!service[section_id].pid); stop.disabled = (!service[section_id].pid);
if (service[section_id].ip)
ip = service[section_id].ip; const host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error');
if (service[section_id].last_update) const ip = service[section_id]?.ip || _('No Data');
last_update = service[section_id].last_update; const last_update = service[section_id]?.last_update || _('Never');
if (service[section_id].next_update) const next_update = this.NextUpdateStrings[service[section_id]?.next_update] || service[section_id]?.next_update || _('Unknown');
next_update = this.NextUpdateStrings[service[section_id].next_update] || service[section_id].next_update; const next_check = service[section_id]?.next_check || _('Unknown');
if (service[section_id].pid) const service_status = service[section_id]?.pid ? '<b>' + _('Running') + '</b> : ' + service[section_id]?.pid : '<b>' + _('Not Running') + '</b>';
service_status = '<b>' + _('Running') + '</b> : ' + service[section_id].pid;
}
cfg_detail_ip.innerHTML = host + '<br />' + ip; cfg_detail_ip.innerHTML = host + '<br />' + ip;
cfg_update.innerHTML = last_update + '<br />' + next_update; cfg_update.innerHTML = last_update + '<br />' + next_check + '<br />' + next_update ;
cfg_status.innerHTML = service_status; cfg_status.innerHTML = service_status;
} }
@@ -1144,10 +1132,8 @@ return view.extend({
o.rawhtml = true; o.rawhtml = true;
o.modalonly = false; o.modalonly = false;
o.textvalue = function(section_id) { o.textvalue = function(section_id) {
var host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error'), const host = uci.get('ddns', section_id, 'lookup_host') || _('Configuration Error');
ip = _('No Data'); const ip = resolved[section_id]?.ip || _('No Data');
if (resolved[section_id] && resolved[section_id].ip)
ip = resolved[section_id].ip;
return host + '<br />' + ip; return host + '<br />' + ip;
}; };
@@ -1157,19 +1143,14 @@ return view.extend({
o.editable = true; o.editable = true;
o.modalonly = false; o.modalonly = false;
o = s.option(form.DummyValue, '_cfg_update', _('Last Update') + "<br />" + _('Next Update')); o = s.option(form.DummyValue, '_cfg_update', _('Last Update') + " |<br />" + _('Next Verify') + " |<br />" + _('Next Update'));
o.rawhtml = true; o.rawhtml = true;
o.modalonly = false; o.modalonly = false;
o.textvalue = function(section_id) { o.textvalue = function(section_id) {
var last_update = _('Never'), next_update = _('Unknown'); const last_update = resolved[section_id]?.last_update || _('Never');
if (resolved[section_id]) { const next_check = resolved[section_id]?.next_check || _('Unknown');
if (resolved[section_id].last_update) const next_update = _this.NextUpdateStrings[resolved[section_id]?.next_update] || resolved[section_id]?.next_update || _('Unknown');
last_update = resolved[section_id].last_update; return last_update + '<br />' + next_check + '<br />' + next_update;
if (resolved[section_id].next_update)
next_update = _this.NextUpdateStrings[resolved[section_id].next_update] || resolved[section_id].next_update;
}
return last_update + '<br />' + next_update;
}; };
return m.render().then(L.bind(function(m, nodes) { return m.render().then(L.bind(function(m, nodes) {

View File

@@ -12,8 +12,6 @@ const ddns_log_path = '/var/log/ddns';
const ddns_package_path = '/usr/share/ddns'; const ddns_package_path = '/usr/share/ddns';
const ddns_run_path = '/var/run/ddns'; const ddns_run_path = '/var/run/ddns';
const luci_helper = '/usr/lib/ddns/dynamic_dns_lucihelper.sh'; const luci_helper = '/usr/lib/ddns/dynamic_dns_lucihelper.sh';
const srv_name = 'ddns-scripts';
const opkg_info_path = '/usr/lib/opkg/info';
const ddns_version_file = '/usr/share/ddns/version'; const ddns_version_file = '/usr/share/ddns/version';
@@ -107,7 +105,7 @@ const methods = {
uci.foreach('ddns', 'service', function(s) { uci.foreach('ddns', 'service', function(s) {
/* uci.foreach danger zone: if you inadvertently call uci.unload('ddns') /* uci.foreach danger zone: if you inadvertently call uci.unload('ddns')
anywhere in this foreach loop, you will produce some spectacular undefined behaviour */ anywhere in this foreach loop, you will produce some spectacular undefined behaviour */
let ip, lastUpdate, nextUpdate; let ip, lastUpdate, nextUpdate, nextCheck;
const section = s['.name']; const section = s['.name'];
if (section == '.anonymous') if (section == '.anonymous')
return; return;
@@ -137,6 +135,7 @@ const methods = {
} }
lastUpdate = int(readfile(`${rundir}/${section}.update`) || 0); lastUpdate = int(readfile(`${rundir}/${section}.update`) || 0);
nextCheck = int(readfile(`${rundir}/${section}.nextcheck`) || 0);
let pid = int(readfile(`${rundir}/${section}.pid`) || 0); let pid = int(readfile(`${rundir}/${section}.pid`) || 0);
@@ -161,10 +160,16 @@ const methods = {
if (lastUpdate > 0) { if (lastUpdate > 0) {
const epoch = time() - _uptime + lastUpdate; const epoch = time() - _uptime + lastUpdate;
convertedLastUpdate = epoch2date(epoch); convertedLastUpdate = epoch2date(epoch);
nextUpdate = epoch2date(epoch + forcedUpdateInterval + checkInterval); nextUpdate = epoch2date(epoch + forcedUpdateInterval);
} }
if (pid > 0 && (lastUpdate + forcedUpdateInterval + checkInterval - _uptime) <= 0) { let convertedNextCheck;
if (nextCheck > 0) {
const epoch = time() - _uptime + nextCheck;
convertedNextCheck = epoch2date(epoch);
}
if (pid > 0 && (lastUpdate + forcedUpdateInterval - _uptime) <= 0) {
nextUpdate = 'Verify'; nextUpdate = 'Verify';
} else if (forcedUpdateInterval === 0) { } else if (forcedUpdateInterval === 0) {
nextUpdate = 'Run once'; nextUpdate = 'Run once';
@@ -178,6 +183,7 @@ const methods = {
ip: ip ? replace(trim(ip), '\n', '<br/>') : null, ip: ip ? replace(trim(ip), '\n', '<br/>') : null,
last_update: lastUpdate !== 0 ? convertedLastUpdate : null, last_update: lastUpdate !== 0 ? convertedLastUpdate : null,
next_update: nextUpdate || null, next_update: nextUpdate || null,
next_check : nextCheck !== 0 ? convertedNextCheck : null,
pid: pid || null, pid: pid || null,
}; };
}); });