saymon-syswatch-linux 1.0.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.
package/README.md ADDED
@@ -0,0 +1,154 @@
1
+ # SysWatch 🖥️
2
+
3
+ **Linux system monitor + learning dashboard** — install it, run it, done.
4
+
5
+ Monitor CPU, memory, disk, services, journal logs and processes from a web UI.
6
+ Every panel shows the exact Linux commands being used — so you **learn while you monitor**.
7
+
8
+ ---
9
+
10
+ ## ⚡ Install & Run (3 steps)
11
+
12
+ ```bash
13
+ # Step 1 — Install
14
+ sudo npm install -g syswatch
15
+
16
+ # Step 2 — Run (first time auto-runs setup wizard)
17
+ sudo syswatch
18
+
19
+ # Step 3 — Open browser
20
+ # http://localhost:8080
21
+ ```
22
+
23
+ **That's it.** On first run, a setup wizard asks you 4 simple questions in the terminal — including your password — and creates the config file automatically.
24
+
25
+ ---
26
+
27
+ ## 🧙 First-Run Setup Wizard
28
+
29
+ When you run SysWatch for the first time (no config found), it automatically starts an interactive wizard:
30
+
31
+ ```
32
+ ╭──────────────────────────────────────────────────────╮
33
+ │ SysWatch — First Time Setup │
34
+ │ Takes about 30 seconds ⚡ │
35
+ ╰──────────────────────────────────────────────────────╯
36
+
37
+ Step 1/4 — Set your login password
38
+ Enter password: ********
39
+ Confirm password: ********
40
+ ✓ Password set!
41
+
42
+ Step 2/4 — HTTP Port
43
+ Port [8080]: (press Enter for default)
44
+ ✓ HTTP port: 8080
45
+
46
+ Step 3/4 — Who can access SysWatch?
47
+ 1) Only this computer (localhost) ← safer
48
+ 2) Anyone on my network (0.0.0.0)
49
+ Choose [1]:
50
+ ✓ Access: Localhost only
51
+
52
+ Step 4/4 — Enable HTTPS?
53
+ Enable HTTPS? [y/N]:
54
+ ✓ HTTPS: Disabled
55
+
56
+ ✓ Setup complete! Config saved → syswatch.config.json
57
+ Starting SysWatch → http://localhost:8080
58
+ ```
59
+
60
+ The wizard creates `syswatch.config.json` automatically. **No manual editing needed.**
61
+
62
+ ---
63
+
64
+ ## 🔁 Re-run Setup (change password, port, etc.)
65
+
66
+ ```bash
67
+ sudo syswatch --setup
68
+ ```
69
+
70
+ ---
71
+
72
+ ## ⚙️ CLI Options
73
+
74
+ ```bash
75
+ sudo syswatch # first run = setup wizard, then start
76
+ sudo syswatch --setup # re-run setup wizard anytime
77
+ sudo syswatch --no-auth # skip password (local testing only)
78
+ sudo syswatch --port 3000 # override port
79
+ sudo syswatch --host 0.0.0.0 # allow LAN access
80
+ sudo syswatch --https # enable HTTPS too
81
+ sudo syswatch --help # show all options
82
+ ```
83
+
84
+ ---
85
+
86
+ ## 🔒 HTTPS
87
+
88
+ **Self-signed (quick):** Answer "y" to the HTTPS question in setup. A cert is auto-generated. Browser will warn "Not Secure" — click Advanced → Proceed. Normal for self-signed.
89
+
90
+ **Let's Encrypt (real domain):**
91
+ ```bash
92
+ sudo certbot certonly --standalone -d yourdomain.com
93
+ # Then edit syswatch.config.json:
94
+ # "certPath": "/etc/letsencrypt/live/yourdomain.com/fullchain.pem"
95
+ # "keyPath": "/etc/letsencrypt/live/yourdomain.com/privkey.pem"
96
+ ```
97
+
98
+ ---
99
+
100
+ ## 🔄 Auto-start on boot (systemd)
101
+
102
+ ```bash
103
+ sudo nano /etc/systemd/system/syswatch.service
104
+ ```
105
+ ```ini
106
+ [Unit]
107
+ Description=SysWatch Linux Monitor
108
+ After=network.target
109
+
110
+ [Service]
111
+ Type=simple
112
+ User=root
113
+ ExecStart=/usr/bin/syswatch
114
+ Restart=on-failure
115
+
116
+ [Install]
117
+ WantedBy=multi-user.target
118
+ ```
119
+ ```bash
120
+ sudo systemctl daemon-reload
121
+ sudo systemctl enable --now syswatch
122
+ ```
123
+
124
+ ---
125
+
126
+ ## 📚 Learn Mode
127
+
128
+ Toggle **📖 Learn Mode** in the dashboard top-right. Every panel shows:
129
+ - The exact Linux command being run
130
+ - What each flag does
131
+ - The Node.js code that calls it
132
+
133
+ | Panel | Commands you learn |
134
+ |-------|--------------------|
135
+ | Overview | `/proc/stat` · `/proc/meminfo` · `/proc/loadavg` · `/proc/net/dev` |
136
+ | Services | `systemctl list-units` · `systemctl show` · `systemctl restart` |
137
+ | Logs | `journalctl -f -u nginx -p err -o json --since "1h ago"` |
138
+ | Processes | `ps aux` · `/proc/PID/stat` · `kill -9 PID` |
139
+ | Boot | `systemd-analyze blame` · `critical-chain` · `plot` |
140
+
141
+ ---
142
+
143
+ ## 🐧 Requirements
144
+
145
+ - **Linux** — Ubuntu 20.04+, Debian 11+, RHEL 8+, Arch, etc.
146
+ - **Node.js 18+** — https://nodejs.org
147
+ - **systemd** — for service control and journalctl
148
+ - **sudo/root** — needed for journal access and service control
149
+
150
+ ---
151
+
152
+ ## 📄 License
153
+
154
+ MIT
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ // ─────────────────────────────────────────────────────
3
+ // bin/gen-cert.js
4
+ // Generates a self-signed TLS cert for HTTPS mode.
5
+ // Uses openssl — must be installed on the system.
6
+ // Saves to: certs/key.pem + certs/cert.pem
7
+ // ─────────────────────────────────────────────────────
8
+ 'use strict';
9
+
10
+ const { execSync } = require('child_process');
11
+ const fs = require('fs');
12
+ const path = require('path');
13
+
14
+ const certsDir = path.join(__dirname, '..', 'certs');
15
+
16
+ function generateCert() {
17
+ if (!fs.existsSync(certsDir)) fs.mkdirSync(certsDir, { recursive: true });
18
+
19
+ const keyPath = path.join(certsDir, 'key.pem');
20
+ const certPath = path.join(certsDir, 'cert.pem');
21
+
22
+ if (fs.existsSync(keyPath) && fs.existsSync(certPath)) {
23
+ console.log('✓ Certificates already exist at certs/');
24
+ return { keyPath, certPath };
25
+ }
26
+
27
+ console.log('🔐 Generating self-signed TLS certificate...');
28
+
29
+ try {
30
+ execSync(
31
+ `openssl req -x509 -newkey rsa:2048 -keyout "${keyPath}" \
32
+ -out "${certPath}" -days 365 -nodes \
33
+ -subj "/CN=syswatch/O=SysWatch/C=US"`,
34
+ { stdio: 'pipe' }
35
+ );
36
+ console.log('✓ Certificates saved to certs/key.pem + certs/cert.pem');
37
+ console.log(' Note: Browser will warn "Not secure" for self-signed certs — that is normal.');
38
+ console.log(' For production, replace with Let\'s Encrypt certs.');
39
+ } catch (e) {
40
+ console.error('✗ openssl not found. Install it: sudo apt install openssl');
41
+ process.exit(1);
42
+ }
43
+
44
+ return { keyPath, certPath };
45
+ }
46
+
47
+ module.exports = { generateCert };
48
+
49
+ // run directly
50
+ if (require.main === module) generateCert();
@@ -0,0 +1,51 @@
1
+ #!/usr/bin/env node
2
+ // ─────────────────────────────────────────────────────
3
+ // SysWatch CLI — bin/syswatch.js
4
+ // Usage:
5
+ // npx syswatch # quick start HTTP
6
+ // npx syswatch --https # HTTP + HTTPS
7
+ // npx syswatch --port 9000 # custom port
8
+ // npx syswatch --host 0.0.0.0 # bind all interfaces
9
+ // npx syswatch --setup # interactive first-run wizard
10
+ // ─────────────────────────────────────────────────────
11
+ 'use strict';
12
+
13
+ const path = require('path');
14
+ const args = process.argv.slice(2);
15
+
16
+ // ── help ───────────────────────────────────────────────
17
+ if (args.includes('--help') || args.includes('-h')) {
18
+ console.log(`
19
+ ╔══════════════════════════════════════════╗
20
+ ║ SysWatch — Linux Monitor + Learn ║
21
+ ╚══════════════════════════════════════════╝
22
+
23
+ Usage:
24
+ npx syswatch [options]
25
+
26
+ Options:
27
+ --port <n> HTTP port (default: 8080)
28
+ --https-port <n> HTTPS port (default: 8443)
29
+ --host <ip> Bind address (default: 127.0.0.1)
30
+ --https Enable HTTPS too
31
+ --no-auth Disable password protection
32
+ --setup Run first-time setup wizard
33
+ --help Show this help
34
+
35
+ Examples:
36
+ npx syswatch # localhost:8080
37
+ npx syswatch --host 0.0.0.0 # LAN access
38
+ npx syswatch --https # HTTP + HTTPS
39
+ npx syswatch --port 3000 --no-auth # no password, port 3000
40
+ `);
41
+ process.exit(0);
42
+ }
43
+
44
+ // ── setup wizard ──────────────────────────────────────
45
+ if (args.includes('--setup')) {
46
+ // force re-run setup even if config exists
47
+ require('../src/setup').run(false);
48
+ } else {
49
+ // server.js will auto-detect missing config and run setup
50
+ require('../src/server');
51
+ }
package/package.json ADDED
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "saymon-syswatch-linux",
3
+ "version": "1.0.0",
4
+ "description": "Linux system monitor & learning dashboard — HTTP/HTTPS, journal logs, services, processes",
5
+ "main": "src/server.js",
6
+ "bin": {
7
+ "syswatch": "./bin/syswatch.js"
8
+ },
9
+ "scripts": {
10
+ "start": "node src/server.js",
11
+ "dev": "node src/server.js --dev",
12
+ "setup-https": "node bin/gen-cert.js"
13
+ },
14
+ "keywords": ["linux", "monitor", "systemd", "journalctl", "sysadmin", "dashboard", "learning"],
15
+ "author": "Saymon",
16
+ "license": "MIT",
17
+ "dependencies": {
18
+ "express": "^4.18.2",
19
+ "cors": "^2.8.5",
20
+ "bcrypt": "^5.1.1",
21
+ "jsonwebtoken": "^9.0.2",
22
+ "cookie-parser": "^1.4.6",
23
+ "express-rate-limit": "^7.1.5"
24
+ },
25
+ "engines": {
26
+ "node": ">=18.0.0"
27
+ }
28
+ }