OpenVPN: Fix query when selecting sessions only

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

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
This commit is contained in:
Michael Tremer
2020-04-13 09:45:33 +02:00
committed by Arne Fitzenreiter
parent 3e10b3de4a
commit 70e1d58745

View File

@@ -107,27 +107,31 @@ my $database_query = qq(
ELSE DATETIME('$from_datestring', 'localtime', 'start of day') ELSE DATETIME('$from_datestring', 'localtime', 'start of day')
END END
), 'utc') ), 'utc')
) ) AS duration
FROM sessions FROM sessions
WHERE WHERE
disconnected_at IS NULL (
OR disconnected_at IS NULL
DATETIME(disconnected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day') OR
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') DATETIME(connected_at, 'localtime') < DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds')
GROUP BY common_name GROUP BY common_name
ORDER BY common_name; ORDER BY common_name, duration DESC;
); );
if ($cgiparams{'CONNECTION_NAME'}) { if ($cgiparams{'CONNECTION_NAME'}) {
$database_query = qq( $database_query = qq(
SELECT * SELECT * FROM sessions
FROM sessions
WHERE WHERE
common_name = '$cgiparams{"CONNECTION_NAME"}' AND ( common_name = '$cgiparams{"CONNECTION_NAME"}'
DATETIME(disconnected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day') AND (
OR DATETIME(disconnected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day')
DATETIME(connected_at, 'localtime') < DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds')); AND
DATETIME(connected_at, 'localtime') < DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds')
)
ORDER BY connected_at;
); );
} }