Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Nov 25, 2025

myservers.cfg no longer gets written to or read (except for migration purposes), so it'd be better to read from the new values instead of continuing to use the old ones @elibosley @Squidly271 .

unless i'm missing something! see #1805

Summary by CodeRabbit

  • New Features

    • Switches to a centralized remote-access configuration with a legacy fallback and richer client-side handling.
    • Optional GraphQL submission path for applying remote settings when available.
  • Bug Fixes

    • Normalized boolean and port handling to prevent incorrect values reaching the UI.
    • Improved error handling and UI state restoration during save/apply flows.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 25, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a centralized ConnectConfig source and refactors Connect.page to derive and normalize remote-access settings, add client helpers for port parsing and building connect inputs, and extend submission to support legacy Dispatcher and optional Apollo GraphQL flows with improved error handling and legacy fallbacks.

Changes

Cohort / File(s) Change Summary
ConnectConfig class
include/connect-config.php
Adds ConnectConfig::getConfig() to centralize connect configuration retrieval used by Connect.page.
Connect page include & PHP normalization
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page
Includes connect-config.php; derives remoteDynamicRemoteAccessType, remoteWanAccessRaw, remoteUpnpEnabledRaw, remoteWanPortRaw from ConnectConfig with legacy myServersFlashCfg['remote'] fallback; normalizes booleans (default false) and port (numeric, default 0); exposes wanAccessOriginal/wanAccessOrg for client use; updates dnsCheckServer text to use normalized port.
Client helpers & form handling
plugin/.../Connect.page (JS additions)
Adds parsePort helper and new buildConnectSettingsInput to map UI selections into structured input; preserves dynamicManual/upnp logic but aligns with central config; normalizes WAN port/boolean parsing for UI.
Submission flow & error handling
plugin/.../Connect.page (JS additions)
Extends save/apply flow to support legacy Dispatcher POST and optional Apollo GraphQL mutations; aggregates mutation/promises with Promise.all; improves button state restoration and user-friendly error handling on failures.

Sequence Diagram(s)

sequenceDiagram
    participant UI as Browser UI (Connect.page)
    participant PHP as Connect.page (PHP)
    participant Config as ConnectConfig
    participant Legacy as Legacy myServersFlashCfg
    participant Dispatcher
    participant Apollo as Apollo GraphQL

    UI->>PHP: Load page
    PHP->>Config: ConnectConfig::getConfig()
    alt Config returned
        Config-->>PHP: Normalized config
    else Fallback to legacy
        PHP->>Legacy: read myServersFlashCfg['remote']
        Legacy-->>PHP: Legacy values
        PHP->>PHP: Derive normalized fields (wanAccess, upnp, port)
    end

    rect rgb(230,245,255)
        Note over UI,PHP: Client init uses `wanAccessOrg`, `remoteWanPortRaw`
        UI->>UI: parsePort(), buildConnectSettingsInput()
    end

    UI->>UI: Submit form → collect mutations
    UI->>Dispatcher: POST legacy endpoint (if used)
    alt Apollo available
        UI->>Apollo: send GraphQL mutations (Promise)
    end
    par Apply remote settings
        Dispatcher-->UI: response
        Apollo-->UI: response
    and
        UI-->UI: Promise.all → finalize success/error
    end
    rect rgb(255,235,235)
        Note over UI: On error restore button state and show message
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Review ConnectConfig::getConfig() for completeness and fallback correctness.
  • Verify normalization logic for booleans and port coercion.
  • Inspect new client helpers (parsePort, buildConnectSettingsInput) for edge cases and input validation.
  • Validate submission branching between Dispatcher and Apollo, the Promise aggregation, and error handling paths.
  • Confirm dnsCheckServer text and other UI updates use the new normalized values.

Poem

🐇 A rabbit hops through code so fine,
Central config now sings in line,
Ports parsed tidy, booleans true,
Old paths kept gently for the view,
Hooray — one source, one carrot stew! 🥕

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly addresses the main change: migrating from myservers config to connect config references throughout the codebase.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/connect

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65ef1f6 and b5caffc.

📒 Files selected for processing (1)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*

📄 CodeRabbit inference engine (.cursor/rules/default.mdc)

Never add comments unless they are needed for clarity of function

Files:

  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page
🔇 Additional comments (5)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page (5)

77-82: LGTM!

The type normalization for $wanAccessOriginal properly handles the format differences between JSON (boolean) and legacy cfg (string) values, ensuring consistent output for JavaScript.


99-102: LGTM!

Clean helper function with proper radix specification and explicit null return for invalid input.


159-173: LGTM!

The buildConnectSettingsInput function provides a clean mapping from UI selections to the GraphQL input structure, with appropriate null handling for UPnP-assigned ports.


285-285: LGTM!

The message now correctly uses $remoteWanPort derived from the new config source, consistent with the overall migration. The htmlspecialchars usage on the IP address is appropriate.


24-40: Based on my verification, I can now provide the final rewritten review comment:


Config read/write asymmetry is intentional but creates a potential mismatch window.

The PHP-side correctly reads from ConnectConfig::getConfig() with legacy fallback, and the normalization logic (filter_var for booleans, is_numeric for port) is solid. However, registerServer writes to both myservers.cfg (via Dispatcher.php) and the new config (via Apollo GraphQL mutation).

The asymmetry: if the Apollo client isn't available during a save, settings are written only to the legacy file. On the next page load, the code reads from connect.json first, then falls back to the legacy file—masking the mismatch temporarily. But if connect.json has been previously written and the Apollo mutation subsequently fails without being retried, connect.json becomes stale while the UI reflects the most recent value from myservers.cfg.

This appears to be by design for gradual migration, but ensure the architecture explicitly documents that Apollo client availability is required for consistent config state, or implement a synchronization mechanism between the two sources.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +24 to +28
$connectConfig = ConnectConfig::getConfig();
$legacyRemoteCfg = $serverState->myServersFlashCfg['remote'] ?? [];

$remoteDynamicRemoteAccessType = $connectConfig['dynamicRemoteAccessType'] ?? ($legacyRemoteCfg['dynamicRemoteAccessType'] ?? null);
$remoteWanAccessRaw = $connectConfig['wanaccess'] ?? ($legacyRemoteCfg['wanaccess'] ?? null);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Remote access writes legacy config after switching to connect.json

Lines 24-28 now populate the page from ConnectConfig::getConfig(), which reads configs/connect.json, but registerServer still posts updates to /boot/config/plugins/dynamix.my.servers/myservers.cfg (see line 147) even though the connect plugin’s persister migrates to and reads from connect.json. User edits to remote access or WAN port will therefore be saved only to the legacy file while the page reload continues to read the untouched connect.json, leaving the settings unchanged in practice.

Useful? React with 👍 / 👎.

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52.04%. Comparing base (832e9d0) to head (b5caffc).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1810   +/-   ##
=======================================
  Coverage   52.04%   52.04%           
=======================================
  Files         874      874           
  Lines       50372    50372           
  Branches     5017     5017           
=======================================
  Hits        26214    26214           
  Misses      24083    24083           
  Partials       75       75           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page (2)

92-92: Consider using json_encode() for JavaScript string output.

While the current values are well-controlled ('yes', 'no', or ''), using json_encode() would be more defensive against future changes that might introduce special characters.

-const wanAccessOrg = "<?=$wanAccessOriginal?>";
+const wanAccessOrg = <?=json_encode($wanAccessOriginal)?>;

57-57: Minor: Redundant null coalescing.

The ?? null is unnecessary since $remoteDynamicRemoteAccessType can already be null from line 27. However, this is harmless and documents the expected fallback clearly.

-$dynamicRemoteAccessType = $remoteDynamicRemoteAccessType ?? null;
+$dynamicRemoteAccessType = $remoteDynamicRemoteAccessType;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 832e9d0 and 65ef1f6.

📒 Files selected for processing (1)
  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page (5 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*

📄 CodeRabbit inference engine (.cursor/rules/default.mdc)

Never add comments unless they are needed for clarity of function

Files:

  • plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page
🔇 Additional comments (4)
plugin/source/dynamix.unraid.net/usr/local/emhttp/plugins/dynamix.my.servers/Connect.page (4)

24-30: LGTM! Clean configuration migration pattern.

The nested null coalescing operator provides a proper fallback chain from new config to legacy config to null default. This ensures backward compatibility during migration.


32-40: LGTM! Robust input normalization.

The use of filter_var with FILTER_VALIDATE_BOOLEAN and FILTER_NULL_ON_FAILURE correctly handles various boolean representations ("yes", "no", "true", "false", "1", "0") while safely defaulting to false for invalid inputs. The numeric port validation is also appropriately defensive.


77-82: LGTM! Proper type normalization for JavaScript interop.

The conditional chain correctly handles all possible types: booleans are converted to 'yes'/'no' strings, existing strings are preserved, and other types (including null) default to empty string.


220-220: LGTM! Correct variable substitution.

The error message properly uses the new $remoteWanPort variable which is guaranteed to be an integer, matching the %u format specifier.

@pujitm pujitm marked this pull request as draft November 25, 2025 20:07
@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL:

https://preview.dl.unraid.net/unraid-api/tag/PR1810/dynamix.unraid.net.plg

@Squidly271
Copy link
Contributor

@pujitm @elibosley

Just don't ever change the filename of the .plg without consulting me first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants