This repository was archived by the owner on Aug 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathproxy.php
More file actions
47 lines (39 loc) · 1.26 KB
/
proxy.php
File metadata and controls
47 lines (39 loc) · 1.26 KB
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
<?php
// Cross-origin proxy
// Not needed if on same domain, or if have elevated privs (apps)
// Not needed if CORS stuff is set up on the API, but doesn't seem to be avail?
require './config.php';
if (!defined('BUGTENDER_PROXY') || !BUGTENDER_PROXY) {
header('HTTP/1.x 403 Not Allowed');
die('Proxy not enabled.');
}
if (!isset($_SERVER['REQUEST_METHOD']) || $_SERVER['REQUEST_METHOD'] !== 'POST') {
header('HTTP/1.x 400 Bad Request');
die('Invalid method; only POST accepted');
}
if (!isset($_SERVER['CONTENT_TYPE']) || $_SERVER['CONTENT_TYPE'] !== 'application/json-rpc') {
header('HTTP/1.x 400 Bad Request');
die('Invalid Content-Type: ' . htmlspecialchars($_SERVER['CONTENT_TYPE']));
}
$type = $_SERVER['CONTENT_TYPE'];
$data = file_get_contents('php://input');
$context = stream_context_create(
array(
'http' => array(
'method' => 'POST',
'content' => $data,
'header' => "Content-Type: $type\r\n",
)
)
);
$old = error_reporting(0);
$stream = fopen(BUGTENDER_PROXY, "r", false, $context);
error_reporting($old);
if ($stream) {
header('Content-Type: application/json');
fpassthru($stream);
fclose($stream);
} else {
header('HTTP/1.x 503 Gateway Error');
die('Gateway error');
}