Lines 36-41
$png = $co->param('png');
Link Here
|
36 |
$mminy=60-50; |
36 |
$mminy=60-50; |
37 |
$mmaxy=420-50; |
37 |
$mmaxy=420-50; |
38 |
|
38 |
|
|
|
39 |
# http://192.168.2.1/lightsquid/graph.cgi?year=2009&month=07&mode=month |
40 |
#$year="2009"; |
41 |
#$month="06"; |
42 |
#$mode="month"; |
43 |
#$png=1; |
44 |
# |
45 |
#http://192.168.2.1/lightsquid/graph.cgi?year=2009&month=07&mode=user&user=192.168.2.1 |
46 |
#$year="2009"; |
47 |
#$month="07"; |
48 |
#$mode="user"; |
49 |
#$user="192.168.2.1"; |
50 |
|
39 |
my @MAP; |
51 |
my @MAP; |
40 |
|
52 |
|
41 |
sub fixnum($) { |
53 |
sub fixnum($) { |
Lines 50-64
sub fixnum($) {
Link Here
|
50 |
sub GetY($) { |
62 |
sub GetY($) { |
51 |
my $value = shift; |
63 |
my $value = shift; |
52 |
my $all = $mmaxy - 30; |
64 |
my $all = $mmaxy - 30; |
53 |
my $diapazon = 5; |
65 |
# my $diapazon = 5; |
54 |
my $indep = $all / $diapazon; |
66 |
# my $indep = $all / $diapazon; |
55 |
|
|
|
56 |
my $tmp = $all / $max; |
57 |
|
58 |
if ( $max < $value ) { $value = $max; } |
59 |
|
60 |
my $y = $mmaxy - $value * $tmp; |
61 |
|
67 |
|
|
|
68 |
my $tmp=$all/($automax-$automin); |
69 |
if ( $automax < $value ) { $value = $automax; } |
70 |
my $y=$mmaxy-($value-$automin)*$tmp; |
62 |
return int($y); |
71 |
return int($y); |
63 |
} ## end sub GetY($) |
72 |
} ## end sub GetY($) |
64 |
|
73 |
|
Lines 126-131
sub InitGraph() {
Link Here
|
126 |
$black = $im->colorAllocate( 0, 0, 0 ); |
135 |
$black = $im->colorAllocate( 0, 0, 0 ); |
127 |
$blue = $im->colorAllocate( 35, 35, 227 ); |
136 |
$blue = $im->colorAllocate( 35, 35, 227 ); |
128 |
$dimgray = $im->colorAllocate( 105, 105, 105 ); |
137 |
$dimgray = $im->colorAllocate( 105, 105, 105 ); |
|
|
138 |
$dimgray2 = $im->colorAllocate( 170, 170, 170 ); |
129 |
$darkblue = $im->colorAllocate( 0, 0, 139 ); |
139 |
$darkblue = $im->colorAllocate( 0, 0, 139 ); |
130 |
$goldenrod = $im->colorAllocate( 234, 234, 174 ); |
140 |
$goldenrod = $im->colorAllocate( 234, 234, 174 ); |
131 |
$goldenrod2 = $im->colorAllocate( 207, 181, 59 ); |
141 |
$goldenrod2 = $im->colorAllocate( 207, 181, 59 ); |
Lines 190-230
sub InitGraph() {
Link Here
|
190 |
#50M- show only line |
200 |
#50M- show only line |
191 |
#50M. skip this value |
201 |
#50M. skip this value |
192 |
|
202 |
|
193 |
#MONTH |
|
|
194 |
$gridvalues{month} = [ "50M-", "100M", "150M-", "200M", "250M-", "300M", "350M-", "400M", "450M-", "500M", "550M.", "600M", "700M", "800M", "900M", "1G", "2G", "3G", "4G", "5G", "6G", "7G", "8G", "9G" , "10G" , "15G" , "20G", "25G", "30G" ]; |
195 |
|
196 |
#USER |
197 |
$gridvalues{user} = [ "5M", "10M", "15M", "20M", "25M", "30M", "35M", "40M", "45M", "50M", "55M", "60M.", "70M", "80M.", "90M", "1G", "2G", "3G", "4G", "5G" ]; |
198 |
|
199 |
$hh{"K"} = 1024; |
203 |
$hh{"K"} = 1024; |
200 |
$hh{"M"} = 1024 * 1024; |
204 |
$hh{"M"} = 1024 * 1024; |
201 |
$hh{"G"} = 1024 * 1024 * 1024; |
205 |
$hh{"G"} = 1024 * 1024 * 1024; |
202 |
$hh{"T"} = 1024 * 1024 * 1024 * 1024; |
206 |
$hh{"T"} = 1024 * 1024 * 1024 * 1024; |
203 |
|
207 |
|
204 |
for ( $i = 0 ; $i < $#{ $gridvalues{$mode} } + 1 ; $i++ ) { |
208 |
$numberoflines=10; |
205 |
$gridvalues{$mode}[$i] =~ m/(\d*)(\D)([\.-])?/; |
209 |
$base=10; |
206 |
|
210 |
$autostep=$automax-$automin; |
207 |
$flag = $3; |
211 |
$automax=$numberoflines*1024+$automin if($autostep<$numberoflines*1024); |
208 |
next if ( $flag eq "." ); |
212 |
$autostep=$automax-$automin; |
209 |
|
213 |
$autostep=1 if($autostep==0); |
210 |
$v = $1 * $hh{$2}; |
214 |
$autostep/=($numberoflines); |
211 |
$y = GetY($v) - 5; |
215 |
$prepow=int(log($autostep)/log(2**10)); |
212 |
|
216 |
$prepow++ if($automax/$autostep>$base); |
213 |
next if ( $v > $max ); |
217 |
$autostep/=(2**10)**$prepow; |
214 |
|
218 |
$pow=int(log($autostep)/log($base)); |
215 |
$im->line( 60, $y, 700, $y, $dimgray ); |
219 |
$step=$autostep/$base**$pow; |
216 |
|
220 |
#print("$step\n"); |
217 |
$im->line( 50, $y + 5, 60, $y, $dimgray ); |
221 |
if ($step<=0.1) {$step=0.1;} |
218 |
$im->line( 47, $y + 5, 50, $y + 5, $dimgray ); |
222 |
elsif($step<=0.2) {$step=0.2;} |
219 |
|
223 |
elsif($step<=0.5) {$step=0.5;} |
220 |
next if ( $flag eq "-" ); |
224 |
elsif($step<=1) {$step=1;} |
221 |
|
225 |
elsif($step<=2) {$step=2;} |
222 |
$im->string( gdSmallFont, 21, $y - 2, fixnum($v), $dimgray ); |
226 |
elsif($step<=5) {$step=5;} |
223 |
} ## end for ( $i = 0 ; $i < $#{... |
227 |
else {$step=10;}; |
224 |
|
228 |
$autostep=$step*$base**$pow*(2**10)**$prepow; |
225 |
#axis name |
229 |
$automin1=int($automin/$autostep)*$autostep; |
226 |
$im->stringUp( gdLargeFont, 20 - 15, 248 - 9, "BYTES", $dimgray ); |
230 |
$automax1=int($automax/$autostep)*$autostep; |
227 |
$im->string( gdLargeFont, 330 + 15, $mmaxy + 20, "DAYS", $dimgray ); |
231 |
if($automin1>$automin) { |
|
|
232 |
$automin=int($automin/$autostep-1)*$autostep; |
233 |
} else { |
234 |
$automin=$automin1; |
235 |
}; |
236 |
|
237 |
if($automax1<$automax) { |
238 |
$automax=int($automax/$autostep+1)*$autostep; |
239 |
} else { |
240 |
$automax=$automax1; |
241 |
} |
242 |
|
243 |
for($v=$automin; $v<=$automax; $v+=$autostep/2) { |
244 |
$y=GetY($v); |
245 |
$im->line( 60, $y, 700, $y, $dimgray2 ); |
246 |
$im->line( 50, $y + 5, 60, $y, $dimgray2 ); |
247 |
$im->line( 47, $y + 5, 50, $y + 5, $dimgray2 ); |
248 |
#$im->string( gdSmallFont, 21, $y - 2, fixnum($v), $dimgray2 ); |
249 |
} |
250 |
|
251 |
for($v=$automin; $v<=$automax; $v+=$autostep) { |
252 |
$y=GetY($v); |
253 |
$im->line( 60, $y, 700, $y, $dimgray ); |
254 |
$im->line( 50, $y + 5, 60, $y, $dimgray ); |
255 |
$im->line( 47, $y + 5, 50, $y + 5, $dimgray ); |
256 |
$im->string( gdSmallFont, 21, $y - 2, fixnum($v), $dimgray ); |
257 |
} |
258 |
|
259 |
#axis name |
260 |
$im->stringUp( gdLargeFont, 20 - 15, 248 - 9, "BYTES", $dimgray ); |
261 |
$im->string( gdLargeFont, 330 + 15, $mmaxy + 20, "DAYS", $dimgray ); |
228 |
} ## end sub InitGraph($$$) |
262 |
} ## end sub InitGraph($$$) |
229 |
|
263 |
|
230 |
|
264 |
|
Lines 233-239
sub InitGraph() {
Link Here
|
233 |
if ( $mode eq "user" ) { $max = $graphmaxuser; $varname="graphmaxuser";} |
267 |
if ( $mode eq "user" ) { $max = $graphmaxuser; $varname="graphmaxuser";} |
234 |
if ( $mode eq "month" ) { $max = $graphmaxall; $varname="graphmaxall";} |
268 |
if ( $mode eq "month" ) { $max = $graphmaxall; $varname="graphmaxall";} |
235 |
|
269 |
|
236 |
$max=1 if ($max == 0); #div0 protection |
270 |
$average = 0; |
|
|
271 |
$days = 0; |
272 |
$automin = 0; |
273 |
$automax = 0; |
274 |
|
275 |
#$max=1 if ($max == 0); #div0 protection |
276 |
$filter = "$year$month"; |
277 |
@daylist = glob("$reportpath/$filter*"); |
278 |
foreach $daypath ( sort @daylist ) { |
279 |
open FF, "<$daypath/.total"; |
280 |
$tmp = <FF>; |
281 |
$size = <FF>; |
282 |
chomp $size; |
283 |
$size =~ s/^size: //; |
284 |
$daypath =~ m/(\d\d\d\d)(\d\d)(\d\d)/; |
285 |
if ( $mode eq "month" ) { |
286 |
# bar( $3, $size ); |
287 |
$bars{$3}=$size; |
288 |
$average += $size; |
289 |
} |
290 |
elsif ( $mode eq "user" ) { |
291 |
while (<FF>) { |
292 |
( $user_, $size, $hit ) = split; |
293 |
if ( $user_ eq $user ) { |
294 |
# bar( $3, $size ); |
295 |
$bars{$3}=$size; |
296 |
$average += $size; |
297 |
} |
298 |
} |
299 |
} ## end elsif ( $mode eq "user" ) |
300 |
$days++; |
301 |
close FF; |
302 |
} ## end foreach $daypath ( sort @daylist) |
303 |
|
304 |
if(0==$max) { |
305 |
while(($bday,$bytes)=each(%bars)) { |
306 |
$automin=$bytes if($automin==0); |
307 |
$automax=$bytes if($automax==0); |
308 |
$automin=$bytes if($automin>$bytes); |
309 |
$automax=$bytes if($automax<$bytes); |
310 |
} |
311 |
if($automin==$automax) { |
312 |
$automax=1000 if(0==$automax); |
313 |
$automin=0; |
314 |
} |
315 |
} else { |
316 |
$automin=0; |
317 |
$automax=$max; |
318 |
} |
237 |
|
319 |
|
238 |
if ( $png == 1 ) { |
320 |
if ( $png == 1 ) { |
239 |
print "Content-type: image/png\n\n"; |
321 |
print "Content-type: image/png\n\n"; |
Lines 260-291
if ( $png == 1 ) {
Link Here
|
260 |
ReplaceTPL( MODE, $txtmode ); |
342 |
ReplaceTPL( MODE, $txtmode ); |
261 |
} |
343 |
} |
262 |
|
344 |
|
|
|
345 |
while (($bday,$bytes)=each(%bars)) { |
346 |
bar($bday,$bytes); |
347 |
} |
263 |
|
348 |
|
264 |
$average = 0; |
|
|
265 |
$days = 0; |
266 |
$filter = "$year$month"; |
267 |
@daylist = glob("$reportpath/$filter*"); |
268 |
foreach $daypath ( sort @daylist ) { |
269 |
open FF, "<$daypath/.total"; |
270 |
$tmp = <FF>; |
271 |
$size = <FF>; |
272 |
chomp $size; |
273 |
$size =~ s/^size: //; |
274 |
$daypath =~ m/(\d\d\d\d)(\d\d)(\d\d)/; |
275 |
|
349 |
|
276 |
if ( $mode eq "month" ) { |
|
|
277 |
bar( $3, $size ); |
278 |
$average += $size; |
279 |
} |
280 |
elsif ( $mode eq "user" ) { |
281 |
while (<FF>) { |
282 |
( $user_, $size, $hit ) = split; |
283 |
if ( $user_ eq $user ) { bar( $3, $size ); $average += $size; } |
284 |
} |
285 |
} ## end elsif ( $mode eq "user" ) |
286 |
$days++; |
287 |
close FF; |
288 |
} ## end foreach $daypath ( sort @daylist) |
289 |
|
350 |
|
290 |
if ( $png == 1 ) { |
351 |
if ( $png == 1 ) { |
291 |
|
352 |
|
Lines 323-332
else {
Link Here
|
323 |
|
384 |
|
324 |
|
385 |
|
325 |
$maxaverage /= ($maxaverageday+1); |
386 |
$maxaverage /= ($maxaverageday+1); |
326 |
ReplaceTPL( VARVALUE,sprintf("%1.2f",int(($maxaverage+($maxaverage*0.30))/(1024*1024*1024/10)+1)/10)); |
387 |
ReplaceTPL( VARVALUE,sprintf("%1.2f",int(($maxaverage+($maxaverage*0.30))/(1024*1024*1024/10)+1)/10)); |
327 |
ReplaceTPL( VARNAME,$varname); |
388 |
ReplaceTPL( VARNAME,$varname); |
328 |
ReplaceTPL(MSG_HEADER_URL,"index.cgi"); |
389 |
ReplaceTPL(MSG_HEADER_URL,"index.cgi"); |
329 |
HideTPL("warning") if ($maxcntr < 7); |
390 |
HideTPL("warning") if(($maxcntr < 7)||(0==$max)); |
330 |
|
391 |
|
331 |
ApplyTPL(); |
392 |
ApplyTPL(); |
332 |
PrintTPL(); |
393 |
PrintTPL(); |