Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 327 ++++++++++++++++++++++++++ langs/en/cgi-bin/en.pl | 2 + 2 files changed, 329 insertions(+) create mode 100755 html/cgi-bin/logs.cgi/ovpnclients.dat
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat new file mode 100755 index 000000000..703f4e507 --- /dev/null +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -0,0 +1,327 @@ +#!/usr/bin/perl +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2020 IPFire Team info@ipfire.org # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see http://www.gnu.org/licenses/. # +# # +############################################################################### + +use strict; +use POSIX(); +use DBI; + +# enable only the following on debugging purpose +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; + +require '/var/ipfire/general-functions.pl'; +require "${General::swroot}/lang.pl"; +require "${General::swroot}/header.pl"; + +my %color = (); +my %mainsettings = (); +&General::readhash("${General::swroot}/main/settings", %mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", %color); + +# Path and file of the OVPN connections database. +my $database = "/var/ipfire/ovpn/clients.db"; + +my %cgiparams=(); +my %logsettings=(); +my %ovpnsettings=(); + +my $errormessage=''; + +# Hash wich contains the month numbers and the translated names for easy access. +my %monthhash = ( + "1" => "$Lang::tr{'january'}", + "2" => "$Lang::tr{'february'}", + "3" => "$Lang::tr{'march'}", + "4" => "$Lang::tr{'april'}", + "5" => "$Lang::tr{'may'}", + "6" => "$Lang::tr{'june'}", + "7" => "$Lang::tr{'july'}", + "8" => "$Lang::tr{'august'}", + "9" => "$Lang::tr{'september'}", + "10" => "$Lang::tr{'october'}", + "11" => "$Lang::tr{'november'}", + "12" => "$Lang::tr{'december'}" +); + +# Get current time. +my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = localtime(time); + +# Adjust month, because Jan starts as month "0". +$month = $month+1; + +# Adjust year number. +$year = $year+1900; + +# Assign default vaules. +$cgiparams{'FROM_DAY'} = $mday; +$cgiparams{'FROM_MONTH'} = $month; +$cgiparams{'FROM_YEAR'} = $year; +$cgiparams{'TO_DAY'} = $mday; +$cgiparams{'TO_MONTH'} = $month; +$cgiparams{'TO_YEAR'} = $year; + +&Header::getcgihash(%cgiparams); + +# Read-in OpenVPN settings and connections. +&General::readhasharray("${General::swroot}/ovpn/ovpnconfig", %ovpnsettings); + +# Init DB Module and connect to the database. +my $database_handle = DBI->connect("DBI:SQLite:dbname=$database", "", "", { RaiseError => 1 }); + +# Generate datestrings for SQL queries. +my $from_datestring = sprintf '%04d-%02d-%02d', ($cgiparams{"FROM_YEAR"}, $cgiparams{"FROM_MONTH"}, $cgiparams{"FROM_DAY"}); +my $to_datestring = sprintf '%04d-%02d-%02d', ($cgiparams{"TO_YEAR"}, $cgiparams{"TO_MONTH"}, $cgiparams{"TO_DAY"}); + +my $database_query = qq( + SELECT + common_name, SUM( + STRFTIME('%s', ( + CASE + WHEN DATETIME(COALESCE(disconnected_at, CURRENT_TIMESTAMP), 'localtime') < DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds') + THEN DATETIME(COALESCE(disconnected_at, CURRENT_TIMESTAMP), 'localtime') + ELSE DATETIME('$to_datestring', 'localtime', 'start of day', '+86399 seconds') + END + ), 'utc') - + STRFTIME('%s', ( + CASE + WHEN DATETIME(connected_at, 'localtime') > DATETIME('$from_datestring', 'localtime', 'start of day') + THEN DATETIME(connected_at, 'localtime') + ELSE DATETIME('$from_datestring', 'localtime', 'start of day') + END + ), 'utc') + ) + FROM sessions + WHERE + disconnected_at IS NULL + OR + 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') + GROUP BY common_name + ORDER BY common_name; +); + +if ($cgiparams{'CONNECTION_NAME'}) { + $database_query = qq( + 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')); + ); +} + +# Prepare SQL statement. +my $statement_handle = $database_handle->prepare($database_query); + +# Execute SQL statement and get retun value if any error happened. +my $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) { + $errormessage = "$DBI::errstr"; +} + +&Header::showhttpheaders(); + +&Header::openpage($Lang::tr{'ovpn rw connection log'}, 1, ''); + +&Header::openbigbox('100%', 'left', '', $errormessage); + +if ($errormessage) { + &Header::openbox('100%', 'left', $Lang::tr{'error messages'}); + print "<font class='base'>$errormessage </font>\n"; + &Header::closebox(); +} + +&Header::openbox('100%', 'left', "$Lang::tr{'settings'}:"); + +print "<form method='post' action="$ENV{'SCRIPT_NAME'}">\n"; +print "<table width='100%'>\n"; + print "<tr>\n"; + print "<td class='base' colspan='2'><b>$Lang::tr{'from'}:</b></td>\n"; + print "</tr>\n"; + + print "<tr>\n"; + print "<td class='base'>$Lang::tr{'day'}: \n"; + &generate_select("FROM_DAY", "days"); + print "</td>\n"; + + print "<td class='base'>$Lang::tr{'month'}: \n"; + &generate_select("FROM_MONTH", "months"); + print "</td>\n"; + + print "<td class='base'>$Lang::tr{'year'}: \n"; + &generate_select("FROM_YEAR", "years"); + print "</td>\n"; + print "</tr>\n"; + + print "<tr><td><br></td></tr>\n"; + + print "<tr>\n"; + print "<td class='base' colspan='2'><b>$Lang::tr{'to'}:</b></td>\n"; + print "</tr>\n"; + + print "<tr>\n"; + print "<td class='base'>$Lang::tr{'day'}: \n"; + &generate_select("TO_DAY", "days"); + print "</td>\n"; + + print "<td class='base'>$Lang::tr{'month'}: \n"; + &generate_select("TO_MONTH", "months"); + print "</td>\n"; + + print "<td class='base'>$Lang::tr{'year'}: \n"; + &generate_select("TO_YEAR", "years"); + print "</td>\n"; + print "</tr>\n"; + + print "<tr><td><br></td></tr>\n"; + + print "<tr>\n"; + print "<td class='base'>$Lang::tr{'ovpn connection name'}:</td>\n"; + print "<td class='base' colspan='2'>\n"; + + print "<select name='CONNECTION_NAME' size='1'>\n"; + print "<option value=''>All</option>\n"; + + # Loop through all configured OpenVPN connections and sort them by name. + foreach my $key (sort { $ovpnsettings{$a}[2] cmp $ovpnsettings{$b}[2] } keys %ovpnsettings) { + my $connection_name = $ovpnsettings{$key}[2]; + my $selected; + + # Skip all non roadwarrior connections. + next unless ($ovpnsettings{"$key"}[3] eq "host"); + + # Check and mark the selected one. + if ($connection_name eq "$cgiparams{'CONNECTION_NAME'}") { + $selected = "selected"; + } + + print "<option value='$connection_name' $selected>$connection_name</option>\n"; + } + + print "</select>\n"; + print "</td>\n"; + print "</tr>\n"; + + print "<tr>\n"; + print "<td width='100%' align='right' colspan='3'><input type='submit' name='ACTION' value='$Lang::tr{'update'}'></td>\n"; + print "</tr>\n"; +print "</table>\n"; +print "</form>\n"; + +&Header::closebox(); + +&Header::openbox('100%', 'left', $Lang::tr{'log'}); + +my $lines = 0; + +print "<table width='100%' class='tbl'>"; + +my $col=""; + +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 = $row[3]; + my $connection_bytes_sent = $row[4]; + + # Colorize columns. + if ($lines % 2) { + $col="bgcolor='$color{'color22'}'"; + } else { + $col="bgcolor='$color{'color20'}'"; + } + +print <<END + <tr> + <td width="40%" align="left" $col>$connection_name</td> + <td width="20%" align="center" $col>$connection_open_time</td> + <td width="20%" align="center" $col>$connection_close_time</td> + <td width="10%" align="center" $col>$connection_bytes_recieved</td> + <td width="10%" align="center" $col>$connection_bytes_sent</td> + </tr> +END +; + + # Increase lines count. + $lines++; + + } + +print "</table><br>\n"; + +&Header::closebox(); + +# Close database connection. +$database_handle->disconnect(); + +&Header::closebigbox(); + +&Header::closepage(); + +# +## Function for easy select generation. +# +sub generate_select($$) { + my ($name, $type) = @_; + + my $start = 1; + my $stop; + + # Adjust start and stop by the given type. + if ($type eq "days") { + $stop = 31; + } elsif ($type eq "months") { + $stop = 12; + } elsif ($type = "years") { + $stop = $year; + $start = $stop - 10; + } + + # Print select HTML tag. + print "<select name='$name' size='1'>\n"; + + # Loop through the range. + for ( my $i = $start; $i <= $stop; $i++) { + print "\t<option "; + + # Check and select the current processed item. + if ($i == $cgiparams{$name}) { + print 'selected="selected" '; + } + + # Check if months are processed and display the corresponding names. + if ($type eq "months") { + print "value='$i'>$monthhash{$i}</option>\n"; + } else { + print "value='$i'>$i</option>\n"; + } + } + + # Close select HTML tag. + print "</select>\n\n"; +} diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index a68c8f411..9d3ca5c6d 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -1915,6 +1915,7 @@ 'ovpn' => 'OpenVPN', 'ovpn add conf' => 'Additional configuration', 'ovpn con stat' => 'OpenVPN Connection Statistics', +'ovpn connection name' => 'Connection name', 'ovpn config' => 'OVPN-Config', 'ovpn crypt options' => 'Cryptographic options', 'ovpn device' => 'OpenVPN device:', @@ -1947,6 +1948,7 @@ 'ovpn reneg sec' => 'Session key lifetime:', 'ovpn routes push' => 'Routes (one per line) e.g. 192.168.10.0/255.255.255.0 192.168.20.0/24', 'ovpn routes push options' => 'Route push options', +'ovpn rw connection log' => 'OpenVPN RW connections log', 'ovpn server status' => 'Current OpenVPN server status:', 'ovpn subnet' => 'OpenVPN subnet:', 'ovpn subnet is invalid' => 'OpenVPN subnet is invalid.',
From: Michael Tremer michael.tremer@ipfire.org
Previously some sessions were selected which did not qualify for the search.
Signed-off-by: Michael Tremer michael.tremer@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; ); }
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index 46667a9d1..bb7bdfb7b 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -207,7 +207,7 @@ print "<table width='100%'>\n"; print "<td class='base' colspan='2'>\n";
print "<select name='CONNECTION_NAME' size='1'>\n"; - print "<option value=''>All</option>\n"; + print "<option value=''>$Lang::tr{'all'}</option>\n";
# Loop through all configured OpenVPN connections and sort them by name. foreach my $key (sort { $ovpnsettings{$a}[2] cmp $ovpnsettings{$b}[2] } keys %ovpnsettings) {
This function can be used to convert an amount of bytes to a humand-readable format.
For example "3221225472" will become "3MB".
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- config/cfgroot/general-functions.pl | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 41a0eac2d..692e072c2 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -1261,4 +1261,29 @@ sub get_nameservers () { return &uniq(@nameservers); }
+# Function to format a string containing the amount of bytes to +# something human-readable. +sub formatBytes { + # Private array which contains the units. + my @units = qw(B KB MB GB TB PB); + + my $bytes = shift; + my $unit; + + # Loop through the array of units. + foreach my $element (@units) { + # Break loop if the bytes are less than the next unit. + last if $bytes < 1024; + + # Divide bytes amount with 1024. + $bytes /= 1024; + + # Assign current processed element to unit. + $unit = $element; + } + + # Return the divided and rounded bytes count and the unit. + return sprintf("%.2f %s", $bytes, $unit); +} + 1;
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index bb7bdfb7b..b601fd292 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -250,8 +250,8 @@ while(my @row = $statement_handle->fetchrow_array()) { my $connection_name = $row[0]; my $connection_open_time = $row[1]; my $connection_close_time = $row[2]; - my $connection_bytes_recieved = $row[3]; - my $connection_bytes_sent = $row[4]; + my $connection_bytes_recieved = &General::formatBytes($row[3]); + my $connection_bytes_sent = &General::formatBytes($row[4]);
# Colorize columns. if ($lines % 2) {
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- langs/en/cgi-bin/en.pl | 3 +++ 1 file changed, 3 insertions(+)
diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 9d3ca5c6d..1d3b87649 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -820,6 +820,7 @@ 'directory writeable' => 'directory writeable', 'disabled' => 'disabled', 'disconnect' => 'OVPN Stop / Disconnect', +'disconnected' => 'Disconnected', 'disconnects' => 'Disconnects', 'disk access per' => 'Disk Access per', 'disk usage' => 'Disk usage', @@ -2103,6 +2104,7 @@ 'reboot sure' => 'Are you sure that you want to reboot?', 'rebooting' => 'Rebooting', 'rebooting ipfire' => 'Rebooting IPFire', +'recieved' => 'Recieved', 'reconnect' => 'Reconnect', 'reconnection' => 'Reconnection', 'red' => 'Internet', @@ -2189,6 +2191,7 @@ 'send cr' => 'ISP requires Carriage Return:', 'send email notification' => 'Enabled, send e-mail notification', 'send test mail' => 'Send Teste-mail', +'sent' => 'Sent', 'september' => 'September', 'serial' => 'Serial', 'server reserved' => 'The connection name server is reserved and not allowed',
The header will be dynamically generated, according the items which will be displayed.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 46 +++++++++++++++++++-------- 1 file changed, 33 insertions(+), 13 deletions(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index b601fd292..33d6d8717 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -243,7 +243,21 @@ my $lines = 0;
print "<table width='100%' class='tbl'>";
-my $col=""; +my $col = "bgcolor='$color{'color20'}'"; + + print "<tr>\n"; + print "<td width='40%' $col><b>$Lang::tr{'ovpn connection name'}</b></td>\n"; + + if ($cgiparams{'CONNECTION_NAME'}) { + print "<td width='20%' $col><b>$Lang::tr{'connected'}</b></td>\n"; + print "<td width='20%' $col><b>$Lang::tr{'disconnected'}</b></td>\n"; + print "<td width='10%' $col><b>$Lang::tr{'recieved'}</b></td>\n"; + print "<td width='10%' $col><b>$Lang::tr{'sent'}</b></td>\n"; + } else { + print "<td $col><b>$Lang::tr{'total connection time'}</b>\n"; + } + + print "</tr>\n";
while(my @row = $statement_handle->fetchrow_array()) { # Assign some nice to read variable names for the DB fields. @@ -253,23 +267,29 @@ while(my @row = $statement_handle->fetchrow_array()) { my $connection_bytes_recieved = &General::formatBytes($row[3]); my $connection_bytes_sent = &General::formatBytes($row[4]);
- # Colorize columns. + # Colorize columns. if ($lines % 2) { + $col="bgcolor='$color{'color20'}'"; + } else { $col="bgcolor='$color{'color22'}'"; + } + + print "<tr>\n"; + print "<td width='40%' $col>$connection_name</td>\n"; + + if ($cgiparams{'CONNECTION_NAME'}) { + print "<td width='20%' $col>$connection_open_time</td>\n"; + print "<td width='20%' $col>$connection_close_time</td>\n"; + print "<td width='10%' $col>$connection_bytes_recieved</td>\n"; + print "<td width='10%' $col>$connection_bytes_sent</td>\n"; } else { - $col="bgcolor='$color{'color20'}'"; + # Convert total connection time into human-readable format. + my $total_time = &General::format_time($row[1]); + + print "<td $col>$total_time</td>\n"; }
-print <<END - <tr> - <td width="40%" align="left" $col>$connection_name</td> - <td width="20%" align="center" $col>$connection_open_time</td> - <td width="20%" align="center" $col>$connection_close_time</td> - <td width="10%" align="center" $col>$connection_bytes_recieved</td> - <td width="10%" align="center" $col>$connection_bytes_sent</td> - </tr> -END -; + print "</tr>\n";
# Increase lines count. $lines++;
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index 33d6d8717..cf3e0e7bc 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -123,7 +123,7 @@ my $database_query = qq(
if ($cgiparams{'CONNECTION_NAME'}) { $database_query = qq( - SELECT * FROM sessions + SELECT common_name, DATETIME(connected_at, 'localtime'), DATETIME(disconnected_at, 'localtime'), bytes_received, bytes_sent FROM sessions WHERE common_name = '$cgiparams{"CONNECTION_NAME"}' AND (
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 7 ++++++- langs/en/cgi-bin/en.pl | 1 + 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index cf3e0e7bc..b84c2b8d7 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -293,8 +293,13 @@ while(my @row = $statement_handle->fetchrow_array()) {
# 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. +unless ($lines) { + print "<tr><td bgcolor='$color{'color22'}' colspan='5' align='center'>$Lang::tr{'no entries'}</td></tr>\n"; +}
print "</table><br>\n";
diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 1d3b87649..171d24937 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -1800,6 +1800,7 @@ 'no alcatelusb firmware' => 'No Alcatel USB firmware. Please upload.', 'no cfg upload' => 'No data was uploaded', 'no dhcp lease' => 'No DHCP lease has been acquired', +'no entries' => 'No entries at the moment.', 'no eciadsl synch.bin file' => 'No ECI ADSL synch.bin file. Please upload.', 'no filter pass' => 'Enter the standard class for non-filtered packets.', 'no fritzdsl driver' => 'No Fritz!DSL driver. Please upload.',
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 5 +++++ langs/en/cgi-bin/en.pl | 1 + 2 files changed, 6 insertions(+)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index b84c2b8d7..a83a0bca9 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -90,6 +90,11 @@ my $database_handle = DBI->connect("DBI:SQLite:dbname=$database", "", "", { Rais my $from_datestring = sprintf '%04d-%02d-%02d', ($cgiparams{"FROM_YEAR"}, $cgiparams{"FROM_MONTH"}, $cgiparams{"FROM_DAY"}); my $to_datestring = sprintf '%04d-%02d-%02d', ($cgiparams{"TO_YEAR"}, $cgiparams{"TO_MONTH"}, $cgiparams{"TO_DAY"});
+# Check if the to datestring is later than the from datestring. +unless ($to_datestring ge $from_datestring) { + $errormessage = "$Lang::tr{'error the to date has to be later than the from date'}"; +} + my $database_query = qq( SELECT common_name, SUM( diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 171d24937..3d07473e7 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -1012,6 +1012,7 @@ 'error config' => 'Could not open /var/ipfire/ovpn/config/ZERINA.ovpn !', 'error external access' => 'Could not open /var/ipfire/xtaccess/config (external acccess could not be granted)!', 'error messages' => 'Error messages', +'error the to date has to be later than the from date' => 'The to date has to be later than the from date!', 'esp encryption' => 'ESP Encryption:', 'esp grouptype' => 'ESP Grouptype:', 'esp integrity' => 'ESP Integrity:',
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- 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 "</tr>\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 "<tr>\n"; - print "<td width='40%' $col>$connection_name</td>\n"; + print "<tr>\n"; + print "<td width='40%' $col>$connection_name</td>\n";
- if ($cgiparams{'CONNECTION_NAME'}) { - print "<td width='20%' $col>$connection_open_time</td>\n"; - print "<td width='20%' $col>$connection_close_time</td>\n"; - print "<td width='10%' $col>$connection_bytes_recieved</td>\n"; - print "<td width='10%' $col>$connection_bytes_sent</td>\n"; - } else { - # Convert total connection time into human-readable format. - my $total_time = &General::format_time($row[1]); + if ($cgiparams{'CONNECTION_NAME'}) { + print "<td width='20%' $col>$connection_open_time</td>\n"; + print "<td width='20%' $col>$connection_close_time</td>\n"; + print "<td width='10%' $col>$connection_bytes_recieved</td>\n"; + print "<td width='10%' $col>$connection_bytes_sent</td>\n"; + } else { + # Convert total connection time into human-readable format. + my $total_time = &General::format_time($row[1]);
- print "<td $col>$total_time</td>\n"; - } + print "<td $col>$total_time</td>\n"; + }
- print "</tr>\n"; + print "</tr>\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 "<tr><td bgcolor='$color{'color22'}' colspan='5' align='center'>$Lang::tr{'no entries'}</td></tr>\n"; }
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- config/cfgroot/general-functions.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/config/cfgroot/general-functions.pl b/config/cfgroot/general-functions.pl index 692e072c2..4c7cf09a8 100644 --- a/config/cfgroot/general-functions.pl +++ b/config/cfgroot/general-functions.pl @@ -1272,14 +1272,14 @@ sub formatBytes {
# Loop through the array of units. foreach my $element (@units) { + # Assign current processed element to unit. + $unit = $element; + # Break loop if the bytes are less than the next unit. last if $bytes < 1024;
# Divide bytes amount with 1024. $bytes /= 1024; - - # Assign current processed element to unit. - $unit = $element; }
# Return the divided and rounded bytes count and the unit.
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 2 +- langs/en/cgi-bin/en.pl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index 093315a64..62b91a054 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -262,7 +262,7 @@ my $col = "bgcolor='$color{'color20'}'"; if ($cgiparams{'CONNECTION_NAME'}) { print "<td width='20%' $col><b>$Lang::tr{'connected'}</b></td>\n"; print "<td width='20%' $col><b>$Lang::tr{'disconnected'}</b></td>\n"; - print "<td width='10%' $col><b>$Lang::tr{'recieved'}</b></td>\n"; + print "<td width='10%' $col><b>$Lang::tr{'received'}</b></td>\n"; print "<td width='10%' $col><b>$Lang::tr{'sent'}</b></td>\n"; } else { print "<td $col><b>$Lang::tr{'total connection time'}</b>\n"; diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 3d07473e7..3675a21ca 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -2106,7 +2106,7 @@ 'reboot sure' => 'Are you sure that you want to reboot?', 'rebooting' => 'Rebooting', 'rebooting ipfire' => 'Rebooting IPFire', -'recieved' => 'Recieved', +'received' => 'Received', 'reconnect' => 'Reconnect', 'reconnection' => 'Reconnection', 'red' => 'Internet',
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index 62b91a054..002a393ad 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -262,8 +262,8 @@ my $col = "bgcolor='$color{'color20'}'"; if ($cgiparams{'CONNECTION_NAME'}) { print "<td width='20%' $col><b>$Lang::tr{'connected'}</b></td>\n"; print "<td width='20%' $col><b>$Lang::tr{'disconnected'}</b></td>\n"; - print "<td width='10%' $col><b>$Lang::tr{'received'}</b></td>\n"; - print "<td width='10%' $col><b>$Lang::tr{'sent'}</b></td>\n"; + print "<td width='10%' align='right' $col><b>$Lang::tr{'received'}</b></td>\n"; + print "<td width='10%' align='right' $col><b>$Lang::tr{'sent'}</b></td>\n"; } else { print "<td $col><b>$Lang::tr{'total connection time'}</b>\n"; } @@ -293,8 +293,8 @@ unless ($errormessage) { if ($cgiparams{'CONNECTION_NAME'}) { print "<td width='20%' $col>$connection_open_time</td>\n"; print "<td width='20%' $col>$connection_close_time</td>\n"; - print "<td width='10%' $col>$connection_bytes_recieved</td>\n"; - print "<td width='10%' $col>$connection_bytes_sent</td>\n"; + print "<td width='10%' align='right' $col>$connection_bytes_recieved</td>\n"; + print "<td width='10%' align='right' $col>$connection_bytes_sent</td>\n"; } else { # Convert total connection time into human-readable format. my $total_time = &General::format_time($row[1]);
From: Michael Tremer michael.tremer@ipfire.org
Signed-off-by: Michael Tremer michael.tremer@ipfire.org --- langs/en/cgi-bin/en.pl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index 3675a21ca..a1747a654 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -1918,7 +1918,7 @@ 'ovpn' => 'OpenVPN', 'ovpn add conf' => 'Additional configuration', 'ovpn con stat' => 'OpenVPN Connection Statistics', -'ovpn connection name' => 'Connection name', +'ovpn connection name' => 'Connection Name', 'ovpn config' => 'OVPN-Config', 'ovpn crypt options' => 'Cryptographic options', 'ovpn device' => 'OpenVPN device:', @@ -1951,7 +1951,7 @@ 'ovpn reneg sec' => 'Session key lifetime:', 'ovpn routes push' => 'Routes (one per line) e.g. 192.168.10.0/255.255.255.0 192.168.20.0/24', 'ovpn routes push options' => 'Route push options', -'ovpn rw connection log' => 'OpenVPN RW connections log', +'ovpn rw connection log' => 'OpenVPN Roadwarrior Connections Log', 'ovpn server status' => 'Current OpenVPN server status:', 'ovpn subnet' => 'OpenVPN subnet:', 'ovpn subnet is invalid' => 'OpenVPN subnet is invalid.', @@ -2446,7 +2446,7 @@ 'tor traffic limit soft' => 'Traffic limit almost reached. Not accepting any new connections.', 'tor traffic read written' => 'Total traffic (read/written)', 'tor use exit nodes' => 'Use only these exit nodes (one per line)', -'total connection time' => 'Total connection time', +'total connection time' => 'Total Connection Time', 'total hits for log section' => 'Total hits for log section', 'traffic back' => 'Back', 'traffic calc time' => 'Time of calculation',
From: Michael Tremer michael.tremer@ipfire.org
Signed-off-by: Michael Tremer michael.tremer@ipfire.org --- html/cgi-bin/logs.cgi/ovpnclients.dat | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/html/cgi-bin/logs.cgi/ovpnclients.dat b/html/cgi-bin/logs.cgi/ovpnclients.dat index 002a393ad..2009990ec 100755 --- a/html/cgi-bin/logs.cgi/ovpnclients.dat +++ b/html/cgi-bin/logs.cgi/ovpnclients.dat @@ -128,7 +128,8 @@ my $database_query = qq(
if ($cgiparams{'CONNECTION_NAME'}) { $database_query = qq( - SELECT common_name, DATETIME(connected_at, 'localtime'), DATETIME(disconnected_at, 'localtime'), bytes_received, bytes_sent FROM sessions + SELECT common_name, DATETIME(connected_at, 'localtime'), DATETIME(disconnected_at, 'localtime'), bytes_received, bytes_sent, + STRFTIME('%s', DATETIME(disconnected_at)) - STRFTIME('%s', DATETIME(connected_at)) AS duration FROM sessions WHERE common_name = '$cgiparams{"CONNECTION_NAME"}' AND ( @@ -260,8 +261,9 @@ my $col = "bgcolor='$color{'color20'}'"; print "<td width='40%' $col><b>$Lang::tr{'ovpn connection name'}</b></td>\n";
if ($cgiparams{'CONNECTION_NAME'}) { - print "<td width='20%' $col><b>$Lang::tr{'connected'}</b></td>\n"; - print "<td width='20%' $col><b>$Lang::tr{'disconnected'}</b></td>\n"; + print "<td width='15%' $col><b>$Lang::tr{'connected'}</b></td>\n"; + print "<td width='15%' $col><b>$Lang::tr{'disconnected'}</b></td>\n"; + print "<td width='10%' align='right' $col><b>$Lang::tr{'duration'}</b></td>\n"; print "<td width='10%' align='right' $col><b>$Lang::tr{'received'}</b></td>\n"; print "<td width='10%' align='right' $col><b>$Lang::tr{'sent'}</b></td>\n"; } else { @@ -279,6 +281,7 @@ unless ($errormessage) { my $connection_close_time = $row[2]; my $connection_bytes_recieved = &General::formatBytes($row[3]); my $connection_bytes_sent = &General::formatBytes($row[4]); + my $duration = &General::format_time($row[5]);
# Colorize columns. if ($lines % 2) { @@ -291,8 +294,9 @@ unless ($errormessage) { print "<td width='40%' $col>$connection_name</td>\n";
if ($cgiparams{'CONNECTION_NAME'}) { - print "<td width='20%' $col>$connection_open_time</td>\n"; - print "<td width='20%' $col>$connection_close_time</td>\n"; + print "<td width='15%' $col>$connection_open_time</td>\n"; + print "<td width='15%' $col>$connection_close_time</td>\n"; + print "<td width='10%' align='right' $col>$duration</td>\n"; print "<td width='10%' align='right' $col>$connection_bytes_recieved</td>\n"; print "<td width='10%' align='right' $col>$connection_bytes_sent</td>\n"; } else { @@ -312,7 +316,7 @@ unless ($errormessage) { # If nothing has been fetched, the amount of lines is still zero. # In this case display a hint about no data. unless ($lines) { - print "<tr><td bgcolor='$color{'color22'}' colspan='5' align='center'>$Lang::tr{'no entries'}</td></tr>\n"; + print "<tr><td bgcolor='$color{'color22'}' colspan='6' align='center'>$Lang::tr{'no entries'}</td></tr>\n"; }
print "</table><br>\n";
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- config/menu/70-log.menu | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/config/menu/70-log.menu b/config/menu/70-log.menu index 08973de5a..48c23ccc2 100644 --- a/config/menu/70-log.menu +++ b/config/menu/70-log.menu @@ -43,6 +43,12 @@ 'title' => "$Lang::tr{'ids logs'}", 'enabled' => 1 }; + $sublogs->{'55.ovpnclients'} = { + 'caption' => $Lang::tr{'ovpn rw connection log'}, + 'uri' => '/cgi-bin/logs.cgi/ovpnclients.dat', + 'title' => "$Lang::tr{'ovpn rw connection log'}, + 'enabled' => 1, + }; $sublogs->{'60.urlfilter'} = { 'caption' => $Lang::tr{'urlfilter logs'}, 'uri' => '/cgi-bin/logs.cgi/urlfilter.dat',
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- langs/en/cgi-bin/en.pl | 1 + 1 file changed, 1 insertion(+)
diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index a1747a654..f9335a0e9 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -936,6 +936,7 @@ 'duplicate ip bold' => 'Duplicate addresses are in <b>bold</b>', 'duplicate mac' => 'Duplicate MAC address entered', 'duplicate name' => 'That name is already being used, please choose another.', +'duration' => 'Duration', 'dyn dns source choice' => 'Dynamic DNS provider(s) will receive an IP address for this IPFire from:', 'dynamic dns' => 'Dynamic DNS', 'dynamic dns client' => 'Dynamic DNS Client',
Signed-off-by: Stefan Schantl stefan.schantl@ipfire.org --- langs/de/cgi-bin/de.pl | 7 +++++++ 1 file changed, 7 insertions(+)
diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 80579e7cc..3959e1655 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -792,6 +792,7 @@ 'directory writeable' => 'Verzeichnis schreibbar', 'disabled' => 'deaktiviert', 'disconnect' => 'OVPN Stop / Trennen', +'disconnected' => 'Getrennt', 'disconnects' => 'Abbrüche', 'disk access per' => 'Plattenzugriff je', 'disk usage' => 'Festplattenbelegung', @@ -894,6 +895,7 @@ 'duplicate ip bold' => 'Doppelte Adressen sind <b>fett</b> gedruckt', 'duplicate mac' => 'Doppelte MAC-Adresse eingegeben', 'duplicate name' => 'Dieser Name wird bereits benutzt. Bitte wählen Sie einen anderen.', +'duration' => 'Dauer', 'dyn dns source choice' => 'Dynamic DNS Anbieter werden eine IP-Adresse für diesen IPFire erhalten von:', 'dynamic dns' => 'Dynamischer DNS', 'dynamic dns client' => 'Dynamischer DNS-Client', @@ -1863,6 +1865,7 @@ 'ovpn' => 'OpenVPN', 'ovpn add conf' => 'Erweiterte Konfiguration', 'ovpn con stat' => 'OpenVPN Verbindungs-Statistik', +'ovpn connection name' => 'Verbindungs-Name', 'ovpn config' => 'OVPN-Konfiguration', 'ovpn crypt options' => 'Kryptografieoptionen', 'ovpn device' => 'OpenVPN-Gerät', @@ -1895,6 +1898,7 @@ 'ovpn reneg sec' => 'Sitzungsschlüssellebensdauer', 'ovpn routes push' => 'Routen (eine pro Zeile) z.b. 192.168.10.0/255.255.255.0 192.168.20.0/24', 'ovpn routes push options' => 'Route push Optionen', +'ovpn rw connection log' => 'OpenVPN Roadwarrior Verbindungs-Log', 'ovpn server status' => 'OpenVPN-Server-Status', 'ovpn subnet' => 'OpenVPN-Subnetz:', 'ovpn subnet is invalid' => 'Das OpenVPN-Subnetz ist ungültig.', @@ -2044,6 +2048,7 @@ 'reboot sure' => 'Sind Sie sicher, dass Sie neustarten wollen?', 'rebooting' => 'Starte neu ...', 'rebooting ipfire' => 'Starte IPFire neu', +'recieved' => 'Empfangen', 'reconnect' => 'Neu Verbinden', 'reconnection' => 'Wiederverbindung', 'red' => 'Internet', @@ -2130,6 +2135,7 @@ 'send cr' => 'ISP verlangt Zeilenrücklaufzeichen:', 'send email notification' => 'Aktiviert, E-Mail Benachrichtigung senden', 'send test mail' => 'Sende Testemail', +'sent' => 'Gesendet', 'september' => 'September', 'serial' => 'serielle', 'server reserved' => 'The connection name server is reserved and not allowed', @@ -2373,6 +2379,7 @@ 'tor traffic read written' => 'Gesamter Traffic (empfangen/gesendet)', 'tor use exit nodes' => 'Nur diese Exit-Nodes benutzen (eins pro Zeile)', 'total connection time' => 'Verbindungszeit', +'total connection time' => 'Gesammte Verbindungszeit', 'total hits for log section' => 'Gesamte Treffer für Protokollsektion', 'traffic back' => 'Zurück', 'traffic calc time' => 'Berechnungszeitpunkt',