174 lines
6.3 KiB
PHP
Executable File
174 lines
6.3 KiB
PHP
Executable File
<?php
|
|
header('Content-Type: application/json');
|
|
|
|
$action = $_GET['action'] ?? $_POST['action'] ?? '';
|
|
$target = $_GET['target'] ?? $_POST['target'] ?? '';
|
|
|
|
$results = ['success' => false, 'message' => '', 'actions' => []];
|
|
|
|
switch ($action) {
|
|
case 'diagnose':
|
|
// Diagnostic complet
|
|
$issues = [];
|
|
|
|
// Vérifier syntaxe PHP
|
|
$phpFiles = glob('/opt/wevads/public/hamid-*.php');
|
|
foreach ($phpFiles as $file) {
|
|
$output = shell_exec("php -l $file 2>&1");
|
|
if (strpos($output, 'No syntax errors') === false) {
|
|
$issues[] = ['type' => 'php_syntax', 'file' => basename($file), 'error' => $output];
|
|
}
|
|
}
|
|
|
|
// Vérifier permissions
|
|
$dirs = ['/opt/wevads/public', '/opt/wevads/public/hamid-files', '/tmp'];
|
|
foreach ($dirs as $dir) {
|
|
if (!is_writable($dir)) {
|
|
$issues[] = ['type' => 'permission', 'path' => $dir];
|
|
}
|
|
}
|
|
|
|
// Vérifier base de données
|
|
try {
|
|
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
|
|
$stmt = $pdo->query("SELECT COUNT(*) FROM admin.hamid_config");
|
|
} catch (Exception $e) {
|
|
$issues[] = ['type' => 'database', 'error' => $e->getMessage()];
|
|
}
|
|
|
|
// Vérifier fichiers critiques
|
|
$criticalFiles = [
|
|
'/opt/wevads/public/hamid-api.php',
|
|
'/opt/wevads/public/hamid-providers-config.php',
|
|
'/opt/wevads/public/hamid-status.php',
|
|
'/usr/local/bin/hamid'
|
|
];
|
|
foreach ($criticalFiles as $file) {
|
|
if (!file_exists($file)) {
|
|
$issues[] = ['type' => 'missing_file', 'file' => $file];
|
|
}
|
|
}
|
|
|
|
$results = ['success' => true, 'issues' => $issues, 'count' => count($issues)];
|
|
break;
|
|
|
|
case 'repair_permissions':
|
|
$commands = [
|
|
'chown -R www-data:www-data /opt/wevads/public',
|
|
'chmod -R 755 /opt/wevads/public',
|
|
'chmod 777 /tmp'
|
|
];
|
|
foreach ($commands as $cmd) {
|
|
shell_exec($cmd);
|
|
$results['actions'][] = $cmd;
|
|
}
|
|
$results['success'] = true;
|
|
$results['message'] = 'Permissions réparées';
|
|
break;
|
|
|
|
case 'repair_config':
|
|
// Recréer la config si manquante
|
|
if (!file_exists('/opt/wevads/public/hamid-providers-config.php')) {
|
|
$results['message'] = 'Fichier config manquant - contactez admin';
|
|
$results['success'] = false;
|
|
} else {
|
|
// Vérifier et réparer les includes
|
|
$files = glob('/opt/wevads/public/hamid-*.php');
|
|
foreach ($files as $file) {
|
|
$content = file_get_contents($file);
|
|
if (strpos($content, 'hamid-providers-config.php') === false &&
|
|
basename($file) !== 'hamid-providers-config.php' &&
|
|
basename($file) !== 'hamid-api.php' &&
|
|
basename($file) !== 'hamid-test-api.php' &&
|
|
basename($file) !== 'hamid-repair-api.php') {
|
|
// Pas besoin d'ajouter pour toutes les pages
|
|
}
|
|
}
|
|
$results['success'] = true;
|
|
$results['message'] = 'Configuration vérifiée';
|
|
}
|
|
break;
|
|
|
|
case 'repair_provider':
|
|
$provider = $target;
|
|
if (empty($provider)) {
|
|
$results['message'] = 'Provider non spécifié';
|
|
break;
|
|
}
|
|
|
|
// Marquer le provider comme "à retester"
|
|
$statusFile = '/tmp/hamid_provider_status.json';
|
|
$status = file_exists($statusFile) ? json_decode(file_get_contents($statusFile), true) : [];
|
|
unset($status[$provider]);
|
|
file_put_contents($statusFile, json_encode($status));
|
|
|
|
$results['success'] = true;
|
|
$results['message'] = "Provider $provider reset pour retest";
|
|
break;
|
|
|
|
case 'repair_all':
|
|
// Réparation complète
|
|
$actions = [];
|
|
|
|
// 1. Permissions
|
|
shell_exec('chown -R www-data:www-data /opt/wevads/public 2>/dev/null');
|
|
shell_exec('chmod -R 755 /opt/wevads/public 2>/dev/null');
|
|
$actions[] = 'Permissions corrigées';
|
|
|
|
// 2. Reset status providers
|
|
@unlink('/tmp/hamid_provider_status.json');
|
|
$actions[] = 'Cache providers vidé';
|
|
|
|
// 3. Vérifier config DB
|
|
try {
|
|
$pdo = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
|
|
$actions[] = 'Connexion DB OK';
|
|
} catch (Exception $e) {
|
|
$actions[] = 'ERREUR DB: ' . $e->getMessage();
|
|
}
|
|
|
|
// 4. Vérifier syntaxe PHP critique
|
|
$criticalFiles = ['hamid-api.php', 'hamid-status.php', 'hamid-providers-config.php'];
|
|
foreach ($criticalFiles as $file) {
|
|
$path = "/opt/wevads/public/$file";
|
|
if (file_exists($path)) {
|
|
$output = shell_exec("php -l $path 2>&1");
|
|
if (strpos($output, 'No syntax errors') !== false) {
|
|
$actions[] = "$file: OK";
|
|
} else {
|
|
$actions[] = "$file: ERREUR SYNTAXE";
|
|
}
|
|
}
|
|
}
|
|
|
|
// 5. Restart PHP-FPM si disponible
|
|
shell_exec('systemctl reload php8.1-fpm 2>/dev/null || systemctl reload php-fpm 2>/dev/null');
|
|
$actions[] = 'PHP-FPM rechargé';
|
|
|
|
$results['success'] = true;
|
|
$results['message'] = 'Réparation complète effectuée';
|
|
$results['actions'] = $actions;
|
|
break;
|
|
|
|
case 'clear_cache':
|
|
// Vider les caches
|
|
@unlink('/tmp/hamid_provider_status.json');
|
|
shell_exec('rm -f /tmp/hamid_*.json 2>/dev/null');
|
|
$results['success'] = true;
|
|
$results['message'] = 'Cache vidé';
|
|
break;
|
|
|
|
case 'restart_services':
|
|
shell_exec('systemctl reload php8.1-fpm 2>/dev/null || systemctl reload php-fpm 2>/dev/null');
|
|
shell_exec('systemctl reload nginx 2>/dev/null || systemctl reload apache2 2>/dev/null');
|
|
$results['success'] = true;
|
|
$results['message'] = 'Services redémarrés';
|
|
break;
|
|
|
|
default:
|
|
$results['message'] = 'Action non reconnue';
|
|
}
|
|
|
|
echo json_encode($results, JSON_PRETTY_PRINT);
|
|
|