Cool Site
- Code: Select all
___ ___ __ __ _______ __
| | |.-----.|__|.--| | | | |.---.-.|__|.-----.
| | || _ || || _ | | || _ || || |
\_____/ |_____||__||_____| |__|_|__||___._||__||__|__|
___ ___ __ __ _______ __
| | |.-----.|__|.--| | | | |.---.-.|__|.-----.
| | || _ || || _ | | || _ || || |
\_____/ |_____||__||_____| |__|_|__||___._||__||__|__|

#!/usr/bin/perl -w
#Figlet-CGI 0.1 by Matthew Borowski
#(C)1999 WorldServe Consulting http://www.worldserve.net
#License: BSD
#Make sure to set the variables below
#
#use the CGI.pm object-oriented module
use strict;
use CGI;
my ($query, $text, $fontname, $fontpath, $maxfontname, $maxtext, $figlet, $fontnameext, @newtext);
#set your font path here (directory with your .flf files) with trailing slash
$fontpath = "/usr/local/share/figlet/";
#set the full path to figlet here
$figlet = "/usr/local/bin/figlet";
#set the maximum length of $fontname
$maxfontname = "30";
#set the maximum length of $text
$maxtext = "50";
#
#
#process the query (either GET or POST)
$query = new CGI;
#print the content-type out
print $query->header;
#make sure font is specified, else quit
unless ($query->param('fontname')){
#print the starting html
print $query->start_html("Figlet Error");
print "<p>Sorry, you didn't select a fontname.\n";
exit;
}
else {
#set the text variable
$fontname = $query->param('fontname');
#escape out the single-quotes so we can enclose in single quote below
$fontname =~ s:\':\'\\'\':g;
}
#if font is longer than $maxfontname characters, quit
if (length($query->param('fontname')) > $maxfontname){
#print the starting html
print $query->start_html("Figlet Error");
print "<p>Sorry, your text is too long (longer than $maxfontname characters).\n";
exit;
}
#if fontname doesn't end in .flf, then quit
$fontnameext = substr($fontname, -4);
unless ($fontnameext eq ".flf"){
print $query->start_html("Figlet Error");
print "<p>Sorry, your fontname does not end in .flf\n";
exit;
}
#unless we can open the file, exit
unless(-r "$fontpath$fontname"){
print $query->start_html("Figlet Error");
print "<p>Invalid font. Cannot open $fontname.\n";
exit;
}
#make sure text is specified, else quit
unless ($query->param('text')){
#print the starting html
print $query->start_html("Figlet Error");
print "<p>Sorry, you didn't specify any text.\n";
exit;
}
else {
#set the text variable
$text = $query->param('text');
#escape out the single-quotes so we can enclose in single quote below
$text =~ s:\':\'\\'\':g;
}
#if text is longer than $maxtext characters, quit
if (length($query->param('text')) > $maxtext){
#print the starting html
print $query->start_html("Figlet Error");
print "<p>Sorry, your text is too long (longer than $maxtext characters).\n";
exit;
}
#print the starting html
print $query->start_html("Figlet: $text");
#print the main part of the page
print <<END;
<h1>Figlet Results:</h1>
<p>Processing '$text' with font $fontname
<hr>
END
#newtext variable becomes the output of the figlet command
@newtext=`echo '$text' | $figlet -f '$fontpath$fontname'`;
#turn the < and > signs into proper HTML formatting (< and >)
s/</</g for @newtext;
s/>/>/g for @newtext;
print "<p><pre>\n @newtext</pre>\n";
print "<hr>\n";
print "<p><font size=-1>Script $ENV{'SCRIPT_NAME'} requested with method $ENV{'REQUEST_METHOD'} by $ENV{'REMOTE_USER'} $ENV{'REMOTE_HOST'} ($ENV{'REMOTE_ADDR'}) with $ENV{'HTTP_USER_AGENT'}</font>\n";
print $query->end_html;
#END



Users browsing this forum: No registered users and 1 guest