Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Default headers.
- $request_headers = array();
- // Merge with our received headers, this MUST be done as javascript/jquery
- // must be allowed to add custom headers
- foreach (getallheaders() as $h_name => $h_value) {
- $request_headers[$h_name] = $h_value;
- }
- // Persistent headers.
- $request_headers['SPLUNKUSER'] = $user->name;
- // Remove the - by cURL itself - added 'Expect' header.
- // @see http://curl.haxx.se/mail/archive-2006-10/0044.html.
- $request_headers['Expect'] = '';
- if ($_SERVER['REQUEST_METHOD'] == 'POST'){
- // Store the posted data to be used multiple times.
- $postfields = file_get_contents('php://input');
- }
- $request_headers_new = array();
- foreach ($request_headers as $h_name => $h_value) {
- $request_headers_new[$h_name] = $h_name . ': '. $h_value;
- }
- if ($_SERVER['REQUEST_METHOD'] == 'POST'){
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
- }
- // Added for new splunk version to work.
- curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/splunk-cookie-'. session_id());
- curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/splunk-cookie-'. session_id());
- //
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, 0);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_TIMEOUT, 0);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
- curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers_new);
- curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
- curl_setopt($ch, CURLOPT_SSLVERSION , 3);
- //Send the request and store the result in an array
- $response = curl_exec ($ch);
- // Separate header and body.
- list($response_headers, $body) = explode("\r\n\r\n", $response);
- $response_headers = str_replace("Transfer-Encoding: chunked\r\n", "", $response_headers);
- // Separate individual headers.
- $response_headers = explode("\r\n", $response_headers);
- foreach ($response_headers as $key => $value) {
- // Sent header to browser.
- header(trim($value));
- }
- // Replace absolute url's (for stylesheets, js etc).
- $body = str_replace($splunk_url, $proxy_url, $body);
- // Sent body to browser.
- echo $body;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement