#!/usr/local/bin/perl $|=1; # birdseye.cgi: a simple server and network utility script # Release 1.0 on 10/22/98 # (C) 1998 BigNoseBird.Com, Inc. This program is freeware and may # be used at no cost to you (just leave this notice intact). # Feel free to modify, hack, and play with this script. Just # be very, very careful what you choose to run. This script is # offered AS-IS with no warranties or guarantees. In other words, # you are alone responsible for the use or misuse of this script. # If you are able to, please test all command line programs via # telnet at the unix prompt before placing them in the script. ################################################################## # # INSTRUCTIONS # # Upload this file to your cgi-bin enabled directory. # If you are using a PC or Mac to access a unix server, be sure # to upload the script as an ASCII file and not as BINARY. # It is important to read the CONFIGURATION section carefully. # The only items you need to set are the commands, the number # of seconds the script should run before stopping, and the # valid domains that can call the script. # # The birdseye.html form only has to provide at the most, two # items- program and target. ################################################################## # # CONFIGURATION SECTION # #The maximum number of seconds this script should run before quiting. #It is important to do this, so that you do not create a denial of #service attack on yourself or others if you use the wrong ping #options. Some commands, such as a traceroute against a firewall #can go on for quite a while before the maximum hops are reached. #set this to a reasonable value. $SECONDS=75; #Just in case we do not want to provide the use of this script to #other site's pages..... Place your domain information in the array #below. Use only lower case letters! #to activate, remove the # (comment character) at the start of the line. @OKAYDOMAINS=('http://yourdomain.com', 'http://www.yourdomain.com'); # put your list of commands here. the first column is the code you # will put in your form for program, ie value="1". The H at the start # of a code indicates that an argument,ie host name MUST be specified. # If no hostname (target) is specified by the user, then the CGI # environment variable 'REMOTE_ADDR' will be used- the user's current # IP address. # # The actual locations of various utility programs vary from server # to server. PLEASE. Do not write asking where yours are. Write to # your server administrator, or telnet to your site and use the # 'which' command to get the information. # The examples below are particular to our site. %commands = ( '1', '/usr/etc/ping -c 5 ', '2', '/usr/local/bin/traceroute ', 'H3', '/usr/local/bin/whois ', 'H4', '/usr/bsd/finger ', '5', '/bin/sar ', '6', '/usr/bsd/uptime ' ); # REMEMBER! The 'H' in the command code means that the user must # enter something in the 'target' field. # you can also use this script as your own personal website monitor. # for security reasons, you might want to htaccess protect the page # calling these functions. Also, use wierd values for the program # codes so people can't try and guess them. Trust me, these are not # the values on my server. ;-) # # IMPORTANT! Do NOT use an 'H' in the codes listed below. # # These are examples only. You can do whatever you want, but do # be careful. To add more programs to the %command list above, # stick them between traceroute and whois to avoid making # punctuation errors, ie, the commas at the end of all lines but # the last. Also, all items must be entered as pairs. 'Z1AB2', "/bin/who -u", #display users on line along with idle time 'UA81R', "/bin/netstat", #show server network connection status 'DVJ87', "/bin/ps -ef", #show all system processes '87UYY', "/bin/sar ; /bin/ps -ef", #run both sar and ps commands #HINTS! In Linux, "ps axef" will give you a cool process tree. The -ef # option does not act the same as most other flavors of unix. # Linix also does not have a sar command. ################################################################## # THERE IS NOTHING YOU NEED DO BEYOND THIS POINT ################################################################## # and let the script begin! # to prevent runaways, call it quits after SECONDS seconds. $SIG{'ALRM'} =\&alarm_handle; alarm($SECONDS ? $SECONDS : 1); &valid_page; &decode_vars; if ($TARGET_HOST eq "" && $PROGRAM =~/H/) {print "Content-type: text/html\n\n"; print "\nNo argument was sent to the command\n"; exit 0; } if ($TARGET_HOST eq "" && $PROGRAM !=~/H/ && $ENV{'REQUEST_METHOD'} eq "POST") { $TARGET_HOST=$ENV{'REMOTE_ADDR'}; } if ($commands{$PROGRAM} eq "") {print "Content-type: text/html\n\n"; print "\nNo command was specified..."; exit 0; } &run_command; exit; ################################################################## sub run_command { print "Content-type: text/html\n\n"; print "
\n";
print "Please wait for script to run, or time out\n";
if ($TARGET_HOST ne "")
{ print "RESULTS OF $commands{$PROGRAM} on $TARGET_HOST\n\n";}
else
{ print "RESULTS OF $commands{$PROGRAM}\n\n";}
open (IX,"$commands{$PROGRAM} $TARGET_HOST |");
while ()
{
chop $_;
print "$_\n";
}
print <<__END_OF_FOOTER__;
Done! Press your back button to return or
Click Here.
Birdseye.cgi is another free script from BigNoseBird.Com __END_OF_FOOTER__ close (IX); } ################################################################## sub alarm_handle { alarm(0); terminate(); } ################################################################## sub terminate { print "Content-type: text/html\n\n"; print "\nYour request exceeded the maximum time limit...\n"; exit 0; } ################################################################## # special security items. # 1. only allow legal characters in. # 2. we do not have to worry about bogus commands being passed # since we are using a hash with codes for the actual system # commands. # 3. change the code below at your own risk of server death! sub decode_vars { $i=0; if ( $ENV{'REQUEST_METHOD'} ne "POST") { $temp=$ENV{'QUERY_STRING'};} else { read(STDIN,$temp,$ENV{'CONTENT_LENGTH'});} @pairs=split(/&/,$temp); foreach $item(@pairs) { ($key,$content)=split(/=/,$item,2); $content=~tr/+/ /; $content=~s/%(..)/pack("c",hex($1))/ge; $content=~s/\012//g; $content=~s/\015//g; $content=~s/ //g; $fields{$key}=$content; } $PROGRAM=$fields{'program'}; if ($fields{'target'}=~ /^([-\@\w.]+)$/ || $fields{'target'} eq "") {$TARGET_HOST=$fields{'target'}; return; } else {$TARGET_HOST=""; print "Content-type: text/html\n\n"; print "Illegal Character(s) sent..."; exit; } } ################################################################## sub valid_page { if (@OKAYDOMAINS == 0) {return;} $DOMAIN_OK=0; $RF=$ENV{'HTTP_REFERER'}; $RF=~tr/A-Z/a-z/; foreach $ts (@OKAYDOMAINS) { if ($RF =~ /$ts/) { return; } } if ( $DOMAIN_OK == 0) { print "Content-type: text/html\n\n Sorry, can't do this from here...."; exit; } }