easy-devops 1.2.0 → 1.3.0

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 (132) hide show
  1. package/README.md +97 -6
  2. package/dist/ui/assets/index-B6zdwEnG.css +1 -0
  3. package/dist/ui/assets/index-Cy0oNmul.js +442 -0
  4. package/dist/ui/assets/socket-DwLPrgsr.js +1 -0
  5. package/dist/ui/assets/socket-K5ttLD2q.js +65 -0
  6. package/dist/ui/brand/apple-touch-icon.png +0 -0
  7. package/dist/ui/brand/favicon-16.png +0 -0
  8. package/dist/ui/brand/favicon-32.png +0 -0
  9. package/dist/ui/brand/favicon-light-16.png +0 -0
  10. package/dist/ui/brand/favicon-light-32.png +0 -0
  11. package/dist/ui/brand/favicon.ico +0 -0
  12. package/dist/ui/brand/icon-192.png +0 -0
  13. package/dist/ui/brand/icon-48.png +0 -0
  14. package/dist/ui/brand/icon-512.png +0 -0
  15. package/dist/ui/brand/icon-64-light.png +0 -0
  16. package/dist/ui/brand/icon-64.png +0 -0
  17. package/dist/ui/brand/logo-dark.png +0 -0
  18. package/dist/ui/brand/logo-light.png +0 -0
  19. package/dist/ui/brand/mark-dark.png +0 -0
  20. package/dist/ui/brand/mark-light.png +0 -0
  21. package/dist/ui/index.html +71 -0
  22. package/install.ps1 +188 -1
  23. package/install.sh +254 -29
  24. package/package.json +17 -5
  25. package/src/cli/dash.js +110 -0
  26. package/src/cli/index.js +237 -106
  27. package/src/cli/managers/domain-manager.js +60 -40
  28. package/src/cli/managers/ssl-manager.js +47 -330
  29. package/src/cli/menu.js +156 -0
  30. package/src/cli/menus/cleanup.js +205 -0
  31. package/src/cli/menus/dashboard.js +93 -2
  32. package/src/cli/menus/runtime.js +236 -0
  33. package/src/cli/menus/service.js +764 -0
  34. package/src/cli/menus/settings.js +176 -8
  35. package/src/cli/menus/uninstall.js +167 -0
  36. package/src/cli/menus/update.js +221 -65
  37. package/src/core/acme-challenge.js +273 -0
  38. package/src/core/cert-operations.js +189 -0
  39. package/src/{dashboard/lib → core}/cert-reader.js +2 -2
  40. package/src/core/cert-renewal.js +494 -0
  41. package/src/core/channels/discord.js +77 -0
  42. package/src/core/channels/telegram.js +120 -0
  43. package/src/core/cleanup.js +600 -0
  44. package/src/core/config.js +169 -2
  45. package/src/core/daemon/ipc.js +292 -0
  46. package/src/core/daemon/lock.js +294 -0
  47. package/src/core/daemon/run.js +241 -0
  48. package/src/core/daemon/stopRequest.js +162 -0
  49. package/src/core/db.js +44 -8
  50. package/src/core/deploy/apps.js +491 -0
  51. package/src/core/deploy/domainLink.js +200 -0
  52. package/src/core/deploy/engine.js +973 -0
  53. package/src/core/deploy/ezfile.js +361 -0
  54. package/src/core/deploy/github.js +239 -0
  55. package/src/core/deploy/githubApi.js +261 -0
  56. package/src/core/deploy/hookServer.js +325 -0
  57. package/src/core/deploy/hubCommands.js +267 -0
  58. package/src/core/deploy/launcher.js +57 -0
  59. package/src/core/deploy/status.js +91 -0
  60. package/src/core/deploy/store.js +398 -0
  61. package/src/core/domainNotifier.js +364 -0
  62. package/src/core/domains-db.js +234 -0
  63. package/src/core/events.js +222 -0
  64. package/src/core/hub/agent.js +842 -0
  65. package/src/core/hubLink.js +306 -0
  66. package/src/core/hubPermissions.js +430 -0
  67. package/src/core/installSource.js +162 -0
  68. package/src/core/jobs/bus.js +120 -0
  69. package/src/core/jobs/index.js +371 -0
  70. package/src/core/jobs/monitors.js +368 -0
  71. package/src/core/jobs/owner.js +217 -0
  72. package/src/core/jobs/revisionWatcher.js +106 -0
  73. package/src/core/nginx-apply.js +213 -0
  74. package/src/core/nginx-conf-generator.js +253 -17
  75. package/src/{dashboard/lib → core}/nginx-service.js +18 -9
  76. package/src/core/notifications/claim.js +214 -0
  77. package/src/core/notifications/dispatch.js +154 -0
  78. package/src/core/notifier.js +103 -0
  79. package/src/core/passwords.js +172 -0
  80. package/src/core/permissions.js +8 -4
  81. package/src/core/platform.js +709 -2
  82. package/src/core/probeCache.js +258 -0
  83. package/src/core/purge.js +372 -0
  84. package/src/core/runner.js +488 -0
  85. package/src/core/service/acl.js +226 -0
  86. package/src/core/service/dataDir.js +345 -0
  87. package/src/core/service/index.js +1128 -0
  88. package/src/core/service/legacy.js +218 -0
  89. package/src/core/service/runtime.js +446 -0
  90. package/src/core/service/runtimeUpdate.js +800 -0
  91. package/src/core/service/systemd.js +458 -0
  92. package/src/core/service/windowsPersonal.js +530 -0
  93. package/src/core/service/windowsService.js +576 -0
  94. package/src/core/service/winsw.js +260 -0
  95. package/src/core/setupCode.js +331 -0
  96. package/src/core/shell.js +128 -13
  97. package/src/core/ssl-issuer.js +627 -0
  98. package/src/core/updater.js +295 -0
  99. package/src/core/validators.js +99 -0
  100. package/src/dashboard/controllers/authController.js +316 -0
  101. package/src/dashboard/controllers/deploymentsController.js +479 -0
  102. package/src/dashboard/controllers/domainsController.js +403 -0
  103. package/src/dashboard/controllers/hubController.js +135 -0
  104. package/src/dashboard/controllers/nginxController.js +146 -0
  105. package/src/dashboard/controllers/processesController.js +368 -0
  106. package/src/dashboard/controllers/settingsController.js +503 -0
  107. package/src/dashboard/controllers/sslController.js +452 -0
  108. package/src/dashboard/lib/daemonBridge.js +163 -0
  109. package/src/dashboard/lib/localRequest.js +235 -0
  110. package/src/dashboard/lib/loginRateLimit.js +119 -0
  111. package/src/dashboard/lib/requireAuth.js +80 -0
  112. package/src/dashboard/public/img/icon.png +0 -0
  113. package/src/dashboard/public/img/icon_b.png +0 -0
  114. package/src/dashboard/public/js/app.js +595 -19
  115. package/src/dashboard/routes/auth.js +14 -33
  116. package/src/dashboard/routes/deployments.js +46 -0
  117. package/src/dashboard/routes/domains.js +20 -363
  118. package/src/dashboard/routes/hub.js +22 -0
  119. package/src/dashboard/routes/nginx.js +22 -146
  120. package/src/dashboard/routes/processes.js +29 -0
  121. package/src/dashboard/routes/settings.js +25 -232
  122. package/src/dashboard/routes/ssl.js +18 -276
  123. package/src/dashboard/server.js +279 -165
  124. package/src/dashboard/socketManager.js +246 -0
  125. package/src/dashboard/views/index.ejs +1 -0
  126. package/src/dashboard/views/partials/domain-form.ejs +64 -1
  127. package/src/dashboard/views/partials/login.ejs +69 -8
  128. package/src/dashboard/views/partials/processes-panel.ejs +261 -0
  129. package/src/dashboard/views/partials/settings-panel.ejs +549 -118
  130. package/src/dashboard/views/partials/sidebar.ejs +3 -1
  131. package/src/dashboard/lib/domains-db.js +0 -51
  132. /package/src/{dashboard/routes → core/channels}/.gitkeep +0 -0
