Help with CGI
Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Help with CGI

  1. #1
    Member
    Join Date
    Oct 2002
    Posts
    32

    Help with CGI

    I am having a bit of trouble with cgi scripts. Every script i run I get

    Internal Server Error -- error 500

    I check the log file and it always says premature end of script header. I have downloaded many scripts where they work on the persons site but I put them in my cgi-bin directory and call it up and I always get that.

    I have attached one of the scripts can someone test it or see what i did wrong.

    Any help apreciated. Oh yea scrips are set to 777

  2. #2
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    Posts
    1,356
    Ok, first off, 777 is BAD. Set it to run as 700 and make sure the owner (perferably something like nobody) owns those files and is also running the http server.

    500 means your script is having problems. First thing I recommend is trying to run the script from a command shell, this will often point out the line number of whatever is causing the problem. I suspect that you probably didn't copy the entire file over or maybe a long line got truncated. It should be pretty apparent once you try this (however it may not be possible in all cases).

    To make any other recommendations, I would have to know: what is the language of the script? What software is running the web server ?

    /nebulus
    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  3. #3
    Member
    Join Date
    Oct 2002
    Posts
    32
    The script needs perl5 wich I have and I am running apache webserver under red hat linux.

    I will try running script from shell

  4. #4
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    Posts
    1,356
    Ok, look at the first line of the perl script, you should see something like:

    #/usr/local/bin/perl

    Make sure perl is in that location (you might be able to get away with a symbolic link if you don't feel like editing the script).

    If it isn't one of those let me know and I will see what I can do to help, but I suspect it is probably you are either pointing to a wrong interpreter (/usr/local/bin/perl) or that you are missing a ' or ; or something somewhere in the script (which is usually the error returned by perl when it is missing something and then reaches the end of the file and can't find it, in which case trying to run it from the command line will proably help you figure out what you did) (leaning heavy towards second one).

    /nebulus
    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  5. #5
    Member
    Join Date
    Oct 2002
    Posts
    32
    Yes I did edit that so it links to where perl is. I ran the script from shell and got a few errors, I am going to run some other scripts and see what they say and maybe I can get one working

    Thanks for the help

  6. #6
    Senior Member
    Join Date
    Oct 2002
    Posts
    181
    Am I right in thinking if you set it to 700 it would not run, as world and group have no rights to run the file, should it be 711, so they can execute the CGI file but not read it? Please tell me if I've got it wrong

    SittingDuck
    I\'m a SittingDuck, but the question is \"Is your web app a Sitting Duck?\"

  7. #7
    Member
    Join Date
    Jul 2002
    Posts
    68
    let me guess you are using emacs as your editor. When i opened up the file i noticed that it was in DOS mode meaning that ^M is appended to each line. If you were to use vi ^M would have not been hidden like emacs. My sugestion would would be to write a short perl script to delete the ^m or look on the net for a similar script. If you still cant find one let me know.
    good luck

    almost forgot the chmod should be set to 755 so the users can execute also but do not give them extra priveleges
    kNoWLeDgE

  8. #8
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    Posts
    1,356
    If you have your web server set to run as a certain unpriveleged user (like nobody), the web pages and scripts are owned by the same user, then 700 is absolutely sufficient (or 400/500 for non-scripts). I did take a look at the script that you provided and I don't see the ^M problem at the end of the lines; however, I did notice that you are shelling out and running commands, which may lead to problems. Your web user would have to have permission to be able run whatever binaries are being run (a few that come to mind were uname -r and man), or there would be problmes with things not displaying properly and perhaps even errors in output.

    However, the error that you reported is more symptimatic of a missing ', ", ;, , , `, ), or } than a permission or binary problem. Another thing to consider is what environment the script would be running in, all of the binaries may not be in the same location on every system, you should probably do a search for them first and set some global value to it and then reference those commands with that variable.

    I will mention that I pasted your script into a test computer with no network connectivity and it worked just fine from the command line, no errors. Check the syntax and permissions by running it from the command line as a normal user (if no errors, then it is probably a problem with permissions, so su - <webuser>, and run it again).

    Hope this helps,

    /nebulus
    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  9. #9
    Senior Member
    Join Date
    Oct 2002
    Posts
    181
    Ok I've checked it and for a CGI script you should be set to 711.

    This would be
    owner = Read, write and execute
    group = execute
    world = execute

    For a static HTML file it should be 744

    This would be
    owner = Read, write and execute
    group = read
    world = read

    SittingDuck
    I\'m a SittingDuck, but the question is \"Is your web app a Sitting Duck?\"

  10. #10
    Member
    Join Date
    Jul 2002
    Posts
    68
    my bad nebulus you are right about the permissions...
    kNoWLeDgE

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •