Files
portspoof_concentrator/settings.php

81 lines
2.5 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
require_once __DIR__ . '/includes/auth.php';
require_login();
$errors = [];
$success = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$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.';
}
}
?>
<!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>
</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; ?>
</nav>
</header>
<main>
<?php if ($success): ?>
<div class="alert ok"><?= htmlspecialchars($success, ENT_QUOTES, 'UTF-8') ?></div>
<?php endif; ?>
<?php foreach ($errors as $e): ?>
<div class="alert err"><?= htmlspecialchars($e, ENT_QUOTES, 'UTF-8') ?></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">
<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>
</main>
<?php include __DIR__ . '/includes/footer.php'; ?>
</body>
</html>