Author Topic: perl training wheels  (Read 3436 times)

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
perl training wheels
« on: 23 September 2002, 03:19 »
i wrote the following into a file:
Code: [Select]
as per a tutorial page i found online, now i have got perl installed on my computer in /usr/bin/perl and when i visit the file with mozilla, it displays it as text rather than getting perl to execute it and then display the html.

Why is this? is it because i am visiting it on the same machine? is there some config i have not set? is the perl i have installed somehow different from the perl i need to do this?

sorry, i know it is very newbish to ask, but what's going on (or not)?
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #1 on: 23 September 2002, 04:01 »
What did you name the file? Usually Apache is configured to treat *.cgi files as executable programs such as Perl programs. Also Apache needs to be configured to recognize *.cgi files as executable programs which it usually doesn't come configured to do so by default. You also need to put "ExecCGI" in your Options in the Apache configuration file for the directory that you want to be able to execute CGI programs.  Also, the file needs to be set "executable" for the user that your Apache server runs under (usually user "apache" or "nobody" but as long as you do a "chmod a+rx file.cgi" that would cover it).

Do you need help with the Apache configuration? I gave m0r the same informtation in another thread...
Someone please remove this account. Thanks...

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
perl training wheels
« Reply #2 on: 23 September 2002, 04:16 »
wow!   :confused:  yes i think i do, where's the thread? thanks, i never realised how much there was out there that i didn't know!

now as i say, there's no reason i shouldn't be able to test my file out on the same machine as it is hosted on is there?
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #3 on: 23 September 2002, 04:22 »
Not at all. Just put it under your web root (as long as you have Apache configured with ExecCGI and the other configs I mentioned) and point your browser to http://localhost/file.cgi.

There actually should be an area that *is* configured by default to run CGI files and that would be under /var/www/cgi-bin on the local directory which would be http://localhost/cgi-bin/file.cgi in the browser.  I'll see if I can dig up the thread on configuring Apache to run CGI files in any directory under your web root.

Yes, here it is:
http://forum.fuckmicrosoft.com/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=5&t=000766

[ September 22, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...

Calum

  • Global Moderator
  • Member
  • ***
  • Posts: 7,812
  • Kudos: 1000
    • Calum Carlyle's music
perl training wheels
« Reply #4 on: 23 September 2002, 04:26 »
thank you very much, good to know you are around with this info when i need it!  :D
visit these websites and make yourself happy forever:
It's my music! | My music on MySpace | Integrational Polytheism

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #5 on: 23 September 2002, 04:46 »
dont you just need to add something like:

<directory /var/www/html/cgi-bin>
Options ExecCGI FollowSymLinks
Order allow,deny
AllowOverRide none
</directory>

and make sure you have the line:
addhandler cg-script .cgi
or somethin'

i cant remember what my exact configuration is but i have it set to execute cgi in all directories except for a couple in my ikonboard tree.

are you following an online tutorial? if so, where is it?

[ September 22, 2002: Message edited by: The Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #6 on: 23 September 2002, 04:48 »
Actually you shouldn't have to add anything if you put the file under the cgi-bin directory.
Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #7 on: 23 September 2002, 04:52 »
my default setup had /var/www/cgi-bin but had the document root set to /var/www/html/
so wouldnt there be no way to access the cgi-bin from the net?
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #8 on: 23 September 2002, 04:56 »
ahhhh... i get it. the ScriptAlias command redirects /cgi-bin/ to /var/www/cgi-bin
Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #9 on: 23 September 2002, 04:59 »
You got it.
Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #10 on: 23 September 2002, 06:15 »
can anyone see whats wrong with this:
i dont plan to really use this script. It was just part of tutorial stuff.
Code: [Select]

[ September 22, 2002: Message edited by: The Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #11 on: 23 September 2002, 06:52 »
Try and run it on the command line, it will tell you where your errors are.

Line 9 is missing an ending quote and a semicolon. And while you are at it you might as well set line 9 to what your sendmail program is (probably /usr/lib/sendmail):

$sendmail = "/usr/lib/sendmail";

Line 24 just doesn't make any sense. Looks like what is missing from line 9, comment it out:

#usr/lib/sendmail";

Line 33 is missing a semicolon:

chop($date);

Line 88 is screwed, turn it into this:

Code: [Select]

So now it should look like this:

Code: [Select]

Actually there was some repeated shit at the top that I got rid of. Now, that fixes the syntax problems. You also need to make sure the program will have write access to the log file you have assigned in the program.

And of course you'll need the configuration file that the program uses which is an empty ~/.allowmailform file in the home directory of the user that is to receive messages from this CGI. That file needs to be readable by the web server which means the user must also have at least the execute bit turned on in their home directory for world.

I just created a basic HTML form that calls this CGI and it worked. It sent mail to my local account. So you'll need to write an HTML form to use it.

[ September 22, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #12 on: 23 September 2002, 07:49 »
after looking over my post agin... i ma sure that i copied that completely wrong...or at least the parts about sendmail that dont make sense.

[ September 22, 2002: Message edited by: The Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'

voidmain

  • VIP
  • Member
  • ***
  • Posts: 5,605
  • Kudos: 184
    • http://voidmain.is-a-geek.net/
perl training wheels
« Reply #13 on: 23 September 2002, 07:58 »
Well like I said, it works.  Just had to create a simple HTML form page to test it:

Code: [Select]

Of course you'll probably not want fields for a couple of them and would want to hard code values using "<input type=hidden>" tags...

[ September 22, 2002: Message edited by: void main ]

Someone please remove this account. Thanks...

Master of Reality

  • VIP
  • Member
  • ***
  • Posts: 4,249
  • Kudos: 177
    • http://www.bobhub.tk
perl training wheels
« Reply #14 on: 23 September 2002, 08:11 »
Code: [Select]
this is the form i have:
Code: [Select]
edit: fixed

[ September 22, 2002: Message edited by: The Master of Reality / Bob ]

[ September 23, 2002: Message edited by: The Master of Reality / Bob ]

Disorder | Rating
Paranoid: Moderate
Schizoid: Moderate
Linux User #283518
'It takes more than a self-inflicted gunshot wound to the head to stop Bob'