80 lines
3.4 KiB
PHP
80 lines
3.4 KiB
PHP
<?php
|
|
// Intents pour wake/archive OSS — doctrine 54/58 NO-DORMANT
|
|
// Chargé par wevia-master-api.php au niveau require_once
|
|
// Match patterns (word-boundary, doctrine 47)
|
|
|
|
// Read message from request (supports POST JSON + GET + POST form)
|
|
if (!function_exists('wevia_oss_match_and_run')) {
|
|
function wevia_oss_match_and_run($msg) {
|
|
if (!$msg) return false;
|
|
|
|
// wake_oss
|
|
if (preg_match('/\bwake\s+oss\s+(\S+)/i', $msg, $m)) {
|
|
$path = trim($m[1]);
|
|
if (!preg_match('#^/opt/[a-zA-Z0-9_.-]+/?$#', $path)) {
|
|
header("Content-Type: application/json");
|
|
echo json_encode(['intent' => 'wake_oss', 'error' => 'invalid path', 'path' => $path]);
|
|
exit;
|
|
}
|
|
$out = ['intent' => 'wake_oss', 'path' => $path, 'actions' => []];
|
|
// Git pull
|
|
$pull = shell_exec("cd " . escapeshellarg($path) . " && timeout 30 git pull --ff-only 2>&1 | tail -5");
|
|
$out['actions']['git_pull'] = trim($pull);
|
|
// Service
|
|
$svc = basename(rtrim($path, '/'));
|
|
$svcstat = trim(shell_exec("systemctl is-active $svc.service 2>&1"));
|
|
$out['actions']['service_status'] = $svcstat;
|
|
// Log
|
|
@file_put_contents('/var/log/weval/oss-wake.log', date('c') . " WAKE $path\n", FILE_APPEND);
|
|
$out['tool'] = 'oss_wake';
|
|
$out['executed'] = true;
|
|
header("Content-Type: application/json");
|
|
echo json_encode($out);
|
|
exit;
|
|
}
|
|
|
|
// archive_oss
|
|
if (preg_match('/\barchive\s+passive\s+(\S+)/i', $msg, $m)) {
|
|
$path = trim($m[1]);
|
|
if (!preg_match('#^/opt/[a-zA-Z0-9_.-]+/?$#', $path)) {
|
|
header("Content-Type: application/json");
|
|
echo json_encode(['intent' => 'archive_oss', 'error' => 'invalid path', 'path' => $path]);
|
|
exit;
|
|
}
|
|
if (!is_dir($path)) {
|
|
header("Content-Type: application/json");
|
|
echo json_encode(['intent' => 'archive_oss', 'error' => 'path does not exist', 'path' => $path]);
|
|
exit;
|
|
}
|
|
$out = ['intent' => 'archive_oss', 'path' => $path, 'actions' => []];
|
|
$svc = basename(rtrim($path, '/'));
|
|
$stop = shell_exec("sudo -n systemctl stop $svc.service 2>&1");
|
|
$out['actions']['service_stop'] = trim($stop) ?: 'no-service';
|
|
$disable = shell_exec("sudo -n systemctl disable $svc.service 2>&1");
|
|
$out['actions']['service_disable'] = trim($disable) ?: 'no-service';
|
|
$marker = rtrim($path, '/') . '/ARCHIVED-' . date('Y-m-d') . '.md';
|
|
$content = "ARCHIVED " . date('c') . "\nReason: doctrine 58 STRATEGIC_PASSIVE_ARCHIVE (Yacine order no-delete)\nReactivable: remove this file + systemctl start $svc\n";
|
|
@file_put_contents($marker, $content);
|
|
$out['actions']['marker'] = file_exists($marker) ? $marker : 'failed';
|
|
@file_put_contents('/var/log/weval/oss-archive.log', date('c') . " ARCHIVE $path\n", FILE_APPEND);
|
|
$out['tool'] = 'oss_archive';
|
|
$out['executed'] = true;
|
|
header("Content-Type: application/json");
|
|
echo json_encode($out);
|
|
exit;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
// Auto-dispatch when required at top of master-api
|
|
$_oss_msg = '';
|
|
$_body = @file_get_contents('php://input');
|
|
if ($_body) {
|
|
$_j = @json_decode($_body, true);
|
|
if (is_array($_j) && !empty($_j['message'])) $_oss_msg = $_j['message'];
|
|
}
|
|
if (!$_oss_msg) $_oss_msg = $_POST['message'] ?? $_GET['message'] ?? '';
|
|
|
|
if ($_oss_msg) wevia_oss_match_and_run($_oss_msg);
|
|
} |