-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapi_proxy.php
51 lines (41 loc) · 1.49 KB
/
api_proxy.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
<?php
/*
Simple WMSPanel API proxy
use:
https://you_server/api_proxy.php?path=/v1/server/[server_id]/rtmp/app/&client_id=[client_id]&api_key=[api_key]
instead of:
https://api.wmspanel.com/v1/server/[server_id]/rtmp/app/?client_id=[client_id]&api_key=[api_key]
*/
$allowed_ips = ['127.0.0.1','192.168.0.1'];
$ip = $_SERVER['REMOTE_ADDR'];
if (!empty($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
} elseif (!empty($_SERVER['HTTP_X_REAL_IP'])) {
$ip = $_SERVER['HTTP_X_REAL_IP'];
} elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$commapos = strrpos($ip, ',');
$ip = trim( substr($ip, $commapos ? $commapos + 1 : 0) );
}
if (!in_array($ip, $allowed_ips)) {
header('HTTP/1.0 403 Forbidden');
die();
}
$path = $_GET['path'];
unset($_GET['path']);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://api.wmspanel.com'.$path.'?'.http_build_query($_GET));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
if ($_SERVER['REQUEST_METHOD'] === 'POST' || $_SERVER['REQUEST_METHOD'] === 'PUT') {
$post_data = file_get_contents('php://input');
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($post_data))
);
}
header('Content-Type: application/json');
curl_exec($curl);
?>