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
@@ -37,6 +37,11 @@ const DEFAULT_FORM = {
37
37
  accessLog: true,
38
38
  customLocations: '',
39
39
  },
40
+ notifications: {
41
+ domain_health: { enabled: true, channelIds: [] },
42
+ cert_expiry: { enabled: true, channelIds: [] },
43
+ nginx_down: { enabled: true, channelIds: [] },
44
+ },
40
45
  };
41
46
 
42
47
  createApp({
@@ -55,6 +60,7 @@ createApp({
55
60
  { id: 'nginx', label: 'Nginx', icon: '🌐' },
56
61
  { id: 'ssl', label: 'SSL Certs', icon: '🔒' },
57
62
  { id: 'domains', label: 'Domains', icon: '🔗' },
63
+ { id: 'logs', label: 'Logs', icon: '📋' },
58
64
  { id: 'settings', label: 'Settings', icon: '⚙️' },
59
65
  ],
60
66
 
@@ -78,6 +84,8 @@ createApp({
78
84
  },
79
85
 
80
86
  // T017-T019: Updated domains state
87
+ domainHealth: {}, // { [name]: true|false|null }
88
+
81
89
  domains: {
82
90
  list: [], loading: false, error: '',
83
91
  showForm: false,
@@ -101,6 +109,14 @@ createApp({
101
109
  performance: false,
102
110
  security: false,
103
111
  advanced: false,
112
+ notifications: false,
113
+ },
114
+
115
+ logs: {
116
+ lines: [],
117
+ activeLog: 'error', // 'error' | 'access'
118
+ paused: false,
119
+ socket: null,
104
120
  },
105
121
 
106
122
  settings: {
@@ -108,10 +124,35 @@ createApp({
108
124
  password: '', loading: false, msg: '', error: '',
109
125
  platform: 'linux', // T022: Platform from settings API
110
126
  },
127
+ settingsTab: 'general', // 'general' | 'notifications'
111
128
 
112
129
  permissions: {
113
130
  configured: false, loading: false, password: '', msg: '', error: '',
114
131
  },
132
+
133
+ backup: {
134
+ restoring: false, msg: '', error: '',
135
+ },
136
+
137
+ channels: {
138
+ list: [],
139
+ loading: false,
140
+ testingId: null,
141
+ testResults: {},
142
+ },
143
+ channelModal: {
144
+ open: false,
145
+ editing: null, // null = add new, string = channel id being edited
146
+ form: { name: '', type: 'discord', webhookUrl: '', botToken: '', chatId: '', message: '' },
147
+ saving: false,
148
+ error: '',
149
+ },
150
+
151
+ notifications: {
152
+ items: [], // { id, type, severity, message, domain?, timestamp }
153
+ panelOpen: false,
154
+ unread: 0,
155
+ },
115
156
  };
116
157
  },
117
158
 
@@ -148,6 +189,15 @@ createApp({
148
189
  localStorage.setItem('ed-sidebar', val);
149
190
  },
150
191
 
192
+ 'logs.lines'() {
193
+ if (!this.logs.paused) {
194
+ this.$nextTick(() => {
195
+ const el = document.getElementById('log-output');
196
+ if (el) el.scrollTop = el.scrollHeight;
197
+ });
198
+ }
199
+ },
200
+
151
201
  // T019: Deep watch form for dirty tracking
152
202
  'domains.form': {
153
203
  handler() {
@@ -202,6 +252,21 @@ createApp({
202
252
  socket.on('nginx:status', (status) => {
203
253
  this.nginx.status = status;
204
254
  });
255
+ socket.on('notification:new', (n) => {
256
+ this.addNotification(n);
257
+ });
258
+ socket.on('domain:health', (results) => {
259
+ const map = {};
260
+ for (const r of results) map[r.name] = r.up;
261
+ this.domainHealth = map;
262
+ });
263
+ socket.on('logs:line', ({ line, logFile }) => {
264
+ if (!this.logs.paused && logFile === this.logs.activeLog) {
265
+ this.logs.lines.push(line);
266
+ if (this.logs.lines.length > 500) this.logs.lines.shift();
267
+ }
268
+ });
269
+ this.logs.socket = socket;
205
270
  },
206
271
 
207
272
  methods: {
@@ -251,6 +316,7 @@ createApp({
251
316
  },
252
317
 
253
318
  async loadPage(p) {
319
+ if (this.page === 'logs' && p !== 'logs') this.unsubscribeLogs();
254
320
  this.page = p;
255
321
  if (p === 'overview') {
256
322
  await Promise.all([this.loadNginxStatus(), this.loadSSL(), this.loadDomains()]);
@@ -258,7 +324,8 @@ createApp({
258
324
  await Promise.all([this.loadNginxStatus(), this.loadNginxConfigs(), this.loadNginxLogs()]);
259
325
  } else if (p === 'ssl') { await this.loadSSL(); }
260
326
  else if (p === 'domains') { await this.loadDomains(); }
261
- else if (p === 'settings') { await Promise.all([this.loadSettings(), this.loadPermissionsStatus()]); }
327
+ else if (p === 'logs') { this.subscribeToLogs(this.logs.activeLog); }
328
+ else if (p === 'settings') { await Promise.all([this.loadSettings(), this.loadPermissionsStatus(), this.loadChannels()]); }
262
329
  },
263
330
 
264
331
  // ── Collapsible Sections ────────────────────────────────────────────
@@ -436,7 +503,9 @@ createApp({
436
503
  if (!isConfirmed) return;
437
504
  }
438
505
  this.domains.showForm = !this.domains.showForm;
439
- if (!this.domains.showForm) {
506
+ if (this.domains.showForm) {
507
+ await this.loadChannels();
508
+ } else {
440
509
  this.resetDomainForm();
441
510
  }
442
511
  },
@@ -458,6 +527,7 @@ createApp({
458
527
  performance: false,
459
528
  security: false,
460
529
  advanced: false,
530
+ notifications: false,
461
531
  };
462
532
  },
463
533
 
@@ -475,6 +545,9 @@ createApp({
475
545
  if (!isConfirmed) return;
476
546
  }
477
547
 
548
+ // Ensure channels are loaded for the notifications section
549
+ await this.loadChannels();
550
+
478
551
  // Fetch domain data
479
552
  const r = await this.api('GET', `/api/domains`);
480
553
  if (!r.ok) {
@@ -524,6 +597,11 @@ createApp({
524
597
  accessLog: domain.advanced?.accessLog ?? true,
525
598
  customLocations: domain.advanced?.customLocations || '',
526
599
  },
600
+ notifications: {
601
+ domain_health: domain.notifications?.domain_health ?? { enabled: true, channelIds: [] },
602
+ cert_expiry: domain.notifications?.cert_expiry ?? { enabled: true, channelIds: [] },
603
+ nginx_down: domain.notifications?.nginx_down ?? { enabled: true, channelIds: [] },
604
+ },
527
605
  };
528
606
 
529
607
  this.domains.editingName = name;
@@ -537,6 +615,7 @@ createApp({
537
615
  performance: true,
538
616
  security: true,
539
617
  advanced: true,
618
+ notifications: true,
540
619
  };
541
620
  },
542
621
 
@@ -717,6 +796,13 @@ createApp({
717
796
  if (r.ok) this.permissions.configured = r.data.configured;
718
797
  },
719
798
 
799
+ async loadChannels() {
800
+ this.channels.loading = true;
801
+ const r = await this.api('GET', '/api/settings/channels');
802
+ this.channels.loading = false;
803
+ if (r.ok) this.channels.list = Array.isArray(r.data) ? r.data : [];
804
+ },
805
+
720
806
  async setupPermissions() {
721
807
  this.permissions.loading = true; this.permissions.msg = ''; this.permissions.error = '';
722
808
  const r = await this.api('POST', '/api/settings/permissions/setup', { password: this.permissions.password });
@@ -730,6 +816,86 @@ createApp({
730
816
  }
731
817
  },
732
818
 
819
+ // ── Logs ──────────────────────────────────────────────────────────────────
820
+ subscribeToLogs(logFile) {
821
+ if (!this.logs.socket) return;
822
+ this.logs.lines = [];
823
+ this.logs.activeLog = logFile;
824
+ this.logs.paused = false;
825
+ this.logs.socket.emit('logs:subscribe', { logFile });
826
+ },
827
+ switchLog(logFile) {
828
+ this.subscribeToLogs(logFile);
829
+ },
830
+ unsubscribeLogs() {
831
+ if (this.logs.socket) this.logs.socket.emit('logs:unsubscribe');
832
+ },
833
+
834
+ // ── Notifications ─────────────────────────────────────────────────────────
835
+ addNotification(n) {
836
+ // Deduplicate by id — replace if same id already exists
837
+ const idx = this.notifications.items.findIndex(i => i.id === n.id);
838
+ if (idx !== -1) {
839
+ this.notifications.items.splice(idx, 1, n);
840
+ } else {
841
+ this.notifications.items.unshift(n);
842
+ if (!this.notifications.panelOpen) this.notifications.unread++;
843
+ }
844
+ },
845
+ toggleNotificationsPanel() {
846
+ this.notifications.panelOpen = !this.notifications.panelOpen;
847
+ if (this.notifications.panelOpen) this.notifications.unread = 0;
848
+ },
849
+ clearNotifications() {
850
+ this.notifications.items = [];
851
+ this.notifications.unread = 0;
852
+ },
853
+ notifIcon(type) {
854
+ if (type === 'nginx_down') return '🔴';
855
+ if (type === 'cert_expiry') return '🔒';
856
+ if (type === 'domain_down') return '⚠️';
857
+ return '🔔';
858
+ },
859
+
860
+ // ── Backup & Restore ──────────────────────────────────────────────────────
861
+ exportBackup() {
862
+ window.location.href = '/api/settings/backup';
863
+ },
864
+ async importBackup(event) {
865
+ const file = event.target.files[0];
866
+ if (!file) return;
867
+ this.backup.msg = ''; this.backup.error = '';
868
+ let data;
869
+ try {
870
+ data = JSON.parse(await file.text());
871
+ } catch {
872
+ this.backup.error = 'Invalid file — could not parse JSON.';
873
+ event.target.value = '';
874
+ return;
875
+ }
876
+ const { isConfirmed } = await Swal.fire({
877
+ title: 'Restore backup?',
878
+ text: 'This will overwrite your current configuration and domains list.',
879
+ icon: 'warning',
880
+ showCancelButton: true,
881
+ confirmButtonText: 'Restore',
882
+ cancelButtonText: 'Cancel',
883
+ ...this.swalTheme,
884
+ });
885
+ event.target.value = '';
886
+ if (!isConfirmed) return;
887
+ this.backup.restoring = true;
888
+ const r = await this.api('POST', '/api/settings/restore', data);
889
+ this.backup.restoring = false;
890
+ if (r.ok) {
891
+ this.backup.msg = 'Restored successfully. Reload the page to see changes.';
892
+ await this.loadSettings();
893
+ await this.loadDomains();
894
+ } else {
895
+ this.backup.error = r.data?.error || 'Restore failed';
896
+ }
897
+ },
898
+
733
899
  async saveSettings() {
734
900
  this.settings.loading = true; this.settings.msg = ''; this.settings.error = '';
735
901
  const payload = {
@@ -744,6 +910,72 @@ createApp({
744
910
  if (r.ok) { this.settings.msg = 'Settings saved ✓'; this.settings.password = ''; }
745
911
  else { this.settings.error = r.data.error || 'Save failed'; }
746
912
  },
913
+
914
+ openAddChannel() {
915
+ this.channelModal.editing = null;
916
+ this.channelModal.form = { name: '', type: 'discord', webhookUrl: '', botToken: '', chatId: '', message: '' };
917
+ this.channelModal.error = '';
918
+ this.channelModal.open = true;
919
+ },
920
+
921
+ openEditChannel(channel) {
922
+ this.channelModal.editing = channel.id;
923
+ this.channelModal.form = {
924
+ name: channel.name,
925
+ type: channel.type,
926
+ webhookUrl: channel.webhookUrl || '',
927
+ botToken: channel.botToken || '',
928
+ chatId: channel.chatId || '',
929
+ message: channel.message || '',
930
+ };
931
+ this.channelModal.error = '';
932
+ this.channelModal.open = true;
933
+ },
934
+
935
+ async saveChannel() {
936
+ this.channelModal.saving = true;
937
+ this.channelModal.error = '';
938
+ const { name, type, webhookUrl, botToken, chatId, message } = this.channelModal.form;
939
+ const payload = { name, type, webhookUrl, botToken, chatId, message };
940
+ const r = this.channelModal.editing
941
+ ? await this.api('PUT', `/api/settings/channels/${this.channelModal.editing}`, payload)
942
+ : await this.api('POST', '/api/settings/channels', payload);
943
+ this.channelModal.saving = false;
944
+ if (r.ok) {
945
+ this.channelModal.open = false;
946
+ await this.loadChannels();
947
+ } else {
948
+ this.channelModal.error = r.data.error || 'Save failed';
949
+ }
950
+ },
951
+
952
+ async deleteChannel(id) {
953
+ const { isConfirmed } = await Swal.fire({
954
+ title: 'Delete channel?',
955
+ text: 'This cannot be undone.',
956
+ icon: 'warning',
957
+ showCancelButton: true,
958
+ confirmButtonText: 'Delete',
959
+ cancelButtonText: 'Cancel',
960
+ ...this.swalTheme,
961
+ });
962
+ if (!isConfirmed) return;
963
+ await this.api('DELETE', `/api/settings/channels/${id}`);
964
+ await this.loadChannels();
965
+ },
966
+
967
+ async testChannelById(id) {
968
+ this.channels.testingId = id;
969
+ this.channels.testResults = { ...this.channels.testResults, [id]: { msg: '', error: '' } };
970
+ const r = await this.api('POST', `/api/settings/channels/${id}/test`);
971
+ this.channels.testingId = null;
972
+ this.channels.testResults = {
973
+ ...this.channels.testResults,
974
+ [id]: r.ok
975
+ ? { msg: 'Test sent ✓', error: '' }
976
+ : { msg: '', error: r.data.error || 'Test failed' },
977
+ };
978
+ },
747
979
  },
748
980
  })
749
981
  .directive('click-outside', {
@@ -1,30 +1,20 @@
1
1
  import { Router } from 'express';
2
- import { loadConfig } from '../../core/config.js';
2
+ import rateLimit from 'express-rate-limit';
3
+ import AuthController from '../controllers/authController.js';
3
4
 
4
5
  const router = Router();
6
+ const controller = new AuthController();
5
7
 
6
- router.post('/login', (req, res) => {
7
- const { password } = req.body;
8
- const { dashboardPassword } = loadConfig();
9
- if (password === dashboardPassword) {
10
- req.session.authenticated = true;
11
- res.json({ ok: true });
12
- } else {
13
- res.status(401).json({ ok: false, error: 'Invalid password' });
14
- }
8
+ const loginLimiter = rateLimit({
9
+ windowMs: 15 * 60 * 1000, // 15 minutes
10
+ max: 10,
11
+ standardHeaders: true,
12
+ legacyHeaders: false,
13
+ message: { ok: false, error: 'Too many login attempts. Try again in 15 minutes.' },
15
14
  });
16
15
 
17
- router.get('/auth', (req, res) => {
18
- if (req.session.authenticated === true) {
19
- res.json({ authenticated: true });
20
- } else {
21
- res.json({ authenticated: false });
22
- }
23
- });
24
-
25
- router.post('/logout', (req, res) => {
26
- req.session.destroy();
27
- res.json({ ok: true });
28
- });
16
+ router.post('/login', loginLimiter, (req, res, next) => controller.login(req, res, next));
17
+ router.get('/auth', (req, res, next) => controller.check(req, res, next));
18
+ router.post('/logout', (req, res, next) => controller.logout(req, res, next));
29
19
 
30
20
  export default router;