|
|
@ -107,38 +107,38 @@ module.exports = class Server { |
|
|
? !!(event.node.req.session && event.node.req.session.authenticated) |
|
|
? !!(event.node.req.session && event.node.req.session.authenticated) |
|
|
: true; |
|
|
: true; |
|
|
|
|
|
|
|
|
return { |
|
|
return { |
|
|
requiresPassword, |
|
|
requiresPassword, |
|
|
authenticated, |
|
|
authenticated, |
|
|
}; |
|
|
}; |
|
|
})) |
|
|
}), |
|
|
|
|
|
) |
|
|
.post('/api/session', defineEventHandler(async (event) => { |
|
|
.post('/api/session', defineEventHandler(async (event) => { |
|
|
const { password } = await readBody(event); |
|
|
const { password } = await readBody(event); |
|
|
|
|
|
|
|
|
if (!requiresPassword) { |
|
|
if (!requiresPassword) { |
|
|
// if no password is required, the API should never be called.
|
|
|
// if no password is required, the API should never be called.
|
|
|
// Do not automatically authenticate the user.
|
|
|
// Do not automatically authenticate the user.
|
|
|
throw createError({ |
|
|
throw createError({ |
|
|
status: 401, |
|
|
status: 401, |
|
|
message: 'Invalid state', |
|
|
message: 'Invalid state', |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if (!isPasswordValid(password)) { |
|
|
if (!isPasswordValid(password)) { |
|
|
throw createError({ |
|
|
throw createError({ |
|
|
status: 401, |
|
|
status: 401, |
|
|
message: 'Incorrect Password', |
|
|
message: 'Incorrect Password', |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
event.node.req.session.authenticated = true; |
|
|
event.node.req.session.authenticated = true; |
|
|
event.node.req.session.save(); |
|
|
event.node.req.session.save(); |
|
|
|
|
|
|
|
|
debug(`New Session: ${event.node.req.session.id}`); |
|
|
debug(`New Session: ${event.node.req.session.id}`); |
|
|
|
|
|
|
|
|
return { success: true }; |
|
|
return { success: true }; |
|
|
}) |
|
|
})); |
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// WireGuard
|
|
|
// WireGuard
|
|
|
app.use( |
|
|
app.use( |
|
|
@ -280,11 +280,11 @@ module.exports = class Server { |
|
|
setHeader( |
|
|
setHeader( |
|
|
event, |
|
|
event, |
|
|
'Content-Disposition', |
|
|
'Content-Disposition', |
|
|
'attachment; filename="wg0.json"' |
|
|
'attachment; filename="wg0.json"', |
|
|
); |
|
|
); |
|
|
setHeader(event, 'Content-Type', 'text/json'); |
|
|
setHeader(event, 'Content-Type', 'text/json'); |
|
|
return config; |
|
|
return config; |
|
|
}) |
|
|
}), |
|
|
) |
|
|
) |
|
|
.put( |
|
|
.put( |
|
|
'/api/wireguard/restore', |
|
|
'/api/wireguard/restore', |
|
|
@ -292,7 +292,7 @@ module.exports = class Server { |
|
|
const { file } = await readBody(event); |
|
|
const { file } = await readBody(event); |
|
|
await WireGuard.restoreConfiguration(file); |
|
|
await WireGuard.restoreConfiguration(file); |
|
|
return { success: true }; |
|
|
return { success: true }; |
|
|
}) |
|
|
}), |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
// Static assets
|
|
|
// Static assets
|
|
|
|