vpn_based_remote_access_system
Version:
毕设:基于OpenVPN的远程访问系统
96 lines (79 loc) • 2.87 kB
JavaScript
const { logInfo, logError } = require('./logs')('Index');
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const session = require('express-session');
const fs = require('fs');
const proxy = require('./proxy');
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
// express-session ����
app.use(session({
secret: 'Thisisasecertkey',
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}));
// ���������ļ�
const config = JSON.parse(fs.readFileSync('config.json', 'utf8'));
const USERPAGEPORT = config.userPagePort;
//const PORT = config.listenPort;
logInfo('==========');
logInfo('Running.');
// ������������������ӿ�
//const { ProxyServer } = require('./proxy');
// ���� userpage.js ·��
const userRoutes = require('./userpage');
app.use(bodyParser.json());
app.use(express.static('public'));
// ʹ�� userpage.js �ж����·��
app.use('/', userRoutes);
const server = app.listen(USERPAGEPORT, () => {
logInfo(`Server of user page is listening at http://localhost:${USERPAGEPORT}`);
});
//const server1 = new ProxyServer(PORT, 15, false);
//server1.startServer();
// �����ض��ź��Թر�����
//process.on('SIGINT', () => proxyServer.stop());
//process.on('SIGTERM', () => proxyServer.stop());
console.log('The system is running.')
readline.on('line', (input) => {
if (input === 'list') {
// �г������еĴ���������
console.table(proxy.getServersList());
}
if (input.startsWith('shut ')) {
const port = input.split(' ')[1]; // �������л�ȡ�˿ں�
if (port == 'all') {
// �����������еĴ������������ر�
const runningServers = proxy.getServersList(); // ��ȡ�����������еķ�����ʵ��
let ports = '';
runningServers.forEach(server => {
ports += server.port + ' ';
});
console.log('Shut down all proxy servers include: ' + ports);
proxy.stopAllServers();
} else if (port) {
// ������ָ���Ķ˿ں�����
proxy.stopServerByPort(parseInt(port)); // �����·���ָֹͣ���˿ڵķ�����
console.log(`Shut down the proxy server on port ${port}.`);
} else {
console.log('Invalid port.');
}
}
if (input === 'stop') {
//server1.shutdownServer();
// ֹͣExpress������
console.log('Shut down the Express server.');
server.close(() => {
console.log('Express server stopped.');
});
// �����������еĴ������������ر�
console.log('Shut down all proxy servers.');
proxy.stopAllServers();
// ��������
process.exit(0);
}
});