Merge remote-tracking branch 'contabo/dc/DC-168-calendar-widget' into dc167-deploy2
This commit is contained in:
51 files changed
+3544
-1040
No files matched your search
@@ -142,8 +142,21 @@ module.exports = function createCalendarRoutes({
|
||||
if (req.body.user !== undefined) updates.user = req.body.user || null;
|
||||
if (updates.name !== undefined) updates.name = String(updates.name).slice(0, 120);
|
||||
if (req.body.pass !== undefined || req.body.token !== undefined) {
|
||||
// DC-170: preserve the credential TYPE not being updated — the old write
|
||||
// stored {pass: body.pass ?? null, token: body.token ?? null}, so
|
||||
// updating pass on a token-authenticated source (or vice versa) nulled
|
||||
// the other field and broke the source's stored credential.
|
||||
let existingCreds = {};
|
||||
try {
|
||||
const raw = await credentialManager.retrieve(`calendar:source:${existing.id}`);
|
||||
if (raw) existingCreds = JSON.parse(raw);
|
||||
} catch (_) { /* start from empty */ }
|
||||
const next = {
|
||||
pass: req.body.pass !== undefined ? req.body.pass : (existingCreds.pass ?? null),
|
||||
token: req.body.token !== undefined ? req.body.token : (existingCreds.token ?? null),
|
||||
};
|
||||
await credentialManager.store(`calendar:source:${existing.id}`,
|
||||
JSON.stringify({ pass: req.body.pass ?? null, token: req.body.token ?? null }),
|
||||
JSON.stringify(next),
|
||||
{ label: `Calendar source ${existing.name}`, updatedAt: new Date().toISOString() });
|
||||
}
|
||||
await calendarStateManager.updateItem(existing.id, updates);
|
||||
@@ -174,7 +187,9 @@ module.exports = function createCalendarRoutes({
|
||||
|
||||
const results = await Promise.allSettled(wanted.map(async (source) => {
|
||||
if (source.type === 'ics') {
|
||||
const resp = await fetchT(source.url, { timeout: 15000 });
|
||||
// DC-170: fetchT ignores opts.timeout (undici) — the 15s intent ran at
|
||||
// the 5s HTTP_DEFAULT. Pass it as the third arg (timeoutMs).
|
||||
const resp = await fetchT(source.url, {}, 15000);
|
||||
if (!resp.ok) throw new Error(`ICS fetch HTTP ${resp.status}`);
|
||||
// Bounded read (judge r3 blocker): same 5 MiB cap as the CalDAV path —
|
||||
// a misbehaving feed must not balloon API memory.
|
||||
|
||||
@@ -28,7 +28,15 @@ module.exports = function({ configStateManager: _configStateManager, asyncHandle
|
||||
return res.json({ setupComplete: false });
|
||||
}
|
||||
const data = await fsp.readFile(ctx.CONFIG_FILE, 'utf8');
|
||||
const config = JSON.parse(data);
|
||||
let config;
|
||||
try {
|
||||
config = JSON.parse(data);
|
||||
} catch (_) {
|
||||
// DC-170: a corrupt/partial config.json (e.g. non-atomic write crash)
|
||||
// previously 500'd this PUBLIC endpoint on every dashboard load.
|
||||
// Degrade to the setup wizard instead of an error page.
|
||||
return res.json({ setupComplete: false, corrupt: true });
|
||||
}
|
||||
res.json(config);
|
||||
}, 'config-get'));
|
||||
|
||||
|
||||
@@ -71,6 +71,21 @@ module.exports = function({ docker, log, asyncHandler, workflowEngine }) {
|
||||
return container;
|
||||
}
|
||||
|
||||
// GET / — list containers (DC-170, audit P0-5: the router previously had NO
|
||||
// list route, so the MCP dashcaddy_list_containers tool 404'd unconditionally)
|
||||
router.get('/', asyncHandler(async (req, res) => {
|
||||
const all = req.query.all !== 'false';
|
||||
const containers = await docker.client.listContainers({ all });
|
||||
success(res, {
|
||||
count: containers.length,
|
||||
containers: containers.map((c) => ({
|
||||
id: c.Id, name: (c.Names && c.Names[0] ? c.Names[0].replace(/^\//, '') : c.Id.slice(0, 12)),
|
||||
image: c.Image, state: c.State, status: c.Status,
|
||||
created: c.Created, ports: c.Ports,
|
||||
})),
|
||||
});
|
||||
}, 'containers-list'));
|
||||
|
||||
// Start container
|
||||
router.post('/:id/start', asyncHandler(async (req, res) => {
|
||||
const container = await getVerifiedContainer(req.params.id);
|
||||
|
||||
@@ -65,6 +65,21 @@ module.exports = function({
|
||||
}
|
||||
}, 'dns-provider-status'));
|
||||
|
||||
// GET /records — list DNS records via the active provider (DC-170, audit
|
||||
// P0-5: the MCP dashcaddy_list_dns tool called GET /dns, which never existed)
|
||||
// NOTE: this file's errorResponse is responses.js `error(res, message, code)`
|
||||
// (message FIRST) — the reversed-arg audit finding does not apply here.
|
||||
router.get('/records', asyncHandler(async (req, res) => {
|
||||
const zone = req.query.zone || (siteConfig.tld ? String(siteConfig.tld).replace(/^\./, '') : '');
|
||||
const provider = dns.getActiveProvider ? dns.getActiveProvider() : null;
|
||||
if (!provider || (provider.supportsCapability && !provider.supportsCapability('list-records'))) {
|
||||
return errorResponse(res, 'Record listing not supported by current DNS provider', 501);
|
||||
}
|
||||
const result = await provider.listRecords({ zone });
|
||||
const records = Array.isArray(result) ? result : (result && result.records) || [];
|
||||
success(res, { zone, count: records.length, records });
|
||||
}, 'dns-records-list'));
|
||||
|
||||
// ===== UNIVERSAL RECORD ENDPOINTS (work with any provider) =====
|
||||
|
||||
// POST /universal/record — Create a DNS record via any provider
|
||||
@@ -703,11 +718,17 @@ module.exports = function({
|
||||
|
||||
const text = await response.text();
|
||||
|
||||
// DC-170: every path must answer — bare returns left requests hanging
|
||||
if (!text || text.trim() === '') {
|
||||
return // Error handled by middleware
|
||||
return errorResponse(res, 'Empty response from DNS server update check', 502);
|
||||
}
|
||||
|
||||
const result = JSON.parse(text);
|
||||
let result;
|
||||
try {
|
||||
result = JSON.parse(text);
|
||||
} catch (_) {
|
||||
return errorResponse(res, 'DNS server returned a non-JSON update response', 502);
|
||||
}
|
||||
|
||||
if (result.status === 'ok') {
|
||||
success(res, {
|
||||
@@ -720,11 +741,11 @@ module.exports = function({
|
||||
instructionsLink: result.response.instructionsLink || null
|
||||
});
|
||||
} else {
|
||||
// Error handled by middleware
|
||||
return errorResponse(res, `DNS server update check failed: ${result.message || result.status}`, 502);
|
||||
}
|
||||
} catch (error) {
|
||||
log.error('dns', error, null, { note: 'DNS update check error' });
|
||||
// Error handled by middleware
|
||||
return errorResponse(res, safeErrorMessage(error), error.statusCode || 502);
|
||||
}
|
||||
}, 'dns-check-update'));
|
||||
|
||||
@@ -761,12 +782,17 @@ module.exports = function({
|
||||
|
||||
const checkText = await checkResponse.text();
|
||||
if (!checkText || checkText.trim() === '') {
|
||||
return // Error handled by middleware
|
||||
return errorResponse(res, 'Empty response from DNS server update check', 502);
|
||||
}
|
||||
let checkResult;
|
||||
try {
|
||||
checkResult = JSON.parse(checkText);
|
||||
} catch (_) {
|
||||
return errorResponse(res, 'DNS server returned a non-JSON update response', 502);
|
||||
}
|
||||
const checkResult = JSON.parse(checkText);
|
||||
|
||||
if (checkResult.status !== 'ok') {
|
||||
return // Error handled by middleware
|
||||
return errorResponse(res, `DNS server update check failed: ${checkResult.message || checkResult.status}`, 502);
|
||||
}
|
||||
|
||||
if (!checkResult.response.updateAvailable) {
|
||||
@@ -792,7 +818,7 @@ module.exports = function({
|
||||
});
|
||||
} catch (error) {
|
||||
log.error('dns', error, null, { note: 'DNS update error' });
|
||||
// Error handled by middleware
|
||||
return errorResponse(res, safeErrorMessage(error), error.statusCode || 502);
|
||||
}
|
||||
}, 'dns-update'));
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const express = require('express');
|
||||
const { ok } = require('../src/utils/responses');
|
||||
// NOTE: the success helper is injected via the factory's deps (deps.ok) — a
|
||||
// top-level import here would be silently shadowed by the destructured param.
|
||||
const { ValidationError } = require('../src/utilities/errors');
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user