-
Notifications
You must be signed in to change notification settings - Fork 0
Fix .conf downloads so WireGuard apps accept the import #11
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -87,6 +87,19 @@ function formatBytes(bytes: number): string { | |||||
| return `${(bytes / 1024 ** i).toFixed(1)} ${units[i]}` | ||||||
| } | ||||||
|
|
||||||
| // Mirrors the backend's confFilename (subscription.go): WireGuard clients derive | ||||||
| // the tunnel name from the imported file's name, and Android/wg-quick tunnel names | ||||||
| // must be 1-15 chars of [a-zA-Z0-9_=+.-] - a raw account label (Unicode, spaces, | ||||||
| // or just too long) makes the app reject the file with "Invalid name". | ||||||
| function confFilename(label: string): string { | ||||||
| let stem = label.toLowerCase().replace(/[^a-z0-9._-]+/g, '-') | ||||||
| if (stem.length > 15) stem = stem.slice(0, 15) | ||||||
| // Trim AFTER truncating so a cut landing on a separator doesn't leave a | ||||||
| // trailing "-"/"." right before the extension. | ||||||
| stem = stem.replace(/^[-.]+|[-.]+$/g, '') | ||||||
| return `${stem === '' ? 'wgpanel' : stem}.conf` | ||||||
| } | ||||||
|
|
||||||
| // Mirrors the backend's peerOnlineWindow (180s) purely for display wording - the | ||||||
| // authoritative online/offline bit itself always comes from the server's `online` | ||||||
| // field, never recomputed here from last_handshake_at. | ||||||
|
|
@@ -776,12 +789,11 @@ function AccountDetailDialog({ | |||||
| <Button | ||||||
| variant="secondary" | ||||||
| onClick={() => { | ||||||
| const slug = (configNodeName ?? 'node').toLowerCase().replace(/[^a-z0-9]+/g, '-') | ||||||
| const blob = new Blob([configText], { type: 'text/plain' }) | ||||||
| const url = URL.createObjectURL(blob) | ||||||
| const link = document.createElement('a') | ||||||
| link.href = url | ||||||
| link.download = `${account.label}-${slug}.conf` | ||||||
| link.download = confFilename(`${account.label}-${configNodeName ?? 'node'}`) | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass the account label and node name as separate arguments to the updated
Suggested change
|
||||||
| link.click() | ||||||
| URL.revokeObjectURL(url) | ||||||
| }} | ||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
When downloading configs for multiple nodes under the same account, combining the account label and node name and then truncating the entire string to 15 characters can easily lead to identical filenames if the account label is long (e.g.,
verylongaccountlabel-node1andverylongaccountlabel-node2both truncate toverylongaccount).This causes two major issues:
(1)to avoid overwriting (e.g.,verylongaccount (1).conf), which contains spaces and parentheses. These characters are invalid under WireGuard's strict[a-zA-Z0-9_=+.-]pattern, causing the WireGuard app to reject the file upon import.To prevent this, we should truncate the account label and node name individually before joining them, ensuring the total length remains within 15 characters.