Re: problem when submitting a string through a form
- From: Nikos <nikos1337@xxxxxxxxx>
- Date: Thu, 3 Jan 2008 10:00:22 -0800 (PST)
Here is index.pl as it is now: you can view it at http://nikos.no-ip.org
if you want
#!/usr/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI qw(:standard);
use DBI;
use POSIX qw(strftime);
use Encode;
my ($select, $article, $row, $data);
my $date = strftime('%y-%m-%d %H:%M:%S', localtime);
my $display_date = strftime('%a %d %b, %I:%M %p', localtime);
Encode::from_to($display_date, 'ISO-8859-7', 'utf8');
my $host = gethostbyaddr (pack ("C4", split (/\./,
$ENV{'REMOTE_ADDR'})), 2) || $ENV{REMOTE_ADDR};
$host = "Administrator" if ( ($host =~ /dell/) or ($host =~ /
localhost/) );
#===============================================================================
my $db = ( $ENV{'SERVER_NAME'} !~ /varsa/ )
? DBI->connect('DBI:mysql:orthodox;localhost', 'root', '*****',
{RaiseError=>1})
: DBI->connect('DBI:mysql:nikosva_orthodox;www.freegreece.net',
'nikosva_nikos', '****', {RaiseError=>1});
#===============================================================================
print header( -charset=>'utf-8' );
my $article = param('select') || "Αρχική Σελίδα!";
my @files = glob "$ENV{'DOCUMENT_ROOT'}/data/text/*.txt";
my @display_files = map m{([^/]+)\.txt}, @files;
Encode::from_to($_, 'ISO-8859-7', 'utf8') for @display_files;
if ( param('select') ) { #If user selected an item from the drop
down menu
unless ( grep { $_ eq param('select') } @display_files ) #Unless
user selection doesn't match one of the valid filenames within
@display_files
{
if( param('select') =~ /\0/ )
{
$article = "*Null Byte Injection* attempted & logged!";
print br() x 2, h1( {class=>'big'}, $article );
}
if( param('select') =~ /\/\.\./ )
{
$article = "*Backwards Directory Traversal* attempted &
logged!";
print br() x 2, h1( {class=>'big'}, $article );
}
$select = $db->prepare( "UPDATE guestlog SET article=?, date=?,
counter=counter+1 WHERE host=?" );
$select->execute( $article, $date, $host );
exit 0;
}
$article = decode('utf8', param('select' ));
Encode::from_to($article, 'utf8', 'ISO-8859-7');
open FILE, "<$ENV{'DOCUMENT_ROOT'}/data/text/$article.txt" or die
$!;
local $/;
$data = <FILE>;
close FILE;
$select = $db->prepare( "UPDATE guestlog SET article=?, date=?,
counter=counter+1 WHERE host=?" );
$select->execute( $article, $date, $host );
}
else {
$select = $db->prepare( "SELECT host FROM guestlog WHERE host=?" );
$select->execute( $host );
if ($select->rows)
{
$select = $db->prepare( "SELECT host, DATE_FORMAT(date, '%a %d
%b, %h:%i') AS date, counter, article FROM guestlog WHERE host=?" );
$select->execute( $host );
$row = $select->fetchrow_hashref;
$data = "Καλώς ήλθες $host! Χαίρομαι που βρίσκεις την σελίδα
ενδιαφέρουσα.
Τελευταία φορά ήρθες εδώ ως $row->{host} στις $row-
{date} !Προηγούμενος αριθμών επισκέψεων => $row->{counter}
Τελευταία είδες το κείμενο [ $row->{article} ]
Ποιό κείμενο θα μελετήσεις αυτήν την φορά !?";
$select = $db->prepare( "UPDATE guestlog SET date=?,
counter=counter+1 WHERE host=?" );
$select->execute( $date, $host );
}
else
{
if ($host eq "Administrator") {
$data = "Γειά σου Νικόλα! Πώς πάνε τα κέφια? ;-)";
}
else {
$data = "Γειά σου $host!
Έρχεσαι για 1η φορά εδώ !!
Ελπίζω να βρείς τα κείμενα ενδιαφέροντα :-)";
}
unless ($host eq "Administrator") {
$select = $db->prepare( "INSERT INTO guestlog (host, date,
article, counter) VALUES (?, ?, ?, ?)" );
$select->execute( $host, $date, $article, 1 );
}
}
}
for ($data) {
s/\n/\\n/g;
s/"/\\"/g;
tr/\cM//d;
}
#======OK, $data set up. Now print header, start_html and JavaScript
stuff======
start_html(
-script => [
"var textToShow = '$data';",
{
-language => 'JAVASCRIPT',
-src => '/data/scripts/char_by_char.js'
}
],
-style => '/data/scripts/style.css',
-title => 'Ορθόδοξα Πνευματικά Θέματα!',
-onload => 'init();'
),
a({href=>'/cgi-bin/register.pl'}, img{src=>'/data/images/reg.jpg'}),
start_form(action=>'/cgi-bin/index.pl'),
h1({class=>'lime'}, "Επέλεξε το κείμενο που σε ενδιαφέρει => ",
popup_menu( -name=>'select', -values=>
\@display_files ),
submit(-label=>'ok')),
end_form,
div({id => "DivText"}),
end_html;
#===============================================================================
The problem is that when the user selects something from my popup
menu(one string) and then submits it, the returned string being sent
back to my index.pl ain't matching this line: unless ( grep { $_ eq
param('select') } @display_files )
and that fact led to believe that the browser or something else
somehow malformes the original value(the one selected before
submission)
I though that this line would take care of the problem coverting it
properly to utf8 but it doesnt :(
$article = decode('utf8', param('select' ));
please help
.
- Follow-Ups:
- Re: problem when submitting a string through a form
- From: Ted Zlatanov
- Re: problem when submitting a string through a form
- From: RedGrittyBrick
- Re: problem when submitting a string through a form
- References:
- problem when submitting a string through a form
- From: Nikos
- Re: problem when submitting a string through a form
- From: Paul Lalli
- Re: problem when submitting a string through a form
- From: Nikos
- Re: problem when submitting a string through a form
- From: Nikos
- Re: problem when submitting a string through a form
- From: RedGrittyBrick
- problem when submitting a string through a form
- Prev by Date: Re: Perl - no longer open source and facing extinction
- Next by Date: Re: Perl - no longer open source and facing extinction
- Previous by thread: Re: problem when submitting a string through a form
- Next by thread: Re: problem when submitting a string through a form
- Index(es):
Relevant Pages
|
Loading