added pm2 status page and updated others
This commit is contained in:
1 parent
39c2a3f1ef
commit
c07a08dfc0
9 files changed
+956
-162
No files matched your search
@@ -0,0 +1,180 @@
|
|||||||
|
// controllers/pm2Controller.js
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
|
function runPm2Command(args, onData) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const cmd = spawn('pm2', args);
|
||||||
|
let stdout = '';
|
||||||
|
let stderr = '';
|
||||||
|
|
||||||
|
cmd.stdout.on('data', data => {
|
||||||
|
const s = data.toString();
|
||||||
|
stdout += s;
|
||||||
|
if (onData) onData({ type: 'stdout', data: s });
|
||||||
|
});
|
||||||
|
|
||||||
|
cmd.stderr.on('data', data => {
|
||||||
|
const s = data.toString();
|
||||||
|
stderr += s;
|
||||||
|
if (onData) onData({ type: 'stderr', data: s });
|
||||||
|
});
|
||||||
|
|
||||||
|
cmd.on('close', code => resolve({ code, stdout, stderr }));
|
||||||
|
cmd.on('error', err => reject(err));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function humanUptime(pm_uptime) {
|
||||||
|
if (!pm_uptime || pm_uptime <= 0) return '—';
|
||||||
|
const diff = Date.now() - pm_uptime;
|
||||||
|
if (diff < 1000) return '0s';
|
||||||
|
const sec = Math.floor(diff / 1000);
|
||||||
|
const days = Math.floor(sec / 86400);
|
||||||
|
const hrs = Math.floor((sec % 86400) / 3600);
|
||||||
|
const mins = Math.floor((sec % 3600) / 60);
|
||||||
|
const parts = [];
|
||||||
|
if (days) parts.push(days + 'd');
|
||||||
|
if (hrs) parts.push(hrs + 'h');
|
||||||
|
if (mins) parts.push(mins + 'm');
|
||||||
|
if (!parts.length) parts.push((sec % 60) + 's');
|
||||||
|
return parts.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeProcess(p) {
|
||||||
|
const pid =
|
||||||
|
p.pid ||
|
||||||
|
(p.pm2_env && p.pm2_env.pm_pid) ||
|
||||||
|
(p.pm2_env && p.pm2_env.pmx && p.pm2_env.pmx.pid) ||
|
||||||
|
null;
|
||||||
|
|
||||||
|
const status = (p.pm2_env && p.pm2_env.status) || p.status || 'unknown';
|
||||||
|
|
||||||
|
let cpu = null, memoryMB = null;
|
||||||
|
if (p.monit) {
|
||||||
|
cpu = typeof p.monit.cpu === 'number' ? p.monit.cpu : null;
|
||||||
|
memoryMB = typeof p.monit.memory === 'number' ? Math.round(p.monit.memory / 1024 / 1024) : null;
|
||||||
|
} else if (p.pm2_env && p.pm2_env.axm_monitor) {
|
||||||
|
cpu = p.pm2_env.axm_monitor.cpu;
|
||||||
|
memoryMB = p.pm2_env.axm_monitor.memory ? Math.round(p.pm2_env.axm_monitor.memory / 1024 / 1024) : null;
|
||||||
|
} else if (p.pm2_env && p.pm2_env.monit) {
|
||||||
|
cpu = p.pm2_env.monit.cpu;
|
||||||
|
memoryMB = p.pm2_env.monit.memory ? Math.round(p.pm2_env.monit.memory / 1024 / 1024) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pm_uptime = (p.pm2_env && p.pm2_env.pm_uptime) || (p.pm_uptime || 0);
|
||||||
|
const uptime = humanUptime(pm_uptime);
|
||||||
|
|
||||||
|
return {
|
||||||
|
name: p.name || (p.pm2_env && p.pm2_env.name) || '—',
|
||||||
|
pid: pid || '—',
|
||||||
|
pm_id: (p.pm2_env && p.pm2_env.pm_id) || (p.pm_id !== undefined ? String(p.pm_id) : '—'),
|
||||||
|
status,
|
||||||
|
cpu: cpu != null ? Number(cpu).toFixed(1) + '%' : '—',
|
||||||
|
memoryMB: memoryMB != null ? memoryMB + ' MB' : '—',
|
||||||
|
uptime,
|
||||||
|
execPath:
|
||||||
|
(p.pm2_env && p.pm2_env.pm_exec_path) ||
|
||||||
|
(p.pm2_env && p.pm2_env.exec_interpreter) ||
|
||||||
|
'—',
|
||||||
|
raw: p
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// VIEW: Render UI
|
||||||
|
// ===============================
|
||||||
|
exports.getManage = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const { stdout } = await runPm2Command(['jlist']);
|
||||||
|
let processes = [];
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(stdout || '[]');
|
||||||
|
processes = Array.isArray(parsed) ? parsed.map(normalizeProcess) : [];
|
||||||
|
} catch (e) {
|
||||||
|
processes = [];
|
||||||
|
}
|
||||||
|
res.render('pm2', { title: 'PM2 Manager', processes });
|
||||||
|
} catch (err) {
|
||||||
|
next(err);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// JSON Process List
|
||||||
|
// ===============================
|
||||||
|
exports.listJson = async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { stdout } = await runPm2Command(['jlist']);
|
||||||
|
let processes = [];
|
||||||
|
try {
|
||||||
|
const parsed = JSON.parse(stdout || '[]');
|
||||||
|
processes = Array.isArray(parsed) ? parsed.map(normalizeProcess) : [];
|
||||||
|
} catch {
|
||||||
|
processes = [];
|
||||||
|
}
|
||||||
|
res.json({ ok: true, processes });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ ok: false, error: err.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// COMMAND EXECUTION
|
||||||
|
// ===============================
|
||||||
|
exports.postCommand = async (req, res) => {
|
||||||
|
// expected body: { cmd:'create'|'start'|'stop'|'restart'|'delete'|'save', name?, scriptPath? }
|
||||||
|
|
||||||
|
const allowed = new Set([
|
||||||
|
'start', 'stop', 'restart', 'delete', 'save', 'create'
|
||||||
|
]);
|
||||||
|
|
||||||
|
const { cmd, name, scriptPath } = req.body;
|
||||||
|
|
||||||
|
if (!allowed.has(cmd)) {
|
||||||
|
return res.status(400).json({ ok: false, error: 'Invalid command' });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let args = [];
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// CREATE = start script with name
|
||||||
|
// -------------------------------
|
||||||
|
if (cmd === 'create') {
|
||||||
|
if (!scriptPath || !name) {
|
||||||
|
return res.status(400).json({ ok: false, error: 'scriptPath and name required' });
|
||||||
|
}
|
||||||
|
if (!/^[\w-]+$/.test(name)) {
|
||||||
|
return res.status(400).json({ ok: false, error: 'Invalid process name' });
|
||||||
|
}
|
||||||
|
args = ['start', scriptPath, '--name', name];
|
||||||
|
console.log(args)
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// SAVE
|
||||||
|
// -------------------------------
|
||||||
|
else if (cmd === 'save') {
|
||||||
|
args = ['save'];
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------
|
||||||
|
// start/stop/restart/delete
|
||||||
|
// -------------------------------
|
||||||
|
else {
|
||||||
|
if (!name) {
|
||||||
|
return res.status(400).json({ ok: false, error: 'name is required' });
|
||||||
|
}
|
||||||
|
if (!/^[\w-]+$/.test(name)) {
|
||||||
|
return res.status(400).json({ ok: false, error: 'Invalid process name' });
|
||||||
|
}
|
||||||
|
args = [cmd, name];
|
||||||
|
}
|
||||||
|
|
||||||
|
const { code, stdout, stderr } = await runPm2Command(args);
|
||||||
|
res.json({ ok: code === 0, code, stdout, stderr });
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ ok: false, error: err.message });
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -33,6 +33,7 @@ header h1 {
|
|||||||
}
|
}
|
||||||
.btn-outline-light:hover {
|
.btn-outline-light:hover {
|
||||||
background-color: #5A5A5A;
|
background-color: #5A5A5A;
|
||||||
|
color: #c7c7c7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ===============================
|
/* ===============================
|
||||||
@@ -191,6 +192,25 @@ footer {
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#logs {
|
||||||
|
height: 60vh;
|
||||||
|
background: #0b1220;
|
||||||
|
color: #e6eef8;
|
||||||
|
padding: 10px;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid #444;
|
||||||
|
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ===============================
|
/* ===============================
|
||||||
RESPONSIVE
|
RESPONSIVE
|
||||||
=============================== */
|
=============================== */
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
|
// routes/index.js
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const queue = require("../controllers/queueController");
|
const queue = require("../controllers/queueController");
|
||||||
|
const pm2 = require("../controllers/pm2Controller");
|
||||||
const { getDb } = require("../lib/mongo");
|
const { getDb } = require("../lib/mongo");
|
||||||
|
|
||||||
// =======================
|
// =======================
|
||||||
@@ -77,4 +79,11 @@ router.post("/clear-queued", async (req, res) => {
|
|||||||
res.redirect("/status");
|
res.redirect("/status");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// =======================
|
||||||
|
// PM2 MANAGEMENT
|
||||||
|
// =======================
|
||||||
|
router.get("/pm2", pm2.getManage);
|
||||||
|
router.get("/pm2/list-json", pm2.listJson);
|
||||||
|
router.post("/pm2/command", pm2.postCommand);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
Binary file not shown.
@@ -1,8 +1,7 @@
|
|||||||
// server.js
|
// server.js (Improved Version B)
|
||||||
require('dotenv').config();
|
require('dotenv').config();
|
||||||
const express = require('express');
|
const express = require('express');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const morgan = require('morgan');
|
|
||||||
const bodyParser = require('body-parser');
|
const bodyParser = require('body-parser');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const WebSocket = require('ws');
|
const WebSocket = require('ws');
|
||||||
@@ -22,11 +21,6 @@ app.use(express.static(path.join(__dirname, 'public')));
|
|||||||
app.use(bodyParser.urlencoded({ extended: true }));
|
app.use(bodyParser.urlencoded({ extended: true }));
|
||||||
app.use(bodyParser.json());
|
app.use(bodyParser.json());
|
||||||
|
|
||||||
// Morgan: log only non-static requests
|
|
||||||
// app.use(morgan(':method :url :status :res[content-length] - :response-time ms', {
|
|
||||||
// skip: (req) => req.url.startsWith('/assets') || req.url.startsWith('/favicon.ico')
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// Routes
|
// Routes
|
||||||
app.use('/', indexRouter);
|
app.use('/', indexRouter);
|
||||||
|
|
||||||
@@ -40,28 +34,113 @@ app.use((err, req, res, next) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
// Wrap Express in HTTP + WS
|
// HTTP + WebSocket server
|
||||||
// -----------------------------
|
// -----------------------------
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
const wss = new WebSocket.Server({ server });
|
const wss = new WebSocket.Server({ server });
|
||||||
|
|
||||||
// When a client connects, stream PM2 logs
|
// Heartbeat for detecting dead connections
|
||||||
wss.on('connection', ws => {
|
function heartbeat() {
|
||||||
const pm2Logs = spawn('pm2', ['logs', '--json']);
|
this.isAlive = true;
|
||||||
|
}
|
||||||
|
|
||||||
pm2Logs.stdout.on('data', data => {
|
wss.on('connection', ws => {
|
||||||
ws.send(data.toString());
|
ws.isAlive = true;
|
||||||
|
ws.on('pong', heartbeat);
|
||||||
|
|
||||||
|
let child = null;
|
||||||
|
|
||||||
|
ws.send(JSON.stringify({ type: 'connected', message: 'ws ready' }));
|
||||||
|
|
||||||
|
ws.on('message', msg => {
|
||||||
|
let payload;
|
||||||
|
try {
|
||||||
|
payload = JSON.parse(msg.toString());
|
||||||
|
} catch {
|
||||||
|
ws.send(JSON.stringify({ type: 'error', error: 'Invalid JSON' }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// START LOGS
|
||||||
|
// -----------------------------
|
||||||
|
if (payload.type === 'logs') {
|
||||||
|
const name = payload.name || null;
|
||||||
|
|
||||||
|
// Clean previous child
|
||||||
|
if (child) {
|
||||||
|
try { child.kill(); } catch {}
|
||||||
|
child = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Correct PM2 argument ordering
|
||||||
|
const args = ['logs', '--raw', '--lines', '200'];
|
||||||
|
if (name) args.splice(1, 0, name);
|
||||||
|
|
||||||
|
try {
|
||||||
|
child = spawn('pm2', args);
|
||||||
|
|
||||||
|
child.stdout.on('data', data => {
|
||||||
|
ws.send(JSON.stringify({ type: 'stdout', data: data.toString() }));
|
||||||
});
|
});
|
||||||
|
|
||||||
pm2Logs.stderr.on('data', data => {
|
child.stderr.on('data', data => {
|
||||||
ws.send('ERROR: ' + data.toString());
|
ws.send(JSON.stringify({ type: 'stderr', data: data.toString() }));
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('close', code => {
|
||||||
|
ws.send(JSON.stringify({ type: 'close', code }));
|
||||||
|
child = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
child.on('error', err => {
|
||||||
|
ws.send(JSON.stringify({ type: 'error', error: err.message }));
|
||||||
|
child = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
ws.send(JSON.stringify({ type: 'info', message: `started logs for ${name || 'all'}` }));
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
ws.send(JSON.stringify({ type: 'error', error: err.message }));
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// -----------------------------
|
||||||
|
// STOP LOGS
|
||||||
|
// -----------------------------
|
||||||
|
if (payload.type === 'stop-logs') {
|
||||||
|
if (child) {
|
||||||
|
try { child.kill(); } catch {}
|
||||||
|
child = null;
|
||||||
|
}
|
||||||
|
ws.send(JSON.stringify({ type: 'info', message: 'logs stopped' }));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.send(JSON.stringify({ type: 'error', error: 'Unknown type' }));
|
||||||
});
|
});
|
||||||
|
|
||||||
ws.on('close', () => {
|
ws.on('close', () => {
|
||||||
pm2Logs.kill();
|
if (child) {
|
||||||
|
try { child.kill(); } catch {}
|
||||||
|
child = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Ping-pong interval every 30s
|
||||||
|
setInterval(() => {
|
||||||
|
wss.clients.forEach(ws => {
|
||||||
|
if (!ws.isAlive) return ws.terminate();
|
||||||
|
|
||||||
|
ws.isAlive = false;
|
||||||
|
ws.ping(); // triggers 'pong'
|
||||||
|
});
|
||||||
|
}, 30000);
|
||||||
|
|
||||||
|
// Start server
|
||||||
server.listen(PORT, () =>
|
server.listen(PORT, () =>
|
||||||
console.log(`Proxer-Downloader running on http://localhost:${PORT}`)
|
console.log(`Proxer-Downloader running on http://localhost:${PORT}`)
|
||||||
);
|
);
|
||||||
+25
-17
@@ -17,26 +17,35 @@
|
|||||||
<!-- SERIES FIELDS -->
|
<!-- SERIES FIELDS -->
|
||||||
<div id="seriesFields">
|
<div id="seriesFields">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Series ID</label>
|
<label class="form-label">ID</label>
|
||||||
<input class="form-control" name="id" placeholder="12345" />
|
<input
|
||||||
|
class="form-control"
|
||||||
|
name="id"
|
||||||
|
type="number"
|
||||||
|
placeholder="ID"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- UPDATED: EPISODE RANGE (FROM / TO) -->
|
<!-- UPDATED: EPISODE RANGE (FROM / TO) -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Episode Range</label>
|
<label class="form-label">Episodes</label>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<input
|
<input
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="episode_from"
|
name="episode_from"
|
||||||
placeholder="From (e.g. 1)"
|
type="number"
|
||||||
|
min="1"
|
||||||
|
placeholder="From"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<input
|
<input
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="episode_to"
|
name="episode_to"
|
||||||
placeholder="To (e.g. 12)"
|
type="number"
|
||||||
|
min="1"
|
||||||
|
placeholder="To"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -45,19 +54,19 @@
|
|||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Language</label>
|
<label class="form-label">Language</label>
|
||||||
<select class="form-select" name="language">
|
<select class="form-select" name="language">
|
||||||
<option value="engsub">engsub</option>
|
<option value="engsub">EngSub</option>
|
||||||
<option value="engdub">engdub</option>
|
<option value="engdub">EngDub</option>
|
||||||
<option value="gersub">gersub</option>
|
<option value="gersub">GerSub</option>
|
||||||
<option value="gerdub">gerdub</option>
|
<option value="gerdub">GerDub</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Name (optional)</label>
|
<label class="form-label">Titel (ohne Extension)</label>
|
||||||
<input
|
<input
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="name"
|
name="name"
|
||||||
placeholder="OnePiece_1_engsub"
|
placeholder="Titel S01E01"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -65,7 +74,7 @@
|
|||||||
<!-- VIDEO FIELDS -->
|
<!-- VIDEO FIELDS -->
|
||||||
<div id="videoFields" style="display: none">
|
<div id="videoFields" style="display: none">
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Video URL</label>
|
<label class="form-label">URL</label>
|
||||||
<input
|
<input
|
||||||
class="form-control"
|
class="form-control"
|
||||||
name="url"
|
name="url"
|
||||||
@@ -74,16 +83,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Filename (optional)</label>
|
<label class="form-label">Speichern Als</label>
|
||||||
<input class="form-control" name="filename" placeholder="MyVideo.mp4" />
|
<input class="form-control" name="filename" placeholder="Titel S01E01.mp4" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- TOKEN -->
|
<!-- TOKEN -->
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label class="form-label">Token suffix</label>
|
<label class="form-label">Token</label>
|
||||||
<input class="form-control" name="token" placeholder="user-token" />
|
<input class="form-control" name="token" placeholder="Token" />
|
||||||
<div class="form-text">Full token = TOKEN_PREFIX + this value</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="d-flex justify-content-between">
|
<div class="d-flex justify-content-between">
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
<nav class="d-flex gap-2">
|
<nav class="d-flex gap-2">
|
||||||
<a class="btn btn-outline-light" href="/">Home</a>
|
<a class="btn btn-outline-light" href="/">Home</a>
|
||||||
<a class="btn btn-outline-light" href="/status">Status</a>
|
<a class="btn btn-outline-light" href="/status">Status</a>
|
||||||
|
<a class="btn btn-outline-light" href="/pm2">PM2</a>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|||||||
+448
@@ -0,0 +1,448 @@
|
|||||||
|
<%- include('partials/header') %>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* Dark theme PM2 CSS (integrates with your style.css) */
|
||||||
|
.pm2-row { cursor: pointer; border: 1px solid #4A4A4A; }
|
||||||
|
.pm2-row.active, .pm2-row.selected-outline {
|
||||||
|
background-color: #555 !important;
|
||||||
|
border-color: #8A190B !important;
|
||||||
|
box-shadow: 0 0 0 2px rgba(138,25,11,0.4);
|
||||||
|
}
|
||||||
|
|
||||||
|
#logs {
|
||||||
|
height: 60vh;
|
||||||
|
background: #0b1220;
|
||||||
|
color: #e6eef8;
|
||||||
|
padding: 10px;
|
||||||
|
font-family: monospace;
|
||||||
|
font-size: 0.85rem;
|
||||||
|
overflow-y: auto;
|
||||||
|
border-radius: 8px;
|
||||||
|
border: 1px solid #444;
|
||||||
|
|
||||||
|
white-space: pre-wrap;
|
||||||
|
word-break: break-word;
|
||||||
|
overflow-wrap: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.kv-label { width: 110px; display: inline-block; color: #C0C0C0; }
|
||||||
|
.kv-value { font-weight: bold; color: #ffffff; }
|
||||||
|
.subtle { color: #BEBEBE; font-size: 0.85rem; }
|
||||||
|
|
||||||
|
.badge-small { font-size: .75rem; padding: .25rem .5rem; border-radius: .4rem; }
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="container py-3" style="max-width:1300px;">
|
||||||
|
|
||||||
|
<div class="row g-3">
|
||||||
|
|
||||||
|
<!-- LEFT COLUMN — PROCESS LIST & CONTROL CENTRE -->
|
||||||
|
<div class="col-md-5 d-flex">
|
||||||
|
<div class="card-dark w-100 d-flex flex-column">
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between mb-2">
|
||||||
|
<div>
|
||||||
|
<h4 class="mb-0">PM2 Processes</h4>
|
||||||
|
<div class="subtle">Select a process to manage and view details.</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="d-flex gap-2 align-items-center">
|
||||||
|
<button id="refresh-list" class="btn btn-sm btn-outline-light">⟳</button>
|
||||||
|
|
||||||
|
<!-- NEW: ONE-CLICK CREATE -->
|
||||||
|
<button id="btn-create" class="btn btn-sm btn-success">
|
||||||
|
<strong>+</strong>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- PROCESS LIST -->
|
||||||
|
<div id="process-list" class="list-group" style="max-height:40vh; overflow-y:auto;">
|
||||||
|
<% if (processes && processes.length) { %>
|
||||||
|
<% processes.forEach(p => {
|
||||||
|
let status = (p.status || '').toLowerCase();
|
||||||
|
let badge = 'bg-secondary';
|
||||||
|
if (status === 'online' || status === 'running') badge = 'bg-success';
|
||||||
|
else if (status.includes('stop') || status.includes('exit')) badge = 'bg-danger';
|
||||||
|
else if (status.includes('launch') || status.includes('start')) badge = 'bg-warning text-dark';
|
||||||
|
%>
|
||||||
|
<a href="#"
|
||||||
|
class="list-group-item pm2-row d-flex justify-content-between"
|
||||||
|
data-name="<%= p.name %>"
|
||||||
|
data-pid="<%= p.pid %>"
|
||||||
|
data-pmid="<%= p.pm_id %>"
|
||||||
|
data-status="<%= p.status %>"
|
||||||
|
>
|
||||||
|
<div>
|
||||||
|
<strong><%= p.name %></strong>
|
||||||
|
<span class="badge badge-small <%= badge %>"><%= p.status %></span>
|
||||||
|
<div class="subtle"><%= p.execPath %></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="text-end">
|
||||||
|
<div>pid: <span><%= p.pid %></span></div>
|
||||||
|
<div class="subtle"><%= p.uptime %></div>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
<% }) %>
|
||||||
|
<% } else { %>
|
||||||
|
<div class="alert alert-warning">No PM2 processes found.</div>
|
||||||
|
<% } %>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- CONTROL CENTRE -->
|
||||||
|
<div id="control-centre" class="mt-3 p-3" style="display:none; background:#3A3A3A; border-radius:8px; border:1px solid #555;">
|
||||||
|
<h5 id="cc-name">Process Name</h5>
|
||||||
|
<div id="cc-sub" class="subtle mb-2">pm_id / pid / status</div>
|
||||||
|
|
||||||
|
<!-- Quick actions -->
|
||||||
|
<div class="d-flex flex-wrap gap-2 mb-3">
|
||||||
|
<button id="btn-start" class="btn btn-success btn-sm">Start</button>
|
||||||
|
<button id="btn-stop" class="btn btn-danger btn-sm">Stop</button>
|
||||||
|
<button id="btn-restart" class="btn btn-warning btn-sm">Restart</button>
|
||||||
|
<button id="btn-delete" class="btn btn-outline-light btn-sm">Delete</button>
|
||||||
|
<button id="btn-save" class="btn btn-outline-light btn-sm">Save</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Details -->
|
||||||
|
<div class="small">
|
||||||
|
<div><span class="kv-label">PM2 name</span> <span class="kv-value" id="detail-name">—</span></div>
|
||||||
|
<div><span class="kv-label">PM2 id</span> <span class="kv-value" id="detail-pmid">—</span></div>
|
||||||
|
<div><span class="kv-label">PID</span> <span class="kv-value" id="detail-pid">—</span></div>
|
||||||
|
<div><span class="kv-label">Status</span> <span class="kv-value" id="detail-status">—</span></div>
|
||||||
|
<div><span class="kv-label">Uptime</span> <span class="kv-value" id="detail-uptime">—</span></div>
|
||||||
|
<div><span class="kv-label">CPU</span> <span class="kv-value" id="detail-cpu">—</span></div>
|
||||||
|
<div><span class="kv-label">Memory</span> <span class="kv-value" id="detail-mem">—</span></div>
|
||||||
|
<div><span class="kv-label">Exec Path</span> <span class="kv-value" id="detail-exec">—</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<pre id="control-output" class="mt-3 p-2" style="background:#0b0b0b; height:110px; overflow:auto; border-radius:6px;">Actions output will appear here.</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- RIGHT COLUMN — LOGS -->
|
||||||
|
<div class="col-md-7 d-flex">
|
||||||
|
<div class="card-dark w-100 d-flex flex-column">
|
||||||
|
|
||||||
|
<div class="d-flex justify-content-between mb-2">
|
||||||
|
<h4>Logs</h4>
|
||||||
|
<div class="d-flex gap-2">
|
||||||
|
<button id="clear-logs" class="btn btn-outline-light btn-sm">Clear</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="logs">[no logs yet]</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
/* ============================================================
|
||||||
|
WEBSOCKET LOG CONNECTION
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
const ws = new WebSocket(
|
||||||
|
(location.protocol === 'https:' ? 'wss://' : 'ws://') + location.host
|
||||||
|
);
|
||||||
|
|
||||||
|
const logsEl = document.getElementById("logs");
|
||||||
|
|
||||||
|
function appendLog(msg) {
|
||||||
|
const line = `[${new Date().toLocaleTimeString()}] ${msg}`;
|
||||||
|
logsEl.textContent += line + "\n";
|
||||||
|
logsEl.scrollTop = logsEl.scrollHeight; // auto-scroll always
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.addEventListener("open", () => appendLog("[ws connected]"));
|
||||||
|
ws.addEventListener("close", () => appendLog("[ws closed]"));
|
||||||
|
|
||||||
|
ws.addEventListener("message", ev => {
|
||||||
|
let obj;
|
||||||
|
try { obj = JSON.parse(ev.data); } catch { appendLog(ev.data); return; }
|
||||||
|
|
||||||
|
if (obj.type === "stdout") appendLog(obj.data);
|
||||||
|
else if (obj.type === "stderr") appendLog(obj.data);
|
||||||
|
else if (obj.type === "info") appendLog("[info] " + obj.message);
|
||||||
|
else if (obj.type === "error") appendLog("[error] " + obj.error);
|
||||||
|
else if (obj.type === "close") appendLog("[log stream closed]");
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
PROCESS SELECTION & DETAILS
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
let selectedEl = null;
|
||||||
|
let selectedData = null;
|
||||||
|
|
||||||
|
function clearSelection() {
|
||||||
|
document.querySelectorAll('.pm2-row')
|
||||||
|
.forEach(r => r.classList.remove('active', 'selected-outline'));
|
||||||
|
selectedEl = null;
|
||||||
|
selectedData = null;
|
||||||
|
document.getElementById("control-centre").style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
function populateControlCentre(d) {
|
||||||
|
document.getElementById("cc-name").innerText = d.name;
|
||||||
|
document.getElementById("cc-sub").innerText =
|
||||||
|
`pm_id: ${d.pmid} • pid: ${d.pid} • status: ${d.status}`;
|
||||||
|
|
||||||
|
document.getElementById("detail-name").innerText = d.name;
|
||||||
|
document.getElementById("detail-pmid").innerText = d.pmid;
|
||||||
|
document.getElementById("detail-pid").innerText = d.pid;
|
||||||
|
document.getElementById("detail-status").innerText = d.status;
|
||||||
|
document.getElementById("detail-uptime").innerText = d.uptime;
|
||||||
|
document.getElementById("detail-cpu").innerText = d.cpu;
|
||||||
|
document.getElementById("detail-mem").innerText = d.memoryMB;
|
||||||
|
document.getElementById("detail-exec").innerText = d.execPath;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchFullProcess(name) {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/pm2/list-json');
|
||||||
|
const json = await res.json();
|
||||||
|
if (!json.ok) return null;
|
||||||
|
return json.processes.find(p => p.name === name) || null;
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindRowEvents() {
|
||||||
|
document.querySelectorAll('.pm2-row').forEach(row => {
|
||||||
|
row.addEventListener('click', async ev => {
|
||||||
|
ev.preventDefault();
|
||||||
|
|
||||||
|
// toggle deselect
|
||||||
|
if (selectedEl === row) {
|
||||||
|
clearSelection();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// highlight selected
|
||||||
|
document.querySelectorAll('.pm2-row')
|
||||||
|
.forEach(r => r.classList.remove('active', 'selected-outline'));
|
||||||
|
row.classList.add('active', 'selected-outline');
|
||||||
|
selectedEl = row;
|
||||||
|
|
||||||
|
// base data
|
||||||
|
selectedData = {
|
||||||
|
name: row.dataset.name,
|
||||||
|
pmid: row.dataset.pmid,
|
||||||
|
pid: row.dataset.pid,
|
||||||
|
status: row.dataset.status
|
||||||
|
};
|
||||||
|
|
||||||
|
// fetch detailed data
|
||||||
|
const full = await fetchFullProcess(selectedData.name);
|
||||||
|
if (full) {
|
||||||
|
selectedData = {
|
||||||
|
name: full.name,
|
||||||
|
pmid: full.pm_id,
|
||||||
|
pid: full.pid,
|
||||||
|
status: full.status,
|
||||||
|
uptime: full.uptime,
|
||||||
|
cpu: full.cpu,
|
||||||
|
memoryMB: full.memoryMB,
|
||||||
|
execPath: full.execPath
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
populateControlCentre(selectedData);
|
||||||
|
document.getElementById("control-centre").style.display = "block";
|
||||||
|
|
||||||
|
// AUTO-START LOGS
|
||||||
|
ws.send(JSON.stringify({
|
||||||
|
type: "logs",
|
||||||
|
name: selectedData.name
|
||||||
|
}));
|
||||||
|
appendLog("[auto logs for: " + selectedData.name + "]");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
bindRowEvents();
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
REFRESH PROCESS LIST
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
async function refreshList() {
|
||||||
|
try {
|
||||||
|
const res = await fetch('/pm2/list-json');
|
||||||
|
const json = await res.json();
|
||||||
|
if (!json.ok) return;
|
||||||
|
|
||||||
|
const list = document.getElementById("process-list");
|
||||||
|
list.innerHTML = '';
|
||||||
|
|
||||||
|
json.processes.forEach(p => {
|
||||||
|
let status = (p.status || '').toLowerCase();
|
||||||
|
let badge = 'bg-secondary';
|
||||||
|
if (status === 'online' || status === 'running') badge = 'bg-success';
|
||||||
|
else if (status.includes('stop') || status.includes('exit')) badge = 'bg-danger';
|
||||||
|
else if (status.includes('start') || status.includes('launch')) badge = 'bg-warning text-dark';
|
||||||
|
|
||||||
|
const item = document.createElement('a');
|
||||||
|
item.href = "#";
|
||||||
|
item.className = "list-group-item pm2-row d-flex justify-content-between";
|
||||||
|
item.dataset.name = p.name;
|
||||||
|
item.dataset.pid = p.pid;
|
||||||
|
item.dataset.pmid = p.pm_id;
|
||||||
|
item.dataset.status = p.status;
|
||||||
|
|
||||||
|
item.innerHTML = `
|
||||||
|
<div>
|
||||||
|
<strong>${p.name}</strong>
|
||||||
|
<span class="badge badge-small ${badge}">${p.status}</span>
|
||||||
|
<div class="subtle">${p.execPath}</div>
|
||||||
|
</div>
|
||||||
|
<div class="text-end">
|
||||||
|
<div>pid: <span>${p.pid}</span></div>
|
||||||
|
<div class="subtle">${p.uptime}</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
|
||||||
|
list.appendChild(item);
|
||||||
|
});
|
||||||
|
|
||||||
|
bindRowEvents();
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("refresh-list").addEventListener("click", refreshList);
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
PM2 COMMAND EXECUTION
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
async function execCommand(payload, outEl) {
|
||||||
|
outEl.textContent = "Running...";
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch('/pm2/command', {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
outEl.textContent = JSON.stringify(json, null, 2);
|
||||||
|
|
||||||
|
if (json.ok) refreshList();
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
outEl.textContent = "Error: " + err.message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
ONE-CLICK CREATE WORKER
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
async function findNextWorkerName() {
|
||||||
|
const res = await fetch('/pm2/list-json');
|
||||||
|
const json = await res.json();
|
||||||
|
if (!json.ok) return "proxerdl-worker1";
|
||||||
|
|
||||||
|
const names = json.processes
|
||||||
|
.map(p => p.name)
|
||||||
|
.filter(n => /^proxerdl-worker\d+$/.test(n));
|
||||||
|
|
||||||
|
const nums = names.map(n => parseInt(n.replace("proxerdl-worker", ""), 10));
|
||||||
|
|
||||||
|
if (nums.length === 0) return "proxerdl-worker1";
|
||||||
|
|
||||||
|
nums.sort((a, b) => a - b);
|
||||||
|
|
||||||
|
let next = 1;
|
||||||
|
for (let n of nums) {
|
||||||
|
if (n === next) next++;
|
||||||
|
else if (n > next) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "proxerdl-worker" + next;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.getElementById("btn-create").addEventListener("click", async () => {
|
||||||
|
const out = document.getElementById("control-output");
|
||||||
|
|
||||||
|
try {
|
||||||
|
const name = await findNextWorkerName();
|
||||||
|
const scriptPath = "/home/pm2/Proxer-Downloader/queue_worker.js";
|
||||||
|
|
||||||
|
out.textContent = "Creating " + name + "...";
|
||||||
|
|
||||||
|
const res = await fetch('/pm2/command', {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
cmd: "create",
|
||||||
|
name,
|
||||||
|
scriptPath
|
||||||
|
})
|
||||||
|
});
|
||||||
|
|
||||||
|
const json = await res.json();
|
||||||
|
out.textContent = JSON.stringify(json, null, 2);
|
||||||
|
|
||||||
|
if (json.ok) {
|
||||||
|
await refreshList();
|
||||||
|
|
||||||
|
const row = [...document.querySelectorAll(".pm2-row")]
|
||||||
|
.find(r => r.dataset.name === name);
|
||||||
|
|
||||||
|
if (row) row.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
out.textContent = "Error: " + err.message;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
QUICK ACTION BUTTONS
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
document.getElementById("btn-start").addEventListener("click", () => {
|
||||||
|
if (!selectedData) return alert("Select a process.");
|
||||||
|
execCommand({ cmd: "start", name: selectedData.name }, document.getElementById("control-output"));
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("btn-stop").addEventListener("click", () => {
|
||||||
|
if (!selectedData) return alert("Select a process.");
|
||||||
|
execCommand({ cmd: "stop", name: selectedData.name }, document.getElementById("control-output"));
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("btn-restart").addEventListener("click", () => {
|
||||||
|
if (!selectedData) return alert("Select a process.");
|
||||||
|
execCommand({ cmd: "restart", name: selectedData.name }, document.getElementById("control-output"));
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("btn-delete").addEventListener("click", () => {
|
||||||
|
if (!selectedData) return alert("Select a process.");
|
||||||
|
execCommand({ cmd: "delete", name: selectedData.name }, document.getElementById("control-output"));
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById("btn-save").addEventListener("click", () => {
|
||||||
|
execCommand({ cmd: "save" }, document.getElementById("control-output"));
|
||||||
|
});
|
||||||
|
|
||||||
|
/* ============================================================
|
||||||
|
LOG ACTIONS
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
|
document.getElementById("clear-logs").addEventListener("click", () => {
|
||||||
|
logsEl.textContent = "";
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<%- include('partials/footer') %>
|
||||||
+178
-129
@@ -1,156 +1,225 @@
|
|||||||
<%- include("partials/header") %>
|
<%- include("partials/header") %>
|
||||||
|
|
||||||
<div class="row">
|
<style>
|
||||||
|
.status-card {
|
||||||
|
background: #3A3A3A;
|
||||||
|
border-radius: 10px;
|
||||||
|
border: 1px solid #444;
|
||||||
|
padding: 15px;
|
||||||
|
box-shadow: 0 4px 12px rgba(0,0,0,0.35);
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-title {
|
||||||
|
margin: 0;
|
||||||
|
font-size: 1.6rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-box {
|
||||||
|
background:#001122;
|
||||||
|
color:#9cf;
|
||||||
|
padding:10px;
|
||||||
|
border-radius:5px;
|
||||||
|
white-space:pre-wrap;
|
||||||
|
overflow-wrap:break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-box-light {
|
||||||
|
background:#222;
|
||||||
|
color:#e0e0e0;
|
||||||
|
padding:10px;
|
||||||
|
border-radius:5px;
|
||||||
|
white-space:pre-wrap;
|
||||||
|
overflow-wrap:break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-box-error {
|
||||||
|
background:#330000;
|
||||||
|
color:#ffb3b3;
|
||||||
|
padding:10px;
|
||||||
|
border-radius:5px;
|
||||||
|
white-space:pre-wrap;
|
||||||
|
overflow-wrap:break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
.section-header {
|
||||||
|
display:flex;
|
||||||
|
justify-content:center;
|
||||||
|
align-items:center;
|
||||||
|
margin-bottom:10px;
|
||||||
|
gap:6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.list-group-item {
|
||||||
|
background:#3A3A3A;
|
||||||
|
border-color:#4A4A4A;
|
||||||
|
}
|
||||||
|
|
||||||
|
details summary {
|
||||||
|
cursor:pointer;
|
||||||
|
margin-top:6px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="row g-3">
|
||||||
|
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<!-- QUEUED -->
|
<!-- QUEUED -->
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3 text-center">
|
<div class="col-md-3">
|
||||||
<div class="d-flex justify-content-center align-items-center mb-2">
|
<div class="status-card text-center">
|
||||||
<h3 class="mb-0">Queued</h3>
|
|
||||||
<form id="clear-queued-form" action="/clear-queued" method="POST" class="ms-2">
|
<div class="section-header">
|
||||||
<button class="btn btn-outline-secondary btn-sm shadow-sm rounded-pill">
|
<h3 class="status-title">Queued</h3>
|
||||||
🗑️
|
<form action="/clear-queued" method="POST">
|
||||||
</button>
|
<button class="btn btn-outline-secondary btn-sm rounded-pill">🗑️</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="list-group" id="queuedList">
|
<ul class="list-group" id="queuedList">
|
||||||
|
<% if (queued.length === 0) { %>
|
||||||
|
<li class="list-group-item ">No queued jobs</li>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% queued.forEach(job => { %>
|
<% queued.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong><%= job.filename %></strong><br />
|
<strong><%= job.filename %></strong><br>
|
||||||
<small><%= job.url %></small><br />
|
<small><%= job.url %></small><br>
|
||||||
<small><%= new Date(job.created_at).toLocaleString() %></small>
|
<small><%= new Date(job.created_at).toLocaleString() %></small>
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
<% if (queued.length === 0) { %>
|
|
||||||
<li class="list-group-item">No queued jobs</li>
|
|
||||||
<% } %>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<!-- PROCESSING -->
|
<!-- PROCESSING -->
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3 text-center">
|
<div class="col-md-3">
|
||||||
<div class="d-flex justify-content-center align-items-center mb-2">
|
<div class="status-card text-center">
|
||||||
<h3 class="mb-0" style="color:#58a6ff">Processing</h3>
|
|
||||||
<form id="clear-processing-form" action="/clear-processing" method="POST" class="ms-2">
|
<div class="section-header">
|
||||||
<button class="btn btn-outline-primary btn-sm shadow-sm rounded-pill">
|
<h3 class="status-title" style="color:#58a6ff;">Processing</h3>
|
||||||
🗑️
|
<form action="/clear-processing" method="POST">
|
||||||
</button>
|
<button class="btn btn-outline-primary btn-sm rounded-pill">🗑️</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="list-group" id="processingList">
|
<ul class="list-group" id="processingList">
|
||||||
|
<% if (processing.length === 0) { %>
|
||||||
|
<li class="list-group-item ">Nothing processing</li>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% processing.forEach(job => { %>
|
<% processing.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong style="color:#58a6ff"><%= job.filename %></strong>
|
<strong style="color:#58a6ff"><%= job.filename %></strong>
|
||||||
<span class="spinner-border spinner-border-sm ms-2" style="color:#58a6ff"></span><br>
|
<span class="spinner-border spinner-border-sm ms-1" style="color:#58a6ff"></span><br>
|
||||||
<small><%= job.url %></small><br>
|
<small><%= job.url %></small><br>
|
||||||
<small>Started: <%= new Date(job.created_at).toLocaleString() %></small>
|
<small>Started: <%= new Date(job.created_at).toLocaleString() %></small><br>
|
||||||
|
|
||||||
<% if (job.fileSize) { %>
|
<% if (job.fileSize) { %>
|
||||||
<br><small>Downloaded: <%= job.fileSize %></small>
|
<small>Downloaded: <%= job.fileSize %></small>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
<% if (job.output_log) { %>
|
<% if (job.output_log) { %>
|
||||||
<details class="mt-2">
|
<details data-id="processing-<%= job._id %>">
|
||||||
<summary class="text-light">Live Log</summary>
|
<summary class="text-light">Live Log</summary>
|
||||||
<pre style="background:#001122; color:#9cf; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre class="log-box"><%- job.output_log %></pre>
|
||||||
<%= job.output_log %>
|
|
||||||
</pre>
|
|
||||||
</details>
|
</details>
|
||||||
<% } %>
|
<% } %>
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
<% if (processing.length === 0) { %>
|
|
||||||
<li class="list-group-item">Nothing processing</li>
|
|
||||||
<% } %>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<!-- DONE -->
|
<!-- DONE -->
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3 text-center">
|
<div class="col-md-3">
|
||||||
<div class="d-flex justify-content-center align-items-center mb-2">
|
<div class="status-card text-center">
|
||||||
<h3 class="text-success mb-0">Done</h3>
|
|
||||||
<form id="clear-done-form" action="/clear-done" method="POST" class="ms-2">
|
<div class="section-header">
|
||||||
<button class="btn btn-outline-success btn-sm shadow-sm rounded-pill">
|
<h3 class="status-title text-success">Done</h3>
|
||||||
🗑️
|
<form action="/clear-done" method="POST">
|
||||||
</button>
|
<button class="btn btn-outline-success btn-sm rounded-pill">🗑️</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="list-group" id="doneList">
|
<ul class="list-group" id="doneList">
|
||||||
|
<% if (finished.length === 0) { %>
|
||||||
|
<li class="list-group-item ">No completed jobs</li>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% finished.forEach(job => { %>
|
<% finished.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong class="text-success"><%= job.filename %></strong><br />
|
|
||||||
|
<strong class="text-success"><%= job.filename %></strong><br>
|
||||||
<small><%= new Date(job.finished_at).toLocaleString() %></small><br>
|
<small><%= new Date(job.finished_at).toLocaleString() %></small><br>
|
||||||
|
|
||||||
<% if (job.fileSize) { %>
|
<% if (job.fileSize) { %>
|
||||||
<small>Size: <%= job.fileSize %></small><br>
|
<small>Size: <%= job.fileSize %></small><br>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
<% if (job.output_log) { %>
|
<% if (job.output_log) { %>
|
||||||
<details class="mt-2">
|
<details data-id="done-<%= job._id %>">
|
||||||
<summary class="text-light">Show Log</summary>
|
<summary class="text-light">Show Log</summary>
|
||||||
<pre style="background:#222; color:#e0e0e0; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre class="log-box-light"><%- job.output_log %></pre>
|
||||||
<%= job.output_log %>
|
|
||||||
</pre>
|
|
||||||
</details>
|
</details>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
<% if (finished.length === 0) { %>
|
|
||||||
<li class="list-group-item">No completed jobs</li>
|
|
||||||
<% } %>
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<!-- FAILED -->
|
<!-- FAILED -->
|
||||||
<!-- ======================= -->
|
<!-- ======================= -->
|
||||||
<div class="col-md-3 text-center">
|
<div class="col-md-3">
|
||||||
<div class="d-flex justify-content-center align-items-center mb-2">
|
<div class="status-card text-center">
|
||||||
<h3 class="text-danger mb-0">Failed</h3>
|
|
||||||
<form id="clear-failed-form" action="/clear-failed" method="POST" class="ms-2">
|
<div class="section-header">
|
||||||
<button class="btn btn-outline-danger btn-sm shadow-sm rounded-pill">
|
<h3 class="status-title text-danger">Failed</h3>
|
||||||
🗑️
|
<form action="/clear-failed" method="POST">
|
||||||
</button>
|
<button class="btn btn-outline-danger btn-sm rounded-pill">🗑️</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul class="list-group" id="failedList">
|
<ul class="list-group" id="failedList">
|
||||||
|
<% if (failed.length === 0) { %>
|
||||||
|
<li class="list-group-item ">No failed jobs</li>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% failed.forEach(job => { %>
|
<% failed.forEach(job => { %>
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong class="text-danger"><%= job.filename %></strong><br />
|
|
||||||
|
<strong class="text-danger"><%= job.filename %></strong><br>
|
||||||
<small><%= new Date(job.failed_at).toLocaleString() %></small><br>
|
<small><%= new Date(job.failed_at).toLocaleString() %></small><br>
|
||||||
|
|
||||||
<% if (job.output_log) { %>
|
<% if (job.output_log) { %>
|
||||||
<details class="mt-2">
|
<details data-id="failed-<%= job._id %>">
|
||||||
<summary class="text-danger">Show Error Log</summary>
|
<summary class="text-danger">Show Error Log</summary>
|
||||||
<pre style="background:#330000; color:#ffb3b3; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre class="log-box-error"><%- job.output_log %></pre>
|
||||||
<%= job.output_log %>
|
|
||||||
</pre>
|
|
||||||
</details>
|
</details>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
</li>
|
</li>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
<% if (failed.length === 0) { %>
|
|
||||||
<li class="list-group-item">No failed jobs</li>
|
|
||||||
<% } %>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- ======================= -->
|
|
||||||
<!-- PM2 LOGS -->
|
|
||||||
<!-- ======================= -->
|
|
||||||
<div class="row mt-4">
|
|
||||||
<div class="col-12">
|
|
||||||
<pre id="pm2Logs" style="background:#383838; padding:10px; border-radius:5px; height:300px; overflow-y:auto; white-space:pre-wrap; color: #330000;"></pre>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- SCRIPT TO BE IMPLEMENTED! -->
|
|
||||||
|
|
||||||
<!-- ======================= -->
|
|
||||||
<!-- AUTO-REFRESH SCRIPT -->
|
|
||||||
<!-- ======================= -->
|
|
||||||
<script>
|
<script>
|
||||||
|
/* ============================================================
|
||||||
|
AUTO REFRESH STATUS
|
||||||
|
============================================================ */
|
||||||
|
|
||||||
function formatBytes(bytes) {
|
function formatBytes(bytes) {
|
||||||
if (!bytes) return "Unknown";
|
if (!bytes) return "Unknown";
|
||||||
const units = ["B","KB","MB","GB","TB"];
|
const units = ["B","KB","MB","GB","TB"];
|
||||||
@@ -164,97 +233,70 @@ function formatBytes(bytes) {
|
|||||||
|
|
||||||
async function refreshStatus() {
|
async function refreshStatus() {
|
||||||
try {
|
try {
|
||||||
// -----------------------------------------
|
// Track open details by data-id
|
||||||
// 1. CAPTURE CURRENTLY OPEN DETAILS TAGS
|
const openMap = new Set(
|
||||||
// -----------------------------------------
|
[...document.querySelectorAll("details")].filter(d => d.open).map(d => d.dataset.id)
|
||||||
const openDetails = new Set();
|
);
|
||||||
document.querySelectorAll("details").forEach((d, index) => {
|
|
||||||
if (d.open) openDetails.add(index);
|
|
||||||
});
|
|
||||||
|
|
||||||
// fetch new data
|
|
||||||
const res = await fetch("/status-data");
|
const res = await fetch("/status-data");
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
// =======================
|
/* Renderer helpers */
|
||||||
// Templates
|
const q = job => `
|
||||||
// =======================
|
|
||||||
|
|
||||||
const renderQueued = job => `
|
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong>${job.filename}</strong><br>
|
<strong>${job.filename}</strong><br>
|
||||||
<small>${job.url}</small><br>
|
<small>${job.url}</small><br>
|
||||||
<small>${new Date(job.created_at).toLocaleString()}</small>
|
<small>${new Date(job.created_at).toLocaleString()}</small>
|
||||||
</li>`;
|
</li>`;
|
||||||
|
|
||||||
const renderProcessing = job => `
|
const p = job => `
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong style="color:#58a6ff">${job.filename}</strong>
|
<strong style="color:#58a6ff">${job.filename}</strong>
|
||||||
<span class="spinner-border spinner-border-sm ms-2" style="color:#58a6ff"></span><br>
|
<span class="spinner-border spinner-border-sm ms-1" style="color:#58a6ff"></span><br>
|
||||||
<small>${job.url}</small><br>
|
<small>${job.url}</small><br>
|
||||||
<small>Started: ${new Date(job.created_at).toLocaleString()}</small><br>
|
<small>Started: ${new Date(job.created_at).toLocaleString()}</small><br>
|
||||||
<small>Downloaded: ${formatBytes(job.fileSize)}</small>
|
<small>Downloaded: ${formatBytes(job.fileSize || 0)}</small>
|
||||||
|
|
||||||
${job.output_log ? `
|
${job.output_log ? `
|
||||||
<details class="mt-2">
|
<details data-id="processing-${job._id}">
|
||||||
<summary class="text-light">Live Log</summary>
|
<summary class="text-light">Live Log</summary>
|
||||||
<pre style="background:#001122; color:#9cf; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre class="log-box">${escapeHtml(job.output_log)}</pre>
|
||||||
${job.output_log}
|
|
||||||
</pre>
|
|
||||||
</details>` : ""}
|
</details>` : ""}
|
||||||
</li>`;
|
</li>`;
|
||||||
|
|
||||||
const renderDone = job => `
|
const d = job => `
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong class="text-success">${job.filename}</strong><br>
|
<strong class="text-success">${job.filename}</strong><br>
|
||||||
<small>${new Date(job.finished_at).toLocaleString()}</small><br>
|
<small>${new Date(job.finished_at).toLocaleString()}</small><br>
|
||||||
<small>Size: ${formatBytes(job.fileSize)}</small>
|
<small>Size: ${formatBytes(job.fileSize || 0)}</small>
|
||||||
|
|
||||||
${job.output_log ? `
|
${job.output_log ? `
|
||||||
<details class="mt-2">
|
<details data-id="done-${job._id}">
|
||||||
<summary class="text-light">Show Log</summary>
|
<summary class="text-light">Show Log</summary>
|
||||||
<pre style="background:#222; color:#e0e0e0; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre class="log-box-light">${escapeHtml(job.output_log)}</pre>
|
||||||
${job.output_log}
|
|
||||||
</pre>
|
|
||||||
</details>` : ""}
|
</details>` : ""}
|
||||||
</li>`;
|
</li>`;
|
||||||
|
|
||||||
const renderFailed = job => `
|
const f = job => `
|
||||||
<li class="list-group-item">
|
<li class="list-group-item">
|
||||||
<strong class="text-danger">${job.filename}</strong><br>
|
<strong class="text-danger">${job.filename}</strong><br>
|
||||||
<small>${new Date(job.failed_at).toLocaleString()}</small><br>
|
<small>${new Date(job.failed_at).toLocaleString()}</small><br>
|
||||||
|
|
||||||
${job.output_log ? `
|
${job.output_log ? `
|
||||||
<details class="mt-2">
|
<details data-id="failed-${job._id}">
|
||||||
<summary class="text-danger">Show Error Log</summary>
|
<summary class="text-danger">Show Error Log</summary>
|
||||||
<pre style="background:#330000; color:#ffb3b3; padding:10px; border-radius:5px; white-space:pre-wrap;">
|
<pre class="log-box-error">${escapeHtml(job.output_log)}</pre>
|
||||||
${job.output_log}
|
|
||||||
</pre>
|
|
||||||
</details>` : ""}
|
</details>` : ""}
|
||||||
</li>`;
|
</li>`;
|
||||||
|
|
||||||
// Replace lists
|
/* Replace lists */
|
||||||
queuedList.innerHTML = data.queued.length ?
|
queuedList.innerHTML = data.queued.length ? data.queued.map(q).join("") : `<li class="list-group-item ">No queued jobs</li>`;
|
||||||
data.queued.map(renderQueued).join("") :
|
processingList.innerHTML = data.processing.length ? data.processing.map(p).join("") : `<li class="list-group-item ">Nothing processing</li>`;
|
||||||
`<li class="list-group-item">No queued jobs</li>`;
|
doneList.innerHTML = data.done.length ? data.done.map(d).join("") : `<li class="list-group-item ">No completed jobs</li>`;
|
||||||
|
failedList.innerHTML = data.failed.length ? data.failed.map(f).join("") : `<li class="list-group-item ">No failed jobs</li>`;
|
||||||
|
|
||||||
processingList.innerHTML = data.processing.length ?
|
// Restore open <details>
|
||||||
data.processing.map(renderProcessing).join("") :
|
document.querySelectorAll("details").forEach(d => {
|
||||||
`<li class="list-group-item">Nothing processing</li>`;
|
if (openMap.has(d.dataset.id)) {
|
||||||
|
d.open = true;
|
||||||
doneList.innerHTML = data.done.length ?
|
}
|
||||||
data.done.map(renderDone).join("") :
|
|
||||||
`<li class="list-group-item">No completed jobs</li>`;
|
|
||||||
|
|
||||||
failedList.innerHTML = data.failed.length ?
|
|
||||||
data.failed.map(renderFailed).join("") :
|
|
||||||
`<li class="list-group-item">No failed jobs</li>`;
|
|
||||||
|
|
||||||
// -----------------------------------------
|
|
||||||
// 2. RESTORE PREVIOUSLY OPEN DETAILS TAGS
|
|
||||||
// -----------------------------------------
|
|
||||||
document.querySelectorAll("details").forEach((d, index) => {
|
|
||||||
if (openDetails.has(index)) d.open = true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -262,8 +304,15 @@ ${job.output_log}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function escapeHtml(text) {
|
||||||
|
return text.replace(/[&<>"']/g, c =>
|
||||||
|
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
setInterval(refreshStatus, 3000);
|
setInterval(refreshStatus, 3000);
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<%- include("partials/footer") %>
|
<%- include("partials/footer") %>
|
||||||
Reference in new issue
Block a user