🐞 fix: Update code formatting
This commit is contained in:
@@ -10,6 +10,7 @@ session_start();
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_flush();
|
||||
}
|
||||
|
||||
ob_implicit_flush(true);
|
||||
|
||||
// Send headers early
|
||||
@@ -33,11 +34,9 @@ $themeRemoteOrigin = ''; // e.g. 'git@github.com:your-org/client-theme-repo.git'
|
||||
$dbPath = __DIR__ . '/panel.sqlite';
|
||||
|
||||
// ---------- Init DB ----------
|
||||
|
||||
$seedInfo = initDb();
|
||||
|
||||
// ---------- Routing / Auth Gate ----------
|
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
|
||||
|
||||
// Logout handler
|
||||
@@ -52,9 +51,9 @@ requireLogin($action);
|
||||
$user = getCurrentUser();
|
||||
|
||||
// ---------- Login Action ----------
|
||||
|
||||
if ($action === 'login') {
|
||||
$loginError = null;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$username = trim($_POST['username'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
@@ -79,8 +78,8 @@ if ($action === 'login') {
|
||||
$loginError = 'Username and password are required.';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -133,7 +132,6 @@ if ($action === 'login') {
|
||||
}
|
||||
|
||||
// ---------- Self password change (processed for any authenticated action) ----------
|
||||
|
||||
$selfPasswordError = null;
|
||||
$selfPasswordMessage = null;
|
||||
$passwordDialogOpen = false;
|
||||
@@ -172,10 +170,9 @@ if (
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Page Layout (for authenticated users) ----------
|
||||
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@@ -215,12 +212,9 @@ if (
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<?php
|
||||
|
||||
// ---------- Actions for authenticated users ----------
|
||||
|
||||
if ($action === 'create') {
|
||||
|
||||
<?php
|
||||
// ---------- Actions for authenticated users ----------
|
||||
if ($action === 'create') {
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && (!isset($_POST['op']) || $_POST['op'] !== 'self_change_password')) {
|
||||
$rawDomain = $_POST['domain'] ?? '';
|
||||
$domain = sanitizeDomain($rawDomain);
|
||||
@@ -300,12 +294,14 @@ if ($action === 'create') {
|
||||
$bootstrapArgs[] = '--theme-starter-repo';
|
||||
$bootstrapArgs[] = $themeStarterRepo;
|
||||
}
|
||||
|
||||
if ($themeRemoteOrigin !== '') {
|
||||
$bootstrapArgs[] = '--theme-remote-origin';
|
||||
$bootstrapArgs[] = $themeRemoteOrigin;
|
||||
}
|
||||
|
||||
$bootstrapCmd = escapeshellcmd($bootstrapScript);
|
||||
|
||||
foreach ($bootstrapArgs as $arg) {
|
||||
$bootstrapCmd .= ' ' . escapeshellarg($arg);
|
||||
}
|
||||
@@ -340,7 +336,6 @@ if ($action === 'create') {
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="card">
|
||||
@@ -394,8 +389,7 @@ if ($action === 'create') {
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
} elseif ($action === 'delete' && isset($_GET['domain'])) {
|
||||
} elseif ($action === 'delete' && isset($_GET['domain'])) {
|
||||
$domain = sanitizeDomain($_GET['domain']);
|
||||
|
||||
if (!$domain) {
|
||||
@@ -470,9 +464,7 @@ if ($action === 'create') {
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
} elseif ($action === 'users' && isAdmin()) {
|
||||
|
||||
} elseif ($action === 'users' && isAdmin()) {
|
||||
$db = getDb();
|
||||
$userMessage = null;
|
||||
$userError = null;
|
||||
@@ -501,6 +493,7 @@ if ($action === 'create') {
|
||||
// Check uniqueness
|
||||
$stmt = $db->prepare('SELECT COUNT(*) FROM users WHERE username = ?');
|
||||
$stmt->execute([$username]);
|
||||
|
||||
if ((int)$stmt->fetchColumn() > 0) {
|
||||
$userError = 'Username already exists.';
|
||||
} else {
|
||||
@@ -512,6 +505,7 @@ if ($action === 'create') {
|
||||
}
|
||||
} elseif ($op === 'reset_password') {
|
||||
$userId = (int)($_POST['user_id'] ?? 0);
|
||||
|
||||
if ($userId > 0) {
|
||||
$stmt = $db->prepare('SELECT username FROM users WHERE id = ?');
|
||||
$stmt->execute([$userId]);
|
||||
@@ -529,6 +523,7 @@ if ($action === 'create') {
|
||||
'username' => $row['username'],
|
||||
'password' => $newPass,
|
||||
];
|
||||
|
||||
$userMessage = 'Password reset for user "' . htmlspecialchars($row['username']) . '".';
|
||||
}
|
||||
} else {
|
||||
@@ -549,9 +544,11 @@ if ($action === 'create') {
|
||||
if ($userMessage) {
|
||||
echo '<p><strong>' . $userMessage . '</strong></p>';
|
||||
}
|
||||
|
||||
if ($userError) {
|
||||
echo '<p><strong>' . htmlspecialchars($userError) . '</strong></p>';
|
||||
}
|
||||
|
||||
if ($generatedPasswordInfo) {
|
||||
echo '<p class="muted">New password for <strong>' . htmlspecialchars($generatedPasswordInfo['username']) . '</strong>: ';
|
||||
echo '<code>' . htmlspecialchars($generatedPasswordInfo['password']) . '</code></p>';
|
||||
@@ -623,8 +620,7 @@ if ($action === 'create') {
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
} else {
|
||||
} else {
|
||||
// Default: site list
|
||||
$cmd = sprintf('sudo %s site list', escapeshellcmd($woPath));
|
||||
$output = [];
|
||||
@@ -642,16 +638,19 @@ if ($action === 'create') {
|
||||
|
||||
// Map of domain => [owner_id, username, role]
|
||||
$meta = [];
|
||||
|
||||
$stmt = $db->query('
|
||||
SELECT s.domain, s.owner_id, u.username, u.role
|
||||
FROM sites s
|
||||
LEFT JOIN users u ON s.owner_id = u.id
|
||||
');
|
||||
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$meta[$row['domain']] = $row;
|
||||
}
|
||||
|
||||
$sites = [];
|
||||
|
||||
foreach ($output as $line) {
|
||||
$line = trim($line);
|
||||
|
||||
@@ -668,11 +667,13 @@ if ($action === 'create') {
|
||||
|
||||
// Take the first column as the domain
|
||||
$parts = preg_split('/\s+/', $line);
|
||||
|
||||
if (!$parts || !isset($parts[0])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$domain = sanitizeDomain($parts[0]);
|
||||
|
||||
if (!$domain) {
|
||||
continue;
|
||||
}
|
||||
@@ -712,28 +713,30 @@ if ($action === 'create') {
|
||||
echo '<li style="margin-bottom:0.75rem;">';
|
||||
echo '<strong>' . $siteEsc . '</strong>';
|
||||
echo ' <span class="tag">dev</span>';
|
||||
|
||||
if ($owner) {
|
||||
echo ' <span class="muted" style="margin-left:0.5rem;">Owner: ' . htmlspecialchars($owner) . '</span>';
|
||||
} else {
|
||||
echo ' <span class="muted" style="margin-left:0.5rem;">Owner: Unassigned</span>';
|
||||
}
|
||||
|
||||
echo '<br>';
|
||||
echo '<a href="' . $url . '" target="_blank" rel="noopener">Open site</a> · ';
|
||||
echo '<a href="' . $adminUrl . '" target="_blank" rel="noopener">WP Admin</a> · ';
|
||||
echo '<a href="?action=delete&domain=' . urlencode($site) . '" class="muted danger">Delete…</a>';
|
||||
echo '</li>';
|
||||
}
|
||||
|
||||
echo '</ul>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
?>
|
||||
|
||||
<!-- Change Password Modal -->
|
||||
<div id="passwordModal" style="display:none;position:fixed;inset:0;z-index:50;align-items:center;justify-content:center;background:rgba(0,0,0,0.7);">
|
||||
<!-- Change Password Modal -->
|
||||
<div id="passwordModal" style="display:none;position:fixed;inset:0;z-index:50;align-items:center;justify-content:center;background:rgba(0,0,0,0.7);">
|
||||
<div class="card" style="max-width:420px;width:90%;margin:0 auto;">
|
||||
<h2 style="margin-top:0;">Change password</h2>
|
||||
|
||||
@@ -769,10 +772,10 @@ if ($action === 'create') {
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const userMenuToggle = document.getElementById('userMenuToggle');
|
||||
const userMenu = document.getElementById('userMenu');
|
||||
const changePasswordLink = document.getElementById('changePasswordLink');
|
||||
@@ -830,8 +833,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
// Re-open dialog after POST for feedback
|
||||
openPasswordModal();
|
||||
<?php endif; ?>
|
||||
});
|
||||
</script>
|
||||
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user