I have a cgi file that was working fine until i opened one up in dreamweaver. All i did was change a colour value on a body tag and re-uploaded it (in ascii) and it didnt work. (something about an internal error or cgi may not be set up for that directly - which it is cos the other pages of the script work fine still)
I re-dowloaded the file opened it in GWD text editor and saved it again as a unix file but still not working. I dont know much about cgi but the code looks fine, yet the script just will not work!
Does anybody know what dreamweaver could have done to this file?!?! Im didnt have a backup (i know) so its a real problem!
Also, when you get it fixed check the file permissions when you upload it, as some FTP programs have a default setting that may not match your requirements.
I have tried to chmod the whole cgi-bin to 777 and it still doesnt work. Also, dreamweaver doesnt seem to have actually changed any characters.
Below is the code. Can anybody see anything obviously wrong that i might have missed?
#!/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;
}
}
}
}
#-------------------------------------------------------------
%vars = e"t_vars; What's this? Looks like D.W. mangling.
%vars = et_vars;
print header(-expires=>'-1d'); This doesn't look right.
print header(expires=>'1d'); (? Just a best guess on my part)
After that, what's going on with line 178? (I say Dreamweaver's going on, that's what's going on . . . )
`"xt_prev($$rows[0]);
Not sure what the programmer intended, maybe it was supposed to be, another guess
print "xt_prev($$rows[0]);"
but at this point I'd say DW has munged it up pretty bad, start from original and keep it out of DW.
After that I got "cannot string terminator "EOF" anywhere . . . " and just couldn't get rid of it. I hate the << string operator. It always gives me crap. :-) I got it to run after changing all the EOF's to qq's, as in
instead of
print <<EOF;
.....
EOF
print qq¦
.....
¦;
Once I did that I got cannot connect to data source, which of course it can't, so at least it ran with these changes. Paypal me some dinero for further assistance (ya, right, hehehe )