[07/19] ovpnclients.dat: Add table header.

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

Commit Message

Stefan Schantl April 13, 2020, 7:45 a.m. UTC
  The header will be dynamically generated, according the items which will
be displayed.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 html/cgi-bin/logs.cgi/ovpnclients.dat | 46 +++++++++++++++++++--------
 1 file changed, 33 insertions(+), 13 deletions(-)
  

Patch

diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat
index b601fd292..33d6d8717 100755
--- a/html/cgi-bin/logs.cgi/ovpnclients.dat
+++ b/html/cgi-bin/logs.cgi/ovpnclients.dat
@@ -243,7 +243,21 @@  my $lines = 0;
 
 print "<table width='100%' class='tbl'>";
 
-my $col="";
+my $col = "bgcolor='$color{'color20'}'";
+
+	print "<tr>\n";
+		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='10%' $col><b>$Lang::tr{'recieved'}</b></td>\n";
+		print "<td width='10%' $col><b>$Lang::tr{'sent'}</b></td>\n";
+	} else {
+		print "<td $col><b>$Lang::tr{'total connection time'}</b>\n";
+	}
+
+	print "</tr>\n";
 
 while(my @row = $statement_handle->fetchrow_array()) {
 	# Assign some nice to read variable names for the DB fields.
@@ -253,23 +267,29 @@  while(my @row = $statement_handle->fetchrow_array()) {
 	my $connection_bytes_recieved = &General::formatBytes($row[3]);
 	my $connection_bytes_sent = &General::formatBytes($row[4]);
 
-	# Colorize columns. 
+	# Colorize columns.
 	if ($lines % 2) {
+		$col="bgcolor='$color{'color20'}'";
+	} else {
 		$col="bgcolor='$color{'color22'}'";
+	}
+
+	print "<tr>\n";
+		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='10%' $col>$connection_bytes_recieved</td>\n";
+		print "<td width='10%' $col>$connection_bytes_sent</td>\n";
 	} else {
-		$col="bgcolor='$color{'color20'}'";
+		# Convert total connection time into human-readable format.
+		my $total_time = &General::format_time($row[1]);
+
+		print "<td $col>$total_time</td>\n";
 	}
 
-print <<END
-	<tr>
-		<td width="40%" align="left" $col>$connection_name</td>
-		<td width="20%" align="center" $col>$connection_open_time</td>
-		<td width="20%" align="center" $col>$connection_close_time</td>
-		<td width="10%" align="center" $col>$connection_bytes_recieved</td>
-		<td width="10%" align="center" $col>$connection_bytes_sent</td>
-	</tr>
-END
-;
+	print "</tr>\n";
 
 	# Increase lines count.
 	$lines++;