Firmware: A-410 [01 Apr. 2014] | A-400 [12 Mar. 2014] | C-300 [13 Feb. 2014] | A-300 [24 Feb. 2014] | C-200 [11 July 2013] | A-200/A-210 [11 July 2013] | Popbox V8 [3 Dec 2013]

Just got your NMT | WIKI has the answers | Search the forum | Forum Rules/Policy | Firmware & Official NMT News | Popcornhour manuals



User(s) browsing this thread: 1 Guest(s)
Thread Closed 
Web interface for controlling your music library
01-11-2009, 04:45 PM (This post was last modified: 01-11-2009 10:19 PM by iix.)
Post: #1
Web interface for controlling your music library
Hi,

I am developing a web interface to mange my music library. I aim to, from my regular browser, be able to easily get an overview of my music, create custom play lists etc.

[Image: screenshothd6.th.png]


I have finished up most of the things I initially have planned but I've run into one problem (or rather two problems one with the php5server and one with using sybhttpd).

1. If I use the php5server all my cgi scripts is run as user nobody. This means I have not been able to kill i.e. Gaya in order to reinitialize it.
2. If I use the sybhttpd server, my cgi's are run as root but I cannot seem to get Javascript POST to work properly. (I can correctly parse the URL but the actual data is nowhere to be found).

In javascript I use the following approch:
Code:
function playList(){
    xmlHttp.onreadystatechange=printResult;
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", playlist_disp.join("\n").length);
    xmlHttp.setRequestHeader("Connection", "close");
    xmlHttp.open("POST","script/mono.cgi", true);
    xmlHttp.send(playlist_disp.join("\n"));
    //foot.innerHTML=playlist_disp.join("\n");
}

Where xmlHttp is a "XMLHttpRequest" object, mono.cgi the wrapper for controlling mono and playlist_disp the playlist I want to play (I construct the full playlist in my javascript so it is to big to only send with a GET request).

To receive this I use the following php code in mono.cgi:
PHP Code:
$choise_get=$_REQUEST["g"];
...
    else if(
$choise_get=="play_list"){
        
$fp fopen('/share/Apps/pms/active_playlist.jsp''w');    
        
fwrite($fp$HTTP_RAW_POST_DATA);
        
killall();
        
$output=system('(mono -audio -bgimg -single -playlist /share/Apps/pms/active_playlist.jsp -dram 1 &) > /dev/null');
        
$result "Command play_list issued";
    }
... 

When I do like this with the php5server everything works fine (but there I have the user privileges issue) but when I use sybhttpd I can't seem to get the "$HTTP_RAW_POST_DATA" to be populated with anything. I have tried returning the values of $GLOBALS, $_SERVER, $_SESSION, $_POST, $_FILES, $_GET, $_REQUEST, $HTTP_RAW_POST_DATA, file_get_contents("php://input") and $_COOKIE.

The php script is issued with #!/mnt/syb8634/server/php5-cgi at the top.

So now onto my questions:

1. Is it possible to receive the contents of the POST "body" when using sybhttpd?
2. Is it possible to give some scripts the rights to execute as root, i.e. only a script to kill and re-init gaya? (incase I cannot use sybhttpd for my intentions)

Also when playing around I noticed that when I start gaya as user "nobody" the resolution gets all screwed up, guess it might have to do with permissions to som of the files.

All help and suggestions for ways to solve this will be greatly appreciated.

EDIT: I just noticed that it seems as if my POST request ends up in the $_GET variable when I parse with php:

Code:
print_r($GLOBALS)
Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( [/opt/sybhttpd/default/pms/script/mono_cgi] => ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) [_REQUEST] => Array ( [/opt/sybhttpd/default/pms/script/mono_cgi] => ) [choise_get] => [result] => No command was sent ) No command was sent200

Also, does anybody know if sybhttpd has some kind of error log (corresponding to /mnt/syb8634/server/php5server/error.log for the php5server)?

EDIT EDIT: I found a reasonable workaround by using the php5server and let php start a telnet session towards the localhost when I want to perform actions with root privileges. (See the comments for http://se.php.net/fsockopen, search for telnet, for more info.)

I will set the thread to solved but if anyone knows the answers to the original questions I'm still interested as it would be nice to skip the extra step and dependency.

//Kristopher
Find all posts by this user
01-12-2009, 05:04 PM
Post: #2
RE: Web interface for controlling your music library
Hi,

I'm interested in your permissions solution using telnet/fsock as I too have a permissions issue (namely using opendir on a mounted USB drive).

Have you thought of building this directly on the PCH itself?

I can find my way home from Sierra Leone, but I'm lost without an inside pocket.
Find all posts by this user
01-12-2009, 06:42 PM
Post: #3
RE: Web interface for controlling your music library
(01-12-2009 05:04 PM)BigLarry Wrote:  Hi,

I'm interested in your permissions solution using telnet/fsock as I too have a permissions issue (namely using opendir on a mounted USB drive).

Have you thought of building this directly on the PCH itself?

The telnet php scripts actually already run natively on the pch (the intention is that all needed should be the PCH, and a computer with a browser ofcourse, to use the app). The original telnet class can be found at http://www.dali.net.nz/Telnet.class.php.txt

The only modifications I made for it to work with the telnetd deamon was to comment out unneeded login steps and to change the prompt we are expecting to get returned to us:
PHP Code:
public function login($username$password) {
        
        try{
            
//$this->setPrompt('login:');
            //$this->waitPrompt();
            //$this->write($username);
            //$this->setPrompt('Password:');
            //$this->waitPrompt();
            //$this->write($password);
            
$this->setPrompt();
            
$this->waitPrompt();
        } catch(
Exception $e){
            
            throw new 
Exception("Login failed.");
        }
        
        return 
self::TELNET_OK;
    }

public function 
setPrompt($s '#'){
        
$this->prompt $s;
        return 
self::TELNET_OK;
    } 

I now see that the change to the prompt is actually quite unnecessary as you just as well could have passed the prompt you wanted to use to setPromt() after initializing the telnet object (as you notice I haven't looked to at the code in any greater depth Wink ).

To later use it in a php script you can for example do:

PHP Code:
#!/mnt/syb8634/server/php5-cgi
<?php 
require_once('../telnet/telnet.php');

$telnet = new Telnet();
$telnet->login('root''op'); 

$telnet->exec('(mono -audio -bgimg -single -playlist /share/Apps/mBox/song_list_tmp.jsp -dram 1 &) > /dev/null');

$telnet->disconnect(); 

This is probably all info I can give at the moment, but, to my luck, the author of the class has been very generous with comments.

//Kristopher
Find all posts by this user
01-29-2009, 02:29 PM
Post: #4
RE: Web interface for controlling your music library
I'm thinkning of developing something in the same lines, I'm currious, where did you find the API, that is the protocol or description of what command can be used over Telnet?
//Linus
Find all posts by this user
01-29-2009, 05:53 PM
Post: #5
RE: Web interface for controlling your music library
(01-29-2009 02:29 PM)linen Wrote:  I'm thinkning of developing something in the same lines, I'm currious, where did you find the API, that is the protocol or description of what command can be used over Telnet?
//Linus

I have no good guide of where to find a description of what can be done over telnet. Most of the things I've found by searching here on the forum. The rest is trial and error.

Sorry if that does not help much...

//K
Find all posts by this user
Thread Closed 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Music player minion connection problems webkocken 6 4,896 09-24-2013 12:18 AM
Last Post: glorifyday
Rainbow Music Player Daemon (MPD) - v0.16.2 shadowcode 124 53,632 09-23-2013 01:11 AM
Last Post: glorifyday
  Music Browser for NMT - Updated August, 2nd, 2011 gkreidl 14 11,033 01-19-2013 04:07 PM
Last Post: winfried_laane
  Any music jukebox that syncs with itunes? superflysocal 0 1,401 07-04-2012 02:57 PM
Last Post: superflysocal
  Music Player Daemon (MPD) 2010-04-04 v0.15.9 shadowcode 245 107,868 03-10-2012 01:05 AM
Last Post: ianny
  Stream music to the popcornhour snakeboots 1 3,146 08-30-2011 02:56 PM
Last Post: minio
  music player daemon MPD & PCH Remote control beatnut88 19 11,998 12-22-2010 12:31 AM
Last Post: dooly
  Controlling Jukebox from PC harrykausl 0 1,391 11-02-2010 12:49 PM
Last Post: harrykausl
  Music Player Daemon (MPD) 2009-10-01 Re-Release alanh 290 139,173 04-24-2010 07:20 AM
Last Post: avanegmond
  Accessing Ctorrent web interface with mobile browser oualibadr 0 1,696 02-25-2010 04:11 PM
Last Post: oualibadr

Forum Jump: