Add nodes management and initial setup pages

- Implemented nodes management functionality in `nodes.php` including create, update, and delete actions.
- Added form validation and error handling for node operations.
- Created a new setup page in `setup.php` for initial administrator account creation.
- Included user feedback messages for successful operations and errors.
- Designed user interface for both nodes management and setup processes.
This commit is contained in:
2025-12-14 01:33:12 -05:00
parent cf0ec74888
commit d8b76233c0
19 changed files with 8800 additions and 0 deletions

239
pathvector-admin/setup.php Normal file
View File

@@ -0,0 +1,239 @@
<?php
/**
* Pathvector Admin - Initial Setup Page
*/
session_start();
require_once __DIR__ . '/config/config.php';
require_once __DIR__ . '/lib/FlatFileDB.php';
require_once __DIR__ . '/lib/Logger.php';
require_once __DIR__ . '/lib/Auth.php';
$db = new FlatFileDB(DATA_PATH);
$logger = new Logger($db);
$auth = new Auth($db);
// Check if already setup
$users = $db->getAll('users');
if (!empty($users)) {
header('Location: login.php');
exit;
}
$error = '';
$success = false;
// Handle setup form submission
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$username = trim($_POST['username'] ?? '');
$password = $_POST['password'] ?? '';
$confirmPassword = $_POST['confirm_password'] ?? '';
// Validation
if (empty($username)) {
$error = 'Username is required.';
} elseif (strlen($username) < 3) {
$error = 'Username must be at least 3 characters.';
} elseif (empty($password)) {
$error = 'Password is required.';
} elseif (strlen($password) < 8) {
$error = 'Password must be at least 8 characters.';
} elseif ($password !== $confirmPassword) {
$error = 'Passwords do not match.';
} else {
// Create admin user
$result = $auth->createUser($username, $password, 'admin');
if ($result['success']) {
$logger->log('setup', 'Initial setup completed', ['admin_user' => $username]);
$success = true;
} else {
$error = $result['message'];
}
}
}
?>
<!DOCTYPE html>
<html lang="en" data-color-mode="auto" data-light-theme="light" data-dark-theme="dark_dimmed">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Setup - Pathvector Admin</title>
<link rel="stylesheet" href="https://unpkg.com/@primer/css@^20.2.4/dist/primer.css">
<style>
body {
min-height: 100vh;
display: flex;
align-items: center;
justify-content: center;
background: var(--color-canvas-subtle);
}
.setup-container {
width: 100%;
max-width: 440px;
padding: 24px;
}
.setup-header {
text-align: center;
margin-bottom: 24px;
}
.setup-logo {
display: inline-flex;
align-items: center;
justify-content: center;
width: 64px;
height: 64px;
background: var(--color-accent-emphasis);
border-radius: 12px;
margin-bottom: 16px;
}
.setup-logo svg {
width: 32px;
height: 32px;
fill: white;
}
.setup-box {
background: var(--color-canvas-default);
border: 1px solid var(--color-border-default);
border-radius: 6px;
padding: 24px;
}
.form-group {
margin-bottom: 16px;
}
.form-group:last-child {
margin-bottom: 0;
}
.form-group label {
display: block;
font-weight: 600;
margin-bottom: 4px;
font-size: 14px;
}
.form-group input {
width: 100%;
}
.form-hint {
font-size: 12px;
color: var(--color-fg-muted);
margin-top: 4px;
}
.setup-steps {
margin-top: 24px;
padding: 16px;
background: var(--color-canvas-subtle);
border-radius: 6px;
}
.setup-steps h3 {
font-size: 14px;
margin-bottom: 12px;
}
.setup-steps ol {
margin: 0;
padding-left: 20px;
font-size: 13px;
color: var(--color-fg-muted);
}
.setup-steps li {
margin-bottom: 4px;
}
</style>
</head>
<body>
<div class="setup-container">
<div class="setup-header">
<div class="setup-logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16">
<path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM8 0a8 8 0 100 16A8 8 0 008 0zm.75 4.75a.75.75 0 00-1.5 0v2.5h-2.5a.75.75 0 000 1.5h2.5v2.5a.75.75 0 001.5 0v-2.5h2.5a.75.75 0 000-1.5h-2.5v-2.5z"/>
</svg>
</div>
<h1 class="h3">Pathvector Admin Setup</h1>
<p class="color-fg-muted">Create your administrator account</p>
</div>
<div class="setup-box">
<?php if ($success): ?>
<div class="flash flash-success mb-3">
<strong>Setup Complete!</strong> Your administrator account has been created.
</div>
<a href="login.php" class="btn btn-primary btn-block">Continue to Login</a>
<?php else: ?>
<?php if ($error): ?>
<div class="flash flash-error mb-3">
<?= htmlspecialchars($error) ?>
</div>
<?php endif; ?>
<form method="POST" action="">
<div class="form-group">
<label for="username">Administrator Username</label>
<input type="text"
id="username"
name="username"
class="form-control"
value="<?= htmlspecialchars($_POST['username'] ?? '') ?>"
autocomplete="username"
autofocus
required>
<p class="form-hint">Choose a username for the admin account.</p>
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password"
id="password"
name="password"
class="form-control"
autocomplete="new-password"
required>
<p class="form-hint">Minimum 8 characters.</p>
</div>
<div class="form-group">
<label for="confirm_password">Confirm Password</label>
<input type="password"
id="confirm_password"
name="confirm_password"
class="form-control"
autocomplete="new-password"
required>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block">
Create Administrator Account
</button>
</div>
</form>
<div class="setup-steps">
<h3>Next Steps After Setup</h3>
<ol>
<li>Configure your ASN(s)</li>
<li>Add router nodes</li>
<li>Create peer templates</li>
<li>Add BGP peers</li>
<li>Set up execution hosts</li>
<li>Generate and apply configurations</li>
</ol>
</div>
<?php endif; ?>
</div>
</div>
</body>
</html>