Solving CGI-bin Script Issue on Linux (Slackware 13)

  • Thread starter Thread starter aihaike
  • Start date Start date
AI Thread Summary
The discussion revolves around a user attempting to execute a script from a web browser that calls Ekiga for VoIP calls using Telify on a Linux system (Slackware 13). The user successfully runs the script from the command line but encounters issues when executing it via a web browser, leading to an empty log file and an internal server error. Key points include the need for proper Apache configuration for CGI scripts, including correct permissions and environment variables. The user learns that Apache runs under a different user context, which may restrict access to certain programs and environment settings. Additionally, the necessity of setting the DISPLAY variable for graphical applications like xclock is highlighted, as well as the requirement for valid HTTP headers in CGI output. Ultimately, the user resolves their issues with guidance on environment variables and permissions.
aihaike
Messages
52
Reaction score
0
Hi all,

I'm running Linux (Slackware 13).
I'm trying to use https://addons.mozilla.org/en-US/firefox/addon/10654" 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 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:
#! /bin/bash

echo Content-type: text/html
echo
echo 
echo "<HTML>"
echo "<HEAD>"
echo "</HEAD>"
echo "<BODY>"
echo "<PRE>"
phonenumber=`echo $1`
ekiga=/usr/local/bin/ekiga
log=~/tmp/telify.log
$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)

Thanks, Eric.
 
Last edited by a moderator:
Technology news on Phys.org
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 ...

Eric.
 
Last edited:
aihaike said:
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 ...

Eric.

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.
 
kote said:
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.

Hi,
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.

Eric.
 
Ok, I begin to figure.
if I copy xclock in my cgi-bin diretory, why can't I do:

http://localhost/cgi-bin/xclock

I mean, I get this:

Code:
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:
OK, I've just figured how to solve my problem without go thought cgi-bin stuff ...
Thanks.

Eric.
 
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:
#!/bin/bash
echo Content-Type: text/html
echo
echo
export DISPLAY=192.168.0.1:0.0
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).

DaveE
 
Hi DaveE,

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

Eric.
 
Back
Top