136 lines
5.6 KiB
PHP
136 lines
5.6 KiB
PHP
<?php
|
|
$configFile = '/opt/wevads/config/ip-whitelist.json';
|
|
|
|
// Charger config avec vérification
|
|
$config = ['whitelisted_ips' => []];
|
|
if (file_exists($configFile)) {
|
|
$json = json_decode(file_get_contents($configFile), true);
|
|
if (is_array($json) && isset($json['whitelisted_ips']) && is_array($json['whitelisted_ips'])) {
|
|
$config = $json;
|
|
}
|
|
}
|
|
|
|
// Actions POST
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) {
|
|
if ($_POST['action'] === 'add' && !empty($_POST['ip'])) {
|
|
$newIP = trim($_POST['ip']);
|
|
$newLabel = trim($_POST['label'] ?? 'Unknown');
|
|
// Vérifier doublon
|
|
$exists = false;
|
|
foreach ($config['whitelisted_ips'] as $entry) {
|
|
if ($entry['ip'] === $newIP) { $exists = true; break; }
|
|
}
|
|
if (!$exists) {
|
|
$config['whitelisted_ips'][] = [
|
|
'ip' => $newIP,
|
|
'label' => $newLabel,
|
|
'added' => date('Y-m-d H:i:s')
|
|
];
|
|
}
|
|
}
|
|
if ($_POST['action'] === 'remove' && isset($_POST['index'])) {
|
|
$idx = (int)$_POST['index'];
|
|
if (isset($config['whitelisted_ips'][$idx])) {
|
|
array_splice($config['whitelisted_ips'], $idx, 1);
|
|
}
|
|
}
|
|
file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
|
|
header('Location: ip-whitelist-manager.php');
|
|
exit;
|
|
}
|
|
|
|
$currentIP = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['HTTP_X_REAL_IP'] ?? $_SERVER['REMOTE_ADDR'] ?? 'unknown';
|
|
if (strpos($currentIP, ',') !== false) {
|
|
$currentIP = trim(explode(',', $currentIP)[0]);
|
|
}
|
|
|
|
// Vérifier si IP actuelle est whitelistée
|
|
$isWhitelisted = false;
|
|
foreach ($config['whitelisted_ips'] as $entry) {
|
|
if ($entry['ip'] === $currentIP) { $isWhitelisted = true; break; }
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>IP Whitelist Manager</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; background: #1a1a2e; color: #fff; padding: 20px; }
|
|
.container { max-width: 800px; margin: 0 auto; }
|
|
h1 { color: #10b981; }
|
|
.current-ip { background: #2d2d44; padding: 15px; border-radius: 8px; margin-bottom: 20px; }
|
|
.current-ip .ip { color: #f59e0b; font-weight: bold; font-size: 18px; }
|
|
.status-ok { color: #10b981; }
|
|
.status-warn { color: #ef4444; }
|
|
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
|
|
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #333; }
|
|
th { background: #2d2d44; }
|
|
.btn { padding: 8px 16px; border: none; border-radius: 4px; cursor: pointer; margin-left: 5px; }
|
|
.btn-add { background: #10b981; color: white; }
|
|
.btn-remove { background: #ef4444; color: white; }
|
|
input { padding: 10px; border-radius: 4px; border: 1px solid #333; background: #2d2d44; color: white; margin-right: 10px; }
|
|
.add-form { background: #2d2d44; padding: 20px; border-radius: 8px; margin-top: 20px; }
|
|
.inline-form { display: inline; }
|
|
</style>
|
|
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<h1>🔒 IP Whitelist Manager</h1>
|
|
|
|
<div class="current-ip">
|
|
<p>Votre IP actuelle: <span class="ip"><?= htmlspecialchars($currentIP) ?></span></p>
|
|
<?php if ($isWhitelisted): ?>
|
|
<span class="status-ok">✓ Whitelistée</span>
|
|
<?php else: ?>
|
|
<span class="status-warn">✗ Non whitelistée</span>
|
|
<form method="post" class="inline-form">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="hidden" name="ip" value="<?= htmlspecialchars($currentIP) ?>">
|
|
<input type="text" name="label" placeholder="Label (ex: Mon VPN)" required style="width:200px;">
|
|
<button type="submit" class="btn btn-add">+ Ajouter mon IP</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
<h2>IPs Autorisées (<?= count($config['whitelisted_ips']) ?>)</h2>
|
|
<table>
|
|
<tr><th>IP</th><th>Label</th><th>Ajoutée</th><th>Action</th></tr>
|
|
<?php foreach ($config['whitelisted_ips'] as $i => $entry): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($entry['ip']) ?></td>
|
|
<td><?= htmlspecialchars($entry['label'] ?? '-') ?></td>
|
|
<td><?= htmlspecialchars($entry['added'] ?? '-') ?></td>
|
|
<td>
|
|
<form method="post" class="inline-form">
|
|
<input type="hidden" name="action" value="remove">
|
|
<input type="hidden" name="index" value="<?= $i ?>">
|
|
<button type="submit" class="btn btn-remove">Supprimer</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
<?php if (empty($config['whitelisted_ips'])): ?>
|
|
<tr><td colspan="4" style="text-align:center;color:#888;">Aucune IP whitelistée</td></tr>
|
|
<?php endif; ?>
|
|
</table>
|
|
|
|
<div class="add-form">
|
|
<h3>Ajouter une IP manuellement</h3>
|
|
<form method="post">
|
|
<input type="hidden" name="action" value="add">
|
|
<input type="text" name="ip" placeholder="Adresse IP" required>
|
|
<input type="text" name="label" placeholder="Label" required>
|
|
<button type="submit" class="btn btn-add">+ Ajouter</button>
|
|
</form>
|
|
</div>
|
|
|
|
<p style="margin-top:30px;color:#888;">
|
|
<a href="security-report.php" style="color:#3b82f6;">← Retour au Rapport de Sécurité</a>
|
|
</p>
|
|
</div>
|
|
<?php include("includes/chatbot-widget.php"); ?>
|
|
|
|
</body>
|
|
</html>
|