Q:
Hi there:
Ok, this is exactly what I am trying to do, I am trying to create a CGI
script that will handle all of my templates (shtml and html code files
contained within a .cgi extention).
For example, if someone goes to a URL called
http://www.yoursite.com/brl/brl.cgi?frontpage
it will bring up the frontpage file
If someone goes to another URL that is different after the ? then it will
bring up something else.
I have written something but it is not working and would like advice on
how to get this thing to work. I have worked on it for 2 weeks now and I
am getting no where fast. Any help would be appreciated.
So far there are 15 template files, but only 13 of those (so far are
located in the templates dir - which will be .htaccess protected), one
other is in a dir below that and the frontpage is in the dir below the
other one. I would like to make the cgi file to be customizable so that I
can add more templates when needed.
Below is the cgi file that I have done so far (with a little help from a
friend)...I hope you can go through it and offer any help you have to get
this to work the way I intend.
Thanks for your help in advance..
The server I am using is a UNIX server with PERL 5 installed - know
nothing else about the server.
cgi code start
#!/usr/local/bin/perl
use CGI::Carp qw(fatalsToBrowser);
##############################################################
# EXAMPLE: USE AS
# http://www.paddymail.net/brl/brl.cgi?frontpage
# For the frontpage file.
##############################################################
## Where all the files are going to be kept
$basepath = "/u280/bacci/brl/templates";
## Tell script to print everything to browser in HTML
print "Content-type: text/html\n\n";
## split the args when needed
@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});
$ARGV[0] =~ s/\W//g;
## start arg
if ($ARGV[0]) {
mkdir("$basepath", 0777) unless (-d "$basepath");
&memberarea;
} else {
print "use as follows http://www.paddymail.net/brl/brl.cgi?blahblahblah";
}
exit;
## start sub routine
sub memberarea {
&oops("Cannot Find the template file, this is most likely a basepath
error. $!") unless (open(THEFILE, "$basepath/$_[0]"));
(@all_data_in_file) = <THEFILE>;
close THEFILE;
print @all_data_in_file;
}
## trim arg if needed
sub trim {
my @out = @_;
for (@out) {
s/^\s+//;
s/\s+$//; }
chomp($out[0]);
return $out[0]; }
## tell me an oops if anything
sub oops {
print "there is an Error! $_[0]";
exit;
}
cgi code end
A:
sub memberarea
&oops("Cannot Find the template file, this is most likely a basepath
error. $!") unless (open(THEFILE, "$basepath/$_[0]"));
You do not pass any argument to this function thus @_ is undef. Here you
mean
sub memberarea
&oops("Cannot Find the template file, this is most likely a basepath
error. $!") unless (open(THEFILE, "$basepath/$ARGV[0]"));
Regards,
Peter
Q:
OK.... I have changed the script, lets say there are two templates in
other areas of the domain but the rest are located within the htaccess
protected dir. How would I call these pages via the script and not get a
login request?
The file names below are examples of what there is going to be so far:
Where the $whatever is, for example, is how I would like to call the page
via the URL in the format of http://www.yoursite.com/brl/brl.cgi?frontpage
or what ever the $blahblahblah is.
$frontpage = "frontpage.cgi"; <-- going to be located in .../brl/
$loggedin = "index.shtml"; <-- going to be located in .../brl/members/
everything else below in .../brl/members/templates/
$G1Text = "GradeOneTextIndex.cgi";
$G1HTML = "GradeOneHTMLIndex.cgi";
$G1TextHistory = "GradeOneTextHistory.cgi";
$G1TextAlphabet = "GradeOneTextAlphabet.cgi";
$G1TextNumbers = "GradeOneTextNumbers.cgi";
$G1TextPunctuation = "GradeOneTextPunctuation.cgi";
$G1TextBrailleFont = "GradeOneTextBrailleFont.cgi";
$G1TextBrailleCard = "GradeOneTextBrailleCard.cgi";
$G1HTMLHistory = "GradeOneHTMLHistory.cgi";
$G1HTMLAlphabet = "GradeOneHTMLAlphabet.cgi";
$G1HTMLNumbers = "GradeOneHTMLNumbers.cgi";
$G1HTMLPunctuation = "GradeOneHTMLPunctuation.cgi";
$BrailleMouseOver = "BrailleMouseOver.cgi";
Hope you can help.
A:
htaccess governs only what script you can execute with or without a
username/password. htaccess has nothing to do with the files that the
script opens and reads/writes. That is solely controlled by UNIX file
permissions.
Regards,
Peter
[ back to toc ]