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

  • Thread starter aihaike
  • Start date
In summary, solving CGI-bin script issues on Linux (Slackware 13) involves checking file permissions, ensuring the correct shebang line is present, and troubleshooting any errors in the script itself. It may also require modifying the Apache configuration file and restarting the server. By following these steps, the issue should be resolved and the CGI-bin script should be able to run properly.
  • #1
aihaike
55
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
  • #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 ...

Eric.
 
Last edited:
  • #3
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.
 
  • #4
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.
 
  • #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

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

Eric.
 
  • #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:
#!/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
 
  • #8
Hi DaveE,

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

Eric.
 

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

1. What is a CGI-bin script and why am I having issues with it on Linux (Slackware 13)?

A CGI-bin script is a program written in a scripting language, such as Perl or Python, that is used to generate dynamic content on a website. It is commonly used for forms, search engines, and other interactive elements. If you are having issues with a CGI-bin script on Linux (Slackware 13), it could be due to incorrect permissions, missing dependencies, or errors in the code.

2. How do I set the correct permissions for a CGI-bin script on Linux (Slackware 13)?

The correct permissions for a CGI-bin script on Linux (Slackware 13) are typically 755, which means the owner has read, write, and execute permissions, and the group and others have read and execute permissions. You can use the chmod command to set these permissions, or use a FTP client or file manager to change them.

3. What dependencies do I need to install for a CGI-bin script to work on Linux (Slackware 13)?

The dependencies required for a CGI-bin script to work on Linux (Slackware 13) will vary depending on the specific script and its requirements. However, some common dependencies for CGI scripts include Perl modules, Python libraries, and web server modules. You can check the documentation for your specific script to determine the necessary dependencies.

4. How do I troubleshoot errors in a CGI-bin script on Linux (Slackware 13)?

If your CGI-bin script is not working properly on Linux (Slackware 13), the first step is to check the error logs for any specific error messages. These logs can typically be found in the /var/log directory. You can also try running the script from the command line to see if it returns any errors. Additionally, you can try debugging the script by adding print statements or using a debugging tool.

5. Can I use a different scripting language for CGI-bin scripts on Linux (Slackware 13)?

Yes, you can use a variety of scripting languages for CGI-bin scripts on Linux (Slackware 13), including Perl, Python, Ruby, and even shell scripts. However, you may need to configure your web server to recognize and execute the script properly. Consult your web server's documentation for instructions on how to do this.

Back
Top