Pearl Script Help


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Pearl Script Help
# 1  
Old 04-23-2005
Pearl Script Help

Code:
#!/usr/bin/perl


$basedir = "/home/MYUSERID/public_html/ordered_files";
$allowall = "yes";
$theext = ".gif";

use CGI;
 
$onnum = 1;

while ($onnum != 11) {
my $req = new CGI; 
my $file = $req->param("FILE$onnum"); 
if ($file ne "") {
my $fileName = $file; 
$fileName =~ s!^.*(\\|\/)!!; 
$newmain = $fileName;
if ($allowall ne "yes") {
if (lc(substr($newmain,length($newmain) - 4,4)) ne $theext){
$filenotgood = "yes";
}
}
if ($filenotgood ne "yes") { 
open (OUTFILE, ">$basedir/$fileName"); 
print "$basedir/$fileName<br>";
while (my $bytesread = read($file, my $buffer, 1024)) { 
print OUTFILE $buffer; 
} 
close (OUTFILE); 
}
}
$onnum++;
}


my $sendmail = "/usr/sbin/sendmail";

# A text file containing a list of valid email recipients and the web pages to 
# which the user should be redirected after email is sent to each, on 
# alternating lines.  This allows one copy of the script to serve multiple 
# purposes without the risk that the script will be abused to send spam.
# YOU MUST CREATE SUCH A TEXT FILE AND CHANGE THE NEXT LINE TO ITS
# LOCATION ON THE SERVER.

my $emailConfPath = "http://www.MEWEBSITE.com/emailman/email.conf";

# Parse any submitted form fields and return an object we can use
# to retrieve them
my $query = new CGI;

my $project = &clean($query->param('project'));
my $name = &clean($query->param('name'));
my $number = &clean($query->param('number'));
my $address = &clean($query->param('address'));
my $address2 = &clean($query->param('address2'));
my $citystate = &clean($query->param('citystate'));
my $sizing = &clean($query->param('sizing'));
my $comments = &clean($query->param('comments'));
my $subject = &clean($query->param('subject'));
my $file1 = &clean($query->param('file1'));
my $file2 = &clean($query->param('file2'));
my $text = &clean($query->param('text'));
my $font = &clean($query->param('font'));
my $dropshadow = &clean($query->param('dropshadow'));
my $textcolor = &clean($query->param('textcolor'));
my $shadowcolor = &clean($query->param('shadowcolor'));


