From mboxrd@z Thu Jan  1 00:00:00 1970
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
Message-ID: <20200413074550.2735-11-stefan.schantl@ipfire.org>
In-Reply-To: <20200413074550.2735-1-stefan.schantl@ipfire.org>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============5552050221455431028=="
List-Id: <development.lists.ipfire.org>

--===============5552050221455431028==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

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/ov=
pnclients.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'}) {
 	);
 }
=20
-# Prepare SQL statement.
-my $statement_handle =3D $database_handle->prepare($database_query);
+my $statement_handle;
+my $database_return_value;
=20
-# Execute SQL statement and get retun value if any error happened.
-my $database_return_value =3D $statement_handle->execute();
+# Only process SQL actions if there is no error message.
+unless ($errormessage) {
+	# Prepare SQL statement.
+	$statement_handle =3D $database_handle->prepare($database_query);
+
+	# Execute SQL statement and get retun value if any error happened.
+	$database_return_value =3D $statement_handle->execute();
+}
=20
 # If an error has been returned, assign it to the errorstring value for disp=
laying.
 if($database_return_value < 0) {
@@ -264,44 +270,47 @@ my $col =3D "bgcolor=3D'$color{'color20'}'";
=20
 	print "</tr>\n";
=20
-while(my @row =3D $statement_handle->fetchrow_array()) {
-	# Assign some nice to read variable names for the DB fields.
-	my $connection_name =3D $row[0];
-	my $connection_open_time =3D $row[1];
-	my $connection_close_time =3D $row[2];
-	my $connection_bytes_recieved =3D &General::formatBytes($row[3]);
-	my $connection_bytes_sent =3D &General::formatBytes($row[4]);
-
-	# Colorize columns.
-	if ($lines % 2) {
-		$col=3D"bgcolor=3D'$color{'color20'}'";
-	} else {
-		$col=3D"bgcolor=3D'$color{'color22'}'";
-	}
+# Only try to fetch the DB items if there is no error message.
+unless ($errormessage) {
+	while(my @row =3D $statement_handle->fetchrow_array()) {
+		# Assign some nice to read variable names for the DB fields.
+		my $connection_name =3D $row[0];
+		my $connection_open_time =3D $row[1];
+		my $connection_close_time =3D $row[2];
+		my $connection_bytes_recieved =3D &General::formatBytes($row[3]);
+		my $connection_bytes_sent =3D &General::formatBytes($row[4]);
+
+		# Colorize columns.
+		if ($lines % 2) {
+			$col=3D"bgcolor=3D'$color{'color20'}'";
+		} else {
+			$col=3D"bgcolor=3D'$color{'color22'}'";
+		}
=20
-	print "<tr>\n";
-		print "<td width=3D'40%' $col>$connection_name</td>\n";
+		print "<tr>\n";
+			print "<td width=3D'40%' $col>$connection_name</td>\n";
=20
-	if ($cgiparams{'CONNECTION_NAME'}) {
-		print "<td width=3D'20%' $col>$connection_open_time</td>\n";
-		print "<td width=3D'20%' $col>$connection_close_time</td>\n";
-		print "<td width=3D'10%' $col>$connection_bytes_recieved</td>\n";
-		print "<td width=3D'10%' $col>$connection_bytes_sent</td>\n";
-	} else {
-		# Convert total connection time into human-readable format.
-		my $total_time =3D &General::format_time($row[1]);
+		if ($cgiparams{'CONNECTION_NAME'}) {
+			print "<td width=3D'20%' $col>$connection_open_time</td>\n";
+			print "<td width=3D'20%' $col>$connection_close_time</td>\n";
+			print "<td width=3D'10%' $col>$connection_bytes_recieved</td>\n";
+			print "<td width=3D'10%' $col>$connection_bytes_sent</td>\n";
+		} else {
+			# Convert total connection time into human-readable format.
+			my $total_time =3D &General::format_time($row[1]);
=20
-		print "<td $col>$total_time</td>\n";
-	}
+			print "<td $col>$total_time</td>\n";
+		}
=20
-	print "</tr>\n";
+		print "</tr>\n";
=20
-	# Increase lines count.
-	$lines++;
+		# Increase lines count.
+		$lines++;
+	}
 }
=20
 # 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.=09
 unless ($lines) {
 	print "<tr><td bgcolor=3D'$color{'color22'}' colspan=3D'5' align=3D'center'=
>$Lang::tr{'no entries'}</td></tr>\n";
 }
--=20
2.26.0


--===============5552050221455431028==--