Browse Source
add filename cleaning at OneTimeLink download (#2253)
* add filename cleaning at OneTimeLink download
* add cleanConfigFilename function in utils/WireGuard
pull/2256/head
YuWorm
7 months ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
10 additions and
7 deletions
-
src/server/api/client/[clientId]/configuration.get.ts
-
src/server/routes/cnf/[oneTimeLink].ts
-
src/server/utils/WireGuard.ts
|
|
|
@ -19,16 +19,11 @@ export default definePermissionEventHandler( |
|
|
|
} |
|
|
|
|
|
|
|
const config = await WireGuard.getClientConfiguration({ clientId }); |
|
|
|
const configName = client.name |
|
|
|
.replace(/[^a-zA-Z0-9_=+.-]/g, '-') |
|
|
|
.replace(/(-{2,}|-$)/g, '-') |
|
|
|
.replace(/-$/, '') |
|
|
|
.substring(0, 32); |
|
|
|
|
|
|
|
setHeader( |
|
|
|
event, |
|
|
|
'Content-Disposition', |
|
|
|
`attachment; filename="${configName || clientId}.conf"` |
|
|
|
`attachment; filename="${WireGuard.cleanClientFilename(client.name) || clientId}.conf"` |
|
|
|
); |
|
|
|
|
|
|
|
setHeader(event, 'Content-Type', 'text/plain'); |
|
|
|
|
|
|
|
@ -30,7 +30,7 @@ export default defineEventHandler(async (event) => { |
|
|
|
setHeader( |
|
|
|
event, |
|
|
|
'Content-Disposition', |
|
|
|
`attachment; filename="${client.name}.conf"` |
|
|
|
`attachment; filename="${WireGuard.cleanClientFilename(client.name) || client.id}.conf"` |
|
|
|
); |
|
|
|
setHeader(event, 'Content-Type', 'text/plain'); |
|
|
|
return config; |
|
|
|
|
|
|
|
@ -170,6 +170,14 @@ class WireGuard { |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
cleanClientFilename(name: string): string { |
|
|
|
return name |
|
|
|
.replace(/[^a-zA-Z0-9_=+.-]/g, '-') |
|
|
|
.replace(/(-{2,}|-$)/g, '-') |
|
|
|
.replace(/-$/, '') |
|
|
|
.substring(0, 32); |
|
|
|
} |
|
|
|
|
|
|
|
async Startup() { |
|
|
|
WG_DEBUG('Starting WireGuard...'); |
|
|
|
// let as it has to refetch if keys change
|
|
|
|
|