Enables the CCP to manage CML instances on remote servers via a lightweight HTTP agent. Key components: - ExecutionDriver abstraction (local-driver.ts / remote-driver.ts) routes operations to local Docker or remote agent transparently - Remote agent package (agent/) with mTLS authentication, Docker Compose operations, file management, backup/upgrade delegation - Certificate service using openssl CLI for CA management and cert issuance - Phone-home registration: remote agents register via invite code, CCP admin approves, agent receives mTLS cert bundle automatically - config.sh integration with configure_control_panel() section - ccp-agent Docker Compose service (profile-gated) - Frontend: AgentRegistrationsPage, InviteCodesPage, Remote Agents sidebar menu - Security hardened: cert bundle wiped after delivery, shell injection prevention via execFile, command allowlist with metachar rejection, rate-limited public endpoints, auto-populated fingerprint pinning Also wires ENABLE_SOCIAL/PEOPLE/ANALYTICS through env.ts, seed.ts, and docker-compose env passthrough (from previous session). Bunker Admin
52 lines
1.9 KiB
TypeScript
52 lines
1.9 KiB
TypeScript
import { Router, Request, Response } from 'express';
|
|
import { getSlugEntry } from '../services/registry.service';
|
|
import { param } from '../utils/params';
|
|
import * as fileService from '../services/file.service';
|
|
|
|
const router = Router();
|
|
|
|
// GET /instance/:slug/env — Read .env as key/value map
|
|
router.get('/instance/:slug/env', async (req: Request, res: Response) => {
|
|
const entry = await getSlugEntry(param(req, 'slug'));
|
|
const envVars = await fileService.readEnvFile(entry.basePath);
|
|
res.json(envVars);
|
|
});
|
|
|
|
// POST /instance/:slug/files — Write rendered template files
|
|
router.post('/instance/:slug/files', async (req: Request, res: Response) => {
|
|
const entry = await getSlugEntry(param(req, 'slug'));
|
|
const { files } = req.body;
|
|
if (!Array.isArray(files)) {
|
|
res.status(400).json({ error: 'VALIDATION', message: 'files array required' });
|
|
return;
|
|
}
|
|
await fileService.writeFiles(entry.basePath, files);
|
|
res.json({ written: files.length });
|
|
});
|
|
|
|
// POST /instance/:slug/mkdir — Create directory
|
|
router.post('/instance/:slug/mkdir', async (req: Request, res: Response) => {
|
|
const entry = await getSlugEntry(param(req, 'slug'));
|
|
const { path: dirPath } = req.body;
|
|
if (!dirPath) {
|
|
res.status(400).json({ error: 'VALIDATION', message: 'path required' });
|
|
return;
|
|
}
|
|
await fileService.mkdirp(entry.basePath, dirPath);
|
|
res.json({ created: dirPath });
|
|
});
|
|
|
|
// POST /instance/:slug/clone-source — Git clone CML source
|
|
router.post('/instance/:slug/clone-source', async (req: Request, res: Response) => {
|
|
const entry = await getSlugEntry(param(req, 'slug'));
|
|
const { gitRepo, gitBranch, excludes } = req.body;
|
|
if (!gitRepo || !gitBranch) {
|
|
res.status(400).json({ error: 'VALIDATION', message: 'gitRepo and gitBranch required' });
|
|
return;
|
|
}
|
|
await fileService.cloneSource(entry.basePath, gitRepo, gitBranch, excludes);
|
|
res.json({ cloned: true });
|
|
});
|
|
|
|
export default router;
|