jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [networks/] [platform/] [linux.pm] - Blame information for rev 10

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::OSdep;
2 
3use RRDs;
4use lib "../../lib";
5 
6sub version {
7 ($VERSION = '$Revision: 1.4 $') =~ s/.*(\d+\.\d+).*/$1/;
8 return "$^O.pm $VERSION";
9 }
10 
11sub sample {
12 my %args=@_;
13 
14 my $IPTABLES=$args{IPTABLES};
15 
16 if ( (! -e "acct_int.dat") || (! -e "acct_ext.dat")) {
176simandl system("$IPTABLES -L acct_int_other -xvn > acct_int.dat");
18 system("$IPTABLES -L acct_ext_other -xvn > acct_ext.dat");
19 foreach $prt ("tcp","udp") {
20 system("$IPTABLES -L acct_int_$prt -xvn | sed 's/all/$prt/g' >> acct_int.dat");
21 system("$IPTABLES -L acct_ext_$prt -xvn | sed 's/all/$prt/g' >> acct_ext.dat");
225simandl system("$IPTABLES -L acct_int_$prt -xvn >> acct_int.dat");
23 system("$IPTABLES -L acct_ext_$prt -xvn >> acct_ext.dat");
24 }
251simandl }
26 
27 my %acct_int_old=readfile("acct_int.dat",$IPTABLES);
28 my %acct_ext_old=readfile("acct_ext.dat",$IPTABLES);
296simandl system("$IPTABLES -L acct_int_other -xvn > acct_int.dat");
30 system("$IPTABLES -L acct_ext_other -xvn > acct_ext.dat");
31 foreach $prt ("tcp","udp") {
325simandl system("$IPTABLES -L acct_int_$prt -xvn | sed 's/all/$prt/g' >> acct_int.dat");
33 system("$IPTABLES -L acct_ext_$prt -xvn | sed 's/all/$prt/g' >> acct_ext.dat");
34 }
351simandl my %acct_int=readfile("acct_int.dat",$IPTABLES);
36 my %acct_ext=readfile("acct_ext.dat",$IPTABLES);
37 
38 my $time=time;
39 
40 foreach my $nn (sort(keys(%acct_int))) {
416simandl $otherin=$acct_int{$nn}[1]-$acct_int_old{$nn}[1];
421simandl $tcpin=$acct_int{$nn}[3]-$acct_int_old{$nn}[3];
43 $udpin=$acct_int{$nn}[5]-$acct_int_old{$nn}[5];
446simandl $otherout=$acct_int{$nn}[2]-$acct_int_old{$nn}[2];
451simandl $tcpout=$acct_int{$nn}[4]-$acct_int_old{$nn}[4];
46 $udpout=$acct_int{$nn}[6]-$acct_int_old{$nn}[6];
476simandl updatedb($args{MODNAME},$time,"int$nn",$tcpin,$udpin,$otherin,$tcpout,$udpout,$otherout);
481simandl }
49 
50 foreach my $nn (sort(keys(%acct_ext))) {
516simandl $otherin=$acct_ext{$nn}[1]-$acct_ext_old{$nn}[1];
521simandl $tcpin=$acct_ext{$nn}[3]-$acct_ext_old{$nn}[3];
53 $udpin=$acct_ext{$nn}[5]-$acct_ext_old{$nn}[5];
546simandl $otherout=$acct_ext{$nn}[2]-$acct_ext_old{$nn}[2];
551simandl $tcpout=$acct_ext{$nn}[4]-$acct_ext_old{$nn}[4];
56 $udpout=$acct_ext{$nn}[6]-$acct_ext_old{$nn}[6];
576simandl updatedb($args{MODNAME},$time,"ext$nn",$tcpin,$udpin,$otherin,$tcpout,$udpout,$otherout);
581simandl }
59 }
60 
61sub readfile {
62 my ($file,$IPTABLES)=@_;
63 my $ip="";
64 undef my %hash;
65 open (FILE,$file);
66 while (<FILE>) {
67 chomp;
68 if (index($IPTABLES,"ipchains") >= 0 ) { ($pkt,$bytes,$target,$proto,$opt,$tosa,$tosx,$ifname,$src,$dst)=split; }
69 else { ($pkt,$bytes,$target,$proto,$opt,$in,$out,$src,$dst)=split; }
70 if ($pkt =~ /^[0-9]*$/ ) {
71 if ($dst eq "") { ($proto,$opt,$in,$out,$src,$dst)=($target,$proto,$opt,$in,$out,$src); }
72 if ($src eq "0.0.0.0/0") { $ip=$dst;$dir=1; } elsif ($dst eq "0.0.0.0/0") { $ip=$src;$dir=0; }
73 if ($proto eq "all") { $prt=1 };
74 if ($proto eq "tcp") { $prt=3 };
75 if ($proto eq "udp") { $prt=5 };
76 if ($ip ne "") {$hash{"$ip"}[$prt+$dir]=$bytes;}
77 }
78 }
79 close (FILE);
80 return %hash;
81 }
82 
83sub updatedb {
847simandl my ($MODNAME,$time,$name,$tcpin,$udpin,$otherin,$tcpout,$udpout,$otherout)=@_;
851simandl $name =~ s/\//_/g;
86 if ( !-e "rrd/$name.rrd") { system "./makerrd $name U"; }
877simandl RRDs::update "rrd/$name.rrd",$time.":".$tcpin.":".$udpin.":".$otherin.":".$tcpout.":".$udpout.":".$otherout;
881simandl if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$name.rrd': $ERROR\n"; }
89 }
90 
91 
921;
93 

Powered by WebSVN 2.2.1