#! /usr/bin/perl # # # use GDBM_File; use Time::Local; $datafile="/home/wleiden/stats/mrtg/users.gdbm"; tie %USERS,'GDBM_File',"$datafile", &GDBM_READER, 0640 || die "Could not open file: $datafile\n"; $now=localtime($limit=$unow=time()); $day=24*60*60; $week=7*$day; $month=30*$day; $year=365*$day; $mode=$ARGV[0]; $limit-=300; if ($mode eq 1) {$limit-=$day;} elsif ($mode eq 2) {$limit-=$week;} elsif ($mode eq 3) {$limit-=$month;} elsif ($mode eq 4) {$limit-=$year;} else {$limit-=300;} foreach $mac (keys %USERS) { $value=$USERS{$mac}; ($lastseen,$IF,$NODE,$ARP,$NICK,$islink,$junk)=split(/\|/,$value); #print "$mac=$lastseen,$IF,$NODE,$ARP,$NICK,$link\n"; if ($lastseen < $limit) {next;} #{print "$lastseen < $limit\n"; next;} if ($islink) {$links++;} else {$users++;} } untie(%USERS); if ($mode < 5) { $in=abs($users); $out=abs($links); } else { $total_datafile="/home/wleiden/stats/mrtg/total_stats.gdbm"; tie %TOTAL_DATA,'GDBM_File',"$total_datafile", &GDBM_READER, 0640|| die "Could not open file:$total_datafile\n"; if ($mode eq 5) { $in=$TOTAL_DATA{"bytes-links-in"}; $out=$TOTAL_DATA{"bytes-links-out"}; if ($links > 0) {$in=$in/$links;$out=$out/$links;} } elsif ($mode eq 6) { $in=$TOTAL_DATA{"bytes-users-in"}; $out=$TOTAL_DATA{"bytes-users-out"}; if ($links > 0) {$in=$in/$users;$out=$out/$users;} } untie(%TOTAL_DATA); } printf "%.0f\n",$in; printf "%.0f\n",$out; printf "%.0f\n",0; printf "\n";