Merge remote changes - resolve conflicts: keep remote package.json v1.4.0, keep local self-updater.js logic, features.js regenerated by build
This commit is contained in:
@@ -13,8 +13,10 @@ COPY src/ ./src/
|
|||||||
COPY routes/ ./routes/
|
COPY routes/ ./routes/
|
||||||
COPY openapi.yaml ./
|
COPY openapi.yaml ./
|
||||||
|
|
||||||
ARG DASHCADDY_COMMIT=unknown
|
# VERSION file holds the short git SHA the image was built from. Committed as
|
||||||
RUN echo "${DASHCADDY_COMMIT}" > VERSION
|
# 'dev' for source builds; the release script (scripts/release.sh) overwrites it
|
||||||
|
# with the actual commit hash before tarballing each release.
|
||||||
|
COPY VERSION ./
|
||||||
|
|
||||||
# Note: Running as root because container needs Docker socket access
|
# Note: Running as root because container needs Docker socket access
|
||||||
# (which is root-equivalent anyway). Socket access required for container management.
|
# (which is root-equivalent anyway). Socket access required for container management.
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
dev
|
||||||
@@ -543,11 +543,36 @@ class BackupManager extends EventEmitter {
|
|||||||
switch (destination.type) {
|
switch (destination.type) {
|
||||||
case 'local':
|
case 'local':
|
||||||
return await this.saveToLocal(data, destination, backupId);
|
return await this.saveToLocal(data, destination, backupId);
|
||||||
|
case 'dropbox':
|
||||||
|
return await this.saveToDropbox(data, destination, backupId);
|
||||||
|
case 'webdav':
|
||||||
|
return await this.saveToWebDAV(data, destination, backupId);
|
||||||
|
case 'sftp':
|
||||||
|
return await this.saveToSFTP(data, destination, backupId);
|
||||||
default:
|
default:
|
||||||
throw new Error(`Unsupported destination type: ${destination.type}`);
|
throw new Error(`Unsupported destination type: ${destination.type}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load encrypted backup blob from a destination location.
|
||||||
|
* Returns a Buffer that can be passed to decryptBackup/decompressBackup.
|
||||||
|
*/
|
||||||
|
async loadFromDestination(location) {
|
||||||
|
switch (location.type) {
|
||||||
|
case 'local':
|
||||||
|
return fs.readFileSync(location.path);
|
||||||
|
case 'dropbox':
|
||||||
|
return await this.loadFromDropbox(location);
|
||||||
|
case 'webdav':
|
||||||
|
return await this.loadFromWebDAV(location);
|
||||||
|
case 'sftp':
|
||||||
|
return await this.loadFromSFTP(location);
|
||||||
|
default:
|
||||||
|
throw new Error(`Unsupported destination type: ${location.type}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save to local filesystem
|
* Save to local filesystem
|
||||||
*/
|
*/
|
||||||
@@ -571,6 +596,257 @@ class BackupManager extends EventEmitter {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==================== CLOUD DESTINATIONS ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve credentials for a given provider via the credentialManager.
|
||||||
|
* Throws if required fields are missing.
|
||||||
|
*/
|
||||||
|
async _getCloudCredentials(provider) {
|
||||||
|
const credentialManager = require('./credential-manager');
|
||||||
|
const creds = {};
|
||||||
|
if (provider === 'dropbox') {
|
||||||
|
creds.token = await credentialManager.retrieve('backup.dropbox.token');
|
||||||
|
if (!creds.token) throw new Error('Dropbox token not configured');
|
||||||
|
} else if (provider === 'webdav') {
|
||||||
|
creds.url = await credentialManager.retrieve('backup.webdav.url');
|
||||||
|
creds.username = await credentialManager.retrieve('backup.webdav.username');
|
||||||
|
creds.password = await credentialManager.retrieve('backup.webdav.password');
|
||||||
|
if (!creds.url || !creds.username || !creds.password) {
|
||||||
|
throw new Error('WebDAV credentials incomplete (need url, username, password)');
|
||||||
|
}
|
||||||
|
} else if (provider === 'sftp') {
|
||||||
|
creds.host = await credentialManager.retrieve('backup.sftp.host');
|
||||||
|
const portStr = await credentialManager.retrieve('backup.sftp.port');
|
||||||
|
creds.port = parseInt(portStr || '22', 10);
|
||||||
|
creds.username = await credentialManager.retrieve('backup.sftp.username');
|
||||||
|
creds.password = await credentialManager.retrieve('backup.sftp.password');
|
||||||
|
creds.privateKey = await credentialManager.retrieve('backup.sftp.privateKey');
|
||||||
|
if (!creds.host || !creds.username || (!creds.password && !creds.privateKey)) {
|
||||||
|
throw new Error('SFTP credentials incomplete (need host, username, and either password or privateKey)');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return creds;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- Dropbox -----
|
||||||
|
|
||||||
|
async saveToDropbox(data, destination, backupId) {
|
||||||
|
const { Dropbox } = require('dropbox');
|
||||||
|
const creds = await this._getCloudCredentials('dropbox');
|
||||||
|
const dbx = new Dropbox({ accessToken: creds.token });
|
||||||
|
|
||||||
|
const folder = (destination.path || '/dashcaddy-backups').replace(/\/+$/, '');
|
||||||
|
const remotePath = `${folder}/${backupId}.backup`;
|
||||||
|
|
||||||
|
await dbx.filesUpload({
|
||||||
|
path: remotePath,
|
||||||
|
contents: data,
|
||||||
|
mode: { '.tag': 'overwrite' },
|
||||||
|
autorename: false,
|
||||||
|
mute: true
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'dropbox',
|
||||||
|
path: remotePath,
|
||||||
|
size: data.length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadFromDropbox(location) {
|
||||||
|
const { Dropbox } = require('dropbox');
|
||||||
|
const creds = await this._getCloudCredentials('dropbox');
|
||||||
|
const dbx = new Dropbox({ accessToken: creds.token });
|
||||||
|
const result = await dbx.filesDownload({ path: location.path });
|
||||||
|
// Node SDK returns fileBinary on the result
|
||||||
|
const fileBinary = result.result.fileBinary || result.result.fileBlob;
|
||||||
|
if (Buffer.isBuffer(fileBinary)) return fileBinary;
|
||||||
|
return Buffer.from(fileBinary);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- WebDAV -----
|
||||||
|
|
||||||
|
async saveToWebDAV(data, destination, backupId) {
|
||||||
|
const { createClient } = require('webdav');
|
||||||
|
const creds = await this._getCloudCredentials('webdav');
|
||||||
|
const client = createClient(creds.url, {
|
||||||
|
username: creds.username,
|
||||||
|
password: creds.password
|
||||||
|
});
|
||||||
|
|
||||||
|
const folder = (destination.path || '/dashcaddy-backups').replace(/\/+$/, '');
|
||||||
|
|
||||||
|
// Ensure folder exists
|
||||||
|
try {
|
||||||
|
const exists = await client.exists(folder);
|
||||||
|
if (!exists) await client.createDirectory(folder, { recursive: true });
|
||||||
|
} catch (_) {
|
||||||
|
// best-effort
|
||||||
|
}
|
||||||
|
|
||||||
|
const remotePath = `${folder}/${backupId}.backup`;
|
||||||
|
await client.putFileContents(remotePath, data, { overwrite: true });
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'webdav',
|
||||||
|
path: remotePath,
|
||||||
|
size: data.length
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadFromWebDAV(location) {
|
||||||
|
const { createClient } = require('webdav');
|
||||||
|
const creds = await this._getCloudCredentials('webdav');
|
||||||
|
const client = createClient(creds.url, {
|
||||||
|
username: creds.username,
|
||||||
|
password: creds.password
|
||||||
|
});
|
||||||
|
const data = await client.getFileContents(location.path);
|
||||||
|
return Buffer.isBuffer(data) ? data : Buffer.from(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----- SFTP -----
|
||||||
|
|
||||||
|
async saveToSFTP(data, destination, backupId) {
|
||||||
|
const SftpClient = require('ssh2-sftp-client');
|
||||||
|
const creds = await this._getCloudCredentials('sftp');
|
||||||
|
const client = new SftpClient();
|
||||||
|
|
||||||
|
try {
|
||||||
|
await client.connect({
|
||||||
|
host: creds.host,
|
||||||
|
port: creds.port,
|
||||||
|
username: creds.username,
|
||||||
|
password: creds.password || undefined,
|
||||||
|
privateKey: creds.privateKey || undefined
|
||||||
|
});
|
||||||
|
|
||||||
|
const folder = (destination.path || '/dashcaddy-backups').replace(/\/+$/, '');
|
||||||
|
// Ensure remote dir exists
|
||||||
|
try {
|
||||||
|
const exists = await client.exists(folder);
|
||||||
|
if (!exists) await client.mkdir(folder, true);
|
||||||
|
} catch (_) {
|
||||||
|
// best-effort
|
||||||
|
}
|
||||||
|
|
||||||
|
const remotePath = `${folder}/${backupId}.backup`;
|
||||||
|
await client.put(Buffer.from(data), remotePath);
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'sftp',
|
||||||
|
path: remotePath,
|
||||||
|
size: data.length
|
||||||
|
};
|
||||||
|
} finally {
|
||||||
|
try { await client.end(); } catch (_) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async loadFromSFTP(location) {
|
||||||
|
const SftpClient = require('ssh2-sftp-client');
|
||||||
|
const creds = await this._getCloudCredentials('sftp');
|
||||||
|
const client = new SftpClient();
|
||||||
|
try {
|
||||||
|
await client.connect({
|
||||||
|
host: creds.host,
|
||||||
|
port: creds.port,
|
||||||
|
username: creds.username,
|
||||||
|
password: creds.password || undefined,
|
||||||
|
privateKey: creds.privateKey || undefined
|
||||||
|
});
|
||||||
|
const buffer = await client.get(location.path);
|
||||||
|
return Buffer.isBuffer(buffer) ? buffer : Buffer.from(buffer);
|
||||||
|
} finally {
|
||||||
|
try { await client.end(); } catch (_) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that a destination is reachable + writable + deletable.
|
||||||
|
* Performs a small write/read/delete probe.
|
||||||
|
*/
|
||||||
|
async testDestination(destination) {
|
||||||
|
const probeId = `test-${Date.now()}`;
|
||||||
|
const probeData = Buffer.from(`dashcaddy-test-${probeId}`);
|
||||||
|
const start = Date.now();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const location = await this.saveToDestination(probeData, destination, probeId);
|
||||||
|
|
||||||
|
// Read it back
|
||||||
|
let readBack = null;
|
||||||
|
try {
|
||||||
|
readBack = await this.loadFromDestination(location);
|
||||||
|
} catch (_) {
|
||||||
|
// Some providers (e.g. local) we already trust the file system; skip
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the probe
|
||||||
|
try {
|
||||||
|
await this._deleteFromDestination(location);
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
const elapsed = Date.now() - start;
|
||||||
|
return {
|
||||||
|
success: true,
|
||||||
|
type: destination.type,
|
||||||
|
elapsedMs: elapsed,
|
||||||
|
verified: readBack ? readBack.equals(probeData) : null
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
success: false,
|
||||||
|
type: destination.type,
|
||||||
|
error: error.message,
|
||||||
|
elapsedMs: Date.now() - start
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete a backup from a destination location
|
||||||
|
*/
|
||||||
|
async _deleteFromDestination(location) {
|
||||||
|
if (location.type === 'local') {
|
||||||
|
if (fs.existsSync(location.path)) fs.unlinkSync(location.path);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (location.type === 'dropbox') {
|
||||||
|
const { Dropbox } = require('dropbox');
|
||||||
|
const creds = await this._getCloudCredentials('dropbox');
|
||||||
|
const dbx = new Dropbox({ accessToken: creds.token });
|
||||||
|
try { await dbx.filesDeleteV2({ path: location.path }); } catch (_) {}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (location.type === 'webdav') {
|
||||||
|
const { createClient } = require('webdav');
|
||||||
|
const creds = await this._getCloudCredentials('webdav');
|
||||||
|
const client = createClient(creds.url, { username: creds.username, password: creds.password });
|
||||||
|
try { await client.deleteFile(location.path); } catch (_) {}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (location.type === 'sftp') {
|
||||||
|
const SftpClient = require('ssh2-sftp-client');
|
||||||
|
const creds = await this._getCloudCredentials('sftp');
|
||||||
|
const client = new SftpClient();
|
||||||
|
try {
|
||||||
|
await client.connect({
|
||||||
|
host: creds.host,
|
||||||
|
port: creds.port,
|
||||||
|
username: creds.username,
|
||||||
|
password: creds.password || undefined,
|
||||||
|
privateKey: creds.privateKey || undefined
|
||||||
|
});
|
||||||
|
try { await client.delete(location.path); } catch (_) {}
|
||||||
|
} finally {
|
||||||
|
try { await client.end(); } catch (_) {}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify backup integrity
|
* Verify backup integrity
|
||||||
*/
|
*/
|
||||||
@@ -605,9 +881,24 @@ class BackupManager extends EventEmitter {
|
|||||||
throw new Error(`Backup not found: ${backupId}`);
|
throw new Error(`Backup not found: ${backupId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load backup data
|
// Load backup data — try each destination location until one succeeds
|
||||||
const location = backup.locations[0]; // Use first location
|
const location = backup.locations[0]; // Primary location
|
||||||
let data = fs.readFileSync(location.path);
|
let data;
|
||||||
|
try {
|
||||||
|
data = await this.loadFromDestination(location);
|
||||||
|
} catch (loadErr) {
|
||||||
|
// Fall back to other locations if available
|
||||||
|
let recovered = false;
|
||||||
|
for (let i = 1; i < backup.locations.length; i++) {
|
||||||
|
try {
|
||||||
|
data = await this.loadFromDestination(backup.locations[i]);
|
||||||
|
recovered = true;
|
||||||
|
console.log(`[BackupManager] Loaded backup from fallback location ${backup.locations[i].type}`);
|
||||||
|
break;
|
||||||
|
} catch (_) {}
|
||||||
|
}
|
||||||
|
if (!recovered) throw loadErr;
|
||||||
|
}
|
||||||
|
|
||||||
// Decrypt if needed
|
// Decrypt if needed
|
||||||
if (backup.encrypted && options.encryptionKey) {
|
if (backup.encrypted && options.encryptionKey) {
|
||||||
@@ -718,10 +1009,12 @@ class BackupManager extends EventEmitter {
|
|||||||
|
|
||||||
for (const backup of toDelete) {
|
for (const backup of toDelete) {
|
||||||
try {
|
try {
|
||||||
// Delete from all locations
|
// Delete from all locations (local + cloud)
|
||||||
for (const location of backup.locations) {
|
for (const location of backup.locations) {
|
||||||
if (location.type === 'local' && fs.existsSync(location.path)) {
|
try {
|
||||||
fs.unlinkSync(location.path);
|
await this._deleteFromDestination(location);
|
||||||
|
} catch (delErr) {
|
||||||
|
console.warn(`[BackupManager] Could not delete ${location.type} location for ${backup.id}:`, delErr.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "dashcaddy-api",
|
"name": "dashcaddy-api",
|
||||||
"version": "1.2.0",
|
"version": "1.4.0",
|
||||||
"description": "DashCaddy API server - Dashboard backend for Docker, Caddy & DNS management",
|
"description": "DashCaddy API server - Dashboard backend for Docker, Caddy & DNS management",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -22,6 +22,7 @@
|
|||||||
"compression": "^1.8.1",
|
"compression": "^1.8.1",
|
||||||
"cors": "^2.8.6",
|
"cors": "^2.8.6",
|
||||||
"dockerode": "^4.0.9",
|
"dockerode": "^4.0.9",
|
||||||
|
"dropbox": "^10.34.0",
|
||||||
"express": "^4.22.1",
|
"express": "^4.22.1",
|
||||||
"express-rate-limit": "^7.5.1",
|
"express-rate-limit": "^7.5.1",
|
||||||
"helmet": "^8.1.0",
|
"helmet": "^8.1.0",
|
||||||
@@ -34,7 +35,9 @@
|
|||||||
"proper-lockfile": "^4.1.2",
|
"proper-lockfile": "^4.1.2",
|
||||||
"qrcode": "^1.5.3",
|
"qrcode": "^1.5.3",
|
||||||
"sharp": "^0.33.5",
|
"sharp": "^0.33.5",
|
||||||
|
"ssh2-sftp-client": "^11.0.0",
|
||||||
"validator": "^13.11.0",
|
"validator": "^13.11.0",
|
||||||
|
"webdav": "^5.7.1",
|
||||||
"ws": "^8.20.0"
|
"ws": "^8.20.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -13,20 +13,32 @@ const docker = new Docker();
|
|||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
const STATS_FILE = process.env.STATS_FILE || path.join(__dirname, 'container-stats.json');
|
const STATS_FILE = process.env.STATS_FILE || path.join(__dirname, 'container-stats.json');
|
||||||
|
const STATS_HOURLY_FILE = process.env.STATS_HOURLY_FILE || path.join(__dirname, 'container-stats-hourly.json');
|
||||||
|
const STATS_DAILY_FILE = process.env.STATS_DAILY_FILE || path.join(__dirname, 'container-stats-daily.json');
|
||||||
const ALERT_CONFIG_FILE = process.env.ALERT_CONFIG_FILE || path.join(__dirname, 'alert-config.json');
|
const ALERT_CONFIG_FILE = process.env.ALERT_CONFIG_FILE || path.join(__dirname, 'alert-config.json');
|
||||||
const STATS_RETENTION_HOURS = parseInt(process.env.STATS_RETENTION_HOURS || '168', 10); // 7 days default
|
const STATS_RETENTION_HOURS = parseInt(process.env.STATS_RETENTION_HOURS || '168', 10); // 7 days raw
|
||||||
|
const STATS_HOURLY_RETENTION_DAYS = parseInt(process.env.STATS_HOURLY_RETENTION_DAYS || '30', 10); // 30 days hourly
|
||||||
|
const STATS_DAILY_RETENTION_DAYS = parseInt(process.env.STATS_DAILY_RETENTION_DAYS || '365', 10); // 365 days daily
|
||||||
const MONITORING_INTERVAL = parseInt(process.env.MONITORING_INTERVAL || '10000', 10); // 10 seconds
|
const MONITORING_INTERVAL = parseInt(process.env.MONITORING_INTERVAL || '10000', 10); // 10 seconds
|
||||||
|
const ROLLUP_HOURLY_INTERVAL = parseInt(process.env.ROLLUP_HOURLY_INTERVAL || String(60 * 60 * 1000), 10); // 1h
|
||||||
|
const ROLLUP_DAILY_INTERVAL = parseInt(process.env.ROLLUP_DAILY_INTERVAL || String(24 * 60 * 60 * 1000), 10); // 24h
|
||||||
|
|
||||||
class ResourceMonitor extends EventEmitter {
|
class ResourceMonitor extends EventEmitter {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.monitoring = false;
|
this.monitoring = false;
|
||||||
this.monitoringInterval = null;
|
this.monitoringInterval = null;
|
||||||
this.stats = new Map(); // containerId -> array of stats
|
this.hourlyRollupTimer = null;
|
||||||
|
this.dailyRollupTimer = null;
|
||||||
|
this.stats = new Map(); // containerId -> { name, history: [...] } (raw 10s samples, 7d)
|
||||||
|
this.hourlyHistory = new Map(); // containerId -> { name, samples: [...] } (hourly avg, 30d)
|
||||||
|
this.dailyHistory = new Map(); // containerId -> { name, samples: [...] } (daily avg, 365d)
|
||||||
this.alerts = new Map(); // containerId -> alert config
|
this.alerts = new Map(); // containerId -> alert config
|
||||||
this.lastAlerts = new Map(); // containerId -> last alert timestamp
|
this.lastAlerts = new Map(); // containerId -> last alert timestamp
|
||||||
|
|
||||||
this.loadStats();
|
this.loadStats();
|
||||||
|
this.loadHourlyStats();
|
||||||
|
this.loadDailyStats();
|
||||||
this.loadAlertConfig();
|
this.loadAlertConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +55,22 @@ class ResourceMonitor extends EventEmitter {
|
|||||||
this.monitoring = true;
|
this.monitoring = true;
|
||||||
this.monitoringInterval = setInterval(() => this.collectStats(), MONITORING_INTERVAL);
|
this.monitoringInterval = setInterval(() => this.collectStats(), MONITORING_INTERVAL);
|
||||||
|
|
||||||
|
// Hourly rollup — fires once an hour, computes the previous full hour
|
||||||
|
this.hourlyRollupTimer = setInterval(() => {
|
||||||
|
try { this.rollupHourly(); } catch (e) { console.error('[ResourceMonitor] hourly rollup error:', e.message); }
|
||||||
|
}, ROLLUP_HOURLY_INTERVAL);
|
||||||
|
|
||||||
|
// Daily rollup — schedule first run at the next midnight, then fire every 24h
|
||||||
|
const now = new Date();
|
||||||
|
const nextMidnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1, 0, 0, 5);
|
||||||
|
const msUntilMidnight = nextMidnight.getTime() - now.getTime();
|
||||||
|
setTimeout(() => {
|
||||||
|
try { this.rollupDaily(); } catch (e) { console.error('[ResourceMonitor] daily rollup error:', e.message); }
|
||||||
|
this.dailyRollupTimer = setInterval(() => {
|
||||||
|
try { this.rollupDaily(); } catch (e) { console.error('[ResourceMonitor] daily rollup error:', e.message); }
|
||||||
|
}, ROLLUP_DAILY_INTERVAL);
|
||||||
|
}, msUntilMidnight);
|
||||||
|
|
||||||
// Initial collection
|
// Initial collection
|
||||||
this.collectStats();
|
this.collectStats();
|
||||||
}
|
}
|
||||||
@@ -60,8 +88,18 @@ class ResourceMonitor extends EventEmitter {
|
|||||||
clearInterval(this.monitoringInterval);
|
clearInterval(this.monitoringInterval);
|
||||||
this.monitoringInterval = null;
|
this.monitoringInterval = null;
|
||||||
}
|
}
|
||||||
|
if (this.hourlyRollupTimer) {
|
||||||
|
clearInterval(this.hourlyRollupTimer);
|
||||||
|
this.hourlyRollupTimer = null;
|
||||||
|
}
|
||||||
|
if (this.dailyRollupTimer) {
|
||||||
|
clearInterval(this.dailyRollupTimer);
|
||||||
|
this.dailyRollupTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.saveStats();
|
this.saveStats();
|
||||||
|
this.saveHourlyStats();
|
||||||
|
this.saveDailyStats();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -464,12 +502,310 @@ class ResourceMonitor extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aggregate a list of raw samples into a single rollup sample
|
||||||
|
* @param {Array} samples - Raw stats samples
|
||||||
|
* @param {string} timestamp - ISO timestamp to use for the rollup bucket
|
||||||
|
* @returns {Object|null} Aggregated sample, or null if input is empty
|
||||||
|
*/
|
||||||
|
_aggregateSamples(samples, timestamp) {
|
||||||
|
if (!samples || samples.length === 0) return null;
|
||||||
|
|
||||||
|
let cpuSum = 0, cpuMax = 0;
|
||||||
|
let memSum = 0, memMax = 0;
|
||||||
|
let memPctSum = 0, memPctMax = 0;
|
||||||
|
let netRxSum = 0, netTxSum = 0;
|
||||||
|
let diskRSum = 0, diskWSum = 0;
|
||||||
|
|
||||||
|
for (const s of samples) {
|
||||||
|
const cpu = s.cpu?.percent || 0;
|
||||||
|
const memUsage = s.memory?.usage || 0;
|
||||||
|
const memPct = s.memory?.percent || 0;
|
||||||
|
cpuSum += cpu; if (cpu > cpuMax) cpuMax = cpu;
|
||||||
|
memSum += memUsage; if (memUsage > memMax) memMax = memUsage;
|
||||||
|
memPctSum += memPct; if (memPct > memPctMax) memPctMax = memPct;
|
||||||
|
netRxSum += s.network?.rxBytes || 0;
|
||||||
|
netTxSum += s.network?.txBytes || 0;
|
||||||
|
diskRSum += s.disk?.readBytes || 0;
|
||||||
|
diskWSum += s.disk?.writeBytes || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const n = samples.length;
|
||||||
|
return {
|
||||||
|
timestamp,
|
||||||
|
sampleCount: n,
|
||||||
|
cpu: {
|
||||||
|
avg: Math.round((cpuSum / n) * 100) / 100,
|
||||||
|
max: Math.round(cpuMax * 100) / 100,
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
avgUsage: Math.round(memSum / n),
|
||||||
|
maxUsage: memMax,
|
||||||
|
avgPercent: Math.round((memPctSum / n) * 100) / 100,
|
||||||
|
maxPercent: Math.round(memPctMax * 100) / 100,
|
||||||
|
avgUsageMB: Math.round(memSum / n / 1024 / 1024),
|
||||||
|
maxUsageMB: Math.round(memMax / 1024 / 1024),
|
||||||
|
},
|
||||||
|
network: {
|
||||||
|
rxBytes: netRxSum,
|
||||||
|
txBytes: netTxSum,
|
||||||
|
rxMB: Math.round(netRxSum / 1024 / 1024 * 100) / 100,
|
||||||
|
txMB: Math.round(netTxSum / 1024 / 1024 * 100) / 100,
|
||||||
|
},
|
||||||
|
disk: {
|
||||||
|
readBytes: diskRSum,
|
||||||
|
writeBytes: diskWSum,
|
||||||
|
readMB: Math.round(diskRSum / 1024 / 1024 * 100) / 100,
|
||||||
|
writeMB: Math.round(diskWSum / 1024 / 1024 * 100) / 100,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Combine already-aggregated samples (e.g. hourly buckets) into a single coarser bucket
|
||||||
|
* @param {Array} samples - Aggregated samples (output of _aggregateSamples)
|
||||||
|
* @param {string} timestamp - ISO timestamp to use for the rollup bucket
|
||||||
|
* @returns {Object|null}
|
||||||
|
*/
|
||||||
|
_combineAggregated(samples, timestamp) {
|
||||||
|
if (!samples || samples.length === 0) return null;
|
||||||
|
|
||||||
|
let totalCount = 0;
|
||||||
|
let cpuWeightedSum = 0, cpuMax = 0;
|
||||||
|
let memWeightedSum = 0, memMax = 0;
|
||||||
|
let memPctWeightedSum = 0, memPctMax = 0;
|
||||||
|
let netRxSum = 0, netTxSum = 0;
|
||||||
|
let diskRSum = 0, diskWSum = 0;
|
||||||
|
|
||||||
|
for (const s of samples) {
|
||||||
|
const w = s.sampleCount || 1;
|
||||||
|
totalCount += w;
|
||||||
|
cpuWeightedSum += (s.cpu?.avg || 0) * w;
|
||||||
|
if ((s.cpu?.max || 0) > cpuMax) cpuMax = s.cpu.max;
|
||||||
|
memWeightedSum += (s.memory?.avgUsage || 0) * w;
|
||||||
|
if ((s.memory?.maxUsage || 0) > memMax) memMax = s.memory.maxUsage;
|
||||||
|
memPctWeightedSum += (s.memory?.avgPercent || 0) * w;
|
||||||
|
if ((s.memory?.maxPercent || 0) > memPctMax) memPctMax = s.memory.maxPercent;
|
||||||
|
netRxSum += s.network?.rxBytes || 0;
|
||||||
|
netTxSum += s.network?.txBytes || 0;
|
||||||
|
diskRSum += s.disk?.readBytes || 0;
|
||||||
|
diskWSum += s.disk?.writeBytes || 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
timestamp,
|
||||||
|
sampleCount: totalCount,
|
||||||
|
cpu: {
|
||||||
|
avg: Math.round((cpuWeightedSum / totalCount) * 100) / 100,
|
||||||
|
max: Math.round(cpuMax * 100) / 100,
|
||||||
|
},
|
||||||
|
memory: {
|
||||||
|
avgUsage: Math.round(memWeightedSum / totalCount),
|
||||||
|
maxUsage: memMax,
|
||||||
|
avgPercent: Math.round((memPctWeightedSum / totalCount) * 100) / 100,
|
||||||
|
maxPercent: Math.round(memPctMax * 100) / 100,
|
||||||
|
avgUsageMB: Math.round(memWeightedSum / totalCount / 1024 / 1024),
|
||||||
|
maxUsageMB: Math.round(memMax / 1024 / 1024),
|
||||||
|
},
|
||||||
|
network: {
|
||||||
|
rxBytes: netRxSum,
|
||||||
|
txBytes: netTxSum,
|
||||||
|
rxMB: Math.round(netRxSum / 1024 / 1024 * 100) / 100,
|
||||||
|
txMB: Math.round(netTxSum / 1024 / 1024 * 100) / 100,
|
||||||
|
},
|
||||||
|
disk: {
|
||||||
|
readBytes: diskRSum,
|
||||||
|
writeBytes: diskWSum,
|
||||||
|
readMB: Math.round(diskRSum / 1024 / 1024 * 100) / 100,
|
||||||
|
writeMB: Math.round(diskWSum / 1024 / 1024 * 100) / 100,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Roll up the previous complete hour of raw samples into a single hourly point.
|
||||||
|
* Trims hourlyHistory entries older than STATS_HOURLY_RETENTION_DAYS.
|
||||||
|
*/
|
||||||
|
rollupHourly() {
|
||||||
|
const now = new Date();
|
||||||
|
// The "previous complete hour" — bucket starts at top of (current_hour - 1)
|
||||||
|
const bucketStart = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() - 1, 0, 0);
|
||||||
|
const bucketEnd = new Date(bucketStart.getTime() + 60 * 60 * 1000);
|
||||||
|
const bucketStartMs = bucketStart.getTime();
|
||||||
|
const bucketEndMs = bucketEnd.getTime();
|
||||||
|
const bucketTimestamp = bucketStart.toISOString();
|
||||||
|
|
||||||
|
for (const [containerId, data] of this.stats.entries()) {
|
||||||
|
const samples = data.history.filter(s => {
|
||||||
|
const t = new Date(s.timestamp).getTime();
|
||||||
|
return t >= bucketStartMs && t < bucketEndMs;
|
||||||
|
});
|
||||||
|
if (samples.length === 0) continue;
|
||||||
|
|
||||||
|
const rollup = this._aggregateSamples(samples, bucketTimestamp);
|
||||||
|
if (!rollup) continue;
|
||||||
|
|
||||||
|
if (!this.hourlyHistory.has(containerId)) {
|
||||||
|
this.hourlyHistory.set(containerId, { name: data.name, samples: [] });
|
||||||
|
}
|
||||||
|
const entry = this.hourlyHistory.get(containerId);
|
||||||
|
entry.name = data.name;
|
||||||
|
// Avoid duplicate buckets if rollup ran twice
|
||||||
|
if (!entry.samples.find(s => s.timestamp === bucketTimestamp)) {
|
||||||
|
entry.samples.push(rollup);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trim old entries
|
||||||
|
const cutoff = Date.now() - (STATS_HOURLY_RETENTION_DAYS * 24 * 60 * 60 * 1000);
|
||||||
|
entry.samples = entry.samples.filter(s => new Date(s.timestamp).getTime() > cutoff);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.saveHourlyStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Roll up the previous complete day of hourly samples into a single daily point.
|
||||||
|
* Trims dailyHistory entries older than STATS_DAILY_RETENTION_DAYS.
|
||||||
|
*/
|
||||||
|
rollupDaily() {
|
||||||
|
const now = new Date();
|
||||||
|
// Previous calendar day, midnight to midnight
|
||||||
|
const bucketStart = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 0, 0, 0);
|
||||||
|
const bucketEnd = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0);
|
||||||
|
const bucketStartMs = bucketStart.getTime();
|
||||||
|
const bucketEndMs = bucketEnd.getTime();
|
||||||
|
const bucketTimestamp = bucketStart.toISOString();
|
||||||
|
|
||||||
|
for (const [containerId, data] of this.hourlyHistory.entries()) {
|
||||||
|
const samples = data.samples.filter(s => {
|
||||||
|
const t = new Date(s.timestamp).getTime();
|
||||||
|
return t >= bucketStartMs && t < bucketEndMs;
|
||||||
|
});
|
||||||
|
if (samples.length === 0) continue;
|
||||||
|
|
||||||
|
const rollup = this._combineAggregated(samples, bucketTimestamp);
|
||||||
|
if (!rollup) continue;
|
||||||
|
|
||||||
|
if (!this.dailyHistory.has(containerId)) {
|
||||||
|
this.dailyHistory.set(containerId, { name: data.name, samples: [] });
|
||||||
|
}
|
||||||
|
const entry = this.dailyHistory.get(containerId);
|
||||||
|
entry.name = data.name;
|
||||||
|
if (!entry.samples.find(s => s.timestamp === bucketTimestamp)) {
|
||||||
|
entry.samples.push(rollup);
|
||||||
|
}
|
||||||
|
|
||||||
|
const cutoff = Date.now() - (STATS_DAILY_RETENTION_DAYS * 24 * 60 * 60 * 1000);
|
||||||
|
entry.samples = entry.samples.filter(s => new Date(s.timestamp).getTime() > cutoff);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.saveDailyStats();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get history for a container by time range, auto-selecting the appropriate tier.
|
||||||
|
* - <= 24h → raw 10s samples
|
||||||
|
* - 1-30 days → hourly rollups
|
||||||
|
* - > 30 days → daily rollups
|
||||||
|
* @param {string} containerId
|
||||||
|
* @param {number} startTime - epoch ms
|
||||||
|
* @param {number} endTime - epoch ms
|
||||||
|
* @returns {{ tier: 'raw'|'hourly'|'daily', samples: Array, unit: string }}
|
||||||
|
*/
|
||||||
|
getHistoryByRange(containerId, startTime, endTime) {
|
||||||
|
const rangeMs = endTime - startTime;
|
||||||
|
const oneDay = 24 * 60 * 60 * 1000;
|
||||||
|
const thirtyDays = 30 * oneDay;
|
||||||
|
|
||||||
|
let tier, samples;
|
||||||
|
if (rangeMs <= oneDay) {
|
||||||
|
tier = 'raw';
|
||||||
|
const data = this.stats.get(containerId);
|
||||||
|
samples = data ? data.history.filter(s => {
|
||||||
|
const t = new Date(s.timestamp).getTime();
|
||||||
|
return t >= startTime && t <= endTime;
|
||||||
|
}) : [];
|
||||||
|
} else if (rangeMs <= thirtyDays) {
|
||||||
|
tier = 'hourly';
|
||||||
|
const data = this.hourlyHistory.get(containerId);
|
||||||
|
samples = data ? data.samples.filter(s => {
|
||||||
|
const t = new Date(s.timestamp).getTime();
|
||||||
|
return t >= startTime && t <= endTime;
|
||||||
|
}) : [];
|
||||||
|
} else {
|
||||||
|
tier = 'daily';
|
||||||
|
const data = this.dailyHistory.get(containerId);
|
||||||
|
samples = data ? data.samples.filter(s => {
|
||||||
|
const t = new Date(s.timestamp).getTime();
|
||||||
|
return t >= startTime && t <= endTime;
|
||||||
|
}) : [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return { tier, samples, unit: tier === 'raw' ? '10s' : tier === 'hourly' ? '1h' : '1d' };
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load hourly rollups from disk
|
||||||
|
*/
|
||||||
|
loadHourlyStats() {
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(STATS_HOURLY_FILE)) {
|
||||||
|
const data = JSON.parse(fs.readFileSync(STATS_HOURLY_FILE, 'utf8'));
|
||||||
|
this.hourlyHistory = new Map(Object.entries(data));
|
||||||
|
console.log(`[ResourceMonitor] Loaded hourly rollups for ${this.hourlyHistory.size} containers`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[ResourceMonitor] Error loading hourly stats:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save hourly rollups to disk
|
||||||
|
*/
|
||||||
|
saveHourlyStats() {
|
||||||
|
try {
|
||||||
|
const data = Object.fromEntries(this.hourlyHistory);
|
||||||
|
fs.writeFileSync(STATS_HOURLY_FILE, JSON.stringify(data, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[ResourceMonitor] Error saving hourly stats:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load daily rollups from disk
|
||||||
|
*/
|
||||||
|
loadDailyStats() {
|
||||||
|
try {
|
||||||
|
if (fs.existsSync(STATS_DAILY_FILE)) {
|
||||||
|
const data = JSON.parse(fs.readFileSync(STATS_DAILY_FILE, 'utf8'));
|
||||||
|
this.dailyHistory = new Map(Object.entries(data));
|
||||||
|
console.log(`[ResourceMonitor] Loaded daily rollups for ${this.dailyHistory.size} containers`);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[ResourceMonitor] Error loading daily stats:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save daily rollups to disk
|
||||||
|
*/
|
||||||
|
saveDailyStats() {
|
||||||
|
try {
|
||||||
|
const data = Object.fromEntries(this.dailyHistory);
|
||||||
|
fs.writeFileSync(STATS_DAILY_FILE, JSON.stringify(data, null, 2));
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[ResourceMonitor] Error saving daily stats:', error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export stats for backup
|
* Export stats for backup
|
||||||
*/
|
*/
|
||||||
exportStats() {
|
exportStats() {
|
||||||
return {
|
return {
|
||||||
stats: Object.fromEntries(this.stats),
|
stats: Object.fromEntries(this.stats),
|
||||||
|
hourlyHistory: Object.fromEntries(this.hourlyHistory),
|
||||||
|
dailyHistory: Object.fromEntries(this.dailyHistory),
|
||||||
alerts: Object.fromEntries(this.alerts),
|
alerts: Object.fromEntries(this.alerts),
|
||||||
exportedAt: new Date().toISOString()
|
exportedAt: new Date().toISOString()
|
||||||
};
|
};
|
||||||
@@ -482,10 +818,18 @@ class ResourceMonitor extends EventEmitter {
|
|||||||
if (data.stats) {
|
if (data.stats) {
|
||||||
this.stats = new Map(Object.entries(data.stats));
|
this.stats = new Map(Object.entries(data.stats));
|
||||||
}
|
}
|
||||||
|
if (data.hourlyHistory) {
|
||||||
|
this.hourlyHistory = new Map(Object.entries(data.hourlyHistory));
|
||||||
|
}
|
||||||
|
if (data.dailyHistory) {
|
||||||
|
this.dailyHistory = new Map(Object.entries(data.dailyHistory));
|
||||||
|
}
|
||||||
if (data.alerts) {
|
if (data.alerts) {
|
||||||
this.alerts = new Map(Object.entries(data.alerts));
|
this.alerts = new Map(Object.entries(data.alerts));
|
||||||
}
|
}
|
||||||
this.saveStats();
|
this.saveStats();
|
||||||
|
this.saveHourlyStats();
|
||||||
|
this.saveDailyStats();
|
||||||
this.saveAlertConfig();
|
this.saveAlertConfig();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,5 +42,115 @@ module.exports = function({ backupManager, asyncHandler }) {
|
|||||||
success(res, { result });
|
success(res, { result });
|
||||||
}, 'backups-restore'));
|
}, 'backups-restore'));
|
||||||
|
|
||||||
|
// ==================== CLOUD DESTINATIONS ====================
|
||||||
|
|
||||||
|
// Test a destination (write+read+delete probe)
|
||||||
|
router.post('/backups/test-destination', asyncHandler(async (req, res) => {
|
||||||
|
const destination = req.body;
|
||||||
|
if (!destination || !destination.type) {
|
||||||
|
const { ValidationError } = require('../errors');
|
||||||
|
throw new ValidationError('destination.type is required');
|
||||||
|
}
|
||||||
|
const result = await backupManager.testDestination(destination);
|
||||||
|
success(res, result);
|
||||||
|
}, 'backups-test-destination'));
|
||||||
|
|
||||||
|
// Get cloud credentials (masked) for a provider
|
||||||
|
// Provider: dropbox | webdav | sftp
|
||||||
|
router.get('/backups/credentials/:provider', asyncHandler(async (req, res) => {
|
||||||
|
const credentialManager = require('../credential-manager');
|
||||||
|
const provider = req.params.provider;
|
||||||
|
if (!['dropbox', 'webdav', 'sftp'].includes(provider)) {
|
||||||
|
const { ValidationError } = require('../errors');
|
||||||
|
throw new ValidationError('Invalid provider');
|
||||||
|
}
|
||||||
|
|
||||||
|
const mask = (val) => val ? '***' : null;
|
||||||
|
let creds = {};
|
||||||
|
if (provider === 'dropbox') {
|
||||||
|
const token = await credentialManager.retrieve('backup.dropbox.token');
|
||||||
|
creds = { token: mask(token) };
|
||||||
|
} else if (provider === 'webdav') {
|
||||||
|
creds = {
|
||||||
|
url: (await credentialManager.retrieve('backup.webdav.url')) || null,
|
||||||
|
username: (await credentialManager.retrieve('backup.webdav.username')) || null,
|
||||||
|
password: mask(await credentialManager.retrieve('backup.webdav.password'))
|
||||||
|
};
|
||||||
|
} else if (provider === 'sftp') {
|
||||||
|
creds = {
|
||||||
|
host: (await credentialManager.retrieve('backup.sftp.host')) || null,
|
||||||
|
port: (await credentialManager.retrieve('backup.sftp.port')) || '22',
|
||||||
|
username: (await credentialManager.retrieve('backup.sftp.username')) || null,
|
||||||
|
password: mask(await credentialManager.retrieve('backup.sftp.password')),
|
||||||
|
privateKey: mask(await credentialManager.retrieve('backup.sftp.privateKey'))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
success(res, { provider, credentials: creds });
|
||||||
|
}, 'backups-credentials-get'));
|
||||||
|
|
||||||
|
// Save cloud credentials for a provider
|
||||||
|
router.post('/backups/credentials/:provider', asyncHandler(async (req, res) => {
|
||||||
|
const credentialManager = require('../credential-manager');
|
||||||
|
const { ValidationError } = require('../errors');
|
||||||
|
const provider = req.params.provider;
|
||||||
|
|
||||||
|
if (!['dropbox', 'webdav', 'sftp'].includes(provider)) {
|
||||||
|
throw new ValidationError('Invalid provider');
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = req.body || {};
|
||||||
|
const storeIfPresent = async (key, val) => {
|
||||||
|
if (val !== undefined && val !== null && val !== '' && val !== '***') {
|
||||||
|
await credentialManager.store(key, String(val));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (provider === 'dropbox') {
|
||||||
|
if (!body.token || body.token === '***') {
|
||||||
|
const existing = await credentialManager.retrieve('backup.dropbox.token');
|
||||||
|
if (!existing) {
|
||||||
|
throw new ValidationError('Dropbox token required');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await credentialManager.store('backup.dropbox.token', body.token);
|
||||||
|
}
|
||||||
|
} else if (provider === 'webdav') {
|
||||||
|
await storeIfPresent('backup.webdav.url', body.url);
|
||||||
|
await storeIfPresent('backup.webdav.username', body.username);
|
||||||
|
await storeIfPresent('backup.webdav.password', body.password);
|
||||||
|
} else if (provider === 'sftp') {
|
||||||
|
await storeIfPresent('backup.sftp.host', body.host);
|
||||||
|
await storeIfPresent('backup.sftp.port', body.port);
|
||||||
|
await storeIfPresent('backup.sftp.username', body.username);
|
||||||
|
await storeIfPresent('backup.sftp.password', body.password);
|
||||||
|
await storeIfPresent('backup.sftp.privateKey', body.privateKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
success(res, { message: `${provider} credentials saved` });
|
||||||
|
}, 'backups-credentials-set'));
|
||||||
|
|
||||||
|
// Delete cloud credentials for a provider
|
||||||
|
router.delete('/backups/credentials/:provider', asyncHandler(async (req, res) => {
|
||||||
|
const credentialManager = require('../credential-manager');
|
||||||
|
const { ValidationError } = require('../errors');
|
||||||
|
const provider = req.params.provider;
|
||||||
|
|
||||||
|
if (!['dropbox', 'webdav', 'sftp'].includes(provider)) {
|
||||||
|
throw new ValidationError('Invalid provider');
|
||||||
|
}
|
||||||
|
|
||||||
|
const keys = {
|
||||||
|
dropbox: ['backup.dropbox.token'],
|
||||||
|
webdav: ['backup.webdav.url', 'backup.webdav.username', 'backup.webdav.password'],
|
||||||
|
sftp: ['backup.sftp.host', 'backup.sftp.port', 'backup.sftp.username', 'backup.sftp.password', 'backup.sftp.privateKey']
|
||||||
|
};
|
||||||
|
|
||||||
|
for (const k of keys[provider]) {
|
||||||
|
try { await credentialManager.delete(k); } catch (_) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
success(res, { message: `${provider} credentials deleted` });
|
||||||
|
}, 'backups-credentials-delete'));
|
||||||
|
|
||||||
return router;
|
return router;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -31,11 +31,28 @@ module.exports = function({ resourceMonitor, docker, asyncHandler, log }) {
|
|||||||
success(res, { stats });
|
success(res, { stats });
|
||||||
}, 'monitoring-stats-container'));
|
}, 'monitoring-stats-container'));
|
||||||
|
|
||||||
// Get historical stats
|
// Get historical stats — supports either ?hours=24 (legacy raw) OR ?startTime=...&endTime=...
|
||||||
|
// (range mode auto-selects raw / hourly / daily tier)
|
||||||
router.get('/monitoring/history/:containerId', asyncHandler(async (req, res) => {
|
router.get('/monitoring/history/:containerId', asyncHandler(async (req, res) => {
|
||||||
|
const containerId = req.params.containerId;
|
||||||
|
|
||||||
|
// Range mode (preferred)
|
||||||
|
if (req.query.startTime && req.query.endTime) {
|
||||||
|
const startTime = parseInt(req.query.startTime, 10);
|
||||||
|
const endTime = parseInt(req.query.endTime, 10);
|
||||||
|
if (Number.isNaN(startTime) || Number.isNaN(endTime) || startTime >= endTime) {
|
||||||
|
const { ValidationError } = require('../errors');
|
||||||
|
throw new ValidationError('Invalid startTime/endTime');
|
||||||
|
}
|
||||||
|
const result = resourceMonitor.getHistoryByRange(containerId, startTime, endTime);
|
||||||
|
success(res, { ...result, startTime, endTime });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Legacy hours-based mode (raw samples only)
|
||||||
const hours = parseInt(req.query.hours) || 24;
|
const hours = parseInt(req.query.hours) || 24;
|
||||||
const history = resourceMonitor.getHistoricalStats(req.params.containerId, hours);
|
const history = resourceMonitor.getHistoricalStats(containerId, hours);
|
||||||
success(res, { history, hours });
|
success(res, { history, hours, tier: 'raw', samples: history, unit: '10s' });
|
||||||
}, 'monitoring-history'));
|
}, 'monitoring-history'));
|
||||||
|
|
||||||
// Get aggregated stats
|
// Get aggregated stats
|
||||||
|
|||||||
@@ -95,6 +95,15 @@ module.exports = function({ updateManager, selfUpdater, asyncHandler, logError }
|
|||||||
if (!check.available) {
|
if (!check.available) {
|
||||||
return res.json({ success: true, message: 'Already up to date' });
|
return res.json({ success: true, message: 'Already up to date' });
|
||||||
}
|
}
|
||||||
|
// Refuse same-version applies. The check.available flag can theoretically be
|
||||||
|
// true with equal versions (commit-mismatch path); applying anyway just
|
||||||
|
// rebuilds the container without changing anything user-visible and pollutes
|
||||||
|
// history with v1.4.0 → v1.4.0 entries.
|
||||||
|
const localV = check.local && check.local.version;
|
||||||
|
const remoteV = check.remote && check.remote.version;
|
||||||
|
if (localV && remoteV && localV === remoteV) {
|
||||||
|
return res.json({ success: true, message: 'Already up to date', version: localV });
|
||||||
|
}
|
||||||
// Start async — container may restart
|
// Start async — container may restart
|
||||||
selfUpdater.applyUpdate(check.remote).catch(err => {
|
selfUpdater.applyUpdate(check.remote).catch(err => {
|
||||||
logError('self-update', err);
|
logError('self-update', err);
|
||||||
@@ -102,8 +111,8 @@ module.exports = function({ updateManager, selfUpdater, asyncHandler, logError }
|
|||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: 'Update initiated',
|
message: 'Update initiated',
|
||||||
fromVersion: check.local.version,
|
fromVersion: localV,
|
||||||
toVersion: check.remote.version,
|
toVersion: remoteV,
|
||||||
});
|
});
|
||||||
}, 'system-update-apply'));
|
}, 'system-update-apply'));
|
||||||
|
|
||||||
|
|||||||
@@ -113,11 +113,12 @@ main() {
|
|||||||
mkdir -p "$backup_dir"
|
mkdir -p "$backup_dir"
|
||||||
log "Backing up current API files to ${backup_dir}"
|
log "Backing up current API files to ${backup_dir}"
|
||||||
|
|
||||||
# Copy all JS files, package.json, Dockerfile, and routes
|
# Copy all JS files, package.json, Dockerfile, and tracked subdirs
|
||||||
for item in "$api_source_dir"/*.js "$api_source_dir"/package.json "$api_source_dir"/package-lock.json "$api_source_dir"/Dockerfile "$api_source_dir"/openapi.yaml; do
|
for item in "$api_source_dir"/*.js "$api_source_dir"/package.json "$api_source_dir"/package-lock.json "$api_source_dir"/Dockerfile "$api_source_dir"/openapi.yaml; do
|
||||||
[[ -f "$item" ]] && cp -f "$item" "$backup_dir/" 2>/dev/null || true
|
[[ -f "$item" ]] && cp -f "$item" "$backup_dir/" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
[[ -d "$api_source_dir/routes" ]] && cp -rf "$api_source_dir/routes" "$backup_dir/"
|
[[ -d "$api_source_dir/routes" ]] && cp -rf "$api_source_dir/routes" "$backup_dir/"
|
||||||
|
[[ -d "$api_source_dir/src" ]] && cp -rf "$api_source_dir/src" "$backup_dir/"
|
||||||
# Save version marker
|
# Save version marker
|
||||||
echo "$from_version" > "$backup_dir/VERSION"
|
echo "$from_version" > "$backup_dir/VERSION"
|
||||||
|
|
||||||
@@ -128,7 +129,14 @@ main() {
|
|||||||
for item in "$staging_dir"/*.js "$staging_dir"/package.json "$staging_dir"/package-lock.json "$staging_dir"/Dockerfile "$staging_dir"/openapi.yaml; do
|
for item in "$staging_dir"/*.js "$staging_dir"/package.json "$staging_dir"/package-lock.json "$staging_dir"/Dockerfile "$staging_dir"/openapi.yaml; do
|
||||||
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
[[ -d "$staging_dir/routes" ]] && cp -rf "$staging_dir/routes" "$api_source_dir/routes/"
|
if [[ -d "$staging_dir/routes" ]]; then
|
||||||
|
rm -rf "$api_source_dir/routes"
|
||||||
|
cp -rf "$staging_dir/routes" "$api_source_dir/routes"
|
||||||
|
fi
|
||||||
|
if [[ -d "$staging_dir/src" ]]; then
|
||||||
|
rm -rf "$api_source_dir/src"
|
||||||
|
cp -rf "$staging_dir/src" "$api_source_dir/src"
|
||||||
|
fi
|
||||||
|
|
||||||
# 5. Rebuild container
|
# 5. Rebuild container
|
||||||
log "Rebuilding container..."
|
log "Rebuilding container..."
|
||||||
@@ -148,7 +156,14 @@ main() {
|
|||||||
for item in "$backup_dir"/*.js "$backup_dir"/package.json "$backup_dir"/package-lock.json "$backup_dir"/Dockerfile "$backup_dir"/openapi.yaml; do
|
for item in "$backup_dir"/*.js "$backup_dir"/package.json "$backup_dir"/package-lock.json "$backup_dir"/Dockerfile "$backup_dir"/openapi.yaml; do
|
||||||
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
[[ -d "$backup_dir/routes" ]] && cp -rf "$backup_dir/routes" "$api_source_dir/routes/"
|
if [[ -d "$backup_dir/routes" ]]; then
|
||||||
|
rm -rf "$api_source_dir/routes"
|
||||||
|
cp -rf "$backup_dir/routes" "$api_source_dir/routes"
|
||||||
|
fi
|
||||||
|
if [[ -d "$backup_dir/src" ]]; then
|
||||||
|
rm -rf "$api_source_dir/src"
|
||||||
|
cp -rf "$backup_dir/src" "$api_source_dir/src"
|
||||||
|
fi
|
||||||
|
|
||||||
write_result "false" "$version" "$(( $(date +%s) - start_time ))" "Docker build failed"
|
write_result "false" "$version" "$(( $(date +%s) - start_time ))" "Docker build failed"
|
||||||
rm -f "${TRIGGER_FILE}.processing"
|
rm -f "${TRIGGER_FILE}.processing"
|
||||||
@@ -166,7 +181,14 @@ main() {
|
|||||||
for item in "$backup_dir"/*.js "$backup_dir"/package.json "$backup_dir"/package-lock.json "$backup_dir"/Dockerfile "$backup_dir"/openapi.yaml; do
|
for item in "$backup_dir"/*.js "$backup_dir"/package.json "$backup_dir"/package-lock.json "$backup_dir"/Dockerfile "$backup_dir"/openapi.yaml; do
|
||||||
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
[[ -d "$backup_dir/routes" ]] && cp -rf "$backup_dir/routes" "$api_source_dir/routes/"
|
if [[ -d "$backup_dir/routes" ]]; then
|
||||||
|
rm -rf "$api_source_dir/routes"
|
||||||
|
cp -rf "$backup_dir/routes" "$api_source_dir/routes"
|
||||||
|
fi
|
||||||
|
if [[ -d "$backup_dir/src" ]]; then
|
||||||
|
rm -rf "$api_source_dir/src"
|
||||||
|
cp -rf "$backup_dir/src" "$api_source_dir/src"
|
||||||
|
fi
|
||||||
|
|
||||||
docker compose build --quiet 2>&1 || docker-compose build --quiet 2>&1 || true
|
docker compose build --quiet 2>&1 || docker-compose build --quiet 2>&1 || true
|
||||||
docker compose up -d 2>&1 || docker-compose up -d 2>&1 || true
|
docker compose up -d 2>&1 || docker-compose up -d 2>&1 || true
|
||||||
@@ -189,7 +211,14 @@ main() {
|
|||||||
for item in "$backup_dir"/*.js "$backup_dir"/package.json "$backup_dir"/package-lock.json "$backup_dir"/Dockerfile "$backup_dir"/openapi.yaml; do
|
for item in "$backup_dir"/*.js "$backup_dir"/package.json "$backup_dir"/package-lock.json "$backup_dir"/Dockerfile "$backup_dir"/openapi.yaml; do
|
||||||
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
[[ -f "$item" ]] && cp -f "$item" "$api_source_dir/" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
[[ -d "$backup_dir/routes" ]] && cp -rf "$backup_dir/routes" "$api_source_dir/routes/"
|
if [[ -d "$backup_dir/routes" ]]; then
|
||||||
|
rm -rf "$api_source_dir/routes"
|
||||||
|
cp -rf "$backup_dir/routes" "$api_source_dir/routes"
|
||||||
|
fi
|
||||||
|
if [[ -d "$backup_dir/src" ]]; then
|
||||||
|
rm -rf "$api_source_dir/src"
|
||||||
|
cp -rf "$backup_dir/src" "$api_source_dir/src"
|
||||||
|
fi
|
||||||
|
|
||||||
docker compose build --quiet 2>&1 || docker-compose build --quiet 2>&1 || true
|
docker compose build --quiet 2>&1 || docker-compose build --quiet 2>&1 || true
|
||||||
docker compose up -d 2>&1 || docker-compose up -d 2>&1 || true
|
docker compose up -d 2>&1 || docker-compose up -d 2>&1 || true
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ Description=Watch for DashCaddy update trigger
|
|||||||
|
|
||||||
[Path]
|
[Path]
|
||||||
PathChanged=/opt/dashcaddy/updates/trigger.json
|
PathChanged=/opt/dashcaddy/updates/trigger.json
|
||||||
MakeDirectory=yes
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
@@ -435,6 +435,7 @@ fetch_source() {
|
|||||||
cp -f "${api_src}/Dockerfile" "$API_DIR/"
|
cp -f "${api_src}/Dockerfile" "$API_DIR/"
|
||||||
cp -f "${api_src}/openapi.yaml" "$API_DIR/" 2>/dev/null || true
|
cp -f "${api_src}/openapi.yaml" "$API_DIR/" 2>/dev/null || true
|
||||||
[[ -d "${api_src}/routes" ]] && cp -rf "${api_src}/routes" "$API_DIR/"
|
[[ -d "${api_src}/routes" ]] && cp -rf "${api_src}/routes" "$API_DIR/"
|
||||||
|
[[ -d "${api_src}/src" ]] && cp -rf "${api_src}/src" "$API_DIR/"
|
||||||
ok "API files deployed"
|
ok "API files deployed"
|
||||||
|
|
||||||
# Deploy dashboard files
|
# Deploy dashboard files
|
||||||
@@ -698,7 +699,6 @@ install_updater_service() {
|
|||||||
Description=Watch for DashCaddy update trigger
|
Description=Watch for DashCaddy update trigger
|
||||||
[Path]
|
[Path]
|
||||||
PathChanged=/opt/dashcaddy/updates/trigger.json
|
PathChanged=/opt/dashcaddy/updates/trigger.json
|
||||||
MakeDirectory=yes
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
PATHEOF
|
PATHEOF
|
||||||
|
|||||||
@@ -0,0 +1,136 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Cut a DashCaddy release: bump dashcaddy-api/package.json, commit, push,
|
||||||
|
# build tarball + version.json on DNS2 (the get.dashcaddy.net publishing
|
||||||
|
# host), refresh install.sh, then mirror everything to the dc-contabo-de
|
||||||
|
# get2 backup.
|
||||||
|
#
|
||||||
|
# Usage: scripts/release.sh <version>
|
||||||
|
# Example: scripts/release.sh 1.4.0
|
||||||
|
#
|
||||||
|
# Pre-flight: must be on `main`, working tree clean, gitea remote reachable.
|
||||||
|
#
|
||||||
|
# Hosts/URLs are overridable via env:
|
||||||
|
# DASHCADDY_RELEASE_HOST default root@100.104.4.5 (DNS2, hosts get.dashcaddy.net)
|
||||||
|
# DASHCADDY_MIRROR_HOST default root@dc-contabo-de (hosts get2.dashcaddy.net)
|
||||||
|
# DASHCADDY_GITEA_URL default http://100.98.123.59:3000/sami7777/dashcaddy.git
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
VERSION="${1:-}"
|
||||||
|
[[ -z "$VERSION" ]] && { echo "Usage: $0 <version>" >&2; exit 1; }
|
||||||
|
[[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || { echo "Invalid version (need X.Y.Z): $VERSION" >&2; exit 1; }
|
||||||
|
|
||||||
|
REPO_ROOT="$(git rev-parse --show-toplevel)"
|
||||||
|
RELEASE_HOST="${DASHCADDY_RELEASE_HOST:-root@100.104.4.5}"
|
||||||
|
MIRROR_HOST="${DASHCADDY_MIRROR_HOST:-root@dc-contabo-de}"
|
||||||
|
GITEA_URL="${DASHCADDY_GITEA_URL:-http://100.98.123.59:3000/sami7777/dashcaddy.git}"
|
||||||
|
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
|
||||||
|
# ── Pre-flight ─────────────────────────────────────────────────────────────
|
||||||
|
[[ -f dashcaddy-api/package.json ]] || { echo "Run from dashcaddy repo root (no dashcaddy-api/package.json)" >&2; exit 1; }
|
||||||
|
[[ -n "$(git status --porcelain)" ]] && { echo "Working tree must be clean" >&2; exit 1; }
|
||||||
|
BRANCH="$(git rev-parse --abbrev-ref HEAD)"
|
||||||
|
[[ "$BRANCH" == "main" ]] || { echo "Must be on main (current: $BRANCH)" >&2; exit 1; }
|
||||||
|
|
||||||
|
CURRENT="$(node -p "require('./dashcaddy-api/package.json').version")"
|
||||||
|
[[ "$CURRENT" == "$VERSION" ]] && { echo "package.json already at $VERSION — nothing to do" >&2; exit 1; }
|
||||||
|
|
||||||
|
echo "─── Cutting release ───"
|
||||||
|
echo " current: $CURRENT"
|
||||||
|
echo " target: $VERSION"
|
||||||
|
echo " release: $RELEASE_HOST"
|
||||||
|
echo " mirror: $MIRROR_HOST"
|
||||||
|
echo
|
||||||
|
|
||||||
|
# ── 1. Bump dashcaddy-api/package.json ────────────────────────────────────
|
||||||
|
echo "[1/6] Bumping dashcaddy-api/package.json"
|
||||||
|
node -e "
|
||||||
|
const fs = require('fs');
|
||||||
|
const pkg = require('./dashcaddy-api/package.json');
|
||||||
|
pkg.version = '$VERSION';
|
||||||
|
fs.writeFileSync('./dashcaddy-api/package.json', JSON.stringify(pkg, null, 2) + '\n');
|
||||||
|
"
|
||||||
|
|
||||||
|
# ── 2. Rebuild status frontend so dist/*.js matches source ────────────────
|
||||||
|
if [[ -f status/build.js ]]; then
|
||||||
|
echo "[2/6] Rebuilding status frontend"
|
||||||
|
(cd status && node build.js >/dev/null)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ── 3. Commit + push ──────────────────────────────────────────────────────
|
||||||
|
echo "[3/6] Committing + pushing"
|
||||||
|
git add dashcaddy-api/package.json
|
||||||
|
# status/dist/ is .gitignored but its tracked files still need re-staging on rebuild.
|
||||||
|
# -f bypasses the ignore for these specific paths.
|
||||||
|
[[ -d status/dist ]] && git add -f status/dist/ 2>/dev/null || true
|
||||||
|
git commit -m "chore(release): bump to $VERSION" >/dev/null
|
||||||
|
git push gitea main >/dev/null
|
||||||
|
COMMIT="$(git rev-parse --short HEAD)"
|
||||||
|
echo " → committed: $COMMIT"
|
||||||
|
|
||||||
|
# ── 4. Build tarball on the publishing host ───────────────────────────────
|
||||||
|
echo "[4/6] Building tarball on $RELEASE_HOST"
|
||||||
|
ssh "$RELEASE_HOST" "set -e
|
||||||
|
rm -rf /tmp/dashcaddy-build
|
||||||
|
mkdir -p /tmp/dashcaddy-build
|
||||||
|
cd /tmp/dashcaddy-build
|
||||||
|
git clone --depth 1 '$GITEA_URL' dashcaddy >/dev/null 2>&1
|
||||||
|
cd dashcaddy
|
||||||
|
ACTUAL_COMMIT=\$(git rev-parse --short HEAD)
|
||||||
|
if [ \"\$ACTUAL_COMMIT\" != \"$COMMIT\" ]; then
|
||||||
|
echo \" ! cloned commit \$ACTUAL_COMMIT does not match expected $COMMIT — aborting\" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
rm -rf .git
|
||||||
|
find . -type d -name node_modules -exec rm -rf {} + 2>/dev/null || true
|
||||||
|
# Bake the actual commit SHA into the api VERSION file so containers built
|
||||||
|
# from this tarball report a real commit (not the 'dev' placeholder).
|
||||||
|
echo \"$COMMIT\" > dashcaddy-api/VERSION
|
||||||
|
cd /tmp/dashcaddy-build
|
||||||
|
tar zcf dashcaddy-$VERSION.tar.gz dashcaddy/
|
||||||
|
"
|
||||||
|
echo " → built /tmp/dashcaddy-build/dashcaddy-$VERSION.tar.gz"
|
||||||
|
|
||||||
|
# ── 5. Publish on the release host ────────────────────────────────────────
|
||||||
|
echo "[5/6] Publishing v$VERSION + refreshed install.sh on $RELEASE_HOST"
|
||||||
|
ssh "$RELEASE_HOST" "set -e
|
||||||
|
cd /var/www/get.dashcaddy.net
|
||||||
|
cp -a release release.backup-\$(date -u +%Y%m%d-%H%M%S)
|
||||||
|
cp /tmp/dashcaddy-build/dashcaddy-$VERSION.tar.gz release/
|
||||||
|
cp /tmp/dashcaddy-build/dashcaddy-$VERSION.tar.gz release/latest.tar.gz
|
||||||
|
( cd release && sha256sum latest.tar.gz > latest.tar.gz.sha256 )
|
||||||
|
cp /tmp/dashcaddy-build/dashcaddy/dashcaddy-installer/install.sh release/install.sh
|
||||||
|
chmod +x release/install.sh
|
||||||
|
SHA256=\$(sha256sum release/dashcaddy-$VERSION.tar.gz | cut -d' ' -f1)
|
||||||
|
cat > release/version.json <<EOF
|
||||||
|
{
|
||||||
|
\"version\": \"$VERSION\",
|
||||||
|
\"commit\": \"$COMMIT\",
|
||||||
|
\"date\": \"\$(date -u +%Y-%m-%dT%H:%M:%SZ)\",
|
||||||
|
\"sha256\": \"\$SHA256\",
|
||||||
|
\"changelog\": \"$COMMIT chore(release): bump to $VERSION\",
|
||||||
|
\"breaking\": false,
|
||||||
|
\"tarball\": \"dashcaddy-$VERSION.tar.gz\"
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
"
|
||||||
|
|
||||||
|
# ── 6. Mirror to backup host ──────────────────────────────────────────────
|
||||||
|
echo "[6/6] Mirroring to $MIRROR_HOST"
|
||||||
|
ssh "$RELEASE_HOST" "rsync -aq --delete /var/www/get.dashcaddy.net/release/ $MIRROR_HOST:/var/www/get2.dashcaddy.net/release/"
|
||||||
|
|
||||||
|
# ── Verify ───────────────────────────────────────────────────────────────
|
||||||
|
echo
|
||||||
|
echo "─── Verifying live ───"
|
||||||
|
SERVED_VER="$(curl -fsSL --max-time 5 https://get.dashcaddy.net/release/version.json | node -p "JSON.parse(require('fs').readFileSync('/dev/stdin')).version")"
|
||||||
|
[[ "$SERVED_VER" == "$VERSION" ]] || { echo "MISMATCH: get.dashcaddy.net serves $SERVED_VER, expected $VERSION" >&2; exit 1; }
|
||||||
|
echo " get.dashcaddy.net → $SERVED_VER ✓"
|
||||||
|
|
||||||
|
SHA_LOCAL="$(ssh "$RELEASE_HOST" "sha256sum /var/www/get.dashcaddy.net/release/dashcaddy-$VERSION.tar.gz | cut -d' ' -f1")"
|
||||||
|
SHA_HTTP="$(curl -fsSL --max-time 30 "https://get.dashcaddy.net/release/dashcaddy-$VERSION.tar.gz" | sha256sum | cut -d' ' -f1)"
|
||||||
|
[[ "$SHA_LOCAL" == "$SHA_HTTP" ]] || { echo "SHA mismatch on served tarball" >&2; exit 1; }
|
||||||
|
echo " tarball sha256 → $SHA_HTTP ✓"
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Done. v$VERSION published from commit $COMMIT."
|
||||||
@@ -2852,6 +2852,28 @@ button:focus-visible {
|
|||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Range selector buttons (resource monitor history) */
|
||||||
|
.stats-range-btn {
|
||||||
|
padding: 4px 10px;
|
||||||
|
background: var(--card-base);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
color: var(--muted);
|
||||||
|
border-radius: 4px;
|
||||||
|
font-size: 0.75rem;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-range-btn:hover {
|
||||||
|
border-color: var(--accent);
|
||||||
|
color: var(--fg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.stats-range-btn.active {
|
||||||
|
background: color-mix(in srgb, var(--accent) 18%, transparent);
|
||||||
|
border-color: var(--accent);
|
||||||
|
color: var(--accent);
|
||||||
|
}
|
||||||
|
|
||||||
/* Status badges (Health and Updates) */
|
/* Status badges (Health and Updates) */
|
||||||
.status-badge {
|
.status-badge {
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
|
|||||||
Vendored
+247
-211
File diff suppressed because one or more lines are too long
@@ -1,5 +1,6 @@
|
|||||||
// App Selector System
|
// App Selector System
|
||||||
(function () {
|
(function () {
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
injectModal('app-selector-modal', `<div id="app-selector-modal" class="weather-modal">
|
injectModal('app-selector-modal', `<div id="app-selector-modal" class="weather-modal">
|
||||||
<div class="app-selector-content">
|
<div class="app-selector-content">
|
||||||
<h2 style="margin: 0 0 24px; color: var(--fg); text-align: center;">Choose an App</h2>
|
<h2 style="margin: 0 0 24px; color: var(--fg); text-align: center;">Choose an App</h2>
|
||||||
@@ -230,7 +231,7 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to fetch app templates:', e);
|
errorHandler.logError('[AppSelector] Fetch Templates', e, { function: 'fetchApiTemplates' });
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -242,7 +243,7 @@
|
|||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to check port:', e);
|
errorHandler.logError('[AppSelector] Check Port', e, { function: 'checkPortAvailability' });
|
||||||
return { available: true }; // Assume available on error
|
return { available: true }; // Assume available on error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -256,7 +257,7 @@
|
|||||||
return data.suggestedPort;
|
return data.suggestedPort;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to get suggested port:', e);
|
errorHandler.logError('[AppSelector] Get Suggested Port', e, { function: 'getSuggestedPort' });
|
||||||
}
|
}
|
||||||
return basePort;
|
return basePort;
|
||||||
}
|
}
|
||||||
@@ -842,7 +843,7 @@
|
|||||||
throw new Error(result.error || 'Deployment failed');
|
throw new Error(result.error || 'Deployment failed');
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Deployment error:', error);
|
errorHandler.logError('[AppSelector] Deployment', error, { function: 'deploy' });
|
||||||
showNotification(
|
showNotification(
|
||||||
`Failed to deploy ${appTemplate.name}: ${error.message}`,
|
`Failed to deploy ${appTemplate.name}: ${error.message}`,
|
||||||
'error',
|
'error',
|
||||||
|
|||||||
+228
-2
@@ -384,6 +384,9 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
// === Automated Backups Tab ===
|
// === Automated Backups Tab ===
|
||||||
|
// Holds the destination currently being edited in the form
|
||||||
|
var currentDestination = { type: 'local' };
|
||||||
|
|
||||||
async function loadBackupSchedule() {
|
async function loadBackupSchedule() {
|
||||||
if (!scheduleContainer) return;
|
if (!scheduleContainer) return;
|
||||||
try {
|
try {
|
||||||
@@ -394,6 +397,10 @@
|
|||||||
var autoKey = Object.keys(cfg)[0];
|
var autoKey = Object.keys(cfg)[0];
|
||||||
var auto = autoKey ? cfg[autoKey] : null;
|
var auto = autoKey ? cfg[autoKey] : null;
|
||||||
|
|
||||||
|
// Pull existing destination (first one) — fall back to local
|
||||||
|
var existingDest = (auto?.destinations && auto.destinations[0]) || { type: 'local' };
|
||||||
|
currentDestination = JSON.parse(JSON.stringify(existingDest));
|
||||||
|
|
||||||
var html = '<div style="padding: 16px; background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 10px; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); margin-bottom: 16px;">';
|
var html = '<div style="padding: 16px; background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 10px; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); margin-bottom: 16px;">';
|
||||||
html += '<h4 style="margin: 0 0 12px; color: var(--accent); font-size: 0.9rem;">⏰ Backup Schedule</h4>';
|
html += '<h4 style="margin: 0 0 12px; color: var(--accent); font-size: 0.9rem;">⏰ Backup Schedule</h4>';
|
||||||
html += '<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px;">';
|
html += '<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 12px;">';
|
||||||
@@ -423,20 +430,238 @@
|
|||||||
html += ' <button id="backup-run-now" style="padding: 8px 16px; border-radius: 6px; cursor: pointer;">▶️ Run Backup Now</button>';
|
html += ' <button id="backup-run-now" style="padding: 8px 16px; border-radius: 6px; cursor: pointer;">▶️ Run Backup Now</button>';
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
html += '</div>';
|
html += '</div>';
|
||||||
|
|
||||||
|
// === Destination Section ===
|
||||||
|
html += '<div style="padding: 16px; background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 10px; border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); margin-bottom: 16px;">';
|
||||||
|
html += '<h4 style="margin: 0 0 12px; color: var(--accent); font-size: 0.9rem;">☁️ Backup Destination</h4>';
|
||||||
|
html += '<div><label style="font-size: 0.8rem; color: var(--muted);">Where to store backups:</label>';
|
||||||
|
html += ' <select id="backup-dest-type" style="width: 100%;">';
|
||||||
|
html += ' <option value="local"' + (currentDestination.type === 'local' ? ' selected' : '') + '>💾 Local disk</option>';
|
||||||
|
html += ' <option value="dropbox"' + (currentDestination.type === 'dropbox' ? ' selected' : '') + '>📦 Dropbox</option>';
|
||||||
|
html += ' <option value="webdav"' + (currentDestination.type === 'webdav' ? ' selected' : '') + '>🌐 WebDAV (Nextcloud / ownCloud)</option>';
|
||||||
|
html += ' <option value="sftp"' + (currentDestination.type === 'sftp' ? ' selected' : '') + '>🔐 SFTP</option>';
|
||||||
|
html += ' </select></div>';
|
||||||
|
html += '<div id="backup-dest-form" style="margin-top: 12px;"></div>';
|
||||||
|
html += '<div id="backup-dest-result" style="display: none; margin-top: 10px; padding: 8px 10px; border-radius: 6px; font-size: 0.8rem;"></div>';
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
html += '<div id="backup-schedule-result" style="display: none; margin-top: 12px; padding: 10px; border-radius: 8px; font-size: 0.85rem;"></div>';
|
html += '<div id="backup-schedule-result" style="display: none; margin-top: 12px; padding: 10px; border-radius: 8px; font-size: 0.85rem;"></div>';
|
||||||
scheduleContainer.innerHTML = html;
|
scheduleContainer.innerHTML = html;
|
||||||
|
|
||||||
document.getElementById('backup-save-schedule')?.addEventListener('click', saveSchedule);
|
document.getElementById('backup-save-schedule')?.addEventListener('click', saveSchedule);
|
||||||
document.getElementById('backup-run-now')?.addEventListener('click', runBackupNow);
|
document.getElementById('backup-run-now')?.addEventListener('click', runBackupNow);
|
||||||
|
|
||||||
|
var destTypeSel = document.getElementById('backup-dest-type');
|
||||||
|
destTypeSel?.addEventListener('change', function() {
|
||||||
|
currentDestination = { type: destTypeSel.value };
|
||||||
|
renderDestinationForm(destTypeSel.value);
|
||||||
|
});
|
||||||
|
renderDestinationForm(currentDestination.type);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
scheduleContainer.innerHTML = '<div class="panel-empty" style="color: var(--bad-fg);">Failed to load schedule: ' + escapeHtml(e.message) + '</div>';
|
scheduleContainer.innerHTML = '<div class="panel-empty" style="color: var(--bad-fg);">Failed to load schedule: ' + escapeHtml(e.message) + '</div>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the provider-specific form fields and load saved credentials (masked)
|
||||||
|
async function renderDestinationForm(type) {
|
||||||
|
var formEl = document.getElementById('backup-dest-form');
|
||||||
|
if (!formEl) return;
|
||||||
|
|
||||||
|
if (type === 'local') {
|
||||||
|
formEl.innerHTML = '<div style="font-size: 0.8rem; color: var(--muted); padding: 8px;">Backups are stored on the host filesystem. No additional configuration required.</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = '';
|
||||||
|
|
||||||
|
if (type === 'dropbox') {
|
||||||
|
html += '<label style="font-size: 0.8rem; color: var(--muted);">Access Token:</label>';
|
||||||
|
html += '<input type="password" id="dest-dropbox-token" placeholder="sl.B..." style="width: 100%; margin-bottom: 8px;" />';
|
||||||
|
html += '<label style="font-size: 0.8rem; color: var(--muted);">Folder path:</label>';
|
||||||
|
html += '<input type="text" id="dest-dropbox-path" placeholder="/dashcaddy-backups" value="' + escapeHtml(currentDestination.path || '/dashcaddy-backups') + '" style="width: 100%; margin-bottom: 8px;" />';
|
||||||
|
html += '<div style="font-size: 0.7rem; color: var(--muted); margin-bottom: 8px;">Generate a token at <a href="https://www.dropbox.com/developers/apps" target="_blank" style="color: var(--accent);">Dropbox App Console</a> with files.content.write + files.content.read scopes.</div>';
|
||||||
|
} else if (type === 'webdav') {
|
||||||
|
html += '<label style="font-size: 0.8rem; color: var(--muted);">Server URL:</label>';
|
||||||
|
html += '<input type="text" id="dest-webdav-url" placeholder="https://cloud.example.com/remote.php/dav/files/username" style="width: 100%; margin-bottom: 8px;" />';
|
||||||
|
html += '<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px;">';
|
||||||
|
html += ' <div><label style="font-size: 0.8rem; color: var(--muted);">Username:</label>';
|
||||||
|
html += ' <input type="text" id="dest-webdav-username" style="width: 100%;" /></div>';
|
||||||
|
html += ' <div><label style="font-size: 0.8rem; color: var(--muted);">Password / App password:</label>';
|
||||||
|
html += ' <input type="password" id="dest-webdav-password" style="width: 100%;" /></div>';
|
||||||
|
html += '</div>';
|
||||||
|
html += '<label style="font-size: 0.8rem; color: var(--muted);">Folder path:</label>';
|
||||||
|
html += '<input type="text" id="dest-webdav-path" placeholder="/dashcaddy-backups" value="' + escapeHtml(currentDestination.path || '/dashcaddy-backups') + '" style="width: 100%; margin-bottom: 8px;" />';
|
||||||
|
} else if (type === 'sftp') {
|
||||||
|
html += '<div style="display: grid; grid-template-columns: 2fr 1fr; gap: 8px; margin-bottom: 8px;">';
|
||||||
|
html += ' <div><label style="font-size: 0.8rem; color: var(--muted);">Host:</label>';
|
||||||
|
html += ' <input type="text" id="dest-sftp-host" placeholder="backup.example.com" style="width: 100%;" /></div>';
|
||||||
|
html += ' <div><label style="font-size: 0.8rem; color: var(--muted);">Port:</label>';
|
||||||
|
html += ' <input type="number" id="dest-sftp-port" value="22" style="width: 100%;" /></div>';
|
||||||
|
html += '</div>';
|
||||||
|
html += '<label style="font-size: 0.8rem; color: var(--muted);">Username:</label>';
|
||||||
|
html += '<input type="text" id="dest-sftp-username" style="width: 100%; margin-bottom: 8px;" />';
|
||||||
|
html += '<label style="font-size: 0.8rem; color: var(--muted);">Auth method:</label>';
|
||||||
|
html += '<select id="dest-sftp-authtype" style="width: 100%; margin-bottom: 8px;">';
|
||||||
|
html += ' <option value="password">Password</option>';
|
||||||
|
html += ' <option value="key">Private key</option>';
|
||||||
|
html += '</select>';
|
||||||
|
html += '<div id="dest-sftp-password-row"><label style="font-size: 0.8rem; color: var(--muted);">Password:</label>';
|
||||||
|
html += ' <input type="password" id="dest-sftp-password" style="width: 100%; margin-bottom: 8px;" /></div>';
|
||||||
|
html += '<div id="dest-sftp-key-row" style="display: none;"><label style="font-size: 0.8rem; color: var(--muted);">Private key (PEM):</label>';
|
||||||
|
html += ' <textarea id="dest-sftp-privatekey" rows="4" style="width: 100%; font-family: monospace; font-size: 0.75rem; margin-bottom: 8px;" placeholder="-----BEGIN OPENSSH PRIVATE KEY-----"></textarea></div>';
|
||||||
|
html += '<label style="font-size: 0.8rem; color: var(--muted);">Remote path:</label>';
|
||||||
|
html += '<input type="text" id="dest-sftp-path" placeholder="/home/user/dashcaddy-backups" value="' + escapeHtml(currentDestination.path || '/home/user/dashcaddy-backups') + '" style="width: 100%; margin-bottom: 8px;" />';
|
||||||
|
}
|
||||||
|
|
||||||
|
html += '<div style="display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap;">';
|
||||||
|
html += ' <button id="dest-save-creds" style="padding: 6px 12px; font-size: 0.8rem; border-radius: 6px; cursor: pointer;">💾 Save Credentials</button>';
|
||||||
|
html += ' <button id="dest-test-conn" style="padding: 6px 12px; font-size: 0.8rem; background: color-mix(in srgb, var(--accent) 20%, transparent); border: 1px solid var(--accent); color: var(--accent); border-radius: 6px; cursor: pointer;">🔌 Test Connection</button>';
|
||||||
|
html += ' <button id="dest-clear-creds" style="padding: 6px 12px; font-size: 0.8rem; border-radius: 6px; cursor: pointer; color: var(--bad-fg);">🗑️ Clear</button>';
|
||||||
|
html += '</div>';
|
||||||
|
|
||||||
|
formEl.innerHTML = html;
|
||||||
|
|
||||||
|
// SFTP auth type toggle
|
||||||
|
if (type === 'sftp') {
|
||||||
|
var authSel = document.getElementById('dest-sftp-authtype');
|
||||||
|
var pwRow = document.getElementById('dest-sftp-password-row');
|
||||||
|
var keyRow = document.getElementById('dest-sftp-key-row');
|
||||||
|
authSel?.addEventListener('change', function() {
|
||||||
|
if (authSel.value === 'key') { pwRow.style.display = 'none'; keyRow.style.display = ''; }
|
||||||
|
else { pwRow.style.display = ''; keyRow.style.display = 'none'; }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById('dest-save-creds')?.addEventListener('click', function() { saveCredentials(type); });
|
||||||
|
document.getElementById('dest-test-conn')?.addEventListener('click', function() { testDestination(type); });
|
||||||
|
document.getElementById('dest-clear-creds')?.addEventListener('click', function() { clearCredentials(type); });
|
||||||
|
|
||||||
|
// Pull existing (masked) credentials
|
||||||
|
await loadCredentials(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
function destResult(msg, ok) {
|
||||||
|
var el = document.getElementById('backup-dest-result');
|
||||||
|
if (!el) return;
|
||||||
|
el.innerHTML = msg;
|
||||||
|
el.style.display = 'block';
|
||||||
|
el.style.background = ok ? 'color-mix(in srgb, var(--ok-fg) 15%, transparent)' : 'color-mix(in srgb, var(--bad-fg) 15%, transparent)';
|
||||||
|
el.style.border = ok ? '1px solid var(--ok-fg)' : '1px solid var(--bad-fg)';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadCredentials(provider) {
|
||||||
|
try {
|
||||||
|
var res = await fetch('/api/v1/backups/credentials/' + provider);
|
||||||
|
var data = await res.json();
|
||||||
|
if (!data.success || !data.credentials) return;
|
||||||
|
var c = data.credentials;
|
||||||
|
if (provider === 'dropbox') {
|
||||||
|
var t = document.getElementById('dest-dropbox-token'); if (t && c.token) t.value = c.token;
|
||||||
|
} else if (provider === 'webdav') {
|
||||||
|
var u = document.getElementById('dest-webdav-url'); if (u && c.url) u.value = c.url;
|
||||||
|
var n = document.getElementById('dest-webdav-username'); if (n && c.username) n.value = c.username;
|
||||||
|
var p = document.getElementById('dest-webdav-password'); if (p && c.password) p.value = c.password;
|
||||||
|
} else if (provider === 'sftp') {
|
||||||
|
var h = document.getElementById('dest-sftp-host'); if (h && c.host) h.value = c.host;
|
||||||
|
var po = document.getElementById('dest-sftp-port'); if (po && c.port) po.value = c.port;
|
||||||
|
var un = document.getElementById('dest-sftp-username'); if (un && c.username) un.value = c.username;
|
||||||
|
var pw = document.getElementById('dest-sftp-password'); if (pw && c.password) pw.value = c.password;
|
||||||
|
var pk = document.getElementById('dest-sftp-privatekey'); if (pk && c.privateKey) pk.value = c.privateKey;
|
||||||
|
if (c.privateKey) {
|
||||||
|
var sel = document.getElementById('dest-sftp-authtype');
|
||||||
|
if (sel) { sel.value = 'key'; sel.dispatchEvent(new Event('change')); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) { /* no creds yet — silent */ }
|
||||||
|
}
|
||||||
|
|
||||||
|
function collectCredentials(provider) {
|
||||||
|
if (provider === 'dropbox') {
|
||||||
|
return { token: document.getElementById('dest-dropbox-token')?.value };
|
||||||
|
}
|
||||||
|
if (provider === 'webdav') {
|
||||||
|
return {
|
||||||
|
url: document.getElementById('dest-webdav-url')?.value,
|
||||||
|
username: document.getElementById('dest-webdav-username')?.value,
|
||||||
|
password: document.getElementById('dest-webdav-password')?.value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (provider === 'sftp') {
|
||||||
|
var auth = document.getElementById('dest-sftp-authtype')?.value;
|
||||||
|
var creds = {
|
||||||
|
host: document.getElementById('dest-sftp-host')?.value,
|
||||||
|
port: parseInt(document.getElementById('dest-sftp-port')?.value) || 22,
|
||||||
|
username: document.getElementById('dest-sftp-username')?.value
|
||||||
|
};
|
||||||
|
if (auth === 'key') creds.privateKey = document.getElementById('dest-sftp-privatekey')?.value;
|
||||||
|
else creds.password = document.getElementById('dest-sftp-password')?.value;
|
||||||
|
return creds;
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveCredentials(provider) {
|
||||||
|
try {
|
||||||
|
var creds = collectCredentials(provider);
|
||||||
|
var res = await secureFetch('/api/v1/backups/credentials/' + provider, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(creds)
|
||||||
|
});
|
||||||
|
var data = await res.json();
|
||||||
|
destResult(data.success ? '✅ Credentials saved' : '⚠️ ' + escapeHtml(data.error || 'Failed'), data.success);
|
||||||
|
} catch (e) {
|
||||||
|
destResult('❌ ' + escapeHtml(e.message), false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function clearCredentials(provider) {
|
||||||
|
if (!confirm('Delete saved ' + provider + ' credentials?')) return;
|
||||||
|
try {
|
||||||
|
var res = await secureFetch('/api/v1/backups/credentials/' + provider, { method: 'DELETE' });
|
||||||
|
var data = await res.json();
|
||||||
|
if (data.success) {
|
||||||
|
destResult('✅ Credentials cleared', true);
|
||||||
|
renderDestinationForm(provider);
|
||||||
|
} else {
|
||||||
|
destResult('⚠️ ' + escapeHtml(data.error || 'Failed'), false);
|
||||||
|
}
|
||||||
|
} catch (e) { destResult('❌ ' + escapeHtml(e.message), false); }
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildDestination(type) {
|
||||||
|
var dest = { type: type };
|
||||||
|
if (type === 'local') return dest;
|
||||||
|
if (type === 'dropbox') dest.path = document.getElementById('dest-dropbox-path')?.value || '/dashcaddy-backups';
|
||||||
|
else if (type === 'webdav') dest.path = document.getElementById('dest-webdav-path')?.value || '/dashcaddy-backups';
|
||||||
|
else if (type === 'sftp') dest.path = document.getElementById('dest-sftp-path')?.value || '/dashcaddy-backups';
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function testDestination(type) {
|
||||||
|
destResult('<span class="brand-spinner"></span> Testing connection...', true);
|
||||||
|
try {
|
||||||
|
var dest = buildDestination(type);
|
||||||
|
var res = await secureFetch('/api/v1/backups/test-destination', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(dest)
|
||||||
|
});
|
||||||
|
var data = await res.json();
|
||||||
|
if (data.success) {
|
||||||
|
var ms = data.elapsedMs ? ' (' + data.elapsedMs + 'ms)' : '';
|
||||||
|
destResult('✅ Connection OK' + ms + ' — write/read/delete probe succeeded', true);
|
||||||
|
} else {
|
||||||
|
destResult('❌ ' + escapeHtml(data.error || 'Connection failed'), false);
|
||||||
|
}
|
||||||
|
} catch (e) { destResult('❌ ' + escapeHtml(e.message), false); }
|
||||||
|
}
|
||||||
|
|
||||||
async function saveSchedule() {
|
async function saveSchedule() {
|
||||||
var schedule = document.getElementById('backup-schedule-select')?.value;
|
var schedule = document.getElementById('backup-schedule-select')?.value;
|
||||||
var retention = parseInt(document.getElementById('backup-retention-select')?.value) || 5;
|
var retention = parseInt(document.getElementById('backup-retention-select')?.value) || 5;
|
||||||
var encrypt = document.getElementById('backup-encrypt-toggle')?.checked ?? true;
|
var encrypt = document.getElementById('backup-encrypt-toggle')?.checked ?? true;
|
||||||
|
var destType = document.getElementById('backup-dest-type')?.value || 'local';
|
||||||
var resultEl = document.getElementById('backup-schedule-result');
|
var resultEl = document.getElementById('backup-schedule-result');
|
||||||
try {
|
try {
|
||||||
var res = await secureFetch('/api/v1/backups/config', {
|
var res = await secureFetch('/api/v1/backups/config', {
|
||||||
@@ -451,7 +676,7 @@
|
|||||||
encrypt: encrypt,
|
encrypt: encrypt,
|
||||||
verify: true,
|
verify: true,
|
||||||
retention: { keep: retention },
|
retention: { keep: retention },
|
||||||
destinations: [{ type: 'local' }]
|
destinations: [buildDestination(destType)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -477,12 +702,13 @@
|
|||||||
async function runBackupNow() {
|
async function runBackupNow() {
|
||||||
var btn = document.getElementById('backup-run-now');
|
var btn = document.getElementById('backup-run-now');
|
||||||
var resultEl = document.getElementById('backup-schedule-result');
|
var resultEl = document.getElementById('backup-schedule-result');
|
||||||
|
var destType = document.getElementById('backup-dest-type')?.value || 'local';
|
||||||
if (btn) { btn.disabled = true; btn.innerHTML = '<span class="brand-spinner"></span> Running...'; }
|
if (btn) { btn.disabled = true; btn.innerHTML = '<span class="brand-spinner"></span> Running...'; }
|
||||||
try {
|
try {
|
||||||
var res = await secureFetch('/api/v1/backups/execute', {
|
var res = await secureFetch('/api/v1/backups/execute', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({ include: ['all'], destinations: [{ type: 'local' }] })
|
body: JSON.stringify({ include: ['all'], destinations: [buildDestination(destType)] })
|
||||||
});
|
});
|
||||||
var data = await res.json();
|
var data = await res.json();
|
||||||
if (resultEl) {
|
if (resultEl) {
|
||||||
|
|||||||
@@ -6,12 +6,16 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const debug = (...args) => {
|
||||||
|
if (window.DASHCADDY_DEBUG) console.log(...args);
|
||||||
|
};
|
||||||
|
|
||||||
class DnsTemplateSelector {
|
class DnsTemplateSelector {
|
||||||
constructor(progressTracker) {
|
constructor(progressTracker) {
|
||||||
this.progressTracker = progressTracker;
|
this.progressTracker = progressTracker;
|
||||||
this.modal = null;
|
this.modal = null;
|
||||||
this.onTemplateSelected = null;
|
this.onTemplateSelected = null;
|
||||||
console.log('[DnsTemplateSelector] Module loaded');
|
debug('[DnsTemplateSelector] Module loaded');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -216,7 +220,7 @@
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
handleTemplateSelection(template) {
|
handleTemplateSelection(template) {
|
||||||
console.log(`[DnsTemplateSelector] Template selected: ${template.id}`);
|
debug(`[DnsTemplateSelector] Template selected: ${template.id}`);
|
||||||
|
|
||||||
// Close modal
|
// Close modal
|
||||||
this.close();
|
this.close();
|
||||||
@@ -235,7 +239,7 @@
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
handleSetupLater() {
|
handleSetupLater() {
|
||||||
console.log('[DnsTemplateSelector] DNS setup deferred');
|
debug('[DnsTemplateSelector] DNS setup deferred');
|
||||||
|
|
||||||
// Mark as deferred in progress tracker
|
// Mark as deferred in progress tracker
|
||||||
if (this.progressTracker) {
|
if (this.progressTracker) {
|
||||||
@@ -316,6 +320,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
window.DnsTemplateSelector = DnsTemplateSelector;
|
window.DnsTemplateSelector = DnsTemplateSelector;
|
||||||
console.log('[DnsTemplateSelector] Module loaded');
|
debug('[DnsTemplateSelector] Module loaded');
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ const DC = {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Error handler for tracking issues
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
|
|
||||||
// ===== GLOBAL SITE CONFIG (loaded from server, cached in localStorage) =====
|
// ===== GLOBAL SITE CONFIG (loaded from server, cached in localStorage) =====
|
||||||
// Only non-sensitive display preferences are cached; DNS IPs/topology are fetched from API
|
// Only non-sensitive display preferences are cached; DNS IPs/topology are fetched from API
|
||||||
const _cachedCfg = JSON.parse(localStorage.getItem('dashcaddy_site_config') || 'null');
|
const _cachedCfg = JSON.parse(localStorage.getItem('dashcaddy_site_config') || 'null');
|
||||||
@@ -160,7 +163,7 @@ async function getCSRFToken() {
|
|||||||
csrfToken = data.token;
|
csrfToken = data.token;
|
||||||
return csrfToken;
|
return csrfToken;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to get CSRF token:', error);
|
errorHandler.logError('[CSRF] Get Token', error, { function: 'getCSRFToken' });
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -185,7 +188,7 @@ async function secureFetch(url, options = {}) {
|
|||||||
'X-CSRF-Token': token
|
'X-CSRF-Token': token
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to add CSRF token to request:', error);
|
errorHandler.logError('[CSRF] Add to Request', error, { function: 'secureFetch' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const debug = (...args) => {
|
||||||
|
if (window.DASHCADDY_DEBUG) { console.log(...args); }
|
||||||
|
};
|
||||||
|
|
||||||
// All modal selectors that can be closed with Escape
|
// All modal selectors that can be closed with Escape
|
||||||
const MODAL_SELECTORS = [
|
const MODAL_SELECTORS = [
|
||||||
'#app-selector-modal',
|
'#app-selector-modal',
|
||||||
@@ -39,9 +43,9 @@
|
|||||||
// Add global keyboard listener
|
// Add global keyboard listener
|
||||||
document.addEventListener('keydown', handleKeyDown);
|
document.addEventListener('keydown', handleKeyDown);
|
||||||
|
|
||||||
console.log('[Keyboard Shortcuts] Initialized');
|
debug('[Keyboard Shortcuts] Initialized');
|
||||||
console.log('[Keyboard Shortcuts] Press Ctrl+K to open quick search');
|
debug('[Keyboard Shortcuts] Press Ctrl+K to open quick search');
|
||||||
console.log('[Keyboard Shortcuts] Press Escape to close modals');
|
debug('[Keyboard Shortcuts] Press Escape to close modals');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Keyboard Shortcuts] Failed to initialize:', e.message);
|
console.warn('[Keyboard Shortcuts] Failed to initialize:', e.message);
|
||||||
}
|
}
|
||||||
@@ -599,7 +603,7 @@
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log('[Keyboard Shortcuts] Unknown action:', action);
|
debug('[Keyboard Shortcuts] Unknown action:', action);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn('[Keyboard Shortcuts] Error executing action:', e.message);
|
console.warn('[Keyboard Shortcuts] Error executing action:', e.message);
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
es.addEventListener('connected', () => {
|
es.addEventListener('connected', () => {
|
||||||
reconnectDelay = 1000; // reset backoff
|
reconnectDelay = 1000; // reset backoff
|
||||||
console.log('[SSE] Connected to event stream');
|
debug('[SSE] Connected to event stream');
|
||||||
});
|
});
|
||||||
|
|
||||||
// Health status changes → update card dots/badges in real time
|
// Health status changes → update card dots/badges in real time
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ========== NOTIFICATION SETTINGS ==========
|
// ========== NOTIFICATION SETTINGS ==========
|
||||||
(function() {
|
(function() {
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
// Inject modal HTML
|
// Inject modal HTML
|
||||||
injectModal('notifications-modal', `<div id="notifications-modal" class="weather-modal">
|
injectModal('notifications-modal', `<div id="notifications-modal" class="weather-modal">
|
||||||
<div class="weather-modal-content" style="min-width: 550px; max-width: 650px;">
|
<div class="weather-modal-content" style="min-width: 550px; max-width: 650px;">
|
||||||
@@ -255,7 +256,7 @@
|
|||||||
document.getElementById('event-deploy-failed').checked = config.events?.deploymentFailed !== false;
|
document.getElementById('event-deploy-failed').checked = config.events?.deploymentFailed !== false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load notification config:', error);
|
errorHandler.logError('[Notifications] Load Config', error, { function: 'loadConfig' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,7 +290,7 @@
|
|||||||
container.innerHTML = '<div style="color: var(--muted); text-align: center; padding: 20px;">No notifications yet</div>';
|
container.innerHTML = '<div style="color: var(--muted); text-align: center; padding: 20px;">No notifications yet</div>';
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load notification history:', error);
|
errorHandler.logError('[Notifications] Load History', error, { function: 'loadHistory' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-18
@@ -9,6 +9,12 @@
|
|||||||
(function() {
|
(function() {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const debug = (...args) => {
|
||||||
|
if (window.DASHCADDY_DEBUG) {
|
||||||
|
console.log(...args);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let progressTracker;
|
let progressTracker;
|
||||||
let themeAdapter;
|
let themeAdapter;
|
||||||
let tourManager;
|
let tourManager;
|
||||||
@@ -20,7 +26,7 @@
|
|||||||
*/
|
*/
|
||||||
async function initializeOnboarding() {
|
async function initializeOnboarding() {
|
||||||
try {
|
try {
|
||||||
console.log('[Onboarding] Initializing system...');
|
debug('[Onboarding] Initializing system...');
|
||||||
|
|
||||||
if (window.__dashcaddySiteConfigLoaded) {
|
if (window.__dashcaddySiteConfigLoaded) {
|
||||||
try {
|
try {
|
||||||
@@ -30,27 +36,27 @@
|
|||||||
|
|
||||||
// Initialize Error Handler first
|
// Initialize Error Handler first
|
||||||
errorHandler = new ErrorHandler();
|
errorHandler = new ErrorHandler();
|
||||||
console.log('[Onboarding] Error Handler initialized');
|
debug('[Onboarding] Error Handler initialized');
|
||||||
|
|
||||||
// Initialize Progress Tracker
|
// Initialize Progress Tracker
|
||||||
progressTracker = new ProgressTracker('dashcaddy_onboarding');
|
progressTracker = new ProgressTracker('dashcaddy_onboarding');
|
||||||
console.log('[Onboarding] Progress Tracker initialized');
|
debug('[Onboarding] Progress Tracker initialized');
|
||||||
|
|
||||||
// Initialize Theme Adapter
|
// Initialize Theme Adapter
|
||||||
themeAdapter = new ThemeAdapter();
|
themeAdapter = new ThemeAdapter();
|
||||||
console.log('[Onboarding] Theme Adapter initialized');
|
debug('[Onboarding] Theme Adapter initialized');
|
||||||
|
|
||||||
// Initialize DNS Template Selector
|
// Initialize DNS Template Selector
|
||||||
dnsTemplateSelector = new DnsTemplateSelector(progressTracker);
|
dnsTemplateSelector = new DnsTemplateSelector(progressTracker);
|
||||||
console.log('[Onboarding] DNS Template Selector initialized');
|
debug('[Onboarding] DNS Template Selector initialized');
|
||||||
|
|
||||||
// Initialize Tour Manager
|
// Initialize Tour Manager
|
||||||
tourManager = new TourManager(progressTracker, themeAdapter, dnsTemplateSelector);
|
tourManager = new TourManager(progressTracker, themeAdapter, dnsTemplateSelector);
|
||||||
console.log('[Onboarding] Tour Manager initialized');
|
debug('[Onboarding] Tour Manager initialized');
|
||||||
|
|
||||||
// Check if tour should auto-start
|
// Check if tour should auto-start
|
||||||
if (tourManager.shouldAutoStart()) {
|
if (tourManager.shouldAutoStart()) {
|
||||||
console.log('[Onboarding] Auto-starting tour for first-time install');
|
debug('[Onboarding] Auto-starting tour for first-time install');
|
||||||
await progressTracker.markInstallOnboardingCompleted();
|
await progressTracker.markInstallOnboardingCompleted();
|
||||||
// Wait a bit for page to fully load
|
// Wait a bit for page to fully load
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
@@ -59,11 +65,11 @@
|
|||||||
} else {
|
} else {
|
||||||
const tourCompleted = progressTracker.isTourCompleted();
|
const tourCompleted = progressTracker.isTourCompleted();
|
||||||
const currentStep = progressTracker.getCurrentStep();
|
const currentStep = progressTracker.getCurrentStep();
|
||||||
console.log(`[Onboarding] Tour not auto-starting (completed: ${tourCompleted}, step: ${currentStep})`);
|
debug(`[Onboarding] Tour not auto-starting (completed: ${tourCompleted}, step: ${currentStep})`);
|
||||||
|
|
||||||
// If tour is in progress, offer to resume
|
// If tour is in progress, offer to resume
|
||||||
if (!tourCompleted && currentStep > 0) {
|
if (!tourCompleted && currentStep > 0) {
|
||||||
console.log('[Onboarding] Tour in progress, can be resumed manually');
|
debug('[Onboarding] Tour in progress, can be resumed manually');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,13 +87,10 @@
|
|||||||
getErrorStats: () => errorHandler.getStatistics()
|
getErrorStats: () => errorHandler.getStatistics()
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[Onboarding] System initialized successfully');
|
debug('[Onboarding] System initialized successfully');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Onboarding] Initialization error:', error);
|
|
||||||
|
|
||||||
// Use error handler if available
|
|
||||||
if (errorHandler) {
|
if (errorHandler) {
|
||||||
errorHandler.logError('Initialization', error);
|
errorHandler.logError('[Onboarding] Initialization', error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Graceful degradation - don't break the dashboard
|
// Graceful degradation - don't break the dashboard
|
||||||
@@ -104,10 +107,12 @@
|
|||||||
|
|
||||||
const clickHandler = () => {
|
const clickHandler = () => {
|
||||||
if (tourManager) {
|
if (tourManager) {
|
||||||
console.log('[Onboarding] Starting tour via button click');
|
debug('[Onboarding] Starting tour via button click');
|
||||||
tourManager.restartTour();
|
tourManager.restartTour();
|
||||||
} else {
|
} else {
|
||||||
console.error('[Onboarding] Tour manager not initialized');
|
if (errorHandler) {
|
||||||
|
errorHandler.logError('[Onboarding] Tour Manager Not Initialized', new Error('Tour manager not initialized'));
|
||||||
|
}
|
||||||
alert('Tour is not available. Check browser console for errors.\n\nPossible issues:\n- Driver.js library failed to load\n- JavaScript errors during initialization');
|
alert('Tour is not available. Check browser console for errors.\n\nPossible issues:\n- Driver.js library failed to load\n- JavaScript errors during initialization');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -157,7 +162,6 @@
|
|||||||
setTimeout(attemptInit, 500);
|
setTimeout(attemptInit, 500);
|
||||||
} else {
|
} else {
|
||||||
// Max retries reached, show fallback
|
// Max retries reached, show fallback
|
||||||
console.error('[Onboarding] Driver.js failed to load after multiple attempts');
|
|
||||||
if (errorHandler) {
|
if (errorHandler) {
|
||||||
errorHandler.handleDriverLoadFailure();
|
errorHandler.handleDriverLoadFailure();
|
||||||
} else {
|
} else {
|
||||||
@@ -179,6 +183,6 @@
|
|||||||
waitForDriver();
|
waitForDriver();
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('[Onboarding] System loaded');
|
debug('[Onboarding] System loaded');
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -18,6 +18,12 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
|
|
||||||
|
const debug = (...args) => {
|
||||||
|
if (window.DASHCADDY_DEBUG) { console.log(...args); }
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ProgressTracker class
|
* ProgressTracker class
|
||||||
* Manages persistent storage of onboarding progress
|
* Manages persistent storage of onboarding progress
|
||||||
@@ -68,7 +74,7 @@
|
|||||||
const data = localStorage.getItem(this.storageKey);
|
const data = localStorage.getItem(this.storageKey);
|
||||||
return data ? JSON.parse(data) : null;
|
return data ? JSON.parse(data) : null;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[ProgressTracker] Error reading from storage:', error);
|
errorHandler.logError('[ProgressTracker] Read Storage', error, { function: '_getStorage' });
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +88,7 @@
|
|||||||
try {
|
try {
|
||||||
localStorage.setItem(this.storageKey, JSON.stringify(state));
|
localStorage.setItem(this.storageKey, JSON.stringify(state));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[ProgressTracker] Error writing to storage:', error);
|
errorHandler.logError('[ProgressTracker] Write Storage', error, { function: '_setStorage' });
|
||||||
// Handle quota exceeded or storage unavailable
|
// Handle quota exceeded or storage unavailable
|
||||||
// Fall back to session storage or in-memory storage
|
// Fall back to session storage or in-memory storage
|
||||||
this._handleStorageError(error);
|
this._handleStorageError(error);
|
||||||
@@ -100,7 +106,7 @@
|
|||||||
sessionStorage.setItem(this.storageKey, JSON.stringify(this._getStorage()));
|
sessionStorage.setItem(this.storageKey, JSON.stringify(this._getStorage()));
|
||||||
console.warn('[ProgressTracker] Falling back to session storage');
|
console.warn('[ProgressTracker] Falling back to session storage');
|
||||||
} catch (sessionError) {
|
} catch (sessionError) {
|
||||||
console.error('[ProgressTracker] Session storage also unavailable:', sessionError);
|
errorHandler.logError('[ProgressTracker] Session Storage Unavailable', sessionError, { function: '_handleStorageError' });
|
||||||
// Could implement in-memory fallback here if needed
|
// Could implement in-memory fallback here if needed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,7 +192,7 @@
|
|||||||
body: JSON.stringify({ onboardingCompleted: true })
|
body: JSON.stringify({ onboardingCompleted: true })
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[ProgressTracker] Failed to persist install onboarding state:', error);
|
errorHandler.logError('[ProgressTracker] Persist Install Onboarding', error, { function: 'markInstallOnboardingCompleted' });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,6 +314,6 @@
|
|||||||
// Export to global scope
|
// Export to global scope
|
||||||
window.ProgressTracker = ProgressTracker;
|
window.ProgressTracker = ProgressTracker;
|
||||||
|
|
||||||
console.log('[ProgressTracker] Module loaded');
|
debug('[ProgressTracker] Module loaded');
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
<div class="panel-tabs">
|
<div class="panel-tabs">
|
||||||
<button class="panel-tab active" data-panel="stats-live">Live Stats</button>
|
<button class="panel-tab active" data-panel="stats-live">Live Stats</button>
|
||||||
<button class="panel-tab" data-panel="stats-aggregated">24h Summary</button>
|
<button class="panel-tab" data-panel="stats-aggregated">24h Summary</button>
|
||||||
|
<button class="panel-tab" data-panel="stats-history">History</button>
|
||||||
<button class="panel-tab" data-panel="stats-alerts">Alerts</button>
|
<button class="panel-tab" data-panel="stats-alerts">Alerts</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -34,6 +35,27 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Tab: Long-term History -->
|
||||||
|
<div id="stats-history" class="panel-section">
|
||||||
|
<div style="display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap;">
|
||||||
|
<label style="font-size: 0.85rem; color: var(--muted);">Container:</label>
|
||||||
|
<select id="stats-history-container" style="padding: 4px 8px; background: var(--card-base); border: 1px solid var(--border); color: var(--fg); border-radius: 4px; font-size: 0.85rem; flex: 1; min-width: 180px;"></select>
|
||||||
|
<div id="stats-history-range-buttons" style="display: flex; gap: 4px;">
|
||||||
|
<button class="stats-range-btn active" data-range="1h">1h</button>
|
||||||
|
<button class="stats-range-btn" data-range="24h">24h</button>
|
||||||
|
<button class="stats-range-btn" data-range="7d">7d</button>
|
||||||
|
<button class="stats-range-btn" data-range="30d">30d</button>
|
||||||
|
<button class="stats-range-btn" data-range="1y">1y</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div id="stats-history-container-area" class="scroll-container">
|
||||||
|
<div class="panel-empty">
|
||||||
|
<span class="empty-icon">📊</span>
|
||||||
|
Choose a container and time range to view history.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Tab: Alert Configuration -->
|
<!-- Tab: Alert Configuration -->
|
||||||
<div id="stats-alerts" class="panel-section">
|
<div id="stats-alerts" class="panel-section">
|
||||||
<div id="stats-alerts-container" class="scroll-container">
|
<div id="stats-alerts-container" class="scroll-container">
|
||||||
@@ -325,4 +347,141 @@
|
|||||||
// Lazy-load tabs
|
// Lazy-load tabs
|
||||||
document.querySelector('[data-panel="stats-aggregated"]')?.addEventListener('click', loadAggregated);
|
document.querySelector('[data-panel="stats-aggregated"]')?.addEventListener('click', loadAggregated);
|
||||||
document.querySelector('[data-panel="stats-alerts"]')?.addEventListener('click', loadAlerts);
|
document.querySelector('[data-panel="stats-alerts"]')?.addEventListener('click', loadAlerts);
|
||||||
|
|
||||||
|
// === History Tab ===
|
||||||
|
const historyContainerSelect = document.getElementById('stats-history-container');
|
||||||
|
const historyArea = document.getElementById('stats-history-container-area');
|
||||||
|
const rangeButtons = document.querySelectorAll('.stats-range-btn');
|
||||||
|
|
||||||
|
let currentRange = '1h';
|
||||||
|
|
||||||
|
function rangeToMs(range) {
|
||||||
|
switch (range) {
|
||||||
|
case '1h': return 60 * 60 * 1000;
|
||||||
|
case '24h': return 24 * 60 * 60 * 1000;
|
||||||
|
case '7d': return 7 * 24 * 60 * 60 * 1000;
|
||||||
|
case '30d': return 30 * 24 * 60 * 60 * 1000;
|
||||||
|
case '1y': return 365 * 24 * 60 * 60 * 1000;
|
||||||
|
default: return 60 * 60 * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function tierLabel(tier) {
|
||||||
|
if (tier === 'raw') return 'live (10s samples)';
|
||||||
|
if (tier === 'hourly') return 'hourly average';
|
||||||
|
if (tier === 'daily') return 'daily average';
|
||||||
|
return tier;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Simple SVG sparkline — no external lib
|
||||||
|
function renderSparkline(samples, accessor, color, label, unit) {
|
||||||
|
if (!samples || samples.length === 0) {
|
||||||
|
return `<div style="text-align: center; color: var(--muted); padding: 20px;">No data for ${escapeHtml(label)}</div>`;
|
||||||
|
}
|
||||||
|
const values = samples.map(accessor).filter(v => v != null);
|
||||||
|
if (values.length === 0) {
|
||||||
|
return `<div style="text-align: center; color: var(--muted); padding: 20px;">No data for ${escapeHtml(label)}</div>`;
|
||||||
|
}
|
||||||
|
const max = Math.max(...values, 1);
|
||||||
|
const min = Math.min(...values, 0);
|
||||||
|
const range = max - min || 1;
|
||||||
|
const w = 600, h = 80, pad = 4;
|
||||||
|
const stepX = (w - pad * 2) / Math.max(values.length - 1, 1);
|
||||||
|
const points = values.map((v, i) => {
|
||||||
|
const x = pad + i * stepX;
|
||||||
|
const y = h - pad - ((v - min) / range) * (h - pad * 2);
|
||||||
|
return `${x.toFixed(1)},${y.toFixed(1)}`;
|
||||||
|
}).join(' ');
|
||||||
|
const last = values[values.length - 1];
|
||||||
|
const avg = values.reduce((a, b) => a + b, 0) / values.length;
|
||||||
|
return `
|
||||||
|
<div style="margin-bottom: 14px;">
|
||||||
|
<div style="display: flex; align-items: baseline; gap: 12px; margin-bottom: 4px;">
|
||||||
|
<span style="font-weight: 600; font-size: 0.9rem;">${escapeHtml(label)}</span>
|
||||||
|
<span style="font-size: 0.75rem; color: var(--muted);">last ${last.toFixed(1)}${unit} · avg ${avg.toFixed(1)}${unit} · max ${max.toFixed(1)}${unit}</span>
|
||||||
|
</div>
|
||||||
|
<svg viewBox="0 0 ${w} ${h}" preserveAspectRatio="none" style="width: 100%; height: ${h}px; background: var(--base); border-radius: 4px;">
|
||||||
|
<polyline fill="none" stroke="${color}" stroke-width="1.5" points="${points}" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateHistoryContainerSelect() {
|
||||||
|
if (!historyContainerSelect) return;
|
||||||
|
const data = cachedMonitoringData || {};
|
||||||
|
const previous = historyContainerSelect.value;
|
||||||
|
const entries = Object.entries(data);
|
||||||
|
if (entries.length === 0) {
|
||||||
|
historyContainerSelect.innerHTML = '<option value="">No containers</option>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
historyContainerSelect.innerHTML = entries
|
||||||
|
.map(([id, info]) => `<option value="${escapeHtml(id)}">${escapeHtml(info.name || id)}</option>`)
|
||||||
|
.join('');
|
||||||
|
if (previous && data[previous]) historyContainerSelect.value = previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadHistory() {
|
||||||
|
if (!historyArea || !historyContainerSelect) return;
|
||||||
|
const containerId = historyContainerSelect.value;
|
||||||
|
if (!containerId) {
|
||||||
|
historyArea.innerHTML = '<div class="panel-empty"><span class="empty-icon">📊</span>No container selected.</div>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const endTime = Date.now();
|
||||||
|
const startTime = endTime - rangeToMs(currentRange);
|
||||||
|
historyArea.innerHTML = '<div class="panel-empty"><span class="brand-spinner"></span> Loading history...</div>';
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/v1/monitoring/history/${encodeURIComponent(containerId)}?startTime=${startTime}&endTime=${endTime}`);
|
||||||
|
const data = await res.json();
|
||||||
|
if (!data.success) throw new Error(data.error || 'Failed to load history');
|
||||||
|
|
||||||
|
const samples = data.samples || [];
|
||||||
|
const tier = data.tier || 'raw';
|
||||||
|
|
||||||
|
if (samples.length === 0) {
|
||||||
|
historyArea.innerHTML = `<div class="panel-empty"><span class="empty-icon">📊</span>No data for the last ${currentRange}. Tier: ${tierLabel(tier)}.</div>`;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Different shape between raw vs rolled-up samples
|
||||||
|
const isRaw = tier === 'raw';
|
||||||
|
const cpuAccessor = isRaw ? (s) => s.cpu?.percent : (s) => s.cpu?.avg;
|
||||||
|
const memAccessor = isRaw ? (s) => s.memory?.percent : (s) => s.memory?.avgPercent;
|
||||||
|
const netRxAccessor = isRaw ? (s) => (s.network?.rxMB || 0) : (s) => (s.network?.rxMB || 0);
|
||||||
|
const netTxAccessor = isRaw ? (s) => (s.network?.txMB || 0) : (s) => (s.network?.txMB || 0);
|
||||||
|
|
||||||
|
let html = `
|
||||||
|
<div style="font-size: 0.75rem; color: var(--muted); margin-bottom: 8px;">
|
||||||
|
${samples.length} samples · ${escapeHtml(tierLabel(tier))} · ${new Date(startTime).toLocaleString()} → ${new Date(endTime).toLocaleString()}
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
html += renderSparkline(samples, cpuAccessor, '#2ecc71', 'CPU', '%');
|
||||||
|
html += renderSparkline(samples, memAccessor, '#3498db', 'Memory', '%');
|
||||||
|
html += renderSparkline(samples, netRxAccessor, '#9b59b6', 'Network RX', ' MB');
|
||||||
|
html += renderSparkline(samples, netTxAccessor, '#e67e22', 'Network TX', ' MB');
|
||||||
|
|
||||||
|
historyArea.innerHTML = html;
|
||||||
|
} catch (e) {
|
||||||
|
historyArea.innerHTML = `<div class="panel-empty"><span class="empty-icon">⚠️</span>Failed to load history: ${escapeHtml(e.message)}</div>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rangeButtons.forEach(btn => {
|
||||||
|
btn.addEventListener('click', () => {
|
||||||
|
rangeButtons.forEach(b => b.classList.remove('active'));
|
||||||
|
btn.classList.add('active');
|
||||||
|
currentRange = btn.dataset.range;
|
||||||
|
loadHistory();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
historyContainerSelect?.addEventListener('change', loadHistory);
|
||||||
|
|
||||||
|
document.querySelector('[data-panel="stats-history"]')?.addEventListener('click', () => {
|
||||||
|
populateHistoryContainerSelect();
|
||||||
|
loadHistory();
|
||||||
|
});
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ===== SERVICE CREDENTIALS =====
|
// ===== SERVICE CREDENTIALS =====
|
||||||
(function() {
|
(function() {
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
injectModal('folder-browser-modal', `<div id="folder-browser-modal" class="weather-modal">
|
injectModal('folder-browser-modal', `<div id="folder-browser-modal" class="weather-modal">
|
||||||
<div class="weather-modal-content" style="min-width: 500px; max-width: 700px; max-height: 80vh;">
|
<div class="weather-modal-content" style="min-width: 500px; max-width: 700px; max-height: 80vh;">
|
||||||
<h3>📂 Browse for Media Folders</h3>
|
<h3>📂 Browse for Media Folders</h3>
|
||||||
@@ -433,7 +434,7 @@
|
|||||||
|
|
||||||
await loadServiceCreds(currentService);
|
await loadServiceCreds(currentService);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to save credentials:', e);
|
errorHandler.logError('[ServiceCredentials] Save', e, { function: 'saveCredentials' });
|
||||||
showError('Failed to save: ' + (e.message || 'Unknown error'));
|
showError('Failed to save: ' + (e.message || 'Unknown error'));
|
||||||
}
|
}
|
||||||
saveBtn.textContent = 'Save';
|
saveBtn.textContent = 'Save';
|
||||||
@@ -460,7 +461,7 @@
|
|||||||
if (btn) btn.classList.remove('has-creds');
|
if (btn) btn.classList.remove('has-creds');
|
||||||
await loadServiceCreds(currentService);
|
await loadServiceCreds(currentService);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to clear credentials:', e);
|
errorHandler.logError('[ServiceCredentials] Clear', e, { function: 'clearCredentials' });
|
||||||
showError('Failed to clear: ' + (e.message || 'Unknown error'));
|
showError('Failed to clear: ' + (e.message || 'Unknown error'));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
// Shared timezone utility — used by setup wizard and settings modal
|
// Shared timezone utility — used by setup wizard and settings modal
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
|
|
||||||
window.populateTimezoneSelect = function(selectEl, selectedTz) {
|
window.populateTimezoneSelect = function(selectEl, selectedTz) {
|
||||||
const timezones = Intl.supportedValuesOf('timeZone');
|
const timezones = Intl.supportedValuesOf('timeZone');
|
||||||
const detected = selectedTz || Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
const detected = selectedTz || Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
||||||
@@ -150,11 +152,11 @@ window.populateTimezoneSelect = function(selectEl, selectedTz) {
|
|||||||
await response.json();
|
await response.json();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
console.error('Failed to save config to server:', response.status);
|
errorHandler.logError('[SetupWizard] Save Config', new Error(`Server returned ${response.status}`), { function: 'saveConfigToServer' });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error saving config to server:', error);
|
errorHandler.logError('[SetupWizard] Save Config', error, { function: 'saveConfigToServer' });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,12 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
|
|
||||||
|
const debug = (...args) => {
|
||||||
|
if (window.DASHCADDY_DEBUG) { console.log(...args); }
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Theme configuration mapping for Driver.js
|
* Theme configuration mapping for Driver.js
|
||||||
* Maps dashboard themes to Driver.js styling
|
* Maps dashboard themes to Driver.js styling
|
||||||
@@ -170,7 +176,7 @@
|
|||||||
attributeFilter: ['class']
|
attributeFilter: ['class']
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log('[ThemeAdapter] Theme change listener initialized');
|
debug('[ThemeAdapter] Theme change listener initialized');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -180,13 +186,13 @@
|
|||||||
* @param {string} oldTheme - Old theme name
|
* @param {string} oldTheme - Old theme name
|
||||||
*/
|
*/
|
||||||
_notifyThemeChange(newTheme, oldTheme) {
|
_notifyThemeChange(newTheme, oldTheme) {
|
||||||
console.log(`[ThemeAdapter] Theme changed: ${oldTheme} → ${newTheme}`);
|
debug(`[ThemeAdapter] Theme changed: ${oldTheme} → ${newTheme}`);
|
||||||
|
|
||||||
this.themeChangeCallbacks.forEach(callback => {
|
this.themeChangeCallbacks.forEach(callback => {
|
||||||
try {
|
try {
|
||||||
callback(newTheme, oldTheme);
|
callback(newTheme, oldTheme);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[ThemeAdapter] Error in theme change callback:', error);
|
errorHandler.logError('[ThemeAdapter] Theme Change Callback', error, { function: '_notifyThemeChange' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -207,7 +213,7 @@
|
|||||||
// Note: Driver.js v1.0+ uses CSS variables, so we inject a style element
|
// Note: Driver.js v1.0+ uses CSS variables, so we inject a style element
|
||||||
this._injectDriverStyles(themeConfig);
|
this._injectDriverStyles(themeConfig);
|
||||||
|
|
||||||
console.log('[ThemeAdapter] Theme applied to driver:', this.currentTheme);
|
debug('[ThemeAdapter] Theme applied to driver:', this.currentTheme);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -302,6 +308,6 @@
|
|||||||
// Export to global scope
|
// Export to global scope
|
||||||
window.ThemeAdapter = ThemeAdapter;
|
window.ThemeAdapter = ThemeAdapter;
|
||||||
|
|
||||||
console.log('[ThemeAdapter] Module loaded');
|
debug('[ThemeAdapter] Module loaded');
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|||||||
@@ -6,6 +6,12 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
|
|
||||||
|
const debug = (...args) => {
|
||||||
|
if (window.DASHCADDY_DEBUG) { console.log(...args); }
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate a tooltip definition
|
* Validate a tooltip definition
|
||||||
* @param {Object} tooltip - The tooltip definition to validate
|
* @param {Object} tooltip - The tooltip definition to validate
|
||||||
@@ -147,7 +153,7 @@
|
|||||||
`${e.tooltip}: ${e.errors.join(', ')}`
|
`${e.tooltip}: ${e.errors.join(', ')}`
|
||||||
).join('\n');
|
).join('\n');
|
||||||
|
|
||||||
console.error('[TooltipDefinitions] Validation errors:', errorMessages);
|
errorHandler.logError('[TooltipDefinitions] Validation', errorMessages, { function: 'validateTooltip' });
|
||||||
throw new TooltipError(`Tooltip validation failed:\n${errorMessages}`);
|
throw new TooltipError(`Tooltip validation failed:\n${errorMessages}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,7 +166,7 @@
|
|||||||
TooltipError
|
TooltipError
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[TooltipDefinitions] Validation module loaded');
|
debug('[TooltipDefinitions] Validation module loaded');
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|
||||||
@@ -489,7 +495,7 @@ function getActiveTooltips() {
|
|||||||
try {
|
try {
|
||||||
return tooltip.condition();
|
return tooltip.condition();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`[TooltipDefinitions] Error evaluating condition for ${tooltip.id}:`, error);
|
errorHandler.logError('[TooltipDefinitions] Condition Eval', error, { function: 'evaluateCondition', tooltipId: tooltip.id });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -534,5 +540,5 @@ window.TooltipDefinitions = {
|
|||||||
getNewFeatureTooltips
|
getNewFeatureTooltips
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log('[TooltipDefinitions] Definitions loaded:', TOOLTIP_DEFINITIONS.length, 'tooltips');
|
debug('[TooltipDefinitions] Definitions loaded:', TOOLTIP_DEFINITIONS.length, 'tooltips');
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ===== TOTP SETTINGS =====
|
// ===== TOTP SETTINGS =====
|
||||||
(function() {
|
(function() {
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
injectModal('totp-settings-modal', `<div id="totp-settings-modal" class="weather-modal">
|
injectModal('totp-settings-modal', `<div id="totp-settings-modal" class="weather-modal">
|
||||||
<div class="weather-modal-content" style="min-width: 420px; max-width: 520px;">
|
<div class="weather-modal-content" style="min-width: 420px; max-width: 520px;">
|
||||||
<h3 style="margin: 0 0 16px; font-size: 1.1rem;">Authentication Settings</h3>
|
<h3 style="margin: 0 0 16px; font-size: 1.1rem;">Authentication Settings</h3>
|
||||||
@@ -185,7 +186,7 @@
|
|||||||
document.getElementById('totp-setup-code').focus();
|
document.getElementById('totp-setup-code').focus();
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('TOTP setup failed:', e);
|
errorHandler.logError('[TOTP] Setup Failed', e, { function: 'setupTOTP' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -274,7 +275,7 @@
|
|||||||
});
|
});
|
||||||
loadTotpSettings(); // Refresh modal + card (handles "never" disabling TOTP)
|
loadTotpSettings(); // Refresh modal + card (handles "never" disabling TOTP)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to update session duration:', err);
|
errorHandler.logError('[TOTP] Update Session Duration', err, { function: 'updateSessionDuration' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -290,7 +291,7 @@
|
|||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.success) loadTotpSettings();
|
if (data.success) loadTotpSettings();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Failed to disable TOTP:', e);
|
errorHandler.logError('[TOTP] Disable Failed', e, { function: 'disableTOTP' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -322,7 +323,7 @@
|
|||||||
const active = data.config.enabled && data.config.isSetUp;
|
const active = data.config.enabled && data.config.isSetUp;
|
||||||
updateAuthCard(active, data.config.sessionDuration);
|
updateAuthCard(active, data.config.sessionDuration);
|
||||||
}
|
}
|
||||||
} catch (e) { console.error('[AuthCard] Failed to update:', e); }
|
} catch (e) { errorHandler.logError('[TOTP] AuthCard Update', e, { function: 'authCardUpdate' }); }
|
||||||
})();
|
})();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
+18
-12
@@ -6,6 +6,12 @@
|
|||||||
(function(window) {
|
(function(window) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
|
|
||||||
|
const debug = (...args) => {
|
||||||
|
if (window.DASHCADDY_DEBUG) { console.log(...args); }
|
||||||
|
};
|
||||||
|
|
||||||
class TourManager {
|
class TourManager {
|
||||||
constructor(progressTracker, themeAdapter, dnsTemplateSelector) {
|
constructor(progressTracker, themeAdapter, dnsTemplateSelector) {
|
||||||
this.progressTracker = progressTracker;
|
this.progressTracker = progressTracker;
|
||||||
@@ -26,7 +32,7 @@
|
|||||||
const driverFactory = window.driver?.js?.driver || window.driver?.driver || window.driver;
|
const driverFactory = window.driver?.js?.driver || window.driver?.driver || window.driver;
|
||||||
|
|
||||||
if (typeof driverFactory !== 'function') {
|
if (typeof driverFactory !== 'function') {
|
||||||
console.error('[TourManager] Driver.js not loaded or invalid. window.driver:', window.driver);
|
errorHandler.logError('[TourManager] Driver.js Not Loaded', new Error('Driver.js not loaded or invalid'), { windowDriver: typeof window.driver });
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +98,7 @@
|
|||||||
const activeTooltips = allTooltips.filter(t => !completedIds.includes(t.id));
|
const activeTooltips = allTooltips.filter(t => !completedIds.includes(t.id));
|
||||||
|
|
||||||
if (activeTooltips.length === 0) {
|
if (activeTooltips.length === 0) {
|
||||||
console.log('[TourManager] No tooltips to show');
|
debug('[TourManager] No tooltips to show');
|
||||||
this.progressTracker.markTourCompleted();
|
this.progressTracker.markTourCompleted();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -131,7 +137,7 @@
|
|||||||
// Add custom handlers for DNS tooltip
|
// Add custom handlers for DNS tooltip
|
||||||
if (tooltip.id === 'dns-priority' && this.dnsTemplateSelector) {
|
if (tooltip.id === 'dns-priority' && this.dnsTemplateSelector) {
|
||||||
step.popover.onSetupNowClick = () => {
|
step.popover.onSetupNowClick = () => {
|
||||||
console.log('[TourManager] Opening DNS template selector');
|
debug('[TourManager] Opening DNS template selector');
|
||||||
this.dnsTemplateSelector.showTemplateSelector();
|
this.dnsTemplateSelector.showTemplateSelector();
|
||||||
// Mark tooltip as completed and move to next
|
// Mark tooltip as completed and move to next
|
||||||
this.progressTracker.markTooltipCompleted(tooltip.id);
|
this.progressTracker.markTooltipCompleted(tooltip.id);
|
||||||
@@ -141,7 +147,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
step.popover.onLaterClick = () => {
|
step.popover.onLaterClick = () => {
|
||||||
console.log('[TourManager] DNS setup deferred');
|
debug('[TourManager] DNS setup deferred');
|
||||||
this.progressTracker.markDnsSetupDeferred();
|
this.progressTracker.markDnsSetupDeferred();
|
||||||
// Mark tooltip as completed and move to next
|
// Mark tooltip as completed and move to next
|
||||||
this.progressTracker.markTooltipCompleted(tooltip.id);
|
this.progressTracker.markTooltipCompleted(tooltip.id);
|
||||||
@@ -198,7 +204,7 @@
|
|||||||
async showTooltip(tooltipId) {
|
async showTooltip(tooltipId) {
|
||||||
const tooltip = window.TooltipDefinitions.getTooltipById(tooltipId);
|
const tooltip = window.TooltipDefinitions.getTooltipById(tooltipId);
|
||||||
if (!tooltip) {
|
if (!tooltip) {
|
||||||
console.error(`[TourManager] Tooltip not found: ${tooltipId}`);
|
errorHandler.logError('[TourManager] Tooltip Not Found', new Error(`Tooltip not found: ${tooltipId}`), { tooltipId });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,11 +238,11 @@
|
|||||||
const newFeatureTooltips = window.TooltipDefinitions.getNewFeatureTooltips();
|
const newFeatureTooltips = window.TooltipDefinitions.getNewFeatureTooltips();
|
||||||
|
|
||||||
if (newFeatureTooltips.length === 0) {
|
if (newFeatureTooltips.length === 0) {
|
||||||
console.log('[TourManager] No new features to show');
|
debug('[TourManager] No new features to show');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`[TourManager] Showing ${newFeatureTooltips.length} new features`);
|
debug(`[TourManager] Showing ${newFeatureTooltips.length} new features`);
|
||||||
|
|
||||||
// Convert to Driver.js steps
|
// Convert to Driver.js steps
|
||||||
const steps = newFeatureTooltips.map((tooltip, index) => {
|
const steps = newFeatureTooltips.map((tooltip, index) => {
|
||||||
@@ -280,7 +286,7 @@
|
|||||||
clearTimeout(resizeTimeout);
|
clearTimeout(resizeTimeout);
|
||||||
resizeTimeout = setTimeout(() => {
|
resizeTimeout = setTimeout(() => {
|
||||||
if (this.isActive && this.driver) {
|
if (this.isActive && this.driver) {
|
||||||
console.log('[TourManager] Window resized, repositioning tooltip');
|
debug('[TourManager] Window resized, repositioning tooltip');
|
||||||
this.driver.refresh();
|
this.driver.refresh();
|
||||||
}
|
}
|
||||||
}, 150); // Debounce for 150ms
|
}, 150); // Debounce for 150ms
|
||||||
@@ -289,7 +295,7 @@
|
|||||||
// Layout change handler (for theme changes, DOM mutations)
|
// Layout change handler (for theme changes, DOM mutations)
|
||||||
this.layoutChangeHandler = () => {
|
this.layoutChangeHandler = () => {
|
||||||
if (this.isActive && this.driver) {
|
if (this.isActive && this.driver) {
|
||||||
console.log('[TourManager] Layout changed, repositioning tooltip');
|
debug('[TourManager] Layout changed, repositioning tooltip');
|
||||||
// Small delay to allow layout to settle
|
// Small delay to allow layout to settle
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.driver) {
|
if (this.driver) {
|
||||||
@@ -347,7 +353,7 @@
|
|||||||
onTourComplete() {
|
onTourComplete() {
|
||||||
this.progressTracker.markTourCompleted();
|
this.progressTracker.markTourCompleted();
|
||||||
this.isActive = false;
|
this.isActive = false;
|
||||||
console.log('[TourManager] Tour completed');
|
debug('[TourManager] Tour completed');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -355,12 +361,12 @@
|
|||||||
*/
|
*/
|
||||||
onTourSkip() {
|
onTourSkip() {
|
||||||
// Save current progress but don't mark as completed
|
// Save current progress but don't mark as completed
|
||||||
console.log('[TourManager] Tour skipped');
|
debug('[TourManager] Tour skipped');
|
||||||
this.isActive = false;
|
this.isActive = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
window.TourManager = TourManager;
|
window.TourManager = TourManager;
|
||||||
console.log('[TourManager] Module loaded');
|
debug('[TourManager] Module loaded');
|
||||||
|
|
||||||
})(window);
|
})(window);
|
||||||
|
|||||||
@@ -335,7 +335,8 @@
|
|||||||
const res = await fetch('/api/v1/system/version');
|
const res = await fetch('/api/v1/system/version');
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
dcVersionInfo.textContent = 'v' + data.version + (data.commit ? ' (' + data.commit.substring(0, 7) + ')' : '');
|
const commit = data.commit && data.commit !== 'unknown' ? data.commit : null;
|
||||||
|
dcVersionInfo.textContent = 'v' + data.version + (commit ? ' (' + commit.substring(0, 7) + ')' : '');
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
dcVersionInfo.textContent = 'Unable to fetch version';
|
dcVersionInfo.textContent = 'Unable to fetch version';
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// ========== WEATHER WIDGET ==========
|
// ========== WEATHER WIDGET ==========
|
||||||
(function() {
|
(function() {
|
||||||
|
const errorHandler = new ErrorHandler();
|
||||||
// Inject modal HTML
|
// Inject modal HTML
|
||||||
injectModal('weather-modal', `<div id="weather-modal" class="weather-modal"><div class="weather-modal-content"><h3>Weather Settings</h3>
|
injectModal('weather-modal', `<div id="weather-modal" class="weather-modal"><div class="weather-modal-content"><h3>Weather Settings</h3>
|
||||||
<label for="weather-location-input">Location:</label>
|
<label for="weather-location-input">Location:</label>
|
||||||
@@ -166,7 +167,7 @@
|
|||||||
weatherWidget.icon.innerHTML = `<span class="weather-emoji">${escapeHtml(weather.icon)}</span>`;
|
weatherWidget.icon.innerHTML = `<span class="weather-emoji">${escapeHtml(weather.icon)}</span>`;
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Weather update error:', error);
|
errorHandler.logError('[Weather] Update Error', error, { function: 'updateWeather' });
|
||||||
weatherWidget.location.textContent = 'Weather Error';
|
weatherWidget.location.textContent = 'Weather Error';
|
||||||
weatherWidget.temp.textContent = 'Error';
|
weatherWidget.temp.textContent = 'Error';
|
||||||
weatherWidget.condition.textContent = 'Failed to load';
|
weatherWidget.condition.textContent = 'Failed to load';
|
||||||
|
|||||||
Reference in New Issue
Block a user