-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsslib.php
149 lines (123 loc) · 3.36 KB
/
sslib.php
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
// Shoutstats version
define('SS_VERSION', '0.8.5');
// The file providing the the config variables
define('SS_CONF', 'config.ini');
// The file providing the server list
define('SS_SERVERS', 'servers.ini');
// The folder containing the generated PNG
define('SS_PATH_GFX', 'gfx');
// The folder containing the RRDtool databases
define('SS_PATH_RRD', 'rrd');
if (!file_exists(SS_CONF))
{
die(SS_CONF.' file is missing');
}
$configuration = parse_ini_file(SS_CONF, TRUE);
define('SS_RRDTOOL_COMMAND', $configuration['Configuration']['rrdtool_command']);
define('SS_NAME', $configuration['Configuration']['stream_name']);
//if(!is_executable(SS_RRDTOOL_COMMAND))
// die(SS_RRDTOOL_COMMAND . ' not found. Please update the ' . SS_CONF . ' file');
exec(SS_RRDTOOL_COMMAND, $output);
if(!count($output))
{
die(SS_RRDTOOL_COMMAND . ' not found. Please update the ' . SS_CONF . ' file');
}
//
// Get the server list from the configuration file
//
function GetServerList()
{
if (!file_exists(SS_SERVERS))
{
die(SS_SERVERS.' file is missing');
}
$servers = parse_ini_file(SS_SERVERS, TRUE);
ksort($servers);
if (!count($servers))
{
die('no server configured, edit the '.SS_CONF.' file');
}
return $servers;
}
//
// Get the number of current and max listeners from the specified server
//
function GetShoutcastStats($host, $port)
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
// can't connect =(
if (!$fp)
{
print("$errstr ($errno)<br>\n");
$server['current'] = 0;
$server['max'] = 0;
// oh yes, it can connect
}
else
{
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n\r\n");
while (!feof($fp))
{
$content .= fgets($fp,128);
}
fclose($fp);
$debut = strpos($content, '<body>') + strlen('<body>');
$fin = strpos($content, '</body>', $debut);
$string = substr($content, $debut, $fin - $debut);
$stats = explode(',', $string);
// server is up but no source is connected
if ($stats[1] == 0)
{
$server['current'] = 0;
// everything is ok
}
else
{
$server['current'] = $stats[0];
}
$server['max'] = $stats[3];
}
// debug
// print("$host:$port = {$server['current']}/{$server['max']}\n");
return $server;
}
function GetIcecastStats($host,$port,$mp)
{
$fp = fsockopen($host, $port, $errno, $errstr, 30);
// can't connect =(
if (!$fp) {
print("$errstr ($errno)<br>\n");
$server['current'] = 0;
$server['max'] = 0;
// oh yes, it can connect
} else {
fputs($fp, "GET /status2.xsl?mount=/".$mp." HTTP/1.0\r\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)\r\n\r\n");
while (!feof($fp)) {
$content .= fgets($fp,128);
}
fclose($fp);
$debut = strpos($content, $mp) + strlen($mp);
$fin = strpos($content, '</pre>', $debut);
$string = substr($content, $debut, $fin - $debut);
$stats = explode(',', $string);
$server['current'] = $stats[3];
}
// debug
//print("{$string}\n");
//print("$host:$port = {$server['current']}\n");
return $server;
}
//
// Template used to display each generated graph
//
function DisplayGraph($txt_freq, $rrdgfx)
{
$size = GetImageSize($rrdgfx);
?>
<p>
<?php echo $txt_freq?> graph:<br />
<img src="<?php echo $rrdgfx?>" <?php echo $size[3]?> alt="<?php echo $txt_freq?> graph" /><br />
</p>
<?php
}