SHARE
TWEET

Untitled

a guest Jan 22nd, 2015 219 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.   // Default headers.
  4.   $request_headers = array();
  5.  
  6.   // Merge with our received headers, this MUST be done as javascript/jquery
  7.   // must be allowed to add custom headers
  8.   foreach (getallheaders() as $h_name => $h_value) {
  9.     $request_headers[$h_name] = $h_value;
  10.   }
  11.  
  12.   // Persistent headers.
  13.   $request_headers['SPLUNKUSER'] = $user->name;
  14.  
  15.   // Remove the - by cURL itself - added 'Expect' header.
  16.   // @see http://curl.haxx.se/mail/archive-2006-10/0044.html.
  17.   $request_headers['Expect'] = '';
  18.  
  19.   if ($_SERVER['REQUEST_METHOD'] == 'POST'){
  20.  
  21.     // Store the posted data to be used multiple times.
  22.     $postfields = file_get_contents('php://input');
  23.   }
  24.    
  25.   $request_headers_new = array();
  26.   foreach ($request_headers as $h_name => $h_value) {
  27.     $request_headers_new[$h_name] = $h_name . ': '. $h_value;
  28.   }
  29.  
  30.   if ($_SERVER['REQUEST_METHOD'] == 'POST'){
  31.     curl_setopt($ch, CURLOPT_POST, 1);
  32.     curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  33.   }
  34.  
  35.   // Added for new splunk version to work.
  36.   curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/splunk-cookie-'. session_id());
  37.   curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/splunk-cookie-'. session_id());
  38.   //
  39.  
  40.   curl_setopt($ch, CURLOPT_URL, $url);
  41.   curl_setopt($ch, CURLOPT_HEADER, 1);
  42.   curl_setopt($ch, CURLOPT_VERBOSE, 0);
  43.   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  44.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  45.   curl_setopt($ch, CURLOPT_TIMEOUT, 0);
  46.   curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  47.   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  48.   curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4 );
  49.   curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers_new);
  50.   curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
  51.   curl_setopt($ch, CURLOPT_SSLVERSION , 3);
  52.  
  53.   //Send the request and store the result in an array
  54.   $response = curl_exec ($ch);
  55.  
  56.   // Separate header and body.
  57.   list($response_headers, $body) = explode("\r\n\r\n", $response);
  58.  
  59.   $response_headers = str_replace("Transfer-Encoding: chunked\r\n", "", $response_headers);
  60.  
  61.   // Separate individual headers.
  62.   $response_headers = explode("\r\n", $response_headers);
  63.  
  64.   foreach ($response_headers as $key => $value) {
  65.  
  66.     // Sent header to browser.
  67.     header(trim($value));
  68.   }
  69.  
  70.   // Replace absolute url's (for stylesheets, js etc).
  71.   $body = str_replace($splunk_url, $proxy_url, $body);
  72.  
  73.   // Sent body to browser.
  74.   echo  $body;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top