diff --git a/dev-panel.vincentdevelopment.ca/htdocs/index.php b/dev-panel.vincentdevelopment.ca/htdocs/index.php index fa1c3df..632b817 100644 --- a/dev-panel.vincentdevelopment.ca/htdocs/index.php +++ b/dev-panel.vincentdevelopment.ca/htdocs/index.php @@ -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,15 +51,15 @@ requireLogin($action); $user = getCurrentUser(); // ---------- Login Action ---------- - if ($action === 'login') { $loginError = null; + if ($_SERVER['REQUEST_METHOD'] === 'POST') { $username = trim($_POST['username'] ?? ''); $password = $_POST['password'] ?? ''; if ($username !== '' && $password !== '') { - $db = getDb(); + $db = getDb(); $stmt = $db->prepare('SELECT id, username, password_hash, role FROM users WHERE username = ?'); $stmt->execute([$username]); $row = $stmt->fetch(PDO::FETCH_ASSOC); @@ -79,8 +78,8 @@ if ($action === 'login') { $loginError = 'Username and password are required.'; } } - ?> +
@@ -133,10 +132,9 @@ if ($action === 'login') { } // ---------- Self password change (processed for any authenticated action) ---------- - -$selfPasswordError = null; +$selfPasswordError = null; $selfPasswordMessage = null; -$passwordDialogOpen = false; +$passwordDialogOpen = false; if ( $user && @@ -157,7 +155,7 @@ if ( } elseif (strlen($newPassword) < 8) { $selfPasswordError = 'New password must be at least 8 characters.'; } else { - $db = getDb(); + $db = getDb(); $stmt = $db->prepare('SELECT password_hash FROM users WHERE id = ?'); $stmt->execute([$user['id']]); $row = $stmt->fetch(PDO::FETCH_ASSOC); @@ -165,17 +163,16 @@ if ( if (!$row || !password_verify($currentPassword, $row['password_hash'])) { $selfPasswordError = 'Current password is incorrect.'; } else { - $hash = password_hash($newPassword, PASSWORD_DEFAULT); + $hash = password_hash($newPassword, PASSWORD_DEFAULT); $update = $db->prepare('UPDATE users SET password_hash = ? WHERE id = ?'); $update->execute([$hash, $user['id']]); $selfPasswordMessage = 'Your password has been updated.'; } } } - // ---------- Page Layout (for authenticated users) ---------- - ?> + @@ -215,623 +212,628 @@ if ( -Invalid domain. Use only letters, numbers, dots and dashes.'; - } else { - // Build WordOps command - $flags = []; - - if ($stackType === 'wp') { - $flags[] = '--wp'; - } elseif ($stackType === 'wpfc') { - $flags[] = '--wpfc'; - } elseif ($stackType === 'plain') { - $flags[] = '--php'; + if (!$projectName) { + $projectName = $domain; } - if ($isMultisite === 'subdir') { - $flags[] = '--wpsubdir'; - } elseif ($isMultisite === 'subdomain') { - $flags[] = '--wpsubdomain'; - } + if (!$domain) { + echo 'WordOps log:
'; - echo '';
-
- @ob_flush();
- @flush();
-
- list($ok, $woLines) = runCommandStreaming($cmd, function ($line) {
- echo htmlspecialchars($line) . "\n";
- @ob_flush();
- @flush();
- });
-
- echo '';
-
- if ($ok) {
- // Record site owner in SQLite
- $db = getDb();
- $stmt = $db->prepare('INSERT OR REPLACE INTO sites (domain, owner_id, created_at) VALUES (?, ?, datetime("now"))');
- $stmt->execute([$domain, $user['id']]);
-
- echo 'Site created successfully.
'; - - // Run bootstrap if requested - if ($bootstrapProfile === 'standard') { - $adminUser = $bootstrapAdminUser; - $adminEmail = $bootstrapAdminEmail; - - $bootstrapArgs = [ - '--domain', $domain, - '--project-name', $projectName, - '--admin-user', $adminUser, - '--admin-email', $adminEmail, - ]; - - if ($themeStarterRepo !== '') { - $bootstrapArgs[] = '--theme-starter-repo'; - $bootstrapArgs[] = $themeStarterRepo; - } - if ($themeRemoteOrigin !== '') { - $bootstrapArgs[] = '--theme-remote-origin'; - $bootstrapArgs[] = $themeRemoteOrigin; - } - - $bootstrapCmd = escapeshellcmd($bootstrapScript); - foreach ($bootstrapArgs as $arg) { - $bootstrapCmd .= ' ' . escapeshellarg($arg); - } - - echo 'Bootstrap log:
'; - echo '';
-
- @ob_flush();
- @flush();
-
- list($bootstrapOk, $bootstrapLines) = runCommandStreaming($bootstrapCmd, function ($line) {
- echo htmlspecialchars($line) . "\n";
- @ob_flush();
- @flush();
- });
-
- echo '';
-
- if ($bootstrapOk) {
- echo 'Bootstrap completed: standard dev stack applied.
'; - } else { - echo 'Bootstrap failed: see log above.
'; - } + if ($stackType === 'wp') { + $flags[] = '--wp'; + } elseif ($stackType === 'wpfc') { + $flags[] = '--wpfc'; + } elseif ($stackType === 'plain') { + $flags[] = '--php'; } - echo ''; - } else { - echo 'Site creation failed. See WordOps log above.
'; - echo ''; - } + if ($isMultisite === 'subdir') { + $flags[] = '--wpsubdir'; + } elseif ($isMultisite === 'subdomain') { + $flags[] = '--wpsubdomain'; + } - echo 'WordOps log:
'; + echo '';
+
+ @ob_flush();
+ @flush();
+
+ list($ok, $woLines) = runCommandStreaming($cmd, function ($line) {
+ echo htmlspecialchars($line) . "\n";
+ @ob_flush();
+ @flush();
+ });
+
+ echo '';
if ($ok) {
- // Remove from metadata
- $stmt = $db->prepare('DELETE FROM sites WHERE domain = ?');
- $stmt->execute([$domain]);
+ // Record site owner in SQLite
+ $db = getDb();
+ $stmt = $db->prepare('INSERT OR REPLACE INTO sites (domain, owner_id, created_at) VALUES (?, ?, datetime("now"))');
+ $stmt->execute([$domain, $user['id']]);
- echo 'Site deleted: ' . htmlspecialchars($domain) . 'Site created successfully.
'; + + // Run bootstrap if requested + if ($bootstrapProfile === 'standard') { + $adminUser = $bootstrapAdminUser; + $adminEmail = $bootstrapAdminEmail; + + $bootstrapArgs = [ + '--domain', $domain, + '--project-name', $projectName, + '--admin-user', $adminUser, + '--admin-email', $adminEmail, + ]; + + if ($themeStarterRepo !== '') { + $bootstrapArgs[] = '--theme-starter-repo'; + $bootstrapArgs[] = $themeStarterRepo; + } + + if ($themeRemoteOrigin !== '') { + $bootstrapArgs[] = '--theme-remote-origin'; + $bootstrapArgs[] = $themeRemoteOrigin; + } + + $bootstrapCmd = escapeshellcmd($bootstrapScript); + + foreach ($bootstrapArgs as $arg) { + $bootstrapCmd .= ' ' . escapeshellarg($arg); + } + + echo 'Bootstrap log:
'; + echo '';
+
+ @ob_flush();
+ @flush();
+
+ list($bootstrapOk, $bootstrapLines) = runCommandStreaming($bootstrapCmd, function ($line) {
+ echo htmlspecialchars($line) . "\n";
+ @ob_flush();
+ @flush();
+ });
+
+ echo '';
+
+ if ($bootstrapOk) {
+ echo 'Bootstrap completed: standard dev stack applied.
'; + } else { + echo 'Bootstrap failed: see log above.
'; + } + } + + echo ''; } else { - echo 'Failed to delete site. Check the log below.'; + echo 'Site creation failed. See WordOps log above.
'; + echo ''; } - echo '' . htmlspecialchars(implode("\n", $output)) . '';
- echo '';
echo 'You're about to delete .
-This will remove the vhost and files. Databases are handled by WordOps according to its defaults.
+' . htmlspecialchars($userError) . '
'; - } - if ($generatedPasswordInfo) { - echo 'New password for ' . htmlspecialchars($generatedPasswordInfo['username']) . ': ';
- echo '' . htmlspecialchars($generatedPasswordInfo['password']) . '
No users found.
- -| Username | -Role | -Actions | -
|---|---|---|
| - | - | - - | -