1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
$mysession = curl_init();
curl_setopt($mysession, CURLOPT_URL, "http://$server/admin.cgi?mode=viewxml");
curl_setopt($mysession, CURLOPT_HEADER, false);
curl_setopt($mysession, CURLOPT_RETURNTRANSFER, true);
curl_setopt($mysession, CURLOPT_POST, false);
curl_setopt($mysession, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($mysession, CURLOPT_USERPWD, "admin:$password");
curl_setopt($mysession, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($mysession, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
$xml = curl_exec($mysession);
curl_close($mysession);
$xml = str_replace("'", "'", $xml);
$result = "";
$listeners = "0";
$maxlisteners = "0";
$songs = "";
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_parse($xml_parser, $xml);
xml_parser_free($xml_parser);
$usa = $listeners;
$temp = "";
foreach ($country as $key=>$val) {
$country = $countries[$key];
if (strlen($country) > 0) {
$temp .= ", $country";
if ($val > 1)
$temp .= " ($val)";
$usa -= $val;
}
}
$result = "There are currently $listeners out of $maxlisteners listeners from:\n";
$result .= "USA ($usa)$temp";
$result .= $songs;
echo trim($result);
function startElement($parser, $name, $attrs) {
global $curTag;
$curTag .= "^$name";
}
function endElement($parser, $name) {
global $curTag;
$caret_pos = strrpos($curTag, '^');
$curTag = substr($curTag, 0, $caret_pos);
}
function characterData($parser, $data) {
global $curTag;
global $country;
global $listeners;
global $maxlisteners;
global $songs;
if ($curTag == "^SHOUTCASTSERVER^LISTENERS^LISTENER^HOSTNAME") {
$parts = explode(".", $data);
$i = end($parts);
$country[$i]++;
}
if ($curTag == "^SHOUTCASTSERVER^CURRENTLISTENERS") {
$listeners = $data;
}
if ($curTag == "^SHOUTCASTSERVER^MAXLISTENERS") {
$maxlisteners = $data;
}
if ($curTag == "^SHOUTCASTSERVER^SONGHISTORY^SONG^TITLE") {
if (strpos($data, " 0:") === false)
$songs .= "\n$data";
}
} |
Partager