#!/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.33
#
# 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. Make sure pmwho can be executed
$PMWHO = "/bin/pmwho";
#
# The path and name to the CGI
$CGI = "http://www.albedo.net/cgi-bin/pmrtm";
#
# Define Your portmasters here
@PORTMASTERS = ("pm1","pm2","pm3");
#
# PORRT is the Key letter to identify the individual Portmasters
# it must match Exactly the portmaster 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;
#
# These set the Online Time colour change (in Hours)
$OYELLOW=2;
$OORANGE=5;
$OPINK=8;
$ORED=18;
# note over 1 day will be red
# this will cause the online time to flash if over 24 hours
$BLINKONDAY=1;
#
# Show tiles
$TITLE=0;
$SDATE=0;
#
# Show Host IP (lets You fit a lot more on the screen)
$SHIP=0;
#
# turn on IP security
$SECURITY = 0;
#
# A list of IP addresses allowed to use this program
@IPLIST = (
"127.0.0.1",
"10.0.0.1"
);
# Filter from DNS (not Yet Used)
$FILTER = "albedo.net";
#
# This sets the number of columns wide to set the display
# this can be set to 2,3,4 or 5 @PORTS must have the same number
# of entries per line
$WIDTH=4;
#
@PORTS = (
"A0,A1,A2,A3",
"A4,A5,A6,A7",
"A8,A9,A10,A11",
"A12,A13,A14,A15",
"A16,A17,A18,A19",
"A20,A21,A22,A24",
"A25,A26,A27,A28",
"A29,A30,A31,A32",
"A33,A34,A35,A36",
"A37,A38,A39,A40",
"A41,A42,A43,A44",
"A45,A46,B1,B2",
"B3,B4,B5,B6",
"B7,B8,B9,B10",
"B11,B12,B13,B14",
"B15,B16,B17,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");
#
$NUMPORTS = 92;
#
$DUPEUSERCGI="http://www.albedo.net/cgi-bin/dupeuser";
#
########################
### This will display a LED style bar-graph of current Bandwidth
### Usage at Your router.
### This data is extracted from an patched MRTG generated file
### You will have to do some Perl hacking to use this.
$USE_VU=0;
#
## VU_SCALE is the BYTES per second per VU segment
# 128k=800 256kb=1600 300kb=2000 512kb=3200
# T1=9625
$VU_SCALE=9625;
# Path to MRTG HTML doc to extract data
$MRTG_FILE="/httpd/htdocs/local/mrtg/router.12.cur";
# Path to the .gif files (with trailing slash)
$VU_GIF="/image/vu/";
#
##########################################################################
# 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 "\n";
exit;
}
}
print "Portmaster User RTM\n";
print "\n";
####################################################################
## Display VU
if ($USE_VU == 1){
open (VU ,$MRTG_FILE);
$vu = ;
close (VU);
($curin,$curout) = split(':',$vu);
## print "$curin $curout
";
$t=$curin;
&dgif;
print "Inbound
";
$t = $curout;
&dgif;
print "Outbound
";
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;
}
if ($WIDTH == 5){
&headof;
&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(/,/,$_);
█
}
if ($WIDTH == 5){
($L1,$L2,$L3,$L4,$L5) = 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;
}
if ($WIDTH==5){
$TL1 = $L3;
&plint;
$TL1 = $L4;
&plint;
$TL1 = $L5;
&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(/ /, $_);
if ($X{$user}) {
print "Dup User login : $user
\n"
}
}
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;
$X{$user}=1;
}
##########
# Print one segment of the title row
sub headof {
print "Sx | User | ";
if ($SHIP == 1) { print "Host | ";}
print "On | I | | ";
}
###########
# Print one port
sub plint {
### Print Port ###############
print "";
if ($PUSER{$TL1} eq "") {
print "";
}
else {
print "";
$use=$use+1;
}
### Print Username ############
print "$TL1 | $PUSER{$TL1} | ";
if ($SHIP == 1) {
print "$PHOST{$TL1} | ";
}
### Print online Time
$FT="";
$FF="";
$PT=$PSTART{$TL1};
if ($PT =~ ":"){
$PT =~ y/:/\./;
if ($PT >= $OYELLOW){
$FT="";
$FF="";
}
if ($PT >= $OORANGE){
$FT="";
$FF="";
}
if ($PT >= $OPINK){
$FT="";
$FF="";
}
if ($PT >= $ORED){
$FT="";
$FF="";
}
}
if ($PSTART =~ "day"){
if ($BLINKONDAY ==1){
$FT="";
}
else{
$FT="";
$FF="";
}
}
print "$FT$PSTART{$TL1}$FF | ";
### Print Idle Time
if ($PON{$TL1} <= ($WYELLOW-1)) {
print "";
}
if ($PON{$TL1} >= $WYELLOW) {
if ($PON{$TL1} >= $WRED) {
print "";
}
else {
print "";
}
}
print "$PON{$TL1} | | \n";
}
#############################
#
sub dgif {
if ($t >= ($VU_SCALE*22)) {$gif="22m.gif";}
elsif ($t >= ($VU_SCALE*21)) {$gif="21m.gif";}
elsif ($t >= ($VU_SCALE*20)) {$gif="20m.gif";}
elsif ($t >= ($VU_SCALE*19)) {$gif="19m.gif";}
elsif ($t >= ($VU_SCALE*18)) {$gif="18m.gif";}
elsif ($t >= ($VU_SCALE*17)) {$gif="17m.gif";}
elsif ($t >= ($VU_SCALE*16)) {$gif="16m.gif";}
elsif ($t >= ($VU_SCALE*15)) {$gif="15m.gif";}
elsif ($t >= ($VU_SCALE*14)) {$gif="14m.gif";}
elsif ($t >= ($VU_SCALE*13)) {$gif="13m.gif";}
elsif ($t >= ($VU_SCALE*12)) {$gif="12m.gif";}
elsif ($t >= ($VU_SCALE*11)) {$gif="11m.gif";}
elsif ($t >= ($VU_SCALE*10)) {$gif="10m.gif";}
elsif ($t >= ($VU_SCALE*9)) {$gif="9m.gif";}
elsif ($t >= ($VU_SCALE*8)) {$gif="8m.gif";}
elsif ($t >= ($VU_SCALE*7)) {$gif="7m.gif";}
elsif ($t >= ($VU_SCALE*6)) {$gif="6m.gif";}
elsif ($t >= ($VU_SCALE*5)) {$gif="5m.gif";}
elsif ($t >= ($VU_SCALE*4)) {$gif="4m.gif";}
elsif ($t >= ($VU_SCALE*3)) {$gif="3m.gif";}
elsif ($t >= ($VU_SCALE*2)) {$gif="2m.gif";}
elsif ($t >= $VU_SCALE) {$gif="1m.gif";}
else {$gif="0m.gif";}
}