Compare commits
5 Commits
1a7e587092
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 7937261925 | |||
| 7babef1372 | |||
| d7ca1abece | |||
|
|
e8d324e89d | ||
|
|
292e7e98bc |
@@ -1,3 +1,5 @@
|
||||
[user]
|
||||
name = VDI Devs
|
||||
email = dev@vincentdesign.ca
|
||||
[safe]
|
||||
directory = /var/www
|
||||
|
||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -4,3 +4,10 @@
|
||||
.well-known/
|
||||
logs/
|
||||
*.sqlite
|
||||
.cache/
|
||||
.config/
|
||||
.local/
|
||||
.npm/
|
||||
.zcompdump
|
||||
*.local
|
||||
|
||||
|
||||
@@ -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>
|
||||
@@ -216,11 +213,8 @@ if (
|
||||
</header>
|
||||
|
||||
<?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,7 +389,6 @@ if ($action === 'create') {
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
} elseif ($action === 'delete' && isset($_GET['domain'])) {
|
||||
$domain = sanitizeDomain($_GET['domain']);
|
||||
|
||||
@@ -470,9 +464,7 @@ if ($action === 'create') {
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
} 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,7 +620,6 @@ if ($action === 'create') {
|
||||
</form>
|
||||
</div>
|
||||
<?php
|
||||
|
||||
} else {
|
||||
// Default: site list
|
||||
$cmd = sprintf('sudo %s site list', escapeshellcmd($woPath));
|
||||
@@ -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,24 +713,26 @@ 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 -->
|
||||
@@ -832,6 +835,5 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
<?php endif; ?>
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
8
helpers/dev-sites.path
Normal file
8
helpers/dev-sites.path
Normal file
@@ -0,0 +1,8 @@
|
||||
[Unit]
|
||||
Description=Watch for new dev sites
|
||||
|
||||
[Path]
|
||||
PathModified=/var/www
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
6
helpers/dev-sites.service
Normal file
6
helpers/dev-sites.service
Normal file
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Update hosts entries for dev sites
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/bin/update-dev-hosts.sh
|
||||
56
helpers/gen-wpcontent-shares
Executable file
56
helpers/gen-wpcontent-shares
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
wwwRoot="/var/www"
|
||||
outFile="/etc/samba/wordops-wpcontent-shares.conf"
|
||||
tmpFile="$(mktemp)"
|
||||
|
||||
# Change these to match your world:
|
||||
sambaGroup="dev" # group allowed to access shares
|
||||
forceGroup="dev" # group to force on created files (optional)
|
||||
|
||||
{
|
||||
echo "; AUTO-GENERATED FILE - DO NOT EDIT"
|
||||
echo "; Generated: $(date -Is)"
|
||||
echo
|
||||
|
||||
shopt -s nullglob
|
||||
for siteDir in "${wwwRoot}"/*; do
|
||||
site="$(basename "${siteDir}")"
|
||||
wpContent="${wwwRoot}/${site}/htdocs/wp-content"
|
||||
|
||||
# Only create shares for sites that look like WP installs
|
||||
if [[ -d "${wpContent}" ]]; then
|
||||
cat <<SHARE
|
||||
|
||||
[${site}]
|
||||
comment = WordPress wp-content for ${site}
|
||||
path = ${wpContent}
|
||||
browseable = yes
|
||||
writable = yes
|
||||
read only = no
|
||||
guest ok = no
|
||||
|
||||
; Lock access down to a group
|
||||
valid users = @${sambaGroup}
|
||||
|
||||
; Keep permissions sane for webserver + devs
|
||||
force group = ${forceGroup}
|
||||
create mask = 0664
|
||||
directory mask = 2775
|
||||
|
||||
; Optional: reduce Finder/Windows junk
|
||||
veto files = /Thumbs.db/.DS_Store/._.DS_Store/
|
||||
SHARE
|
||||
fi
|
||||
done
|
||||
} > "${tmpFile}"
|
||||
|
||||
# Basic sanity check: refuse to install a broken file
|
||||
testparm -s "${tmpFile}" >/dev/null
|
||||
|
||||
sudo mv "${tmpFile}" "${outFile}"
|
||||
sudo chmod 0644 "${outFile}"
|
||||
|
||||
# Reload Samba to pick up new shares (no disconnect like restart)
|
||||
sudo systemctl reload smbd || sudo systemctl reload samba
|
||||
9
helpers/gen-wpcontent-shares.path
Normal file
9
helpers/gen-wpcontent-shares.path
Normal file
@@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=Watch /var/www and regenerate Samba shares on change
|
||||
|
||||
[Path]
|
||||
PathChanged=/var/www
|
||||
PathModified=/var/www
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
6
helpers/gen-wpcontent-shares.service
Normal file
6
helpers/gen-wpcontent-shares.service
Normal file
@@ -0,0 +1,6 @@
|
||||
[Unit]
|
||||
Description=Generate Samba shares for WordPress wp-content folders
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
ExecStart=/usr/local/sbin/gen-wpcontent-shares
|
||||
31
helpers/update-dev-hosts.sh
Normal file
31
helpers/update-dev-hosts.sh
Normal file
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
HOSTS_FILE="/etc/hosts"
|
||||
SITES_DIR="/var/www"
|
||||
DEV_DOMAIN="vincentdevelopment.ca"
|
||||
|
||||
TMP=$(mktemp)
|
||||
|
||||
echo "# BEGIN DEV-SITES" >> "$TMP"
|
||||
|
||||
for dir in "$SITES_DIR"/*; do
|
||||
site=$(basename "$dir")
|
||||
|
||||
# Skip system dirs
|
||||
[[ "$site" == "html" ]] && continue
|
||||
|
||||
echo "127.0.0.1 $site" >> "$TMP"
|
||||
|
||||
# Uncomment when system goes live
|
||||
# echo "127.0.0.1 $site $site.$DEV_DOMAIN"
|
||||
done
|
||||
|
||||
echo "# END DEV-SITES" >> "$TMP"
|
||||
|
||||
# Remove existing block
|
||||
sed -i '/# BEGIN DEV-SITES/,/# END DEV-SITES/d' "$HOSTS_FILE"
|
||||
|
||||
# Append fresh block
|
||||
cat "$TMP" >> "$HOSTS_FILE"
|
||||
|
||||
rm "$TMP"
|
||||
@@ -90,8 +90,10 @@ else
|
||||
if wp user list --field=user_email | grep -q "^${ADMIN_EMAIL}\$"; then
|
||||
echo "Admin email ${ADMIN_EMAIL} already in use; skipping user create."
|
||||
else
|
||||
wp user create "$ADMIN_USER" "$ADMIN_EMAIL" --role=administrator --user_pass="$(openssl rand -base64 16)"
|
||||
echo "Admin user $ADMIN_USER created with email $ADMIN_EMAIL (random password)."
|
||||
PASS=$(openssl rand -base64 16)
|
||||
|
||||
wp user create "$ADMIN_USER" "$ADMIN_EMAIL" --role=administrator --user_pass="$PASS"
|
||||
echo "Admin user $ADMIN_USER created with email $ADMIN_EMAIL ($PASS)."
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -119,6 +121,12 @@ DEV_PLUGINS=(
|
||||
query-monitor
|
||||
user-switching
|
||||
debug-bar
|
||||
https://docs.vincentdevelopment.ca/files/advanced-custom-fields-pro.zip
|
||||
https://docs.vincentdevelopment.ca/files/gravity-forms.zip
|
||||
autodescription
|
||||
better-search-replace
|
||||
google-site-kit
|
||||
simple-history
|
||||
)
|
||||
|
||||
for PLUGIN in "${DEV_PLUGINS[@]}"; do
|
||||
@@ -151,7 +159,7 @@ if [[ -n "$THEME_STARTER_REPO" ]]; then
|
||||
mkdir -p "$THEMES_DIR"
|
||||
|
||||
# Slug from project name
|
||||
THEME_SLUG=$(echo "$PROJECT_NAME" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-')
|
||||
THEME_SLUG=$(echo "$PROJECT_NAME" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed 's/-$//')
|
||||
[[ -z "$THEME_SLUG" ]] && THEME_SLUG="custom-theme"
|
||||
|
||||
TARGET_THEME_DIR="${THEMES_DIR}/${THEME_SLUG}"
|
||||
@@ -187,4 +195,15 @@ else
|
||||
echo "==> Theme starter repo not provided; skipping theme bootstrap."
|
||||
fi
|
||||
|
||||
echo "==> Installing dependencies..."
|
||||
cd "$TARGET_THEME_DIR"
|
||||
/usr/local/bin/composer install
|
||||
/usr/bin/npm install
|
||||
|
||||
echo "==> Doing initial build..."
|
||||
/usr/bin/npm run build
|
||||
|
||||
echo "==> Updating site permissions..."
|
||||
sudo /usr/local/bin/wo-fix-perms.sh "$DOMAIN"
|
||||
|
||||
echo "==> Bootstrap complete."
|
||||
|
||||
Reference in New Issue
Block a user