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 02/19] OpenVPN: Fix query when selecting sessions only
Date: Mon, 13 Apr 2020 09:45:33 +0200	[thread overview]
Message-ID: <20200413074550.2735-2-stefan.schantl@ipfire.org> (raw)
In-Reply-To: <20200413074550.2735-1-stefan.schantl@ipfire.org>

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

From: Michael Tremer <michael.tremer(a)ipfire.org>

Previously some sessions were selected which did not qualify
for the search.

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

diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat
index 703f4e507..46667a9d1 100755
--- a/html/cgi-bin/logs.cgi/ovpnclients.dat
+++ b/html/cgi-bin/logs.cgi/ovpnclients.dat
@@ -107,27 +107,31 @@ my $database_query = qq(
                                         ELSE DATETIME('$from_datestring', 'localtime', 'start of day')
                         END
                 ), 'utc')
-        )
+        ) AS duration
         FROM sessions
         WHERE
-                disconnected_at IS NULL
-                OR
-                DATETIME(disconnected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day')
-                OR
+                (
+			disconnected_at IS NULL
+	                OR
+	                DATETIME(disconnected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day')
+		)
+                AND
                 DATETIME(connected_at, 'localtime') < DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds')
         GROUP BY common_name
-        ORDER BY common_name;
+        ORDER BY common_name, duration DESC;
 );
 
 if ($cgiparams{'CONNECTION_NAME'}) {
 	$database_query = qq(
-		SELECT *
-		FROM sessions
+		SELECT * FROM sessions
 		WHERE
-			common_name = '$cgiparams{"CONNECTION_NAME"}' AND (
-			DATETIME(disconnected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day')
-			OR
-			DATETIME(connected_at, 'localtime') < DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds'));
+			common_name = '$cgiparams{"CONNECTION_NAME"}'
+			AND (
+				DATETIME(disconnected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day')
+				AND
+				DATETIME(connected_at, 'localtime') < DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds')
+			)
+		ORDER BY connected_at;
 	);
 }
 
-- 
2.26.0


  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 ` Stefan Schantl [this message]
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 ` [PATCH 11/19] ovpnclients.dat: Do not perform DB actions if there is an error message Stefan Schantl
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-2-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