Ok guys, I don't know whats going on. Something I figured would be a simple cgi script has become a nightmare that I can't figure out without using an extensive "if" process. Here is what I am trying to do. I am by far not an expert in perl coming from a vb background so my code is probably lacking and extreamly ugly so beware!
1.) My program needs to interpret 3 portions of a url request to append to various functions (seems simple.)
GENERAL REQUEST SYNTAX EXAMPLES
a.) Example: External import request - external site
href =
b.) Example: External import request local site
href =
b.) Example Internal import request local site
href =
href =
TO BE INTERPRETED
a. $root The http root path IE: (Default if not present in request)
b. $path The extended directory path IE: /inform (
c. $file The file name IE: /victim.htm
THE GOLDEN RULES
a.) $root . $path . $file should make a valid formatted url in the event $path or $file is not present in the request
b.) URL's are case sensitive so should be stored in the case received.
PROBLEMS
$file should be null if a . is not present and should never equal the domain name itself.
if $file does not contain a . then it should remain null with contents appended to $path
I hope this is clear, I tried my best to explain my issue. If you want me to make a long story short here is exactly what I am tring to do.
I need to parse a url request to into portions
any help would be greatly appreciated!
#!/usr/bin/perl -wT
use LWP::Simple;
use CGI;
my $cgi = new CGI;
#Default if not provided
my $root = '
my $path = '';
my $count = 0;
my @nav = $cgi->param();
$nav = $cgi->param($nav[0]);
$path = '/' .$nav . '/';
#Remove all the //'s
while (rindex($path, '//') != -1){
my $test = rindex($path,'//');
if ($test != -1){
$path = substr($path,0,$test) . '/' . substr($path,$test + 2);
}
}
#remove the trailing / if applicable
$test = length($path) - 1;
if (substr($path, $test) == '/'){
$path = substr($path,0, $test);
}
#Process a root from $path
$test = rindex(lc($path), 'http:/');
if ($test != -1){
$test = $test + 5;
$root = substr($path,$test);
@test = split('/', $root);
$root = "[1]";
}
print "Content-Type: text/html\n\n";
print "Root: $root\n\n Dir: $path";
exit (0);
1.) My program needs to interpret 3 portions of a url request to append to various functions (seems simple.)
GENERAL REQUEST SYNTAX EXAMPLES
a.) Example: External import request - external site
href =
b.) Example: External import request local site
href =
b.) Example Internal import request local site
href =
href =
TO BE INTERPRETED
a. $root The http root path IE: (Default if not present in request)
b. $path The extended directory path IE: /inform (
c. $file The file name IE: /victim.htm
THE GOLDEN RULES
a.) $root . $path . $file should make a valid formatted url in the event $path or $file is not present in the request
b.) URL's are case sensitive so should be stored in the case received.
PROBLEMS
$file should be null if a . is not present and should never equal the domain name itself.
if $file does not contain a . then it should remain null with contents appended to $path
I hope this is clear, I tried my best to explain my issue. If you want me to make a long story short here is exactly what I am tring to do.
I need to parse a url request to into portions
any help would be greatly appreciated!
#!/usr/bin/perl -wT
use LWP::Simple;
use CGI;
my $cgi = new CGI;
#Default if not provided
my $root = '
my $path = '';
my $count = 0;
my @nav = $cgi->param();
$nav = $cgi->param($nav[0]);
$path = '/' .$nav . '/';
#Remove all the //'s
while (rindex($path, '//') != -1){
my $test = rindex($path,'//');
if ($test != -1){
$path = substr($path,0,$test) . '/' . substr($path,$test + 2);
}
}
#remove the trailing / if applicable
$test = length($path) - 1;
if (substr($path, $test) == '/'){
$path = substr($path,0, $test);
}
#Process a root from $path
$test = rindex(lc($path), 'http:/');
if ($test != -1){
$test = $test + 5;
$root = substr($path,$test);
@test = split('/', $root);
$root = "[1]";
}
print "Content-Type: text/html\n\n";
print "Root: $root\n\n Dir: $path";
exit (0);