Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Reply
Thread Tools Search this Thread Display Modes
Old 24th February 2019, 07:30   #1
PARALAX
Junior Member
 
Join Date: Feb 2011
Posts: 22
Listeners Counter & Online Status for V2 server - Missing variable

I have a small, simple shoutcast script that needs a little finetuning, though I know I'm on the right path there. Depending on the online status of the Shoutcast server, the script of our old V1 server displays a corresponding graphic in the form of a green, yellow or red light. In addition, it counts the individual listeners per server and adds them to a total number that is also output on the generated page. Furthermore, by interrogating the "AIM" information by sending the ID tag "LIVE" or "LIVE2", a special graphics for live broadcasts can be displayed. However, this only works with Shoutcast V1 servers.

My goal is to make the script so compatible, at least for Shoutcast V2 server, that the online status as well as the listeners counter works, even with multiple mountpoints.

I have already added a new configuration called "sid". However, I still miss the code which queries and processes the corresponding URL in the browser depending on the SID value. I have already tried to build parts of other scripts there, but so far without success. Maybe someone can help here and rewrite the script accordingly and bring it up to date.

PHP Code:
<?php

$manyListeners 
100// Display listeners bold after how many listeners?

$sc_servers = array(
    
'dsl' => array(
        
'name'           => 'DSL',
        
'ip'             => '136.243.11.11',
        
'port'           => '8300',
        
'sid'         => '1'// SID-Number for Shoutcast V2 server
        
'online_imgurl'  => '/gfx/status_dsl_on.gif'//  URL to your online image
        
'offline_imgurl' => '/gfx/status_dsl_off.gif'//  URL to your offline image
        
'down_imgurl'    => '/gfx/status_dsl_down.gif'//  URL to your downtime image
        
'live_imgurl'    => '/gfx/status_dsl_live.gif'// URL to your live status image

//        'override_downness'  => 'extern_dsl'    // Get Online & Offline status from another server instead?
    
),
//    'extern_dsl' => array( //  URL to your online image
//        'name'           => 'DSL', //  URL to your offline image
//        'ip'             => '136.243.11.11', //  URL to your downtime image
//        'port'           => '8000' // URL to your live status image
//    ),
    
'mobile' => array(
        
'name'           => 'Mobile',
        
'ip'             => '136.243.11.11'// static ip address of server, do not use dns names (static ip is faster)
        
'port'           => '8300'// port number of shoutcast server
        
'sid'         => '2'// SID-Number for Shoutcast V2 server
        
'online_imgurl'  => '/gfx/status_mobile_on.gif'//  URL to your online image
        
'offline_imgurl' => '/gfx/status_mobile_off.gif'//  URL to your offline image
        
'down_imgurl'    => '/gfx/status_mobile_down.gif'//  URL to your downtime image
        
'live_imgurl'    => '/gfx/status_mobile_on.gif'// URL to your live status image
    
),
    
'video' => array(
        
'name'           => 'Videostream',
        
'ip'             => '136.243.11.11'// static ip address of server, do not use dns names (static ip is faster)
        
'port'           => '8100'// port number of shoutcast server
        
'online_imgurl'  => '/gfx/status_video_on.gif'//  URL to your online image
        
'offline_imgurl' => '/gfx/status_video_off.gif'//  URL to your offline image
        
'down_imgurl'    => '/gfx/status_video_down.gif'//  URL to your downtime image
        
'live_imgurl'    => '/gfx/status_video_live.gif'// URL to your live status image
    
),
);

ini_set("max_execution_time""20");

function 
getDoc($server$filename) {
    global 
$sc_errno$errstr;
    
$scp = @fsockopen($server['ip'], $server['port'], $errno$errstr8);
    if(!
$scp) return null;

    
fputs($scp,"GET $filename HTTP/1.0\r\nUser-Agent: SC Status (Mozilla Compatible)\r\n\r\n");
    
$r "";
    while(!
feof($scp)) {
        
$r .= fgets($scp1024);
    }
    @
fclose($scp);
    return 
$r;
}

function 
getServerInfo($server) {
    
$seven getDoc($server"/7.html");
    if(
$seven === null) return array('status' => "DOWN"'listeners' => 0);

    
$seven ereg_replace(".*<body>"""$seven);
    
$seven ereg_replace("</body>.*"","$seven);
    
$sc_contents explode(",",$seven);

    if(
$sc_contents[1] != 1) return array('status' => "OFFLINE"'listeners' => 0);

    
$index getDoc($server"/index.html");
    
$listeners $sc_contents[0];
    if(
$index === null) return array('status' => "ONLINE"'listeners' => $listeners); // 7.html ging ja...

    
$index ereg_replace(".*Stream AIM:"""$index);

    
$tdStart strpos($index'</td>');
    
$index substr($index$tdStart+5);

    
$tdStart strpos($index'</td>');
    
$index substr($index0$tdStart);

    if(
strpos($index"live") !== false
        
||strpos($index"Live") !== false
        
||strpos($index"LIVE") !== false
        
||strpos($index"live2") !== false
        
||strpos($index"Live2") !== false
        
||strpos($index"LIVE2") !== false) return array('status' => "LIVE"'listeners' => $listeners);
    return array(
'status' => "ONLINE"'listeners' => $listeners);
}

