106 lines
5.9 KiB
PHP
106 lines
5.9 KiB
PHP
<?php
|
|
|
|
// === WEVAL SECRETS LOADER ===
|
|
$_WEVAL_SECRETS = [];
|
|
if (file_exists('/etc/weval/secrets.env')) {
|
|
foreach (file('/etc/weval/secrets.env', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES) as $line) {
|
|
if (strpos($line, '#') === 0) continue;
|
|
if (strpos($line, '=') !== false) {
|
|
list($k, $v) = explode('=', $line, 2);
|
|
$_WEVAL_SECRETS[trim($k)] = trim($v);
|
|
}
|
|
}
|
|
}
|
|
function weval_secret($key, $default='') {
|
|
global $_WEVAL_SECRETS;
|
|
return $_WEVAL_SECRETS[$key] ?? getenv($key) ?: $default;
|
|
}
|
|
|
|
// WEVAL Blade — Telegram Bot Fallback
|
|
// Webhook: https://weval-consulting.com/api/blade-telegram.php
|
|
// Setup: curl "https://api.telegram.org/bot8544624912/setWebhook?url=https://weval-consulting.com/api/blade-telegram.php"
|
|
header("Content-Type: application/json");
|
|
$TG_TOKEN = "8544624912";
|
|
$TG_CHAT = "7605775322";
|
|
$BLADE_API = "https://weval-consulting.com/api/blade-api.php";
|
|
$BLADE_KEY = weval_secret('BLADE_KEY','BLADE2026');
|
|
|
|
$input = json_decode(file_get_contents("php://input"), true);
|
|
$msg = $input["message"]["text"] ?? "";
|
|
$chat_id = $input["message"]["chat"]["id"] ?? "";
|
|
$from = $input["message"]["from"]["first_name"] ?? "?";
|
|
|
|
if (!$msg || $chat_id != $TG_CHAT) { echo json_encode(["ok" => true]); exit; }
|
|
|
|
$msg = trim($msg);
|
|
$response = "";
|
|
|
|
// Command mapping
|
|
$task = null;
|
|
$m = mb_strtolower($msg);
|
|
|
|
if (preg_match('/^\/screenshot|^capture|^ecran/i', $m)) {
|
|
$task = ["type" => "screenshot", "cmd" => "screenshot", "label" => "TG: Screenshot"];
|
|
} elseif (preg_match('/^\/sysinfo|^system|^info blade/i', $m)) {
|
|
$task = ["type" => "sysinfo", "cmd" => "sysinfo", "label" => "TG: SysInfo"];
|
|
} elseif (preg_match('/^\/pull|^git pull/i', $m)) {
|
|
$task = ["type" => "git_pull", "cmd" => 'C:\Users\Yace\Desktop\CLAUDE\weval-consulting', "label" => "TG: Git Pull"];
|
|
} elseif (preg_match('/^\/push|^git push/i', $m)) {
|
|
$task = ["type" => "git_push", "cmd" => 'C:\Users\Yace\Desktop\CLAUDE\weval-consulting', "label" => "TG: Git Push"];
|
|
} elseif (preg_match('/^\/disk|^espace|^disque/i', $m)) {
|
|
$task = ["type" => "powershell", "cmd" => 'Get-PSDrive C,D,E -EA 0|Select Name,@{N="Free(GB)";E={[math]::Round($_.Free/1GB)}},@{N="Used(GB)";E={[math]::Round($_.Used/1GB)}}|FT', "label" => "TG: Disk"];
|
|
} elseif (preg_match('/^\/procs|^process/i', $m)) {
|
|
$task = ["type" => "powershell", "cmd" => 'Get-Process|Sort CPU -Desc|Select -First 10 Name,CPU,WS|FT', "label" => "TG: Procs"];
|
|
} elseif (preg_match('/^\/clean|^nettoie/i', $m)) {
|
|
$task = ["type" => "powershell", "cmd" => 'Remove-Item $env:TEMP\* -Recurse -Force -EA 0;"Temp cleaned"', "label" => "TG: Cleanup"];
|
|
} elseif (preg_match('/^\/ouvre (.+)/i', $m, $matches)) {
|
|
$url = trim($matches[1]);
|
|
$map = ["weval"=>"https://weval-consulting.com","arsenal"=>"https://weval-consulting.com/arsenal-proxy/ceo-dashboard.html","crm"=>"https://crm.weval-consulting.com","wevia"=>"https://weval-consulting.com/wevia","analytics"=>"https://analytics.weval-consulting.com","wevads"=>"https://weval-consulting.com/wevads-ia/"];
|
|
$found = $map[strtolower($url)] ?? (filter_var($url, FILTER_VALIDATE_URL) ? $url : null);
|
|
if ($found) $task = ["type" => "open_url", "cmd" => $found, "label" => "TG: Open " . substr($url, 0, 30)];
|
|
else $response = "URL non reconnue. Essaie: weval, arsenal, crm, wevia, analytics, wevads ou une URL directe.";
|
|
} elseif (preg_match('/^\/notify (.+)/i', $m, $matches)) {
|
|
$task = ["type" => "notify", "cmd" => trim($matches[1]), "label" => "TG: Notify"];
|
|
} elseif (preg_match('/^\/ps (.+)/i', $m, $matches)) {
|
|
$task = ["type" => "powershell", "cmd" => trim($matches[1]), "label" => "TG: PS"];
|
|
} elseif (preg_match('/^\/morning|^routine matin/i', $m)) {
|
|
// Multi-task recipe
|
|
$steps = [
|
|
["type"=>"git_pull","cmd"=>'C:\Users\Yace\Desktop\CLAUDE\weval-consulting',"label"=>"Morning: Git Pull"],
|
|
["type"=>"open_url","cmd"=>"https://weval-consulting.com","label"=>"Morning: WEVAL"],
|
|
["type"=>"open_url","cmd"=>"https://weval-consulting.com/arsenal-proxy/ceo-dashboard.html","label"=>"Morning: Arsenal"],
|
|
["type"=>"screenshot","cmd"=>"screenshot","label"=>"Morning: Screenshot"]
|
|
];
|
|
foreach ($steps as $s) {
|
|
file_get_contents($BLADE_API . "?" . http_build_query(array_merge($s, ["k"=>$BLADE_KEY, "action"=>"push", "source"=>"telegram", "priority"=>"9"])));
|
|
}
|
|
$response = "Routine matinale lancee (4 etapes)";
|
|
} elseif (preg_match('/^\/status/i', $m)) {
|
|
$st = json_decode(file_get_contents($BLADE_API . "?action=status"), true);
|
|
$b = $st["blade"] ?? [];
|
|
$online = $b["online"] ? "ONLINE" : "OFFLINE";
|
|
$hb = $b["heartbeat"] ?? [];
|
|
$response = "Blade: $online\nCPU: " . ($hb["cpu"]??"?") . " | RAM: " . ($hb["ram"]??"?") . " | Disk: " . ($hb["disk"]??"?") . "\nUptime: " . ($hb["uptime"]??"?") . "\nTasks: " . ($b["tasks"]["pending"]??0) . " pending, " . ($b["tasks"]["done"]??0) . " done";
|
|
} elseif ($m === "/help") {
|
|
$response = "Commandes Blade:\n/status — Etat du Blade\n/screenshot — Capture ecran\n/sysinfo — Info systeme\n/disk — Espace disque\n/procs — Top processus\n/pull — Git pull\n/push — Git push\n/clean — Nettoyer temp\n/ouvre [url|nom] — Ouvrir URL\n/notify [msg] — Notification\n/ps [cmd] — PowerShell\n/morning — Routine matinale\n/help — Cette aide";
|
|
} else {
|
|
$response = "Commande non reconnue. Tape /help pour la liste.";
|
|
}
|
|
|
|
// Push task if parsed
|
|
if ($task) {
|
|
$task["k"] = $BLADE_KEY;
|
|
$task["action"] = "push";
|
|
$task["source"] = "telegram";
|
|
$task["priority"] = "8";
|
|
$r = json_decode(file_get_contents($BLADE_API . "?" . http_build_query($task)), true);
|
|
$response = "Tache envoyee: " . ($task["label"] ?? "?") . "\nID: " . ($r["task"]["id"] ?? "?");
|
|
}
|
|
|
|
// Reply to Telegram
|
|
if ($response) {
|
|
file_get_contents("https://api.telegram.org/bot{$TG_TOKEN}:AAGsMH_M7Qdmf4sL5Iq7Ohe_P5c4_Pv-eTg/sendMessage?" . http_build_query(["chat_id" => $chat_id, "text" => $response]));
|
|
}
|
|
|
|
echo json_encode(["ok" => true]);
|