Files
weval-consulting/api/blade-mattermost.php

54 lines
2.5 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 — Mattermost Incoming Webhook Handler
// Trigger: /blade [command] in Mattermost
header("Content-Type: application/json");
$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);
$text = $input["text"] ?? "";
if (!$text) { $text = $_POST["text"] ?? ""; }
$user = $input["user_name"] ?? $_POST["user_name"] ?? "?";
$m = mb_strtolower(trim($text));
$task = null; $response = "";
if (preg_match('/^screenshot/i', $m)) $task = ["type"=>"screenshot","cmd"=>"screenshot","label"=>"MM: Screenshot"];
elseif (preg_match('/^sysinfo|^info/i', $m)) $task = ["type"=>"sysinfo","cmd"=>"sysinfo","label"=>"MM: SysInfo"];
elseif (preg_match('/^pull/i', $m)) $task = ["type"=>"git_pull","cmd"=>'C:\Users\Yace\Desktop\CLAUDE\weval-consulting',"label"=>"MM: Git Pull"];
elseif (preg_match('/^disk/i', $m)) $task = ["type"=>"powershell","cmd"=>'Get-PSDrive C -EA 0|Select Used,Free|FT',"label"=>"MM: Disk"];
elseif (preg_match('/^status/i', $m)) {
$st = json_decode(file_get_contents($BLADE_API."?action=status"), true);
$b = $st["blade"]??[];
$response = "| Metric | Value |\n|---|---|\n| Status | ".($b["online"]?"ONLINE":"OFFLINE")." |\n| CPU | ".($b["heartbeat"]["cpu"]??"?")." |\n| RAM | ".($b["heartbeat"]["ram"]??"?")." |\n| Tasks | ".($b["tasks"]["pending"]??0)." pending |";
} elseif (preg_match('/^ps (.+)/i', $m, $mm)) {
$task = ["type"=>"powershell","cmd"=>trim($mm[1]),"label"=>"MM: PS"];
} else {
$response = "Usage: `screenshot`, `sysinfo`, `pull`, `disk`, `status`, `ps <cmd>`";
}
if ($task) {
$task["k"]=$BLADE_KEY; $task["action"]="push"; $task["source"]="mattermost"; $task["priority"]="8";
$r = json_decode(file_get_contents($BLADE_API."?".http_build_query($task)), true);
$response = "Task pushed: **".$task["label"]."**\nID: `".($r["task"]["id"]??"?")."`";
}
echo json_encode(["response_type"=>"in_channel","text"=>$response?:"Task sent"]);