@@ -1,281 +1,23 @@
1
1
  import express from 'express';
2
- import { listAllCerts } from '../lib/cert-reader.js';
3
- import { issueCert, renewCert } from '../../cli/managers/ssl-manager.js';
4
- import { loadConfig } from '../../core/config.js';
5
- import { promises as dns } from 'dns';
2
+ import SslController from '../controllers/sslController.js';
3
+ import { requireAuth } from '../lib/requireAuth.js';
6
4
 
7
5
  const router = express.Router();
8
-
9
- // ─── In-memory DNS challenge state ────────────────────────────────────────────
10
- // Keyed by domain name. Entries are cleaned up when the ACME process exits
11
- // or when cancelled. Entries older than 10 minutes are forcibly removed.
12
-
13
- const pendingDnsChallenges = new Map();
14
-
15
- setInterval(() => {
16
- const now = Date.now();
17
- for (const [domain, state] of pendingDnsChallenges) {
18
- if (now - state.createdAt > 10 * 60 * 1000) {
19
- state.confirmDeferred.reject(new Error('DNS challenge timed out after 10 minutes'));
20
- pendingDnsChallenges.delete(domain);
21
- }
22
- }
23
- }, 60000);
24
-
25
- // ─── POST /api/ssl/create ─────────────────────────────────────────────────────
26
-
27
- router.post('/create', async (req, res) => {
28
- const { domain, www = false, validationMethod = 'http', email = null } = req.body ?? {};
29
-
30
- if (!domain || typeof domain !== 'string' || !domain.trim()) {
31
- return res.status(400).json({ error: 'domain is required' });
32
- }
33
-
34
- const domainKey = domain.trim();
35
- const config = loadConfig();
36
- const acmeEmail = email || config.acmeEmail;
37
-
38
- if (validationMethod === 'dns') {
39
- // Two-phase flow: spawn ACME process, wait for TXT record, respond 202, pause until confirm.
40
- let confirmResolve, confirmReject;
41
- const confirmPromise = new Promise((resolve, reject) => {
42
- confirmResolve = resolve;
43
- confirmReject = reject;
44
- });
45
-
46
- let resultResolve;
47
- const resultPromise = new Promise((resolve) => { resultResolve = resolve; });
48
-
49
- // Track whether a response has already been sent (202 from onDnsChallenge)
50
- let responseSent = false;
51
-
52
- const onDnsChallenge = async (txtName, txtValue) => {
53
- responseSent = true;
54
- pendingDnsChallenges.set(domainKey, {
55
- domain: domainKey,
56
- txtName,
57
- txtValue,
58
- confirmDeferred: { resolve: confirmResolve, reject: confirmReject },
59
- resultPromise,
60
- createdAt: Date.now(),
61
- });
62
-
63
- res.status(202).json({
64
- status: 'waiting_dns',
65
- domain: domainKey,
66
- txtName,
67
- txtValue,
68
- hint: 'Add a DNS TXT record with the name and value above, then call POST /api/ssl/create-confirm',
69
- });
70
-
71
- // Pause until user calls /create-confirm (resolves) or /create-cancel (rejects)
72
- await confirmPromise;
73
- };
74
-
75
- // Run issueCert in the background — it will call onDnsChallenge which sends 202 and pauses.
76
- issueCert(domainKey, { www: !!www, validationMethod: 'dns', email: acmeEmail, onDnsChallenge })
77
- .then(result => {
78
- resultResolve(result);
79
- pendingDnsChallenges.delete(domainKey);
80
- if (!responseSent) {
81
- responseSent = true;
82
- if (result.success) {
83
- return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
84
- }
85
- const { step } = result.error ?? {};
86
- if (step === 'email configuration') {
87
- return res.status(400).json({ error: 'email_required', hint: 'Configure acmeEmail in settings or provide email parameter.' });
88
- }
89
- return res.status(500).json({ success: false, error: result.error });
90
- }
91
- })
92
- .catch(err => {
93
- const errResult = {
94
- success: false,
95
- certPath: null,
96
- keyPath: null,
97
- error: {
98
- step: 'certificate issuance',
99
- cause: err.message,
100
- consequence: 'Unexpected error during DNS certificate issuance.',
101
- nginxRunning: true,
102
- configSaved: false,
103
- },
104
- };
105
- resultResolve(errResult);
106
- pendingDnsChallenges.delete(domainKey);
107
- if (!responseSent) {
108
- responseSent = true;
109
- return res.status(500).json({ success: false, error: errResult.error });
110
- }
111
- });
112
-
113
- // The response is sent either by onDnsChallenge (202) or by the .then()/.catch() above.
114
- return;
115
- }
116
-
117
- // HTTP validation path (synchronous — responds when complete)
118
- const result = await issueCert(domainKey, { www: !!www, validationMethod: 'http', email: acmeEmail });
119
-
120
- if (result.success) {
121
- return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
122
- }
123
-
124
- const { step } = result.error;
125
- if (step === 'email configuration') {
126
- return res.status(400).json({
127
- error: 'email_required',
128
- hint: 'Configure acmeEmail in settings or provide email parameter.',
129
- });
130
- }
131
- if (step === 'port 80 check') {
132
- return res.status(409).json({
133
- error: 'port_busy',
134
- detail: result.error.cause,
135
- hint: 'Stop the process using port 80 and try again.',
136
- });
137
- }
138
- return res.status(500).json({ success: false, error: result.error });
139
- });
140
-
141
- // ─── POST /api/ssl/create-confirm ────────────────────────────────────────────
142
-
143
- router.post('/create-confirm', async (req, res) => {
144
- const { domain } = req.body ?? {};
145
- const domainKey = domain?.trim();
146
- const state = domainKey ? pendingDnsChallenges.get(domainKey) : null;
147
-
148
- if (!state) {
149
- return res.status(404).json({
150
- error: 'no_pending_challenge',
151
- hint: 'No DNS challenge is pending for this domain. Start a new certificate issuance.',
152
- });
153
- }
154
-
155
- try {
156
- const records = await dns.resolveTxt(`_acme-challenge.${domainKey}`);
157
- const flatRecords = records.flat();
158
-
159
- const found = flatRecords.includes(state.txtValue);
160
- if (!found) {
161
- return res.status(400).json({
162
- error: 'dns_not_propagated',
163
- 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.',
164
- expected: state.txtValue,
165
- found: flatRecords,
166
- });
167
- }
168
- } catch (err) {
169
- return res.status(400).json({
170
- error: 'dns_lookup_failed',
171
- hint: 'Failed to lookup the expected TXT record. Make sure you added the correct TXT record.',
172
- detail: err.message,
173
- });
174
- }
175
- // Signal issueCert() to continue with the ACME process
176
- await state.confirmDeferred.resolve();
177
-
178
- // Wait for the ACME process to complete
179
- const result = await state.resultPromise;
180
- pendingDnsChallenges.delete(domainKey);
181
-
182
- if (result.success) {
183
- return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
184
- }
185
- return res.status(500).json({ success: false, error: result.error });
186
- });
187
-
188
- // ─── POST /api/ssl/create-cancel ─────────────────────────────────────────────
189
-
190
- router.post('/create-cancel', async (req, res) => {
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
- });
208
-
209
- // ─── GET /api/ssl ─────────────────────────────────────────────────────────────
210
-
211
- router.get('/', async (req, res) => {
212
- const certs = await listAllCerts();
213
- res.json(certs);
214
- });
215
-
216
- // ─── POST /api/ssl/renew/:domain ─────────────────────────────────────────────
217
-
218
- router.post('/renew/:domain', async (req, res) => {
219
- const domain = req.params.domain;
220
- const config = loadConfig();
221
-
222
- if (!config.acmeEmail) {
223
- return res.status(400).json({
224
- error: 'email_required',
225
- hint: 'Configure acmeEmail in settings first.',
226
- });
227
- }
228
-
229
- const certs = await listAllCerts();
230
- const found = certs.find(cert => cert.domain === domain);
231
- if (!found) {
232
- return res.status(404).json({ error: `Domain '${domain}' not found` });
233
- }
234
-
235
- const result = await renewCert(domain, { validationMethod: 'http', email: config.acmeEmail });
236
-
237
- if (result.success) {
238
- return res.json({ success: true, certPath: result.certPath, keyPath: result.keyPath });
239
- }
240
-
241
- const { step } = result.error;
242
- if (step === 'port 80 check') {
243
- return res.status(409).json({
244
- error: 'port_busy',
245
- detail: result.error.cause,
246
- hint: 'Stop the process using port 80 and try again.',
247
- });
248
- }
249
- return res.status(500).json({ success: false, error: result.error });
250
- });
251
-
252
- // ─── POST /api/ssl/renew-all ─────────────────────────────────────────────────
253
-
254
- router.post('/renew-all', async (req, res) => {
255
- const config = loadConfig();
256
-
257
- if (!config.acmeEmail) {
258
- return res.status(400).json({
259
- error: 'email_required',
260
- hint: 'Configure acmeEmail in settings first.',
261
- });
262
- }
263
-
264
- const certs = await listAllCerts();
265
- const expiring = certs.filter(c => c.daysLeft !== null && c.daysLeft < 30);
266
- const results = [];
267
-
268
- for (const cert of expiring) {
269
- const result = await renewCert(cert.domain, { validationMethod: 'http', email: config.acmeEmail });
270
- results.push({
271
- domain: cert.domain,
272
- success: result.success,
273
- certPath: result.certPath,
274
- keyPath: result.keyPath,
275
- });
276
- }
277
-
278
- res.json(results);
279
- });
6
+ const controller = new SslController();
7
+
8
+ /**
9
+ * Every route below requires a dashboard session. See lib/requireAuth.js —
10
+ * this is the single gate, and removing it exposes these endpoints to anyone
11
+ * who can reach the dashboard port.
12
+ */
13
+ router.use(requireAuth);
14
+
15
+
16
+ router.post('/create', (req, res, next) => controller.create(req, res, next));
17
+ router.post('/create-confirm', (req, res, next) => controller.createConfirm(req, res, next));
18
+ router.post('/create-cancel', (req, res, next) => controller.createCancel(req, res, next));
19
+ router.get('/', (req, res, next) => controller.list(req, res, next));
20
+ router.post('/renew/:domain', (req, res, next) => controller.renew(req, res, next));
21
+ router.post('/renew-all', (req, res, next) => controller.renewAll(req, res, next));
280
22
 
281
23
  export default router;