PDA

View Full Version : trouble locating .pm file in my cgi-bin


bazz
03-02-2005, 06:24 PM
Hi,

This is quite difficult to explain in words but here goes.

I have two files in the same directory.
Both require a .pm file from the cgi-bin.
The code at the top of both files is the same.
The .pm file is common to both perl files.
One file can find it and works perfectly :))
The other throws up the error 500 page saying:

Can't locate /domains/574/1617/html/cgi-bin/control_panel.pm in @INC (@INC contains: relative/path/to/perl/ C:\Ambrose\CMS\cgi-bin\1\MEAL_M~1\admin C:/Perl/lib C:/Perl/site/lib .) at showbuild.pl line 8.

Now I am completley stumped, frustrated and heading twords hairless. I expect that I am missing something very simple but I think I need some therapy if I can't even copy and paste any more.

here's the header codes for pulling the .pm file

use CGI 'param';

use lib 'relative/path/to/perl/';

require '/domains/574/1617/html/cgi-bin/control_panel.pm';



my $incs=new includes;
print 'Content-type: text/html'."\n\n";


here's the script in full, including the header (above).

#!/usr/bin/perl
print "Content-type: text/html\n\n";

use CGI 'param';

use lib 'relative/path/to/perl/';

require '/domains/574/1617/html/cgi-bin/control_panel.pm';





my $incs=new includes;
print 'Content-type: text/html'."\n\n";

# Print the HTML content header; set global names
#
$Root = $ENV{"DOCUMENT_ROOT"};
$Path = $ENV{"PATH_INFO"};
$Referer = $ENV{"HTTP_REFERER"};
$Request = $ENV{"REQUEST_URI"};
$Path =~ s/[^a-zA-Z0-9\£\.\_]//g;


$Directory = $Request;

