1

So I'm trying to update the following code which monitors icecast and shoutcast listeners because when I upgraded to shoutcast 2 it stopped working and the author is AWOL or at least chosing not to answer.

Now I think that I've have solved the problem with the regex code but it's still not working. Which makes me think the manner in which the code retrieves the status page and the new URL format is also a problem.

Anyway I would appreciate any help you can give me in trying to work out how to fix this, thank you!

Source code: https://github.com/munin-monitoring/contrib/blob/f444e600c9718ba249d46d3b44d6b6ebaccb0aa3/plugins/network/radio

The old regex from line 158:

preg_match_all( "/.*?Stream Status: \<\/td\>\<td\>\<b\>\Stream is up at \d*? kbps with (\d*?) of \d*? listeners\<\/b\>\<\/td\>\<\/tr\>/s", $xml, $parser );

My first regex:

preg_match_all( "/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at (\d*?) kbps with \<B\>(\d*?) of (\d*?) listeners/s", $xml, $parser );

The problem code:

    function getShout( $host, $port, $name ) {
            $error = false;
            $fp = fsockopen( $host, $port, $errno, $errstr, 10 );
            if ( !$fp ) {
                    $error = $errstr ."(". $errno .")";
            } else {
                    fputs( $fp, "GET / HTTP/1.0\r\n" );
                    fputs($fp, "User-Agent: Mozilla\r\n");
                    fputs( $fp, "Connection: close\r\n\r\n" );

                    $xml = "";

                    while ( !feof( $fp ) ) {
                            $xml .= fgets($fp, 512);
                    }
                    fclose( $fp );

                    if ( stristr( $xml, "HTTP/1.0 200 OK" ) == true ) {
                            $xml = trim( substr( $xml, 42 ) );
                    } else {
                            $error = "Bad login";
                    }
                    if ( !$error ) {
                            $res = array( "found" => true );

                            preg_match_all( "/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at (\d*?) kbps with \<B\>(\d*?) of (\d*?) listeners/s", $xml, $parser );

                            $res["listeners"] = $parser[1][0];
                            $res["name"] = $name;

                    } else {
                            $res = $error;
                    }
            }
            return $res;
    }

The output I get from running the plugin at the command line...

rock.value B

pop.value B

rap.value B

dnb.value B

psytrance.value B

breaks.value B

dubstep.value B

reggae.value B

techno.value B

ambient.value B

complete.value 0

Sample shoutcast v1 status page: http://stream.radioamlo.info:8010/

Sample shoutcast v2 status page: http://91.221.151.237:8994/index.html?sid=1


UPDATE #1: My second regex which looks better:

preg_match_all( "/.*?Stream Status: \<\/font\>\<\/td\>\<td>\<font class\=default\>\<b\>Stream is up at \d*? kbps with \<B\>(\d*?) of \d*? 

UPDATE #2: Adding 'echo $xml;' after '$error = "Bad login";' returns the following error:

<html><head><title>Redirect</title></head><body>Click <a href="/index.html?sid=1">here</a> for redirect.</body></html>techno.value B
HTTP/1.1 302 Found
Content-Type:text/html;charset=utf-8
Location:index.html?sid=1
Content-Length:118
Community
  • 1
  • 1
Fat Finger
  • 59
  • 1
  • 2
  • 7

1 Answers1

0

According the things you wrote the problem is, that the location where your information are fetched had changed. The error-message posted by you already tells the new location (prepend the host name before it).

I'm not that familiar with fsock, bot I think it can't deal with redirects. So I would advice you to use cURL instead: Just stick to the first example on on the cURL manual. The output of cURL then just replaces your $xml. Remember to pass the GET-Information ?sid=1 to cURL as well!

Just test this and then you will see if there are more errors regarding the parsing of the string. If yes, pleas post the "new $xml".

fjellfly
  • 388
  • 1
  • 13