This repository has been archived by the owner on Aug 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
api.php
340 lines (332 loc) · 12.7 KB
/
api.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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
<?php
/*
* @author: Scottish Borders Design
* @script: SBD SHOUTcast Manager
* @function: API Generation Page
* @website: http://scottishbordersdesign.co.uk/
*/
header('Access-Control-Allow-Origin: *');
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
if (isset($_GET['getkey']) || isset($_GET['apistatus']) || isset($_GET['apiLevel']) || isset($_GET['genkey']) || isset($_GET['revokeKey'])) {
session_start();
if (isset($_GET['getkey']) && !$_SESSION['username'] || isset($_GET['apistatus']) && !$_SESSION['username'] || isset($_GET['apiLevel']) && !$_SESSION['username'] || isset($_GET['genkey']) && !$_SESSION['username'] || isset($_GET['revokeKey']) && !$_SESSION['username']) {
die("Error: -99");
}
include "include/functions.inc.php";
$db = dbconnect();
if (isset($_GET['apistatus']) && $_GET['apistatus'] == '1') {
if ($config['api_enabled'] == '1') {
die ('Online');
} else {
die ('Offline');
}
}
if (isset($_GET['getkey']) && $_GET['getkey'] == '1') {
$db->where("username", $_SESSION['username']);
$row = $db->getOne("members");
if (!$row['api_key'] || $row['api_key'] == '' || $row['api_key'] == 'NULL') {
$apiKey = "0000-0000-000";
} else {
$apiKey = $row['api_key'];
}
die($apiKey);
}
if (isset($_GET['genkey']) && $_GET['genkey'] == '1') {
$key = genKey();
$db->where('username', $_SESSION['username']);
$db->update('members', array(
'api' => '1',
'api_key' => $key
));
addevent($_SESSION['username'], ' [API KEY] Generated Key');
}
if (isset($_GET['revokeKey']) && $_GET['revokeKey'] == '1') {
$key = genKey();
$db->where('username', $_SESSION['username']);
$db->update('members', array(
'api' => '0',
'api_key' => ''
));
addevent($_SESSION['username'], ' [API KEY] Revoked Key');
}
if (isset($_GET['apiLevel']) && $_GET['apiLevel'] == '1') {
$db->where("username", $_SESSION['username']);
$row = $db->getOne("members");
switch ($row['api']) {
case '0':
$level = "None";
break;
case '1':
$level = "Basic";
break;
case '2':
$level = "Reseller";
break;
case '3':
$level = "Admin";
break;
default:
$level = "None";
break;
}
die($level);
}
exit;
} else {
include "header.php";
$myid = getuid($_SESSION['username']);
$myservers = getmyserversMulti_byid($myid);
}
?>
<h1>
SHOUTcast Panel
<small>API</small>
</h1>
<ol class="breadcrumb">
<li><a href="#"><i class="fa fa-dashboard"></i> SHOUTcast Panel</a></li>
<li class="active">API</li>
</ol>
</section>
<!-- Main content -->
<section class="content">
<div class="row">
<div class="col-xs-12">
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3 id="apistatustext">
Checking ...
</h3>
<p>
API Status
</p>
</div>
<div class="icon">
<i id="statuscheckicon" class="ion ion-loading-c"></i>
<!-- status online: ion-android-earth -->
<!-- status offline: ion-close-round -->
<!-- status loading: ion-loading-c -->
</div>
<a href="#" onClick="checkAPIStatus();return false;" class="small-box-footer">
Check Status <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green">
<div class="inner">
<h3 id="yourkey">
Fetching ...
</h3>
<p>
Your Key
</p>
</div>
<div class="icon">
<i id="keyloader" class="ion ion-key"></i>
</div>
<a href="#" onClick="genkey();return false;" class="small-box-footer">
Generate Key <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-yellow">
<div class="inner">
<h3 id="apilevel">
Fetching ...
</h3>
<p>
Access Level
</p>
</div>
<div class="icon">
<i id="apiloader" class="ion ion-settings"></i>
</div>
<a href="#" onClick="revokeKey();return false;" class="small-box-footer">
Revoke <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red">
<div class="inner">
<h3>
v1.5
</h3>
<p>
API Version
</p>
</div>
<div class="icon">
<i class="ion ion-code"></i>
</div>
<a data-toggle="modal" onClick="loadDocs();" data-target="#myModal" href="#myModal" class="small-box-footer">
View Developer Documents <i class="fa fa-arrow-circle-right"></i>
</a>
</div>
</div><!-- ./col -->
</div>
</div><!-- /.row -->
</div>
<?php
$i = "0";
if (isset($_GET['page'])) {
$page = $_GET['page'];
} else {
$page = 1;
};
$db->pageLimit = 50;
$db->where("user", $_SESSION['username']);
$events = $db->arraybuilder()->paginate("api_events", $page);
?>
<div class="box">
<div class="box-header" style=" ">
<h3 class="box-title">API Event Log</h3>
</div><!-- /.box-header -->
<div class="box-body table-responsive">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Host/IP</th>
<th>Type</th>
<th>Action</th>
<th>Timestamp</th>
</tr>
</thead>
<tbody>
<?php
foreach ($events as $key => $event){
echo "<tr>";
echo "<td>{$event['host']}</td>";
echo "<td>{$event['url']}</td>";
echo "<td>{$event['action']}</td>";
echo "<td>{$event['timestamp']}</td>";
echo "</tr>";
}
echo "</tbody><tfoot>showing {$page} out of {$db->totalPages}</tfoot></table></div><!-- /.box-body --></div>";
?>
<ul class="pagination pagination-sm no-margin pull-right">
<?php
for ($d=1; $d<=$db->totalPages; $d++) {
echo "<li><a href=\"{$config['web_addr']}/api.php?page=".$d."/\">".$d."</a></li>";
};
?>
</ul>
<?php require('footer.php');
?>
<script>
function checkAPIStatus(){
$('#statuscheckicon').attr('class', 'ion-loading-c');
$('#apistatustext').html("Checking ...");
$.get( "?apistatus=1", function( data ) {
if (data.indexOf("Offline") > -1) {
$('#statuscheckicon').attr('class', 'ion-close-round');
};
if (data.indexOf("Online") > -1) {
$('#statuscheckicon').attr('class', 'ion-android-earth');
};
$('#apistatustext').html(data);
});
} checkAPIStatus();
function getKey(){
$('#keyloader').attr('class', 'ion-loading-c');
$('#yourkey').html("Fetching ...");
$.get( "?getkey=1", function( data ) {
$('#yourkey').html(data);
});
$('#keyloader').attr('class', 'ion-key');
} getKey();
function genkey(){
$('#keyloader').attr('class', 'ion-loading-c');
$('#yourkey').html("Generating ...");
$.get( "?genkey=1", function( data ) {
getKey();
apiLevel();
checkAPIStatus();
});
$('#keyloader').attr('class', 'ion-key');
}
function apiLevel(){
$('#apiloader').attr('class', 'ion-loading-c');
$('#apilevel').html("Fetching ...");
$.get( "?apiLevel=1", function( data ) {
$('#apilevel').html(data);
});
$('#apiloader').attr('class', 'ion-settings');
} apiLevel();
function revokeKey(){
$('#apiloader').attr('class', 'ion-loading-c');
$('#apilevel').html("Fetching ...");
$.get( "?revokeKey=1", function( data ) {
getKey();
apiLevel();
checkAPIStatus();
});
$('#apiloader').attr('class', 'ion-settings');
}
function loadDocs(){
jQuery('.yourAPIKey').each(function(){
jQuery(this).html( jQuery('#yourkey').html() );
});
}
function changePort(){
if (jQuery('#portNumberSelector').val() == 'null') {
jQuery('#docsViewer').slideUp();
} else {
jQuery('#docsViewer').slideDown();
}
}
</script>
<!-- Modal Graphical Stats View -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog" style="width:92%;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Developer Documents</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="server">API Server Selection</label>
<select class="form-control" name="portNumberSelector" id="portNumberSelector" onChange="changePort();">
<option value="null">Select Server</option>
<?php
foreach ($myservers as $key => $server) {
if (isset($port) && $port == $server['PortBase']) {
echo "<option value='{$server['PortBase']}' selected>{$server['servername']} - {$server['PortBase']}</option>";
} else {
echo "<option value='{$server['PortBase']}'>{$server['servername']} - {$server['PortBase']}</option>";
}
}
?>
</select>
</div>
<div id="docsViewer" style="display:none;">
<?php
include("api/docs/index.php");
?>
</div>
<script>
$('#portNumberSelector').on('change', function (e) {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
jQuery('.yourPortNumber').each(function(){
jQuery(this).html( valueSelected );
});
});
</script>
</div>
<div class="modal-footer" id="">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->