#!/usr/bin/perl # BSD users will need to change this to /usr/local/bin/perl ############################################################### # By J.R. Greer jrg@albedo.net # ftp://ftp.albedo.net/pub/portmaster/ # http://www.albedo.net/pub/portmaster/ # # (c) 1997,98 all rights reserved # # Version 0.25 # # The program is placed under the GNU Public License (GPL) # You may copy freely or modify the code in anyway as long # as the above information stays intact. # # # This program requires pmwho by johan Persson, jp@abc.se # path to PMWHO $PMWHO = "/sbin/pmwho"; # # The path and name to the CGI $CGI = "http://www.albedo.net/cgi-bin/pmrtm.pl"; # # Define Your portmasters here @PORTMASTERS = ("pm1","pm2","pm3"); # You may need to define them with full names # ("pm1.domain.com ..... # # PORRT is the Key letter to identify the individual Portmasters # it must match Exactly the portmasterd defined above, Letters # Can NOT be duplicated and should be capitals. @PORTT=("A","B","C"); # # # define the number of seconds for auto refresh. $REFRESH="60"; # # These set when the users idle time changes colour $WYELLOW=6; $WRED=20; # # Show tiles $TITLE=1; $SDATE=0; # # Show Host IP (lets You fit a lot more on the screen) $SHIP=0; # $SHIP=1; # turn on IP security $SECURITY = 1; # # A list of IP addresses allowed to use this program # Place the IP of Your workstation here or You will not be able # to use this program. @IPLIST = ( "127.0.0.1", "169.42.55.12", ); # Filter from DNS (Not used) $FILTER = "domain.com"; # # This sets the number of columbs wide to set the display # this can be set to 2,3 or 4 @PORTS must have the same number # of entries per line $WIDTH=3; # @PORTS = ( "A0,A1,A2", "A3,A4,A5", "A6,A7,A8", "A9,A10,A11", "A12,A13,A14", "A15,A16,A17", "A18,A19,A20", "A21,A22,B1", "B2,B3,B4", "B5,B7,B8", "B9,C1,C2", "C3,C4,C5", "C6,C7,C8", "C9,C10,C11", "C12,C13,C14", "C15,C16,C17", "C18,C19,C20", "C21,C22,C23", "C24,C25,C26", "C27,C28,C29"); # # This is used for modem load $NUMPORTS = 59; ########################################################################## # Do not Edit below this line unless You really understand PERL ########################################################################## ####### First Print the HTML Header print "Content-type: text/html\n\n"; if ($SECURITY == 1){ foreach (@IPLIST) { if ($ENV{'REMOTE_ADDR'} eq $_) {$SECURE = 1;} } if ($SECURE == 0) { print "404 Not Found\n"; print "\n"; print "You do not have permission to access this program

"; print "\n"; exit; } } print "Portmaster User RTM\n"; print ""; print "\n"; ####### Now login and get the data from the Portmasters $pms = @PORTMASTERS; FPM: for ($i=0;$i<$pms;$i++) { @list=`$PMWHO $PORTMASTERS[$i]`; foreach (@list) { &o1; $port =~ s/S/$PORTT[$i]/; &o2; } next FPM; } ####### Now display the data print ""; if ($TITLE == 1){ print ""; &headof; if ($WIDTH == 3){ &headof;} if ($WIDTH == 4){ &headof; &headof; } &headof; print ""; } foreach (@PORTS){ if ($WIDTH == 2){ ($L1,$L2) = split(/,/,$_); █ } if ($WIDTH == 3){ ($L1,$L2,$L3) = split(/,/,$_); █ } if ($WIDTH == 4){ ($L1,$L2,$L3,$L4) = split(/,/,$_); █ } } print "

"; $T = int(($use*100)/$NUMPORTS); print "Use $T %
"; ####### Finish the HTML page print ""; exit; ############################### # Print one line of the table sub block { print ""; $TL1 = $L1; &plint; $TL1 = $L2; &plint; if ($WIDTH==3){ $TL1 = $L3; &plint; } if ($WIDTH==4){ $TL1 = $L3; &plint; $TL1 = $L4; &plint; } print "\n"; } ####################################### ### Extract portmaster data ### There is probably a better way to do this :) sub o1 { $t = "$_"; $t =~ s/\s//; $t =~ s/\n//; $t =~ s/\r//; $t =~ s/^(.)(.*)/$1/; next if ($t eq "-" ); next if ($t eq "P" ); $_ =~ s/\s\s\s\s/\040/g; $_ =~ s/\s\s\s/\040/g; $_ =~ s/\s\s/\040/g; $_ =~ s/\s\s/\040/g; ($port, $user, $host, $x, $x1 ,$x2, $start ,$on) = split(/ /, $_); } sub o2 { $t = "$user"; $t =~ s/\s//; $t =~ s/\n//; $t =~ s/\r//; $t =~ s/^(.)(.*)/$1/; next if ($t eq "-" ); $PUSER{$port} = $user; $PHOST{$port} = $host; $PSTART{$port} = $start; $PON{$port} = $on; } ########## # Print one segment of the title row sub headof { print "SxUser"; if ($SHIP == 1) { print "Host";} print "OnI "; } ########### # Print one port sub plint { print ""; if ($PUSER{$TL1} eq "") { print ""; } else { print ""; $use=$use+1; } print "$TL1$PUSER{$TL1}"; if ($SHIP == 1) { print "$PHOST{$TL1}"; } print "$PSTART{$TL1}"; if ($PON{$TL1} <= ($WYELLOW-1)) { print ""; } if ($PON{$TL1} >= $WYELLOW) { if ($PON{$TL1} >= $WRED) { print ""; } else { print ""; } } print "$PON{$TL1}\n"; }