public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Stefan Schantl <stefan.schantl@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH 11/19] ovpnclients.dat: Do not perform DB actions if there is an error message.
Date: Mon, 13 Apr 2020 09:45:42 +0200	[thread overview]
Message-ID: <20200413074550.2735-11-stefan.schantl@ipfire.org> (raw)
In-Reply-To: <20200413074550.2735-1-stefan.schantl@ipfire.org>

[-- Attachment #1: Type: text/plain, Size: 3992 bytes --]

Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
 html/cgi-bin/logs.cgi/ovpnclients.dat | 77 +++++++++++++++------------
 1 file changed, 43 insertions(+), 34 deletions(-)

diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat
index a83a0bca9..093315a64 100755
--- a/html/cgi-bin/logs.cgi/ovpnclients.dat
+++ b/html/cgi-bin/logs.cgi/ovpnclients.dat
@@ -140,11 +140,17 @@ if ($cgiparams{'CONNECTION_NAME'}) {
 	);
 }
 
-# Prepare SQL statement.
-my $statement_handle = $database_handle->prepare($database_query);
+my $statement_handle;
+my $database_return_value;
 
-# Execute SQL statement and get retun value if any error happened.
-my $database_return_value = $statement_handle->execute();
+# Only process SQL actions if there is no error message.
+unless ($errormessage) {
+	# Prepare SQL statement.
+	$statement_handle = $database_handle->prepare($database_query);
+
+	# Execute SQL statement and get retun value if any error happened.
+	$database_return_value = $statement_handle->execute();
+}
 
 # If an error has been returned, assign it to the errorstring value for displaying.
 if($database_return_value < 0) {
@@ -264,44 +270,47 @@ my $col = "bgcolor='$color{'color20'}'";
 
 	print "</tr>\n";
 
-while(my @row = $statement_handle->fetchrow_array()) {
-	# Assign some nice to read variable names for the DB fields.
-	my $connection_name = $row[0];
-	my $connection_open_time = $row[1];
-	my $connection_close_time = $row[2];
-	my $connection_bytes_recieved = &General::formatBytes($row[3]);
-	my $connection_bytes_sent = &General::formatBytes($row[4]);
-
-	# Colorize columns.
-	if ($lines % 2) {
-		$col="bgcolor='$color{'color20'}'";
-	} else {
-		$col="bgcolor='$color{'color22'}'";
-	}
+# Only try to fetch the DB items if there is no error message.
+unless ($errormessage) {
+	while(my @row = $statement_handle->fetchrow_array()) {
+		# Assign some nice to read variable names for the DB fields.
+		my $connection_name = $row[0];
+		my $connection_open_time = $row[1];
+		my $connection_close_time = $row[2];
+		my $connection_bytes_recieved = &General::formatBytes($row[3]);
+		my $connection_bytes_sent = &General::formatBytes($row[4]);
+
+		# 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";
+		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 {
-		# Convert total connection time into human-readable format.
-		my $total_time = &General::format_time($row[1]);
+		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 {
+			# Convert total connection time into human-readable format.
+			my $total_time = &General::format_time($row[1]);
 
-		print "<td $col>$total_time</td>\n";
-	}
+			print "<td $col>$total_time</td>\n";
+		}
 
-	print "</tr>\n";
+		print "</tr>\n";
 
-	# Increase lines count.
-	$lines++;
+		# Increase lines count.
+		$lines++;
+	}
 }
 
 # If nothing has been fetched, the amount of lines is still zero.
-# In this case display a hint about no data.
+# 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";
 }
-- 
2.26.0


  parent reply	other threads:[~2020-04-13  7:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-13  7:45 [PATCH 01/19] openvpn: Add WUI page for client usage statistics Stefan Schantl
2020-04-13  7:45 ` [PATCH 02/19] OpenVPN: Fix query when selecting sessions only Stefan Schantl
2020-04-13  7:45 ` [PATCH 03/19] ovpnclients.dat: Fix hard coded language string Stefan Schantl
2020-04-13  7:45 ` [PATCH 04/19] general-functions.pl: Add formatBytes() function Stefan Schantl
2020-04-13  7:45 ` [PATCH 05/19] ovpnclients.dat: Display traffic details in a human-readable format Stefan Schantl
2020-04-13  7:45 ` [PATCH 06/19] Langs: Add strings for disconnect, sent and recieved Stefan Schantl
2020-04-13  7:45 ` [PATCH 07/19] ovpnclients.dat: Add table header Stefan Schantl
2020-04-13  7:45 ` [PATCH 08/19] ovpnclients.dat: Convert timestamps into localtime Stefan Schantl
2020-04-13  7:45 ` [PATCH 09/19] ovpnclients.dat: Display a notice if there are no entries Stefan Schantl
2020-04-13  7:45 ` [PATCH 10/19] ovpnclients.dat: Display error when the to date is not later than the from date Stefan Schantl
2020-04-13  7:45 ` Stefan Schantl [this message]
2020-04-13  7:45 ` [PATCH 12/19] general-functions.pl: formatBytes() Fix computing the correct unit Stefan Schantl
2020-04-13  7:45 ` [PATCH 13/19] ovpnclients.dat: Fix type in received Stefan Schantl
2020-04-13  7:45 ` [PATCH 14/19] ovpnclients.dat: Align traffic values to the right side Stefan Schantl
2020-04-13  7:45 ` [PATCH 15/19] OpenVPN: Capitalise some headings and labels Stefan Schantl
2020-04-13  7:45 ` [PATCH 16/19] OpenVPN Log: Add connection duration Stefan Schantl
2020-04-13  7:45 ` [PATCH 17/19] Add ovpnclients page to log menu Stefan Schantl
2020-04-13  7:45 ` [PATCH 18/19] Langs/en.pl: Add duration Stefan Schantl
2020-04-13  7:45 ` [PATCH 19/19] Langs/de.pl: Add translations for OpenVPN roadwarrior connection log Stefan Schantl

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200413074550.2735-11-stefan.schantl@ipfire.org \
    --to=stefan.schantl@ipfire.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox