jablonka.czprosek.czf

hotsanic

Subversion Repositories:
[/] [trunk/] [modules/] [iwconf/] [platform/] [default.pm.old03] - Blame information for rev 25

 

Line No. Rev Author Line
11simandlpackage HotSaNICmod::OSdep;
2 
3use RRDs;
4 
5sub version {
6 ($VERSION = '$Revision: 1.0 $') =~ s/.*(\d+\.\d+).*/$1/;
7 my $platform;
8 foreach (keys(%INC)) { $platform=$_ if $_ =~ /platform/; }
9 return "$platform $VERSION";
10}
11 
12sub sample {
13 
14#uncomment this for debug output to temp.txt
15#all print will be done into the file
16#$temp = "/opt/HotSaNIC/modules/iwconf/temp.txt";
17#open (TEMPFILE,">$temp");
18#open (STDERR,">&TEMPFILE") || die ("open STDERR failed");
19#open (STDOUT,">&TEMPFILE") || die ("open STDOUT failed");
20 
21 
22 my %args=@_;
23 
24 $mtime=(stat("rrd"))[9];
25 $now=time;
26 
27 utime $now,$now,"rrd";
28 
29 $IWCONF = $args{IWCONFIG};
30 $IWLIST = $args{IWLIST};
31 $hostap = $args{HOSTAP};
32 
33 
34 my @IFACES=();
35 my @IFMACS=();
36 
37 foreach (keys(%args)) {
38 if (index($_,"IFACE:") >=0 ) {
39 (undef,$device)=split /:/;
40 push @IFACES,$device;
41 }
42 }
43 foreach (keys(%args)) {
44 if (index($_,"MAC,") >=0 ) {
45 (undef,$dev,$mac)=split /,/;
46 push @IFMACS,"$dev,$mac";
47 }
48 }
49 
50 foreach $device (@IFACES) {
51 my $rate = 0;
52 my $quality = 0;
53 my $signal = 0;
54 my $noise = 0;
55 my $mode = 0;
56 
57 $command = "$IWCONF $device";
58 open (FILE,"$command|");
59 while(<FILE>) {
60 $var=$_;
61 if ($var =~ /^.*Rate[=|:]+(.*)M.*/) {
62 $rate = $1;
63 } elsif ($var =~ /^.*Quality[=|:]+(.*)\/.*[=|:](.*)\sdBm.*[=|:](.*)\sdBm.*/) {
64 $quality = $1;
65 $signal = $2;
66 $noise = $3;
67 last;
68 } elsif ($var =~ /^.*Mode[=|:]+(.*) Fre.*/ ) {
69 $mode=$1;
70 }
71 }
72 close(FILE);
73 $rate=$rate*1;
74 
75 if ( $mode eq "Managed" ) {
76 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
77 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise;
78 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
79 }
80 
81 if ( $mode eq "Ad-Hoc" ) {
82 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
83 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$quality.":".$signal.":".$noise;
84 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
85 }
86 
87#print "$device\n";
88 
89 if (( $mode eq "Master" ) && ( $device =~ /ath(.*)/ )) {
90 $IFMACSNR[0]=7;
91 $IFMACSNR[1]=4;
92 $clients = 0;
93 $madwifing=0;
94 $wlancmd = "/usr/local/bin/wlanconfig";
95# (-e $wlancmd) || $madwifing=0;
96 
97 if ( $madwifing == 1 ) {
98 ############# madwifi-ng ###########
99 #getting all clients into variable
100 $command = "$wlancmd $device list sta | grep ^0";
101#print "ng: $command\n";
102 #processing all clients to get mac and signal
103#print "twu som @macline \n";
104 open (FILE,"$command|");
105 while(<FILE>) {
106 $var=$_;
107 @macline=split(" ",$var);
108#print "tu som @macline \n";
109 $clients = $clients + 10;
110 
111 $mac = shift(@macline);
112 $signal = shift(@macline);
113 $signal = shift(@macline);
114 $signal = shift(@macline);
115 $signal = shift(@macline);
116#print "mac adresa : $mac ma signal $signal\n";
117#print "mac adresy : @IFMACS\n";
118 $nummac = 0;
119 foreach $ifmac (@IFMACS) {
120 ($ifmaci,$ifmacm)=split(/,/,$ifmac);
121 if ($ifmaci eq $device ) {
122 if ($ifmacm eq $mac) {
123#print "$ifmaci $ifmacm $ifmac\n";
124 $IFMACSNR[$nummac]=$signal;
125 }
126 $nummac = $nummac + 1;
127 } # if
128 } # foreach
129 } # while
130 close(FILE);
131 } # if
132 else { ############# old madwifi ###########
133 $command = "$IWLIST $device peers | grep 00 | tr \"A-Z\" \"a-z\"";
134#print "old: $command\n";
135 open (FILE,"$command|");
136 while(<FILE>) {
137 $var=$_;
138 $clients = $clients + 10;
139 if ($var =~ /^\s*(.*)\s:\s.*quality[=|:]+(.*)\/.*/) {
140 $signal = $2;
141 $mac = $1;
142#print "$1 $2\n";
143#print "@IFMACS\n";
144 $nummac = 0;
145 foreach $ifmac (@IFMACS) {
146 ($ifmaci,$ifmacm)=split(/,/,$ifmac);
147 if ($ifmaci eq $device ) {
148 if ($ifmacm eq $mac) {
149#print "$ifmaci $ifmacm $ifmac\n";
150 $IFMACSNR[$nummac]=$signal;
151 }
152 $nummac = $nummac + 1;
153 } # if
154 } # foreach
155 } # if
156 } # while
157 close(FILE);
158 }
159############# old madwifi ###########
160 
161 if ($IFMACSNR[0] eq "") {
162 $IFMACSNR[0]=1;
163 }
164 if ($IFMACSNR[1] eq "") {
165 $IFMACSNR[1]=2;
166 }
167#print "@IFMACSNR\n";
168 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
169 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1];
170 if ($ERROR = RRDs::error) { print time," ",$MODNAME,": unable to update `$device.rrd': $ERROR"; }
171 } # if
172 
173 if (( $mode eq "Master" ) && ( $device =~ /wlan(.*)/ )) {
174 @clients = glob( "/proc/net/hostap/$device/00*" );
175 $clients = @clients;
176 $clients = $clients*10;
177 $signal=0;
178 $noise=0;
179 @IFMACSNR=();
180 foreach $ifmac (@IFMACS)
181 {
182 ($ifmaci,$ifmacm)=split(/,/,$ifmac);
183 if ($ifmaci eq $device ) {
184 $iwmsnr=0;
185 if ( -r "/proc/net/hostap/$ifmaci/$ifmacm" )
186 {
187 open (FILE,"/proc/net/hostap/$ifmaci/$ifmacm");
188 while(<FILE>)
189 {
190 $var=$_;
191 if ($var =~ /^.*silence=+(.*) dBm.*signal=+(.*) dBm.*rate=.*/)
192 {
193 ($iwmsilence,undef)=split(/ /,$1);
194 ($iwmsignal,undef)=split(/ /,$2);
195 $iwmsnr=$iwmsignal-$iwmsilence;
196 last;
197 }
198 }
199 close(FILE);
200 }
201 push @IFMACSNR,$iwmsnr;
202 }
203 }
204 push @IFMACSNR,15;
205 push @IFMACSNR,25;
206 if ($IFMACSNR[0] eq "") {
207 $IFMACSNR[0]=11;
208 }
209 if ($IFMACSNR[1] eq "") {
210 $IFMACSNR[1]=22;
211 }
212 
213 if ( ! -e "rrd/$device.rrd" ) { system("./makerrd","$device","U") }
214 RRDs::update "rrd/$device.rrd",time.":".$rate.":".$clients.":".$IFMACSNR[0].":".$IFMACSNR[1];
215 if ($ERROR = RRDs::error) { dupe_control("warn",$ARGS{"MODNAME"},"unable to update `$device.rrd': $ERROR"); }
216 }
217 }
218# close (TEMPFILE);
219# close (STDERR);
220# close (STDOUT);
221}
2221;

Powered by WebSVN 2.2.1