easy-devops 1.1.0 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +2 -2
  2. package/package.json +6 -3
  3. package/src/cli/index.js +13 -1
  4. package/src/cli/menus/dashboard.js +1 -1
  5. package/src/core/channels/discord.js +77 -0
  6. package/src/core/channels/telegram.js +120 -0
  7. package/src/core/db.js +8 -1
  8. package/src/core/domainNotifier.js +298 -0
  9. package/src/core/events.js +130 -0
  10. package/src/core/notifier.js +73 -0
  11. package/src/core/shell.js +59 -7
  12. package/src/dashboard/controllers/authController.js +29 -0
  13. package/src/dashboard/controllers/domainsController.js +416 -0
  14. package/src/dashboard/controllers/nginxController.js +128 -0
  15. package/src/dashboard/controllers/settingsController.js +335 -0
  16. package/src/dashboard/controllers/sslController.js +291 -0
  17. package/src/dashboard/public/img/icon.png +0 -0
  18. package/src/dashboard/public/img/icon_b.png +0 -0
  19. package/src/dashboard/public/js/app.js +234 -2
  20. package/src/dashboard/routes/auth.js +12 -22
  21. package/src/dashboard/routes/domains.js +11 -363
  22. package/src/dashboard/routes/nginx.js +13 -146
  23. package/src/dashboard/routes/settings.js +16 -189
  24. package/src/dashboard/routes/ssl.js +9 -276
  25. package/src/dashboard/server.js +24 -27
  26. package/src/dashboard/socketManager.js +282 -0
  27. package/src/dashboard/views/index.ejs +52 -0
  28. package/src/dashboard/views/partials/domain-form.ejs +64 -1
  29. package/src/dashboard/views/partials/domains-panel.ejs +4 -0
  30. package/src/dashboard/views/partials/login.ejs +1 -1
  31. package/src/dashboard/views/partials/logs-panel.ejs +67 -0
  32. package/src/dashboard/views/partials/settings-panel.ejs +263 -87
  33. package/src/dashboard/views/partials/sidebar.ejs +3 -1
  34. /package/src/{dashboard/routes → core/channels}/.gitkeep +0 -0
