2023-09-05 17:18:55 +00:00
|
|
|
<?php
|
|
|
|
|
2023-09-06 21:51:20 +00:00
|
|
|
require __DIR__ . '/inc/functions.php';
|
|
|
|
|
2023-09-05 17:18:55 +00:00
|
|
|
// Define the remote root URL as a constant
|
|
|
|
define('REMOTE_ROOT_URL', 'http://localhost:8300/');
|
|
|
|
|
|
|
|
function proxy() {
|
|
|
|
// Extract the path and query parameters from the client request (e.g., /resource?param=value)
|
|
|
|
$clientPath = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
|
|
|
|
$clientQuery = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
|
|
|
|
|
|
|
|
// Create the full remote URL by combining the remote root, client path, and query parameters
|
|
|
|
$remoteUrl = REMOTE_ROOT_URL . ltrim($clientPath, '/') . ($clientQuery ? '?' . $clientQuery : '');
|
|
|
|
|
|
|
|
$ch = curl_init();
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $remoteUrl);
|
|
|
|
curl_setopt($ch, CURLOPT_HEADER, true);
|
2023-09-06 21:51:20 +00:00
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // Return the response as a string
|
2023-09-05 17:18:55 +00:00
|
|
|
|
2023-09-20 19:37:12 +00:00
|
|
|
// Set the HTTP method explicitly to match the original request method
|
|
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']);
|
|
|
|
|
2023-09-05 17:18:55 +00:00
|
|
|
// If there was a POST request, then forward that as well.
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
|
|
curl_setopt($ch, CURLOPT_POST, true);
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $_POST);
|
|
|
|
}
|
|
|
|
|
2023-09-06 21:51:20 +00:00
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
|
|
|
if ($response === false) {
|
|
|
|
header("HTTP/1.1 502 Bad Gateway");
|
|
|
|
echo "Proxy Error: Unable to communicate with the backend server.";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Split the response into headers and body
|
|
|
|
list($headers, $body) = explode("\r\n\r\n", $response, 2);
|
|
|
|
|
|
|
|
// Set the headers from the backend response
|
|
|
|
$headerLines = explode("\r\n", $headers);
|
|
|
|
foreach ($headerLines as $headerLine) {
|
|
|
|
header($headerLine);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Output the body content
|
|
|
|
echo $body;
|
|
|
|
|
2023-09-05 17:18:55 +00:00
|
|
|
curl_close($ch);
|
|
|
|
}
|
|
|
|
|
2023-09-06 21:51:20 +00:00
|
|
|
function main() {
|
2023-09-07 20:22:10 +00:00
|
|
|
global $mod, $config;
|
2023-09-06 21:51:20 +00:00
|
|
|
|
|
|
|
check_login(true);
|
|
|
|
|
|
|
|
if (!$mod) {
|
|
|
|
// Get the current URL, including query parameters
|
|
|
|
$currentUrl = $_SERVER['REQUEST_URI'];
|
|
|
|
$status = 303;
|
|
|
|
$redirectUrl = '/mod.php?r=' . urlencode($currentUrl) . '&status=' . $status;
|
|
|
|
header('Location: ' . $redirectUrl, true, $status);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-09-07 20:22:10 +00:00
|
|
|
if (!hasPermission($config['mod']['spam_noticer'])) {
|
|
|
|
header("HTTP/1.1 403 Forbidden");
|
|
|
|
echo "You do not have sufficient privileges.";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2023-09-06 21:51:20 +00:00
|
|
|
proxy();
|
|
|
|
}
|
|
|
|
|
|
|
|
main();
|