141 lines
4.7 KiB
PHP
141 lines
4.7 KiB
PHP
<?php
|
||
require_once __DIR__ . '/includes/auth.php';
|
||
require_once __DIR__ . '/includes/functions.php';
|
||
require_login();
|
||
|
||
$errors = [];
|
||
$success = '';
|
||
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||
$action = $_POST['action'] ?? '';
|
||
|
||
if ($action === 'password') {
|
||
$current = $_POST['current_password'] ?? '';
|
||
$new = $_POST['new_password'] ?? '';
|
||
$confirm = $_POST['confirm_password'] ?? '';
|
||
|
||
if (!password_verify($current, active_pass_hash())) {
|
||
$errors[] = 'Current password is incorrect.';
|
||
} elseif (strlen($new) < 8) {
|
||
$errors[] = 'New password must be at least 8 characters.';
|
||
} elseif ($new !== $confirm) {
|
||
$errors[] = 'New passwords do not match.';
|
||
} elseif (!save_password($new)) {
|
||
$errors[] = 'Could not write auth.passwd — check file permissions.';
|
||
} else {
|
||
$success = 'Password updated successfully.';
|
||
}
|
||
|
||
} elseif ($action === 'retention') {
|
||
$days = (int)($_POST['retention_days'] ?? 0);
|
||
if ($days < 1) {
|
||
$errors[] = 'Retention period must be at least 1 day.';
|
||
} else {
|
||
set_setting('retention_days', (string)$days);
|
||
$success = 'Retention period saved.';
|
||
}
|
||
|
||
} elseif ($action === 'frequent_ip_threshold') {
|
||
$threshold = (int)($_POST['frequent_ip_threshold'] ?? 0);
|
||
if ($threshold < 1) {
|
||
$errors[] = 'Threshold must be at least 1.';
|
||
} else {
|
||
set_setting('frequent_ip_threshold', (string)$threshold);
|
||
$success = 'Frequent IP threshold saved.';
|
||
}
|
||
}
|
||
}
|
||
|
||
$retention_days = (int)get_setting('retention_days', '7');
|
||
$frequent_ip_threshold = (int)get_setting('frequent_ip_threshold', '5');
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="en">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||
<title>Settings – portspoof concentrator</title>
|
||
<style>
|
||
<?php include __DIR__ . '/includes/style.php'; ?>
|
||
</style>
|
||
<script>document.documentElement.setAttribute('data-theme',localStorage.getItem('theme')||'dark')</script>
|
||
</head>
|
||
<body>
|
||
<header>
|
||
<h1>portspoof<span>concentrator</span></h1>
|
||
<nav>
|
||
<a href="index.php">Dashboard</a>
|
||
<a href="nodes.php">Nodes</a>
|
||
<a href="settings.php" class="active">Settings</a>
|
||
<?php if (auth_enabled()): ?>
|
||
<a href="logout.php" style="color:var(--muted)">Sign out</a>
|
||
<?php endif; ?>
|
||
<?php include __DIR__ . '/includes/theme_toggle.php'; ?>
|
||
</nav>
|
||
</header>
|
||
<main>
|
||
|
||
<?php if ($success): ?>
|
||
<div class="alert ok"><?= h($success) ?></div>
|
||
<?php endif; ?>
|
||
<?php foreach ($errors as $e): ?>
|
||
<div class="alert err"><?= h($e) ?></div>
|
||
<?php endforeach; ?>
|
||
|
||
<section class="card">
|
||
<h2>Change password</h2>
|
||
<?php if (!auth_enabled()): ?>
|
||
<p class="muted">Authentication is disabled. Set <code>UI_PASS_HASH</code> in <code>config.php</code> to enable it.</p>
|
||
<?php else: ?>
|
||
<form method="post">
|
||
<input type="hidden" name="action" value="password">
|
||
<label>Current password
|
||
<input type="password" name="current_password" autocomplete="current-password" required>
|
||
</label>
|
||
<label>New password <small>(minimum 8 characters)</small>
|
||
<input type="password" name="new_password" autocomplete="new-password" required minlength="8">
|
||
</label>
|
||
<label>Confirm new password
|
||
<input type="password" name="confirm_password" autocomplete="new-password" required minlength="8">
|
||
</label>
|
||
<button type="submit">Update password</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<h2>Data retention</h2>
|
||
<p class="muted" style="margin-bottom:1rem;font-size:.85rem">
|
||
Connections older than the retention period are removed by the daily purge cron.
|
||
</p>
|
||
<form method="post">
|
||
<input type="hidden" name="action" value="retention">
|
||
<label>Retention period <small>(days)</small>
|
||
<input type="number" name="retention_days" min="1" max="3650"
|
||
value="<?= $retention_days ?>" style="width:120px">
|
||
</label>
|
||
<button type="submit">Save</button>
|
||
</form>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<h2>Frequent IP threshold</h2>
|
||
<p class="muted" style="margin-bottom:1rem;font-size:.85rem">
|
||
Minimum number of connections for an IP to appear in
|
||
<code>api/frequent_ips.php</code>.
|
||
</p>
|
||
<form method="post">
|
||
<input type="hidden" name="action" value="frequent_ip_threshold">
|
||
<label>Minimum connections
|
||
<input type="number" name="frequent_ip_threshold" min="1" max="99999"
|
||
value="<?= $frequent_ip_threshold ?>" style="width:120px">
|
||
</label>
|
||
<button type="submit">Save</button>
|
||
</form>
|
||
</section>
|
||
|
||
</main>
|
||
<?php include __DIR__ . '/includes/footer.php'; ?>
|
||
</body>
|
||
</html>
|