Merge branch 'master' into remember-me

This commit is contained in:
Philip H.
2024-08-16 19:25:36 +02:00
committed by GitHub
13 changed files with 72 additions and 10 deletions
+17
View File
@@ -33,6 +33,7 @@ const {
LANG,
UI_TRAFFIC_STATS,
UI_CHART_TYPE,
UI_SHOW_LINKS,
} = require('../config');
const requiresPassword = !!PASSWORD_HASH;
@@ -98,6 +99,11 @@ module.exports = class Server {
return `"${UI_CHART_TYPE}"`;
}))
.get('/api/ui-show-links', defineEventHandler((event) => {
setHeader(event, 'Content-Type', 'application/json');
return `${UI_SHOW_LINKS}`;
}))
// Authentication
.get('/api/session', defineEventHandler((event) => {
const authenticated = requiresPassword
@@ -109,6 +115,17 @@ module.exports = class Server {
authenticated,
};
}))
.get('/:clientHash', defineEventHandler(async (event) => {
const clientHash = getRouterParam(event, 'clientHash');
const clients = await WireGuard.getClients();
const client = clients.find((client) => client.hash === clientHash);
if (!client) return;
const clientId = client.id;
const config = await WireGuard.getClientConfiguration({ clientId });
setHeader(event, 'Content-Disposition', `attachment; filename="${clientHash}.conf"`);
setHeader(event, 'Content-Type', 'text/plain');
return config;
}))
.post('/api/session', defineEventHandler(async (event) => {
const { password, remember } = await readBody(event);
+2
View File
@@ -5,6 +5,7 @@ const path = require('path');
const debug = require('debug')('WireGuard');
const crypto = require('node:crypto');
const QRCode = require('qrcode');
const CRC32 = require('crc-32');
const Util = require('./Util');
const ServerError = require('./ServerError');
@@ -147,6 +148,7 @@ ${client.preSharedKey ? `PresharedKey = ${client.preSharedKey}\n` : ''
createdAt: new Date(client.createdAt),
updatedAt: new Date(client.updatedAt),
allowedIPs: client.allowedIPs,
hash: Math.abs(CRC32.str(clientId)).toString(16),
downloadableConfig: 'privateKey' in client,
persistentKeepalive: null,
latestHandshakeAt: null,