function 
renderStatus($server$status) {
    switch(
$status) {
        case 
'DOWN':
            
$tooltip "Server ist inaktiv";
            
$image $server['down_imgurl'];
            break;
        case 
'OFFLINE':
            
$tooltip "Server ist offline";
            
$image $server['offline_imgurl'];
            break;
        case 
'ONLINE':
            
$tooltip "Server ist online";
            
$image $server['online_imgurl'];
            break;
        case 
'LIVE':
            
$tooltip "Livesendung l&auml;uft";
            
$image $server['live_imgurl'];
            break;
    }

    echo 
'<p title="' $tooltip '"><img src="' $image '" alt="' $tooltip '"></p>';
}

if(
$_GET['inner']==null) {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
    <link rel=Stylesheet type="text/css" media=all href="/gfx/radio_small.css">
    <script type="text/javascript" src="/prototype.js"></script>
    <script type="text/javascript" src="/utils.js"></script>
    <style type="text/css">
        body { margin-left: 0; margin-right: 0 }
        tr { background-color: #90a6ca }
        td { text-align: center }
    </style>
</head>
<body margin='0' onLoad="periodical(60, setInnerHTML.curry('bodybody', 'sc_status.php?inner=1'))"><span id='bodybody'>
<?php
}

// Which servers are displayed?
$visibleServers = array('dsl''mobile''video');

// Which servers are counted?
$listenerKeys = array('dsl''mobile'); // add "extern_" in case of query an external server instead.

$allInfos = array();

foreach(
$sc_servers as $server => $config) {
    
$allInfos[$server] = getServerInfo($config);
}

foreach(
$sc_servers as $server => $config) {
    if(
$config['override_downness']) {
        
$otherStatus $allInfos[$config['override_downness']]['status'];
        if(
$otherStatus == "DOWN" || $otherStatus == "OFFLINE") {
            
$allInfos[$server]['status'] = $otherStatus;
        }
    }
}

echo 
"<body bgcolor='#A4B0C4'>\n";
echo 
"<table border='0' cellpadding='0' cellspacing='1' bgcolor='#566A8E' width='100%'>\n";

echo 
'<tr bgcolor="#566a8e">
        <td bgcolor="#566A8E"><b>Serverstatus</b></td>
    </tr>
'
;

foreach(
$visibleServers as $k) {
    echo
"<tr height='16'><td>\n";
    
renderStatus($sc_servers[$k], $allInfos[$k]['status']);
    echo
"</td></tr>\n";
}

$listenersSum 0;
$tooltip "";
foreach(
$listenerKeys as $k) {
    
$listenersSum += $allInfos[$k]['listeners'];
    
$addToTooltip $allInfos[$k]['listeners'] > 0;
    if(
$addToTooltip) {
        if(
$tooltip != ""$tooltip .= "   |   ";
        
$tooltip .= $sc_servers[$k]['name'] . ": " $allInfos[$k]['listeners'];
    }
}

$listenersSumText $listenersSum >= $manyListeners "<b>" $listenersSum "</b>" $listenersSum;

// ***** Start Display Listeners
echo'<tr height="16"><td><div align="center" title = "' $tooltip '">
<table border="0" cellspacing="0" cellpadding="0" width="94"><tr><td><div align="left"><img src="/gfx/listener.gif"></div></td><td align="right" style="text-align: right">' 
$listenersSumText '</td></tr></table>';
echo
'</div></td></tr>';
// ***** End Display Listeners

echo'</table>';
echo
'</body>';

if(
$_GET['inner']==null) {
    echo 
"\n</span></body></html>";
}
?>
Code snippets that I found in other scripts, but unfortunately did not work:

PHP Code:
/* for V2, add sid to url */
                    
if ($this->sid==0)
                       
fputs($fp"GET /admin.cgi?pass=".$this->passwd."&mode=viewxml HTTP/1.0\r\n");
                    else
                       
fputs($fp"GET /admin.cgi?sid=".$this->sid."&pass=".$this->passwd."&mode=viewxml HTTP/1.1\r\n");
                    
fputs($fp"User-Agent: Mozilla\r\n\r\n");
                    while (!
feof($fp)) {
                                
$this->_xml .= fgets($fp512);
                    }
                    
fclose($fp);                    
            
$this->_xml utf8_encode($this->_xml); // Added by Gavin @ MixStream.net
                        
if (stristr($this->_xml"200 OK") == true) {
                           
$xxp=strpos($this->_xml,"<");
                            
$this->_xml trim(substr($this->_xml$xxp));
                        } else {
                                
$this->_error "Bad login";
                                return(
0);
                        }

                        
$xmlparser xml_parser_create();
                        if (!
xml_parse_into_struct($xmlparser$this->_xml$this->_values$this->_indexes)) {
                                
$this->_error "Unparsable XML";
                                return(
0);
                        } 
PHP Code:
if ($shoutcast->sid>0) {
           
$v2info="?sid=".$shoutcast->sid;
           
$v2xtra=":".$shoutcast->sid;
        } else {
           
$v2info="";
           
$v2xtra="";
        } 
Where do I have to insert or replace them to make it work?
PARALAX is offline   Reply With Quote
Old 24th February 2019, 19:57   #2
PARALAX
Junior Member
 
Join Date: Feb 2011
Posts: 22
@neralex: Did you get my PM?
PARALAX is offline   Reply With Quote
Old 27th February 2019, 00:59   #3
PARALAX
Junior Member
 
Join Date: Feb 2011
Posts: 22
Still waiting for an answer...
PARALAX is offline   Reply With Quote
Old 27th February 2019, 06:41   #4
neralex
Major Dude
 
Join Date: Mar 2011
Posts: 576
lol
neralex is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump