imported>DrOwl No edit summary |
imported>DrOwl No edit summary |
||
Line 16: | Line 16: | ||
--[[User:DrOwl|DrOwl]] 00:32, 23 May 2005 (CEST) |
--[[User:DrOwl|DrOwl]] 00:32, 23 May 2005 (CEST) |
||
oki i see =) simple really just need to chek it out with php instead of perl =) |
|||
i guessit willbe similer becouse its just somenice regex =) |
|||
<code> |
|||
<pre> |
|||
#!/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 = "/home/drowl/figlet/fonts/"; |
|||
#set the full path to figlet here |
|||
$figlet = "/home/drowl/figlet/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; |
|||
<h2>FnorD here is your words</h2> |
|||
<p>YoU wanTed to see '$text' in the StYle of $fontname |
|||
<hr> |
|||
END |
|||
#newtext variable becomes the output of the figlet command |
|||
@newtext=`echo '$text' | $figlet -d '/home/drowl/figlet/fonts' -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 "<A href=/index.php target=master>Home</a> <A href=/figlet.php target=master>Figlet</a><br>\n"; |
|||
print "<p><font size=-1> 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 |
|||
</pre> |
|||
</code> |
|||
--[[User:DrOwl|DrOwl]] 00:49, 23 May 2005 (CEST) |
|||
Installed it now and testing. Returns the figlet now, but BEFORE all other html. Trying to fix... |
Installed it now and testing. Returns the figlet now, but BEFORE all other html. Trying to fix... |
Revision as of 22:49, 22 May 2005
ok we stilll need to do playing for the excapecommands and such... maybe we can just run some tr RegXs for doggy chars... there must be a way formaking it safe =) ill checkout the perl version =)
+the passthrough command works in my tests ie, using
<pre> <?php passthru('echo moo | /home/drowl/figlet/figlet -d /home/drowl/figlet/fonts'); ?> </pre>
returns the multi line figlet on my shell
+still need to add the font tags =)
--DrOwl 00:32, 23 May 2005 (CEST)
oki i see =) simple really just need to chek it out with php instead of perl =)
i guessit willbe similer becouse its just somenice regex =)
#!/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 = "/home/drowl/figlet/fonts/";
#set the full path to figlet here
$figlet = "/home/drowl/figlet/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;
<h2>FnorD here is your words</h2>
<p>YoU wanTed to see '$text' in the StYle of $fontname
<hr>
END
#newtext variable becomes the output of the figlet command
@newtext=`echo '$text' | $figlet -d '/home/drowl/figlet/fonts' -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 "<A href=/index.php target=master>Home</a> <A href=/figlet.php target=master>Figlet</a><br>\n";
print "<p><font size=-1> 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
--DrOwl 00:49, 23 May 2005 (CEST)
Installed it now and testing. Returns the figlet now, but BEFORE all other html. Trying to fix...
getting this help: < dammit> mutante: try using popen("figlet $input","r");
stay tuned... mutante 13:12, 21 May 2005 (CEST)
13:06 < mutante> hmm,while trying to write a mediawiki extension i always get the output i return BEFORE all other html in the wiki pages instead of inline...what could i be doing wrong 13:08 < mutante> $output=system ("figlet $input"); <maybe connected to using a system command to create output 13:08 < dammit> of course, PECL would do the job 13:09 < mutante> it returns what i want, just before the rest of all html 13:09 < dammit> haha, figlet ;-) 13:09 < mutante> yea *g* 13:09 < dammit> mutante: try using popen("figlet $input","r"); 13:09 < dammit> and don't forget to escape special characters in your $input 13:09 < dammit> or you'll end up in h4x0red box 13:10 < mutante> dammit: $input = mysql_escape_string($input); good enough? 13:12 < dammit> *shrug* :) 13:12 < dammit> then make it "figlet '$input'" 13:12 < JeLuF> mutante: No. mysql_escape_string is for SQL commands, not for shell commands 13:13 < mutante> JeLuF: oh,yea,is there something like "bash_escape_string" ? 13:14 < mutante> i guess i need to be afraid of ;'s 13:14 < JeLuF> or $( or ` or or or 13:14 < hendrik> escapeshellcmd 13:15 < JeLuF> mutante: http://de2.php.net/manual-lookup.php?pattern=escape 13:15 < mutante> does this sound good: $input =~ /[Aa-Zz]|[1-0]; 13:15 < TimStarling> use wfEscapeShellArg, it works on windows, kind of 13:15 < mutante> thanks for all the help