Created
April 14, 2012 17:13
-
-
Save andreyvit/2386007 to your computer and use it in GitHub Desktop.
Tender (tenderapp.com) proxy script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Works: browsing, logging in, file downloads, images attached to KB articles | |
// Doesn't work: posting, file uploads | |
error_reporting(E_ERROR); | |
// phpinfo(); exit; | |
define('OUR_HOST', 'livereload.com'); | |
define('THEIR_HOST', 'livereload.tenderapp.com'); | |
function proxy_header(&$cu, $string) { | |
$length = strlen($string); | |
header($string); | |
return $length; | |
} | |
$url = "http://" . THEIR_HOST . "/help" . $_SERVER["PATH_INFO"]; | |
if (!empty($_SERVER['QUERY_STRING'])) | |
$url .= '?' . $_SERVER['QUERY_STRING']; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_BINARYTRANSFER, TRUE); | |
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); | |
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'proxy_header'); | |
if (!empty($_SERVER["HTTP_COOKIE"])) | |
curl_setopt($ch, CURLOPT_COOKIE, $_SERVER["HTTP_COOKIE"]); | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
if (count($_POST) > 0) { | |
$post = array(); | |
foreach ($_POST as $k => $v) { | |
if (strlen($v) > 0 && $v{0} == '@') | |
$v = ' ' . $v; | |
$post[$k] = $v; | |
} | |
foreach ($_FILES as $k => $file) { | |
if (file_exists($file['tmp_name'])) { | |
$post[$k] = '@' . $file['tmp_name'] . (empty($file['type']) ? '' : ';type=' . $file['type']); | |
} | |
} | |
} | |
curl_setopt($ch, CURLOPT_POST, TRUE); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $post); | |
// curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input")); | |
} elseif ($_SERVER['REQUEST_METHOD'] !== 'GET') { | |
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $_SERVER['REQUEST_METHOD']); | |
} | |
$headers = array('Host: ' . OUR_HOST); | |
if (!empty($_SERVER["HTTP_ACCEPT"])) | |
$headers[] = "Accept: " . $_SERVER["HTTP_ACCEPT"]; | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
$output = curl_exec($ch); | |
echo $output; | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment