close
Skip to content

Add WireGuard VPN WebUI REST support (list + toggle) - #266

Draft
rosch100 wants to merge 2 commits into
kbr:v2-developmentfrom
rosch100:add-fritzwireguard-v2dev-core-squash
Draft

Add WireGuard VPN WebUI REST support (list + toggle)#266
rosch100 wants to merge 2 commits into
kbr:v2-developmentfrom
rosch100:add-fritzwireguard-v2dev-core-squash

Conversation

@rosch100

@rosch100 rosch100 commented Jun 7, 2026

Copy link
Copy Markdown

Hi kbr,

Thanks a lot for your suggestions. This PR keeps the change minimal-invasive in fritzconnection: it only adds what WireGuard WebUI REST needs and reuses existing core mechanisms (SID login/challenge + REST plumbing) instead of introducing new abstractions.

This PR enables:

  • listing WireGuard VPN connections via POST /data.lua (WireGuard page shareWireguard)
  • toggling a connection via PUT /api/v0/generic/vpn/connection/{uid}, with verification by re-listing

Why the core additions are needed:

  • some endpoints require WebUI-like headers (Origin/Referer), so call_rest_api supports extra_headers
  • digest auth on the shared requests session must not interfere with SID-based Authorization, so it is temporarily disabled for these REST calls
  • for https, FritzSID.login_url uses the correct AHA/WebUI port (remote_port) to avoid port/routing mismatches

Auth/error semantics:

  • WireGuard listing/toggle propagate HTTP 401/403 as FritzAuthorizationError.

Included changes (core-only):

  • fritzconnection/lib/fritzwireguard.py
  • fritzconnection/core/fritzhttp.py, fritzconnection/core/fritzconnection.py, fritzconnection/core/fritz_sid.py
  • small compatibility fixes included in this branch to keep existing runtime/tests working: fritzconnection/core/processor.py and fritzconnection/lib/fritzstatus.py (no WireGuard behavior changes)

Tests/verification:

  • pytest -q fritzconnection/tests/test_fritzwireguard.py

@rosch100
rosch100 marked this pull request as ready for review June 7, 2026 11:39
@kbr

kbr commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR. Please keep pull-requests small, like mentioned in contibuting.md.

Can it be that you have used AI to generate code and the PR description? In case you use AI helpers, don't let them write code, but let them help you write code (like a pair programming companion).

You are also in the v2-development branch (still under development (sic) with a lot of refacturing!). So for a commit please don't run ruff on code not related to the PR.

Some comments about the other files (partly already mentioned in your note):

  • fritzstatus.py: PR unrelated changes.

  • processor.py: This module has been removed in the v2-branch. Tests about this module also. Some adaptions must still be made to the devices-, hosts- and functional tests. It makes no sense to add this module again to make obsolete code happy.

  • fritzconnection.py: the only PR related change is about providing a (needed) option for additional headers. And yes, ElementTree seems missing after refactoring. Seems I have not have a ruff run on this file since then.

  • fritzhttp.py: again the option for additional headers with code duplications. Did you really run in the mentioned digest/session-id collisions? Or is this just an assumption? The way authentication works is api-specific and has not been an issue in the past.

  • fritz_sid.py: blocktime is currently not implemented (and I'm unsure whether it should), but has no direct relation to the PR. The https-port is indeed not checked here, but the solution for this is much more easier than the suggested changes. The introduced cache is a micro-optimisation not needed after a correct change. The change in the type-annotation makes no sense.

Here is the roadmap from my point of view:

  • Check for the https port in fritz_sid.py. However everything will work without this as long as the port does not change. So this should be done but is not required for the PR.

  • The http-call should have an option for additional headers. This must be done to make your lib-module work. I may want to add this in a more generalised way. Will think about it.

Hopefully I can handle this in a fortnight.

Then you can care about the new library module and the according tests (two files).

A note: for me the term WebUI seems to be wrong. This implies an interface designed for human users. This is not what happens here. I suggest to not use this term.

So far my first impressions.

@rosch100
rosch100 marked this pull request as draft June 7, 2026 19:34
@rosch100
rosch100 force-pushed the add-fritzwireguard-v2dev-core-squash branch from 482d7fb to 177ffe1 Compare June 7, 2026 19:37
@coderabbitai coderabbitai Bot mentioned this pull request Aug 11, 2026
2 tasks
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.

2 participants