Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Cgi-bin script issue

  1. Dec 17, 2009 #1
    Hi all,

    I'm running Linux (Slackware 13).
    I'm trying to use https://addons.mozilla.org/en-US/firefox/addon/10654" [Broken] with Ekiga to perform sip calls vis VoipDiscount.
    Telify is able to get phone number from webpages, so then I wrote a cgi-bin script in bash which execute Ekiga with the phonenumber cached by Telify.
    When I execute the script in a shell giving a phone number as arguments it works.
    Then when I load the script from the browser: http://localhost/cgi-bin/telify.sh?0041xxxyyyzzz [Broken] it gets the phone number 0041xxxyyyzzz since it prints it but it does not execute Ekiga like in the xterm vie the command "./telify.sh 0041xxxyyyzzz".
    Here is my script:

    Code (Text):
    #! /bin/bash

    echo Content-type: text/html
    echo "<HTML>"
    echo "<HEAD>"
    echo "</HEAD>"
    echo "<BODY>"
    echo "<PRE>"
    phonenumber=`echo $1`
    $ekiga --call sip:$phonenumber@sip.voipdiscount.com >& $log
    echo "$ekiga --call sip:$phonenumber@sip.voipdiscount.com >& $log"
    echo "</PRE>"
    echo "</BODY>"
    echo "</HTML>"
    And here the output:

    /usr/local/bin/ekiga --call sip:0041xxxyyyzzz@sip.voipdiscount.com >& /srv/httpd/tmp/telify.log

    Note that the log file is empty.

    Any idea?
    Why can't I execute a program from this script when it's load from the browser? (only shell command are executed)


    Last edited by a moderator: May 4, 2017
  2. jcsd
  3. Dec 18, 2009 #2
    well, me again,

    I tried to link and then cp ekiga to my cgi-bin directory but I got some error like "access denied" or "internal error".
    On the other hand, I put "xclock" in mu script telify.sh described in my previous post and it does not get executed when I execute the script from the browser. From the commsnd line I get the clock.
    It seems there is something wrong in my apache configuration .....

    Last edited: Dec 18, 2009
  4. Dec 18, 2009 #3
    Hi Eric. I recommend you go through http://httpd.apache.org/docs/2.2/howto/cgi.html to make sure your Apache is set up properly for CGI. You'll have to have the script in the right directory with the right permissions for Apache to execute it etc. You don't want Apache running programs on your computer without your explicit permission.
  5. Dec 19, 2009 #4
    Thanks for your answer.
    Actually, my config looks good since I can execute a basic bash (or even python) script.
    The issue is when I try to execute an other program from my script.
    For instance, I've been trying to execute xclock. form the xterm it works, from the browser it does not.
    I need to understand how to do that.

  6. Dec 19, 2009 #5
    Ok, I begin to figure.
    if I copy xclock in my cgi-bin diretory, why can't I do:

    http://localhost/cgi-bin/xclock [Broken]

    I mean, I get this:

    Code (Text):
    Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator, email@domain.xx and inform them of the time the error occurred, and anything you might have done that may have caused the error.

    More information about this error may be available in the server error log.
    Last edited by a moderator: May 4, 2017
  7. Dec 19, 2009 #6
    OK, I've just figured how to solve my problem without go thought cgi-bin stuff ...

  8. Dec 21, 2009 #7
    Two probable causes, although I see you may have already solved them.

    1) Environment variables

    When you run a program in bash on the command line, you have a lot settings in your ENV. When you run a program through Apache, you have VERY different settings. Chances are, you're missing something like the specific PATH, or some other environment setting. When on the normal command line, type "env" to find out what environment variables you're using, then try setting them within your script.

    2) Permissioning

    When you run under Apache, you're often set up as another user. Often, webservers run as "nobody", and don't have write access, or permission to run some low-level programs. Find out what userid Apache is using, and check the permissions of all the explicit programs that you're trying to use, as well as the permissions associated with any configuration files that they may need to load.

    As for the xclock question, that's easy. Two problems:

    A) xclock needs a DISPLAY environment variable to run on. And a million to one says that your Apache server does NOT have a value set for DISPLAY (because that would be silly).

    B) xclock doesn't print out any HTTP headers. When Apache gets a request to run a CGI script, it executes the script, captures the output, and then divides the output into "headers" and "not headers". Before returning the output to the requesting browser, it takes a look at the "headers" that it received from the script, and checks to see that they're valid. If they're not valid, it throws a 500 error (like the one you showed). If they ARE valid, then it intermixes the headers that the script printed along with some other standard HTTP headers, and returns them to the requesting browser. Then, it returns the rest of the "not headers" to the client as well.

    For the sake of reference, HTTP headers typically look like this:

    Content-Type: text/html

    If you had (for example) a script called "run_xclock.cgi":

    Code (Text):
    echo Content-Type: text/html
    export DISPLAY=
    xclock &
    echo I started xclock!
    That might actually work-- although you'd be opening up an xclock to some J-Random terminal somewhere (which may or may not accept your connection, thus potentially killing your experiment).

  9. Jan 7, 2010 #8
    Hi DaveE,

    Thank you so much for your help and sorry for my late reply.
    Now everything is clear.

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook