From 5693560dddbd9875eb0e278518ff668fd9bbf652 Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sun, 5 Oct 2025 20:17:47 +0000 Subject: [PATCH] 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 --- .../src/components/Alerts/ThresholdsTable.tsx | 28 +++++----- scripts/sync-production-config.sh | 52 ++++++++++++------- scripts/toggle-mock.sh | 27 +++++++++- 3 files changed, 73 insertions(+), 34 deletions(-) diff --git a/frontend-modern/src/components/Alerts/ThresholdsTable.tsx b/frontend-modern/src/components/Alerts/ThresholdsTable.tsx index bc428f36a..b83f2de31 100644 --- a/frontend-modern/src/components/Alerts/ThresholdsTable.tsx +++ b/frontend-modern/src/components/Alerts/ThresholdsTable.tsx @@ -1033,21 +1033,10 @@ const dockerContainersGroupedByHost = createMemo>((pr

VMs & Containers

-
-
- - Powered-off alerts - - - {props.guestDisableConnectivity ? 'Off' : 'On'} - -
+
+ + Powered-off alerts + + + {props.guestDisableConnectivity ? 'Off' : 'On'} +

Turn this off if you routinely power guests down and don’t want warnings. diff --git a/scripts/sync-production-config.sh b/scripts/sync-production-config.sh index fe9b729f6..64cf0c557 100755 --- a/scripts/sync-production-config.sh +++ b/scripts/sync-production-config.sh @@ -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" diff --git a/scripts/toggle-mock.sh b/scripts/toggle-mock.sh index 4f3c90e3e..43dd4a570 100755 --- a/scripts/toggle-mock.sh +++ b/scripts/toggle-mock.sh @@ -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"