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

  • Thread starter Thread starter aihaike
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a CGI-bin script issue on Linux (Slackware 13) related to executing external programs from a web browser. The participants explore the challenges of running a script that successfully executes commands in a shell but fails to do so when accessed via a web server.

Discussion Character

  • Technical explanation
  • Debate/contested

Main Points Raised

  • Eric describes a CGI-bin script that works in the shell but fails to execute Ekiga when accessed through a browser, despite printing the expected output.
  • Eric notes that linking or copying Ekiga to the CGI-bin directory results in access denied or internal error messages.
  • Another participant suggests checking Apache's configuration for proper CGI setup, including script location and permissions.
  • Eric mentions that basic scripts work, indicating that the configuration might be correct, but issues arise when trying to execute other programs like xclock.
  • Eric receives feedback about potential causes, including environment variables and permission issues when running scripts under Apache.
  • One participant explains that xclock requires a DISPLAY environment variable and that it does not produce valid HTTP headers, which could lead to server errors.
  • Another participant provides a sample script that sets the DISPLAY variable and includes proper HTTP headers, suggesting it might work under certain conditions.

Areas of Agreement / Disagreement

Participants express various hypotheses regarding the issues faced, with no consensus on a single solution. Multiple potential causes are discussed without resolution.

Contextual Notes

Limitations include the dependence on environment variables and permissions, as well as the need for valid HTTP headers in CGI scripts. The discussion does not resolve the underlying issues related to executing external programs from a web server context.

Who May Find This Useful

Users troubleshooting CGI-bin scripts on Linux, particularly those using Apache, and those interested in executing external programs from web applications.

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.