From patchwork Mon Apr 13 07:45:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2951 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4910zw2b4rz3yBt for ; Mon, 13 Apr 2020 07:46:20 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4910zk5TcQz2jN; Mon, 13 Apr 2020 07:46:10 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4910zk1YVlz30FQ; Mon, 13 Apr 2020 07:46:10 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4910zd4t44z2yRK for ; Mon, 13 Apr 2020 07:46:05 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 4910zZ5m2wz2Lv; Mon, 13 Apr 2020 07:46:02 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1586763963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TgtoPJBIoUYBdU61dybXGsWuX/rKrBuHXyRSQjI+cbU=; b=i/1eD71haH2TxHiX4PAMy+h78VjGII5Ar/NhUaH9uc1AGo3p9K4X2RE3BNZc8Vpl4HoJqr eOKDjP1BNDCAM5CA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1586763963; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TgtoPJBIoUYBdU61dybXGsWuX/rKrBuHXyRSQjI+cbU=; b=gIpf2PG2yzLk9gtI2HNGF0rBxUc3BFzHQUxlf5DSYwfBsEOMGCjFBELF6ssYi6+vw2F4+n 6gRXqFIHQzvhjcjucoAzDGw8KrFZOPCiI1etv7kZhJtxdX+cbrGmTwBObOXQILDAmpFI34 GCRUr0q5Z7nRdGwpPIxZbt/8IelP5Jk7UyIzbv9JWgHs4Pu0b4Dn+iksFzi4hncXI2s4xM RgA7nBjNXvvZ8Yn9AXjhgJDfUv69ayQqjh861WdHBkb68rKYEG1UxMirBjQrlawjvgE8n6 vmhgWMtRF02Fg5sXmA8+pDtTnxOY3lp72lvsnvXOwJC0F2rLD04w3cCinM7rYg== From: Stefan Schantl 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> References: <20200413074550.2735-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Stefan Schantl --- 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 "\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 "\n"; - print "$connection_name\n"; + print "\n"; + print "$connection_name\n"; - if ($cgiparams{'CONNECTION_NAME'}) { - print "$connection_open_time\n"; - print "$connection_close_time\n"; - print "$connection_bytes_recieved\n"; - print "$connection_bytes_sent\n"; - } else { - # Convert total connection time into human-readable format. - my $total_time = &General::format_time($row[1]); + if ($cgiparams{'CONNECTION_NAME'}) { + print "$connection_open_time\n"; + print "$connection_close_time\n"; + print "$connection_bytes_recieved\n"; + print "$connection_bytes_sent\n"; + } else { + # Convert total connection time into human-readable format. + my $total_time = &General::format_time($row[1]); - print "$total_time\n"; - } + print "$total_time\n"; + } - print "\n"; + print "\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 "$Lang::tr{'no entries'}\n"; }