mirror of
https://github.com/vincentmli/bpfire.git
synced 2026-04-28 11:43:25 +02:00
some small code fixes
git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@1049 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
@@ -552,9 +552,6 @@ END
|
||||
103;ppp0;udp;;4500;;4500;
|
||||
103;ppp0;udp;;500;;500;
|
||||
104;ppp0;tcp;;;;80;
|
||||
108;ppp0;esp;;;;;
|
||||
108;ppp0;l2tp;;;;;
|
||||
109;ppp0;icmp;;;;;
|
||||
200;imq0;icmp;;;;;
|
||||
203;imq0;esp;;;;;
|
||||
203;imq0;tcp;;;;1194;
|
||||
|
||||
@@ -52,7 +52,8 @@ if ((${Lang::language} eq 'el') ||
|
||||
(${Lang::language} eq 'zt')) {
|
||||
eval `/bin/cat "${General::swroot}/langs/en.pl"`;
|
||||
} else {
|
||||
%tr=%Lang::tr; # use translated version for other languages
|
||||
use translated version for other languages
|
||||
%tr=%Lang::tr;
|
||||
}
|
||||
|
||||
# Settings
|
||||
@@ -97,17 +98,13 @@ sub gettraffic {
|
||||
my $bytesin=0;
|
||||
my $bytesout=0;
|
||||
|
||||
foreach (@ipacsum)
|
||||
{
|
||||
foreach (@ipacsum){
|
||||
# Incoming...
|
||||
$bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/);
|
||||
|
||||
# Forwarded Incoming...
|
||||
$bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/);
|
||||
|
||||
# Outgoing...
|
||||
$bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/);
|
||||
|
||||
# Forwarded Outgoing...
|
||||
$bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/);
|
||||
}
|
||||
@@ -131,7 +128,6 @@ sub updatecpudata {
|
||||
}
|
||||
|
||||
my ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq);
|
||||
|
||||
open STAT, "/proc/stat";
|
||||
while(<STAT>) {
|
||||
chomp;
|
||||
@@ -142,14 +138,11 @@ sub updatecpudata {
|
||||
close STAT;
|
||||
$user += $nice;
|
||||
$irq += $softirq;
|
||||
|
||||
|
||||
RRDs::update ("$rrdlog/cpu.rrd",
|
||||
"-t", "user:system:idle:iowait:irq",
|
||||
"N:$user:$system:$idle:$iowait:$irq");
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::update for cpu: $ERROR\n" if $ERROR;
|
||||
|
||||
}
|
||||
|
||||
sub updateloaddata {
|
||||
@@ -162,7 +155,6 @@ sub updateloaddata {
|
||||
"RRA:AVERAGE:0.5:5:2016",
|
||||
"RRA:AVERAGE:0.5:15:2880",
|
||||
"RRA:AVERAGE:0.5:60:8760");
|
||||
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
|
||||
}
|
||||
@@ -190,25 +182,12 @@ sub updatememdata {
|
||||
open MEM, "/proc/meminfo";
|
||||
while(<MEM>) {
|
||||
chomp;
|
||||
if ($_ =~ /^MemTotal:/) {
|
||||
my @temp = split (/\s+/, $_);
|
||||
$memused = $temp[1];
|
||||
} elsif ($_ =~ /^MemFree:/) {
|
||||
my @temp = split (/\s+/, $_);
|
||||
$memfree = $temp[1];
|
||||
} elsif ($_ =~ /^Cached:/) {
|
||||
my @temp = split (/\s+/, $_);
|
||||
$memcache = $temp[1];
|
||||
} elsif ($_ =~ /^Buffers:/) {
|
||||
my @temp = split (/\s+/, $_);
|
||||
$membuffers = $temp[1];
|
||||
} elsif ($_ =~ /^SwapTotal:/) {
|
||||
my @temp = split (/\s+/, $_);
|
||||
$swaptotal = $temp[1];
|
||||
} elsif ($_ =~ /^SwapFree:/) {
|
||||
my @temp = split (/\s+/, $_);
|
||||
$swapfree = $temp[1];
|
||||
}
|
||||
if ($_ =~ /^MemTotal:/) {my @temp = split (/\s+/, $_);$memused = $temp[1];
|
||||
} elsif ($_ =~ /^MemFree:/) {my @temp = split (/\s+/, $_);$memfree = $temp[1];
|
||||
} elsif ($_ =~ /^Cached:/) {my @temp = split (/\s+/, $_);$memcache = $temp[1];
|
||||
} elsif ($_ =~ /^Buffers:/) {my @temp = split (/\s+/, $_);$membuffers = $temp[1];
|
||||
} elsif ($_ =~ /^SwapTotal:/) {my @temp = split (/\s+/, $_);$swaptotal = $temp[1];
|
||||
} elsif ($_ =~ /^SwapFree:/) {my @temp = split (/\s+/, $_);$swapfree = $temp[1];}
|
||||
}
|
||||
close MEM;
|
||||
|
||||
@@ -216,14 +195,10 @@ sub updatememdata {
|
||||
open DF, "/tmp/diskfree";
|
||||
while(<DF>) {
|
||||
chomp;
|
||||
if ($_ =~ /^shm/) {
|
||||
my @temp = split (/\s+/, $_);
|
||||
$memshared = $temp[2];
|
||||
}
|
||||
if ($_ =~ /^shm/) {my @temp = split (/\s+/, $_);$memshared = $temp[2];}
|
||||
}
|
||||
close DF;
|
||||
system("/bin/rm -f /tmp/diskfree");
|
||||
|
||||
$swapused = $swaptotal-$swapfree;
|
||||
RRDs::update ("$rrdlog/mem.rrd",
|
||||
"-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree",
|
||||
@@ -247,26 +222,20 @@ sub updatediskdata {
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::create for disk $disk: $ERROR\n" if $ERROR;
|
||||
}
|
||||
|
||||
my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`;
|
||||
($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen);
|
||||
|
||||
print "\nread:".$readsect."write:".$writesect."\n";
|
||||
|
||||
if ($readsect && $writesect) {
|
||||
RRDs::update ("$rrdlog/disk-".$array[$#array].".rrd",
|
||||
"-t", "readsect:writesect",
|
||||
"N:$readsect:$writesect");
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR;
|
||||
} else {
|
||||
print "Error in RRD::update for disk: $disk no data available\n";
|
||||
}
|
||||
} else {print "Error in RRD::update for disk: $disk no data available\n";}
|
||||
}
|
||||
|
||||
sub updateifdata {
|
||||
my $interface = $_[0];
|
||||
|
||||
if ( ! -e "$rrdlog/$interface.rrd") {
|
||||
RRDs::create ("$rrdlog/$interface.rrd", "--step=300",
|
||||
"DS:incoming:ABSOLUTE:600:0:12500000",
|
||||
@@ -278,7 +247,6 @@ sub updateifdata {
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::create for $interface: $ERROR\n" if $ERROR;
|
||||
}
|
||||
|
||||
my $traffic = gettraffic ($interface);
|
||||
RRDs::update ("$rrdlog/$interface.rrd",
|
||||
"-t", "incoming:outgoing",
|
||||
@@ -293,9 +261,7 @@ sub updatefwhitsdata {
|
||||
my $aktuell=0;
|
||||
my $portaktuell=0;
|
||||
my $skip=0;
|
||||
|
||||
if (! -e "$rrdlog/firewallhits.rrd")
|
||||
{
|
||||
if (! -e "$rrdlog/firewallhits.rrd"){
|
||||
RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300",
|
||||
"DS:amount:GAUGE:600:0:U",
|
||||
"DS:portamount:GAUGE:600:0:U",
|
||||
@@ -306,51 +272,34 @@ sub updatefwhitsdata {
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::create for cpu: $ERROR\n" if $ERROR;
|
||||
}
|
||||
|
||||
system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits");
|
||||
if (!(open (FILE,'/tmp/messages.fwhits'))) {
|
||||
$skip=1;
|
||||
}
|
||||
if (!(open (FILE,'/tmp/messages.fwhits'))) {$skip=1;}
|
||||
$aktuell = 0;
|
||||
if (!$skip) {
|
||||
while (<FILE>) {
|
||||
if (/kernel:.*(IN=.*)$/) {
|
||||
$aktuell++;
|
||||
}
|
||||
if (/kernel:.*(IN=.*)$/) {$aktuell++;}
|
||||
}
|
||||
close (FILE);
|
||||
}
|
||||
|
||||
system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits");
|
||||
if (!(open (FILE,'/tmp/snort.fwhits'))) {
|
||||
$skip=1;
|
||||
}
|
||||
if (!(open (FILE,'/tmp/snort.fwhits'))) {$skip=1;}
|
||||
$alertaktuell = 0;
|
||||
if (!$skip) {
|
||||
while (<FILE>) {
|
||||
if (/scan.*$/) {
|
||||
$alertaktuell++;
|
||||
}
|
||||
if (/scan.*$/) {$alertaktuell++;}
|
||||
}
|
||||
close (FILE);
|
||||
}
|
||||
|
||||
if (!(open (FILE,'/tmp/messages.fwhits'))) {
|
||||
$skip=1;
|
||||
}
|
||||
if (!(open (FILE,'/tmp/messages.fwhits'))) {$skip=1;}
|
||||
$portaktuell = 0;
|
||||
if (!$skip) {
|
||||
while (<FILE>) {
|
||||
if (/kernel:.*(Scan.*)$/) {
|
||||
$portaktuell++;
|
||||
}
|
||||
if (/kernel:.*(Scan.*)$/) {$portaktuell++;}
|
||||
}
|
||||
close (FILE);
|
||||
}
|
||||
|
||||
system("rm /tmp/messages.fwhits");
|
||||
system("rm /tmp/snort.fwhits");
|
||||
|
||||
$portamount = $portaktuell + $alertaktuell;
|
||||
chomp($portamount);
|
||||
RRDs::update ("$rrdlog/firewallhits.rrd",
|
||||
@@ -384,18 +333,14 @@ sub updatelq {
|
||||
my @temp = split (/\/|\%|\s/, $pingoutput);
|
||||
$packetloss = $temp[5];
|
||||
$roundtrip = $temp[17];
|
||||
|
||||
print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
|
||||
|
||||
if ( $packetloss eq "100" ){
|
||||
my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q ping.ipfire.org | tail -2`;
|
||||
my @temp = split (/\/|\%|\s/, $pingoutput);
|
||||
$packetloss = $temp[5];
|
||||
$roundtrip = $temp[17];
|
||||
|
||||
print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
|
||||
}
|
||||
|
||||
RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
|
||||
@@ -407,8 +352,7 @@ sub updatehdddata
|
||||
my $standby;
|
||||
my @array = split(/\//,$disk);
|
||||
|
||||
if ( ! -e "$rrdlog/hddshutdown-".$array[$#array].".rrd")
|
||||
{
|
||||
if ( ! -e "$rrdlog/hddshutdown-".$array[$#array].".rrd"){
|
||||
# database did not exist -> create
|
||||
RRDs::create ("$rrdlog/hddshutdown-".$array[$#array].".rrd", "--step=300",
|
||||
"DS:standby:GAUGE:600:0:1",
|
||||
@@ -427,8 +371,7 @@ sub updatehdddata
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
|
||||
|
||||
if ( ! -e "$rrdlog/hddtemp-".$array[$#array].".rrd")
|
||||
{
|
||||
if ( ! -e "$rrdlog/hddtemp-".$array[$#array].".rrd"){
|
||||
# database did not exist -> create
|
||||
RRDs::create ("$rrdlog/hddtemp-".$array[$#array].".rrd", "--step=300",
|
||||
"DS:temperature:GAUGE:600:0:100",
|
||||
@@ -441,21 +384,13 @@ sub updatehdddata
|
||||
}
|
||||
|
||||
# Temperaturlesen w<>rde die Platte aufwecken!!!
|
||||
if (!$standby)
|
||||
{
|
||||
if (!$standby){
|
||||
$temp = 0;
|
||||
my $hdd_output = '';
|
||||
my $smart_output = '';
|
||||
|
||||
if ( -e "$path_smartctl" )
|
||||
{
|
||||
system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
|
||||
}
|
||||
|
||||
if ( -e "$path_hddtemp" )
|
||||
{
|
||||
if ( -e "$path_smartctl" ){system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");}
|
||||
if ( -e "$path_hddtemp" ){
|
||||
$hdd_output = `$path_hddtemp -qn /dev/$disk`;
|
||||
|
||||
# I know 4 response possible responses:
|
||||
#
|
||||
# /dev/harddisk: harddisk type: S.M.A.R.T. not available
|
||||
@@ -463,43 +398,20 @@ sub updatehdddata
|
||||
# /dev/harddisk: harddisk type: 37?C or ?F
|
||||
# 37
|
||||
|
||||
if ( index($hdd_output, "S.M.A.R.T.") != -1 )
|
||||
{
|
||||
$temp = 0;
|
||||
if ( index($hdd_output, "S.M.A.R.T.") != -1 ){$temp = 0;}
|
||||
elsif ( index($hdd_output, "no sensor") != -1 ){$temp = 1;}
|
||||
elsif ( index($hdd_output, "$disk") != -1 ){my @temp = split(/:/,$hdd_output);$temp[2] =~ s/\D//gi;$temp = $temp[2];}
|
||||
else{$hdd_output =~ /(\d+)\s/;$temp = $1;}
|
||||
}
|
||||
elsif ( index($hdd_output, "no sensor") != -1 )
|
||||
{
|
||||
$temp = 1;
|
||||
}
|
||||
elsif ( index($hdd_output, "$disk") != -1 )
|
||||
{
|
||||
my @temp = split(/:/,$hdd_output);
|
||||
$temp[2] =~ s/\D//gi;
|
||||
$temp = $temp[2];
|
||||
$temp = $1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$hdd_output =~ /(\d+)\s/;
|
||||
$temp = $1;
|
||||
}
|
||||
}
|
||||
elsif ( -e "/var/log/smartctl_out_hddtemp-".$array[$#array] )
|
||||
{
|
||||
elsif ( -e "/var/log/smartctl_out_hddtemp-".$array[$#array] ){
|
||||
$hdd_output = `cat /var/log/smartctl_out_hddtemp-".$array[$#array]." | grep Temperature_`;
|
||||
my @t = split(/\s+/,$hdd_output);
|
||||
$temp = $t[9];
|
||||
}
|
||||
else
|
||||
{
|
||||
$temp = 0;
|
||||
}
|
||||
|
||||
}else{$temp = 0;}
|
||||
|
||||
print "Temperature for ".$array[$#array]."->".$temp."<-\n";
|
||||
# Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
|
||||
if ($temp)
|
||||
{
|
||||
if ($temp){
|
||||
RRDs::update ("$rrdlog/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp");
|
||||
$ERROR = RRDs::error;
|
||||
print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
|
||||
@@ -509,24 +421,18 @@ sub updatehdddata
|
||||
|
||||
sub updatembmondata
|
||||
{
|
||||
if ( ! -e "$rrdlog/mbmon.rrd" )
|
||||
{
|
||||
if ( ! -e "$rrdlog/mbmon.rrd" ){
|
||||
# database did not exist -> create
|
||||
|
||||
@args = ("$rrdlog/mbmon.rrd");
|
||||
|
||||
push(@args, "--step=300");
|
||||
foreach $key ( sort(keys %mbmon_values) )
|
||||
{
|
||||
push(@args, "DS:$key:GAUGE:600:U:U");
|
||||
}
|
||||
foreach $key ( sort(keys %mbmon_values) ){push(@args, "DS:$key:GAUGE:600:U:U");}
|
||||
push(@args, "RRA:AVERAGE:0.5:1:576");
|
||||
push(@args, "RRA:AVERAGE:0.5:6:672");
|
||||
push(@args, "RRA:AVERAGE:0.5:24:732");
|
||||
push(@args, "RRA:AVERAGE:0.5:144:1460");
|
||||
|
||||
print("create ". join( ", ", @args)) if ( $dbg );
|
||||
|
||||
RRDs::create (@args);
|
||||
$ERROR = RRDs::error;
|
||||
print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR;
|
||||
@@ -536,8 +442,7 @@ sub updatembmondata
|
||||
my @val;
|
||||
my $template;
|
||||
|
||||
foreach $key ( sort(keys %mbmon_values) )
|
||||
{
|
||||
foreach $key ( sort(keys %mbmon_values) ){
|
||||
push(@ds, $key);
|
||||
push(@val, $mbmon_values{$key});
|
||||
}
|
||||
@@ -560,30 +465,19 @@ sleep 8;
|
||||
###
|
||||
### Squid Graphs
|
||||
###
|
||||
if ( -e "/var/log/squid/access.log") {
|
||||
system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");
|
||||
}
|
||||
if ( -e "/var/log/squid/access.log") {system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1");}
|
||||
|
||||
###
|
||||
### utf8 conversion
|
||||
###
|
||||
if ((${Lang::language} eq 'cs') ||
|
||||
(${Lang::language} eq 'hu') ||
|
||||
(${Lang::language} eq 'pl') ||
|
||||
(${Lang::language} eq 'sk')) {
|
||||
if ((${Lang::language} eq 'cs') || (${Lang::language} eq 'hu') || (${Lang::language} eq 'pl') || (${Lang::language} eq 'sk')) {
|
||||
# Czech, Hungarian, Polish and Slovak character set
|
||||
foreach my $key(keys %Lang::tr) {
|
||||
from_to($tr{$key}, "utf-8", "iso-8859-2");
|
||||
}
|
||||
foreach my $key(keys %Lang::tr) {from_to($tr{$key}, "utf-8", "iso-8859-2");}
|
||||
} elsif (${Lang::language} eq 'tr') {
|
||||
# Turkish
|
||||
foreach my $key(keys %Lang::tr) {
|
||||
from_to($tr{$key}, "utf-8", "iso-8859-9");
|
||||
}
|
||||
foreach my $key(keys %Lang::tr) {from_to($tr{$key}, "utf-8", "iso-8859-9");}
|
||||
} else {
|
||||
foreach my $key(keys %Lang::tr) {
|
||||
from_to($tr{$key}, "utf-8", "iso-8859-1");
|
||||
}
|
||||
foreach my $key(keys %Lang::tr) {from_to($tr{$key}, "utf-8", "iso-8859-1");}
|
||||
}
|
||||
|
||||
###
|
||||
@@ -618,23 +512,12 @@ chomp $newdiskstats;
|
||||
my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`;
|
||||
chomp $status;
|
||||
|
||||
if ($status !~/standby/ || $diskstats ne $newdiskstats)
|
||||
{
|
||||
if (-e "/tmp/hddshutdown-".$array[$#array])
|
||||
{
|
||||
system("unlink /tmp/hddshutdown-".$array[$#array]);
|
||||
}
|
||||
}
|
||||
|
||||
if (-e "/tmp/hddshutdown-".$array[$#array])
|
||||
{
|
||||
$status = " standby\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
$status = " active\n";
|
||||
if ($status !~/standby/ || $diskstats ne $newdiskstats){
|
||||
if (-e "/tmp/hddshutdown-".$array[$#array]){system("unlink /tmp/hddshutdown-".$array[$#array]);}
|
||||
}
|
||||
|
||||
if (-e "/tmp/hddshutdown-".$array[$#array]){$status = " standby\n";}
|
||||
else{$status = " active\n";}
|
||||
|
||||
open(DATEI, ">>/tmp/hddstatus") || die "Datei nicht gefunden";
|
||||
print DATEI $disk."-".$status;
|
||||
@@ -667,10 +550,6 @@ updatembmondata();
|
||||
if (@ipacsum) {
|
||||
updateifdata ("GREEN");
|
||||
updateifdata ("RED");
|
||||
if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) {
|
||||
updateifdata ("ORANGE");
|
||||
}
|
||||
if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) {
|
||||
updateifdata ("BLUE");
|
||||
}
|
||||
if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) {updateifdata ("ORANGE");}
|
||||
if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) {updateifdata ("BLUE");}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user