151 lines
7.4 KiB
PHP
151 lines
7.4 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// Initialize database and create table if it doesn't exist
|
|
try {
|
|
$pdo = db();
|
|
$pdo->exec("CREATE TABLE IF NOT EXISTS services (
|
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
|
name VARCHAR(255) NOT NULL,
|
|
repo_url VARCHAR(255) NOT NULL,
|
|
owner_team VARCHAR(255) NOT NULL,
|
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
)");
|
|
} catch (PDOException $e) {
|
|
// If this fails, the page will show a generic error.
|
|
error_log("DB connection or table creation failed: " . $e->getMessage());
|
|
}
|
|
|
|
// Fetch services
|
|
$services = [];
|
|
if (isset($pdo)) {
|
|
$stmt = $pdo->query("SELECT id, name, repo_url, owner_team, created_at FROM services ORDER BY created_at DESC");
|
|
$services = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
// Handle feedback messages
|
|
$feedback = $_SESSION['feedback'] ?? null;
|
|
unset($_SESSION['feedback']);
|
|
|
|
$project_name = htmlspecialchars($_SERVER['PROJECT_NAME'] ?? 'Aegis Platform');
|
|
$project_description = htmlspecialchars($_SERVER['PROJECT_DESCRIPTION'] ?? 'The Proactive System Integrity Platform');
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title><?= $project_name ?></title>
|
|
<meta name="description" content="<?= $project_description ?>">
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
<script src="https://unpkg.com/feather-icons"></script>
|
|
</head>
|
|
<body>
|
|
|
|
<header class="p-4 text-white header-gradient">
|
|
<div class="container d-flex justify-content-between align-items-center">
|
|
<h1 class="h4 mb-0"><?= $project_name ?></h1>
|
|
<p class="mb-0 d-none d-sm-block"><?= $project_description ?></p>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="container mt-5">
|
|
<div class="row">
|
|
<div class="col-lg-4 mb-4">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title mb-3"><i data-feather="plus-circle" class="me-2"></i>Register a New Service</h5>
|
|
<form action="add_service.php" method="POST">
|
|
<div class="mb-3">
|
|
<label for="name" class="form-label">Service Name</label>
|
|
<input type="text" class="form-control" id="name" name="name" placeholder="e.g., Authentication Service" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="repo_url" class="form-label">Repository URL</label>
|
|
<input type="url" class="form-control" id="repo_url" name="repo_url" placeholder="https://github.com/user/repo" required>
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="owner_team" class="form-label">Owner (Team)</label>
|
|
<input type="text" class="form-control" id="owner_team" name="owner_team" placeholder="e.g., Core Infrastructure" required>
|
|
</div>
|
|
<button type="submit" class="btn btn-primary w-100">Add Service</button>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="col-lg-8">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h5 class="card-title mb-3"><i data-feather="database" class="me-2"></i>Registered Services</h5>
|
|
<?php if (empty($services) && isset($pdo)): ?>
|
|
<div class="text-center text-muted p-4">
|
|
<i data-feather="hard-drive" class="mb-3" style="width: 48px; height: 48px;"></i>
|
|
<p>No services registered yet.<br>Use the form to add the first one.</p>
|
|
</div>
|
|
<?php elseif (!isset($pdo)): ?>
|
|
<div class="alert alert-danger">Could not connect to the database. Please check the configuration.</div>
|
|
<?php else: ?>
|
|
<div class="table-responsive">
|
|
<table class="table table-hover">
|
|
<thead class="table-light">
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Repository</th>
|
|
<th>Owner</th>
|
|
<th>Registered</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($services as $service): ?>
|
|
<tr>
|
|
<td><?= htmlspecialchars($service['name']) ?></td>
|
|
<td><a href="<?= htmlspecialchars($service['repo_url']) ?>" target="_blank" rel="noopener noreferrer"><?= htmlspecialchars(parse_url($service['repo_url'], PHP_URL_HOST) . parse_url($service['repo_url'], PHP_URL_PATH)) ?><i data-feather="external-link" class="ms-1" style="width: 14px; height: 14px;"></i></a></td>
|
|
<td><?= htmlspecialchars($service['owner_team']) ?></td>
|
|
<td><?= date("M d, Y", strtotime($service['created_at'])) ?></td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<?php if ($feedback): ?>
|
|
<div class="toast-container">
|
|
<div id="feedbackToast" class="toast show align-items-center text-white bg-<?= $feedback['type'] ?> border-0" role="alert" aria-live="assertive" aria-atomic="true">
|
|
<div class="d-flex">
|
|
<div class="toast-body">
|
|
<?= htmlspecialchars($feedback['message']) ?>
|
|
</div>
|
|
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<footer class="container text-center text-muted py-4">
|
|
<small>© <?= date('Y') ?> <?= $project_name ?>. All rights reserved.</small>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivrnet.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script>
|
|
feather.replace();
|
|
|
|
// Auto-hide toast
|
|
const toastElement = document.getElementById('feedbackToast');
|
|
if (toastElement) {
|
|
const toast = new bootstrap.Toast(toastElement, { delay: 5000 });
|
|
toast.show();
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|