From 8bfdf3769bb6363119c8459950b5efb1e67b7b19 Mon Sep 17 00:00:00 2001 From: "courtmanr@gmail.com" Date: Thu, 20 Nov 2025 11:46:11 +0000 Subject: [PATCH] Update config persistence, crypto, and dev script --- internal/config/persistence.go | 6 ++++++ internal/crypto/crypto.go | 23 +++++++++++++++-------- scripts/hot-dev.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/internal/config/persistence.go b/internal/config/persistence.go index d120048..2715079 100644 --- a/internal/config/persistence.go +++ b/internal/config/persistence.go @@ -901,6 +901,9 @@ func (c *ConfigPersistence) saveNodesConfig(pveInstances []PVEInstance, pbsInsta return err } + // DEBUG: Log the JSON data being saved to check for TemperatureMonitoringEnabled + log.Info().Str("json", string(data)).Msg("DEBUG: Saving nodes config JSON") + if err := c.EnsureConfigDir(); err != nil { return err } @@ -1051,6 +1054,9 @@ func (c *ConfigPersistence) LoadNodesConfig() (*NodesConfig, error) { } } + // DEBUG: Log the JSON data loaded from disk + log.Info().Str("json", string(data)).Msg("DEBUG: Loaded nodes config JSON") + var config NodesConfig if err := json.Unmarshal(data, &config); err != nil { return nil, err diff --git a/internal/crypto/crypto.go b/internal/crypto/crypto.go index ca2d84e..70a887a 100644 --- a/internal/crypto/crypto.go +++ b/internal/crypto/crypto.go @@ -52,15 +52,21 @@ func getOrCreateKeyAt(dataDir string) ([]byte, error) { // Try to read existing key from new location if data, err := os.ReadFile(keyPath); err == nil { - key := make([]byte, 32) - n, err := base64.StdEncoding.Decode(key, data) - if err == nil && n == 32 { - log.Debug().Msg("Found and loaded existing encryption key") - return key, nil + // Use DecodedLen to allocate sufficient space, then slice to actual length + // This prevents panics if the file contains more data than expected + decoded := make([]byte, base64.StdEncoding.DecodedLen(len(data))) + n, err := base64.StdEncoding.Decode(decoded, data) + if err == nil { + if n == 32 { + log.Debug().Msg("Found and loaded existing encryption key") + return decoded[:n], nil + } + log.Warn(). + Int("decodedBytes", n). + Msg("Encryption key has invalid length (expected 32 bytes)") } else { log.Warn(). Err(err). - Int("decodedBytes", n). Msg("Failed to decode encryption key") } } else { @@ -70,9 +76,10 @@ func getOrCreateKeyAt(dataDir string) ([]byte, error) { // Check for key in old location and migrate if found (only if paths differ) if dataDir != "/etc/pulse" && keyPath != oldKeyPath { if data, err := os.ReadFile(oldKeyPath); err == nil { - key := make([]byte, 32) - n, err := base64.StdEncoding.Decode(key, data) + decoded := make([]byte, base64.StdEncoding.DecodedLen(len(data))) + n, err := base64.StdEncoding.Decode(decoded, data) if err == nil && n == 32 { + key := decoded[:n] // Migrate key to new location if err := os.MkdirAll(filepath.Dir(keyPath), 0700); err != nil { // Migration failed, but we can still use the old key diff --git a/scripts/hot-dev.sh b/scripts/hot-dev.sh index 163c97a..98e68ed 100755 --- a/scripts/hot-dev.sh +++ b/scripts/hot-dev.sh @@ -24,9 +24,28 @@ load_env_file "${ROOT_DIR}/.env.dev" FRONTEND_PORT=${FRONTEND_PORT:-${PORT:-7655}} PORT=${PORT:-${FRONTEND_PORT}} +# Try to detect LAN IP +if [[ -z ${LAN_IP:-} ]]; then + # Try hostname -I (Linux) + if command -v hostname >/dev/null 2>&1 && hostname -I >/dev/null 2>&1; then + LAN_IP=$(hostname -I | awk '{print $1}') + fi + + # Fallback for macOS + if [[ -z ${LAN_IP:-} ]]; then + LAN_IP=$(ipconfig getifaddr en0 2>/dev/null || echo "") + fi + + # Fallback to 0.0.0.0 if detection fails + if [[ -z ${LAN_IP:-} ]]; then + LAN_IP="0.0.0.0" + fi +fi + FRONTEND_DEV_HOST=${FRONTEND_DEV_HOST:-0.0.0.0} FRONTEND_DEV_PORT=${FRONTEND_DEV_PORT:-${FRONTEND_PORT}} -PULSE_DEV_API_HOST=${PULSE_DEV_API_HOST:-127.0.0.1} +# Use LAN IP for API host so other devices can connect +PULSE_DEV_API_HOST=${PULSE_DEV_API_HOST:-${LAN_IP}} PULSE_DEV_API_PORT=${PULSE_DEV_API_PORT:-7656} if [[ -z ${PULSE_DEV_API_URL:-} ]]; then @@ -43,9 +62,13 @@ if [[ -z ${PULSE_DEV_WS_URL:-} ]]; then fi fi +# Allow all origins for LAN access +ALLOWED_ORIGINS="*" + export FRONTEND_PORT PORT export FRONTEND_DEV_HOST FRONTEND_DEV_PORT export PULSE_DEV_API_HOST PULSE_DEV_API_PORT PULSE_DEV_API_URL PULSE_DEV_WS_URL +export ALLOWED_ORIGINS # Auto-detect pulse-sensor-proxy socket if available HOST_PROXY_SOCKET="/mnt/pulse-proxy/pulse-sensor-proxy.sock" @@ -77,7 +100,8 @@ cat <