#Note: subject is not mandatory, but you can easily change that
if (($project eq "") || (($name eq "") || ($number eq "") || ($address eq "") || ($citystate eq "") || ($sizing eq ""))
{
	&error("Requist Denied",
		"You must fill out all of the required fields." .
		"Please Try Again.");
}

if (!open(IN, "$emailConfPath")) {
	&error("Configuration Error",
		"The Configuration file is missing or corrupt" .
		"please repair the file.");
	my $ok = 0;
	while (1) {
		my $recipientc = <IN>;
		if ($recipientc eq "") {
			last;
		}
		my $returnpage = <IN>;
		if ($returnpage eq "") {
			last;
		}
		if ($recipientc eq $recipient) {
			$ok = 1;
			last;
		}
	}
	close(IN);
	if (!$ok) {
		&error("Email Rejected",
			"You are unable to submit a file at this time try e-mailing this form to :" .
			"user@MEWEBSITE.com to get your order in." .
			"You also may note that there is a problem with this form on the site.");
	}
	# Open a pipe to the sendmail program
	open(OUT, "|$sendmail -t");
	print OUT <<EOM
To: $recipient
Subject: $subject
Project Name:       $project
Customers Name:     $name 
Customers Phone:    $number 
Address:            $address 
                    $address2 
City/State/Zip:     $citystate 
Sizing:             $sizing
Files:              $file1
                    $file2
Lettering Text:     $text
Font for Lettering: $font
Drop Shadow:        $dropshadow
Text Color:         $textcolor
Shadow Color:       $shadowcolor
Additional Notes:   $comments

EOM
;
	close(OUT);
	# Now redirect to the appropriate "landing" page for this recipient.
	print $query->redirect($returnPage);
}

sub clean
{

	my $s = shift @_;
	$s =~ s/^\s+//;
	$s =~ s/\s+$//;
	return $s;
}

sub error
{
	my($title, $content) = @_;
	print $query->header;
	print <<EOM
<html>
<head>
<title>$title</title>
</head>
<body>
<h1 align="center">$title</h1>
<p>
$content
</p>
EOM
;
	exit 0;
}


Last edited by nikah_01; 04-23-2005 at 10:15 PM..
# 2  
Old 04-23-2005
It might help if you were to indicate what help you want.

Also it would be best to enclose your script in code tags so thatformatting is preserved, it makes it much easier to read.

Last edited by reborg; 04-23-2005 at 08:47 PM..
# 3  
Old 04-23-2005
Okay that is the code what it is supposed to do is work with a form to upload
files and email the form info.

Can someone take a look and tell me where the problem is

The error is 500
Unexpected server error.
It doesn't give any details.
# 4  
Old 04-23-2005
Sorry new here I edited and added the details after.
My srver is giving me a very plain error message and doesn't give a line number either...
# 5  
Old 04-23-2005
Can you access the server log? I mean the Apache error log? If you are on a paid host, you can mostly access it (via CPanel, Plesk or something like that), or maybe you can have access to the physical log too (for dedicated server). Most of the time the exact perl error should be there with the line number with some context information.

The 500 internal server error message is not the perl error message that should give. Unless you can give this error, it is impossible to tell what went wrong.
# 6  
Old 04-23-2005
Premature end of script headers: /home/MEUSERID/public_html/cgi-bin/order.cgi Execution of order.cgi aborted due to compilation errors. {" syntax error at order.cgi line 71, near ")
# 7  
Old 04-23-2005
Okay it seems to me I am having a problem with the ending of the script before the files are finished uploading. I thinks this is because I combined 2 old scipts I wrote and edited for the needs of this site so can someone tell me where I need to put the
exit0;
command at at I think that should solve the problem....
Or at least the one I know about now.

Thank You
Nikah
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

2. UNIX for Dummies Questions & Answers

Pearl script Net::SFTP authentication error

#!/usr/local/bin/perl -w use Net::SFTP; use File::Copy; my $user=(getpwuid($<)); my $server = "servername"; print "user - $user server - $server \n"; my %args = ( user => "$user", ssh_args => {port=> 'portnum'} ); $args{debug} = 1; $args{user} = "user"; my $sftp=Net::SFTP->new($server,... (1 Reply)
Discussion started by: Yashaswini H L
1 Replies

3. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

4. UNIX for Dummies Questions & Answers

Pearl,Unix systems Commands

hi does anyone have any knowledge of pearl, unix systems commmands and what are the basic commands??????apppreciated for your help. (1 Reply)
Discussion started by: BIzzare12
1 Replies

5. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

6. Shell Programming and Scripting

c function calling from a pearl script

Hi, Is it possible to call a c function defined in a .c file from a pearl script? How is this possible? Thannks in advance, JS (2 Replies)
Discussion started by: jisha
2 Replies

7. UNIX for Advanced & Expert Users

Pearl script to automate SSL certificate import

Hello, I want to automate the process of importing a SSL certificate name *.cer to cacerts through perl script. both the certificates belong to same folder. The usual way of doing it is by executing the below command which imports the key name certnew.cer to cacerts in the same folder. ... (4 Replies)
Discussion started by: m_kk
4 Replies

8. Shell Programming and Scripting

how to log if the program contains both bourne-shell & pearl scripts

I have a program (say, MyProgram) written in Bourne-shell script, but at some point it calls another script written in pearl, as illustrated below: #!/bin/sh ..... case $x in 1) ConfigSystem1 ( b-shell script) 2) ConfigSystem2 ( pl) 3) ConfigSystem3 (b-shell) .... Then I create... (0 Replies)
Discussion started by: bluemoon1
0 Replies

9. Shell Programming and Scripting

pearl

Sir, I am in doubt using pearl can i create exe files in pearl. Also is there a pearl compiller.I am new to pearl and please suggest how can i learn pearl arun (1 Reply)
Discussion started by: arunkumar_mca
1 Replies
Login or Register to Ask a Question