Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

dkaser
Copy link
Collaborator

@dkaser dkaser commented Sep 16, 2025

Summary by CodeRabbit

  • New Features

    • Added “Add Peers to /etc/hosts” option in Tailscale settings. When enabled, the server will populate /etc/hosts with Tailnet peer names for on-server name resolution and automatically update entries after changes.
  • Behavior

    • Peer entries are added automatically when enabled; certain exit-node peers are excluded from being added.
  • Documentation

    • Added UI help text describing the option and updated DNS warning to reference it as a safer alternative to MagicDNS.

Copy link

coderabbitai bot commented Sep 16, 2025

Walkthrough

Adds a user-configurable option to add Tailscale peers to /etc/hosts. Adds a UI setting and localization entries, a new Config flag, implements System::addToHostFile(...), and invokes it from Watcher when enabled to write self and peer host mappings while skipping Mullvad exit nodes.

Changes

Cohort / File(s) Summary
UI Setting
src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php
Adds a select setting ADD_PEERS_TO_HOSTS (No/Yes) bound to $tailscaleConfig->AddPeersToHosts, with label/help using new translation keys; submitted with the settings form.
Localization
src/usr/local/emhttp/plugins/tailscale/locales/en_US.json
Adds settings.hosts and settings.context.hosts strings; updates warnings.dns to mention the new hosts option as a safer alternative.
Backend: Config
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Config.php
Adds public boolean property AddPeersToHosts, initialized from ADD_PEERS_TO_HOSTS.
Backend: System
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php
Class now extends \EDACerton\PluginUtils\System; adds public static function addToHostFile(\stdClass $status): void to collect self+peer entries, validate IPv4, skip peers tagged tag:mullvad-exit-node, and update /etc/hosts.
Backend: Watcher
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Watcher.php
After applying config and services, conditionally invokes Tailscale\System::addToHostFile($status) when AddPeersToHosts is enabled.
CI/config
.coderabbit.yaml
Adds reviews.pre_merge_checks.docstrings.mode: off; removes unit_tests: enabled: false under finishing_touches; removes level: default under tools.phpstan; other finishing_touches docstrings settings unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as User
  participant UI as Settings UI
  participant C as Config (persisted)
  participant W as Watcher
  participant S as System::addToHostFile
  participant H as /etc/hosts

  U->>UI: Set "Add Peers to /etc/hosts" = Yes
  UI->>C: Save ADD_PEERS_TO_HOSTS=1

  Note over W: Periodic/background run
  W->>C: Load AddPeersToHosts
  alt AddPeersToHosts enabled
    W->>S: addToHostFile(status)
    S->>S: Collect self + peer entries (skip tag:mullvad-exit-node)
    S->>H: Update entries (validated IPv4)
  else Disabled
    W-->>W: Skip hosts update
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Pre-merge checks and finishing touches

✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change — adding an option to include Tailscale peers in /etc/hosts — and maps directly to the changes in the UI, config, and system behavior. It is concise, specific, free of noise, and uses a conventional "feat:" prefix appropriate for the scope of the change.
✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hosts-file

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions github-actions bot added the feat label Sep 16, 2025
Copy link

@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 (3)
src/usr/local/emhttp/plugins/tailscale/locales/en_US.json (1)

63-65: Tiny copy tweak (optional).

Consider “Tailnet DNS names” instead of “Tailnet addresses” for precision.

- "hosts": "Adds Tailscale peers to /etc/hosts for name resolution. This is useful if you want to be able to use Tailnet addresses, without the potential complications of enabling Tailscale DNS on the server."
+ "hosts": "Adds Tailscale peers to /etc/hosts for name resolution. This is useful if you want to use Tailnet DNS names, without the potential complications of enabling Tailscale DNS on the server."
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Watcher.php (1)

89-94: Also refresh /etc/hosts on DNS name changes (optional).

When the DNS name changes, peers/self may also have changed. Consider reapplying hosts to stay current.

                 if ($newTsName != $tsName) {
                     $utils->logmsg("Detected DNS name change");
                     $tsName = $newTsName;

                     $utils->run_task('Tailscale\System::refreshWebGuiCert');
+                    if ($this->config->AddPeersToHosts) {
+                        // Re-sync hosts mappings with latest status
+                        $utils->run_task('Tailscale\System::addToHostFile', array($status));
+                    }
                 }
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (1)

34-47: Self entry handling is reasonable; consider IPv6 support (optional).

Only IPv4 entries are added. If acceptable, you can include IPv6 too.

