mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-27 03:07:43 +02:00
Hinzugefügt:
* Nochmal ein neues Shutdown-Bild. * Schnelle Profilauswahl in der index.cgi * Nettraffic. * Capiinfo. Geändert: * Menü komplett neu sortiert. * Javascript-Option aus gui.cgi entfernt. * Pakfire-Fehler beseitigt. * Sämtliche /var/ipcop durch /var/ipfire ersetzt. git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@129 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
@@ -24,6 +24,41 @@ my %cgiparams=();
|
||||
$cgiparams{'ACTION'} = '';
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'dial profile'})
|
||||
{
|
||||
my $profile = $cgiparams{'PROFILE'};
|
||||
my %tempcgiparams = ();
|
||||
$tempcgiparams{'PROFILE'} = '';
|
||||
&General::readhash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
|
||||
\%tempcgiparams);
|
||||
|
||||
# make a link from the selected profile to the "default" one.
|
||||
unlink("${General::swroot}/ppp/settings");
|
||||
link("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
|
||||
"${General::swroot}/ppp/settings");
|
||||
system ("/bin/touch", "${General::swroot}/ppp/updatesettings");
|
||||
|
||||
# read in the new params "early" so we can write secrets.
|
||||
%cgiparams = ();
|
||||
&General::readhash("${General::swroot}/ppp/settings", \%cgiparams);
|
||||
$cgiparams{'PROFILE'} = $profile;
|
||||
$cgiparams{'BACKUPPROFILE'} = $profile;
|
||||
&General::writehash("${General::swroot}/ppp/settings-$cgiparams{'PROFILE'}",
|
||||
\%cgiparams);
|
||||
|
||||
# write secrets file.
|
||||
open(FILE, ">/${General::swroot}/ppp/secrets") or die "Unable to write secrets file.";
|
||||
flock(FILE, 2);
|
||||
my $username = $cgiparams{'USERNAME'};
|
||||
my $password = $cgiparams{'PASSWORD'};
|
||||
print FILE "'$username' * '$password'\n";
|
||||
chmod 0600, "${General::swroot}/ppp/secrets";
|
||||
close FILE;
|
||||
|
||||
&General::log("$Lang::tr{'profile made current'} $tempcgiparams{'PROFILENAME'}");
|
||||
$cgiparams{'ACTION'} = "$Lang::tr{'dial'}";
|
||||
}
|
||||
|
||||
if ($cgiparams{'ACTION'} eq $Lang::tr{'dial'}) {
|
||||
system('/etc/rc.d/rc.red','start') == 0
|
||||
or &General::log("Dial failed: $?"); }
|
||||
|
||||
@@ -56,11 +56,6 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}")
|
||||
goto SAVE_ERROR;
|
||||
}
|
||||
|
||||
if ($cgiparams{'JAVASCRIPT'} !~ /^(on|off)$/) {
|
||||
$errormessage = $Lang::tr{'invalid input'};
|
||||
goto SAVE_ERROR;
|
||||
}
|
||||
|
||||
# Set flag if index page is to refresh whilst ppp is up.
|
||||
# Default is NO refresh.
|
||||
if ($cgiparams{'REFRESHINDEX'} ne 'off') {
|
||||
@@ -79,7 +74,6 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}")
|
||||
|
||||
# write cgi vars to the file.
|
||||
$mainsettings{'LANGUAGE'} = $cgiparams{'lang'};
|
||||
$mainsettings{'JAVASCRIPT'} = $cgiparams{'JAVASCRIPT'};
|
||||
$mainsettings{'WINDOWWITHHOSTNAME'} = $cgiparams{'WINDOWWITHHOSTNAME'};
|
||||
$mainsettings{'PPPUPDOWNBEEP'} = $cgiparams{'PPPUPDOWNBEEP'};
|
||||
$mainsettings{'REFRESHINDEX'} = $cgiparams{'REFRESHINDEX'};
|
||||
@@ -87,12 +81,6 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}")
|
||||
&Lang::reload($cgiparams{'lang'});
|
||||
SAVE_ERROR:
|
||||
} else {
|
||||
if ($mainsettings{'JAVASCRIPT'}) {
|
||||
$cgiparams{'JAVASCRIPT'} = $mainsettings{'JAVASCRIPT'};
|
||||
} else {
|
||||
$cgiparams{'JAVASCRIPT'} = 'on';
|
||||
}
|
||||
|
||||
if ($mainsettings{'WINDOWWITHHOSTNAME'}) {
|
||||
$cgiparams{'WINDOWWITHHOSTNAME'} = $mainsettings{'WINDOWWITHHOSTNAME'};
|
||||
} else {
|
||||
@@ -115,16 +103,11 @@ if ($cgiparams{'ACTION'} eq "$Lang::tr{'save'}")
|
||||
# Default settings
|
||||
if ($cgiparams{'ACTION'} eq "$Lang::tr{'restore defaults'}")
|
||||
{
|
||||
$cgiparams{'JAVASCRIPT'} = 'on';
|
||||
$cgiparams{'WINDOWWITHHOSTNAME'} = 'off';
|
||||
$cgiparams{'PPPUPDOWNBEEP'} = 'on';
|
||||
$cgiparams{'REFRESHINDEX'} = 'off';
|
||||
}
|
||||
|
||||
$checked{'JAVASCRIPT'}{'off'} = '';
|
||||
$checked{'JAVASCRIPT'}{'on'} = '';
|
||||
$checked{'JAVASCRIPT'}{$cgiparams{'JAVASCRIPT'}} = "checked='checked'";
|
||||
|
||||
$checked{'WINDOWWITHHOSTNAME'}{'off'} = '';
|
||||
$checked{'WINDOWWITHHOSTNAME'}{'on'} = '';
|
||||
$checked{'WINDOWWITHHOSTNAME'}{$cgiparams{'WINDOWWITHHOSTNAME'}} = "checked='checked'";
|
||||
@@ -154,10 +137,6 @@ print <<END
|
||||
<tr>
|
||||
<td colspan='2'><p><b>$Lang::tr{'display'}</b></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type='checkbox' name='JAVASCRIPT' $checked{'JAVASCRIPT'}{'on'} />
|
||||
<td width='100%'>$Lang::tr{'enable javascript'}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><input type='checkbox' name='WINDOWWITHHOSTNAME' $checked{'WINDOWWITHHOSTNAME'}{'on'} /></td>
|
||||
<td>$Lang::tr{'display hostname in window title'}</td>
|
||||
|
||||
@@ -180,24 +180,57 @@ print "</p>\n";
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
# Test browser, and direct User where to turn off Javascript if necessary
|
||||
# only display message if Javascript is currently enabled
|
||||
if (${Header::javascript}) {
|
||||
print <<END
|
||||
<script type='text/javascript'>\n
|
||||
if(navigator.platform.indexOf("MacPPC")>(-1)){
|
||||
document.write(
|
||||
"<center><p>"
|
||||
+ "$Lang::tr{'javascript menu error1'}"
|
||||
+ " <a href='/cgi-bin/gui.cgi'>$Lang::tr{'gui settings'}</a> "
|
||||
+ "$Lang::tr{'javascript menu error2'}"
|
||||
+ "</p></center>"
|
||||
)
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'quick control'});
|
||||
# read in the profile names into @profilenames.
|
||||
my $c;
|
||||
my $maxprofiles = 5;
|
||||
my @profilenames = ();
|
||||
|
||||
for ($c = 1; $c <= $maxprofiles; $c++)
|
||||
{
|
||||
my %temppppsettings = ();
|
||||
$temppppsettings{'PROFILENAME'} = '';
|
||||
&General::readhash("${General::swroot}/ppp/settings-$c", \%temppppsettings);
|
||||
$profilenames[$c] = $temppppsettings{'PROFILENAME'};
|
||||
}
|
||||
</script>
|
||||
my %selected;
|
||||
for ($c = 1; $c <= $maxprofiles; $c++) {
|
||||
$selected{'PROFILE'}{$c} = '';
|
||||
}
|
||||
$selected{'PROFILE'}{$pppsettings{'PROFILE'}} = "selected='selected'";
|
||||
|
||||
print <<END;
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td align='left'>
|
||||
<form method='post' action='/cgi-bin/dial.cgi'>
|
||||
$Lang::tr{'profile'}:
|
||||
<select name='PROFILE'>
|
||||
END
|
||||
;
|
||||
my $dialButtonDisabled = "disabled='disabled'";
|
||||
for ($c = 1; $c <= $maxprofiles; $c++)
|
||||
{
|
||||
if ($profilenames[$c] ne '') {
|
||||
$dialButtonDisabled = "";
|
||||
print "\t<option value='$c' $selected{'PROFILE'}{$c}>$c. $profilenames[$c]</option>\n";
|
||||
}
|
||||
}
|
||||
$dialButtonDisabled = "disabled='disabled'" if (-e '/var/run/ppp-ipcop.pid' || -e "${General::swroot}/red/active");
|
||||
|
||||
print <<END;
|
||||
</select>
|
||||
<input type='submit' name='ACTION' value='$Lang::tr{'dial profile'}' $dialButtonDisabled />
|
||||
</form>
|
||||
</td>
|
||||
<td align='right'>
|
||||
<form method='post' action='/cgi-bin/shutdown.cgi'>
|
||||
<input type='submit' name='ACTION' value='$Lang::tr{'shutdown'}' />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
|
||||
297
html/cgi-bin/traffic.cgi
Normal file
297
html/cgi-bin/traffic.cgi
Normal file
@@ -0,0 +1,297 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# SmoothWall CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The SmoothWall Team
|
||||
#
|
||||
|
||||
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 '/var/ipfire/net-traffic/net-traffic-lib.pl';
|
||||
|
||||
my %cgiparams;
|
||||
my %pppsettings;
|
||||
my %netsettings;
|
||||
|
||||
&General::readhash("${General::swroot}/ppp/settings", \%pppsettings);
|
||||
&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
|
||||
|
||||
my @wday = ($Lang::tr{'wday1'}, $Lang::tr{'wday2'}, $Lang::tr{'wday3'}, $Lang::tr{'wday4'}, $Lang::tr{'wday5'}, $Lang::tr{'wday6'}, $Lang::tr{'wday7'});
|
||||
|
||||
my ($s, $min, $h, $d, $m,$y) = localtime(time);
|
||||
$y+=1900;
|
||||
$m+=1;
|
||||
$m = $m < 10 ? $m = "0".$m : $m;
|
||||
|
||||
$cgiparams{'MONTH'} = $m;
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
$cgiparams{'YEAR'} = $y;
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
my %selectYear;
|
||||
$selectYear{'YEAR'}{'2001'} = '';
|
||||
$selectYear{'YEAR'}{'2002'} = '';
|
||||
$selectYear{'YEAR'}{'2003'} = '';
|
||||
$selectYear{'YEAR'}{'2004'} = '';
|
||||
$selectYear{'YEAR'}{'2005'} = '';
|
||||
$selectYear{'YEAR'}{'2006'} = '';
|
||||
$selectYear{'YEAR'}{'2007'} = '';
|
||||
$selectYear{'YEAR'}{'2008'} = '';
|
||||
$selectYear{'YEAR'}{'2009'} = '';
|
||||
$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\'';
|
||||
|
||||
&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left');
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'settingsc'});
|
||||
|
||||
print <<END;
|
||||
<table width='80%' align='center'>
|
||||
<tr>
|
||||
<td width='95%' 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>
|
||||
</select>
|
||||
<select name='YEAR'>
|
||||
<option $selectYear{'YEAR'}{'2001'} value='2001'>2001</option>
|
||||
<option $selectYear{'YEAR'}{'2002'} value='2002'>2002</option>
|
||||
<option $selectYear{'YEAR'}{'2003'} value='2003'>2003</option>
|
||||
<option $selectYear{'YEAR'}{'2004'} value='2004'>2004</option>
|
||||
<option $selectYear{'YEAR'}{'2005'} value='2005'>2005</option>
|
||||
<option $selectYear{'YEAR'}{'2006'} value='2006'>2006</option>
|
||||
<option $selectYear{'YEAR'}{'????'} value='????'>$Lang::tr{'allmsg'}</option>
|
||||
</select>
|
||||
<input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
|
||||
</form>
|
||||
</td>
|
||||
<td width='5%' align='center'>
|
||||
<form method='post' action='/cgi-bin/traffics.cgi'>
|
||||
<input type='submit' name='ACTION' value=' > ' />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
|
||||
|
||||
my $dateWidth = '20%';
|
||||
my $netWidth = '34%';
|
||||
my $inOutWidth = '17%';
|
||||
|
||||
# 4 networks
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
|
||||
$dateWidth = '12%';
|
||||
$netWidth = '22%';
|
||||
$inOutWidth = '11%';
|
||||
}
|
||||
# 3 networks
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
|
||||
$dateWidth = '16%';
|
||||
$netWidth = '28%';
|
||||
$inOutWidth = '14%';
|
||||
}
|
||||
|
||||
print <<END;
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='$dateWidth' align='center' class='boldbase'></td>
|
||||
<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
|
||||
END
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
|
||||
print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
|
||||
}
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
|
||||
print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</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>
|
||||
END
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
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'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
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 <<END;
|
||||
<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>
|
||||
<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>
|
||||
</tr>
|
||||
END
|
||||
|
||||
my $total_blue_in=0;
|
||||
my $total_blue_out=0;
|
||||
my $total_green_in=0;
|
||||
my $total_green_out=0;
|
||||
my $total_orange_in=0;
|
||||
my $total_orange_out=0;
|
||||
my $total_red_in=0;
|
||||
my $total_red_out=0;
|
||||
my $lines=0;
|
||||
|
||||
my $displayMode = "daily";
|
||||
my $startMonth = $cgiparams{'MONTH'};
|
||||
my $endMonth = $cgiparams{'MONTH'};
|
||||
|
||||
if ($cgiparams{'MONTH'} eq '??') {
|
||||
$displayMode = "monthly";
|
||||
$startMonth = '01';
|
||||
$endMonth = '12';
|
||||
}
|
||||
|
||||
my $start = "$cgiparams{'YEAR'}$startMonth"."01";
|
||||
my $end = "$cgiparams{'YEAR'}$endMonth"."32";
|
||||
my %allDaysBytes = ();
|
||||
my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
|
||||
|
||||
|
||||
foreach (@allDays) {
|
||||
$total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
|
||||
$total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
$total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
|
||||
$total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
|
||||
}
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
$total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
|
||||
$total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
|
||||
}
|
||||
|
||||
$total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
|
||||
$total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
|
||||
|
||||
if ($lines % 2) {
|
||||
print "<tr bgcolor='${Header::table1colour}'>"; }
|
||||
else {
|
||||
print "<tr bgcolor='${Header::table2colour}'>"; }
|
||||
|
||||
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'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
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'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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_green_in=sprintf("%.2f", ($total_green_in/1048576));
|
||||
$total_green_out=sprintf("%.2f", ($total_green_out/1048576));
|
||||
$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_red_in=sprintf("%.2f", ($total_red_in/1048576));
|
||||
$total_red_out=sprintf("%.2f", ($total_red_out/1048576));
|
||||
|
||||
if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
|
||||
else {print "<tr bgcolor='${Header::table2colour}'>"; }
|
||||
|
||||
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'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
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'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
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>";
|
||||
}
|
||||
|
||||
print <<END;
|
||||
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>
|
||||
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
357
html/cgi-bin/traffics.cgi
Normal file
357
html/cgi-bin/traffics.cgi
Normal file
@@ -0,0 +1,357 @@
|
||||
#!/usr/bin/perl
|
||||
#
|
||||
# SmoothWall CGIs
|
||||
#
|
||||
# This code is distributed under the terms of the GPL
|
||||
#
|
||||
# (c) The SmoothWall Team
|
||||
#
|
||||
|
||||
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 '/var/ipfire/net-traffic/net-traffic-lib.pl';
|
||||
|
||||
my %cgiparams;
|
||||
my %netsettings;
|
||||
|
||||
&General::readhash("${General::swroot}/ethernet/settings", \%netsettings);
|
||||
|
||||
my @years=("2001","2002","2003","2004","2005","2006","2007","2008","2009");
|
||||
|
||||
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 @wday = ($Lang::tr{'wday1'}, $Lang::tr{'wday2'}, $Lang::tr{'wday3'}, $Lang::tr{'wday4'}, $Lang::tr{'wday5'}, $Lang::tr{'wday6'}, $Lang::tr{'wday7'});
|
||||
|
||||
my @now = localtime(time);
|
||||
|
||||
$now[5] = $now[5]+1900;
|
||||
|
||||
$cgiparams{'STARTDAY'} = 10;
|
||||
$cgiparams{'STOPDAY'} = 11;
|
||||
$cgiparams{'STARTYEAR'} = $now[5];
|
||||
$cgiparams{'STOPYEAR'} = $now[5];
|
||||
|
||||
# this periode started last month
|
||||
if ($now[3] < 10) {
|
||||
$cgiparams{'STARTMONTH'} = $now[4]-1;
|
||||
$cgiparams{'STOPMONTH'} = $now[4];
|
||||
# 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{'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;
|
||||
$cgiparams{'STOPMONTH'} = 0;
|
||||
}
|
||||
}
|
||||
|
||||
&Header::getcgihash(\%cgiparams);
|
||||
|
||||
&Header::showhttpheaders();
|
||||
|
||||
&Header::openpage($Lang::tr{'sstraffic'}, 1, '');
|
||||
|
||||
&Header::openbigbox('100%', 'left');
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'settingsc'});
|
||||
|
||||
print <<END;
|
||||
<table width='100%' align='center'>
|
||||
<tr>
|
||||
<td width='95%' class='base' align='center'>
|
||||
<form method='post' action='/cgi-bin/traffics.cgi'>
|
||||
$Lang::tr{'trafficfrom'}
|
||||
<select name='STARTDAY'>
|
||||
END
|
||||
|
||||
foreach (@days)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($_ == $cgiparams{'STARTDAY'}) {
|
||||
print 'selected=\'selected\' '; }
|
||||
print "value='$_'>$_</option>\n";
|
||||
}
|
||||
print <<END;
|
||||
</select>
|
||||
<select name='STARTMONTH'>
|
||||
END
|
||||
|
||||
foreach (@months)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($_ == $cgiparams{'STARTMONTH'}) {
|
||||
print 'selected=\'selected\' '; }
|
||||
print "value='$_'>$longmonths[$_]</option>\n";
|
||||
}
|
||||
|
||||
print <<END;
|
||||
</select>
|
||||
<select name='STARTYEAR'>
|
||||
END
|
||||
|
||||
for (my $index=0; $index<=$#years; $index++) {
|
||||
print "\t<option ";
|
||||
if ($years[$index] == $cgiparams{'STARTYEAR'}) {
|
||||
print 'selected=\'selected\' '; }
|
||||
print "value='$years[$index]'>$years[$index]</option>\n";
|
||||
}
|
||||
|
||||
print <<END;
|
||||
</select>
|
||||
$Lang::tr{'trafficto'}
|
||||
<select name='STOPDAY'>
|
||||
END
|
||||
|
||||
foreach (@days)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($_ == $cgiparams{'STOPDAY'})
|
||||
{
|
||||
print 'selected=\'selected\' '; }
|
||||
print "value='$_'>$_</option>\n";
|
||||
}
|
||||
|
||||
print <<END;
|
||||
</select>
|
||||
<select name='STOPMONTH'>
|
||||
END
|
||||
|
||||
foreach (@months)
|
||||
{
|
||||
print "\t<option ";
|
||||
if ($_ == $cgiparams{'STOPMONTH'}) {
|
||||
print 'selected=\'selected\' '; }
|
||||
print "value='$_'>$longmonths[$_]</option>\n";
|
||||
}
|
||||
|
||||
print <<END;
|
||||
</select>
|
||||
<select name='STOPYEAR'>
|
||||
END
|
||||
|
||||
for (my $index = 0; $index <=$#years; $index++) {
|
||||
print "\t<option ";
|
||||
if ($years[$index] == $cgiparams{'STOPYEAR'}) {
|
||||
print 'selected=\'selected\' '; }
|
||||
print "value='$years[$index]'>$years[$index]</option>\n";
|
||||
}
|
||||
|
||||
|
||||
print <<END;
|
||||
</select>
|
||||
<input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
|
||||
</form>
|
||||
</td>
|
||||
<td width='5%' align='center'>
|
||||
<form method='post' action='/cgi-bin/traffic.cgi'>
|
||||
<input type='submit' name='ACTION' value=' > ' />
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
|
||||
|
||||
my $dateWidth = '20%';
|
||||
my $netWidth = '34%';
|
||||
my $inOutWidth = '17%';
|
||||
|
||||
# 4 networks
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) {
|
||||
$dateWidth = '12%';
|
||||
$netWidth = '22%';
|
||||
$inOutWidth = '11%';
|
||||
}
|
||||
# 3 networks
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) {
|
||||
$dateWidth = '16%';
|
||||
$netWidth = '28%';
|
||||
$inOutWidth = '14%';
|
||||
}
|
||||
|
||||
print <<END;
|
||||
<table width='100%'>
|
||||
<tr>
|
||||
<td width='$dateWidth' align='center' class='boldbase'></td>
|
||||
<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficgreen'}</b></td>
|
||||
END
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) {
|
||||
print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficblue'}</b></td>";
|
||||
}
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) {
|
||||
print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</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>
|
||||
END
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
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'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
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 <<END;
|
||||
<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>
|
||||
<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>
|
||||
</tr>
|
||||
END
|
||||
|
||||
my $total_blue_in=0;
|
||||
my $total_blue_out=0;
|
||||
my $total_green_in=0;
|
||||
my $total_green_out=0;
|
||||
my $total_orange_in=0;
|
||||
my $total_orange_out=0;
|
||||
my $total_red_in=0;
|
||||
my $total_red_out=0;
|
||||
my $lines=0;
|
||||
|
||||
|
||||
my $startyear = $cgiparams{'STARTYEAR'};
|
||||
my $stopyear = $cgiparams{'STOPYEAR'};
|
||||
|
||||
my $startMonth = $cgiparams{'STARTMONTH'}+1;
|
||||
$startMonth = $startMonth < 10 ? $startMonth = "0".$startMonth : $startMonth;
|
||||
|
||||
my $endMonth = $cgiparams{'STOPMONTH'}+1;
|
||||
$endMonth = $endMonth < 10 ? $endMonth = "0".$endMonth : $endMonth;
|
||||
|
||||
my $startDay = $cgiparams{'STARTDAY'};
|
||||
$startDay = $startDay < 10 ? $startDay = "0".$startDay : $startDay;
|
||||
|
||||
my $endDay = $cgiparams{'STOPDAY'}+1;
|
||||
$endDay = $endDay < 10 ? $endDay = "0".$endDay : $endDay;
|
||||
|
||||
my $displayMode = "daily_multi";
|
||||
my $start = $startyear.$startMonth.$startDay;
|
||||
my $end = $stopyear.$endMonth.$endDay;
|
||||
|
||||
my %allDaysBytes = ();
|
||||
my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode);
|
||||
|
||||
|
||||
foreach (@allDays) {
|
||||
$total_green_in += $allDaysBytes{$_}{${Traffic::green_in}};
|
||||
$total_green_out += $allDaysBytes{$_}{${Traffic::green_out}};
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
$total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}};
|
||||
$total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}};
|
||||
}
|
||||
|
||||
if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
$total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}};
|
||||
$total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}};
|
||||
}
|
||||
|
||||
$total_red_in += $allDaysBytes{$_}{${Traffic::red_in}};
|
||||
$total_red_out += $allDaysBytes{$_}{${Traffic::red_out}};
|
||||
|
||||
if ($lines % 2) {
|
||||
print "<tr bgcolor='${Header::table1colour}'>"; }
|
||||
else {
|
||||
print "<tr bgcolor='${Header::table2colour}'>"; }
|
||||
|
||||
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'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
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'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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_green_in=sprintf("%.2f", ($total_green_in/1048576));
|
||||
$total_green_out=sprintf("%.2f", ($total_green_out/1048576));
|
||||
$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_red_in=sprintf("%.2f", ($total_red_in/1048576));
|
||||
$total_red_out=sprintf("%.2f", ($total_red_out/1048576));
|
||||
|
||||
if ($lines % 2) {print "<tr bgcolor='${Header::table1colour}'>"; }
|
||||
else {print "<tr bgcolor='${Header::table2colour}'>"; }
|
||||
|
||||
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'} =~ /^(4|5|6|7)$/)
|
||||
{
|
||||
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'} =~ /^(1|3|5|7)$/)
|
||||
{
|
||||
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>";
|
||||
}
|
||||
|
||||
print <<END;
|
||||
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>
|
||||
<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>
|
||||
</tr>
|
||||
</table>
|
||||
END
|
||||
|
||||
&Header::closebox();
|
||||
|
||||
&Header::closebigbox();
|
||||
|
||||
&Header::closepage();
|
||||
Reference in New Issue
Block a user