#!/usr/bin/perl5 # # By Kevin Kadow (kadow@msg.net), loosely based on Internet Direct's 'pmwho' # Part of the unpublished 'pmweb' web-based portmaster control software. # # This program needs 'pm.pl' in the current or a @INC directory in order # to run. Get it in ftp.rellim.com:/pub/admin/bpmtools2.0.tar.gz # # To use as a CGI script, invoke with '-html' (e.g. in ServerSide Include) # or force $html to 1. require 'pm.pl'; require 'flush.pl'; # # Put your portmaster password, domain, and hostnames here, you can instead # put the password in pm.pl and comment out the $Pass= line here. # $Pass="card$lights"; $domain=".mydomain.com"; @All = ( "aicpm1","aicpm2" ); $count= $#All +1; $LongCall=4; #Flag people who've been on for more than four hours $| = 1; # # Handle command line arguments # while($_=shift) { $Verbose++ if(m/^-v/); $html++ if(m/^-html/); } # # Print the appropriate header # if($html) { $date=`date`; chop $date; print <<"EOF"; Content-type: text/html Refresh: 120
EOF } else { print <<"EOF"; Server ## Username Hostname Status Idle Time Flags EOF } # #Cycle through the list of portmasters # foreach $Host (@All) { portmaster::Connect($Host,$Pass); for ($Cnt = 0; $Cnt <= 29; $Cnt++) { local($Flag,$Status,$address,$Machine); &portmaster::Who("$Cnt"); $Ports++; next if("IDLE" eq $PortValue{$Cnt,STATUS}); $Used++; #if($PortValue{$Cnt, PORT_TYPE} ne "Login/Netwrk" ) { #warn "Port $Cnt on $Host is not configured for Login/Netwrk!!\n"; #}; $User=$PortValue{$Cnt, USERNAME}; $Users{$User}++; if($Users{$User} >1) { # #Logged on more than once! # $Flag="x".$Users{$User}; } $Status=$PortValue{$Cnt, STATUS}, $address=$PortValue{$Cnt,FRAMED_ADDR}; if($address eq "0.0.0.0") { # # Addr9 is just a guess. # $address=$PortValue{$Cnt,Addr9}; } else { $Status="SLIP/PPP"; $SLIP++; } # # Convert their time online to human readable, flag long calls # $time=$PortValue{$Cnt, STARTTIME}; $hours=int($time / 60); $Flag.="!" if($hours >$LongCall); $minutes= $time % 60; unless($Machine=$lookup{$address}) { $Machine=$address unless($Machine=&address2name($address)); $Machine=~ s/$domain//; $lookup{$address}=$Machine; } $Total{$Machine}++ unless($Status eq "SLIP/PPP"); printf "$Host-S%2.2d %-10s %-15s %15s %4d %2d:%2.2d %s\n", $Cnt, $User, $Machine, $Status, $PortValue{$Cnt, IDLETIME},$hours,$minutes,$Flag; } close(portmaster'DS); } # # Print the trailer # print "\n"; print "
" if($html); foreach $Machine (keys(%Total)) { if($html) { print "${Machine}: $Total{$Machine}
\n"; } else { print "$Machine:$Total{$Machine} " } } if($html) { print "SLIP: ${SLIP}
\n"; print "Total $Used of $Ports\n"; } else { print "SLIP/PPP: $SLIP = $Used/$Ports\n"; } exit; sub address2name { local($addr,@bytes)=@_; local($name,$aliases,$addrtype,$length,@addrs); ($name,$aliases,$addrtype,$length,@addrs) = gethostbyname($addr); ($name,$aliases,$addrtype,$length,@addrs) = gethostbyaddr($addrs[0],$addrtype); return($name); }