User Tools

Site Tools


perl:start

Perl stuff

Old, probably badly written and not maintained! You have been warned.

cgi-bin bits

env.pl

- Prints out webserver variables available to your script

#!/bin/perl  - or whatever your path to perl is
# env.pl
# This script dumps the environment variables in HTML format
 
use strict;
use warnings;
$|=1;
 
print "Content-type:text/html\n\n";
 
foreach my $var (sort keys %ENV) {
    print $var . "=" . $ENV{$var} . "<br>\n";
}

about.pl

#!/usr/sbin/perl
use strict;
use warnings;
$now = localtime ;
print "Content-type: text/html", "\n\n";
print "<HTML>", "\n";
print "<HEAD><TITLE>About this server</TITLE></HEAD>", "\n";
print "<BODY><H1>About this server</H1>", "\n";
print "<HR><PRE>";
 
print "Today is                 ", $now, "<BR>", "\n";
print "Server Name:             ", $ENV{'SERVER_NAME'}, "<BR>", "\n";
print "Running on Port:         ", $ENV{'SERVER_PORT'}, "<BR>", "\n";
print "Server Software:         ", $ENV{'SERVER_SOFTWARE'}, "<BR>", "\n";
print "Server Protocol:         ", $ENV{'SERVER_PROTOCOL'}, "<BR>", "\n";
print "CGI Revision:            ", $ENV{'GATEWAY_INTERFACE'}, "<BR>", "\n\n";
print "You are ", $ENV{'REMOTE_ADDR'}, "<BR>", "\n";
print "Your machine is ", $ENV{REMOTE_HOST}, "<BR>", "\n";
print "<HR></PRE>", "\n";
print "</BODY></HTML>", "\n";
 
exit (0)

my-ip.pl

#!/usr/bin/perl
 
#developed from original script by Andrew Stringer 09/10/2002 onwards.
 
use strict;
use warnings;
 
#Set to ip passed from apache or if undefined, use Google.
my $remotehost=$ENV{'REMOTE_ADDR'} || '8.8.8.8';
 
my $ENVIRO=`env` ;
 
print "Content-type:text/html\n\n";
 
print <<ENDOFTEXT1;
<html>
<head>
<title>My ip</title>
</head>
 
<body>
Your ipaddress is:- $remotehost
<br><br>
 
 
ENDOFTEXT1
 
#print $ENVIRO ;
 
my @traceroute=`/usr/bin/tcptraceroute $remotehost`;
 
print "@traceroute \n";
# Again, you can print (or do whatever with) the answer:
 
my $i;
foreach $i (@traceroute) {
# Here you can print or analize each line of the answer
print "$i\n<br>";
}
 
 
print <<ENDOFTEXT2;
 
End of trace.
 
</body>
</html>
ENDOFTEXT2
 
exit (0);

convert2html.pl

Convert to HTML

#!/usr/bin/perl
#written by Andrew Stringer 30-04-2006
#this is intended to be run from an ssi:-
#<!--#include virtual="/cgi-bin/convert2html.pl?path/to/file.xml" -->
#it takes an html file or xml file and converts the < to &lt; etc. and
#prints to stdout enclosed in a <pre> </pre> tag. This allows code listings
#to appear in web pages correctly formatted.

use warnings;
use strict;

MAIN:
{
my $line;
#set prefix to path to webroot
my $prefix = '/data/rainsbrook/http';
my $query = $ENV{'QUERY_STRING'} ;

my $debug = '0' ;

#remove double dots (..) to prevent file system traversal
#Only naughty boys would want to do this, should not affect normal users.
$query =~ s/\.\.//g;
$query =~ s/\/\//\//g;

#only allow files below the webroot to be readout
my $url = "$prefix/$query" ;

open (FILE, "$url");

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

if($debug){
print "ENV{'QUERY_STRING'} is $query \n<br>\n" ;
print "URL is $url \n";
}

print "<pre>\n";

while ($line = <FILE>) 
	{
#use /g to catch all occurances on each line
	$line =~ s/\</\&lt\;/g;
	$line =~ s/\>/\&gt\;/g;

	print $line;
	}
print "</pre>\n";

}
exit(0);
perl/start.txt · Last modified: by andrew

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki