355 lines
13 KiB
PHP
Executable File
355 lines
13 KiB
PHP
Executable File
<?php
|
|
session_start();
|
|
|
|
// Simple auth (à améliorer avec vrai système auth)
|
|
$authorized = true; // TODO: Implémenter vraie auth
|
|
|
|
if (!$authorized) {
|
|
header('HTTP/1.1 403 Forbidden');
|
|
exit('Accès non autorisé');
|
|
}
|
|
|
|
try {
|
|
$db = new PDO("pgsql:host=localhost;dbname=adx_system", "admin", "admin123");
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
} catch(Exception $e) {
|
|
die("Erreur DB: " . $e->getMessage());
|
|
}
|
|
|
|
// Charger config actuelle
|
|
$config = $db->query("SELECT * FROM admin.brain_config ORDER BY id")->fetchAll(PDO::FETCH_ASSOC);
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Brain Config Editor - WEVADS</title>
|
|
<style>
|
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
body {
|
|
font-family: 'Segoe UI', sans-serif;
|
|
background: linear-gradient(135deg, #1e3c72, #2a5298);
|
|
color: #fff;
|
|
padding: 20px;
|
|
}
|
|
.header {
|
|
background: rgba(0,0,0,0.3);
|
|
padding: 30px;
|
|
border-radius: 15px;
|
|
margin-bottom: 30px;
|
|
text-align: center;
|
|
}
|
|
.header h1 { font-size: 2.5em; margin-bottom: 10px; }
|
|
.warning {
|
|
background: rgba(255,152,0,0.2);
|
|
border-left: 4px solid #ff9800;
|
|
padding: 15px;
|
|
margin: 20px 0;
|
|
border-radius: 5px;
|
|
}
|
|
.section {
|
|
background: rgba(0,0,0,0.5);
|
|
padding: 25px;
|
|
border-radius: 12px;
|
|
margin-bottom: 20px;
|
|
}
|
|
.section h2 {
|
|
color: #4CAF50;
|
|
margin-bottom: 20px;
|
|
border-bottom: 2px solid #4CAF50;
|
|
padding-bottom: 10px;
|
|
}
|
|
.config-grid {
|
|
display: grid;
|
|
gap: 20px;
|
|
}
|
|
.config-item {
|
|
background: rgba(255,255,255,0.05);
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
border-left: 4px solid #4CAF50;
|
|
}
|
|
.config-label {
|
|
font-weight: bold;
|
|
color: #4CAF50;
|
|
margin-bottom: 10px;
|
|
font-size: 1.2em;
|
|
}
|
|
.config-description {
|
|
color: #ccc;
|
|
margin-bottom: 15px;
|
|
font-size: 0.9em;
|
|
}
|
|
.input-group {
|
|
margin: 10px 0;
|
|
}
|
|
.input-group label {
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
font-weight: bold;
|
|
}
|
|
.input-group input, .input-group textarea {
|
|
width: 100%;
|
|
padding: 10px;
|
|
border: 1px solid rgba(255,255,255,0.2);
|
|
background: rgba(0,0,0,0.3);
|
|
color: #fff;
|
|
border-radius: 5px;
|
|
font-family: monospace;
|
|
}
|
|
.input-group textarea {
|
|
min-height: 150px;
|
|
font-size: 0.9em;
|
|
}
|
|
.btn {
|
|
padding: 12px 24px;
|
|
border: none;
|
|
border-radius: 5px;
|
|
cursor: pointer;
|
|
font-size: 1em;
|
|
margin: 5px;
|
|
transition: all 0.3s;
|
|
}
|
|
.btn-save { background: #4CAF50; color: #fff; }
|
|
.btn-save:hover { background: #45a049; }
|
|
.btn-reset { background: #f44336; color: #fff; }
|
|
.btn-reset:hover { background: #da190b; }
|
|
.btn-backup { background: #2196F3; color: #fff; }
|
|
.btn-backup:hover { background: #0b7dda; }
|
|
.history {
|
|
background: rgba(0,0,0,0.3);
|
|
padding: 15px;
|
|
border-radius: 5px;
|
|
margin-top: 20px;
|
|
max-height: 200px;
|
|
overflow-y: auto;
|
|
}
|
|
.history-item {
|
|
padding: 10px;
|
|
border-bottom: 1px solid rgba(255,255,255,0.1);
|
|
font-size: 0.9em;
|
|
}
|
|
.success {
|
|
background: rgba(76,175,80,0.2);
|
|
border-left: 4px solid #4CAF50;
|
|
padding: 15px;
|
|
margin: 20px 0;
|
|
border-radius: 5px;
|
|
}
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
<div class="header">
|
|
<h1>🧠 Brain Config Editor</h1>
|
|
<div>Configuration complète du système auto-réparant WEVADS</div>
|
|
</div>
|
|
|
|
<div class="warning">
|
|
<strong>⚠️ ATTENTION:</strong> Modifications critiques système. Un backup automatique est créé avant chaque sauvegarde.
|
|
</div>
|
|
|
|
<div style="text-align:center; margin-bottom:30px;">
|
|
<button class="btn btn-backup" onclick="createBackup()">💾 Créer Backup Manuel</button>
|
|
<button class="btn btn-reset" onclick="resetToDefault()">🔄 Reset Config Par Défaut</button>
|
|
</div>
|
|
|
|
<form id="configForm" onsubmit="saveConfig(event)">
|
|
<!-- PROMPT SYSTÈME -->
|
|
<div class="section">
|
|
<h2>📋 Prompt Système Brain IA</h2>
|
|
<div class="config-item">
|
|
<div class="config-label">Prompt Principal</div>
|
|
<div class="config-description">Instructions système pour le Brain - Définit mission, règles, contexte</div>
|
|
<div class="input-group">
|
|
<textarea name="system_prompt" id="system_prompt"><?php
|
|
$prompt_row = array_filter($config, fn($c) => $c['config_key'] === 'system_prompt');
|
|
echo !empty($prompt_row) ? htmlspecialchars(reset($prompt_row)['config_value']) : '';
|
|
?></textarea>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- SEUILS -->
|
|
<div class="section">
|
|
<h2>⚙️ Seuils & Limites</h2>
|
|
<div class="config-grid">
|
|
<?php
|
|
$thresholds = [
|
|
'disk_threshold' => ['label' => 'Seuil Disk Space (%)', 'desc' => 'Déclenchement nettoyage automatique'],
|
|
'memory_threshold' => ['label' => 'Seuil Memory (%)', 'desc' => 'Déclenchement restart services'],
|
|
'quota_threshold' => ['label' => 'Seuil Quota Warning (%)', 'desc' => 'Création alertes quotas'],
|
|
'log_retention_days' => ['label' => 'Rétention Logs (jours)', 'desc' => 'Suppression logs anciens'],
|
|
'error_timeout_hours' => ['label' => 'Timeout Serveur Error (heures)', 'desc' => 'Suppression serveurs en erreur prolongée']
|
|
];
|
|
|
|
foreach ($thresholds as $key => $info) {
|
|
$value_row = array_filter($config, fn($c) => $c['config_key'] === $key);
|
|
$value = !empty($value_row) ? reset($value_row)['config_value'] : '';
|
|
echo "
|
|
<div class='config-item'>
|
|
<div class='config-label'>{$info['label']}</div>
|
|
<div class='config-description'>{$info['desc']}</div>
|
|
<div class='input-group'>
|
|
<input type='number' name='$key' value='$value'>
|
|
</div>
|
|
</div>
|
|
";
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- FRÉQUENCES -->
|
|
<div class="section">
|
|
<h2>🕒 Fréquences Routines (CRON)</h2>
|
|
<div class="config-grid">
|
|
<?php
|
|
$frequencies = [
|
|
'cron_auto_debug' => ['label' => 'auto_debug_routines', 'desc' => 'Format: */5 * * * * (minute heure jour mois jour_semaine)'],
|
|
'cron_proactive_monitor' => ['label' => 'proactive_monitor', 'desc' => 'Format: */10 * * * *'],
|
|
'cron_system_health' => ['label' => 'auto_system_health', 'desc' => 'Format: 0 * * * *']
|
|
];
|
|
|
|
foreach ($frequencies as $key => $info) {
|
|
$value_row = array_filter($config, fn($c) => $c['config_key'] === $key);
|
|
$value = !empty($value_row) ? reset($value_row)['config_value'] : '';
|
|
echo "
|
|
<div class='config-item'>
|
|
<div class='config-label'>{$info['label']}</div>
|
|
<div class='config-description'>{$info['desc']}</div>
|
|
<div class='input-group'>
|
|
<input type='text' name='$key' value='$value' placeholder='*/5 * * * *'>
|
|
</div>
|
|
</div>
|
|
";
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<div style="text-align:center; margin: 30px 0;">
|
|
<button type="submit" class="btn btn-save">💾 Sauvegarder Configuration</button>
|
|
</div>
|
|
</form>
|
|
|
|
<!-- HISTORIQUE -->
|
|
<div class="section">
|
|
<h2>📜 Historique Modifications</h2>
|
|
<div class="history">
|
|
<?php
|
|
$history = $db->query("
|
|
SELECT * FROM admin.brain_config_history
|
|
ORDER BY created_at DESC LIMIT 20
|
|
")->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
foreach ($history as $h) {
|
|
echo "<div class='history-item'>";
|
|
echo "<strong>" . date('Y-m-d H:i:s', strtotime($h['created_at'])) . "</strong> - ";
|
|
echo $h['action'] . " par " . ($h['modified_by'] ?? 'system');
|
|
if ($h['backup_data']) {
|
|
echo " <a href='#' onclick='rollback({$h['id']})' style='color:#4CAF50'>[Rollback]</a>";
|
|
}
|
|
echo "</div>";
|
|
}
|
|
?>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="result"></div>
|
|
|
|
<script>
|
|
async function saveConfig(e) {
|
|
e.preventDefault();
|
|
|
|
if (!confirm('⚠️ Sauvegarder ces modifications? Un backup sera créé automatiquement.')) {
|
|
return;
|
|
}
|
|
|
|
const formData = new FormData(e.target);
|
|
const data = Object.fromEntries(formData);
|
|
|
|
try {
|
|
const response = await fetch('/api/brain_config.php?action=save', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify(data)
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
document.getElementById('result').innerHTML =
|
|
'<div class="success">✅ Configuration sauvegardée avec succès! Backup créé.</div>';
|
|
setTimeout(() => location.reload(), 2000);
|
|
} else {
|
|
alert('❌ Erreur: ' + result.error);
|
|
}
|
|
} catch (error) {
|
|
alert('❌ Erreur réseau: ' + error.message);
|
|
}
|
|
}
|
|
|
|
async function createBackup() {
|
|
if (!confirm('Créer un backup manuel de la configuration actuelle?')) return;
|
|
|
|
try {
|
|
const response = await fetch('/api/brain_config.php?action=backup', {method: 'POST'});
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
alert('✅ Backup créé: ' + result.backup_id);
|
|
location.reload();
|
|
} else {
|
|
alert('❌ Erreur: ' + result.error);
|
|
}
|
|
} catch (error) {
|
|
alert('❌ Erreur: ' + error.message);
|
|
}
|
|
}
|
|
|
|
async function resetToDefault() {
|
|
if (!confirm('⚠️ ATTENTION: Reset complet à la configuration par défaut. Continuer?')) return;
|
|
|
|
try {
|
|
const response = await fetch('/api/brain_config.php?action=reset', {method: 'POST'});
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
alert('✅ Configuration réinitialisée');
|
|
location.reload();
|
|
} else {
|
|
alert('❌ Erreur: ' + result.error);
|
|
}
|
|
} catch (error) {
|
|
alert('❌ Erreur: ' + error.message);
|
|
}
|
|
}
|
|
|
|
async function rollback(historyId) {
|
|
if (!confirm('Restaurer cette version de la configuration?')) return;
|
|
|
|
try {
|
|
const response = await fetch('/api/brain_config.php?action=rollback', {
|
|
method: 'POST',
|
|
headers: {'Content-Type': 'application/json'},
|
|
body: JSON.stringify({history_id: historyId})
|
|
});
|
|
|
|
const result = await response.json();
|
|
|
|
if (result.success) {
|
|
alert('✅ Configuration restaurée');
|
|
location.reload();
|
|
} else {
|
|
alert('❌ Erreur: ' + result.error);
|
|
}
|
|
} catch (error) {
|
|
alert('❌ Erreur: ' + error.message);
|
|
}
|
|
}
|
|
</script>
|
|
|
|
</body>
|
|
</html>
|