--- /dev/null
+#!/usr/bin/perl
+#
+# This code is distributed under the terms of the GPL
+#
+# (c) Achim Weber 2006
+#
+# $Id: monitorTraffic.pl,v 1.14 2006/12/15 14:43:57 dotzball Exp $
+#
+#
+
+use strict;
+
+# enable only the following on debugging purpose
+use warnings;
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/net-traffic/net-traffic-lib.pl";
+require "${General::swroot}/net-traffic/net-traffic-admin.pl";
+
+my @dummy = (${Traffic::red_in},${Traffic::red_out});
+undef(@dummy);
+
+# Debug level:
+# 0 - send email (if enabled), no print
+# 1 - send email (if enabled), print
+# 2 - only print
+my $debugLevel = 0;
+# Debug
+
+my %log = ();
+$log{'CALC_VOLUME_TOTAL'} = 0;
+$log{'CALC_VOLUME_IN'} = 0;
+$log{'CALC_VOLUME_OUT'} = 0;
+$log{'CALC_WEEK_TOTAL'} = 0;
+$log{'CALC_WEEK_IN'} = 0;
+$log{'CALC_WEEK_OUT'} = 0;
+$log{'CALC_LAST_RUN'} = 0;
+$log{'CALC_PERCENT'} = 0;
+$log{'WARNMAIL_SEND'} = 'no';
+
+# current time == endtime
+my $currentTime = time;
+
+# on force we don't load the log data
+unless(defined($ARGV[0]) && $ARGV[0] eq '--force') {
+ &General::readhash($NETTRAFF::logfile, \%log);
+}
+
+
+# Only send email?
+if(defined($ARGV[0]) && ($ARGV[0] eq '--testEmail' || $ARGV[0] eq '--warnEmail'))
+{
+ print "Send testmail\n" if($debugLevel > 0);
+ # send (test|warn) email
+ my $return = &sendEmail($ARGV[0]);
+ print "$return\n";
+ exit 0;
+}
+
+
+# should we recalculate?
+# calc seconds for one interval
+my $intervalTime = $NETTRAFF::settings{'CALC_INTERVAL'} * 60;
+# next time, we have to calculate
+my $nextRunTime = $log{'CALC_LAST_RUN'} + $intervalTime;
+
+if ($debugLevel > 0)
+{
+ my($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($log{'CALC_LAST_RUN'});
+ my $lastRun = sprintf("%04d-%02d-%02d, %02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min);
+ print "last run: $lastRun\n";
+
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($nextRunTime);
+ my $nextRun = sprintf("%04d-%02d-%02d, %02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min);
+ print "next run: $nextRun\n";
+
+ ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($currentTime);
+ my $current = sprintf("%04d-%02d-%02d, %02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min);
+ print "current time: $current\n";
+}
+
+# use a little time buffer in case the last run started some seconds earlier
+if($currentTime < ($nextRunTime - 60) )
+{
+ # nothing to do
+ if ($debugLevel > 0)
+ {
+ my $infoMsg = "Net-Traffic: nothing to do, do next calculation later.";
+ print "$infoMsg\n";
+ &General::log($infoMsg);
+ }
+ exit 0;
+}
+elsif($debugLevel > 0)
+{
+ my $infoMsg = "Net-Traffic: Calc traffic now.";
+ print "$infoMsg\n";
+ &General::log($infoMsg);
+}
+
+####
+# Calculate Traffic
+#
+
+$log{'CALC_LAST_RUN'} = $currentTime;
+my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($currentTime);
+
+
+#####################
+# this month traffic
+###
+my $startDay = '1';
+my $startMonth = $mon + 1;
+my $startYear = $year + 1900;
+
+if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+{
+ $startDay = $NETTRAFF::settings{'STARTDAY'};
+}
+
+# this periode started last month
+if ($mday < $startDay)
+{
+ # when current month is january we start in last year december
+ if ($startMonth == 1) {
+ $startYear--;
+ $startMonth = 12;
+ }
+ else
+ {
+ $startMonth--;
+ }
+}
+$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
+$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
+
+my $start = "$startYear$startMonth$startDay";
+
+my %month = &getTrafficData($start, $currentTime);
+
+$log{'CALC_VOLUME_TOTAL'} = $month{'TOTAL'};
+$log{'CALC_VOLUME_IN'} = $month{'IN'};
+$log{'CALC_VOLUME_OUT'} = $month{'OUT'};
+#####################
+
+
+#####################
+# this week traffic
+###
+$startMonth = $mon;
+$startYear = $year + 1900;
+$startDay = $mday-($wday >0 ? $wday-1 : 6);
+# borrowed from ipacsum
+my @mofg = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
+
+if ($startDay < 1) {
+ $startMonth--;
+ if ($startMonth < 0) {
+ $startMonth += 12;
+ $startYear--;
+ }
+ $startDay += $mofg[$startMonth];
+}
+
+# $mon starts at 0 but we have to start at 1
+$startMonth++;
+
+$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
+$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
+
+$start = "$startYear$startMonth$startDay";
+
+my %week = &getTrafficData($start, $currentTime);
+$log{'CALC_WEEK_TOTAL'} = $week{'TOTAL'};
+$log{'CALC_WEEK_IN'} = $week{'IN'};
+$log{'CALC_WEEK_OUT'} = $week{'OUT'};
+####################
+
+
+
+my $infoMsg = "Reached: $log{'CALC_VOLUME_TOTAL'} MB\n";
+$infoMsg .= "start: $start";
+print "$infoMsg\n" if ($debugLevel > 0);
+
+
+# monthly traffic volume?
+if ($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+{
+ $log{'CALC_PERCENT'} = sprintf("%d", ($log{'CALC_VOLUME_TOTAL'} / $NETTRAFF::settings{'MONTHLY_VOLUME'} * 100));
+
+ my $infoMsg = "Used (\%): $log{'CALC_PERCENT'} \% - Max.: $NETTRAFF::settings{'MONTHLY_VOLUME'} MB";
+ print "$infoMsg\n" if ($debugLevel > 0);
+
+
+ if($NETTRAFF::settings{'WARN_ON'} eq 'on'
+ && $log{'CALC_PERCENT'} >= $NETTRAFF::settings{'WARN'})
+ {
+ # warnlevel is reached
+ if ($debugLevel > 0)
+ {
+ my $warnMsg = "Net-Traffic warning: $infoMsg";
+ print "$warnMsg\n";
+ &General::log($warnMsg);
+ }
+
+ if($debugLevel < 2)
+ {
+ if($NETTRAFF::settings{'SEND_EMAIL_ON'} eq 'on'
+ && $log{'WARNMAIL_SEND'} ne 'yes')
+ {
+ # send warn email
+ my $return = &sendEmail('--warnEmail');
+
+ if($return =~ /Email was sent successfully!/)
+ {
+ $log{'WARNMAIL_SEND'} = 'yes';
+ }
+ else {
+ $log{'WARNMAIL_SEND'} = 'no';
+ }
+ }
+ }
+
+ }
+ else
+ {
+ # warnlevel not reached, reset warnmail send
+ $log{'WARNMAIL_SEND'} = 'no';
+ }
+}
+
+&General::writehash($NETTRAFF::logfile, \%log);
+
+exit 0;
+
+
+sub getTrafficData
+{
+ my $p_start = shift;
+ my $p_currentTime = shift;
+
+ if($debugLevel > 0)
+ {
+ print "----------------------\n";
+ print "start: $p_start\n";
+ print "current time: $p_currentTime\n";
+ }
+
+ #my $displayMode = "exactTimeframe";
+ my $displayMode = "exactEnd";
+
+ my %allDaysBytes = ();
+ my @allDays = &Traffic::calcTraffic(\%allDaysBytes, $p_start, $p_currentTime, $displayMode);
+
+ my %traff = ();
+ $traff{'IN'} = 0;
+ $traff{'OUT'} = 0;
+ $traff{'TOTAL'} = 0;
+
+ foreach my $day (@allDays)
+ {
+ if($debugLevel > 0)
+ {
+ print "day: $day\n";
+ print "in: $allDaysBytes{$day}{${Traffic::red_in}}\n";
+ print "out: $allDaysBytes{$day}{${Traffic::red_out}}\n";
+ }
+
+ $traff{'IN'} += $allDaysBytes{$day}{${Traffic::red_in}};
+ $traff{'OUT'} += $allDaysBytes{$day}{${Traffic::red_out}};
+ }
+
+ $traff{'TOTAL'} = $traff{'IN'} + $traff{'OUT'};
+
+ # formating
+ $traff{'TOTAL'} = sprintf("%.2f", ($traff{'TOTAL'}/1048576));
+ $traff{'IN'} = sprintf("%.2f", ($traff{'IN'}/1048576));
+ $traff{'OUT'} = sprintf("%.2f", ($traff{'OUT'}/1048576));
+
+ if($debugLevel > 0)
+ {
+ print "IN: $traff{'IN'}\n";
+ print "OUT: $traff{'OUT'}\n";
+ print "TOTAL: $traff{'TOTAL'}\n";
+ print "----------------------\n";
+ }
+
+ return %traff;
+}
+
+
+sub sendEmail
+{
+ my $mailtyp = shift;
+
+ my $template = "";
+
+ my %ipfireSettings = ();
+ &General::readhash("${General::swroot}/main/settings", \%ipfireSettings);
+ my $host = "$ipfireSettings{'HOSTNAME'}.$ipfireSettings{'DOMAINNAME'}";
+
+ my $subject = "[Net-Traffic] $host: ";
+
+ if($mailtyp eq '--warnEmail')
+ {
+ $subject .= $Lang::tr{'subject warn'};
+ $template = "warn";
+ }
+ else
+ {
+ $subject .= $Lang::tr{'subject test'};
+ $template = "test";
+ }
+
+ if(-e "${General::swroot}/net-traffic/templates/$template.${Lang::language}")
+ {
+ $template .= ".${Lang::language}";
+ }
+ else
+ {
+ $template .= ".en";
+ }
+
+ # read template
+ open(FILE, "${General::swroot}/net-traffic/templates/$template");
+ my @temp = <FILE>;
+ close(FILE);
+
+ my $date_current = &NETTRAFF::getFormatedDate($currentTime);
+ my $date_lastrun = &NETTRAFF::getFormatedDate($log{'CALC_LAST_RUN'});
+
+ my $message = "";
+ foreach my $line (@temp)
+ {
+ chomp($line);
+ $line =~ s/__HOSTNAME__/$host/;
+ $line =~ s/__CALC_VOLUME_TOTAL__/$log{'CALC_VOLUME_TOTAL'}/;
+ $line =~ s/__CALC_PERCENT__/$log{'CALC_PERCENT'}/;
+ $line =~ s/__MONTHLY_VOLUME__/$NETTRAFF::settings{'MONTHLY_VOLUME'}/;
+ $line =~ s/__STARTDAY__/$NETTRAFF::settings{'STARTDAY'}/;
+ $line =~ s/__CURRENT_DATE__/$date_current/;
+ $line =~ s/__LAST_RUN__/$date_lastrun/;
+
+ $message .= "$line\n";
+ }
+
+
+ my $cmd = "/usr/local/bin/sendEmail_nettraffic -f $NETTRAFF::settings{'EMAIL_FROM'} ";
+ $cmd .= " -t $NETTRAFF::settings{'EMAIL_TO'} ";
+ $cmd .= " -u \"$subject\" ";
+ $cmd .= " -m \"$message\" ";
+ $cmd .= " -s $NETTRAFF::settings{'EMAIL_SERVER'} ";
+
+ if($NETTRAFF::settings{'EMAIL_USR'} ne '') {
+ $cmd .= " -xu $NETTRAFF::settings{'EMAIL_USR'} ";
+ }
+ if($NETTRAFF::settings{'EMAIL_PW'} ne '') {
+ $cmd .= " -xp $NETTRAFF::settings{'EMAIL_PW'} ";
+ }
+
+ my $return = `$cmd`;
+
+ return $return;
+}
+
+
--- /dev/null
+#!/usr/bin/perl
+#
+# This file is a library file for the Net-Traffic Addon.
+#
+# Copyright (C) 2006 Achim Weber <dotzball@users.sourceforge.net>
+#
+# $Id: net-traffic-admin.pl,v 1.13 2006/12/10 13:46:00 dotzball Exp $
+#
+# 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 2 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, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+package NETTRAFF;
+
+use strict;
+use LWP::UserAgent;
+
+require '/var/ipfire/general-functions.pl';
+require "${General::swroot}/lang.pl";
+require "${General::swroot}/header.pl";
+
+$|=1; # line buffering
+
+my $updateUrl = "http://blockouttraffic.de/version/Net-Traffic.latest";
+my $latestVersionFile = "${General::swroot}/net-traffic/latestVersion";
+
+%NETTRAFF::settings;
+
+
+$NETTRAFF::settingsfile = "${General::swroot}/net-traffic/settings";
+$NETTRAFF::versionfile = "${General::swroot}/net-traffic/version";
+$NETTRAFF::logfile = "/var/log/net-traffic.log";
+$NETTRAFF::colorOk = '#00FF00';
+$NETTRAFF::colorWarn = '#FFFF00';
+$NETTRAFF::colorMax = '#FF0000';
+
+
+#~ $NETTRAFF::settingsCGI = '/cgi-bin/fwrulesadm.cgi';
+#~ $NETTRAFF::configCGI = '/cgi-bin/fwrules.cgi';
+#~ $NETTRAFF::advConfCGI = '/cgi-bin/fwadvconf.cgi';
+
+
+@NETTRAFF::longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
+ $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
+ $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
+ $Lang::tr{'december'} );
+
+@NETTRAFF::months = ( 0,1,2,3,4,5,6,7,8,9,10,11 );
+
+@NETTRAFF::years=("2001","2002","2003","2004","2005","2006","2007","2008","2009");
+
+#workaround to suppress a warning when a variable is used only once
+my @dummy = ( $General::version );
+undef (@dummy);
+
+
+# Init Settings
+$NETTRAFF::settings{'MONTHLY_VOLUME_ON'} = 'off';
+$NETTRAFF::settings{'MONTHLY_VOLUME'} = '1';
+$NETTRAFF::settings{'STARTDAY'} = '1';
+$NETTRAFF::settings{'WARN_ON'} = 'off';
+$NETTRAFF::settings{'WARN'} = '80';
+$NETTRAFF::settings{'CALC_INTERVAL'} = '60';
+$NETTRAFF::settings{'SHOW_AT_HOME'} = 'on';
+$NETTRAFF::settings{'SEND_EMAIL_ON'} = 'off';
+$NETTRAFF::settings{'EMAIL_TO'} = '';
+$NETTRAFF::settings{'EMAIL_FROM'} = '';
+$NETTRAFF::settings{'EMAIL_USR'} = '';
+$NETTRAFF::settings{'EMAIL_PW'} = '';
+$NETTRAFF::settings{'EMAIL_SERVER'} = '';
+$NETTRAFF::settings{'VERSION_CHECK_ON'} = 'off';
+
+&NETTRAFF::readSettings();
+
+
+sub readSettings
+{
+ &General::readhash($NETTRAFF::settingsfile, \%NETTRAFF::settings);
+}
+
+
+sub showNetTrafficVersion
+{
+ my %versionSettings = ();
+
+ &General::readhash($NETTRAFF::versionfile, \%versionSettings);
+
+ print <<END;
+ <a href="http://$versionSettings{'URL'}" target="_blank">
+ <b>Net-Traffic $versionSettings{'VERSION_INSTALLED'}
+ -
+END
+ print "Build $versionSettings{'BUILD_INSTALLED'}";
+
+ if ($versionSettings{'IS_TESTVERSION'} == 1) {
+ print " - Testversion $versionSettings{'TESTVERSION'}";
+ }
+ print "</b></a><br /><br />\n";
+
+ # check for new version
+ &checkForNewVersion();
+}
+
+sub traffPercentbar
+{
+ my $percent = $_[0];
+ my $fg = '#a0a0a0';
+ my $bg = '#e2e2e2';
+
+ if ($percent =~ m/^(\d+)%$/ )
+ {
+ print <<END;
+ <table width='100%' border='1' cellspacing='0' cellpadding='0' style='border-width:1px;border-style:solid;border-color:$fg;width:100%;height:10px;'>
+ <tr>
+END
+
+ if ($percent eq "100%" || $1 > 100)
+ {
+ $fg = $NETTRAFF::colorMax;
+ print "<td width='100%' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
+ }
+ elsif ($percent eq "0%")
+ {
+ print "<td width='100%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
+ }
+ else
+ {
+ if($NETTRAFF::settings{'WARN_ON'} eq 'on'
+ && $1 >= $NETTRAFF::settings{'WARN'})
+ {
+ $fg = $NETTRAFF::colorWarn;
+ }
+
+ print "<td width='$percent' bgcolor='$fg' style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td width='" . (100-$1) . "%' bgcolor='$bg' style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
+ }
+ print <<END;
+ <img src='/images/null.gif' width='1' height='1' alt='' />
+ </td>
+ </tr>
+ </table>
+END
+
+ }
+}
+
+
+sub checkForNewVersion
+{
+ if ($NETTRAFF::settings{'VERSION_CHECK_ON'} ne 'on')
+ {
+ return;
+ }
+
+ # download latest version
+ &downloadLatestVersionInfo();
+
+ if(-e $latestVersionFile)
+ {
+ my %versionSettings = ();
+ &General::readhash($NETTRAFF::versionfile, \%versionSettings);
+
+ my %latestVersion = ();
+ &General::readhash($latestVersionFile, \%latestVersion);
+
+ if( $versionSettings{'VERSION_INSTALLED'} lt $latestVersion{'VERSION_AVAILABLE'}
+ || ( $versionSettings{'VERSION_INSTALLED'} le $latestVersion{'VERSION_AVAILABLE'}
+ && $versionSettings{'BUILD_INSTALLED'} lt $latestVersion{'BUILD_AVAILABLE'} ) )
+ {
+ &Header::openbox('100%', 'left', $Lang::tr{'info'});
+ print <<END;
+ <table width="100%">
+ <tr>
+ <td>
+ $Lang::tr{'net traffic newversion'}
+ <a href="$latestVersion{'URL_UPDATE'}" target="_blank">
+ <b>$latestVersion{'URL_UPDATE'}</b>
+ </a>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <b>v$latestVersion{'VERSION_AVAILABLE'} - Build $latestVersion{'BUILD_AVAILABLE'}
+ </table>
+END
+
+ &Header::closebox();
+ }
+ }
+}
+
+sub downloadLatestVersionInfo
+{
+ # only check if we are online
+ if (! -e '/var/ipfire/red/active')
+ {
+ return;
+ }
+
+ # download latest version file if it is not existing or outdated (i.e. 5 days old)
+ if((! -e $latestVersionFile) || (int(-M $latestVersionFile) > 5))
+ {
+ my %versionSettings = ();
+ &General::readhash($NETTRAFF::versionfile, \%versionSettings);
+
+ my $ua = LWP::UserAgent->new;
+ $ua->timeout(120);
+ $ua->agent("Mozilla/4.0 (compatible; IPFire $General::version; $versionSettings{'VERSION_INSTALLED'})");
+ my $content = $ua->get($updateUrl);
+
+ if ( $content->is_success )
+ {
+#~ open(FILE, ">$latestVersionFile") or die "Could not write file: $latestVersionFile";
+#~ flock (FILE, 2);
+#~ print FILE "$content->content\n";
+#~ close(FILE);
+
+ my %latestVersion = ();
+
+ # latest versions, format is: MOD_VERSION="1.3.0"
+ $content->content =~ /MOD_VERSION="(.+?)"/;
+ $latestVersion{'VERSION_AVAILABLE'} = $1;
+
+ # latest build, format is: MOD_BUILD="0"
+ $content->content =~ /MOD_BUILD="(.+?)"/;
+ $latestVersion{'BUILD_AVAILABLE'} = $1;
+
+ # URL format is: MOD_URL="http://blockouttraffic.de/nt_index.php"
+ $content->content =~ /MOD_URL="(.+?)"/;
+ $latestVersion{'URL_UPDATE'} = $1;
+
+ &General::writehash($latestVersionFile, \%latestVersion);
+ }
+ }
+}
+
+
+sub getFormatedDate
+{
+ my $time = shift;
+ my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time);
+
+ return sprintf("%04d-%02d-%02d, %02d:%02d", 1900+$year, $mon+1, $mday, $hour, $min);;
+
+}
+# always return 1;
+1;
+# EOF
#!/usr/bin/perl
#
-# $Id: net-traffic-lib.pl,v 1.4 2005/03/17 11:43:55 dotzball Exp $
+# $Id: net-traffic-lib.pl,v 1.10 2007/01/09 19:00:35 dotzball Exp $
#
# Summarize all IP accounting files from start to end time
#
use Time::Local;
use Socket;
use IO::Handle;
+#use warnings;
+#use strict;
$|=1; # line buffering
-@moff = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 );
+my @moff = (0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 );
# =()<$datdelim="@<DATDELIM>@";>()=
-$datdelim="#-#-#-#-#";
+my $datdelim="#-#-#-#-#";
# =()<$prefix="@<prefix>@";>()=
-$prefix="/usr";
+my $prefix="/usr";
# =()<$exec_prefix="@<exec_prefix>@";>()=
-$exec_prefix="${prefix}";
+my $exec_prefix="${prefix}";
# =()<$INSTALLPATH="@<INSTALLPATH>@";>()=
-$INSTALLPATH="${exec_prefix}/sbin";
-$datdir="/var/log/ip-acct";
+my $INSTALLPATH="${exec_prefix}/sbin";
+my $datdir="/var/log/ip-acct";
-$me=$0;
+my $me=$0;
$me =~ s|^.*/([^/]+)$|$1|;
-$now = time;
-$fetchipac="$INSTALLPATH/fetchipac";
-$rule_regex = ".*"; # match rules with this regex only
+my $now = time;
+my $fetchipac="$INSTALLPATH/fetchipac";
+my $rule_regex = ".*"; # match rules with this regex only
+my $machine_name;
+my $fetchipac_options;
+my ($newest_timestamp_before_starttime, $oldest_timestamp_after_endtime);
+my (%rule_firstfile, %rule_lastfile);
+my $count;
+my @timestamps;
+my $rulenumber;
+my ($starttime, $endtime);
## Net-Traffic variables ##
-my %allDays = ();
+my %allDays;
my $allDaysBytes;
my $tzoffset = 0;
my $displayMode = "daily";
$starttime = shift;
$endtime = shift;
$displayMode = shift;
-
+
+ # init
+ %allDays = ();
$starttime =~ /^(\d\d\d\d)(\d\d)/;
$curYear = $1;
$curMonth = $2;
$tzoffset = time-timegm(localtime());
$machine_name = undef;
- $starttime = makeunixtime($starttime);
- $endtime = makeunixtime($endtime);
+ if($displayMode ne "exactTimeframe")
+ {
+ $starttime = makeunixtime($starttime);
+ if($displayMode ne 'exactEnd') {
+ $endtime = makeunixtime($endtime);
+ }
+ }
$endtime -= 1;
# options that we need to pass to fetchipac if we call it.
$endtime = $now if ($endtime > $now);
$starttime = 0 if ($starttime < 0);
- $mystarttime = &makemydailytime($starttime);
- $myendtime = &makemydailytime($endtime);
- %rule_firstfile = %rule_lastfile = ( );
+#~ $mystarttime = &makemydailytime($starttime);
+#~ $myendtime = &makemydailytime($endtime);
+ %rule_firstfile = ( );
+ %rule_lastfile = ( );
+ @timestamps = ();
# find out which timestamps we need to read.
# remember newest timestamp before starttime so we know when data for
}
close DATA;
- push(@timestamps, $oldest_timestamp_after_endtime)
+ push(@timestamps, $oldest_timestamp_after_endtime)
if ($oldest_timestamp_after_endtime);
- unshift(@timestamps, $newest_timestamp_before_starttime)
+ unshift(@timestamps, $newest_timestamp_before_starttime)
if ($newest_timestamp_before_starttime);
$rulenumber = 0;
# read all data we need and put the data into memory.
&read_data;
- @days_sorted = sort keys %allDays;
+ my @days_sorted = sort keys %allDays;
return @days_sorted;
}
##########################
$curMonth = 1;
$curYear++;
}
- my $newMonth = $curYear;
+ my $newMonth = $curYear;
$newMonth .= $curMonth < 10 ? "0".$curMonth."01" : $curMonth."01";
$newMonth .= "01";
$curDay = &makeunixtime($newMonth);
if ($timestamp < $starttime) {
# this record is too old, we dont need the data.
- # However, the timestamp gives us a clue on the
+ # However, the timestamp gives us a clue on the
# time period the next item covers.
$do_collect = 0;
}
# first one, split the data (if we know for how
# long this data is valid, and if $laststamp is not
# equal to $starttime in which case the split is
- # redundant). If we don't have a clue about the
+ # redundant). If we don't have a clue about the
# last file time before our first file was created,
# we do not know how much of the file data is in our
# time frame. we assume everything belongs to us.
if ($laststamp && $laststamp != $newest_timestamp_before_starttime) {
my $newdata = &split_data($data,
$laststamp, $timestamp, $starttime);
- $glb_data_before = $data;
+#~ $glb_data_before = $data;
$data = $newdata;
$laststamp = $starttime;
}
if ($after_time == 0) {
$after_time = 1;
if ($laststamp) {
- $glb_data_after =
- &split_data($data,$laststamp,$timestamp,$endtime);
+#~ $glb_data_after =
+#~ &split_data($data,$laststamp,$timestamp,$endtime);
+ &split_data($data,$laststamp,$timestamp,$endtime);
} else {
$do_collect = 0;
}
# $fac1 now says us how much weight the first result has.
# initialize the set we will return.
my @ret = ( );
-
- foreach $set (@$data) {
+
+ foreach my $set (@$data) {
my ($rule, $bytes, $pkts) = @$set;
$$set[1] = int($bytes * $fac1 + 0.5);
$$set[2] = int($pkts * $fac1 + 0.5);
# put data from one file into global data structures
# must be called in correct sorted file name order to set rules_lastfile
# and rules_firstfile (which are currently useless)
-# arguments:
+# arguments:
# $1=index number of file; $2 = reference to array with data from file
sub collect_data {
my($filedata, $ifile, $i, $day);
my $rule = $$set[0];
my $bytes = $$set[1];
my $pkts = $$set[2];
-
+
$_ = $rule;
/^(.*) \(.*$/;
$_ = $1;
my $newDay = &makemydailytime($s);
$newDay =~ /^\d\d\d\d-(\d\d)-\d\d$/;
- return 1 if ($1 > $curMonth && $displayMode ne "daily_multi");
-
+ return 1 if ($1 > $curMonth && $displayMode ne "daily_multi");
+
$allDaysBytes->{$s}{'Day'} = $newDay;
}
else {
# read data record from filehandle $1
# number of records is $2
-# Return value: reference to array a of length n;
+# Return value: reference to array a of length n;
# n is the number of rules
# each field in a is an array aa with 3 fields
# the fields in arrays aa are: [0]=name of rule; [1]=byte count;
# use time zone offset $tzoffset (input=wall clock time, output=UTC)
sub makeunixtime {
my($y, $m, $d, $h, $i, $e);
- $s = shift;
+ my $s = shift;
$h=0; $i=0; $e=0;
if ($s =~ /^(\d\d\d\d)(\d\d)(\d\d)/) {
# Reset Dialup Statistics
bootrun 0 0 1 * * /usr/local/bin/dialctrl.pl reset
+
+# run traffic monitoring every 5 minutes
+*/5 * * * * /usr/local/bin/monitorTraff > /dev/null
--- /dev/null
+Dies ist eine Testemail von Net-Traffic auf Ihrem IPCop __HOSTNAME__.
+
+Verbrauchtes Monatsvolumen: __CALC_VOLUME_TOTAL__ MB (__CALC_PERCENT__ %)
+Maximales Volumen pro Abrechnungsperiode: __MONTHLY_VOLUME__ MB
+
+Erste Tag der Abrechnungsperiode ist: __STARTDAY__
+
+Aktuelles Datum: __CURRENT_DATE__
+Letzte Traffic Berechnung: __LAST_RUN__
+
--- /dev/null
+This is a testemail from Net-Traffic on your IPCop __HOSTNAME__.
+
+This months volume: __CALC_VOLUME_TOTAL__ MB (__CALC_PERCENT__ %)
+Maximum volume per period: __MONTHLY_VOLUME__ MB
+
+Startday of periode is: __STARTDAY__
+
+Current date is: __CURRENT_DATE__
+Last traffic calculation: __LAST_RUN__
+
--- /dev/null
+To jest email testowy z Net-Traffic na Twoim IPCop __HOSTNAME__.
+
+Transfer w tym miesi¹cu: __CALC_VOLUME_TOTAL__ MB (__CALC_PERCENT__ %)
+Maksymalny transfer w okresie: __MONTHLY_VOLUME__ MB
+
+Pocz¹tkowy dzieñ okresu: __STARTDAY__
+
+Bie¿¹ca data: __CURRENT_DATE__
+Ostatnie obliczenia ruchu: __LAST_RUN__
+
+
--- /dev/null
+Der Traffic auf Ihrem IPCop __HOSTNAME__ hat das gewählte Warnlevel erreicht!
+
+Verbrauchtes Monatsvolumen: __CALC_VOLUME_TOTAL__ MB (__CALC_PERCENT__ %)
+Maximales Volumen pro Abrechnungsperiode: __MONTHLY_VOLUME__ MB
+
+Erste Tag der Abrechnungsperiode ist: __STARTDAY__
+
+Aktuelles Datum: __CURRENT_DATE__
+
--- /dev/null
+The traffic on your IPCop __HOSTNAME__ has reached the selected warnlevel!
+
+This months volume: __CALC_VOLUME_TOTAL__ MB (__CALC_PERCENT__ %)
+Maximum volume per period: __MONTHLY_VOLUME__ MB
+
+Startday of periode is: __STARTDAY__
+
+Current date is: __CURRENT_DATE__
+
--- /dev/null
+Transfer na Twoim IPCop __HOSTNAME__ osi¹gn¹³ ustalony poziom ostrze¿eñ!
+
+Transfer w tym miesi¹cu: __CALC_VOLUME_TOTAL__ MB (__CALC_PERCENT__ %)
+Maksymalny transfer w okresie: __MONTHLY_VOLUME__ MB
+
+Pocz¹tkowy dzieñ okresu: __STARTDAY__
+
+Bie¿¹ca data: __CURRENT_DATE__
+
+
usr/local/bin/qosctrl
usr/local/bin/rebuildhosts
usr/local/bin/redctrl
+usr/local/bin/monitorTraff
#usr/local/bin/restartapplejuice
usr/local/bin/restartsnort
usr/local/bin/restartssh
WARNING: translation string unused: calamaris report interval (in minutes)
WARNING: translation string unused: capsinactive
WARNING: translation string unused: cfg restart
+WARNING: translation string unused: check for net traffic update
WARNING: translation string unused: choose config
WARNING: translation string unused: clear cache
WARNING: translation string unused: compression
WARNING: translation string unused: calamaris report interval (in minutes)
WARNING: translation string unused: capsinactive
WARNING: translation string unused: cfg restart
+WARNING: translation string unused: check for net traffic update
WARNING: translation string unused: choose config
WARNING: translation string unused: choose media
WARNING: translation string unused: clear cache
END
+require "${General::swroot}/net-traffic/net-traffic-admin.pl";
+
+if($NETTRAFF::settings{'SHOW_AT_HOME'} eq 'on')
+{
+ my %calc = ();
+ $calc{'CALC_VOLUME_TOTAL'} = 0;
+ $calc{'CALC_VOLUME_IN'} = 0;
+ $calc{'CALC_VOLUME_OUT'} = 0;
+ $calc{'CALC_WEEK_TOTAL'} = 0;
+ $calc{'CALC_WEEK_IN'} = 0;
+ $calc{'CALC_WEEK_OUT'} = 0;
+ $calc{'CALC_LAST_RUN'} = 0;
+ $calc{'CALC_PERCENT'} = 0;
+
+ &General::readhash($NETTRAFF::logfile, \%calc);
+
+ my $calctime = &NETTRAFF::getFormatedDate($calc{'CALC_LAST_RUN'});
+
+ print <<END;
+ <hr /><br />
+
+ <table width='80%'>
+ <tr>
+ <td colspan='4' align='center' nowrap='nowrap' >$Lang::tr{'traffic monitor'} ($Lang::tr{'traffic calc time'} $calctime)</td>
+ </tr>
+ <tr>
+ <td align='center' nowrap='nowrap' > </td>
+ <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>
+ <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td>
+ <td align='center' nowrap='nowrap' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficsum'}</b></font></td>
+ </tr>
+ <tr>
+ <td align='center' nowrap='nowrap' >$Lang::tr{'this weeks volume'} (MB):</td>
+ <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_IN'}</td>
+ <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_OUT'}</td>
+ <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_WEEK_TOTAL'}</td>
+ </tr>
+ <tr>
+ <td align='center' nowrap='nowrap' >$Lang::tr{'this months volume'} (MB):</td>
+ <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_IN'}</td>
+ <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_OUT'}</td>
+ <td align='center' nowrap='nowrap' class='boldbase'>$calc{'CALC_VOLUME_TOTAL'}</td>
+ </tr>
+END
+
+ if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+ {
+print "<tr><td align='center'>max. $NETTRAFF::settings{'MONTHLY_VOLUME'} MB</td><td align='left' colspan='3' nowrap='nowrap'>";
+&NETTRAFF::traffPercentbar("$calc{'CALC_PERCENT'}%");
+print "</td><td align='left' nowrap='nowrap'> $calc{'CALC_PERCENT'}%</td></tr>";
+ }
+ print "</table>";
+}
+
&Header::closebox();
&Header::closebigbox();
#
# (c) The SmoothWall Team
#
+# $Id: traffic.cgi,v 1.19 2007/01/09 18:59:23 dotzball Exp $
+#
+# traffic.cgi, v1.1.0 2003/10/18
+# supports now:
+# * IPCop v1.3.0
+# * choosing year
+#
+# 18 June 2004 Achim Weber
+# - added functionality to work with IPCop 1.4.0
+# - use some functions from ipacsum
use strict;
require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
require "${General::swroot}/header.pl";
-require '/var/ipfire/net-traffic/net-traffic-lib.pl';
+require "${General::swroot}/net-traffic/net-traffic-admin.pl";
+require "${General::swroot}/net-traffic/net-traffic-lib.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);
-my %cgiparams;
+my @dummy = (@NETTRAFF::months, @NETTRAFF::longmonths, $NETTRAFF::colorOk, $NETTRAFF::colorWarn, $NETTRAFF::colorMax);
+undef(@dummy);
+
+my %cgiparams;
my %pppsettings;
my %netsettings;
&General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
-my ($s, $min, $h, $d, $m,$y) = localtime(time);
-$y+=1900;
-$m+=1;
-$m = $m < 10 ? $m = "0".$m : $m;
+my @now = localtime(time);
+
+$now[5] = $now[5]+1900;
+
+$cgiparams{'STARTYEAR'} = $now[5];
+$cgiparams{'STARTMONTH'} = $now[4];
+
+my $startDay = '1';
+my $endDay = '1';
+
+if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+{
+ $startDay = $NETTRAFF::settings{'STARTDAY'};
+ $endDay = $NETTRAFF::settings{'STARTDAY'};
+}
+
+# this periode started last month
+if ($now[3] < $startDay)
+{
+ # when current month is january we start in last year december
+ if ($now[4] == 0) {
+ $cgiparams{'STARTYEAR'} = $now[5]-1;
+ $cgiparams{'STARTMONTH'} = 11;
+ }
+ else
+ {
+ $cgiparams{'STARTYEAR'} = $now[5];
+ $cgiparams{'STARTMONTH'} = $now[4]-1;
+ }
+}
-$cgiparams{'MONTH'} = $m;
-&Header::getcgihash(\%cgiparams);
-$cgiparams{'YEAR'} = $y;
&Header::getcgihash(\%cgiparams);
-&Header::showhttpheaders();
+my $selectYearALL = "";
+$selectYearALL = 'selected=\'selected\'' if($cgiparams{'STARTYEAR'} eq '????');
-my %selectYear;
-$selectYear{'YEAR'}{'2007'} = '';
-$selectYear{'YEAR'}{'2008'} = '';
-$selectYear{'YEAR'}{'2009'} = '';
-$selectYear{'YEAR'}{'2010'} = '';
-$selectYear{'YEAR'}{'2011'} = '';
-$selectYear{'YEAR'}{'2012'} = '';
-$selectYear{'YEAR'}{'????'} = '';
-$selectYear{'YEAR'}{$cgiparams{'YEAR'}} = 'selected=\'selected\'';
-
-
-my %selected;
-
-$selected{'MONTH'}{'01'} = '';
-$selected{'MONTH'}{'02'} = '';
-$selected{'MONTH'}{'03'} = '';
-$selected{'MONTH'}{'04'} = '';
-$selected{'MONTH'}{'05'} = '';
-$selected{'MONTH'}{'06'} = '';
-$selected{'MONTH'}{'07'} = '';
-$selected{'MONTH'}{'08'} = '';
-$selected{'MONTH'}{'09'} = '';
-$selected{'MONTH'}{'10'} = '';
-$selected{'MONTH'}{'11'} = '';
-$selected{'MONTH'}{'12'} = '';
-$selected{'MONTH'}{'??'} = '';
-$selected{'MONTH'}{$cgiparams{'MONTH'}} = 'selected=\'selected\'';
+my $selectMonthALL = "";
+$selectMonthALL = 'selected=\'selected\'' if($cgiparams{'STARTMONTH'} eq '??');
+&Header::showhttpheaders();
&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
-
&Header::openbigbox('100%', 'left');
+&Header::openbox('100%', 'left', "");
-&Header::openbox('100%', 'left', $Lang::tr{'settings'});
+my $firstDayTxt = '';
+
+if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+{
+ $firstDayTxt = " ($Lang::tr{'monthly volume start day short'}: $NETTRAFF::settings{'STARTDAY'}.)";
+}
print <<END;
- <table width='80%' align='center'>
+ <table width='100%' align='center'>
<tr>
- <td width='95%' align='left' nowrap='nowrap'>
+ <td width='90%' align='left' nowrap='nowrap'>
<form method='post' action='/cgi-bin/traffic.cgi'>
- $Lang::tr{'selecttraffic'}
- <select name='MONTH'>
- <option $selected{'MONTH'}{'01'} value='01'>$Lang::tr{'january'}</option>
- <option $selected{'MONTH'}{'02'} value='02'>$Lang::tr{'february'}</option>
- <option $selected{'MONTH'}{'03'} value='03'>$Lang::tr{'march'}</option>
- <option $selected{'MONTH'}{'04'} value='04'>$Lang::tr{'april'}</option>
- <option $selected{'MONTH'}{'05'} value='05'>$Lang::tr{'may'}</option>
- <option $selected{'MONTH'}{'06'} value='06'>$Lang::tr{'june'}</option>
- <option $selected{'MONTH'}{'07'} value='07'>$Lang::tr{'july'}</option>
- <option $selected{'MONTH'}{'08'} value='08'>$Lang::tr{'august'}</option>
- <option $selected{'MONTH'}{'09'} value='09'>$Lang::tr{'september'}</option>
- <option $selected{'MONTH'}{'10'} value='10'>$Lang::tr{'october'}</option>
- <option $selected{'MONTH'}{'11'} value='11'>$Lang::tr{'november'}</option>
- <option $selected{'MONTH'}{'12'} value='12'>$Lang::tr{'december'}</option>
- <option $selected{'MONTH'}{'??'} value='??'>$Lang::tr{'allmsg'}</option>
+ $Lang::tr{'selecttraffic'}$firstDayTxt:
+ <select name='STARTMONTH'>
+END
+
+foreach my $month (@NETTRAFF::months)
+{
+ print "\t<option ";
+ if ("$month" eq "$cgiparams{'STARTMONTH'}") {
+ print 'selected=\'selected\' '; }
+ print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
+}
+
+print <<END;
+ <option $selectMonthALL value='??'>$Lang::tr{'allmsg'}</option>
</select>
- <select name='YEAR'>
- <option $selectYear{'YEAR'}{'2007'} value='2007'>2007</option>
- <option $selectYear{'YEAR'}{'2008'} value='2008'>2008</option>
- <option $selectYear{'YEAR'}{'2009'} value='2009'>2009</option>
- <option $selectYear{'YEAR'}{'2010'} value='2010'>2010</option>
- <option $selectYear{'YEAR'}{'2011'} value='2011'>2011</option>
- <option $selectYear{'YEAR'}{'2012'} value='2012'>2012</option>
- <option $selectYear{'YEAR'}{'????'} value='????'>$Lang::tr{'allmsg'}</option>
+ <select name='STARTYEAR'>
+END
+
+for (my $index=0; $index<=$#NETTRAFF::years; $index++) {
+ print "\t<option ";
+ if ("$NETTRAFF::years[$index]" eq "$cgiparams{'STARTYEAR'}") {
+ print 'selected=\'selected\' '; }
+ print "value='$NETTRAFF::years[$index]'>$NETTRAFF::years[$index]</option>\n";
+}
+
+print <<END;
+ <option $selectYearALL value='????'>$Lang::tr{'allmsg'}</option>
</select>
<input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
</form>
- </td>
+ </td>
+ <td width='5%' align='center'>
+ <form method='post' action='/cgi-bin/trafficadm.cgi'>
+ <input type='submit' name='ACTION' value='$Lang::tr{'net-traffic configuration'}' />
+ </form>
+ </td>
<td width='5%' align='center'>
<form method='post' action='/cgi-bin/traffics.cgi'>
<input type='submit' name='ACTION' value=' > ' />
</form>
- </td>
+ </td>
</tr>
</table>
END
&Header::closebox();
-&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
+&Header::openbox('100%', 'left', "$Lang::tr{'traffics'}");
my $dateWidth = '20%';
my $netWidth = '34%';
print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
}
-if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
- print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
- }
+if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
+ print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
+}
print <<END;
</tr>
</table>
<table width='100%'>
<tr>
<td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
- <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
- <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
+ <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficin'}</b></font></td>
+ <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficout'}</b></font></td>
END
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
-{
+{
print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
-}
+}
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
-{
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
-}
+{
+ print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficin'}</b></font></td>";
+ print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficout'}</b></font></td>";
+}
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
{
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>";
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>";
+print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>";
+print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td>";
}
- print"</tr>";
+print "</tr>";
my $total_blue_in=0;
my $total_blue_out=0;
my $total_red_out=0;
my $lines=0;
-my $displayMode = "daily";
-my $startMonth = $cgiparams{'MONTH'};
-my $endMonth = $cgiparams{'MONTH'};
-if ($cgiparams{'MONTH'} eq '??') {
+
+my $startYear = $cgiparams{'STARTYEAR'};
+my $endYear = $cgiparams{'STARTYEAR'};
+my $startMonth = $cgiparams{'STARTMONTH'};
+my $endMonth = $cgiparams{'STARTMONTH'};
+my $displayMode = "daily_multi";
+$startDay = '1';
+$endDay = '1';
+my $selectedMonth = '0';
+
+if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+{
+ $startDay = $NETTRAFF::settings{'STARTDAY'};
+ $endDay = $NETTRAFF::settings{'STARTDAY'};
+}
+
+# "show All ?
+if ($cgiparams{'STARTYEAR'} eq '????')
+{
+ # 'show all month' + 'show all years'
+ # OR <selected Month> + 'show all years'
+
+ # if we have a <selected Month>, we read all traffic but display only the selected month
+ if($cgiparams{'STARTMONTH'} ne '??')
+ {
+ $selectedMonth = $cgiparams{'STARTMONTH'} + 1;
+ $selectedMonth = $selectedMonth < 10 ? $selectedMonth = "0".$selectedMonth : $selectedMonth;
+ }
+
+ $displayMode = "monthly";
+ # start with 1970-01-01
+ $startYear = 1970;
+ $startMonth = '1';
+ $startDay = '1';
+ # end with next year: 20xx-01-01
+ $endYear = $now[5] + 1;
+ $endMonth = '1';
+ $endDay = '1';
+}
+elsif ($cgiparams{'STARTMONTH'} eq '??')
+{
+ # 'show all month' + 200x
$displayMode = "monthly";
- $startMonth = '01';
- $endMonth = '12';
+ # start with 200x-01-01
+ $startMonth = '1';
+ $startDay = '1';
+ # end with (200x+1)-01-01
+ $endYear = $startYear + 1;
+ $endMonth = '1';
+ $endDay = '1';
+}
+else
+{
+ # no "Show All"
+ $startMonth++;
+ $endMonth = $endMonth + 2;
+
+ # this periode started last month
+ if ($now[3] < $startDay)
+ {
+ # when current month is january we start in last year december
+ if ($endMonth == 1) {
+ $startYear--;
+ $startMonth = 12;
+ }
+ }
+ else
+ {
+ # when we are in december, this periode ends next year january
+ if ($startMonth == 12) {
+ $endYear++;
+ $endMonth = 1;
+ }
+ }
}
-my $start = "$cgiparams{'YEAR'}$startMonth"."01";
-my $end = "$cgiparams{'YEAR'}$endMonth"."32";
+
+
+$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
+$endMonth = $endMonth < 10 ? $endMonth = "0".$endMonth : $endMonth;
+$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
+$endDay = $endDay < 10 ? $endDay = "0".$endDay : $endDay;
+
+my $start = "$startYear$startMonth$startDay";
+my $end = "$endYear$endMonth$endDay";
+
my %allDaysBytes = ();
my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
-foreach (@allDays) {
+foreach (@allDays)
+{
+ # special code for: <selected Month> + 'show all years'
+ if($cgiparams{'STARTMONTH'} ne '??' && $cgiparams{'STARTYEAR'} eq '????')
+ {
+ # show only those traffic in the selected month
+ if($allDaysBytes{$_}{'Day'} !~ /^\d\d\d\d-$selectedMonth$/)
+ {
+ next;
+ }
+ }
+
$total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
$total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
{
$total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
$total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
}
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
{
$total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
$total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
}
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
- {
+ {
$total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
$total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
- }
-
+ }
+
if ($lines % 2) {
print "<tr bgcolor='$color{'color20'}'>"; }
else {
- print "<tr bgcolor='$color{'color22'}'>"; }
-
+ print "<tr bgcolor='$color{'color22'}}'>"; }
+
printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576);
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
- {
+ {
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576);
- }
+ }
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
- {
+ {
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576);
- }
- if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
+ }
+
+ if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
{
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576);
- }
+ }
+
$lines++;
}
$total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
$total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
$total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
-$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
+$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
$total_red_in=sprintf("%.2f", ($total_red_in/1048576));
$total_red_out=sprintf("%.2f", ($total_red_out/1048576));
-
+
if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; }
else {print "<tr bgcolor='$color{'color22'}'>"; }
-
+
print <<END;
<td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
END
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
-{
+{
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
}
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
-{
+{
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
}
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
{
- print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
- print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
-}
-print <<END;
- </tr>
- </table>
+print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
+print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
+}
+print "</tr></table>";
+
+if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+{
+ my $total_red_all = sprintf("%.2f", ($total_red_in + $total_red_out));
+
+ my $color = $NETTRAFF::colorOk;
+
+ my $warnTraff = ($NETTRAFF::settings{'MONTHLY_VOLUME'} * $NETTRAFF::settings{'WARN'} / 100);
+ if($NETTRAFF::settings{'WARN_ON'} eq 'on'
+ && $warnTraff < $total_red_all)
+ {
+ $color = $NETTRAFF::colorWarn;
+ }
+ if($NETTRAFF::settings{'MONTHLY_VOLUME'} < $total_red_all)
+ {
+ $color = $NETTRAFF::colorMax;
+ }
+
+ print <<END;
+ <table width='100%'>
+ <tr><td align='center' class='boldbase' nowrap='nowrap' ><b>$Lang::tr{'monthly volume'} ($NETTRAFF::settings{'MONTHLY_VOLUME'} MB)</b></td></tr>
+ <tr><td align='center' class='boldbase' nowrap='nowrap' bgcolor='$color'><b>$total_red_all MB</b></td></tr>
+ </table>
END
+}
&Header::closebox();
-
&Header::closebigbox();
-
&Header::closepage();
--- /dev/null
+#!/usr/bin/perl
+#
+# This code is distributed under the terms of the GPL
+#
+# Copyright (c) 2005 Achim Weber
+#
+# $Id: trafficadm.cgi,v 1.21 2006/12/31 14:33:18 dotzball Exp $
+#
+
+use strict;
+
+# 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";
+require "${General::swroot}/net-traffic/net-traffic-admin.pl";
+
+my %cgiparams;
+my $errormessage = '';
+my $infomessage = '';
+my $saveerror = 0;
+my @days = ( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 );
+my @warnLevels = ( 50,60,70,80,90,100 );
+
+my @dummy = ($NETTRAFF::settingsfile, ${Header::colourred});
+undef(@dummy);
+
+&Header::showhttpheaders();
+
+# Init parameters
+$cgiparams{'MONTHLY_VOLUME_ON'} = 'off';
+$cgiparams{'MONTHLY_VOLUME'} = '';
+$cgiparams{'STARTDAY'} = '1';
+$cgiparams{'WARN_ON'} = 'off';
+$cgiparams{'WARN'} = '80';
+$cgiparams{'CALC_INTERVAL'} = '60';
+$cgiparams{'SHOW_AT_HOME'} = 'off';
+$cgiparams{'SEND_EMAIL_ON'} = 'off';
+$cgiparams{'EMAIL_TO'} = '';
+$cgiparams{'EMAIL_FROM'} = '';
+$cgiparams{'EMAIL_USR'} = '';
+$cgiparams{'EMAIL_PW'} = '';
+$cgiparams{'EMAIL_SERVER'} = '';
+$cgiparams{'VERSION_CHECK_ON'} = 'off';
+
+
+&Header::getcgihash(\%cgiparams);
+
+if ($cgiparams{'ACTION'} eq $Lang::tr{'save'})
+{
+ &validSave();
+
+ if ($errormessage) {
+ $saveerror = 1;
+ }
+ else { # no error, all right, save new settings
+ &General::writehash($NETTRAFF::settingsfile, \%cgiparams);
+ # calculate traffic
+ `/usr/local/bin/monitorTraff --force < /dev/null > /dev/null 2>&1 &`;
+ }
+} # end if ($cgiparams{'ACTION'} eq $Lang::tr{'save'})
+
+
+# if user want to save settings and get a errormessage, we don´t
+# overwrite users input
+unless ($saveerror) {
+
+ &NETTRAFF::readSettings();
+
+ $cgiparams{'MONTHLY_VOLUME_ON'} = $NETTRAFF::settings{'MONTHLY_VOLUME_ON'};
+ $cgiparams{'MONTHLY_VOLUME'} = $NETTRAFF::settings{'MONTHLY_VOLUME'};
+ $cgiparams{'STARTDAY'} = $NETTRAFF::settings{'STARTDAY'};
+ $cgiparams{'WARN_ON'} = $NETTRAFF::settings{'WARN_ON'};
+ $cgiparams{'WARN'} = $NETTRAFF::settings{'WARN'};
+ $cgiparams{'CALC_INTERVAL'} = $NETTRAFF::settings{'CALC_INTERVAL'};
+ $cgiparams{'SHOW_AT_HOME'} = $NETTRAFF::settings{'SHOW_AT_HOME'};
+ $cgiparams{'SEND_EMAIL_ON'} = $NETTRAFF::settings{'SEND_EMAIL_ON'};
+ $cgiparams{'EMAIL_TO'} = $NETTRAFF::settings{'EMAIL_TO'};
+ $cgiparams{'EMAIL_FROM'} = $NETTRAFF::settings{'EMAIL_FROM'};
+ $cgiparams{'EMAIL_USR'} = $NETTRAFF::settings{'EMAIL_USR'};
+ $cgiparams{'EMAIL_PW'} = $NETTRAFF::settings{'EMAIL_PW'};
+ $cgiparams{'EMAIL_SERVER'} = $NETTRAFF::settings{'EMAIL_SERVER'};
+ $cgiparams{'VERSION_CHECK_ON'} = $NETTRAFF::settings{'VERSION_CHECK_ON'};
+
+} # end unless ($saveerror)
+
+
+if ($cgiparams{'ACTION'} eq $Lang::tr{'send test mail'})
+{
+ # send test email
+ my $return = `/usr/local/bin/monitorTraff --testEmail`;
+
+ if($return =~ /Email was sent successfully!/)
+ {
+ $infomessage = "$Lang::tr{'test email was sent'}<br/>";
+ }
+ else
+ {
+ $errormessage = "$Lang::tr{'test email could not be sent'}:<br/>";
+ $errormessage .= "$return <br />";
+ }
+
+
+} # end if ($cgiparams{'ACTION'} eq $Lang::tr{'send test mail'})
+
+
+
+my %selected;
+$selected{'CALC_INTERVAL'}{'5'} = '';
+$selected{'CALC_INTERVAL'}{'10'} = '';
+$selected{'CALC_INTERVAL'}{'15'} = '';
+$selected{'CALC_INTERVAL'}{'30'} = '';
+$selected{'CALC_INTERVAL'}{'60'} = '';
+$selected{'CALC_INTERVAL'}{$cgiparams{'CALC_INTERVAL'}} = "selected='selected'";
+
+my %checked;
+$checked{'MONTHLY_VOLUME_ON'}{'off'} = '';
+$checked{'MONTHLY_VOLUME_ON'}{'on'} = '';
+$checked{'MONTHLY_VOLUME_ON'}{$cgiparams{'MONTHLY_VOLUME_ON'}} = "checked='checked'";
+
+$checked{'WARN_ON'}{'off'} = '';
+$checked{'WARN_ON'}{'on'} = '';
+$checked{'WARN_ON'}{$cgiparams{'WARN_ON'}} = "checked='checked'";
+
+$checked{'SHOW_AT_HOME'}{'off'} = '';
+$checked{'SHOW_AT_HOME'}{'on'} = '';
+$checked{'SHOW_AT_HOME'}{$cgiparams{'SHOW_AT_HOME'}} = "checked='checked'" ;
+
+$checked{'SEND_EMAIL_ON'}{'off'} = '';
+$checked{'SEND_EMAIL_ON'}{'on'} = '';
+$checked{'SEND_EMAIL_ON'}{$cgiparams{'SEND_EMAIL_ON'}} = "checked='checked'" ;
+
+$checked{'VERSION_CHECK_ON'}{'off'} = '';
+$checked{'VERSION_CHECK_ON'}{'on'} = '';
+$checked{'VERSION_CHECK_ON'}{$cgiparams{'VERSION_CHECK_ON'}} = "checked='checked'" ;
+
+
+my $btnTestmailDisabled = "";
+$btnTestmailDisabled = "disabled='disabled'" if($cgiparams{'SEND_EMAIL_ON'} ne 'on');
+
+&Header::openpage($Lang::tr{'traffic monitor'}, 1, '');
+&Header::openbigbox('100%', 'left');
+
+if ($errormessage) {
+ &Header::openbox('100%', 'left', $Lang::tr{'error messages'});
+ print "<class name='base'><font color='${Header::colourred}'>$errormessage\n</font>";
+ print " </class>\n";
+ &Header::closebox();
+}
+
+if($infomessage) {
+ &Header::openbox('100%', 'left', "$Lang::tr{'traffic info messages'}:");
+ print "<class name='base'>$infomessage\n";
+ print " </class>\n";
+ &Header::closebox();
+}
+
+&Header::openbox('100%', 'left', "$Lang::tr{'net-traffic configuration'}:");
+
+print <<END;
+ <form method='post' action='$ENV{'SCRIPT_NAME'}'>
+ <table width='100%'>
+ <tr>
+ <td align='left' class='base' width='1%'>
+ <input type="checkbox" name="SHOW_AT_HOME" $checked{'SHOW_AT_HOME'}{'on'} />
+ </td>
+ <td align='left' class='base' nowrap='nowrap' colspan="3">
+ $Lang::tr{'display traffic at home'}
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base'>
+ <input type="checkbox" name="MONTHLY_VOLUME_ON" $checked{'MONTHLY_VOLUME_ON'}{'on'} />
+ </td>
+ <td align='left' class='base' nowrap='nowrap' colspan="2">
+ $Lang::tr{'monthly volume'} (MByte):
+ </td>
+ <td align='left' class='base' >
+ <input type='text' name='MONTHLY_VOLUME' value='$cgiparams{'MONTHLY_VOLUME'}' size='20' maxlength='17' />
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"></td>
+ <td align='left' class='base' nowrap='nowrap' >
+ $Lang::tr{'monthly volume start day'}:
+ </td>
+ <td align='left' class='base' >
+ <select name='STARTDAY'>
+END
+
+foreach my $day (@days)
+{
+ print " <option ";
+ if ($day == $cgiparams{'STARTDAY'}) {
+ print 'selected=\'selected\' '; }
+ print "value='$day'>$day</option>\n";
+}
+print <<END;
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' width='1%'></td>
+ <td align='left' class='base' width='1%'>
+ <input type="checkbox" name="WARN_ON" $checked{'WARN_ON'}{'on'} />
+ </td>
+ <td align='left' class='base' width='20%' nowrap='nowrap'>
+ $Lang::tr{'warn when traffic reaches'}:
+ </td>
+ <td align='left' class='base' width='78%'>
+ <select name='WARN'>
+END
+
+foreach my $level (@warnLevels)
+{
+ print " <option ";
+ if ($level == $cgiparams{'WARN'}) {
+ print 'selected=\'selected\' '; }
+ print "value='$level'>$level</option>\n";
+}
+print <<END;
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"></td>
+ <td align='left' class='base' nowrap='nowrap' >
+ $Lang::tr{'calc traffic all x minutes'}:
+ </td>
+ <td align='left' class='base' >
+ <select name='CALC_INTERVAL'>
+ <option value='5' $selected{'CALC_INTERVAL'}{'5'} > 5</option>
+ <option value='10' $selected{'CALC_INTERVAL'}{'10'}>10</option>
+ <option value='15' $selected{'CALC_INTERVAL'}{'15'}>15</option>
+ <option value='30' $selected{'CALC_INTERVAL'}{'30'}>30</option>
+ <option value='60' $selected{'CALC_INTERVAL'}{'60'}>60</option>
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base'> </td>
+ <td align='left' class='base'>
+ <input type="checkbox" name="SEND_EMAIL_ON" $checked{'SEND_EMAIL_ON'}{'on'} />
+ </td>
+ <td align='left' class='base' colspan="2" nowrap='nowrap' >
+ $Lang::tr{'send email notification'}:
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"> </td>
+ <td align='left' class='base' nowrap='nowrap'>
+ $Lang::tr{'to email adr'}:
+ </td>
+ <td align='left' class='base' >
+ <input type='text' name='EMAIL_TO' value='$cgiparams{'EMAIL_TO'}' size='25' />
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"> </td>
+ <td align='left' class='base' nowrap='nowrap'>
+ $Lang::tr{'from email adr'}:
+ </td>
+ <td align='left' class='base' >
+ <input type='text' name='EMAIL_FROM' value='$cgiparams{'EMAIL_FROM'}' size='25' />
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"> </td>
+ <td align='left' class='base' nowrap='nowrap'>
+ $Lang::tr{'from email user'}:
+ </td>
+ <td align='left' class='base' >
+ <input type='text' name='EMAIL_USR' value='$cgiparams{'EMAIL_USR'}' size='25' />
+ <img src='/blob.gif' alt='*' />
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"> </td>
+ <td align='left' class='base' nowrap='nowrap'>
+ $Lang::tr{'from email pw'}:
+ </td>
+ <td align='left' class='base' >
+ <input type='password' name='EMAIL_PW' value='$cgiparams{'EMAIL_PW'}' size='25' />
+ <img src='/blob.gif' alt='*' />
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"> </td>
+ <td align='left' class='base' nowrap='nowrap'>
+ $Lang::tr{'from email server'}:
+ </td>
+ <td align='left' class='base' >
+ <input type='text' name='EMAIL_SERVER' value='$cgiparams{'EMAIL_SERVER'}' size='25' />
+ </td>
+ </tr>
+ <tr>
+ <td align='left' class='base' colspan="2"> </td>
+ <td align='left' class='base' colspan="2">
+ <input type='submit' name='ACTION' value='$Lang::tr{'send test mail'}' $btnTestmailDisabled />
+ </td>
+ </tr>
+ </table>
+ <hr />
+ <table width='100%'>
+ <tr>
+ <td align='left' class='base' nowrap='nowrap' width='2%'>
+ <img src='/blob.gif' alt ='*' align='top' />
+ <font class='base'>$Lang::tr{'this field may be blank'}</font>
+ </td>
+ <td align='center' class='base' width='48%'>
+ <input type='submit' name='ACTION' value='$Lang::tr{'save'}' />
+END
+
+ # if user input cause an error
+ # and user want a reset, we re-read settings from settingsfile
+ if ($errormessage ne '') {
+ print "<input type='submit' name='ACTION' value='$Lang::tr{'reset'}' />";
+ }
+ else {
+ print "<input type='reset' name='ACTION' value='$Lang::tr{'reset'}' />";
+ }
+
+print <<END;
+ </td>
+ <td align='left' class='base' nowrap='nowrap' width='50%'> </td>
+ </tr>
+ </table>
+ </form>
+ <hr />
+ <table width='100%'>
+ <tr>
+ <td align='left' class='base' width='2%'>
+
+ </td>
+ <td align='left' class='base' width='98%'>
+ <form method='post' action='/cgi-bin/traffic.cgi'>
+ <input type='submit' name='ACTION' value='$Lang::tr{'traffic back'}' />
+ </form>
+ </td>
+ </tr>
+ </table>
+END
+
+&Header::closebox();
+&Header::closebigbox();
+&Header::closepage();
+
+
+sub validSave
+{
+ if ($cgiparams{'SHOW_AT_HOME'} ne 'on' ) {
+ $cgiparams{'SHOW_AT_HOME'} = 'off';
+ }
+
+ if ($cgiparams{'MONTHLY_VOLUME_ON'} ne 'on' ) {
+ $cgiparams{'MONTHLY_VOLUME_ON'} = 'off';
+ }
+
+ if($cgiparams{'MONTHLY_VOLUME_ON'} eq 'on')
+ {
+ if($cgiparams{'MONTHLY_VOLUME'} !~ /^\d+$/ || $cgiparams{'MONTHLY_VOLUME'} < 1) {
+ $errormessage .= "$Lang::tr{'monthly traffic bad'}<br/>";
+ }
+
+ if($cgiparams{'STARTDAY'} < 1 || 31 < $cgiparams{'STARTDAY'}) {
+ $errormessage .= "$Lang::tr{'monthly start day bad'}<br/>";
+ }
+
+ if ($cgiparams{'WARN_ON'} ne 'on' ) {
+ $cgiparams{'WARN_ON'} = 'off';
+ }
+
+ if($cgiparams{'WARN_ON'} eq 'on' && $cgiparams{'WARN'} !~ /^\d+$/) {
+ $errormessage .= "$Lang::tr{'traffic warn level bad'}<br/>";
+ }
+
+ if($cgiparams{'CALC_INTERVAL'} < 5 || 60 < $cgiparams{'CALC_INTERVAL'}) {
+ $errormessage .= "$Lang::tr{'traffic calc time bad'}<br/>";
+ }
+
+ if ($cgiparams{'SEND_EMAIL_ON'} ne 'on' ) {
+ $cgiparams{'SEND_EMAIL_ON'} = 'off';
+ }
+
+ if($cgiparams{'SEND_EMAIL_ON'} eq 'on' )
+ {
+ if($cgiparams{'EMAIL_TO'} eq '' || (! &General::validemail($cgiparams{'EMAIL_TO'})) ) {
+ $errormessage .= "$Lang::tr{'to warn email bad'}<br/>";
+ }
+
+ if($cgiparams{'EMAIL_FROM'} eq '' || (! &General::validemail($cgiparams{'EMAIL_FROM'}))) {
+ $errormessage .= "$Lang::tr{'from warn email bad'}<br/>";
+ }
+
+ if($cgiparams{'EMAIL_SERVER'} eq '') {
+ $errormessage .= "$Lang::tr{'email server can not be empty'}<br/>";
+ }
+ }
+ } # monthly volumne == on
+
+ if ($cgiparams{'VERSION_CHECK_ON'} ne 'on' ) {
+ $cgiparams{'VERSION_CHECK_ON'} = 'off';
+ }
+}
#
# (c) The SmoothWall Team
#
+# $Id: traffics.cgi,v 1.12 2006/11/15 21:14:02 dotzball Exp $
+#
+# traffics.cgi, v1.1.0 2003/10/18
+# supports now:
+# * IPCop v1.3.0
+# * choosing year
use strict;
require '/var/ipfire/general-functions.pl';
require "${General::swroot}/lang.pl";
require "${General::swroot}/header.pl";
-require '/var/ipfire/net-traffic/net-traffic-lib.pl';
+require "${General::swroot}/net-traffic/net-traffic-admin.pl";
+require "${General::swroot}/net-traffic/net-traffic-lib.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);
-my %cgiparams;
+my %cgiparams;
my %netsettings;
&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
-my @years=("2007","2008","2009","2010","2011","2012","2013","2014","2015");
-
-my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'},
- $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'},
- $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'},
- $Lang::tr{'december'} );
-
-my @months = ( 0,1,2,3,4,5,6,7,8,9,10,11 );
my @days = ( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 );
-my @now = localtime(time);
+my @now = localtime(time);
$now[5] = $now[5]+1900;
-$cgiparams{'STARTDAY'} = 10;
-$cgiparams{'STOPDAY'} = 11;
-$cgiparams{'STARTYEAR'} = $now[5];
-$cgiparams{'STOPYEAR'} = $now[5];
+$cgiparams{'STARTDAY'} = 10;
+$cgiparams{'STOPDAY'} = 11;
+$cgiparams{'STARTYEAR'} = $now[5];
+$cgiparams{'STOPYEAR'} = $now[5];
+
+if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on')
+{
+ $cgiparams{'STARTDAY'} = $NETTRAFF::settings{'STARTDAY'};
+ $cgiparams{'STOPDAY'} = $NETTRAFF::settings{'STARTDAY'};
+}
# this periode started last month
-if ($now[3] < 10) {
+if ($now[3] < $cgiparams{'STARTDAY'}) {
$cgiparams{'STARTMONTH'} = $now[4]-1;
$cgiparams{'STOPMONTH'} = $now[4];
# when current month is january we start in last year december
- if ($now[4] == 0) {
+ if ($cgiparams{'STOPMONTH'} == 0) {
$cgiparams{'STARTYEAR'} = $now[5]-1;
- $cgiparams{'STARTMONTH'} = 11;
+ $cgiparams{'STARTMONTH'} = 11;
}
}
else {
$cgiparams{'STARTMONTH'} = $now[4];
$cgiparams{'STOPMONTH'} = $now[4]+1;
- # when we are december, this periode ends next year january
- if ($now[4] == 11) {
- $cgiparams{'STOPYEAR'} = $now[5]+1;
+ # when we are in december, this periode ends next year january
+ if ($cgiparams{'STARTMONTH'} == 11) {
+ $cgiparams{'STOPYEAR'} = $now[5]+1;
$cgiparams{'STOPMONTH'} = 0;
}
}
-
-&Header::getcgihash(\%cgiparams);
+&Header::getcgihash(\%cgiparams);
&Header::showhttpheaders();
-
&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
-
&Header::openbigbox('100%', 'left');
-
-&Header::openbox('100%', 'left', $Lang::tr{'settings'});
+&Header::openbox('100%', 'left', "");
print <<END;
<table width='100%' align='center'>
<tr>
- <td width='95%' class='base' align='center'>
+ <td width='90%' class='base' align='center'>
<form method='post' action='/cgi-bin/traffics.cgi'>
$Lang::tr{'trafficfrom'}
<select name='STARTDAY'>
END
-foreach (@days)
+foreach my $day (@days)
{
print "\t<option ";
- if ($_ == $cgiparams{'STARTDAY'}) {
+ if ($day == $cgiparams{'STARTDAY'}) {
print 'selected=\'selected\' '; }
- print "value='$_'>$_</option>\n";
+ print "value='$day'>$day</option>\n";
}
print <<END;
</select>
<select name='STARTMONTH'>
END
-foreach (@months)
+foreach my $month (@NETTRAFF::months)
{
print "\t<option ";
- if ($_ == $cgiparams{'STARTMONTH'}) {
+ if ($month == $cgiparams{'STARTMONTH'}) {
print 'selected=\'selected\' '; }
- print "value='$_'>$longmonths[$_]</option>\n";
+ print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
}
print <<END;
<select name='STARTYEAR'>
END
-for (my $index=0; $index<=$#years; $index++) {
+foreach my $year (@NETTRAFF::years) {
print "\t<option ";
- if ($years[$index] == $cgiparams{'STARTYEAR'}) {
+ if ($year == $cgiparams{'STARTYEAR'}) {
print 'selected=\'selected\' '; }
- print "value='$years[$index]'>$years[$index]</option>\n";
+ print "value='$year'>$year</option>\n";
}
print <<END;
<select name='STOPDAY'>
END
-foreach (@days)
+foreach my $day (@days)
{
print "\t<option ";
- if ($_ == $cgiparams{'STOPDAY'})
+ if ($day == $cgiparams{'STOPDAY'})
{
print 'selected=\'selected\' '; }
- print "value='$_'>$_</option>\n";
+ print "value='$day'>$day</option>\n";
}
print <<END;
<select name='STOPMONTH'>
END
-foreach (@months)
+foreach my $month (@NETTRAFF::months)
{
print "\t<option ";
- if ($_ == $cgiparams{'STOPMONTH'}) {
+ if ($month == $cgiparams{'STOPMONTH'}) {
print 'selected=\'selected\' '; }
- print "value='$_'>$longmonths[$_]</option>\n";
+ print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
}
print <<END;
<select name='STOPYEAR'>
END
-for (my $index = 0; $index <=$#years; $index++) {
+foreach my $year (@NETTRAFF::years) {
print "\t<option ";
- if ($years[$index] == $cgiparams{'STOPYEAR'}) {
+ if ($year == $cgiparams{'STOPYEAR'}) {
print 'selected=\'selected\' '; }
- print "value='$years[$index]'>$years[$index]</option>\n";
+ print "value='$year'>$year</option>\n";
}
print <<END;
</select>
<input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
- </form>
- </td>
+ </form>
+ </td>
<td width='5%' align='center'>
<form method='post' action='/cgi-bin/traffic.cgi'>
<input type='submit' name='ACTION' value=' > ' />
</form>
- </td>
+ </td>
</tr>
</table>
END
&Header::closebox();
-&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
+&Header::openbox('100%', 'left', "$Lang::tr{'traffics'}");
my $dateWidth = '20%';
my $netWidth = '34%';
print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
}
-if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
- print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
- }
-
+if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
+{
+print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
+}
print <<END;
- <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
</tr>
</table>
<table width='100%'>
<tr>
<td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
- <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
- <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
+ <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficin'}</b></font></td>
+ <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficout'}</b></font></td>
END
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
-{
+{
print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
-}
+}
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
-{
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
-}
+{
+ print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficin'}</b></font></td>";
+ print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficout'}</b></font></td>";
+}
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
-{
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>";
- print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>";
+{
+print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>";
+print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td>";
}
- print"</tr>";
+print "</tr>";
my $total_blue_in=0;
my $total_blue_out=0;
foreach (@allDays) {
$total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
$total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
{
$total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
$total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
}
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
{
$total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
$total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
}
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
{
$total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
$total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
}
-
+
if ($lines % 2) {
print "<tr bgcolor='$color{'color20'}'>"; }
else {
print "<tr bgcolor='$color{'color22'}'>"; }
-
+
printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576);
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
- {
+ {
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576);
- }
+ }
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
- {
+ {
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576);
- }
- if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
+ }
+ if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
{
printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576);
printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576);
- }
+ }
$lines++;
}
$total_blue_in=sprintf("%.2f", ($total_blue_in/1048576));
$total_blue_out=sprintf("%.2f", ($total_blue_out/1048576));
$total_orange_in=sprintf("%.2f", ($total_orange_in/1048576));
-$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
+$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576));
$total_red_in=sprintf("%.2f", ($total_red_in/1048576));
$total_red_out=sprintf("%.2f", ($total_red_out/1048576));
-
-if ($lines % 2) {print "<tr bgcolor='$color{'color20'}'>"; }
+
+if ($lines % 2) {print "<tr bgcolor='$color{'color22'}'>"; }
else {print "<tr bgcolor='$color{'color22'}'>"; }
-
+
print <<END;
<td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
END
-
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
-{
+{
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
}
if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
-{
+{
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
}
+
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
{
- print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
- print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
-}
-print <<END;
- </tr>
- </table>
-END
+print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
+print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
+}
+print "</tr></table>";
&Header::closebox();
-
&Header::closebigbox();
-
&Header::closepage();
'calamaris unlimited' => 'unbegrenzt',
'calamaris view' => 'Anzeigen',
'calamaris view report' => 'Bericht anzeigen',
+'calc traffic all x minutes' => 'Berechne den Traffic alle x Minuten',
'cancel' => 'Abbrechen',
'cancel-adv-options' => 'Abbrechen',
'cannot enable both nat traversal and compression' => 'NAT Traversal und Kompression können nicht gleichzeitig aktiviert sein.',
'chain' => 'Verknüpfung',
'change passwords' => 'Passwörter ändern',
'change share' => 'Freigabeeinstellungen ändern',
+'check for net traffic update' => 'Prüfe auf Net-Traffic Updates',
'check vpn lr' => 'Überprüfen',
'choose config' => 'Konfiguration auswaehlen',
'cipher' => 'Verschlüsselung',
'disk usage' => 'Festplattenbelegung:',
'display' => 'Anzeige',
'display hostname in window title' => 'Hostname im Fenstertitel anzeigen',
+'display traffic at home' => 'Berechneten Traffic auf der Startseite anzeigen',
'display webinterface effects' => 'Überblendeffekte einschalten',
'dl client arch' => 'Client Paket herunterladen (zip)',
'dmz' => 'DMZ',
'edit share' => 'Freigabe bearbeiten',
'editor' => 'Editor',
'eg' => 'z.B.:',
+'email server can not be empty' => 'Email Server darf nicht leer sein',
'emailreportlevel' => 'Email Reportlevel',
'empty' => 'Dieses Feld kann leer bleiben',
'empty profile' => 'Unbenannt',
'fritzdsl help' => 'Um eines der folgenden Fritz!DSL Modems (Fritz!Card DSL=fcdsl / Fritz!CardDSL SL=fcdslsl / Fritz!Card DSL V2.0=fcdsl2 / Fritz!Card DSL USB=fcdslusb / Fritz!Card DSL USB SL=fcdslslusb) nutzen zu können, müssen Sie ein Paket auf Ihre IPFire-Box laden. Bitte laden Sie den tarball entsprechend Ihrer Version von der IPFire-Webseite herunter und laden Sie dann die gesamte <b>fcdsl-(ihre_version).tgz</b> mit dem folgenden Formular hoch.',
'fritzdsl upload' => 'Fritz!DSL-Treiber hochladen',
'from' => 'Von',
+'from email adr' => 'Von Email Adresse',
+'from email pw' => 'Von Email Passwort',
+'from email server' => 'Von Email Server',
+'from email user' => 'Von Email Benutzer',
+'from warn email bad' => 'Von Email Adresse ist nicht gültig',
'gateway' => 'Gateway',
'gateway ip' => 'Gateway-IP',
'gen static key' => 'Statischen Schlüssel erzeugen',
'monday' => 'Montag',
'month' => 'Monat',
'monthly firewallhits' => 'monatliche Firewalltreffer',
+'monthly start day bad' => 'Monatlicher Starttag ist nicht gültig',
+'monthly traffic bad' => 'Monatliches Volumen ist nicht gültig',
+'monthly volume' => 'Monatliches Volumen',
+'monthly volume start day' => 'Erster Tag der Monatlichen Abrechnungsperiode',
+'monthly volume start day short' => 'Erste Tag',
'months' => 'Monate',
'more' => 'weitere',
'mount' => 'Einbinden',
'net config type' => 'Netzwerk-Konfigurations-Typ',
'net config type help' => 'GREEN ist das lokale Netzwerk, RED ist das Internet, BLUE ist WLAN, ORANGE ist die DMZ.',
'net to net vpn' => 'Netz-zu-Netz Virtual Private Network',
+'net traffic newversion' => 'Es ist eine neue Net-Traffic Version verfügbar:',
+'net-traffic configuration' => 'Net-Traffic Konfiguration',
'netbios name' => 'Netbios Name',
'netmask' => 'Netzwerkmaske',
'network' => 'Netzwerk',
'select source net' => 'Auswahl Quell-Netz',
'selecttraffic' => 'Trafficübersicht auswählen:',
'send cr' => 'ISP verlangt Zeilenrücklaufzeichen:',
+'send email notification' => 'Aktiviert, Email Benachrichtigung senden',
+'send test mail' => 'Sende Testemail',
'september' => 'September',
'serial' => 'serielle',
'server reserved' => 'The connection name server is reserved and not allowed',
'stop ovpn server' => 'Stoppe OpenVPN Server',
'stopped' => 'ANGEHALTEN',
'subject' => 'Betreff',
+'subject test' => 'Testemail',
+'subject warn' => 'Warnung - Warnlevel erreicht',
'subnet' => 'Subnet',
'subnet is invalid' => 'Netzmaske ist ungültig',
'subscripted user rules' => 'Sourcefire VRT Regeln mit Abonnement',
'system status information' => 'System-Statusinformationen',
'telephone not set' => 'Telefonnummer nicht angegeben.',
'test' => 'test',
+'test email could not be sent' => 'Könnte Testemail nicht senden',
+'test email was sent' => 'Testemail wurde erfolgreich versand',
'the following update was successfully installed' => 'Das folgende Update wurde erfolgreich installiert',
'the statistics were last updated at' => 'Die Statistik wurde zuletzt aktualisiert am',
'theme' => 'Style',
'this field may be blank' => 'Dieses Feld kann leer bleiben.',
'this is not a valid archive' => 'Dies ist kein gültiges Archiv.',
'this is not an authorised update' => 'Dies ist kein autorisiertes Update.',
+'this months volume' => 'Diesen Monat',
'this update is already installed' => 'Dieses Update wurde bereits installiert.',
+'this weeks volume' => 'Diese Woche',
'thursday' => 'Donnerstag',
'time' => 'Uhrzeit',
'time date manually reset' => 'Datum/Zeit wurden manuell zurückgesetzt.',
'timeout must be a number' => 'Wartezeit muss eine Zahl sein.',
'title' => 'Titel',
'to' => 'Bis',
+'to email adr' => 'An Email Adresse',
'to install an update' => 'Um ein Update zu installieren, laden Sie zuerst die folgende .tgz.gpg Datei hoch:',
+'to warn email bad' => 'An Email Adresse ist nicht gültig',
'toggle enable disable' => 'Aktivieren oder Deaktivieren',
'tone' => 'Ton',
'tone dial' => 'Tonwahl:',
'too long 80 char max' => ' ist zu lang, es sind maximal 80 Zeichen erlaubt',
'total hits for log section' => 'Gesamte Treffer für Log Sektion',
+'traffic back' => 'Zurück',
+'traffic calc time' => 'Berechnungszeitpunkt',
+'traffic calc time bad' => 'Berechnungsintervall ist nicht gültig',
+'traffic info messages' => 'Info',
+'traffic monitor' => 'Traffic Monitor',
'traffic on' => 'Verkehr auf',
'traffic shaping' => 'Traffic Shaping',
'traffic shaping settings' => 'Einstellungen der Datenflußkontrolle',
+'traffic warn level bad' => 'Warnlevel ist nicht gültig',
'trafficblue' => 'WLAN',
'trafficdate' => 'Datum',
'trafficfrom' => 'Von',
'vpn vhost' => 'Roadwarrior virtuelle IP (manchmal auch Inner-IP genannt)',
'vpn watch' => 'Netz-zu-Netz VPN neu starten, wenn sich Remote-IP ändert (DynDNS). Dies hilft DPD (Dead Peer Detection)',
'waiting to synchronize clock' => 'Bitte warten, die Uhr wird synchronisiert',
+'warn when traffic reaches' => 'Warnen wenn Traffic x % erreicht',
'warning messages' => 'Warnhinweise',
'web hits' => 'Gesamtanzahl der Websites zum ausgewählten Kriterium',
'web proxy' => 'Web-Proxy',
'calamaris unlimited' => 'unlimited',
'calamaris view' => 'View',
'calamaris view report' => 'View report',
+'calc traffic all x minutes' => 'Calculate traffic all x minutes',
'cancel' => 'Cancel',
'cancel-adv-options' => 'Cancel',
'cannot enable both nat traversal and compression' => 'Cannot enable both NAT Traversal and Compression.',
'chain' => 'Chain',
'change passwords' => 'Change passwords',
'change share' => 'edit share options',
+'check for net traffic update' => 'Check for Net-Traffic updates',
'check vpn lr' => 'Check',
'choose config' => 'Choose Config',
'choose media' => 'Choose media',
'disk usage' => 'Disk usage:',
'display' => 'Display',
'display hostname in window title' => 'Display hostname in window title',
+'display traffic at home' => 'Display calculated traffic on startpage',
'display webinterface effects' => 'Activate effects',
'dl client arch' => 'Download Client Package (zip)',
'dmz' => 'DMZ',
'edit share' => 'edit share',
'editor' => 'Editor',
'eg' => 'e.g:',
+'email server can not be empty' => 'Email server can not be empty',
'emailreportlevel' => 'Emailreportlevel',
'empty' => 'This field may be left blank',
'empty profile' => 'empty',
'fritzdsl help' => 'To utilise one of Fritz!DSL fcdsl / fcdslsl / fcdsl2 / fcdslusb / fcdslslusb modem, you must upload a package to your IPFire box. Please download the tarball corresponding to your version from the IPFire Website and then upload the entire <b>fcdsl-(your_version).tgz</b> using the form below.',
'fritzdsl upload' => 'Upload Fritz!DSL Driver',
'from' => 'From',
+'from email adr' => 'From Email address',
+'from email pw' => 'From Email password',
+'from email server' => 'From Email server',
+'from email user' => 'From Email user',
+'from warn email bad' => 'From email address is not valid',
'g.dtm' => 'TO BE REMOVED',
'g.lite' => 'TO BE REMOVED',
'gateway' => 'Gateway',
'monday' => 'Monday',
'month' => 'Month',
'monthly firewallhits' => 'monthly firewallhits',
+'monthly start day bad' => 'Monthly start day is not correct',
+'monthly traffic bad' => 'Monthly volume is not correct',
+'monthly volume' => 'Monthly volume',
+'monthly volume start day' => 'First day of monthly period',
+'monthly volume start day short' => 'First day',
'months' => 'months',
'more' => 'more',
'mount' => 'Mount',
'net config type' => 'kind of network configuration',
'net config type help' => 'GREEN is the local network, RED is the internet, BLUE is WLAN, ORANGE is the DMZ.',
'net to net vpn' => 'Net-to-Net Virtual Private Network',
+'net traffic newversion' => 'New Net-Traffic version is available:',
+'net-traffic configuration' => 'Net-Traffic Configuration',
'netbios name' => 'Netbios Name',
'netmask' => 'Netmask',
'network' => 'Network',
'select source net' => 'Select a source net. If you have no Orange or Blue net configured, you need no DMZ Pinholes.',
'selecttraffic' => 'Select utilization-overview:',
'send cr' => 'ISP requires Carriage Return:',
+'send email notification' => 'Enabled, send email notification',
+'send test mail' => 'Send Testemail',
'september' => 'September',
'serial' => 'Serial',
'server reserved' => 'The connection name server is reserved and not allowed',
'stop ovpn server' => 'Stop OpenVPN Server',
'stopped' => 'STOPPED',
'subject' => 'Subject',
+'subject test' => 'Testemail',
+'subject warn' => 'Warning - warnlevel reached',
'subnet' => 'Subnet',
'subnet is invalid' => 'Netmask is invalid',
'subscripted user rules' => 'Sourcefire VRT rules with subscription',
'system status information' => 'System Status Information',
'telephone not set' => 'Telephone not set.',
'test' => 'test',
+'test email could not be sent' => 'Could not sent Testemail',
+'test email was sent' => 'Testemail was send successfully',
'the following update was successfully installed' => 'The following update was successfully installed',
'the statistics were last updated at' => 'The statistics were last updated at',
'theme' => 'Theme',
'this field may be blank' => 'This field may be blank.',
'this is not a valid archive' => 'This is not a valid archive.',
'this is not an authorised update' => 'This is not an authorised update.',
+'this months volume' => 'This months volume',
'this update is already installed' => 'This update is already installed.',
+'this weeks volume' => 'This weeks volume',
'thursday' => 'Thursday',
'time' => 'Time',
'time date manually reset' => 'Time/Date manually reset.',
'timeout must be a number' => 'Timeout must be a number.',
'title' => 'Title',
'to' => 'To',
+'to email adr' => 'To Email address',
'to install an update' => 'To install an update please upload the .tgz.gpg file below:',
+'to warn email bad' => 'To email address is not valid',
'toggle enable disable' => 'Enable or Disable',
'tone' => 'Tone',
'tone dial' => 'Tone dial:',
'total hits for log section' => 'Total Hits for Log Section',
+'traffic back' => 'Back',
+'traffic calc time' => 'Time of calculation',
+'traffic calc time bad' => 'Calculation time is not correct',
+'traffic info messages' => 'Info messages',
+'traffic monitor' => 'Traffic Monitor',
'traffic on' => 'Traffic on',
'traffic shaping' => 'Traffic Shaping',
'traffic shaping settings' => 'Traffic Shaping Settings',
+'traffic warn level bad' => 'Warnlevel is not correct',
'trafficblue' => 'WLAN',
'trafficdate' => 'Date',
'trafficfrom' => 'From',
'vpn vhost' => 'Roadwarrior virtual IP (sometimes called Inner-IP)',
'vpn watch' => 'Restart net-to-net vpn when remote peer IP changes (dyndns), it helps DPD',
'waiting to synchronize clock' => 'Waiting to synchronize clock',
+'warn when traffic reaches' => 'Warn when traffic reaches x %',
'warning messages' => 'Warning messages',
'web hits' => 'Total number of websites matching selected criteria for',
'web proxy' => 'Web proxy',
# Create all directories
for i in addon-lang auth backup ca certs connscheduler crls ddns dhcp dhcpc dmzholes \
ethernet extrahd/bin fwlogs isdn key langs logging main mbmon menu.d modem net-traffic \
- nfs optionsfw outgoing/bin patches pakfire portfw \
+ net-traffic\templates nfs optionsfw outgoing/bin patches pakfire portfw \
ppp private proxy/advanced/cre proxy/calamaris/bin qos/bin red remote snort time tripwire/report \
updatexlrator/bin updatexlrator/autocheck urlfilter/autoupdate urlfilter/bin upnp vpn \
wakeonlan wireless xtaccess ; do \
certs/index.txt ddns/config ddns/noipsettings ddns/settings ddns/ipcache dhcp/settings \
dhcp/fixleases dhcp/advoptions dmzholes/config ethernet/aliases ethernet/settings ethernet/known_nics ethernet/scanned_nics \
extrahd/scan extrahd/devices extrahd/partitions extrahd/settings fwlogs/ipsettings fwlogs/portsettings\
- isdn/settings main/hosts main/settings optionsfw/settings outgoing/settings outgoing/rules pakfire/settings \
+ isdn/settings main/hosts main/settings net-traffic\settings optionsfw/settings outgoing/settings outgoing/rules pakfire/settings \
portfw/config ppp/settings-1 ppp/settings-2 ppp/settings-3 ppp/settings-4 \
ppp/settings-5 ppp/settings proxy/settings proxy/advanced/settings proxy/advanced/cre/enable remote/settings qos/settings qos/classes qos/subclasses qos/level7config qos/portconfig \
qos/tosconfig snort/settings tripwire/settings upnp/settings vpn/config vpn/settings vpn/ipsec.conf \
cp $(DIR_SRC)/config/cfgroot/modem-defaults $(CONFIG_ROOT)/modem/defaults
cp $(DIR_SRC)/config/cfgroot/modem-settings $(CONFIG_ROOT)/modem/settings
cp $(DIR_SRC)/config/cfgroot/net-traffic-lib.pl $(CONFIG_ROOT)/net-traffic/net-traffic-lib.pl
+ cp $(DIR_SRC)/config/cfgroot/net-traffic-admin.pl $(CONFIG_ROOT)/net-traffic/net-traffic-admin.pl
+ cp $(DIR_SRC)/config/cfgroot/monitorTraffic.pl /usr/local/bin/monitorTraffic.pl
cp $(DIR_SRC)/config/cfgroot/nfs-server $(CONFIG_ROOT)/nfs/nfs-server
cp $(DIR_SRC)/config/cfgroot/p2protocols $(CONFIG_ROOT)/outgoing/p2protocols
cp $(DIR_SRC)/config/outgoingfw/outgoingfw.pl $(CONFIG_ROOT)/outgoing/bin/
# Language files
cp $(DIR_SRC)/langs/de/cgi-bin/de.pl $(CONFIG_ROOT)/langs/
cp $(DIR_SRC)/langs/en/cgi-bin/en.pl $(CONFIG_ROOT)/langs/
+
+ # Copy Net-Traffic Templates
+ cp $(DIR_SRC)/config/nettraffic/templates/* $(CONFIG_ROOT)/net-traffic/templates/
+ touch /var/log/net-traffic.log
# Configroot permissions
chown -R nobody:nobody $(CONFIG_ROOT)
SUID_PROGS = setdmzholes setportfw setfilters setxtaccess \
squidctrl restartssh ipfirereboot setaliases \
ipsecctrl timectrl dhcpctrl restartsnort \
- restartapplejuice rebuildhosts \
+ monitorTraff restartapplejuice rebuildhosts \
restartsyslogd logwatch openvpnctrl \
restartwireless getipstat qosctrl launch-ether-wake \
redctrl extrahdctrl sambactrl upnpctrl tripwirectrl \
smartctrl: smartctrl.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ smartctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
+monitorTraff: monitorTraff.c setuid.o ../install+setup/libsmooth/varval.o
+ $(COMPILE) -I../install+setup/libsmooth/ monitorTraff.c setuid.o ../install+setup/libsmooth/varval.o -o $@
+
clamavctrl: clamavctrl.c setuid.o ../install+setup/libsmooth/varval.o
$(COMPILE) -I../install+setup/libsmooth/ clamavctrl.c setuid.o ../install+setup/libsmooth/varval.o -o $@
--- /dev/null
+/* Addon helper program - monitorTraff
+ *
+ * This program is distributed under the terms of the GNU General Public
+ * Licence. See the file COPYING for details.
+ *
+ * Copyright (c) Achim Weber 2 November 2006
+ *
+ * Wrapper for Perl Monitoring script
+ *
+ * $Id: monitorTraff.c,v 1.4 2006/11/15 17:53:43 dotzball Exp $
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "setuid.h"
+
+/* define parameters */
+#define PARA_TEST "--testEmail"
+#define PARA_WARN "--warnEmail"
+#define PARA_FORCE "--force"
+
+struct keyvalue *kv = NULL;
+
+void usage()
+{
+ fprintf (stderr, "Usage:\n");
+ fprintf (stderr, "\tmonitorTraff [PARAMETER]\n");
+ fprintf (stderr, "\t\tWhen called without parameter, monitorTraff calculates the traffic.\n");
+ fprintf (stderr, "\t\tPARAMETER:\n");
+ fprintf (stderr, "\t\t\t--testEmail : Send a test email\n");
+ fprintf (stderr, "\t\t\t--warnEmail : Send a warn email\n");
+ fprintf (stderr, "\t\t\t--force : Force re-calculation\n");
+}
+
+int main(int argc, char *argv[])
+{
+ char buffer[STRING_SIZE];
+
+ if (!(initsetuid()))
+ return 1;
+
+ // What should we do?
+ if (argc==1)
+ {
+ // calc traffic
+ safe_system("/usr/local/bin/monitorTraffic.pl");
+ }
+ else if (argc==2
+ && (strcmp(argv[1], PARA_TEST)==0
+ || strcmp(argv[1], PARA_WARN)==0
+ || strcmp(argv[1], PARA_FORCE)==0) )
+ {
+ // send (test|warn) Email or force re-calc
+ memset(buffer, 0, STRING_SIZE);
+ if ( snprintf(buffer, STRING_SIZE - 1, "/usr/local/bin/monitorTraffic.pl %s", argv[1]) >= STRING_SIZE )
+ {
+ fprintf(stderr, "Command too long\n");
+ exit(1);
+ }
+ safe_system(buffer);
+ }
+ else
+ {
+ usage();
+ }
+
+ return 0;
+}