Files
html/api/wevia-opus-arch-early.php

71 lines
3.9 KiB
PHP

<?php
// V41 EARLY
if (!isset($_mam) || empty($_mam)) return;
$_oaa_m = mb_strtolower(trim($_mam));
if (!function_exists('_oaa_sse')) {
function _oaa_sse($type, $text, $engine='Resolver/opus-arch-actions-v41') {
header('Content-Type: text/event-stream');
echo 'data: ' . json_encode(['type'=>$type, 'text'=>$text, 'engine'=>$engine]) . "\n\n";
@ob_flush(); @flush();
exit;
}
}
if (preg_match('/unlock\s+registry\s+opus.?arch|register.*opus.?arch.*tools?/i', $_oaa_m)) {
$r = '/opt/wevia-brain/tool-registry-v2.json';
$info = ['size'=>@filesize($r), 'owner'=>@fileowner($r), 'perms'=>substr(sprintf('%o',fileperms($r)),-4), 'writable'=>is_writable($r)];
$out = @shell_exec('sudo chmod 664 '.escapeshellarg($r).' 2>&1; sudo chown www-data:www-data '.escapeshellarg($r).' 2>&1; stat -c "%a %U" '.escapeshellarg($r));
_oaa_sse('exec', 'Registry: '.json_encode($info).' | chmod: '.trim($out));
}
if (preg_match('/install\s+whisper\.?cpp|whisper\.?cpp\s+install/i', $_oaa_m)) {
$check = @shell_exec('ls -la /opt/whisper.cpp/main 2>&1 | head -1');
if (strpos($check, 'main') !== false && strpos($check, 'No such') === false) {
_oaa_sse('exec', 'Already built: '.trim($check));
}
$out = @shell_exec('timeout 60 bash -c "cd /opt && (test -d whisper.cpp || sudo git clone https://github.com/ggerganov/whisper.cpp.git) 2>&1 | tail -5" 2>&1');
_oaa_sse('exec', 'Whisper: '.substr($out,0,400));
}
if (preg_match('/cree?\s+docker\s+sandbox\s+refactor|create\s+docker\s+sandbox/i', $_oaa_m)) {
$exists = trim(@shell_exec('docker ps -a --filter name=refactor-sandbox --format "{{.Names}}:{{.Status}}" 2>&1'));
if ($exists) _oaa_sse('exec', 'Exists: '.$exists);
$out = @shell_exec('timeout 20 docker run -d --name refactor-sandbox -v /var/www/html:/code:ro php:8.2-cli tail -f /dev/null 2>&1');
_oaa_sse('exec', 'Created: '.substr($out,0,200));
}
if (preg_match('/renouvelle\s+github\s+pat|github\s+pat\s+renouvelle|renew\s+github\s+token/i', $_oaa_m)) {
$instr = "GitHub PAT Manual (2FA): 1.Chrome yacineutt 2.github.com/settings/tokens/new 3.WEVAL-S204-2026 repo+workflow+admin:org 90d 4.Copy 5.echo GITHUB_PAT=ghp_NEW>>/etc/weval/secrets.env";
@file_put_contents('/opt/wevads/vault/drafts/github-pat-renewal.md', $instr);
_oaa_sse('exec', 'Instructions saved: '.$instr);
}
if (preg_match('/renouvelle\s+whatsapp\s+token|whatsapp\s+token\s+renouvelle|renew\s+whatsapp/i', $_oaa_m)) {
$instr = "WhatsApp Manual (Meta 2FA): 1.business.facebook.com/settings/ 2.WhatsApp Business API 3.Generate token 4.Update WHATSAPP_TOKEN in secrets.env";
@file_put_contents('/opt/wevads/vault/drafts/whatsapp-token-renewal.md', $instr);
_oaa_sse('exec', 'Instructions saved: '.$instr);
}
if (preg_match('/kaggle\s+fine.?tune\s+phase\s*5|trigger\s+kaggle\s+notebook\s+fine.?tune/i', $_oaa_m)) {
$key = '';
foreach (@file('/etc/weval/secrets.env') ?: [] as $line) {
if (preg_match('/^KAGGLE_API_KEY=(.+)$/', trim($line), $m)) { $key = trim(str_replace(['"',"'"], '', $m[1])); break; }
}
if (!$key) _oaa_sse('exec', 'Kaggle key missing in secrets.env');
$ch = curl_init('https://www.kaggle.com/api/v1/kernels/list?user=yace222&pageSize=10');
curl_setopt_array($ch, [CURLOPT_RETURNTRANSFER=>true, CURLOPT_TIMEOUT=>10, CURLOPT_USERPWD=>$key]);
$out = curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
_oaa_sse('exec', 'Kaggle HTTP '.$code.': '.substr($out,0,300));
}
if (preg_match('/drafts?\s+gmail\s+partenaires|gmail\s+drafts?\s+(vistex|huawei|kaouther)/i', $_oaa_m)) {
$files = array_map('basename', glob('/opt/wevads/vault/drafts/email-*.md'));
$has = false;
foreach (@file('/etc/weval/secrets.env') ?: [] as $line) if (strpos($line,'GMAIL_OAUTH_TOKEN=')===0) { $has = true; break; }
$msg = $has ? 'OAuth configured' : 'OAuth not configured';
_oaa_sse('exec', $msg.'. 3 drafts local: '.implode(', ',$files));
}