From: Michael Tremer Date: Mon, 13 Apr 2020 07:45:33 +0000 (+0200) Subject: OpenVPN: Fix query when selecting sessions only X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=70e1d5874580cd07a8e38050b80d190ce0805a09;p=people%2Fpmueller%2Fipfire-2.x.git OpenVPN: Fix query when selecting sessions only Previously some sessions were selected which did not qualify for the search. Signed-off-by: Michael Tremer Signed-off-by: Arne Fitzenreiter --- diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index 703f4e5078..46667a9d1f 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; ); }