Thread Closed

cgi-bin script issue

 
Share Thread
Dec17-09, 04:21 PM   #1
 
Thumbs down

cgi-bin script issue


Hi all,

I'm running Linux (Slackware 13).
I'm trying to use Telify 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.
PhysOrg.com science news on PhysOrg.com

>> New language discovery reveals linguistic insights
>> US official: Solar plane to help ground energy use (Update)
>> Four microphones, computer algorithm enough to produce 3-D model of simple, convex room
Dec18-09, 09:21 PM   #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.
Dec18-09, 11:19 PM   #3
 
Quote by aihaike View Post
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.
Dec19-09, 07:15 AM   #4
 

cgi-bin script issue


Quote by kote View Post
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.
Dec19-09, 07:37 AM   #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.
Dec19-09, 09:08 AM   #6
 
OK, I've just figured how to solve my problem without go thought cgi-bin stuff ...
Thanks.

Eric.
Dec21-09, 04:13 PM   #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
Jan7-10, 09:34 PM   #8
 
Hi DaveE,

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

Eric.
Thread Closed

Similar discussions for: cgi-bin script issue
Thread Forum Replies
math with action script (Joukowski's + action script = HOW!!?!?!?) Programming & Comp Sci 1
UNIX scp script Programming & Comp Sci 3
script similar to [tex] General Discussion 2
post script Computing & Technology 2