@@ -0,0 +1,335 @@
1
+ import fs from 'fs/promises';
2
+ import path from 'path';
3
+ import os from 'os';
4
+ import crypto from 'crypto';
5
+ import { loadConfig, saveConfig } from '../../core/config.js';
6
+ import { validatePort, validateEmail } from '../../core/validators.js';
7
+ import { run, runWithStdin } from '../../core/shell.js';
8
+ import { checkPermissionsConfigured } from '../../core/permissions.js';
9
+ import { dbGet, dbSet } from '../../core/db.js';
10
+ import { loadChannels, saveChannels, sendNotification } from '../../core/notifier.js';
11
+
12
+ class SettingsController {
13
+ get(req, res) {
14
+ try {
15
+ const config = loadConfig();
16
+ const { dashboardPort, nginxDir, sslDir, acmeEmail } = config;
17
+ res.json({
18
+ dashboardPort,
19
+ nginxDir,
20
+ sslDir,
21
+ acmeEmail,
22
+ platform: process.platform === 'win32' ? 'win32' : 'linux',
23
+ });
24
+ } catch (err) {
25
+ res.status(500).json({ error: 'Internal server error' });
26
+ }
27
+ }
28
+
29
+ update(req, res) {
30
+ try {
31
+ const { dashboardPort, dashboardPassword, nginxDir, sslDir, acmeEmail } = req.body;
32
+
33
+ if (dashboardPort !== undefined) {
34
+ const portError = validatePort(parseInt(dashboardPort, 10));
35
+ if (portError) return res.status(400).json({ error: portError });
36
+ }
37
+
38
+ if (dashboardPassword !== undefined && typeof dashboardPassword !== 'string') {
39
+ return res.status(400).json({ error: 'Password must be a string' });
40
+ }
41
+
42
+ if (nginxDir !== undefined && (typeof nginxDir !== 'string' || nginxDir.trim() === '')) {
43
+ return res.status(400).json({ error: 'Nginx directory must be a non-empty string' });
44
+ }
45
+ if (sslDir !== undefined && (typeof sslDir !== 'string' || sslDir.trim() === '')) {
46
+ return res.status(400).json({ error: 'SSL directory must be a non-empty string' });
47
+ }
48
+
49
+ if (acmeEmail !== undefined) {
50
+ const emailError = validateEmail(acmeEmail);
51
+ if (emailError) return res.status(400).json({ error: emailError });
52
+ }
53
+
54
+ const currentConfig = loadConfig();
55
+ const updates = {};
56
+
57
+ if (dashboardPort !== undefined) updates.dashboardPort = parseInt(dashboardPort, 10);
58
+ if (dashboardPassword !== undefined) updates.dashboardPassword = dashboardPassword;
59
+ if (nginxDir !== undefined) updates.nginxDir = nginxDir.trim();
60
+ if (sslDir !== undefined) updates.sslDir = sslDir.trim();
61
+ if (acmeEmail !== undefined) updates.acmeEmail = acmeEmail.trim();
62
+
63
+ saveConfig({ ...currentConfig, ...updates });
64
+ res.json({ success: true });
65
+ } catch (err) {
66
+ res.status(500).json({ error: 'Internal server error' });
67
+ }
68
+ }
69
+
70
+ async getPermissions(req, res) {
71
+ if (process.platform === 'win32') return res.json({ configured: true });
72
+ try {
73
+ const configured = await checkPermissionsConfigured();
74
+ res.json({ configured });
75
+ } catch {
76
+ res.json({ configured: false });
77
+ }
78
+ }
79
+
80
+ async setupPermissions(req, res) {
81
+ if (process.platform === 'win32') {
82
+ return res.status(400).json({ error: 'Not applicable on Windows' });
83
+ }
84
+
85
+ const { password } = req.body ?? {};
86
+ if (!password || typeof password !== 'string') {
87
+ return res.status(400).json({ error: 'Password is required' });
88
+ }
89
+
90
+ const whichResult = await run('which nginx');
91
+ if (!whichResult.success || !whichResult.stdout.trim()) {
92
+ return res.status(500).json({ error: 'nginx not found. Is nginx installed?' });
93
+ }
94
+ const nginxPath = whichResult.stdout.trim().split('\n')[0].trim();
95
+ const user = os.userInfo().username;
96
+
97
+ const sudoRules = [
98
+ '/usr/bin/systemctl start nginx',
99
+ '/usr/bin/systemctl stop nginx',
100
+ '/usr/bin/systemctl reload nginx',
101
+ '/usr/bin/systemctl restart nginx',
102
+ '/usr/bin/systemctl',
103
+ nginxPath,
104
+ `${nginxPath} -t`,
105
+ `${nginxPath} -s reload`,
106
+ `${nginxPath} -s stop`,
107
+ `${nginxPath} -s quit`,
108
+ '/usr/bin/certbot',
109
+ '/usr/bin/mkdir',
110
+ '/usr/bin/cp',
111
+ '/usr/bin/chmod',
112
+ '/usr/bin/chown',
113
+ '/usr/bin/tee',
114
+ ].join(', ');
115
+
116
+ const sudoersContent = `${user} ALL=(ALL) NOPASSWD: ${sudoRules}\n`;
117
+
118
+ const tmpFile = path.join('/tmp', `easy-devops-sudoers-${Date.now()}`);
119
+ try {
120
+ await fs.writeFile(tmpFile, sudoersContent, { mode: 0o600 });
121
+ } catch (err) {
122
+ return res.status(500).json({ error: 'Failed to write temp file', output: err.message });
123
+ }
124
+
125
+ const setupCmd = [
126
+ `mkdir -p /etc/easy-devops /var/log/easy-devops`,
127
+ `chown ${user}:${user} /etc/easy-devops /var/log/easy-devops`,
128
+ `chown -R ${user}:${user} /etc/nginx/conf.d 2>/dev/null || true`,
129
+ `cp '${tmpFile}' /etc/sudoers.d/easy-devops`,
130
+ `chmod 440 /etc/sudoers.d/easy-devops`,
131
+ ].join(' && ');
132
+
133
+ const result = await runWithStdin('sudo', ['-S', 'bash', '-c', setupCmd], password + '\n');
134
+ await fs.unlink(tmpFile).catch(() => {});
135
+
136
+ if (!result.success) {
137
+ const output = result.stderr || result.stdout;
138
+ const wrongPassword = output.includes('incorrect password') || output.includes('Sorry, try again') || output.includes('3 incorrect');
139
+ return res.status(wrongPassword ? 401 : 500).json({
140
+ error: wrongPassword ? 'Incorrect password' : 'Setup failed',
141
+ output,
142
+ });
143
+ }
144
+
145
+ res.json({ success: true });
146
+ }
147
+
148
+ backup(req, res) {
149
+ try {
150
+ const config = loadConfig();
151
+ const domains = dbGet('domains') || [];
152
+ const { dashboardPassword: _pw, ...safeConfig } = config;
153
+ const backup = {
154
+ version: 1,
155
+ exportedAt: new Date().toISOString(),
156
+ config: safeConfig,
157
+ domains,
158
+ };
159
+ res.setHeader('Content-Disposition', `attachment; filename="easy-devops-backup-${Date.now()}.json"`);
160
+ res.setHeader('Content-Type', 'application/json');
161
+ res.json(backup);
162
+ } catch (err) {
163
+ res.status(500).json({ error: 'Export failed' });
164
+ }
165
+ }
166
+
167
+ restore(req, res) {
168
+ try {
169
+ const { config, domains } = req.body ?? {};
170
+ if (!config || typeof config !== 'object') {
171
+ return res.status(400).json({ error: 'Invalid backup: missing config' });
172
+ }
173
+ const current = loadConfig();
174
+ const merged = { ...current, ...config, dashboardPassword: current.dashboardPassword };
175
+ saveConfig(merged);
176
+ if (Array.isArray(domains)) {
177
+ dbSet('domains', domains);
178
+ }
179
+ res.json({ success: true });
180
+ } catch (err) {
181
+ res.status(500).json({ error: 'Restore failed' });
182
+ }
183
+ }
184
+
185
+ // ── Notification Channel CRUD ─────────────────────────────────────────────
186
+
187
+ /**
188
+ * GET /api/settings/channels
189
+ * Returns the full channel list.
190
+ */
191
+ getChannels(req, res) {
192
+ try {
193
+ res.json(loadChannels());
194
+ } catch (err) {
195
+ res.status(500).json({ error: 'Internal server error' });
196
+ }
197
+ }
198
+
199
+ /**
200
+ * POST /api/settings/channels
201
+ * Creates a new named channel.
202
+ */
203
+ createChannel(req, res) {
204
+ try {
205
+ const { name, type, webhookUrl, botToken, chatId, message } = req.body ?? {};
206
+
207
+ if (!name || typeof name !== 'string' || !name.trim()) {
208
+ return res.status(400).json({ error: 'Channel name is required' });
209
+ }
210
+ if (!['discord', 'telegram'].includes(type)) {
211
+ return res.status(400).json({ error: 'Channel type must be discord or telegram' });
212
+ }
213
+ if (type === 'discord' && (!webhookUrl || !webhookUrl.trim())) {
214
+ return res.status(400).json({ error: 'Discord channels require a webhookUrl' });
215
+ }
216
+ if (type === 'telegram') {
217
+ if (!botToken || !botToken.trim()) {
218
+ return res.status(400).json({ error: 'Telegram channels require a botToken' });
219
+ }
220
+ if (!chatId || !chatId.trim()) {
221
+ return res.status(400).json({ error: 'Telegram channels require a chatId' });
222
+ }
223
+ }
224
+
225
+ const channel = {
226
+ id: crypto.randomUUID(),
227
+ name: name.trim(),
228
+ type,
229
+ ...(type === 'discord' ? { webhookUrl: webhookUrl.trim() } : {}),
230
+ ...(type === 'telegram' ? { botToken: botToken.trim(), chatId: chatId.trim() } : {}),
231
+ ...(message && message.trim() ? { message: message.trim() } : {}),
232
+ };
233
+
234
+ const channels = loadChannels();
235
+ channels.push(channel);
236
+ saveChannels(channels);
237
+
238
+ res.status(201).json(channel);
239
+ } catch (err) {
240
+ res.status(500).json({ error: 'Internal server error' });
241
+ }
242
+ }
243
+
244
+ /**
245
+ * PUT /api/settings/channels/:id
246
+ * Updates name and/or credentials for an existing channel.
247
+ * Type is immutable after creation.
248
+ */
249
+ updateChannel(req, res) {
250
+ try {
251
+ const { id } = req.params;
252
+ const channels = loadChannels();
253
+ const idx = channels.findIndex((ch) => ch.id === id);
254
+ if (idx === -1) return res.status(404).json({ error: 'Channel not found' });
255
+
256
+ const existing = channels[idx];
257
+ const { name, webhookUrl, botToken, chatId, message } = req.body ?? {};
258
+
259
+ const updated = { ...existing };
260
+ if (name !== undefined) {
261
+ if (!name.trim()) return res.status(400).json({ error: 'Channel name cannot be empty' });
262
+ updated.name = name.trim();
263
+ }
264
+ if (existing.type === 'discord' && webhookUrl !== undefined) {
265
+ updated.webhookUrl = webhookUrl.trim();
266
+ }
267
+ if (existing.type === 'telegram') {
268
+ if (botToken !== undefined) updated.botToken = botToken.trim();
269
+ if (chatId !== undefined) updated.chatId = chatId.trim();
270
+ }
271
+
272
+ // Handle message field - allow clearing by setting to empty string
273
+ if (message !== undefined) {
274
+ if (message && message.trim()) {
275
+ updated.message = message.trim();
276
+ } else {
277
+ delete updated.message;
278
+ }
279
+ }
280
+
281
+ channels[idx] = updated;
282
+ saveChannels(channels);
283
+ res.json(updated);
284
+ } catch (err) {
285
+ res.status(500).json({ error: 'Internal server error' });
286
+ }
287
+ }
288
+
289
+ /**
290
+ * DELETE /api/settings/channels/:id
291
+ */
292
+ deleteChannel(req, res) {
293
+ try {
294
+ const { id } = req.params;
295
+ const channels = loadChannels();
296
+ const idx = channels.findIndex((ch) => ch.id === id);
297
+ if (idx === -1) return res.status(404).json({ error: 'Channel not found' });
298
+
299
+ channels.splice(idx, 1);
300
+ saveChannels(channels);
301
+ res.json({ deleted: id });
302
+ } catch (err) {
303
+ res.status(500).json({ error: 'Internal server error' });
304
+ }
305
+ }
306
+
307
+ /**
308
+ * POST /api/settings/channels/:id/test
309
+ * Sends a test notification to a single channel.
310
+ */
311
+ async testChannel(req, res) {
312
+ try {
313
+ const { id } = req.params;
314
+ const channels = loadChannels();
315
+ if (!channels.find((ch) => ch.id === id)) {
316
+ return res.status(404).json({ error: 'Channel not found' });
317
+ }
318
+
319
+ await sendNotification(
320
+ {
321
+ type: 'test',
322
+ message: 'Test notification from Easy DevOps. This channel is working correctly.',
323
+ timestamp: new Date().toISOString(),
324
+ },
325
+ [id]
326
+ );
327
+
328
+ res.json({ success: true });
329
+ } catch (err) {
330
+ res.status(500).json({ error: err.message || 'Failed to send test notification' });
331
+ }
332
+ }
333
+ }
334
+
335
+ export default SettingsController;
@@ -0,0 +1,291 @@
1
+ import { listAllCerts } from '../lib/cert-reader.js';
2
+ import { issueCert, renewCert } from '../../cli/managers/ssl-manager.js';
3
+ import { loadConfig } from '../../core/config.js';
4
+ import { promises as dns } from 'dns';
5
+
6
+ // In-memory DNS challenge state
7
+ // Keyed by domain name. Entries are cleaned up when the ACME process exits
8
+ // or when cancelled. Entries older than 10 minutes are forcibly removed.
9
+ const pendingDnsChallenges = new Map();
10
+
11
+ setInterval(() => {
12
+ const now = Date.now();
13
+ for (const [domain, state] of pendingDnsChallenges) {
14
+ if (now - state.createdAt > 10 * 60 * 1000) {
15
+ state.confirmDeferred.reject(new Error('DNS challenge timed out after 10 minutes'));
16
+ pendingDnsChallenges.delete(domain);
17
+ }
18
+ }
19
+ }, 60000);
20
+
21
+ class SslController {
22
+ async create(req, res, next) {
23
+ try {
24
+ const { domain, www = false, validationMethod = 'http', email = null } = req.body ?? {};
25
+
26
+ if (!domain || typeof domain !== 'string' || !domain.trim()) {
27
+ return res.status(400).json({ error: 'domain is required' });
28
+ }
29
+
30
+ const domainKey = domain.trim();
31
+ const config = loadConfig();
32
+ const acmeEmail = email || config.acmeEmail;
33
+
34
+ if (validationMethod === 'dns') {
35
+ // Two-phase flow: spawn ACME process, wait for TXT record, respond 202, pause until confirm.
36
+ let confirmResolve, confirmReject;
37
+ const confirmPromise = new Promise((resolve, reject) => {
38
+ confirmResolve = resolve;
39
+ confirmReject = reject;
40
+ });
41
+
42
+ let resultResolve;
43
+ const resultPromise = new Promise((resolve) => { resultResolve = resolve; });
44
+
45
+ // Track whether a response has already been sent (202 from onDnsChallenge)
46
+ let responseSent = false;
47
+
48
+ const onDnsChallenge = async (txtName, txtValue) => {
49
+ responseSent = true;
50
+ pendingDnsChallenges.set(domainKey, {
51
+ domain: domainKey,
52
+ txtName,
53
+ txtValue,
54
+ confirmDeferred: { resolve: confirmResolve, reject: confirmReject },
55
+ resultPromise,
56
+ createdAt: Date.now(),
57
+ });
58
+
59
+ res.status(202).json({
60
+ status: 'waiting_dns',
61
+ domain: domainKey,
62
+ txtName,
63
+ txtValue,
64
+ hint: 'Add a DNS TXT record with the name and value above, then call POST /api/ssl/create-confirm',
65
+ });
66
+
67
+ // Pause until user calls /create-confirm (resolves) or /create-cancel (rejects)
68
+ await confirmPromise;
69
+ };
70
+
71
+ // Run issueCert in the background — it will call onDnsChallenge which sends 202 and pauses.
72
+ issueCert(domainKey, { www: !!www, validationMethod: 'dns', email: acmeEmail, onDnsChallenge })
73
+ .then(result => {
74
+ resultResolve(result);
75
+ pendingDnsChallenges.delete(domainKey);
76
+ if (!responseSent) {
77
+ responseSent = true;
78
+ if (result.success) {
79
+ return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
80
+ }
81
+ const { step } = result.error ?? {};
82
+ if (step === 'email configuration') {
83
+ return res.status(400).json({ error: 'email_required', hint: 'Configure acmeEmail in settings or provide email parameter.' });
84
+ }
85
+ return res.status(500).json({ success: false, error: result.error });
86
+ }
87
+ })
88
+ .catch(err => {
89
+ const errResult = {
90
+ success: false,
91
+ certPath: null,
92
+ keyPath: null,
93
+ error: {
94
+ step: 'certificate issuance',
95
+ cause: err.message,
96
+ consequence: 'Unexpected error during DNS certificate issuance.',
97
+ nginxRunning: true,
98
+ configSaved: false,
99
+ },
100
+ };
101
+ resultResolve(errResult);
102
+ pendingDnsChallenges.delete(domainKey);
103
+ if (!responseSent) {
104
+ responseSent = true;
105
+ return res.status(500).json({ success: false, error: errResult.error });
106
+ }
107
+ });
108
+
109
+ // The response is sent either by onDnsChallenge (202) or by the .then()/.catch() above.
110
+ return;
111
+ }
112
+
113
+ // HTTP validation path (synchronous — responds when complete)
114
+ const result = await issueCert(domainKey, { www: !!www, validationMethod: 'http', email: acmeEmail });
115
+
116
+ if (result.success) {
117
+ return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
118
+ }
119
+
120
+ const { step } = result.error;
121
+ if (step === 'email configuration') {
122
+ return res.status(400).json({
123
+ error: 'email_required',
124
+ hint: 'Configure acmeEmail in settings or provide email parameter.',
125
+ });
126
+ }
127
+ if (step === 'port 80 check') {
128
+ return res.status(409).json({
129
+ error: 'port_busy',
130
+ detail: result.error.cause,
131
+ hint: 'Stop the process using port 80 and try again.',
132
+ });
133
+ }
134
+ return res.status(500).json({ success: false, error: result.error });
135
+ } catch (error) {
136
+ next(error);
137
+ }
138
+ }
139
+
140
+ async createConfirm(req, res, next) {
141
+ try {
142
+ const { domain } = req.body ?? {};
143
+ const domainKey = domain?.trim();
144
+ const state = domainKey ? pendingDnsChallenges.get(domainKey) : null;
145
+
146
+ if (!state) {
147
+ return res.status(404).json({
148
+ error: 'no_pending_challenge',
149
+ hint: 'No DNS challenge is pending for this domain. Start a new certificate issuance.',
150
+ });
151
+ }
152
+
153
+ try {
154
+ const records = await dns.resolveTxt(`_acme-challenge.${domainKey}`);
155
+ const flatRecords = records.flat();
156
+
157
+ const found = flatRecords.includes(state.txtValue);
158
+ if (!found) {
159
+ return res.status(400).json({
160
+ error: 'dns_not_propagated',
161
+ hint: 'The expected TXT record value was not found. Make sure you added the correct TXT record and wait a few minutes for DNS propagation.',
162
+ expected: state.txtValue,
163
+ found: flatRecords,
164
+ });
165
+ }
166
+ } catch (err) {
167
+ return res.status(400).json({
168
+ error: 'dns_lookup_failed',
169
+ hint: 'Failed to lookup the expected TXT record. Make sure you added the correct TXT record.',
170
+ detail: err.message,
171
+ });
172
+ }
173
+ // Signal issueCert() to continue with the ACME process
174
+ await state.confirmDeferred.resolve();
175
+
176
+ // Wait for the ACME process to complete
177
+ const result = await state.resultPromise;
178
+ pendingDnsChallenges.delete(domainKey);
179
+
180
+ if (result.success) {
181
+ return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
182
+ }
183
+ return res.status(500).json({ success: false, error: result.error });
184
+ } catch (error) {
185
+ next(error);
186
+ }
187
+ }
188
+
189
+ async createCancel(req, res, next) {
190
+ try {
191
+ const { domain } = req.body ?? {};
192
+ const domainKey = domain?.trim();
193
+ const state = domainKey ? pendingDnsChallenges.get(domainKey) : null;
194
+
195
+ if (!state) {
196
+ return res.status(404).json({
197
+ error: 'no_pending_challenge',
198
+ hint: 'No DNS challenge is pending for this domain.',
199
+ });
200
+ }
201
+
202
+ // Reject the deferred — issueCert() will return a failure result
203
+ state.confirmDeferred.reject(new Error('cancelled by user'));
204
+ pendingDnsChallenges.delete(domainKey);
205
+
206
+ return res.json({ cancelled: true });
207
+ } catch (error) {
208
+ next(error);
209
+ }
210
+ }
211
+
212
+ async list(req, res, next) {
213
+ try {
214
+ const certs = await listAllCerts();
215
+ res.json(certs);
216
+ } catch (error) {
217
+ next(error);
218
+ }
219
+ }
220
+
221
+ async renew(req, res, next) {
222
+ try {
223
+ const domain = req.params.domain;
224
+ const config = loadConfig();
225
+
226
+ if (!config.acmeEmail) {
227
+ return res.status(400).json({
228
+ error: 'email_required',
229
+ hint: 'Configure acmeEmail in settings first.',
230
+ });
231
+ }
232
+
233
+ const certs = await listAllCerts();
234
+ const found = certs.find(cert => cert.domain === domain);
235
+ if (!found) {
236
+ return res.status(404).json({ error: `Domain '${domain}' not found` });
237
+ }
238
+
239
+ const result = await renewCert(domain, { validationMethod: 'http', email: config.acmeEmail });
240
+
241
+ if (result.success) {
242
+ return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
243
+ }
244
+
245
+ const { step } = result.error;
246
+ if (step === 'port 80 check') {
247
+ return res.status(409).json({
248
+ error: 'port_busy',
249
+ detail: result.error.cause,
250
+ hint: 'Stop the process using port 80 and try again.',
251
+ });
252
+ }
253
+ return res.status(500).json({ success: false, error: result.error });
254
+ } catch (error) {
255
+ next(error);
256
+ }
257
+ }
258
+
259
+ async renewAll(req, res, next) {
260
+ try {
261
+ const config = loadConfig();
262
+
263
+ if (!config.acmeEmail) {
264
+ return res.status(400).json({
265
+ error: 'email_required',
266
+ hint: 'Configure acmeEmail in settings first.',
267
+ });
268
+ }
269
+
270
+ const certs = await listAllCerts();
271
+ const expiring = certs.filter(c => c.daysLeft !== null && c.daysLeft < 30);
272
+ const results = [];
273
+
274
+ for (const cert of expiring) {
275
+ const result = await renewCert(cert.domain, { validationMethod: 'http', email: config.acmeEmail });
276
+ results.push({
277
+ domain: cert.domain,
278
+ success: result.success,
279
+ certPath: result.certPath,
280
+ keyPath: result.keyPath,
281
+ });
282
+ }
283
+
284
+ res.json(results);
285
+ } catch (error) {
286
+ next(error);
287
+ }
288
+ }
289
+ }
290
+
291
+ export default SslController;
Binary file
Binary file