chomp ($Directory);
($vars1,$vars2,$vars3,$vars4,$vars5,$vars6,) = split(/\//,$Directory);

#That splits to give vars like these?

#$vars1 = cgi-bin
#$vars2 = ClientName
#$vars3 = whether admin folder or not
#$vars4 = MenuType
#$vars5 = file.pl
#$vars6 = specific menu


#$Files = `ls $Root/cgi-bin/a_default/Meal_Menus/files/$Path/*`;
#$Files = `ls $Root/$vars2/$vars3/$vars4/files/$Path/*`;



if ($Path eq "") {
$Path = "ALL";
}
$Action = "View";
$Fdir = "$Root/$vars2/$vars3/$vars4/files/ALL";




$Base = "NOFILE";

#
# Call the processing functions
#
&get_posts;
&put_header;
if ($Action eq "Create") {
$File = $Fdir . "/" . $Base;
if (open (DAT, "< $File")) {
print "<H3>This file already exists!</H3>\n";
&put_trailer;
close DAT;
exit;
}
} else {
&open_file;
}
&put_file;
&close_file;
&put_trailer;

#
# Retrieve postings
#
sub get_posts {
while (<>) {
@Posts = split(/&/);
foreach $PostItem (@Posts) {
($PostKey,$PostVal) = split(/=/,$PostItem);
$PostVal =~ s/\+/_/g;
$PostVal =~ s/%(..)/pack("c",hex($1))/ge;
$PostVal =~ s/\n//g;
if ($PostKey eq "action") {
$Action = $PostVal;
} elsif ($PostKey eq "file") {
$File = $PostVal;
$File =~ s/ /_/g;
} elsif ($PostKey eq "fdir") {
$Fdir = $PostVal;
$Fdir =~ s/ /_/g;
} elsif ($PostKey eq "base") {
$Base = $PostVal;
}
}
}
}

#
# Print the header block
#
sub put_header {

#print $incs->header;
print <<ENDPR;

<br /><br />
<strong><h1>Preview the entered result</h1></strong>
ENDPR
}

#
# Open the data file
#
sub open_file {
if (!open (DAT,"< $File")) {
print "<H3>This file does not exist!</H3>\n";
&put_trailer;
exit;
}
}

#
# Display the file
#
sub put_file {

#
# Load or initialise for new
#
if ($Action ne "Create") {

#
# Load data from existing file
#
while (($Line = <DAT>)) {
chop $Line;
($Keyword,$Value) = split(/:/,$Line);
if ($Keyword eq "Date") {
$Date = $Value;
} elsif ($Keyword eq "Availability") {
$Availability = $Value;
} elsif ($Keyword eq "Reference") {
$Reference = $Value;
} elsif ($Keyword eq "Title") {
$Title = $Value;
} elsif ($Keyword eq "Price") {
$Price = $Value;
} elsif ($Keyword eq "Summary") {
$Summary = $Summary . $Value;
if ($Action ne "Edit") {
$Summary = $Summary . "<BR>\n";
} else {
$Summary = $Summary . "\n";
}
} elsif ($Keyword eq "Body") {
$Body = $Body . $Value;
if ($Action ne "Edit") {
$Body = $Body . "<BR>\n";
} else {
$Body = $Body . "\n";
}
}
}
chop $Summary;
chop $Body;
} else {

#
# New file - set defaults
#
$Date = `date +%d/%m/%Y`;
$Availability = "";
$Price = "";
$Title = "";
$Reference = "";
$Summary = "";
$Body = "";
}

#
# Break the date
#
($Day,$Month,$Year) = split(/\//,$Date);

#
# Start the form/table
#
print "<FORM ACTION=/$vars2/$vars3/$vars4/$vars5/savefile.pl/$Path METHOD=POST>\n";
print "<TABLE ALIGN=CENTER WIDTH=80% CELLPADDING=3 CELLSPACING=2 BORDER=0>\n";
print "<TR><TD><FONT SIZE = -1><B>Reference</B></TD>\n";
print "<TD><FONT SIZE = -1>\n";
if ($Action eq "Create" || $Action eq "Edit") {
print "<INPUT NAME=reference VALUE=\"$Base\">\n";
} else {
print "$Reference\n";
}

print "<TR><TD><FONT SIZE = -1><B>Available until</B></TD>\n";
print "<TD><FONT SIZE = -1>\n";
if ($Action eq "Create" || $Action eq "Edit") {
print "<INPUT NAME=availability VALUE=\"$Availability\">\n";
} else {
print "$Availability\n";
}

# print "</TD></TR>\n";
# print "<TR><TD><FONT SIZE = -1><B>Date</B></TD>\n";
# print "<TD><FONT SIZE = -1>\n";
# if ($Action eq "Create" || $Action eq "Edit") {
# print "<SELECT NAME=day SIZE=1>\n";
# for ($SDay = 1;$SDay <= 31;$SDay++) {
# if ($SDay == $Day) {
# print "<OPTION SELECTED VALUE=$SDay>$SDay\n";
# } else {
# print "<OPTION VALUE=$SDay>$SDay\n";
# }
# }
# print "</SELECT>\n";
# print "<SELECT NAME=month SIZE=1>\n";
# for ($SMonth = 1;$SMonth <= 12;$SMonth++) {
# if ($SMonth == $Month) {
# print "<OPTION SELECTED VALUE=$SMonth>$SMonth\n";
# } else {
# print "<OPTION VALUE=$SMonth>$SMonth\n";
# }
# }
# print "</SELECT>\n";
# print "<SELECT NAME=year SIZE=1>\n";
# for ($SYear = 1999;$SYear <= 2037;$SYear++) {
# if ($SYear == $Year) {
# print "<OPTION SELECTED VALUE=$SYear>$SYear\n";
# } else {
# print "<OPTION VALUE=$SYear>$SYear\n";
# }
# }
# print "</SELECT>\n";
# } else {
# print "$Date\n";
# }
print "</TD></TR>\n";
print "<TR><TD><FONT SIZE = -1><B>Title</B></TD>\n";
print "<TD><FONT SIZE = -1>\n";
if ($Action eq "Create" || $Action eq "Edit") {
print "<INPUT NAME=title VALUE=\"$Title\">\n";
} else {
print "$Title\n";
}
print "</TD></TR>\n";
print "</TD></TR>\n";
print "<TR><TD><FONT SIZE = -1><B>Price</B></TD>\n";
print "<TD><FONT SIZE = -1>\n";
if ($Action eq "Create" || $Action eq "Edit") {
print "<INPUT NAME=price VALUE=\"$Price\">\n";
} else {
print "$Price\n";
}
print "</TD></TR>\n";
print "<TR><TD><FONT SIZE = -1><B>Summary</B></TD>\n";
print "<TD><FONT SIZE = -1>\n";
if ($Action eq "Create" || $Action eq "Edit") {
print "<TEXTAREA NAME=summary ROWS=2 COLS=50>\n";
print "$Summary\n";
print "</TEXTAREA>\n";
} else {
print "$Summary\n";
}
print "</TD></TR>\n";
print "<TR><TD><FONT SIZE = -1><B>Additional Info</B></TD>\n";
print "<TD><FONT SIZE = -1>\n";
if ($Action eq "Create" || $Action eq "Edit") {
print "<TEXTAREA NAME=body ROWS=10 COLS=50>\n";
print "$Body\n";
print "</TEXTAREA>\n";
} else {
print "$Body\n";
}
print "</TD></TR>\n";
print "</TABLE>\n";
print "<CENTER>\n";
if ($Action eq "Create" || $Action eq "Edit") {
print "<INPUT TYPE=SUBMIT NAME=action VALUE=Save>\n";
} elsif ($Action eq "Delete") {
print "<INPUT TYPE=SUBMIT NAME=action VALUE=Delete>\n";
}
print "<INPUT TYPE=HIDDEN NAME=file VALUE=$File>\n";
print "<INPUT TYPE=HIDDEN NAME=fdir VALUE=$Fdir>\n";
print "<INPUT TYPE=HIDDEN NAME=base VALUE=$Base>\n";
print "</FORM>\n";
}

#
# Close the data file
#
sub close_file {
close DAT;
print qq(
<CENTER><strong>Instructions:</strong>
<br />
1. The entry to Additional Info must be in list form. Nothing technical here, simply after each list item, hit the return key to see the dialogue display as a list<br /><br />
2. If using accents, grave, acute etc, for such words as T&acirc;ble d'H&ocirc;te, the following codes should be useful:-<br /><br />
Accents: - Place your chosen vowel [upper or lower case], between the &amp; and the code.<br />
<br />&amp;amp; = ampersand<br />&amp;Ocirc; = &Ocirc; Replace the letter as appropriate.<br />
&amp;deg; = &deg;degrees (proof)<br />
&amp;egrave; = &egrave;<br />
&amp;Eacute; = &Eacute;<br />
&amp;egrave; = &egrave;
<br />
<a class=textlink href="/$vars2/$vars3/$vars4/$vars5/builddb.pl/$Path">Back
to Database index</a>
<div class="leftdiv"></div>
</div>
)


}

#
# Print the trailer block
#
sub put_trailer {
print <<ENDPR;


ENDPR
}
#print $incs->footer;


#
# Display key data
#
sub put_keys {
print "<PRE>";
print "Root = $Root\n";
print "Path = $Path\n";
print "Referer = $Referer\n";
print "Request = $Request\n";
print "File = $File\n";
print "Fdir = $Fdir\n";
print "Base = $Base\n";
print "</PRE>\n";
print "<HR>\n";
}



and because I know many of you hate somebody just putting up a whole script and then asking, plz fix this, I shall show you the other file that is in the same folder and, which works. The only fault in the code above is in the top 8 lines. Maybe its a conflict but I just don't get it.

working code


#!/usr/bin/perl -w
#
use CGI 'param';

use lib 'relative/path/to/perl/';

require '/domains/574/1617/html/cgi-bin/control_panel.pm';



my $incs=new includes;
print 'Content-type: text/html'."\n\n";

#
# Print the HTML content header; set global names
#
$Root = $ENV{"DOCUMENT_ROOT"};
$Path = $ENV{"PATH_INFO"};
$Referer = $ENV{"HTTP_REFERER"};
$Request = $ENV{"REQUEST_URI"};
$Path =~ s/[^a-zA-Z0-9\.]//g;


$Directory = $Request;

chomp ($Directory);
($vars1,$vars2,$vars3,$vars4,$vars5,$vars6,) = split(/\//,$Directory);

#That splits to give vars like these?

#$vars2 = cgi-bin
#$vars3 = ClientName
#$vars4 = MenuType
#$vars5 = file.pl
#$vars6 = specific menu





if ($Path eq "") {
$Path = "ALL";
}
$Files = `ls $Root/cgi-bin/a_default/room_tariffs/files/$Path/*`;
$Files =~ s/\n/ /g;
@Files = split(/ /,$Files);

#
# Call the processing functions
#
&get_posts;
&put_header;
&generate_index;
&put_trailer;

#
# Retrieve postings
#
sub get_posts {
while (<>) {
@Posts = split(/&/);
foreach $PostItem (@Posts) {
($PostKey,$PostVal) = split(/=/,$PostItem);
}
}
}

#
# Print the header block
#
sub put_header {

print $incs->header;
print <<ENDPR;
<link rel="stylesheet" href="/stylesheets/$vars3/html/prices.css" type="text/css" media="screen">
<br /><br />
<strong><h1>Modify Prices</h1></strong>
ENDPR
}

#
# Generate the index
#
sub generate_index {

#
# Generate the table header
#
print "<table class=table>\n";
print "<tr>\n";
print "<td class=title_td>Dates</td>\n";
print "<td class=title_td>Room Type</td>\n";
print "<td class=title_td>Price</td>\n";
print "<td class=title_td colspan=3>Control Buttons</td>\n";
print "</tr>\n";

#
# Process each file in the list
#
foreach $File (@Files) {

#
# Extract the base file name
#
$Base = $File;
$Base =~ s/.*\///;

#
# Set defaults
#
$Dates = "Dates not entered";
$Room_Type = "Room Type not entered";
$Price = "Price not entered";
$Description = "No Description";

#
# Extract headers from file
#
if (open (DAT,"< $File")) {
$Body = 0;
while ($Body == 0 && ($Line = <DAT>)) {
chop $Line;
($Keyword,$Value) = split(/:/,$Line);
if ($Keyword eq "Dates") {
$Dates = $Value;
} elsif ($Keyword eq "Room_Type") {
$Room_Type = $Value;
} elsif ($Keyword eq "Price") {
$Price = $Value;
} elsif ($Keyword eq "Description") {
$Description = $Value;
}
else {
$Body = 1;
}
}

close DAT;
}

#
# Create the form/table row for this item
#
print "<tr><form action=/cgi-bin/a_default/room_tariffs/admin/showdb.pl/$Path method=post>\n";
print "<td class=normal_td>$Dates</td>\n";
print "<td class=normal_td>$Room_Type</td>\n";
print "<td class=normal_td>$Price</td>\n";


print "<td class=normal_td><input type=submit name=action value=View></td>\n";
print "<td class=normal_td><input type=submit name=action value=Edit></TD>\n";
print "<td class=normal_td><input type=submit name=action value=Delete></TD>\n";
print "<td><input type=hidden name=file value=$File></TD>\n";
print "<td><input type=hidden name=fdir value=$Root/cgi-bin/a_default/room_tariffs/files/$Path></td>\n";
print "<td><input type=hidden name=base value=$Base></td>\n";
print "</form></tr>\n";
}

#
# Close the table and create the CREATE form
#
print "</table>\n";
print "<center>\n";
print "<br /><strong>Please name your entry Item1, Item2, etc (No spaces)</strong>\n";
print "<br /><br />\n";
print "<form action=/cgi-bin/a_default/room_tariffs/admin/showdb.pl/$Path method=post>\n";
print "<input name=base>\n";
print "<input type=submit name=action value=Create>\n";
print "<input type=hidden name=fdir value=$Root/cgi-bin/a_default/room_tariffs/files/$Path>\n";
print "</form>\n";
print "<a href=\"/$vars2/$vars3/control_panel.pl\">Return to Control Panel</a>\n";
}

#
# Print the trailer block
#
sub put_trailer {
print $incs->footer;
}

#
# Display key data
#
sub put_keys {
print "<PRE>";
print "Root = $Root\n";
print "Path = $Path\n";
print "Referer = $Referer\n";
print "Request = $Request\n";
print "Files = $Files\n";
print "</PRE>\n";
print "<HR>\n";
}



any pointers greatly appreciated.

Bazz

mlseim
03-02-2005, 07:49 PM
Bazz ...

Did you just copy and paste your example wrong on the post,
or are you doing "Content-type:" twice on your actual script?

You can't do it twice ....
===================================================

#!/usr/bin/perl

print "Content-type: text/html\n\n"; <--- take this one out.

use CGI 'param';

use lib 'relative/path/to/perl/';

require '/domains/574/1617/html/cgi-bin/control_panel.pm';


my $incs=new includes;
print 'Content-type: text/html'."\n\n";

bazz
03-02-2005, 08:55 PM
Gonna try to take a break for a couple of days. Got it sorted when I changed the relative filepaths (I added another ../) what seems to have fristreated me was that the server still has a major issue which is slowing it down and so it wasn't updating my changes quick enough. They'd better get it fixed soon as its now nearly six weeks since it started to play up - an age.

Thanks Max for the pointer. I had C+P'd it wrongly if that doesn't sound wude :)

bazz