Page 1 of 1

PHP / VideoLAN / Linux Question - "exec" function

Posted: Sun Dec 11, 2005 10:52 am
by gtrawoger
Hi All,

I didn't know under what subject I should put this. I hope this is the right one, but it's hard to put under one hat, since there could be multiple possibilities where the error lies. Anyways, without any further ado:

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:

Code: Select all

<?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.)
I even gave apache root privileges (so I think. I am unsure if I did it correctly, since it didn't work).
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?????????

Now, again, as initially stated, I could have done something wrong somewhere (install of PHP, Apache, yada yada... )
I am up to try anything. If you have any clue what may be the problem here,or have a suggestion on doing in different, let me know.

Gerrit

Posted: Sun Dec 11, 2005 1:14 pm
by Chris Corbyn
Have you tried making sure that exec() is working by doing something simple like a `df -ah' or an `ls -al' ?

Perhaps the xawtv-remote command works only for the user that started the xawtv app? I'm eaqually on a limb here ;)

NOTE: You can also try this backtick syntax...

Code: Select all

<?php
if (isset($_POST["check"])) {
if ($_POST["channel"] == "Up") {
$command = '/usr/bin/xawtv-remote setchannel next';
echo `$command`;
}
if ($_POST["channel"] == "Down") {
$command = 'usr/bin/xawtv-remote setchannel prev';
echo `$command`;
}
if ($_POST["channelnumber"] != "") {
$command = 'usr/bin/xawtv-remote setchannel '.$_POST["channelnumber"];
echo `$command`;
}
}
?>
<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>

Posted: Sun Dec 11, 2005 9:08 pm
by gtrawoger
Thanks for the quick reply....
Have you tried making sure that exec() is working by doing something simple like a `df -ah' or an `ls -al' ?
I tried doing a "ls" on the /var/www directory and the /usr/bin directory, and it works on both. It spits out all the files that are in the directory.
Perhaps the xawtv-remote command works only for the user that started the xawtv app?
You see, that's what I thought... :roll: .... and I tried to give apache the privileges to the xawtv-remote program. I also made a copy of it and put it into the /var/www directory and gave it to apache. It works in a terminal, but again not through "exec".

I really don't know where I am making the mistake. I tried using a backtick syntax to give me back everything that is put to the "exec" function and whatever it puts back out. The only thing I get is a "1" (I get "127" if I put in a bad directory or a bad filename... so I believe "127" means "Bad Filename"!)

Thank you for your reply though... maybe I need to give you guys more info????? Ask for whatever you want!

Gerrit

Posted: Sun Dec 25, 2005 8:57 pm
by gtrawoger
Ok, here is an update......

I found out that in instead of putting the error on screen it put it in the apache error file (duh!) :roll:

And the error I am getting is "can't open display", which is a xawtv-remote error.

I assume, because it tries to run it as user "apache" it can't find the x server, which makes sense, since xawtv is started by user "tv".

I guess the next question is, how can I get apache to access the display? Or maybe I can make user "tv" run the command? How would I do that then?

Anyways, any help would be appreciated!!

Posted: Mon Dec 26, 2005 10:03 am
by Chris Corbyn
gtrawoger wrote:Ok, here is an update......

I found out that in instead of putting the error on screen it put it in the apache error file (duh!) :roll:

And the error I am getting is "can't open display", which is a xawtv-remote error.

I assume, because it tries to run it as user "apache" it can't find the x server, which makes sense, since xawtv is started by user "tv".

I guess the next question is, how can I get apache to access the display? Or maybe I can make user "tv" run the command? How would I do that then?

Anyways, any help would be appreciated!!
You need to play with the environment variable $DISPLAY (in *nix/bash not PHP). The default is "localhost:0" where localhost is the machine and 0 is the display (if you have one monitor it's almost always 0).

When apache runs scripts this may be different.

Try:

Code: Select all

<?php

echo `echo $DISPLAY`;

?>
You'll want to set it to be the same IP as the target machine (e.g. 192.168.1.7:0)

Code: Select all

<?php

`export DISPLAY=192.168.1.7:0`;

?>
All this still might not work :lol:

EDIT | Your X configuration on the target machines will need to support X11 forwarding too (see xorg.conf)

Posted: Thu Feb 09, 2006 10:12 pm
by gtrawoger
Ok, I just wanted to add some more information here.

Since I use VNC and I log into the machine that way, this may also cause another obstancle.

VNC creates another virtual desktop (vncserver) and I log into that one. I like it better than taking control of the main desktop, since it works much faster and if I want to restart the desktop, I can do that without getting completely logged out.

So, with this added information, the virtual desktop running XAWTV, does anybody know what to do?

More Info

Posted: Fri Feb 10, 2006 8:53 pm
by gtrawoger
Ok, I punched in the $DISPLAY command in a shell and this is what I get:

[tv@localhost ~]$ echo $DISPLAY
:1.0

(For a list of commands for xawtv-remote go here: about.com )

So then, this is the command I use in the PHP:

Code: Select all

//THIS IS FOR CHANNEL UP
echo exec("xawtv-remote -d :1.0 setchannel next");
Error Message:

Xlib: connection to ":1.0" refused by server
Xlib: No protocol specified

can't open display :1.0



Or if I tried:

Code: Select all

//THIS IS FOR CHANNEL UP
echo exec("xawtv-remote -d 1.0 setchannel next");
(you will notice I took off the ":" )

Error Message:

can't open display 1.0



:?: :?: :?: :?: :?: :?:

Man, this can't be this hard, can it? I am stumped still.

I think I tried all the combinations available.
[/b][/url]