[16/19] OpenVPN Log: Add connection duration

Message ID 20200413074550.2735-16-stefan.schantl@ipfire.org
State Accepted
Commit 186c0ddd91ee5bfb3de2e5190b33af78b2e714be
Headers show
Series [01/19] openvpn: Add WUI page for client usage statistics | expand

Commit Message

Stefan Schantl April 13, 2020, 7:45 a.m. UTC
From: Michael Tremer <michael.tremer@ipfire.org>

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
---
 html/cgi-bin/logs.cgi/ovpnclients.dat | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

Patch

diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat
index 002a393ad..2009990ec 100755
--- a/html/cgi-bin/logs.cgi/ovpnclients.dat
+++ b/html/cgi-bin/logs.cgi/ovpnclients.dat
@@ -128,7 +128,8 @@  my $database_query = qq(
 
 if ($cgiparams{'CONNECTION_NAME'}) {
 	$database_query = qq(
-		SELECT common_name, DATETIME(connected_at, 'localtime'), DATETIME(disconnected_at, 'localtime'), bytes_received, bytes_sent FROM sessions
+		SELECT common_name, DATETIME(connected_at, 'localtime'), DATETIME(disconnected_at, 'localtime'), bytes_received, bytes_sent,
+			STRFTIME('%s', DATETIME(disconnected_at)) - STRFTIME('%s', DATETIME(connected_at)) AS duration FROM sessions
 		WHERE
 			common_name = '$cgiparams{"CONNECTION_NAME"}'
 			AND (
@@ -260,8 +261,9 @@  my $col = "bgcolor='$color{'color20'}'";
 		print "<td width='40%' $col><b>$Lang::tr{'ovpn connection name'}</b></td>\n";
 
 	if ($cgiparams{'CONNECTION_NAME'}) {
-		print "<td width='20%' $col><b>$Lang::tr{'connected'}</b></td>\n";
-		print "<td width='20%' $col><b>$Lang::tr{'disconnected'}</b></td>\n";
+		print "<td width='15%' $col><b>$Lang::tr{'connected'}</b></td>\n";
+		print "<td width='15%' $col><b>$Lang::tr{'disconnected'}</b></td>\n";
+		print "<td width='10%' align='right' $col><b>$Lang::tr{'duration'}</b></td>\n";
 		print "<td width='10%' align='right' $col><b>$Lang::tr{'received'}</b></td>\n";
 		print "<td width='10%' align='right' $col><b>$Lang::tr{'sent'}</b></td>\n";
 	} else {
@@ -279,6 +281,7 @@  unless ($errormessage) {
 		my $connection_close_time = $row[2];
 		my $connection_bytes_recieved = &General::formatBytes($row[3]);
 		my $connection_bytes_sent = &General::formatBytes($row[4]);
+		my $duration = &General::format_time($row[5]);
 
 		# Colorize columns.
 		if ($lines % 2) {
@@ -291,8 +294,9 @@  unless ($errormessage) {
 			print "<td width='40%' $col>$connection_name</td>\n";
 
 		if ($cgiparams{'CONNECTION_NAME'}) {
-			print "<td width='20%' $col>$connection_open_time</td>\n";
-			print "<td width='20%' $col>$connection_close_time</td>\n";
+			print "<td width='15%' $col>$connection_open_time</td>\n";
+			print "<td width='15%' $col>$connection_close_time</td>\n";
+			print "<td width='10%' align='right' $col>$duration</td>\n";
 			print "<td width='10%' align='right' $col>$connection_bytes_recieved</td>\n";
 			print "<td width='10%' align='right' $col>$connection_bytes_sent</td>\n";
 		} else {
@@ -312,7 +316,7 @@  unless ($errormessage) {
 # If nothing has been fetched, the amount of lines is still zero.
 # In this case display a hint about no data.	
 unless ($lines) {
-	print "<tr><td bgcolor='$color{'color22'}' colspan='5' align='center'>$Lang::tr{'no entries'}</td></tr>\n";
+	print "<tr><td bgcolor='$color{'color22'}' colspan='6' align='center'>$Lang::tr{'no entries'}</td></tr>\n";
 }
 
 print "</table><br>\n";