diff --git a/CHANGES b/CHANGES
index 12291d84e..86d172426 100644
--- a/CHANGES
+++ b/CHANGES
@@ -2659,5 +2659,5 @@
* dashboard: backup logs links are grayed out because of z-index
* branding: make oidc login does not use cloudron name
* translation: fix crash when translated text has single quote (french)
-
+* dyndns: show logs
diff --git a/dashboard/src/js/client.js b/dashboard/src/js/client.js
index d84f7c39e..e7414704e 100644
--- a/dashboard/src/js/client.js
+++ b/dashboard/src/js/client.js
@@ -79,6 +79,7 @@ var TASK_TYPES = {
TASK_CHANGE_MAIL_LOCATION: 'changeMailLocation',
TASK_SYNC_DNS_RECORDS: 'syncDnsRecords',
TASK_UPDATE_DISK_USAGE: 'updateDiskUsage',
+ TASK_SYNC_DYNDNS: 'syncDyndns',
};
const APP_TYPES = {
@@ -4083,9 +4084,10 @@ angular.module('Application').service('Client', ['$http', '$interval', '$timeout
return 'User ' + (data.user ? data.user.username : data.userId) + ' logged out';
case ACTION_DYNDNS_UPDATE: {
- details = '';
- if (data.fromIpv4 !== data.toIpv4) details += 'DNS was updated from IPv4 ' + data.fromIpv4 + ' to ' + data.toIpv4 + '. ';
- if (data.fromIpv6 !== data.toIpv6) details += 'DNS was updated from IPv6 ' + data.fromIpv6 + ' to ' + data.toIpv6 + '.';
+ details = data.errorMessage ? 'Error updating DNS. ' : 'Updated DNS. ';
+ if (data.fromIpv4 !== data.toIpv4) details += 'From IPv4 ' + data.fromIpv4 + ' to ' + data.toIpv4 + '. ';
+ if (data.fromIpv6 !== data.toIpv6) details += 'From IPv6 ' + data.fromIpv6 + ' to ' + data.toIpv6 + '.';
+ if (data.errorMessage) details += ' ' + data.errorMessage;
return details;
}
diff --git a/dashboard/src/translation/en.json b/dashboard/src/translation/en.json
index 91d097caf..55dc47ccc 100644
--- a/dashboard/src/translation/en.json
+++ b/dashboard/src/translation/en.json
@@ -790,7 +790,8 @@
},
"dyndns": {
"title": "Dynamic DNS",
- "description": "Enable this option to keep all your DNS records in sync with a changing IP address. This is useful when Cloudron runs in a network with a frequently changing public IP address like a home connection."
+ "description": "Enable this option to keep all your DNS records in sync with a changing IP address. This is useful when Cloudron runs in a network with a frequently changing public IP address like a home connection.",
+ "showLogsAction": "Show Logs"
},
"configureIp": {
"title": "Configure IP Provider",
diff --git a/dashboard/src/translation/nl.json b/dashboard/src/translation/nl.json
index 29879126a..a8bd1affc 100644
--- a/dashboard/src/translation/nl.json
+++ b/dashboard/src/translation/nl.json
@@ -1502,7 +1502,8 @@
"paste": "Plakken",
"copy": "Kopiëren",
"cut": "Knippen",
- "edit": "Bewerk"
+ "edit": "Bewerk",
+ "open": "Open"
},
"mtime": "Bewerkt"
},
@@ -1517,6 +1518,16 @@
},
"newDirectory": {
"errorAlreadyExists": "Bestaat al"
+ },
+ "uploader": {
+ "exitWarning": "Uploaden nog bezig. Weet je zeker dat je deze pagina wilt sluiten?",
+ "uploading": "Uploaden"
+ },
+ "extractionInProgress": "Bezig met uitpakken",
+ "textEditor": {
+ "undo": "Ongedaan maken",
+ "redo": "Opnieuw doen",
+ "save": "Bewaar"
}
},
"email": {
diff --git a/dashboard/src/translation/ru.json b/dashboard/src/translation/ru.json
index 6b1f4b7e4..02a696ea5 100644
--- a/dashboard/src/translation/ru.json
+++ b/dashboard/src/translation/ru.json
@@ -1489,7 +1489,8 @@
"cut": "Вырезать",
"paste": "Вставить",
"selectAll": "Выбрать все",
- "copy": "Скопировать"
+ "copy": "Скопировать",
+ "open": "Открыть"
},
"symlink": "Символическая ссылка на {{ target }}",
"mtime": "Изменён"
@@ -1517,6 +1518,16 @@
},
"status": {
"restartingApp": "перезапускаем приложение"
+ },
+ "extractionInProgress": "Идёт извлечение",
+ "uploader": {
+ "exitWarning": "Загрузка ещё не завершена. Вы уверены, что хотите закрыть страницу?",
+ "uploading": "Загружаем"
+ },
+ "textEditor": {
+ "undo": "Отменить операцию",
+ "redo": "Повторить операцию",
+ "save": "Сохранить"
}
},
"email": {
diff --git a/dashboard/src/views/network.html b/dashboard/src/views/network.html
index 49ce72c77..b7212da0a 100644
--- a/dashboard/src/views/network.html
+++ b/dashboard/src/views/network.html
@@ -277,7 +277,21 @@
diff --git a/dashboard/src/views/network.js b/dashboard/src/views/network.js
index 6e6aa742d..10a856816 100644
--- a/dashboard/src/views/network.js
+++ b/dashboard/src/views/network.js
@@ -1,9 +1,9 @@
'use strict';
/* global angular */
-/* global $ */
+/* global $, TASK_TYPES */
-angular.module('Application').controller('NetworkController', ['$scope', '$location', 'Client', function ($scope, $location, Client) {
+angular.module('Application').controller('NetworkController', ['$scope', '$location', '$timeout', 'Client', function ($scope, $location, $timeout, Client) {
Client.onReady(function () { if (!Client.getUserInfo().isAtLeastAdmin) $location.path('/'); });
$scope.user = Client.getUserInfo();
@@ -37,12 +37,25 @@ angular.module('Application').controller('NetworkController', ['$scope', '$locat
busy: false,
error: '',
isEnabled: false,
+ tasks: [],
+
+ refreshTasks: function () {
+ Client.getTasksByType(TASK_TYPES.TASK_SYNC_DYNDNS, function (error, tasks) {
+ if (error) return console.error(error);
+ $scope.dyndnsConfigure.tasks = tasks.slice(0, 10);
+ if ($scope.dyndnsConfigure.tasks.length && $scope.dyndnsConfigure.tasks[0].active) {
+ $timeout($scope.renewCerts.refreshTasks, 5000);
+ }
+ });
+ },
refresh: function () {
Client.getDynamicDnsConfig(function (error, enabled) {
if (error) return console.error(error);
$scope.dyndnsConfigure.isEnabled = enabled;
+
+ $scope.dyndnsConfigure.refreshTasks();
});
},
diff --git a/src/cron.js b/src/cron.js
index 124a0b7f1..8f98bf7dd 100644
--- a/src/cron.js
+++ b/src/cron.js
@@ -245,8 +245,9 @@ function dynamicDnsChanged(enabled) {
if (enabled) {
gJobs.dynamicDns = new CronJob({
- cronTime: '5 * * * * *', // we only update the records if the ip has changed.
- onTick: async () => await safe(dyndns.sync(AuditSource.CRON), { debug }),
+ // often home IPs change at the full hour, so we give it 5min to settle
+ cronTime: '00 5 * * * *',
+ onTick: async () => { await safe(dyndns.refreshDns(AuditSource.CRON), { debug }); },
start: true
});
} else {
diff --git a/src/dyndns.js b/src/dyndns.js
index f42e1af47..944e6b0f2 100644
--- a/src/dyndns.js
+++ b/src/dyndns.js
@@ -1,6 +1,7 @@
'use strict';
exports = module.exports = {
+ refreshDns,
sync
};
@@ -13,50 +14,70 @@ const apps = require('./apps.js'),
paths = require('./paths.js'),
safe = require('safetydance'),
settings = require('./settings.js'),
- sysinfo = require('./sysinfo.js');
+ sysinfo = require('./sysinfo.js'),
+ tasks = require('./tasks.js');
-// called for dynamic dns setups where we have to update the IP
// FIXME: this races with apptask. can result in a conflict if apptask is doing some dns operation and this code changes entries
-async function sync(auditSource) {
+async function refreshDns(auditSource) {
assert.strictEqual(typeof auditSource, 'object');
const ipv4 = await sysinfo.getServerIPv4();
const ipv6 = await sysinfo.getServerIPv6();
const info = safe.JSON.parse(safe.fs.readFileSync(paths.DYNDNS_INFO_FILE, 'utf8')) || { ipv4: null, ipv6: null };
- if (info.ip) { // legacy cache file
- info.ipv4 = info.ip;
- delete info.ip;
- }
const ipv4Changed = info.ipv4 !== ipv4;
const ipv6Changed = ipv6 && info.ipv6 !== ipv6; // both should be RFC 5952 format
if (!ipv4Changed && !ipv6Changed) {
- debug(`refreshDNS: no change in IP ipv4: ${ipv4} ipv6: ${ipv6}`);
+ debug(`refreshDns: no change in IP. ipv4: ${ipv4} ipv6: ${ipv6}`);
return;
}
- debug(`refreshDNS: updating IP from ${info.ipv4} to ipv4: ${ipv4} (changed: ${ipv4Changed}) ipv6: ${ipv6} (changed: ${ipv6Changed})`);
- if (ipv4Changed) await dns.upsertDnsRecords(constants.DASHBOARD_SUBDOMAIN, settings.dashboardDomain(), 'A', [ ipv4 ]);
- if (ipv6Changed) await dns.upsertDnsRecords(constants.DASHBOARD_SUBDOMAIN, settings.dashboardDomain(), 'AAAA', [ ipv6 ]);
+ debug(`refreshDns: updating IP from ${info.ipv4} to ipv4: ${ipv4} (changed: ${ipv4Changed}) ipv6: ${ipv6} (changed: ${ipv6Changed})`);
+
+ // update dns in a separate task so we can have trackable logs
+ const taskId = await tasks.add(tasks.TASK_SYNC_DYNDNS, [ ipv4Changed ? ipv4 : null, ipv6Changed ? ipv6 : null, auditSource ]);
+ tasks.startTask(taskId, {}, async function (error) {
+ if (error) {
+ await eventlog.add(eventlog.ACTION_DYNDNS_UPDATE, auditSource, { taskId, fromIpv4: info.ipv4, fromIpv6: info.ipv6, toIpv4: ipv4, toIpv6: ipv6, errorMessage: error.message });
+ return;
+ }
+
+ await eventlog.add(eventlog.ACTION_DYNDNS_UPDATE, auditSource, { taskId, fromIpv4: info.ipv4, fromIpv6: info.ipv6, toIpv4: ipv4, toIpv6: ipv6 });
+ info.ipv4 = ipv4;
+ info.ipv6 = ipv6;
+ safe.fs.writeFileSync(paths.DYNDNS_INFO_FILE, JSON.stringify(info), 'utf8');
+ });
+
+ return taskId;
+}
+
+async function sync(ipv4, ipv6, auditSource, progressCallback) {
+ assert(ipv4 === null || typeof ipv4 === 'string');
+ assert(ipv6 === null || typeof ipv6 === 'string');
+ assert.strictEqual(typeof auditSource, 'object');
+ assert.strictEqual(typeof progressCallback, 'function');
+
+ let percent = 10;
+ progressCallback({ percent, message: `Updating dashboard domain ${settings.dashboardFqdn()}`});
+ if (ipv4) await dns.upsertDnsRecords(constants.DASHBOARD_SUBDOMAIN, settings.dashboardDomain(), 'A', [ ipv4 ]);
+ if (ipv6) await dns.upsertDnsRecords(constants.DASHBOARD_SUBDOMAIN, settings.dashboardDomain(), 'AAAA', [ ipv6 ]);
const result = await apps.list();
for (const app of result) {
+ percent += Math.round(90/result.length);
+ progressCallback({ percent, message: `Updating app ${app.fqdn}`});
+
const locations = [{ domain: app.domain, subdomain: app.subdomain }]
.concat(app.secondaryDomains)
.concat(app.redirectDomains)
.concat(app.aliasDomains);
for (const location of locations) {
- if (ipv4Changed) await dns.upsertDnsRecords(location.subdomain, location.domain, 'A', [ ipv4 ]);
- if (ipv6Changed) await dns.upsertDnsRecords(location.subdomain, location.domain, 'AAAA', [ ipv6 ]);
+ if (ipv4) await dns.upsertDnsRecords(location.subdomain, location.domain, 'A', [ ipv4 ]);
+ if (ipv6) await dns.upsertDnsRecords(location.subdomain, location.domain, 'AAAA', [ ipv6 ]);
}
}
- debug('refreshDNS: updated apps');
-
- await eventlog.add(eventlog.ACTION_DYNDNS_UPDATE, auditSource, { fromIpv4: info.ipv4, fromIpv6: info.ipv6, toIpv4: ipv4, toIpv6: ipv6 });
- info.ipv4 = ipv4;
- info.ipv6 = ipv6;
- safe.fs.writeFileSync(paths.DYNDNS_INFO_FILE, JSON.stringify(info), 'utf8');
+ progressCallback({ percent: 100, message: 'refreshDNS: updated apps' });
}
diff --git a/src/tasks.js b/src/tasks.js
index 5b981893f..a189fd35e 100644
--- a/src/tasks.js
+++ b/src/tasks.js
@@ -23,6 +23,7 @@ exports = module.exports = {
TASK_BACKUP: 'backup',
TASK_UPDATE: 'update',
TASK_CHECK_CERTS: 'checkCerts',
+ TASK_SYNC_DYNDNS: 'syncDyndns',
TASK_SETUP_DNS_AND_CERT: 'setupDnsAndCert',
TASK_CLEAN_BACKUPS: 'cleanBackups',
TASK_SYNC_EXTERNAL_LDAP: 'syncExternalLdap',
diff --git a/src/taskworker.js b/src/taskworker.js
index 648d2bf20..6bdee6f8f 100755
--- a/src/taskworker.js
+++ b/src/taskworker.js
@@ -9,6 +9,7 @@ const apptask = require('./apptask.js'),
cloudron = require('./cloudron.js'),
database = require('./database.js'),
dns = require('./dns.js'),
+ dyndns = require('./dyndns.js'),
externalLdap = require('./externalldap.js'),
fs = require('fs'),
mail = require('./mail.js'),
@@ -29,6 +30,7 @@ const TASKS = { // indexed by task type
syncExternalLdap: externalLdap.sync,
changeMailLocation: mail.changeLocation,
syncDnsRecords: dns.syncDnsRecords,
+ syncDyndns: dyndns.sync,
updateDiskUsage: system.updateDiskUsage,
_identity: async (arg, progressCallback) => { progressCallback(); return arg; },