[ back to toc ]

I am going crazy, HELP ME PLEASE!

Date: 2001/12/24 17:31

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 m
ean

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
Q:
With all of the templates, the script is going to need to know what file
is to be opened according to the URL the user goes to, how do I do this?

Does each file need its own argument and then its own sub routine?
A:
I do not understand this question.

Regards,
Peter
Q:
Does each file (template) need its own argument and subroutine... like the
following:

## 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;
}

I have attempted to create this argument but getting a compilation error:
## start arg
if ($ARGV[0] eq 'loggedin') { &memberarea($basepath/$loggedin); }
elsif ($ARGV[0] eq 'G1Text') { &memberarea($basepath/$G1Text); }
elsif ($ARGV[0] eq 'G1HTML') { &memberarea($basepath/$G1HTML); }
elsif ($ARGV[0] eq 'G1TextHistory')
&memberarea($basepath/$G1TextHistory); }
elsif ($ARGV[0] eq 'G1TextAlphabet')
&memberarea($basepath/$G1TextAlphabet); }
elsif ($ARGV[0] eq 'G1TextNumbers')
&memberarea($basepath/$G1TextNumbers); }
elsif ($ARGV[0] eq 'G1TextPunctuation')
&memberarea($basepath/$G1TextPunctuation); }
elsif ($ARGV[0] eq 'G1TextBrailleFont')
&memberarea($basepath/$G1TextBrailleFont); }
elsif ($ARGV[0] eq 'G1TextBrailleCard')
&memberarea($basepath/$G1TextBrailleCard); }
elsif ($ARGV[0] eq 'G1HTMLHistory')
&memberarea($basepath/$G1HTMLHistory); }
elsif ($ARGV[0] eq 'G1HTMLAlphabet')
&memberarea($basepath/$G1HTMLAlphabet); }
elsif ($ARGV[0] eq 'G1HTMLNumbers')
&memberarea($basepath/$G1HTMLNumbers); }
elsif ($ARGV[0] eq 'G1HTMLPunctuation')
&memberarea($basepath/$G1HTMLPunctuation); }
elsif ($ARGV[0] eq 'BrailleMouseOver')
&memberarea($basepath/$BrailleMouseOver); }
else { &memberarea($basepath/$frontpage); }
mkdir("$basepath", 0777) unless (-d "$basepath");
&memberarea;
} else {
print "use as follows http://www.paddymail.net/brl/brl.cgi?blahblahblah";
}
exit;
I have placed all the variables in the script stating the basepath and the
names of the files.
A:
why not call

&memberarea("$basepath/" . ARGV[0]);

Regards,
Peter

Q:
I have two directories, one that contains the template files and another
that contains only the frontpage template, the script below can find the
frontpage template but cannot find any other template file. What is going
on with this? I have tried many things and nothing seems to work. All
files and folders that are relevant are CHMOD to 755.

#!/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/members";
$front = "/u280/bacci/brl";
## Start the pathways to the template file names in the arg
$frontpage = "frontpage.cgi";
$loggedin = "index.shtml";
$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";
## 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] eq 'loggedin') { &memberarea($loggedin); }
elsif ($ARGV[0] eq 'G1Text') { &memberarea($G1Text); }
elsif ($ARGV[0] eq 'G1HTML') { &memberarea($G1HTML); }
elsif ($ARGV[0] eq 'G1TextHistory') { &memberarea($G1TextHistory); }
elsif ($ARGV[0] eq 'G1TextAlphabet') { &memberarea($G1TextAlphabet); }
elsif ($ARGV[0] eq 'G1TextNumbers') { &memberarea($G1TextNumbers); }
elsif ($ARGV[0] eq 'G1TextPunctuation')
{ &memberarea($G1TextPunctuation); }
elsif ($ARGV[0] eq 'G1TextBrailleFont')
{ &memberarea($G1TextBrailleFont); }
elsif ($ARGV[0] eq 'G1TextBrailleCard')
{ &memberarea($G1TextBrailleCard); }
elsif ($ARGV[0] eq 'G1HTMLHistory') { &memberarea($G1HTMLHistory); }
elsif ($ARGV[0] eq 'G1HTMLAlphabet') { &memberarea($G1HTMLAlphabet); }
elsif ($ARGV[0] eq 'G1HTMLNumbers') { &memberarea($G1HTMLNumbers); }
elsif ($ARGV[0] eq 'G1HTMLPunctuation')
{ &memberarea($G1HTMLPunctuation); }
elsif ($ARGV[0] eq 'BrailleMouseOver') { &memberarea($BrailleMouseOver); }
else { &frontpage($frontpage); }
mkdir("$basepath", 0777) unless (-d "$basepath");
&memberarea;
&frontpage;
exit;
## start sub routine
sub memberarea {
&oops("Cannot Find the template file, this is most likely a basepath
error. $!") unless (open(THEFILE, "$memberarea/$_[0]"));
(@all_data_in_file) = <THEFILE>;
close THEFILE;
print @all_data_in_file;
}
sub frontpage {
&oops("Cannot Find the frontpage template file, this is most likely a
basepath error. $!") unless (open(THEFILE, "$front/$_[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;
}
A:
I do not know what the problem is with your program. The issue is most
probably some programming error and has nothing to do with the file
permissions. As far as I can see the program is written is a style that
implies that you have small experience in this field. Try hard and make
lot of print instructions into your code and debug it. Unfortuately I have
no time to debug the code.

Regards,
Peter

[ back to toc ]