Files
html/api/blade-tasks/executor.html
2026-04-12 22:57:03 +02:00

104 lines
4.3 KiB
HTML

<!DOCTYPE html>
<html><head>
<title>WEVIA Blade Executor</title>
<style>
body{font-family:monospace;background:#0a0a0f;color:#0f0;padding:20px}
.task{background:#111;border:1px solid #333;padding:10px;margin:5px 0;border-radius:8px}
.done{border-color:#0f0} .fail{border-color:#f00} .pending{border-color:#ff0}
#log{max-height:400px;overflow-y:auto;font-size:12px}
h1{color:#0f0;font-size:18px} .ts{color:#666;font-size:10px}
</style>
</head><body>
<h1>WEVIA BLADE EXECUTOR v1.0</h1>
<div id="status">Initializing...</div>
<div id="log"></div>
<script>
const API = 'https://weval-consulting.com/api/blade-api.php?k=BLADE2026';
const ENGINE = 'https://weval-consulting.com/api/wevia-action-engine.php';
let running = true;
function log(msg, type='info') {
const d = document.getElementById('log');
const ts = new Date().toLocaleTimeString();
d.innerHTML = `<div class="task ${type}"><span class="ts">${ts}</span> ${msg}</div>` + d.innerHTML;
}
async function poll() {
try {
const r = await fetch(`${API}&action=poll`);
const d = await r.json();
const tasks = d.tasks || [];
document.getElementById('status').textContent = `${tasks.length} pending tasks | Polling every 10s`;
for (const task of tasks.slice(0, 3)) {
log(`Processing: ${task.label || task.type} (${task.id})`, 'pending');
let result = '';
let status = 'done';
try {
if (task.type === 'browser_automation' || task.type === 'open_url') {
// Open URL in new tab
const url = task.url || task.cmd;
if (url && url.startsWith('http')) {
window.open(url, '_blank');
result = 'Opened: ' + url;
}
} else if (task.type === 'system' && task.cmd && task.cmd.includes('shutdown')) {
// Reboot — dangerous, skip for now
result = 'Reboot task skipped (manual confirmation needed)';
status = 'pending';
} else if (task.type === 'powershell' || task.type === 'python') {
// Can't run local commands from browser
// But we can redirect server-executable tasks to Action Engine
if (task.cmd && task.cmd.includes('Start-Process')) {
// Extract URL from Start-Process command
const urlMatch = task.cmd.match(/https?:\/\/[^\s'"]+/);
if (urlMatch) {
window.open(urlMatch[0], '_blank');
result = 'Opened URL: ' + urlMatch[0];
}
} else {
result = 'Browser cannot execute local commands. Use PowerShell executor.';
status = 'pending';
}
} else if (task.type === 'playwright') {
// Playwright tasks need local Python — redirect to browser
const url = task.url || '';
if (url) {
window.open(url, '_blank');
result = 'Opened for manual interaction: ' + url;
} else {
result = 'Playwright task needs local Python executor';
status = 'pending';
}
}
// Report result
if (status === 'done') {
await fetch(`${API}&action=report&id=${task.id}&status=done&result=${encodeURIComponent(result.substring(0,200))}`, {method:'POST'});
log(`Done: ${result}`, 'done');
}
} catch (e) {
log(`Error: ${e.message}`, 'fail');
await fetch(`${API}&action=report&id=${task.id}&status=failed&error=${encodeURIComponent(e.message)}`, {method:'POST'});
}
}
} catch (e) {
log(`Poll error: ${e.message}`, 'fail');
}
}
// Auto-poll every 10 seconds
setInterval(poll, 10000);
poll(); // Initial poll
// Keep page alive
setInterval(() => {
fetch(`${API}&action=heartbeat&hostname=blade-executor&cpu=browser&ram=browser&version=web-1.0`, {method:'POST'});
}, 30000);
log('Executor started. Polling every 10s.', 'done');
</script>
</body></html>