guacamole force VPN

This commit is contained in:
Manuel Romero
2024-03-13 16:28:19 +01:00
parent 79ae38b76b
commit ab4052c35c
2 changed files with 16 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ const axios = require('axios');
const qs = require('qs');
const fs = require('qs');
const path = require('path');
const requestIp = require('request-ip');
// set up database for express session
@@ -289,6 +290,18 @@ module.exports.ensureAuthenticatedDoLogin = async function(req, res, next) {
res.redirect(`/login?redirectTo=${req.originalUrl}`);
};
module.exports.ensureAuthenticatedAndVPNDoLogin = async function(req, res, next) {
const ipAddress = requestIp.getClientIp(req);
var isVPN = ipAddress.indexOf("10.0.0") !== -1;
if ( !isVPN ) {
res.send("You do not seem connected to the VPN, please connect");
} else if ( await _ensureAuthenticated(req) ) {
return next();
} else {
res.redirect(`/login?redirectTo=${req.originalUrl}`);
}
};
module.exports.ensureAuthenticated = async function(req, res, next) {
if ( await _ensureAuthenticated(req) ) {
return next();
@@ -296,6 +309,8 @@ module.exports.ensureAuthenticated = async function(req, res, next) {
res.status(401).send({"error": "Unauthorized"});
};
module.exports.ensureAuthenticatedAndAdmin = async function(req, res, next) {
if ( await _ensureAuthenticated(req) && (req.user.role === 'admin' || req.user.role === 'superadmin') ) {
return next();

View File

@@ -96,7 +96,7 @@ app.use('/', express.static(__dirname + '/../dist/qmi-cloud'));
passport.init(app, IS_SECURE ? true : false);
app.use('/guacamole/', passport.ensureAuthenticatedDoLogin, createProxyMiddleware({
app.use('/guacamole/', passport.ensureAuthenticatedAndVPNDoLogin, createProxyMiddleware({
target: 'http://qmicloud-dev.qliktech.com:8080/',
ws: true,
changeOrigin: true,