forked from mirrors/amnezia-wg-easy
Fix short link. Generate One Time Link (#1301)
Co-authored-by: Vadim Babadzhanyan <vadim.babadzhanyan@my.games>
This commit is contained in:
parent
352a022f30
commit
968d2b90a0
6 changed files with 61 additions and 7 deletions
|
@ -132,14 +132,15 @@ module.exports = class Server {
|
|||
authenticated,
|
||||
};
|
||||
}))
|
||||
.get('/:clientHash', defineEventHandler(async (event) => {
|
||||
const clientHash = getRouterParam(event, 'clientHash');
|
||||
.get('/cnf/:clientOneTimeLink', defineEventHandler(async (event) => {
|
||||
const clientOneTimeLink = getRouterParam(event, 'clientOneTimeLink');
|
||||
const clients = await WireGuard.getClients();
|
||||
const client = clients.find((client) => client.hash === clientHash);
|
||||
const client = clients.find((client) => client.oneTimeLink === clientOneTimeLink);
|
||||
if (!client) return;
|
||||
const clientId = client.id;
|
||||
const config = await WireGuard.getClientConfiguration({ clientId });
|
||||
setHeader(event, 'Content-Disposition', `attachment; filename="${clientHash}.conf"`);
|
||||
await WireGuard.eraseOneTimeLink({ clientId });
|
||||
setHeader(event, 'Content-Disposition', `attachment; filename="${clientOneTimeLink}.conf"`);
|
||||
setHeader(event, 'Content-Type', 'text/plain');
|
||||
return config;
|
||||
}))
|
||||
|
@ -252,6 +253,14 @@ module.exports = class Server {
|
|||
await WireGuard.enableClient({ clientId });
|
||||
return { success: true };
|
||||
}))
|
||||
.post('/api/wireguard/client/:clientId/generateOneTimeLink', defineEventHandler(async (event) => {
|
||||
const clientId = getRouterParam(event, 'clientId');
|
||||
if (clientId === '__proto__' || clientId === 'constructor' || clientId === 'prototype') {
|
||||
throw createError({ status: 403 });
|
||||
}
|
||||
await WireGuard.generateOneTimeLink({ clientId });
|
||||
return { success: true };
|
||||
}))
|
||||
.post('/api/wireguard/client/:clientId/disable', defineEventHandler(async (event) => {
|
||||
const clientId = getRouterParam(event, 'clientId');
|
||||
if (clientId === '__proto__' || clientId === 'constructor' || clientId === 'prototype') {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue