Nathan Pralle - www.nathanpralle.com
Kickass Phone Rates from 3U
PLACES TO GO:  
Back to Software Print Version
WHO.PL

Scripts.com Freshmeat The Perl Archive HotScripts

#!/usr/bin/perl -w
use strict;
use IO::Socket;

###############################################
# WHO.PL
# Talker "Who's Online?" CGI Script
# Copyleft 2005 Nathan E. Pralle

# DESCRIPTION:  
#
# SYNTAX:  
#
# CONTACT:   Questions?  Comments?
#            http://www.nathanpralle.com/contact.html
#################################################################

########################
# CONFIGURATION OPTIONS
#

# Talker Name
my $talkername		="The Forever Beyond";

# Talker Host Name 
my $hostname		="foreverbeyond.org";

# Talker Port Number
my $portnum			=7000;

# Timeout -- how long to wait for a response when trying to connect (default 1000)
my $timeout			=1000;

# Specify the 'who' command
my $whocmd			='who';

# Login search term
# Specify a word (unique) found in the login prompt
my $loginsearch	="account";

# End 'who' search
# Specify a word that appears at the end of the 'who' display
my $whosearch		="here.";

# Output Title
# Title at the head of the output (empty quotes ("") to disable)
my $titlewho		="Users Online";

# Webpage Header File
# Specifies a location (relative) for you to include HTML to surround the output
# Blank quotes ("") to deactivate
my $headerfile		="header.txt";

# Webpage Footer File
# Specifies a location (relative) for you to include HTML to surroung the output
# Blank quotes ("") to deactivate
my $footerfile		="footer.txt";
########################

print "Content-type:text/html\n\n";

my $sock = new IO::Socket::INET (
	PeerAddr =>$hostname,
	PeerPort => $portnum,
	Proto=> 'tcp',
	Timeout => "$timeout",
);

if($sock){
	&priwho;
}
else{
	&testsock;
}

sub priwho {
	if($headerfile ne ""){
		open(HEADER,"$headerfile")||die("can't open header file: $!\n");
		while(<HEADER>){
			print;
		}
		close(HEADER);
	}
	print "<center>\n";
	print "<table border=1 cellspacing=6 cellpadding=6><tr><td bgcolor=\"#000000\">\n";
	print "<font color=\"#FFFFFF\"><b>";
	print "<h1>$titlewho</h1>";
	print $sock "$whocmd\n";
	while(<$sock>){
		print STDERR;
		if(/($loginsearch)/){
			last;
		}
	}
	while (<$sock>){
		chomp;
		s/[^0-9A-Za-z \`\~\!\@\#\$\%\^\&\*\(\)\_\-\+\=\|\}\{\\\]\[\"\:\'\;\?\>\<\/\.\,\t]//gi;
		s/ /&nbsp;/g;
   	s/\[31m/\<font color="#FF0000"\>/gi;
   	s/\[32m/\<font color="#00FF00"\>/gi;
   	s/\[33m/\<font color="#FFFF00"\>/gi;
   	s/\[34m/\<font color="#0000FF"\>/gi;
   	s/\[35m/\<font color="#FF00CC"\>/gi;
   	s/\[36m/\<font color="#66FFFF"\>/gi;
		s/\[[0-9]+m//gi;
		print "<tt><b>";
		print;
		print "</tt>";
		print "</font><font color=white><br>\n";
		if(/($whosearch)/){
			last;
		}
	}
	close($sock);
	print "</td></tr></table>\n";
	if($footerfile ne ""){
		open(FOOTER,"$footerfile")||die("Can't open footer file: $!\n");
		while(<FOOTER>){
			print;
		}
		close(FOOTER);
	}
}

exit;

sub testsock {
	print"<html><head></head><body bgcolor=000000>\n";
	print "<center><font size =+3 color=FFFF00>\n";
	print "<pre>$talkername is down right now, check again later.</pre>\n";
	print "</center></font></body></html>\n";
	exit;
}



This site and all content (C)2002-2008 Nathan E. Pralle (www.nathanpralle.com).