Hi I'm new to perl and would like a few pointers on a perl script that I am writing. The script that I am writing has to retrieve data from a web form using either the 'Post' or 'Get' method. the data will be in the following form. usernameassword:group:sh*ll :superuserstatus. I then have to write this data to a text file I have got so far but can get no further. I have tried running the script from both the command line and through the form. But to no avail. The data is being passed using the get method as I can see it in the URL but the data is not being procesed.
I have also included the code thanks for any help.
Cheers
Robb
#! /usr/bin/perl
print "Content-type: text/html\n\n";
my $cgi_data;
my $no_of_data=0;
if (-e "Passwordfile.txt"
{
open(pass, ">>Passwordfile.txt"
}
else
{
open(pass, ">Passwordfile.txt"
}
if((($ENV{REQUEST_METHOD} eq "GET" and ($ENV{QUERY_STRING} ne "") or
(($ENV{REQUEST_METHOD} eq "POST" and ($ENV{CONTENT_LENGTH} > 0)))
{
if($ENV{REQUEST_METHOD} eq "GET"
{
$cgi_data = $ENV{QUERY_STRING};
}
else
{
read(STDIN,$cgi_data,$ENV{CONTENT_LENGTH});
}
my %form_data_list;
@form_data_list = split(/&/,$cgi_data);
for (my $i=0; $i<@return_data; $i++)
{
my ($name, $value) = split(/=/,$return_data[$i]);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
if (defined($form_data_list{$name}))
{
$form_data_list{$name} .=",$value";
} else {
$form_data_list{$name} = $value;
}
}
if($cgi_data =~ /[;><&\*`|[]/)
{
print "You have breached Security";
exit 0;
}
$no_of_data=1;
}
if ($no_data == 0)
{
print ("\n"
print ("No data has been passed\n"
}
else
{
print (pass "$value[0]:$value[1]:$value[2]:$value[3]:$value[4]"
}
close(pass);
I have also included the code thanks for any help.
Cheers
Robb
#! /usr/bin/perl
print "Content-type: text/html\n\n";
my $cgi_data;
my $no_of_data=0;
if (-e "Passwordfile.txt"
{
open(pass, ">>Passwordfile.txt"
}
else
{
open(pass, ">Passwordfile.txt"
}
if((($ENV{REQUEST_METHOD} eq "GET" and ($ENV{QUERY_STRING} ne "") or
(($ENV{REQUEST_METHOD} eq "POST" and ($ENV{CONTENT_LENGTH} > 0)))
{
if($ENV{REQUEST_METHOD} eq "GET"
{
$cgi_data = $ENV{QUERY_STRING};
}
else
{
read(STDIN,$cgi_data,$ENV{CONTENT_LENGTH});
}
my %form_data_list;
@form_data_list = split(/&/,$cgi_data);
for (my $i=0; $i<@return_data; $i++)
{
my ($name, $value) = split(/=/,$return_data[$i]);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
if (defined($form_data_list{$name}))
{
$form_data_list{$name} .=",$value";
} else {
$form_data_list{$name} = $value;
}
}
if($cgi_data =~ /[;><&\*`|[]/)
{
print "You have breached Security";
exit 0;
}
$no_of_data=1;
}
if ($no_data == 0)
{
print ("\n"
print ("No data has been passed\n"
}
else
{
print (pass "$value[0]:$value[1]:$value[2]:$value[3]:$value[4]"
}
close(pass);