Improve powered-off alerts toggle layout and fix dev config sync

- Consolidate powered-off alerts toggle into single compact row
- Fix encryption key mismatch between dev and production environments
- Always sync production encryption key to prevent decryption errors
- Add sync command to toggle-mock.sh for manual config updates
This commit is contained in:
rcourtman
2025-10-05 20:17:47 +00:00
parent 35790834fc
commit 5693560ddd
3 changed files with 73 additions and 34 deletions
@@ -1033,21 +1033,10 @@ const dockerContainersGroupedByHost = createMemo<Record<string, Resource[]>>((pr
<h4 class="text-sm font-medium text-gray-700 dark:text-gray-200 mb-3">
VMs & Containers
</h4>
<div class="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between mb-3">
<div class="flex items-center gap-2">
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">
Powered-off alerts
</span>
<span
class={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold ${
props.guestDisableConnectivity
? 'bg-gray-200 text-gray-700 dark:bg-gray-600 dark:text-gray-100'
: 'bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-200'
}`}
>
{props.guestDisableConnectivity ? 'Off' : 'On'}
</span>
</div>
<div class="flex items-center gap-3 mb-3">
<span class="text-sm font-medium text-gray-700 dark:text-gray-200">
Powered-off alerts
</span>
<label class="relative inline-flex items-center cursor-pointer">
<input
type="checkbox"
@@ -1064,6 +1053,15 @@ const dockerContainersGroupedByHost = createMemo<Record<string, Resource[]>>((pr
/>
<div class="w-11 h-6 bg-gray-200 peer-focus:outline-none rounded-full peer dark:bg-gray-700 peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-blue-600"></div>
</label>
<span
class={`inline-flex items-center rounded-full px-2 py-0.5 text-[10px] font-semibold ${
props.guestDisableConnectivity
? 'bg-gray-200 text-gray-700 dark:bg-gray-600 dark:text-gray-100'
: 'bg-blue-100 text-blue-700 dark:bg-blue-900/40 dark:text-blue-200'
}`}
>
{props.guestDisableConnectivity ? 'Off' : 'On'}
</span>
</div>
<p class="text-xs text-gray-500 dark:text-gray-400 mb-3">
Turn this off if you routinely power guests down and dont want warnings.
+34 -18
View File
@@ -18,20 +18,23 @@ echo " Source: $PROD_DIR"
echo " Target: $DEV_DIR"
echo ""
# Copy encryption key if it exists AND dev doesn't have a key yet
# CRITICAL: Always sync production encryption key to dev
# This ensures dev can decrypt production's encrypted config files
if [ -f "$PROD_DIR/.encryption.key" ]; then
if [ ! -f "$DEV_DIR/.encryption.key" ]; then
cp -f "$PROD_DIR/.encryption.key" "$DEV_DIR/.encryption.key"
chmod 600 "$DEV_DIR/.encryption.key"
echo "✓ Synced encryption key (dev didn't have one)"
echo "✓ Synced encryption key from production"
else
# Dev already has a key - compare ages
if [ "$PROD_DIR/.encryption.key" -nt "$DEV_DIR/.encryption.key" ]; then
echo "⚠ Production encryption key is newer than dev key"
echo " This is unusual - dev key is usually created first"
echo " Keeping existing dev key to avoid breaking encrypted configs"
# Check if keys are different
if ! cmp -s "$PROD_DIR/.encryption.key" "$DEV_DIR/.encryption.key"; then
echo "⚠ Dev encryption key differs from production - syncing production key"
echo " (This prevents decryption errors when loading production configs)"
cp -f "$PROD_DIR/.encryption.key" "$DEV_DIR/.encryption.key"
chmod 600 "$DEV_DIR/.encryption.key"
echo "✓ Synced encryption key from production"
else
echo "✓ Dev encryption key already exists and is current"
echo "✓ Dev encryption key matches production"
fi
fi
fi
@@ -39,28 +42,41 @@ fi
# Copy nodes configuration - WITH VALIDATION
if [ -f "$PROD_DIR/nodes.enc" ]; then
# Check if production nodes.enc is valid (not corrupted)
# Only sync if destination doesn't exist OR production file is newer
# Only sync if destination doesn't exist OR production file is newer OR dev copy is corrupted
SHOULD_SYNC=false
if [ ! -f "$DEV_DIR/nodes.enc" ]; then
# Destination doesn't exist, safe to sync
SHOULD_SYNC=true
echo " → Dev nodes.enc doesn't exist, will sync from production"
elif [ "$PROD_DIR/nodes.enc" -nt "$DEV_DIR/nodes.enc" ]; then
# Production is newer
echo " → Production nodes.enc is newer than dev copy"
SHOULD_SYNC=true
else
# Dev is newer or same age - KEEP THE DEV COPY
echo " → Dev nodes.enc is current, keeping existing copy"
echo " → (Production: $(stat -c %y "$PROD_DIR/nodes.enc" 2>/dev/null | cut -d' ' -f1-2))"
echo " → (Dev: $(stat -c %y "$DEV_DIR/nodes.enc" 2>/dev/null | cut -d' ' -f1-2))"
# Dev copy exists - validate it before deciding
DEV_SIZE=$(stat -c %s "$DEV_DIR/nodes.enc" 2>/dev/null || echo 0)
PROD_SIZE=$(stat -c %s "$PROD_DIR/nodes.enc" 2>/dev/null || echo 0)
# Check if dev copy is suspiciously small (likely corrupted)
if [ "$DEV_SIZE" -lt 100 ]; then
echo " → Dev nodes.enc is too small ($DEV_SIZE bytes), likely corrupted"
SHOULD_SYNC=true
# Check if files are different (always prefer production to avoid drift)
elif ! cmp -s "$PROD_DIR/nodes.enc" "$DEV_DIR/nodes.enc"; then
echo " → Dev nodes.enc differs from production, syncing to avoid drift"
echo " → (Production: $PROD_SIZE bytes, Dev: $DEV_SIZE bytes)"
SHOULD_SYNC=true
else
# Files are identical
echo " → Dev nodes.enc is identical to production, no sync needed"
fi
fi
if [ "$SHOULD_SYNC" = true ]; then
# Back up the old dev copy if it exists (for debugging)
if [ -f "$DEV_DIR/nodes.enc" ]; then
cp -f "$DEV_DIR/nodes.enc" "$DEV_DIR/nodes.enc.before-sync-$(date +%Y%m%d-%H%M%S)" 2>/dev/null || true
fi
cp -f "$PROD_DIR/nodes.enc" "$DEV_DIR/nodes.enc"
chmod 600 "$DEV_DIR/nodes.enc"
echo "✓ Synced nodes configuration"
echo "✓ Synced nodes configuration from production"
fi
elif [ -f "$PROD_DIR/nodes.json" ]; then
cp -f "$PROD_DIR/nodes.json" "$DEV_DIR/nodes.json"
+26 -1
View File
@@ -129,6 +129,27 @@ edit_config() {
echo "Run '$0 on' or '$0 off' to apply changes"
}
sync_config() {
echo -e "${YELLOW}Syncing production configuration to dev...${NC}"
if [ -f "$ROOT_DIR/scripts/sync-production-config.sh" ]; then
"$ROOT_DIR/scripts/sync-production-config.sh"
echo ""
echo -e "${GREEN}✓ Configuration synced!${NC}"
# Only restart if backend is currently running
if pgrep -x pulse > /dev/null; then
echo ""
restart_backend
else
echo "Backend not running. Start hot-dev to use the updated config."
fi
else
echo -e "${RED}✗ Sync script not found${NC}"
return 1
fi
}
case "$1" in
on)
enable_mock
@@ -142,15 +163,19 @@ case "$1" in
edit)
edit_config
;;
sync)
sync_config
;;
*)
echo "Mock Data Mode Control for Pulse"
echo ""
echo "Usage: $0 {on|off|status|edit}"
echo "Usage: $0 {on|off|status|edit|sync}"
echo ""
echo " on - Enable mock data mode"
echo " off - Disable mock mode, use real nodes"
echo " status - Show current mock mode status"
echo " edit - Edit mock configuration"
echo " sync - Sync production config to dev (use after adding nodes)"
echo ""
echo "After changing modes, restart hot-dev:"
echo " Ctrl+C in hot-dev terminal"