app.use( function ( req, res, next ) {
if (req.url === '/.well-known/appspecific/com.chrome.devtools.json' ) next();
else {
- logger.warn(req.originalUrl);
- logger.warn(req.headers['x-forwarded-for']);
- logger.warn(req.headers['X-Real-IP']);
- logger.warn(req.headers['x-real-ip']);
- logger.warn(req.headers);
next( createError( 404 ) );
}
try {
// Read from the OpenVPN status log to get the client's real IP
const statusContent = fs.readFileSync('/var/log/openvpn/openvpn-status.log', 'utf8');
- logger.warn(statusContent);
let clientIp = null;
- logger.warn(clientName);
- logger.warn(duration);
const clientLine = statusContent.split('\n').find(line =>
line.startsWith(`${clientName},`) && !line.startsWith('Virtual Address')
);
- logger.warn(clientLine);
if (clientLine) {
const [, realAddress] = clientLine.split(',');
clientIp = realAddress.split(':')[0];
return next(new createError(404, `Client ${clientName} not connected`));
}
- logger.warn(clientIp);
-
// Disconnect client via management interface
const client = new net.Socket();
let connectionAttempted = false;
client.on('connect', () => {
- logger.warn('Connected to OpenVPN management interface');
connectionAttempted = true;
client.write(`kill ${clientName}\n`);
});
client.on('data', async (data) => {
const response = data.toString();
- logger.warn(response);
if (!response.includes('ERROR:')) {
- logger.warn(duration);
- logger.warn(clientIp);
if (duration && clientIp) {
// Add iptables rule to block client IP for duration
const conn = new Client();