]> git.ipfire.org Git - ipfire-2.x.git/commitdiff
openvpn: Create database schema if not exists
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 25 May 2020 09:17:29 +0000 (10:17 +0100)
committerArne Fitzenreiter <arne_f@ipfire.org>
Tue, 26 May 2020 11:12:23 +0000 (11:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
html/cgi-bin/logs.cgi/ovpnclients.dat

index 2009990ec844f0535e858ae5fd5500c6f2251025..a064893a1a5cc7b75880a8c3b5c40fac7b63cf7b 100755 (executable)
@@ -95,6 +95,21 @@ unless ($to_datestring ge $from_datestring) {
        $errormessage = "$Lang::tr{'error the to date has to be later than the from date'}";
 }
 
        $errormessage = "$Lang::tr{'error the to date has to be later than the from date'}";
 }
 
+# Initialise database
+my $cursor = $database_handle->prepare("
+       CREATE TABLE IF NOT EXISTS sessions(
+               common_name TEXT NOT NULL,
+               connected_at TEXT NOT NULL,
+               disconnected_at TEXT,
+               bytes_received INTEGER,
+               bytes_sent INTEGER
+       );
+
+       -- Create index for speeding up searches
+       CREATE INDEX IF NOT EXISTS sessions_common_name ON sessions(common_name);
+");
+$cursor->execute();
+
 my $database_query = qq(
        SELECT
         common_name, SUM(
 my $database_query = qq(
        SELECT
         common_name, SUM(