#! /usr/bin/perl # # # use GDBM_File; use Time::Local; $datafile="/home/wleiden/stats/mrtg/users.gdbm"; $ddir="/home/wleiden/stats/mrtg/data"; $htmldir="/home/wleiden/public_html/mrtg/users/"; $now=localtime($unow=time()); chdir($ddir) || die "Could not chdir to $ddir\n"; foreach $file (<*.debug>) { if ($file=~/(\S+?).gdbm.debug/) {$node=$1;} else {$node="unknown";} open(FILE,$file) || die "Could not open file: $file\n"; #print STDERR "Doing: $file\n"; while () { chomp(); if (/XXX-(.*)/) {$doing=$1;next;} if ($doing=~/users-(\S+)/) { $if=$1; if (/^(\S+)\s+.*ASSOC.*/) { $mac=lc($1); $ASSOC{$mac}=1; $NODE{$mac}=$node; $IF{$mac}=$if; #print "$_\n"; } } elsif ($doing=~/wicontrol/) { if (/Station name:\s*\[\s*(.+)\s*\]/) { $nick=$1; } elsif (/MAC address:\s*\[\s*(\S+)\s*\]/) { $mac=lc($1); $NICK{$mac}=$nick; #print "WICTRL MAC $mac=$nick\n"; $nick=''; } } elsif ($doing=~/ARP/) { if (/\(([0-9.]+)\)\s+at\s+([0-9a-f:]{17})/) { $ip=$1;$mac=lc($2); $ARP{$mac}=$1; #print "ARP IP=$ip=$mac\n"; } } elsif ($doing=~/dhcp/) { if (/lease (\S+) {$/) {$ip=$1;} if (/hardware ethernet (\S+);$/) {$mac=$1;} if (/ends (\d+) (\S+) (\S+);$/) { $a=$1;$date=$2;$time=$3; ($hour,$min,$sec)=split(/:/,$time); ($year,$mon,$mday)=split(/\//,$date); $ends=timegm($sec,$min,$hour,$mday,$mon-1,$year); #printf "$ends = $year-$mon-$mday $hour;$min;$sec = %s\n",$s=localtime($ends) } if (/client-hostname "(.*)";$/) {$hostname=$1;} if (/^}$/) { if (($NICK{$mac} eq '') || ($DHCP{$mac})) { if ($ends > $now-300) { $ARP{$mac}=$ip; if ($hostname) {$NICK{$mac}=$hostname;} else {$NICK{$mac}="dhcp";} $DHCP{$mac}=1; } else {$ARP{$mac}=$ip;$NICK{$mac}="dhcp expired";} } $mac=$ip=$hostname=''; } } } close(FILE); } $users=0; $links=0; foreach $mac (keys %ASSOC) { if ($ARP{$mac}!~/^172.16/) {$users++;} else {$links++;}} open (INDEX,">$htmldir/index.html") || die; print INDEX < Users on Wireless Leiden

Currently $users Users and $links Links on wireless Leiden

EOI tie %USERS,'GDBM_File',"$datafile", &GDBM_WRCREAT, 0640 || die "Could not open file: $datafile\n"; foreach $mac (sort bynode keys %ASSOC) { # print "$mac $IF{$mac}\@$NODE{$mac}\t$ARP{$mac}\t$NICK{$mac}\n"; if ($ARP{$mac}=~/^172.16/) {$b="";$islink=1;} else {$b="";$islink=0;} print INDEX < EOI2 $USERS{$mac}="$unow|$IF{$mac}|$NODE{$mac}|$ARP{$mac}|$NICK{$mac}|$islink|"; } untie(%USERS); print INDEX <

users Traffic Graph

users Traffic Graph today

users Traffic Graph last week

users Traffic Graph last month

users Traffic Graph last year

Generated at: $now EOF close(INDEX); printf "%.0f\n",abs($users); printf "%.0f\n",abs($links); printf "%.0f\n",0; printf "\n"; sub bynode { return("$NODE{$a}$IF{$a}" cmp "$NODE{$b}$IF{$b}"); }

MAC interf. NODE IP Nick
$b$mac $b$IF{$mac} $b$NODE{$mac} $b$ARP{$mac} $b$NICK{$mac}