Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ob_start("ob_gzhandler");
- if (!function_exists("curl_init")) die ("This proxy requires PHP's cURL extension. Please install/enable it on your server and try again.");
- if (!function_exists("getallheaders")) {
- function getallheaders() {
- $result = array();
- foreach($_SERVER as $key => $value) {
- if (substr($key, 0, 5) == "HTTP_") {
- $key = str_replace(" ", "-", ucwords(strtolower(str_replace("_", " ", substr($key, 5)))));
- $result[$key] = $value;
- } else {
- $result[$key] = $value;
- }
- }
- return $result;
- }
- }
- define("PROXY_PREFIX", "http" . (isset($_SERVER['HTTPS']) ? "s" : "") . "://" . $_SERVER["SERVER_NAME"] . ($_SERVER["SERVER_PORT"] != 80 ? ":" . $_SERVER["SERVER_PORT"] : "") . $_SERVER["SCRIPT_NAME"] . "/");
- function makeRequest($url) {
- $user_agent = $_SERVER["HTTP_USER_AGENT"];
- if (empty($user_agent)) {
- $user_agent = "Mozilla/5.0 (compatible; miniProxy)";
- }
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
- $browserRequestHeaders = getallheaders();
- unset($browserRequestHeaders["Host"]);
- unset($browserRequestHeaders["Content-Length"]);
- unset($browserRequestHeaders["Accept-Encoding"]);
- curl_setopt($ch, CURLOPT_ENCODING, "");
- $curlRequestHeaders = array();
- foreach ($browserRequestHeaders as $name => $value) {
- $curlRequestHeaders[] = $name . ": " . $value;
- }
- curl_setopt($ch, CURLOPT_HTTPHEADER, $curlRequestHeaders);
- switch ($_SERVER["REQUEST_METHOD"]) {
- case "POST":
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, file_get_contents("php://input"));
- break;
- case "PUT":
- curl_setopt($ch, CURLOPT_PUT, true);
- curl_setopt($ch, CURLOPT_INFILE, fopen("php://input"));
- break;
- }
- curl_setopt($ch, CURLOPT_HEADER, true);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt ($ch, CURLOPT_FAILONERROR, true);
- curl_setopt($ch, CURLOPT_URL, $url);
- $response = curl_exec($ch);
- $responseInfo = curl_getinfo($ch);
- $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
- curl_close($ch);
- $responseHeaders = substr($response, 0, $headerSize);
- $responseBody = substr($response, $headerSize);
- return array("headers" => $responseHeaders, "body" => $responseBody, "responseInfo" => $responseInfo);
- }
- function rel2abs($rel, $base) {
- if (empty($rel)) $rel = ".";
- if (parse_url($rel, PHP_URL_SCHEME) != "" || strpos($rel, "//") === 0) return $rel;
- if ($rel[0] == "#" || $rel[0] == "?") return $base.$rel;
- extract(parse_url($base));
- $path = isset($path) ? preg_replace('#/[^/]*$#', "", $path) : "/";
- if ($rel[0] == '/') $path = "";
- $port = isset($port) && $port != 80 ? ":" . $port : "";
- $auth = "";
- if (isset($user)) {
- $auth = $user;
- if (isset($pass)) {
- $auth .= ":" . $pass;
- }
- $auth .= "@";
- }
- $abs = "$auth$host$path$port/$rel";
- for ($n = 1; $n > 0; $abs = preg_replace(array("#(/\.?/)#", "#/(?!\.\.)[^/]+/\.\./#"), "/", $abs, -1, $n)) {}
- return $scheme . "://" . $abs;
- }
- function proxifyCSS($css, $baseURL) {
- return preg_replace_callback(
- '/url\((.*?)\)/i',
- function($matches) use ($baseURL) {
- $url = $matches[1];
- if (strpos($url, "'") === 0) {
- $url = trim($url, "'");
- }
- if (strpos($url, "\"") === 0) {
- $url = trim($url, "\"");
- }
- if (stripos($url, "data:") === 0) return "url(" . $url . ")";
- return "url(" . PROXY_PREFIX . rel2abs($url, $baseURL) . ")";
- },
- $css);
- }
- $url = substr($_SERVER["REQUEST_URI"], strlen($_SERVER["SCRIPT_NAME"]) + 1);
- if (empty($url)) die("<html><head><title>PHProxy</title></head><head>
- <body bgcolor=black><center><a href=http://azzatssinz.tumblr.com><img src=http://azzat.wap.mu/files/1049320/piZap_1451738626699.jpg></a><br>
- <style>
- input { margin:0;background-color:#000000;border:1px solid #000000; }
- </style>
- <center><form onsubmit=\"window.location.href='" . PROXY_PREFIX . "' + document.getElementById('site').value; return false;\" /><input method=\"post\" id=\"site\" type=\"text\" size=\"30\" /><input type=\"submit\" value=\"GO!!!\" /></form></center></body></html>");
- if (strpos($url, "//") === 0) $url = "http:" . $url;
- if (!preg_match("@^.*://@", $url)) $url = "http://" . $url;
- $response = makeRequest($url);
- $rawResponseHeaders = $response["headers"];
- $responseBody = $response["body"];
- $responseInfo = $response["responseInfo"];
- $header_blacklist_pattern = "/^Content-Length|^Transfer-Encoding|^Content-Encoding.*gzip/i";
- $responseHeaderBlocks = array_filter(explode("\r\n\r\n", $rawResponseHeaders));
- $lastHeaderBlock = end($responseHeaderBlocks);
- $headerLines = explode("\r\n", $lastHeaderBlock);
- foreach ($headerLines as $header) {
- $header = trim($header);
- if (!preg_match($header_blacklist_pattern, $header)) {
- header($header);
- }
- }
- $contentType = "";
- if (isset($responseInfo["content_type"])) $contentType = $responseInfo["content_type"];
- if (stripos($contentType, "text/html") !== false) {
- $detectedEncoding = mb_detect_encoding($responseBody, "UTF-8, ISO-8859-1");
- if ($detectedEncoding) {
- $responseBody = mb_convert_encoding($responseBody, "HTML-ENTITIES", $detectedEncoding);
- }
- $doc = new DomDocument();
- @$doc->loadHTML($responseBody);
- $xpath = new DOMXPath($doc);
- foreach($xpath->query('//form') as $form) {
- $method = $form->getAttribute("method");
- $action = $form->getAttribute("action");
- $action = empty($action) ? $url : rel2abs($action, $url);
- $form->setAttribute("action", PROXY_PREFIX . $action);
- }
- foreach($xpath->query('//style') as $style) {
- $style->nodeValue = proxifyCSS($style->nodeValue, $url);
- }
- foreach ($xpath->query('//*[@style]') as $element) {
- $element->setAttribute("style", proxifyCSS($element->getAttribute("style"), $url));
- }
- $proxifyAttributes = array("href", "src");
- foreach($proxifyAttributes as $attrName) {
- foreach($xpath->query('//*[@' . $attrName . ']') as $element) {
- $attrContent = $element->getAttribute($attrName);
- if ($attrName == "href" && (stripos($attrContent, "javascript:") === 0 || stripos($attrContent, "mailto:") === 0)) continue;
- $attrContent = rel2abs($attrContent, $url);
- $attrContent = PROXY_PREFIX . $attrContent;
- $element->setAttribute($attrName, $attrContent);
- }
- }
- $head = $xpath->query('//head')->item(0);
- $body = $xpath->query('//body')->item(0);
- $prependElem = $head != NULL ? $head : $body;
- if ($prependElem != NULL) {
- $scriptElem = $doc->createElement("script",
- '(function() {
- if (window.XMLHttpRequest) {
- function parseURI(url) {
- var m = String(url).replace(/^\s+|\s+$/g, "").match(/^([^:\/?#]+:)?(\/\/(?:[^:@]*(?::[^:@]*)?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/);
- // authority = "//" + user + ":" + pass "@" + hostname + ":" port
- return (m ? {
- href : m[0] || "",
- protocol : m[1] || "",
- authority: m[2] || "",
- host : m[3] || "",
- hostname : m[4] || "",
- port : m[5] || "",
- pathname : m[6] || "",
- search : m[7] || "",
- hash : m[8] || ""
- } : null);
- }
- function rel2abs(base, href) { // RFC 3986
- function removeDotSegments(input) {
- var output = [];
- input.replace(/^(\.\.?(\/|$))+/, "")
- .replace(/\/(\.(\/|$))+/g, "/")
- .replace(/\/\.\.$/, "/../")
- .replace(/\/?[^\/]*/g, function (p) {
- if (p === "/..") {
- output.pop();
- } else {
- output.push(p);
- }
- });
- return output.join("").replace(/^\//, input.charAt(0) === "/" ? "/" : "");
- }
- href = parseURI(href || "");
- base = parseURI(base || "");
- return !href || !base ? null : (href.protocol || base.protocol) +
- (href.protocol || href.authority ? href.authority : base.authority) +
- removeDotSegments(href.protocol || href.authority || href.pathname.charAt(0) === "/" ? href.pathname : (href.pathname ? ((base.authority && !base.pathname ? "/" : "") + base.pathname.slice(0, base.pathname.lastIndexOf("/") + 1) + href.pathname) : base.pathname)) +
- (href.protocol || href.authority || href.pathname ? href.search : (href.search || base.search)) +
- href.hash;
- }
- var proxied = window.XMLHttpRequest.prototype.open;
- window.XMLHttpRequest.prototype.open = function() {
- if (arguments[1] !== null && arguments[1] !== undefined) {
- var url = arguments[1];
- url = rel2abs("' . $url . '", url);
- url = "' . PROXY_PREFIX . '" + url;
- arguments[1] = url;
- }
- return proxied.apply(this, [].slice.call(arguments));
- };
- }
- })();'
- );
- $scriptElem->setAttribute("type", "text/javascript");
- $prependElem->insertBefore($scriptElem, $prependElem->firstChild);
- }
- echo "<!-- AZZATSSINS -->\n" . $doc->saveHTML();
- } else if (stripos($contentType, "text/css") !== false) {
- echo proxifyCSS($responseBody, $url);
- } else {
- header("Content-Length: " . strlen($responseBody));
- echo $responseBody;
- }
- ?>
Add Comment
Please, Sign In to add comment