jablonka.czprosek.czf

hotsanic

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

 

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];
44 $icmpin=$acct_int{$nn}[7]-$acct_int_old{$nn}[7];
456simandl $otherout=$acct_int{$nn}[2]-$acct_int_old{$nn}[2];
461simandl $tcpout=$acct_int{$nn}[4]-$acct_int_old{$nn}[4];
47 $udpout=$acct_int{$nn}[6]-$acct_int_old{$nn}[6];
48 $icmpout=$acct_int{$nn}[8]-$acct_int_old{$nn}[8];
496simandl updatedb($args{MODNAME},$time,"int$nn",$tcpin,$udpin,$otherin,$tcpout,$udpout,$otherout);
501simandl }
51 
52 foreach my $nn (sort(keys(%acct_ext))) {
536simandl $otherin=$acct_ext{$nn}[1]-$acct_ext_old{$nn}[1];
541simandl $tcpin=$acct_ext{$nn}[3]-$acct_ext_old{$nn}[3];
55 $udpin=$acct_ext{$nn}[5]-$acct_ext_old{$nn}[5];
56 $icmpin=$acct_ext{$nn}[7]-$acct_ext_old{$nn}[7];
576simandl $otherout=$acct_ext{$nn}[2]-$acct_ext_old{$nn}[2];
581simandl $tcpout=$acct_ext{$nn}[4]-$acct_ext_old{$nn}[4];
59 $udpout=$acct_ext{$nn}[6]-$acct_ext_old{$nn}[6];
60 $icmpout=$acct_ext{$nn}[8]-$acct_ext_old{$nn}[8];
616simandl updatedb($args{MODNAME},$time,"ext$nn",$tcpin,$udpin,$otherin,$tcpout,$udpout,$otherout);
621simandl }
63 }
64 
65sub readfile {
66 my ($file,$IPTABLES)=@_;
67 my $ip="";
68 undef my %hash;
69 open (FILE,$file);
70 while (<FILE>) {
71 chomp;
72 if (index($IPTABLES,"ipchains") >= 0 ) { ($pkt,$bytes,$target,$proto,$opt,$tosa,$tosx,$ifname,$src,$dst)=split; }
73 else { ($pkt,$bytes,$target,$proto,$opt,$in,$out,$src,$dst)=split; }
74 if ($pkt =~ /^[0-9]*$/ ) {
75 if ($dst eq "") { ($proto,$opt,$in,$out,$src,$dst)=($target,$proto,$opt,$in,$out,$src); }
76 if ($src eq "0.0.0.0/0") { $ip=$dst;$dir=1; } elsif ($dst eq "0.0.0.0/0") { $ip=$src;$dir=0; }
77 if ($proto eq "all") { $prt=1 };
78 if ($proto eq "tcp") { $prt=3 };
79 if ($proto eq "udp") { $prt=5 };
80 if ($proto eq "icmp") { $prt=7 };
81 if ($ip ne "") {$hash{"$ip"}[$prt+$dir]=$bytes;}
82 }
83 }
84 close (FILE);
85 return %hash;
86 }
87 
88sub updatedb {
89 my ($MODNAME,$time,$name,$tcpin,$udpin,$icmpin,$tcpout,$udpout,$icmpout)=@_;
90 $name =~ s/\//_/g;
91 if ( !-e "rrd/$name.rrd") { system "./makerrd $name U"; }
92 RRDs::update "rrd/$name.rrd",$time.":".$tcpin.":".$udpin.":".$icmpin.":".$tcpout.":".$udpout.":".$icmpout;
93 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$name.rrd': $ERROR\n"; }
94 }
95 
96 
971;
98 

Powered by WebSVN 2.2.1