BLADE control center: blade-control.html UI live status+tasks+watchdog+actions · 2 nouveaux endpoints blade-task-queue (add + flush avec archive doctrine 59 no-delete) · Blade online avec heartbeat + 36 tasks pending identifies · pages liens vers tasks-live
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
Some checks failed
WEVAL NonReg / nonreg (push) Has been cancelled
This commit is contained in:
@@ -35,6 +35,57 @@ switch ($action) {
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case "flush":
|
||||
$older_days = max(1, intval($_GET["older_days"] ?? $_POST["older_days"] ?? 7));
|
||||
$cutoff = time() - ($older_days * 86400);
|
||||
$archived = 0; $kept = 0;
|
||||
$archive_dir = $queue_dir . "archived_" . date("Y-m-d") . "/";
|
||||
@mkdir($archive_dir, 0777, true);
|
||||
foreach (glob($queue_dir . "*.json") as $ff) {
|
||||
$t = @json_decode(@file_get_contents($ff), true);
|
||||
if (!$t) continue;
|
||||
if (($t["status"] ?? "") === "done" || ($t["status"] ?? "") === "completed") {
|
||||
$t_time = strtotime($t["completed_at"] ?? $t["created_at"] ?? "");
|
||||
if ($t_time > 0 && $t_time < $cutoff) {
|
||||
// MOVE to archive, not delete (doctrine 59 NO-DELETE)
|
||||
@rename($ff, $archive_dir . basename($ff));
|
||||
$archived++;
|
||||
} else { $kept++; }
|
||||
}
|
||||
}
|
||||
echo json_encode([
|
||||
"ok" => true,
|
||||
"action" => "flush",
|
||||
"older_days" => $older_days,
|
||||
"archived" => $archived,
|
||||
"kept" => $kept,
|
||||
"archive_dir" => $archive_dir,
|
||||
"note" => "done tasks moved to archive (not deleted, doctrine 59)"
|
||||
]);
|
||||
break;
|
||||
|
||||
case "add":
|
||||
$id = "task_" . date("YmdHis") . "_" . substr(md5(rand()), 0, 6);
|
||||
$task = [
|
||||
"id" => $id,
|
||||
"name" => $_POST["name"] ?? $_GET["name"] ?? "Unnamed",
|
||||
"type" => $_POST["type"] ?? $_GET["type"] ?? "powershell",
|
||||
"command" => $_POST["cmd"] ?? $_POST["command"] ?? $_GET["cmd"] ?? "",
|
||||
"cmd" => $_POST["cmd"] ?? $_POST["command"] ?? $_GET["cmd"] ?? "",
|
||||
"priority" => $_POST["priority"] ?? "normal",
|
||||
"status" => "pending",
|
||||
"created" => date("c"),
|
||||
"created_by" => "blade-control-ui"
|
||||
];
|
||||
if (!$task["command"]) {
|
||||
echo json_encode(["error" => "cmd required"]);
|
||||
break;
|
||||
}
|
||||
file_put_contents($queue_dir . $id . ".json", json_encode($task, JSON_PRETTY_PRINT));
|
||||
echo json_encode(["ok" => true, "task_id" => $id, "task" => $task]);
|
||||
break;
|
||||
|
||||
case "create":
|
||||
$id = "task_" . date("YmdHis") . "_" . substr(md5(rand()), 0, 6);
|
||||
$task = [
|
||||
|
||||
223
blade-control.html
Normal file
223
blade-control.html
Normal file
@@ -0,0 +1,223 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr"><head>
|
||||
<meta charset="UTF-8"><title>Blade Razer · Control Center</title>
|
||||
<style>
|
||||
body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;background:#0a0e27;color:#e4e8f7;margin:0;padding:24px;max-width:1400px;margin:0 auto;padding:24px;line-height:1.5}
|
||||
h1{color:#6ba3ff;border-bottom:2px solid #1e3a8a;padding-bottom:8px;margin-top:0}
|
||||
h2{color:#c084fc;margin-top:24px}
|
||||
.card{background:#141933;border:1px solid #263161;border-radius:8px;padding:16px;margin:12px 0}
|
||||
.flex{display:flex;gap:16px;flex-wrap:wrap}.flex>div{flex:1;min-width:180px;text-align:center}
|
||||
.num{font-size:28px;font-weight:bold;color:#6ba3ff}
|
||||
.lbl{color:#9ca8d3;font-size:12px;text-transform:uppercase}
|
||||
.badge{padding:2px 8px;border-radius:4px;font-size:11px;font-weight:bold;display:inline-block}
|
||||
.ok{background:#10b981;color:#fff}.warn{background:#f59e0b;color:#111}.ko{background:#ef4444;color:#fff}.info{background:#3b82f6;color:#fff}
|
||||
.dot{width:12px;height:12px;border-radius:50%;display:inline-block;margin-right:6px}
|
||||
.dot.online{background:#10b981;animation:pulse 2s infinite}
|
||||
.dot.offline{background:#ef4444}
|
||||
@keyframes pulse{0%,100%{opacity:1}50%{opacity:0.5}}
|
||||
table{width:100%;border-collapse:collapse}th,td{padding:8px;border-bottom:1px solid #263161;text-align:left;font-size:13px;vertical-align:top}
|
||||
th{background:#1e2549;color:#9ca8d3;font-size:11px;text-transform:uppercase}
|
||||
button{background:#1e3a8a;color:#fff;border:0;padding:8px 14px;border-radius:4px;cursor:pointer;font-size:12px;margin-right:4px}
|
||||
button:hover{background:#2950a7}button.primary{background:#10b981}button.primary:hover{background:#059669}button.danger{background:#ef4444}
|
||||
code{background:#0f1529;padding:2px 6px;border-radius:3px;color:#fbbf24;font-family:Monaco,monospace;font-size:12px}
|
||||
pre{background:#000;color:#0f0;padding:12px;border-radius:4px;font-family:Monaco,monospace;font-size:11px;overflow-x:auto;max-height:350px;overflow-y:auto}
|
||||
a{color:#6ba3ff}
|
||||
.task-row.pending{border-left:3px solid #f59e0b}
|
||||
.task-row.dispatched{border-left:3px solid #3b82f6}
|
||||
.task-row.done{border-left:3px solid #10b981}
|
||||
</style></head>
|
||||
<body>
|
||||
|
||||
<h1>🎮 Blade Razer · Control Center</h1>
|
||||
<p>Monitoring + control du Blade (Windows workstation). Heartbeat, task queue, wake status, commande à envoyer.</p>
|
||||
|
||||
<h2>📊 État live</h2>
|
||||
<div class="card">
|
||||
<div class="flex">
|
||||
<div>
|
||||
<div><span class="dot" id="dot">⚫</span><span class="num" id="status-txt">—</span></div>
|
||||
<div class="lbl">Status Blade</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="num" id="last-hb">—</div>
|
||||
<div class="lbl">Dernier heartbeat</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="num" id="pending">—</div>
|
||||
<div class="lbl">Tasks pending</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="num" id="dispatched">—</div>
|
||||
<div class="lbl">Dispatched</div>
|
||||
</div>
|
||||
<div>
|
||||
<div class="num" id="done">—</div>
|
||||
<div class="lbl">Done</div>
|
||||
</div>
|
||||
</div>
|
||||
<p style="margin-top:12px;color:#9ca8d3" id="blade-meta">—</p>
|
||||
</div>
|
||||
|
||||
<h2>🔄 Actions</h2>
|
||||
<div class="card">
|
||||
<button class="primary" onclick="refresh()">🔄 Refresh status</button>
|
||||
<button onclick="sendTask('Get-Date', 'Test ping')">▶️ Send test task (Get-Date)</button>
|
||||
<button onclick="sendTask('Get-Process | Sort-Object CPU -Descending | Select -First 10', 'Top CPU')">📊 Top CPU</button>
|
||||
<button onclick="flushDone()">🧹 Flush tasks done > 7j</button>
|
||||
<button onclick="toggleAuto()"><span id="auto-lbl">▶️ Auto-refresh 10s</span></button>
|
||||
</div>
|
||||
|
||||
<h2>📋 Task queue</h2>
|
||||
<div class="card" id="tasks-container">Chargement…</div>
|
||||
|
||||
<h2>📜 Blade watchdog log (dernières 20 lignes)</h2>
|
||||
<div class="card">
|
||||
<pre id="watchdog-log">Chargement…</pre>
|
||||
</div>
|
||||
|
||||
<h2>❓ Si Blade est OFFLINE — Que faire ?</h2>
|
||||
<div class="card">
|
||||
<p><strong>Cas 1 : Blade éteint physiquement</strong></p>
|
||||
<ol>
|
||||
<li>Aller sur le Razer Blade</li>
|
||||
<li>Power button pression courte (réveil) ou longue (démarrage complet)</li>
|
||||
<li>Sentinel agent démarre auto au login Windows</li>
|
||||
<li>Heartbeat revient dans 60s max</li>
|
||||
</ol>
|
||||
|
||||
<p><strong>Cas 2 : Blade allumé mais agent cassé</strong></p>
|
||||
<ol>
|
||||
<li>Admin PowerShell sur le Blade :</li>
|
||||
<li><code>cd C:\ProgramData\WEVAL && .\sentinel-agent.ps1</code></li>
|
||||
<li>Si erreur, relancer avec <code>Set-ExecutionPolicy Bypass -Scope Process</code></li>
|
||||
</ol>
|
||||
|
||||
<p><strong>Cas 3 : Blade online mais tasks s'accumulent (cas actuel)</strong></p>
|
||||
<ol>
|
||||
<li>L'agent ne consume pas la queue → vérifier sur Blade que le script poll est bien en boucle</li>
|
||||
<li>Tail du log agent : <code>Get-Content C:\ProgramData\WEVAL\agent.log -Tail 20</code></li>
|
||||
<li>Restart agent : <code>Stop-Process -Name powershell -Force; .\sentinel-agent.ps1</code></li>
|
||||
</ol>
|
||||
</div>
|
||||
|
||||
<h2>🔗 Liens</h2>
|
||||
<div class="card">
|
||||
<ul>
|
||||
<li><a href="/api/blade-status.php?k=BLADE2026" target="_blank">API blade-status</a></li>
|
||||
<li><a href="/api/blade-task-queue.php?k=BLADE2026" target="_blank">API blade-task-queue</a></li>
|
||||
<li><a href="/api/blade-poll.php?k=BLADE2026&action=poll" target="_blank">API blade-poll (simule agent)</a></li>
|
||||
<li><a href="/tasks-live.html">Tasks & Logs Live (autres services)</a></li>
|
||||
<li><a href="/wevia-master.html">WEVIA Master (chat)</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
let autoTimer = null;
|
||||
let autoActive = false;
|
||||
|
||||
async function refresh() {
|
||||
try {
|
||||
const r = await fetch('/api/blade-status.php?k=BLADE2026');
|
||||
const d = await r.json();
|
||||
const b = d.blade || {};
|
||||
const hb = b.heartbeat || {};
|
||||
const s = b.stats || {};
|
||||
|
||||
const online = b.online === true;
|
||||
document.getElementById('dot').innerHTML = online ? '<span class="dot online"></span>' : '<span class="dot offline"></span>';
|
||||
document.getElementById('status-txt').textContent = online ? 'ONLINE' : 'OFFLINE';
|
||||
document.getElementById('status-txt').style.color = online ? '#10b981' : '#ef4444';
|
||||
|
||||
if (hb.ts) {
|
||||
const d2 = new Date(hb.ts);
|
||||
const ago = Math.round((Date.now() - d2.getTime()) / 1000);
|
||||
document.getElementById('last-hb').textContent = ago < 60 ? ago + 's' : ago < 3600 ? Math.round(ago/60) + 'min' : Math.round(ago/3600) + 'h';
|
||||
}
|
||||
document.getElementById('pending').textContent = s.pending || 0;
|
||||
document.getElementById('dispatched').textContent = s.dispatched || 0;
|
||||
document.getElementById('done').textContent = s.done || 0;
|
||||
|
||||
document.getElementById('blade-meta').innerHTML =
|
||||
`Hostname: <strong>${hb.hostname || '?'}</strong> · IP: <strong>${hb.ip || '?'}</strong> · Agent: <strong>${hb.agent_version || '?'}</strong> · ts: <strong>${hb.ts || '—'}</strong>`;
|
||||
|
||||
// Load tasks
|
||||
loadTasks();
|
||||
} catch(e) {
|
||||
document.getElementById('status-txt').textContent = 'ERROR';
|
||||
document.getElementById('status-txt').style.color = '#ef4444';
|
||||
}
|
||||
}
|
||||
|
||||
async function loadTasks() {
|
||||
try {
|
||||
const r = await fetch('/api/blade-task-queue.php?k=BLADE2026');
|
||||
const d = await r.json();
|
||||
const tasks = d.tasks || [];
|
||||
const tc = document.getElementById('tasks-container');
|
||||
if (!tasks.length) {
|
||||
tc.innerHTML = '<p style="color:#9ca8d3">Aucune tâche.</p>';
|
||||
return;
|
||||
}
|
||||
tc.innerHTML = '<table><tr><th>Status</th><th>Name</th><th>Type</th><th>Created</th><th>Command (extrait)</th></tr>' +
|
||||
tasks.slice(0, 30).map(t => `<tr class="task-row ${t.status}">
|
||||
<td><span class="badge ${t.status === 'pending' ? 'warn' : t.status === 'done' ? 'ok' : 'info'}">${t.status}</span></td>
|
||||
<td>${escapeHtml(t.name || '?')}</td>
|
||||
<td>${escapeHtml(t.type || 'ps')}</td>
|
||||
<td style="color:#9ca8d3;font-size:11px">${(t.created || '').slice(0, 16).replace('T', ' ')}</td>
|
||||
<td><code>${escapeHtml((t.command || t.cmd || '').slice(0, 80))}...</code></td>
|
||||
</tr>`).join('') + '</table>';
|
||||
} catch(e) {
|
||||
document.getElementById('tasks-container').innerHTML = 'Error loading tasks: ' + e.message;
|
||||
}
|
||||
|
||||
// Load watchdog log
|
||||
fetch('/api/tasks-live-api.php?action=tail&file=blade-watchdog.log&n=20').then(r => r.json()).then(d => {
|
||||
document.getElementById('watchdog-log').textContent = d.content || '(log vide)';
|
||||
}).catch(e => {
|
||||
document.getElementById('watchdog-log').textContent = 'Log non accessible: ' + e.message;
|
||||
});
|
||||
}
|
||||
|
||||
async function sendTask(cmd, name) {
|
||||
if (!confirm(`Envoyer la commande au Blade ?\n\n${cmd}`)) return;
|
||||
try {
|
||||
const fd = new FormData();
|
||||
fd.append('k', 'BLADE2026');
|
||||
fd.append('name', name);
|
||||
fd.append('cmd', cmd);
|
||||
fd.append('type', 'powershell');
|
||||
const r = await fetch('/api/blade-task-queue.php?k=BLADE2026&action=add', {method:'POST', body: fd});
|
||||
const d = await r.json();
|
||||
alert('Task submitted: ' + JSON.stringify(d).slice(0, 200));
|
||||
refresh();
|
||||
} catch(e) {
|
||||
alert('Error: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function flushDone() {
|
||||
if (!confirm('Flush les tâches "done" de plus de 7 jours ?')) return;
|
||||
try {
|
||||
const r = await fetch('/api/blade-task-queue.php?k=BLADE2026&action=flush&older_days=7');
|
||||
const d = await r.json();
|
||||
alert('Flush result: ' + JSON.stringify(d));
|
||||
refresh();
|
||||
} catch(e) {
|
||||
alert('Error: ' + e.message);
|
||||
}
|
||||
}
|
||||
|
||||
function toggleAuto() {
|
||||
autoActive = !autoActive;
|
||||
document.getElementById('auto-lbl').textContent = autoActive ? '⏸️ Auto 10s ON' : '▶️ Auto-refresh 10s';
|
||||
if (autoActive) autoTimer = setInterval(refresh, 10000);
|
||||
else clearInterval(autoTimer);
|
||||
}
|
||||
|
||||
function escapeHtml(s) {
|
||||
return (s || '').toString().replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
||||
}
|
||||
|
||||
refresh();
|
||||
</script>
|
||||
</body></html>
|
||||
Reference in New Issue
Block a user