View Full Version : Uploading CGI scripts
iambaz
02-28-2005, 10:53 AM
Hi,
I am updating a web site for a client. They had a cgi chat board on the old one that they wished to keep.
The thing is, i downloaded the cgi files to my machine, opened one up and edited it in dreamwever. When i uploaded it again, im getting an error. I then read it must be upoaded in ascii which i did - but got a different error. The ONLY thing i edited on the script was a hex colour value.
Another thing i noticed is that when i open the cgi files that work and were not edited in windows notebad - the script is not legible, however when i re-download the edited file i had uploaded in ascii mode - it is still legible. Does this mean that the files are not uploading in the correct format?
Skeeter87
02-28-2005, 11:46 AM
Try saving it as a unix text file... You can do this for example with the GWD text editor available at: http://www.gwdsoft.com/
iambaz
02-28-2005, 11:56 AM
Great text editor! :thumbsup:
I have tried saving as unix and still get this error:
"The server encountered an internal error or misconfiguration and was unable to complete your request. Your administrator may not have enabled CGI access for this directory."
I know that cgi is enabled as the other pages from the chat board are still working fine.
iambaz
02-28-2005, 11:58 AM
Could i have completely wrecked the script cos i opened and saved it in dreamwever? When i open it in the GWD editor it still looks the same as the rest. Im stumped.
iambaz
02-28-2005, 12:21 PM
After some more investigation, I have found that if i open a cgi script with dreamweaver and then save it also in dreamwever, the script no longer works. Even if i upload it as a unix file. I am baffled. I haveopened up the code in a text editor afetr its been saved in DW and it looks exactly the same, yet for some reason just will not run.
Doesn anybody know why this is?
mlseim
02-28-2005, 01:56 PM
Did you set the permissions correctly for your script?
That would be the thing called: CHMOD ... set to 755.
Not sure how it's done with Dreamweaver, but it's a
typical function with FTP programs.
iambaz
02-28-2005, 04:17 PM
Yes i have chmod all the files in the cgi-bin to 777 just to be sure (and tried 755).
Below is the code, can anybody see any obvious errors i might be missing?
#!/usr/bin/perl
#
# Author : Eddie Bragg
# Date : 08/11/2000
#
# Edited by : Paul Molyneux
# Date : 22/04/2002
#
# Discussion room script
# The front page of the discussion forums
use DBI;
use CGI qw/:standard/;
use Time::localtime;
use Time::Local;
use discuss;
%vars = e"t_vars;
if ($dbh = DBI->connect($dsn, $user, $pass)) {
print header(-expires=>'-1d');
&draw_html;
$dbh->disconnect;
} else {
print "location: ../noservice.html\n\n";
}
exit(0);
#-------------------------------------------------------------
sub draw_html {
# sub routine that draw the html to the browser.
print <<EOF;
html>
<head>
<title> --- discussion room --- </title>
<link rel="stylesheet" href="../css/bibby.css" type="text/css">
<script language="javascript" src="../js/mo.js"></script>
</head>
<body bgcolor="#010066">
<center>
<table width=640 cellpadding="0" cellspacing="0" border="0">
<tr><td align=left valign="bottom">
<a href="add_message.cgi" onmouseover="switchto('post',1);window.status='Post New Message';return true"
onMouseOut="switchto('post',0);window.status=' ';return true" onfocus="blur()">
<img src="../images/post_newoff.gif" width="165" height="25" border="0" alt="Post New Message" name="post"></a>*
</td>
<td align="right" valign="top"><a href="discuss_main.cgi"
onMouseover="window.status='Bibby Line Limited'; return true"
onMouseout="window.status=''; return true">
<img src="../images/logo.gif" width="253" height="62" alt="Bibby Line Limited" border="0"></a></td>
</tr>
<tr><td align=left class="header">Discussions</td></tr>
<tr><td align=center colspan="2">
<table width="640" border="0" cellspacing="0" cellpadding="1">
<tr><td>
<table width=640 class="tablebg">
<tr class="boardheaderbg">
<td align=left width=80 class="boardtop">Date Posted</td>
<td align=left width=260 class="boardtop">Subject</td>
<td align=left width=120 class="boardtop">Author</td>
<td align=left width=50 class="boardtop">Messages</td>
<td align=center width=70 class="boardtop">Last Msg</td>
<td align=center width=70 class="boardtop">Replies</td>
</tr>
EOF
&show_messages;
print <<EOF;
/table>
</td></tr>
</table>
</td></tr>
</table>
</body>
</html>
EOF
}
#-------------------------------------------------------------
sub show_messages {
# Retrieves all 1st messages in a thread for the selected forum and outputs them in a table
my $sql = "SELECT a.message_id,a.name,a.subject,a.posted,a.thread_id,b.messages,b.last_added,b.replies FROM messages AS a,threads AS b";
$sql .= " WHERE a.message_id = a.thread_id AND a.thread_id = b.thread_id AND a.status = 'l' ORDER BY b.last_added DESC";
my $allmessages = [];
my $ms;
my $bgcolor="#CCCCCC";
my $now = time();
my $rows;
my @dthreads;
my $row_num = 0;
if (!$vars{'srn'}) {
$vars{'srn'} = 0;
$vars{'prn'} = 0;
} else {
$vars{'prn'} = ($vars{'srn'} - 19);
}
if ($new_sth = &do_sql_command($sql,$dbh)) {
$rows = &do_count_sql($sql,$dbh);
if ($$rows[0] > 0) {
while ($allmessages = $new_sth->fetch) {
if (($$rows[0] > 20) && (($$allmessages[6] + 2592000) < $now)) {
push(@dthreads,$$allmessages[4]);
$$rows[0] -=1;
} else {
if ($row_num >= $vars{'srn'}) {
my ($dposted,$tposted) = &format_date($$allmessages[3]);
my ($ldposted,$tposted) = &format_date($$allmessages[6]);
print <<EOF;
tr>
<td align=left height=20 width=80 bgcolor="$bgcolor" class=text><font size=2 color="#000000">*$dposted</font></td>
<td align=left height=20 width=260 bgcolor="$bgcolor" class=text><a href="read_message.cgi?fmt=1&mid=$$allmessages[0]&thid=$$allmessages[4]"><font size=2>$$allmessages[2]</font></a></td>
<td align=left height=20 width=120 bgcolor="$bgcolor" class=text><font size=2 color="#000000">$$allmessages[1]</font></td>
<td align=center height=20 width=50 bgcolor="$bgcolor" class=text><font size=2 color="#000000">$$allmessages[5]</font></td>
<td align=center height=20 width=70 bgcolor="$bgcolor" class=text><font size=2 color="#000000">$ldposted</font></td>
<td align=center height=20 width=70 bgcolor="$bgcolor" class=text><font size=2 color="#000000">$$allmessages[7]</font></td>
</tr>
EOF
if ($row_num == ($vars{'srn'}+18)) {
$vars{'srn'}+=19;
last;
}
}
$row_num++;
}
if ($bgcolor eq "#CCCCCC") { $bgcolor = "#DDDDDD"; } else { $bgcolor = "#CCCCCC"; }
}
if (!$row_num) {
print "<tr><td colspan=5 height=30 class='wtext'><font size=1>No message posted in this message forum</font></td></tr>";
}
if ($row_num == $$rows[0]) { $vars{'srn'} = $$rows[0]; }
`"xt_prev($$rows[0]);
if ($#dthreads != -1) { &delete_threads(@dthreads) }
} else {
print "<tr><td colspan=4 height=30 class='wtext'><font size=1>No message posted in this message forum</font></td></tr>";
}
$new_sth->finish;
}
}
#-------------------------------------------------------------
sub next_prev {
# If there are more than 20 messages it will put a next and previous if you have clicked to the next page
my ($rws) = @_;
my $npline = "<tr><td align=\"left\" colspan=3 valign=center>";
if ($vars{'srn'} > 19) {
$npline .= "<a href=\"discuss_main.cgi?srn=".$vars{'prn'}."\" onMouseOver=\"switchto(\'previous\',1);window.status=\'Previous\';return true\" onMouseOut=\"switchto(\'previous\',0);window.status=\' \';return true\" onFocus=\"blur()\">
<img src=\"../images/previousoff.gif\" width=\"76\" height=\"17\" border=\"0\" alt=\"Previous\" name=\"previous\"></a>";
}
$npline .= "</td><td align=\"right\" colspan=3 valign=center>";
if ($vars{'srn'} < $rws) {
$npline .= "<a href=\"discuss_main.cgi?srn=".$vars{'srn'}."&prn=".$vars{'prn'}."\" onMouseOver=\"switchto(\'next\',1);window.status=\'Next\';return true\" onMouseOut=\"switchto(\'next\',0);window.status=\' \';return true\" onFocus=\"blur()\">
<img src=\"../images/nextoff.gif\" width=\"53\" height=\"17\" border=\"0\" alt=\"Next\" name=\"next\"></a>";
}
$npline .= "</td></tr>";
print $npline;
}
#-------------------------------------------------------------
sub delete_threads {
# Deletes a thread if the last message is more than 30 days old
my (@threads) = @_;
my $sql;
my $new_sth;
my $del_sth;
foreach $thread (@threads) {
$sql = "SELECT message_id FROM messages WHERE thread_id = '".$thread."'";
if ($new_sth = &do_sql_command($sql,$dbh)) {
my $delmessages = [];
while ($delmessages = $new_sth->fetch) {
&delete_message_file($$delmessages[0]);
$sql = "DELETE FROM messages WHERE message_id = '".$$delmessages[0]."'";
$del_sth = &do_sql_command($sql,$dbh);
$del_sth->finish;
}
$new_sth->finish;
$sql = "DELETE FROM threads WHERE thread_id = '".$thread."'";
if ($new_sth = &do_sql_command($sql,$dbh)) {
$new_sth->finish;
}
}
}
}
#-------------------------------------------------------------
mlseim
02-28-2005, 05:53 PM
With my set font, I can't tell if these are single quotes or double quotes.
these two lines:
%vars = e"t_vars;
`"xt_prev($$rows[0]);
that's sort of suspicious.
You might try commenting out large sections of
your script and see if you can find the part where
the error is occuring.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.