Files
scripts-bash/servers/linux/config_services.php
2026-03-08 08:17:21 +01:00

42 lines
1.4 KiB
PHP

<?php
$configFile = 'services_to_check.conf';
// Sauvegarde si le formulaire est envoyé
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$selected = $_POST['services'] ?? [];
file_put_contents($configFile, implode("\n", $selected));
echo "✅ Configuration mise à jour !<br><a href='/'>Retour</a>";
exit;
}
// Récupération de tous les services installés
$allServices = [];
exec("systemctl list-unit-files --type=service --no-legend", $output);
foreach ($output as $line) {
$parts = preg_split('/\s+/', $line);
if (isset($parts[0])) $allServices[] = str_replace('.service', '', $parts[0]);
}
// Lecture de la config actuelle
$currentConfig = file_exists($configFile) ? explode("\n", trim(file_get_contents($configFile))) : ["ssh", "fail2ban"];
?>
<!DOCTYPE html>
<html>
<head><title>Config Services</title></head>
<body>
<h2>Services à surveiller</h2>
<form method="post">
<div style="height: 300px; overflow-y: scroll; border: 1px solid #ccc; padding: 10px;">
<?php foreach ($allServices as $svc): ?>
<label>
<input type="checkbox" name="services[]" value="<?= $svc ?>" <?= in_array($svc, $currentConfig) ? 'checked' : '' ?>>
<?= $svc ?>
</label><br>
<?php endforeach; ?>
</div>
<br>
<button type="submit">Enregistrer la configuration</button>
</form>
</body>
</html>