normalize config file name for download to make it work on Windows

Windows client name is derived from config file name when importing to WireGuard and it only accepts names satisfying /^[a-zA-Z0-9_=+.-]{1,32}$/.
For more information look at af60ab2299/conf/name.go (L24).
This commit is contained in:
Vojta Drbohlav 2021-10-11 21:50:53 +02:00
parent 67b820d985
commit 722bd18999

View File

@ -99,7 +99,8 @@ module.exports = class Server {
const { clientId } = req.params;
const client = await WireGuard.getClient({ clientId });
const config = await WireGuard.getClientConfiguration({ clientId });
res.header('Content-Disposition', `attachment; filename="${client.name}.conf"`);
const configName = client.name.replace(/[^a-zA-Z0-9_=+.-]/g, '-').replace(/(-{2,}|-$)/g, '-').replace(/-$/, '').substring(0, 32);
res.header('Content-Disposition', `attachment; filename="${configName}.conf"`);
res.header('Content-Type', 'text/plain');
res.send(config);
}))