-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add option to include Tailscale peers in /etc/hosts #40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Derek Kaser <[email protected]>
WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches🧪 Generate unit tests
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. Comment |
There was a problem hiding this 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
⛔ 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.
@coderabbitai generate docstrings |
Warning Docstrings generation is disabled for your repository or organization. |
Signed-off-by: Derek Kaser <[email protected]>
Signed-off-by: Derek Kaser <[email protected]>
There was a problem hiding this 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, addfinishing_touches.docstrings.enabled: false
underreviews
: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 withphpstan.enabled: false
. Consider trimming:tools: phpstan: enabled: false - level: default
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 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
@coderabbitai update the title for this pr |
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainI'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:
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: 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:
|
Signed-off-by: Derek Kaser <[email protected]>
There was a problem hiding this 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 withfinishing_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 towarning
and optionally tweakthreshold
.Optional diff:
- pre_merge_checks: - docstrings: - mode: off + pre_merge_checks: + docstrings: + mode: warning + threshold: 60
Summary by CodeRabbit
New Features
Behavior
Documentation