Created
January 17, 2015 08:20
-
-
Save hirthwork/bcc3b9524f708fff4751 to your computer and use it in GitHub Desktop.
i2p-proxy.php
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 | |
function headerfunc($ch, $str){ | |
header($str); | |
return strlen($str); | |
} | |
function writefunc($ch, $str){ | |
print $str; | |
flush(); | |
return strlen($str); | |
} | |
$url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; | |
$curlSession = curl_init(); | |
curl_setopt($curlSession, CURLOPT_URL, $url); | |
curl_setopt($curlSession, CURLOPT_HEADER, false); | |
if (preg_match("/[.]i2p$/", $_SERVER['HTTP_HOST']) == 1) { | |
curl_setopt($curlSession, CURLOPT_PROXY, '10.100.0.1:4444'); | |
} | |
curl_setopt($curlSession, CURLOPT_HEADERFUNCTION, 'headerfunc'); | |
curl_setopt($curlSession, CURLOPT_WRITEFUNCTION, 'writefunc'); | |
curl_setopt($curlSession, CURLOPT_RETURNTRANSFER, false); | |
curl_setopt($curlSession, CURLOPT_TIMEOUT, 300); | |
curl_setopt($curlSession, CURLOPT_FOLLOWLOCATION, 1); | |
if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
$postinfo = file_get_contents('php://input'); | |
curl_setopt ($curlSession, CURLOPT_POST, 1); | |
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, $postinfo); | |
} | |
curl_exec ($curlSession); | |
if (curl_error($curlSession)) { | |
print curl_error($curlSession); | |
} | |
curl_close ($curlSession); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment