Icecast Streaming Media Server Forum Index Icecast Streaming Media Server
Icecast is a Xiph Foundation Project
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

need to read Title and Listeners but Script doesn't work

 
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Icecast Server
View previous topic :: View next topic  
Author Message
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Fri May 29, 2009 8:39 am    Post subject: need to read Title and Listeners but Script doesn't work Reply with quote

This script doesdn't work and I don't know what to change. My path to stats (or stats.xsl) is:

/usr/local/share/icecast/admin/stats.xsl

Using Icecast 2.3.1



<?php

$server = "your.server.com:8001";
$user = "admin";
$passw = "adminpassword";
$mountpoint = "/yourmountpoint";

$fp = fopen("http://$user:$passw@$server/admin/stats","r")
or die("Error reading Icecast data from $server.");

while(!feof($fp))
{
$data .= fread($fp, 8192);
}

fclose($fp);

// Now parse the XML output for our mountpoint
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);

$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) =
array_values($xml_elem['att
ributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}

$listeners = $params['ICESTATS'][$mountpoint]['LISTENERS'];
$currenttrack = $params['ICESTATS'][$mountpoint]['TITLE'];

echo "$listeners listeners are currently connected.";
echo "<br />";
echo "Currently playing: $currenttrack";

?>
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sat May 30, 2009 7:16 am    Post subject: Reply with quote

A lot of views but no help Sad
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Sat May 30, 2009 12:58 pm    Post subject: Reply with quote

maybe because "doesn't work" is a very poor description of the problem. Based on your posting, it could be as simple as no php installed. Does the stats request actually work, does icecast provide it? are there any messages from php? these are all fairly basic points that you should determine.

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sat May 30, 2009 5:46 pm    Post subject: Reply with quote

I know that it doesn't work Smile I didn't write it.
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sat May 30, 2009 5:55 pm    Post subject: Reply with quote

The script wasn't written by me. As the owner of a web hosting company with over 100 *Nix servers I can assure you that PHP is installed. Smile If I turn on error checking it tells me no array. But also if I try using the command http://user:password@serveraddress:port/admin/stats I get nothing. It won't login. If it cannot login it has no chance of working and the array will be empty.

So my original question remains.

What is a way to read the title and song, and number of listeners?
Thanks for the help. Our churches do live broadcasting and need this capability.
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Sat May 30, 2009 7:27 pm    Post subject: Reply with quote

So the first thing to do is find out why the admin url is not working. Obviously you are using an old version but that should be ok for this. I would check the access log for the /admin/stats request to see if the return code is 200 or not, also check if there is anything showing in the error log when that request comes in. Any reached internal limit or permission failure will show in the error log.

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sat May 30, 2009 8:26 pm    Post subject: Reply with quote

Checking the error_log was a good idea because it revealed:

/var/www/vhosts/default/htdocs/admin doesn't exist.

But Icecast is installed as its own directory in /usr/local/share/icecast/admin. I created a symbolic link and it works.

But IE 8 complains

Windows cannot find http://user:password@servername:8000/admin/stats Plese check the spelling a try again. Firefox won't even let me get this far.

So then I tried the other way used for updating the meta tag (that works fine)

http://servername:80000/admin/stats?authuser=user&passwd=password

but I still get prompted for the username and password.

I again tried the first method and tailed the error_log and it does not report and error after adding the symlink. But the script still doesn't work. It shows only:

listeners are currently connected.
Currently playing:

I CAN open the header now and build an array but this isn't my script to begin with. I even wrote:

Code:

$fp = fopen("http://$user:$passw@$server/admin/stats","r")
or die("Error reading Icecast data from $server.");

while(!feof($fp))
{
$data .= fread($fp, 8192);
}

fclose($fp);

print_r($data);


and it dumps the array. So the script I came across partially works but does not properly parse the data. xml_parser_create() works in PHP 4 or 5 so that isn't the issue.

It appears that what I have learned from this is that Windows won't allow me direct access to the page. I can get access now through PHP, but the script fails after reading the header.

Your help IS appreciated. I have at least made some progress.
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Sat May 30, 2009 8:36 pm    Post subject: Reply with quote

Maybe your adminroot is set incorrectly in the icecast xml, if it is set to /var/www/vhosts/default/htdocs/admin instead of /usr/local/share/icecast/admin. Make sure the paths are set correctly for webroot and adminroot. Maybe your loglevel needs to be higher?

I don't know if IE will take that style of url, but I know firefox does

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sat May 30, 2009 9:08 pm    Post subject: Reply with quote

No, not correct. You see when a php script runs under a site on a shared server it is jailed and cannot directly see the icecast installation. /var/www/vhosts/default/htdocs is actually the servers default hosting space. When a command is issued to the server it will read there and the symlink solved that by pointing to the icecsat admin DIR. There's probably another way of doing this but this way worked. Now the issue is undefined arrays in PHP failing.
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Sat May 30, 2009 9:34 pm    Post subject: Reply with quote

krazybob wrote:

Windows cannot find http://user:password@servername:8000/admin/stats Plese check the spelling a try again. Firefox won't even let me get this far.


While I'll accept you may be right about the php script, regarding the admin stats working, your previous posting indicated otherwise.

If you have placed a symbolic link in to refer to a directory outside of the jail then don't expect that to work when you are inside the jail. After all it would defeat the reason for having a jail in the first place. To put it explicitly, are you able to see the xml stats in firefox using the request to icecast., If not then resolve that part first.

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sun May 31, 2009 6:47 am    Post subject: Reply with quote

My previous post stated that I wrote a script that was able to read the headers after creating the symlink.

As you know Icecast installs generally a the server level. Not at the shared hosting site level. For a script to work from a site it refers to the servers httpdocs root. That isn't where Icecast was installed and cannot see the admin files. Creating a symlink solved that problem but created another. With the symlink in place I cannot call http://server:8000/admin/stats and see formatted output. I see XML output after logging in, so the symlink will need to be removed.

See here's the rub. If calling http://user:password@servername:port/admin the browser (server) will look at the servers IP address and look in its httpdocs root. In this case, /var/www/vhosts/default/htdocs and then for /admin. Server security is certainly not going to allow someone at the server httpdocs root to see /usr/local/share....

The script login portion is now working but getting the XML data is not. An array error needs to be corrected.

Code:

[root@server1 httpdocs]# php geticecasttitle.php
PHP Notice:  Undefined variable:  data in /var/www/vhosts/website.name/httpdocs/geticecasttitle.php on line 13
PHP Notice:  Undefined index:  att
ributes in /var/www/vhosts/website.name/httpdocs/geticecasttitle.php on line 30
PHP Warning:  array_values(): The argument should be an array in /var/www/vhosts/website.name/httpdocs/geticecasttitle.php on line 30
PHP Notice:  Undefined index:  att
ributes in /var/www/vhosts/website.name/httpdocs/geticecasttitle.php on line 30
PHP Warning:  array_values(): The argument should be an array in /var/www/vhosts/website.name/httpdocs/geticecasttitle.php on line 30
PHP Notice:  Undefined index:  att


If you have a solution perhaps that would be more productive. I cannot see the XML stats with the script I found on the internet. I can see the raw XML output using the script I wrote but now needs to be parsed. The part of the script not working now is the XML parser command.

I just need a script that works. I installed Icecast using the recommended defaults and the script I located should work. It does not.
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sun May 31, 2009 6:54 am    Post subject: Reply with quote

I removed the symlink and my script can still read the raw XML.I don't know how. I KNOW that others have already done this and I don't know why I cannot find a working script.

I have also learned that /admin/stats shows formated XML whgile /admin/stats/xsl shows browser output.
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
karlH
Code Warrior
Code Warrior


Joined: 13 Jun 2005
Posts: 5476
Location: UK

PostPosted: Sun May 31, 2009 12:55 pm    Post subject: Reply with quote

If you are using a chroot jail then copy or hard link the files for admin/webroot into the jail. The xml output won't need those support files but if you have an incorrect setup then checking things is going to be more difficult, especially if you do not look at logs.

karl.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
krazybob



Joined: 06 Oct 2008
Posts: 18

PostPosted: Sun May 31, 2009 7:02 pm    Post subject: Reply with quote

There's a post missing in here. I posted before you that I got everything to work and can now see the song title and number of listeners. But the script still has errors only seen in the shell or by turning error reporting on. Here is the working script:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-STORE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="MUST-REVALIDATE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="01 Jan 2000 00:00:00 GMT">
<title>Get Icecast Title</title>
</head>

<body>

<?php

$server = "server:port";
$user = "user";
$passw = "password";
$mountpoint = "/mountpoint";
$fp = '';     // added to suppress undefined variable
$data = ''; // added to suppress undefined variable

$fp = fopen("http://$user:$passw@$server/admin/stats","r")
or die("Error reading Icecast data from $server.");

while(!feof($fp))
{
$data .= fread($fp, 8192);
}

fclose($fp);

// Now parse the XML output for our mountpoint
$xml_parser = xml_parser_create();
xml_parse_into_struct($xml_parser, $data, $vals, $index);
xml_parser_free($xml_parser);

$params = array();
$level = array();
foreach ($vals as $xml_elem) {
if ($xml_elem['type'] == 'open') {
if (array_key_exists('attributes',$xml_elem)) {
list($level[$xml_elem['level']],$extra) = array_values($xml_elem['attributes']);
} else {
$level[$xml_elem['level']] = $xml_elem['tag'];
}
}
if ($xml_elem['type'] == 'complete') {
$start_level = 1;
$php_stmt = '$params';
while($start_level < $xml_elem['level']) {
$php_stmt .= '[$level['.$start_level.']]';
$start_level++;
}
$php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];';
eval($php_stmt);
}
}

$listeners = $params['ICESTATS'][$mountpoint]['LISTENERS'];
$currenttrack = $params['ICESTATS'][$mountpoint]['TITLE'];

echo "$listeners listeners are currently connected.";
echo "<br />";
echo "Currently playing: $currenttrack";

?>

</body>
</html>


Here are the errors still generated:

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-STORE">
<META HTTP-EQUIV="CACHE-CONTROL" CONTENT="MUST-REVALIDATE">
<META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">
<META HTTP-EQUIV="EXPIRES" CONTENT="01 Jan 2000 00:00:00 GMT">
<title>Get Icecast Title</title>
</head>

<body>

PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
PHP Notice:  Undefined offset:  1 in /var/www/vhosts/server.name/httpdocs/gettitle.php on line 45
0 listeners are currently connected.<br />Currently playing: CENTRAL
</body>
</html>


Getting these reosolved will result in a code block for others to use as well. I mean, ya'll helped.
_________________
Bob Ricci
Christian Hosting Solutions
http://christian-hosting-solutions.com
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Icecast Streaming Media Server Forum Index -> Icecast Server All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group
subRebel style by ktauber