res.status( 500 ).json( { error:`SSH connection failed: ${ err.message }` } );
} ).connect( sshConfig );
}, getClients:async ( req, res, next ) => {
- const conn = new Client();
+ const statusContent = await fs.readFile('/var/log/openvpn/status.log', 'utf8');
+ const clients = [];
+ let inClientList = false;
+
+ console.log(statusContent);
+
+ statusContent.split('\n').forEach(line => {
+ console.log(line);
+ if (line.startsWith('Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since')) {
+ inClientList = true;
+ return;
+ }
+ if (line.startsWith('ROUTING TABLE') || line === '') {
+ inClientList = false;
+ return;
+ }
+ if (inClientList) {
+ const [common_name, real_address, bytes_received, bytes_sent, connected_since] = line.split(',');
+ console.log(common_name, real_address, bytes_received, bytes_sent, connected_since);
+ clients.push({
+ common_name,
+ virtual_address: real_address.split(':')[0],
+ bytes_received,
+ bytes_sent,
+ connected_since,
+ });
+ }
+ });
+ /*const conn = new Client();
conn.on( 'ready', () => {
const command = `cat /var/log/openvpn/openvpn-status.log`;
conn.exec( command, ( err, stream ) => {
} );
} ).on( 'error', ( err ) => {
res.status( 500 ).json( { error:`SSH connection failed: ${ err.message }` } );
- } ).connect( sshConfig );
+ } ).connect( sshConfig );*/
}
};
\ No newline at end of file