This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Re: calling amarok from php - stumped

Tags: None
(comma "," separated)
kaens
Registered Member
Posts
8
Karma
0

calling amarok from php - stumped

Sat Apr 14, 2007 2:45 am
Alright, I'm very stumped now.

I've written a php frontend for music players - foobar2000 on windows (swear to god it's about the only one with command line support) and hopefully a few linux players.

Amarok, I was hoping, would be one of them.

I've been trying to call amarok from php's exec command.

at first I tried:

exec("amarok -p") to start playing a file. This didn't work. Rerouting the output of this to a log told me the connection was being refused to xserver, so I ran xhost + local:apache@. Now, executing the exec("amarok -p") command spits out a whole lot of "database not found" and "trying to create directory in /root/.kde/share - this looks to me as if it's running as root (which it shouldn't be, i don't think).

So then I did some searching, and found that the reccomended way to manipulate amarok through the command line was with dcop, so I tried exec("dcop amarok player play"), to no avail. Just "couldn't attach to dcop server". exec(DISPLAY=:0 dcop amarok player play") has the same results.

What's going on here? What am I doing wrong? Any help would be appreciated.
Hydrogen
Registered Member
Posts
95
Karma
0
php exec()'s the program under the priviledges php is running under.. if php is started as root then it will exec() programs as root.
kaens
Registered Member
Posts
8
Karma
0
That makes sense. Thank you, will see if it works if I start php as a normal user.

Actually, is there a way to specify what user the exec call will use? Or maybe have it call a script that would set that?

I mean, it seems like php wants to run as root. xampp has to run as root.

Besides, why wouldn't this work as root anyhow?

Huh. I'm going to try some things.

Last edited by kaens on Sat Apr 14, 2007 5:09 am, edited 1 time in total.
kaens
Registered Member
Posts
8
Karma
0
Alright - I tried making a bash script to call amarok, then calling that from php, which didn't work.

So then I had the script change users to a user who can start amarok from a command line without a problem, and then start amarok, and IT STILL DOESN'T WORK.

Man. su user and su - user. Same results
kaens
Registered Member
Posts
8
Karma
0
Next failed technique -

Set /home/user/.ICEauthority to be able to be read from whomever

$cmd="dcop --all-users amarok player play";
exec($cmd);

returns:

DCOPClient::attachInternal. Attach failed Could not open network socket.
ERROR: Couldn't attach to DCOP server

I'm not sure where to start looking for the solution to this.

Last edited by kaens on Sat Apr 14, 2007 7:18 pm, edited 1 time in total.
Jejem
Registered Member
Posts
5
Karma
0
I'll have a look on it and perform some tests...
Jejem
Registered Member
Posts
5
Karma
0
jejem@tahyse:/tmp$ cat amarok.php
#!/usr/bin/php
exec('dcop amarok player pause');
echo 'Paused'."\r\n";
exec('dcop amarok player play');
echo 'Playing again'."\r\n";

then a ./amarok.php works well, player is pausing then playing the music again...

everything works fine.
kaens
Registered Member
Posts
8
Karma
0
Can you call that from a web-page and have it work?

exec("/pathto/amarok.php");

I can start and stop from a command-line fine, it's from a page where I'm running into problems
kaens
Registered Member
Posts
8
Karma
0
Actually, trying to run a php script from the command line that looks like so:

echo 'starting\n';
exec('dcop amarok player play');

gives me "call failed";

changing the call to:

exec('dcop --all-users amarok player play');

gives me :

call failed
DCOPClient::attachInternal. Attach failed Authentication rejected, reason: None of the authentication protocols specified are supported and host-based authentication failed.
ERROR: Couldn't attach to DCOP server.

Could this be because I'm using xampp? My php is in /opt/lampp/bin/php?

I can execute dcop commands from the command line, or from a shell script (BASH) without a problem.

Last edited by kaens on Sat Apr 14, 2007 7:57 pm, edited 1 time in total.
Jejem
Registered Member
Posts
5
Karma
0
don't use lampp, just install php-cli package of your distro...

you can find me on IRC (freenode, #amarok) if you want, it's better than a forum-conv.
kaens
Registered Member
Posts
8
Karma
0
Thing is, I'm trying to call this script from a webpage.

I'm trying to control amarok from a webpage.

Writing a php script like so:

#!/pathto/php
exec('amarok -p');

?>

works fine from the command line, doesn't work when called from a browser. Doesn't work if I exec the script name from a browser.

Egh. I'm going to trash lampp and install manually, then see what happens.
Jejem
Registered Member
Posts
5
Karma
0
It's .. normal ... that you can't launch it directly from your web-browser... your web-server is doing bad things ... :o
kaens
Registered Member
Posts
8
Karma
0
I'm starting to realize that xampp is not a very good way to go about installing php and apache for a situation like this.

What I don't understand is why the same exec call (in the same language) would work from the command line, but not from a browser.

Hypothetically, what I want to happen is this:

I have a web page running on a local music server, not accessible to the web. People can connect to it, browse through the directories, select a song or album folder and queue it up. I've got this working for foobar2000 on windows. I want to support as many players and operating systems as possible, so that other people can use this without much of a pain.

I figured that writing the linux player support would be a lot easier than the windows support, since (almost) everything has really good command line support.

The page has buttons for play, pause, etc. They all send off an "exec" command with what should be the appropriate arguments.

Ergh.

The linux machine I'm testing on right now doesn't have net access, and has kubuntu installed on it with lampp. Apparently this is a bad way to set this up. If I'm not mistaken I should be able to launch commands through exec right? I've tested doing things like running ls and directing the output to a file, which works fine. I can not start any kde apps though. Sigh.

The problems I'm having are probably due to:

lampp being a weird all-in-one thing
the user php is running as

which I don't think are solvable without just seperately installing php and apache
Jejem
Registered Member
Posts
5
Karma
0
The "problem" for your Linux experience is that on Windows, you don't have to care about user permissions, so any one (the web-server too) can launch commands directly...

Linux, with it's user-permissions layer, put you in troubles to handle it...

xampp (or lampp) is a bad thing for that ... but php-cli can do that much better ... even through apache ...

You can come on IRC, or add me to your msn/aim/yahoo ... if you want... it'll be better than a forum-convi as i said in my previous post... :)


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], lockheed, Sogou [Bot]