PDA

View Full Version : Need help with CGI scripts. New to the language.


SpecOPS
09-02-2001, 02:59 PM
I am just now learning CGI and Perl. I have been struggling with this script for quite sometime, and was wondering if anyone that has more extensive knowledge of CGI or Perl would be kind enough to help me. All I am trying to do is make a simple little news script that will post news for me. I tried it and this is what I have come up with so far.

#!/usr/local/bin/perl
use strict;

my ($title, $body, $admin, $password, $setpass, $newsbase, @time, @days, @months);

$title=param('title');
$body=param('body');
$admin=param('admin');
$password=param('password');
#Set your password here!
$setpass="whatever you want";
@time=localtime;
@days = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday);
@months = qw(January February March April May June July August September October November December);

allow();
if ($setpass ne $password) {
print "Wrong Password!!";
} else {
open (NEWS, ">>big/dom/xsubzeronetwork/www/news.txt") || Error('open', 'file');
print NEWS "<table width='50%' align='center' bgcolor='#00002F' border='1'>
<tr>
<td align='left'><font size='4'; font color='yellow'>Posted by $admin at $time[2]:$time[1] on @days[$time[6]], @months[$time[4]] $time[3]</font></td>
</tr>
<tr>
<td align='center'><font size='4'; font color='white'>$title</font></td>
</tr>
<tr>
<td></br></td>
</tr>
<tr>
<td><font size='2'; font color='white'>$body</font></td>
</tr>
</table>";
close (NEWS);
}
sub allow {
print "Content-type: text/html\n\n";
}
sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}

I am also new to SSL and I was wondering how I would post this script into my main news page using SSL. Thanks in advance

Paulanator
09-02-2001, 06:46 PM
I am learning also, and I found a great quick ref guide that has been very helpful.

Perl and CGI for the World Wide Web, a visual quickstart guide, by Elizabeth Castro.

Great book, I have this and her HTML 4 guide, both super resources.

Good luck,
Paul

SpecOPS
09-02-2001, 10:04 PM
that is the book that i am reading to learn CGI, and I was not able to find out what was wrong with my script.

Terra
09-02-2001, 10:49 PM
$title=param('title');
Where is the function 'param()' defined at?

If you telnet/SSH into your account and:
$perl -c scriptname.pl

It will do a cursory check...

You also have your standard error logs:
logs_web/error
and
logs_cgi/script

Both of these will reveal more detailed information...

Since this is a 3rd party script, I cannot go much further than this other than pointing out your available error logs...

One more note, until you can get this to work - don't even ponder the SSL side of it yet since your environment may (or may not) change opening up a whole new ball game...

Many times people will install scripts not knowing exactly what kind of impact they will have on a server... I am asking that you take the time to learn what scripts are all about and how to perform the basics of script troubleshooting... If you are unable to fully understand the concepts of CGI, then I would recommend that you seek out the services of a professional or specialist to do the work for you...

In short, everyone has to start somewhere and there is a rich source of information all around you on the net... It is never advisable to take shortcuts when dealing with dynamic content due to the inherit risks of doing so...

Here is a link to our Service Desk FAQ that may help:
http://service.futurequest.net/tech/support.cfg/php/enduser/std_adp.php?p_sid=_zi*DcWf&p_lva=&p_refno=001119-000025&p_created=974672114&p_sp=cF9ncmlkc29ydD0mcF9yb3dfY250PTEzJnBfc2VhcmNoX3RleHQ9JnBfc2Vh cmNoX3R5cGU9MyZwX3Byb2RfbHZsMT02JnBfcHJvZF9sdmwyPX5hbnl_JnBfc29yd F9ieT1kZmx0JnBfcGFnZT0x&p_li=

Anyone care to provide links to basic CGI tutorials that has recently helped them?

In conclusion: Dynamic Content is a granted privilege and not an inherit right...

--
Terra
--I wonder what will happen if I push this big red shiny button--
FutureQuest

Rich
09-03-2001, 04:47 AM
I am also new to SSL and I was wondering how I would post this script into my main news page using SSL. Thanks in advance

Why would you need SSL for 'news'?

Rich

YFS200
09-03-2001, 03:28 PM
I would be glad to help, but I am not sure what's going on. Can you give us a little info on what this script should do?

It looks like it's part of a much larger script.
You want to append the HTML to a file right?

YFS

SpecOPS
09-03-2001, 07:33 PM
The script is suppose to be very simple. All that it is suppose to do is post a headline and body news. What I am not sure how to do is post it to a webpage that people can then inturn view. I had a script that would display the news in the way I wanted it to but then it would just dissappear after I exited out of the page.

Leo Krans
09-03-2001, 10:22 PM
There is a very easy way for putting news at your site. Have a look at http://w.moreover.com/webmaster/

But maybe this is not what you want.

Leo

YFS200
09-04-2001, 03:39 AM
I think I get it.

You have a forum setup on a web page.
You enter in the title, body, password, etc.
You submit it to this script.
The script wraps a HTML footer and header around it and appends it to news.txt.

Am I on the right track?

If this is so, can you post a link to the form you fill out so I can use it to test with?

YFS

SpecOPS
09-05-2001, 11:57 PM
ok heres a link to the form. The password is password. What I want to know is how do you get this script to post onto a html file.

YFS200
09-08-2001, 10:52 PM
I don't seem to see the link.
Did you post it?

YFS