bazz
03-22-2005, 09:17 PM
the attached code works perfectly, if I omit the code at line 8. But I have other similar scripts in the same DIR which use this code and work as expected. It's just this one that is messin' about.
Can anyone shed light on the reason why and help to fix it?
The logs show no reason but my code (which normally says "The file has been saved an added to the database), instead says,
"This file cannot be saved!<BR>please alert the system administrator".
Sorry that I can't give you more.
BTW the purpose of the code before the #####################line, is to insert two files which are being called from the specific_control_panel.pm They effectively put website appearance into the outpuuted page. Those two files are the html header and footer, which form the remainder of the page.
Bazz
#!/usr/bin/perl -w
use CGI 'param';
use lib 'relative/path/to/perl/';
require '/domains/574/1617/html/cgi-bin/specific_control_panel.pm';
print 'Content-type: text/html'."\n\n";
my $incs=new includes; #i THINK THAT THIS IS THE LINE THAT CAUSES THE TROUBLE
######################################
# 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;
#################################
#MY AMENDMENT
###############################
$Directory = $Request;
chomp ($Directory);
($vars2,$vars3,$vars4) = 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
###############################
#END OF MY AMENDMENT
###############################
if ($Path eq "") {
$Path = "ALL";
}
$Action = "Save";
#$Fdir = "$Root/FILES/$vars3/ALL";
$Fdir = "$Root/FILES/$vars3/ALL";
$Base = "";
#
# Call processing functions
#
&get_posts;
&put_header;
if ($Action eq "Save") {
&open_file;
&save_file;
&close_file;
} elsif ($Action eq "Delete") {
&delete_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/:/;/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;
$Base =~ s/ /_/g;
} elsif ($PostKey eq "title") {
$Title = $PostVal;
$Title =~ s/\r\n/ /g;
$Title =~ s/\n/ /g;
$Title =~ s/ *$//g;
} elsif ($PostKey eq "price") {
$Price = $PostVal;
$Price =~ s/\r\n/ /g;
$Price =~ s/\n/ /g;
$Price =~ s/ *$//g;
} elsif ($PostKey eq "availability") {
$Availability = $PostVal;
$Availability =~ s/\r\n/ /g;
$Availability =~ s/\n/ /g;
$Availability =~ s/ *$//g;
} elsif ($PostKey eq "date") {
$Date = $PostVal;
$Date =~ s/ *$//g;
} elsif ($PostKey eq "day") {
$Day = $PostVal;
$Day =~ s/ *$//g;
} elsif ($PostKey eq "month") {
$Month = $PostVal;
$Month =~ s/ *$//g;
} elsif ($PostKey eq "year") {
$Year = $PostVal;
$Year =~ s/ *$//g;
} elsif ($PostKey eq "reference") {
$Reference = $PostVal;
$Reference =~ s/\r\n/ /g;
$Reference =~ s/\n/ /g;
$Reference =~ s/ *$//g;
} elsif ($PostKey eq "summary") {
$Summary = $PostVal;
$Summary =~ s/\r//g;
} elsif ($PostKey eq "body") {
$Body = $PostVal;
$Body =~ s/\r//g;
}
}
}
}
#
# Print the header block
#
sub put_header {
#print $incs->header;
print <<ENDPR;
<br /><br /><br /><br /><br /><br />
ENDPR
}
#
# Open the data file
#
sub open_file {
if (!open (DAT,"> $File")) {
print "<FONT SIZE = -1><B>This file cannot be saved!<BR>please alert the system administrator.\n";
&put_trailer;
exit;
}
}
#
# Save the file
#
sub save_file {
print DAT "Date:$Day/$Month/$Year\n";
print DAT "Reference:$Reference\n";
print DAT "Availability:$Availability\n";
print DAT "Title:$Title\n";
@Summary = split(/\n/,$Summary);
foreach $Line (@Summary) {
$Line =~ s/<BR>//g;
print DAT "Summary:$Line\n";
}
@Body = split(/\n/,$Body);
foreach $Line (@Body) {
$Line =~ s/<BR>//g;
print DAT "Body:$Line\n";
}
print "<FONT SIZE = -1><B>This file has been saved<BR>and added to the Database.\n";
}
#
# Close the data file
#
sub close_file {
close DAT;
}
#
# Zap the file
#
sub delete_file {
if (unlink $File) {
print "<FONT SIZE = -1><B>This file has been deleted<BR>and removed from the Database.\n";
} else {
print "<FONT SIZE = -1><B>This file cannot be deleted.<BR>please alert the system administrator.\n";
}
}
#
# Print the trailer block
#
sub put_trailer {
print <<ENDPR;
<br /><br /><br /><br /><a href="/$vars2/$vars3/$vars4/HTMLbuilddb.pl/$Path">Back
to Database index</a>
ENDPR
}
#
# 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 "Date = $Date\n";
print "Title = $Availability\n";
print "Title = $Title\n";
print "Price = $Price\n";
print "Reference = $Reference\n";
print "Summary = $Summary\n";
print "Body = $Body\n";
print "</PRE>\n";
print "<HR>\n";
}
Can anyone shed light on the reason why and help to fix it?
The logs show no reason but my code (which normally says "The file has been saved an added to the database), instead says,
"This file cannot be saved!<BR>please alert the system administrator".
Sorry that I can't give you more.
BTW the purpose of the code before the #####################line, is to insert two files which are being called from the specific_control_panel.pm They effectively put website appearance into the outpuuted page. Those two files are the html header and footer, which form the remainder of the page.
Bazz
#!/usr/bin/perl -w
use CGI 'param';
use lib 'relative/path/to/perl/';
require '/domains/574/1617/html/cgi-bin/specific_control_panel.pm';
print 'Content-type: text/html'."\n\n";
my $incs=new includes; #i THINK THAT THIS IS THE LINE THAT CAUSES THE TROUBLE
######################################
# 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;
#################################
#MY AMENDMENT
###############################
$Directory = $Request;
chomp ($Directory);
($vars2,$vars3,$vars4) = 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
###############################
#END OF MY AMENDMENT
###############################
if ($Path eq "") {
$Path = "ALL";
}
$Action = "Save";
#$Fdir = "$Root/FILES/$vars3/ALL";
$Fdir = "$Root/FILES/$vars3/ALL";
$Base = "";
#
# Call processing functions
#
&get_posts;
&put_header;
if ($Action eq "Save") {
&open_file;
&save_file;
&close_file;
} elsif ($Action eq "Delete") {
&delete_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/:/;/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;
$Base =~ s/ /_/g;
} elsif ($PostKey eq "title") {
$Title = $PostVal;
$Title =~ s/\r\n/ /g;
$Title =~ s/\n/ /g;
$Title =~ s/ *$//g;
} elsif ($PostKey eq "price") {
$Price = $PostVal;
$Price =~ s/\r\n/ /g;
$Price =~ s/\n/ /g;
$Price =~ s/ *$//g;
} elsif ($PostKey eq "availability") {
$Availability = $PostVal;
$Availability =~ s/\r\n/ /g;
$Availability =~ s/\n/ /g;
$Availability =~ s/ *$//g;
} elsif ($PostKey eq "date") {
$Date = $PostVal;
$Date =~ s/ *$//g;
} elsif ($PostKey eq "day") {
$Day = $PostVal;
$Day =~ s/ *$//g;
} elsif ($PostKey eq "month") {
$Month = $PostVal;
$Month =~ s/ *$//g;
} elsif ($PostKey eq "year") {
$Year = $PostVal;
$Year =~ s/ *$//g;
} elsif ($PostKey eq "reference") {
$Reference = $PostVal;
$Reference =~ s/\r\n/ /g;
$Reference =~ s/\n/ /g;
$Reference =~ s/ *$//g;
} elsif ($PostKey eq "summary") {
$Summary = $PostVal;
$Summary =~ s/\r//g;
} elsif ($PostKey eq "body") {
$Body = $PostVal;
$Body =~ s/\r//g;
}
}
}
}
#
# Print the header block
#
sub put_header {
#print $incs->header;
print <<ENDPR;
<br /><br /><br /><br /><br /><br />
ENDPR
}
#
# Open the data file
#
sub open_file {
if (!open (DAT,"> $File")) {
print "<FONT SIZE = -1><B>This file cannot be saved!<BR>please alert the system administrator.\n";
&put_trailer;
exit;
}
}
#
# Save the file
#
sub save_file {
print DAT "Date:$Day/$Month/$Year\n";
print DAT "Reference:$Reference\n";
print DAT "Availability:$Availability\n";
print DAT "Title:$Title\n";
@Summary = split(/\n/,$Summary);
foreach $Line (@Summary) {
$Line =~ s/<BR>//g;
print DAT "Summary:$Line\n";
}
@Body = split(/\n/,$Body);
foreach $Line (@Body) {
$Line =~ s/<BR>//g;
print DAT "Body:$Line\n";
}
print "<FONT SIZE = -1><B>This file has been saved<BR>and added to the Database.\n";
}
#
# Close the data file
#
sub close_file {
close DAT;
}
#
# Zap the file
#
sub delete_file {
if (unlink $File) {
print "<FONT SIZE = -1><B>This file has been deleted<BR>and removed from the Database.\n";
} else {
print "<FONT SIZE = -1><B>This file cannot be deleted.<BR>please alert the system administrator.\n";
}
}
#
# Print the trailer block
#
sub put_trailer {
print <<ENDPR;
<br /><br /><br /><br /><a href="/$vars2/$vars3/$vars4/HTMLbuilddb.pl/$Path">Back
to Database index</a>
ENDPR
}
#
# 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 "Date = $Date\n";
print "Title = $Availability\n";
print "Title = $Title\n";
print "Price = $Price\n";
print "Reference = $Reference\n";
print "Summary = $Summary\n";
print "Body = $Body\n";
print "</PRE>\n";
print "<HR>\n";
}