-                if (is_string($ip) && filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) {
+                if (is_string($ip) && filter_var($ip, FILTER_VALIDATE_IP)) {
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4968cb5 and cf6f59a.

⛔ Files ignored due to path filters (1)
  • src/usr/local/php/unraid-tailscale-utils/composer.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php (1 hunks)
  • src/usr/local/emhttp/plugins/tailscale/locales/en_US.json (3 hunks)
  • src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Config.php (2 hunks)
  • src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (1 hunks)
  • src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Watcher.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (1)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Utils.php (2)
  • Utils (22-184)
  • logwrap (66-73)
src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php (1)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Info.php (1)
  • tr (66-69)
🪛 PHPMD (2.15.0)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php

50-50: Avoid unused local variables such as '$k'. (undefined)

(UnusedLocalVariable)

🔇 Additional comments (8)
src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Config.php (2)

32-32: AddPeersToHosts config flag looks good.

Public typed bool is consistent with the existing config surface.


56-56: Initialization default is sane; confirm persistence path.

Defaulting to "0" via boolval is fine given update.php writes "0/1". Please confirm ADD_PEERS_TO_HOSTS is included wherever config gets persisted/loaded in other flows (e.g., diagnostics export), to avoid drift.

src/usr/local/emhttp/plugins/tailscale/locales/en_US.json (2)

50-50: Label reads clearly.

"Add Peers to /etc/hosts" aligns with the setting behavior.


103-103: DNS warning addition is helpful.

Explicitly pointing users to the safer hosts alternative is a good UX touch.

src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/Watcher.php (1)

74-76: Good: gated hostfile update behind config; run after services restart.

This fits the startup flow.

src/usr/local/emhttp/plugins/tailscale/include/Pages/Settings.php (1)

105-117: Hosts toggle wiring looks correct.

Name/id keys match config, and text uses translations properly.

src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (2)

29-29: Extending base System is appropriate.

Keeps hostfile behavior centralized if the helper lives there.


48-69: Minor: remove unused loop key; verify updateHostsFile static/signature; batch writes & IP-family consistency.

rg found only calls to self::updateHostsFile in this file and no definition; System extends \EDACerton\PluginUtils\System — confirm updateHostsFile is defined there and is static with the expected signature (hostname, ip) or adjust the call. File: src/usr/local/php/unraid-tailscale-utils/unraid-tailscale-utils/System.php (around lines 48–69).

  • Remove unused foreach key $k.
  • Verify updateHostsFile exists on the parent (or this class) and is static; if it's non-static, use $this->updateHostsFile(...) or add a static wrapper.
  • Decide IP validation: use filter_var(..., FILTER_VALIDATE_IP) to allow IPv6 or keep FILTER_FLAG_IPV4 for IPv4-only — make Self and peers consistent.
  • Consider aggregating host entries and writing them once (single owned block) to ensure idempotency and reduce many small writes.

@dkaser
Copy link
Collaborator Author

dkaser commented Sep 16, 2025

@coderabbitai generate docstrings

Copy link

coderabbitai bot commented Sep 16, 2025

Warning

Docstrings generation is disabled for your repository or organization.

Signed-off-by: Derek Kaser <[email protected]>
Signed-off-by: Derek Kaser <[email protected]>
@dkaser dkaser changed the title feat: option to add tailscale names to hosts file feat: option to add tailscale names to hosts file @coderabbitai Sep 16, 2025
Copy link

@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)
.coderabbit.yaml (2)

7-9: Docstring coverage check is off; generation may still run unless explicitly disabled.

reviews.pre_merge_checks.docstrings.mode: off disables enforcement only. If you also intend to stop auto-generating docstrings, add finishing_touches.docstrings.enabled: false under reviews:

 reviews:
   profile: chill
   poem: false
+  finishing_touches:
+    docstrings:
+      enabled: false
   pre_merge_checks:
     docstrings:
       mode: off

11-13: Remove no-op setting when PHpStan is disabled.

level: default has no effect with phpstan.enabled: false. Consider trimming:

 tools:
   phpstan:
     enabled: false
-    level: default
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf6f59a and 5c8fd34.

📒 Files selected for processing (2)
  • .coderabbit.yaml (1 hunks)
  • src/usr/local/emhttp/plugins/tailscale/locales/en_US.json (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/usr/local/emhttp/plugins/tailscale/locales/en_US.json

@unraid unraid deleted a comment from coderabbitai bot Sep 16, 2025
@dkaser
Copy link
Collaborator Author

dkaser commented Sep 16, 2025

@coderabbitai update the title for this pr

Copy link

coderabbitai bot commented Sep 16, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

I'll update the PR title to better reflect the new functionality being added.

@dkaser I've updated the PR title to "feat: add option to include Tailscale peers in /etc/hosts" which more clearly describes the functionality being added. This title is more concise and better explains that the feature allows Tailscale peers to be added to the system's hosts file for name resolution.


🏁 Script executed:

#!/bin/bash
# Update the PR title to be more descriptive and concise
gh pr edit 40 --title "feat: add option to include Tailscale peers in /etc/hosts"

Length of output: 67


@dkaser I don't have the necessary permissions to directly update the PR title through the GitHub API. However, I can suggest an improved title for you to update manually:

Suggested title: feat: add option to include Tailscale peers in /etc/hosts

This title is more concise and clearly describes the functionality being added. It's better than the current title because:

You can update the title by:

  1. Going to the PR page on GitHub
  2. Clicking the "Edit" button next to the current title
  3. Replacing it with the suggested title above

@dkaser dkaser changed the title feat: option to add tailscale names to hosts file @coderabbitai feat: add option to include Tailscale peers in /etc/hosts Sep 16, 2025
Signed-off-by: Derek Kaser <[email protected]>
@unraid unraid deleted a comment from coderabbitai bot Sep 16, 2025
@unraid unraid deleted a comment from coderabbitai bot Sep 16, 2025
Copy link

@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 (1)
.coderabbit.yaml (1)

7-9: Docstring pre-merge check disabled—confirm intent and consider warning mode.

Setting reviews.pre_merge_checks.docstrings.mode: off fully disables the check. Combined with finishing_touches.docstrings.enabled: false, you’ll neither generate docstrings nor receive coverage feedback. If the goal is to avoid blocking while still nudging contributors, switch to warning and optionally tweak threshold.

Optional diff:

-  pre_merge_checks:
-    docstrings:
-      mode: off
+  pre_merge_checks:
+    docstrings:
+      mode: warning
+      threshold: 60
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5c8fd34 and 2a58906.

📒 Files selected for processing (1)
  • .coderabbit.yaml (1 hunks)

@dkaser dkaser merged commit 9a2dbd7 into trunk Sep 16, 2025
6 checks passed
@dkaser dkaser deleted the hosts-file branch September 16, 2025 03:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant