Sign in to follow this  
ontheheap

Problem executing cgi script

Recommended Posts

ontheheap    798
I wrote a small cgi/perl script that takes a screenshot of my current desktop. Basically, it calls "system("sudo include -window root ../htdocs/captured.jpeg"); I am able to run it from the command prompt (yes, as the user "nobody") and it works fine. However, when I place it in my cgi-bin and run it from firefox it doesn't work. My httpd.conf file _is_ setup for the user/group nobody/nobody and I've setup sudoers accordingly (for example, not asking for a password so the script can function correctly). Like I said, it works if I su to nobody from the console and run it, but calling it from the browser does nothing! Anyone have any experience with doing anything like this? Edit: and the script _is_ being executed because I'm printing a timestamp to the window and it shows up fine.

Share this post


Link to post
Share on other sites
Null and Void    1088
Because of that last part, I'd take a guess that the relative path "../htdocs/captured.jpeg" isn't being used correctly since the current working directory that the CGI script is called with from the HTTP daemon isn't what you're expecting.

Share this post


Link to post
Share on other sites
ontheheap    798
I've changed it to /var/www/htdocs/captured.jpeg but it still doesn't work when executed through the browser. I took a look at the error log and it says import: unable to open X server. I'm trying to find something on google now, but I'm not totally sure what to look for.

Share this post


Link to post
Share on other sites
Null and Void    1088
Quote:
Original post by ontheheap
I've changed it to /var/www/htdocs/captured.jpeg but it still doesn't work when executed through the browser. I took a look at the error log and it says import: unable to open X server. I'm trying to find something on google now, but I'm not totally sure what to look for.

Oh, yes, I forgot all about that somehow.

You have to give it a display from which to capture the root window. The "default" display (kind-of) for single user machines is ":0.0". You can specify the display to any "normal" X application with some arguments like "-display :0.0" or by setting the environment variable DISPLAY before executing the application. A more sophisticated solution would be needed to have it track one user's display or something more reliable.

Share this post


Link to post
Share on other sites
Sign in to follow this