LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work (https://www.linuxquestions.org/questions/linux-software-2/php-videolan-fedora-core-question-how-can-i-get-the-php-exec-function-to-work-391147/)

gtrawoger 12-09-2005 10:12 PM

PHP / VideoLAN / Fedora Core Question - how can I get the PHP "exec" function to work
 
Hi All,

this is my first post in any forum, period! In fact, so far, any of my questions have been asked before and I could google the answer. This time I am stuck!

Here is my project: I wanted to stream my TV signal over the network, so that any of the computers attached could watch TV without having a TV Tuner card in it.

My solution so far: I put together an old P3-550 with a ATI TV Wonder Card, installed Fedora Core 4 & VideoLAN. I use XAWTV to set the channel I want to watch and let VideoLAN stream the signal. I installed KDE, but am using IceWM on it, since it is much leaner. I also access the box through VNC, which I have been using to change the channel.

What I wanted to do next: I wanted to write a quick PHP script (make it look like a remote control) to change the channels. There is a way to change the channel, through "xawtv-remote". The command is "xawtv-remote setchannel next" or "prev" or the number of the channel. Very simple really.

My Dilema: Well, I thought this would be real easy. Just write a PHP code like this:

<?php
if (isset($_POST["check"])) {
if ($_POST["channel"] == "Up") {
echo exec('/usr/bin/xawtv-remote setchannel next');
}
if ($_POST["channel"] == "Down") {
echo exec('usr/bin/xawtv-remote setchannel prev');
}
if ($_POST["channelnumber"] != "") {
echo exec('usr/bin/xawtv-remote setchannel '.$_POST["channelnumber"]);
}
}
?>
<hmtl>
<head>
<TITLE>TV Remote</TITLE>
</head>
<body><center>
<FORM method="POST" action="">
<INPUT value="send" name="check" type="hidden">
<INPUT type="submit" name="channel" value="Down"><br>
<INPUT type="submit" name="channel" value="Up"><br>
Or enter Channel #: <INPUT type="text" name="channelnumber" value="<?php if (isset($_POST["check"])) {
echo $_POST["channelnumber"];
}
?>"><INPUT type="submit" name="submit" value="Set"><br> </FORM>
</center>
</body>
</hmtl>


Now, all I get is an output of "1", evertime I send the channel change, but the channel doesn't change. If I type that command in a Terminal it does what it's suppossed to do.
I know that the command is proper (I played with it for hours, taking away the complete path, moving the file, changing the privileges of the file, etc.) :confused:
I even gave apache root privileges (so I think. I am unsure if I did it correctly, since it didn't work).:scratch:
Well, I tried different PHP commands, such as "system", but nothing. I am not sure where the error lies, since it doesn't really give me an error, just "1".
I went and checked to see if the PHP.ini had anything turn on that would prevent the script from executing, but I know exec works, since I can "ls" the directory and get the files.
Then I went and checked the apache httpd.conf file to see if there is something amiss, but again, couldn't find anything. I even tried the "sudo" thing, changing the permissions with visudo.
Really, what is left to do?????????:mad:


I am up to try anything. If you have any clue what may be the problem here, let me know.

Gerrit

bulliver 12-16-2005 02:50 PM

First of all: you have a typo:
Code:

if ($_POST["channel"] == "Down") {
 echo exec('usr/bin/xawtv-remote setchannel prev');
 }
 if ($_POST["channelnumber"] != "") {
 echo exec('usr/bin/xawtv-remote setchannel '.$_POST["channelnumber"]);

Those need to have "/" prepended...

Second: if you have "safe mode" on then you need to put anything you want to "exec" into safe_mode_exec_dir (see php.ini)

When I run your script on my system i get:
Code:

sh: /etc/apache2/bin/xawtv-remote: No such file or directory
Which is expected, as I have no "xawtv-remote" in my safe exec dir "/etc/apache2/bin/"

So: either turn off safe mode (not a good idea if server is publically accessable) or put the command in your safe_mode_exec_dir, or make whatever directory the program is in your safe_mode_exec_dir (again, not good security wize...)

HTH

gtrawoger 12-21-2005 06:49 AM

Ok, here is an update (sorry it took so long, I do not have too much time to put into this)....


I finally (after this last post) took a look into the apache error log, and guess what? I found the error messages I needed to see (instead of simply getting "1")....

It spits out "can't get display" when I call on the exec function. Which is great in some way, since this is a xawtv-remote error message, pointing toward that the exec function IS working. :rolleyes:

Now, next issue is to figure out how to get the apache user to use the xawtv-remote program to change xawtv station that is running on user "tv".

Would I be using "sudo" on this? Can anybody help me there????

Thanks.

gtrawoger 12-21-2005 06:51 AM

oh... I forgot... bulliver.... thanks for the reply. It did send me the right way!!!!


All times are GMT -5. The time now is 03:49 AM.