function onHeadersReceived(ProxyEvent $event)
 {
     // so stupid... onCompleted won't be called on "streaming" responses
     $response = $event['response'];
     $request_url = $event['request']->getUri();
     // proxify header location value
     if ($response->headers->has('location')) {
         $location = $response->headers->get('location');
         // just in case this is a relative url like: /en
         $response->headers->set('location', proxify_url($location, $request_url));
     }
     $code = $response->getStatusCode();
     $text = $response->getStatusText();
     if ($code >= 400 && $code <= 600) {
         throw new \Exception("Error accessing resource: {$code} - {$text}");
     }
     // we need content-encoding (in case server refuses to serve it in plain text)
     $forward_headers = array('content-type', 'content-length', 'accept-ranges', 'content-range', 'content-disposition', 'location', 'set-cookie');
     foreach ($response->headers->all() as $name => $value) {
         // is this one of the headers we wish to forward back to the client?
         if (!in_array($name, $forward_headers)) {
             $response->headers->remove($name);
         }
     }
     // do not ever cache our proxy pages!
     $response->headers->set("cache-control", "no-cache, no-store, must-revalidate");
     $response->headers->set("pragma", "no-cache");
     $response->headers->set("expires", 0);
 }
Exemple #2
0
 private function form_action($matches)
 {
     // $matches[1] holds single or double quote - whichever was used by webmaster
     // $matches[2] holds form submit URL - can be empty which in that case should be replaced with current URL
     if (!$matches[2]) {
         $matches[2] = $this->base_url;
     }
     $new_action = proxify_url($matches[2], $this->base_url);
     // what is form method?
     $form_post = preg_match('@method=(["\'])post\\1@i', $matches[0]) == 1;
     // take entire form string - find real url and replace it with proxified url
     $result = str_replace($matches[2], $new_action, $matches[0]);
     // must be converted to POST otherwise GET form would just start appending name=value pairs to your proxy url
     if (!$form_post) {
         // may throw Duplicate Attribute warning but only first method matters
         $result = str_replace("<form", '<form method="POST"', $result);
         // got the idea from Glype - insert this input field to notify proxy later that this form must be converted to GET during http
         $result .= '<input type="hidden" name="convertGET" value="1">';
     }
     return $result;
 }
 private function img_sprite($matches)
 {
     return str_replace($matches[1], proxify_url($matches[1], $matches[1]), $matches[0]);
 }
Exemple #4
0
// how are our URLs be generated from this point? this must be set here so the proxify_url function below can make use of it
if (Config::get('url_mode') == 1) {
    Config::set('encryption_key', md5(Config::get('app_key') . $_SERVER['REMOTE_ADDR']));
} else {
    if (Config::get('url_mode') == 2) {
        Config::set('encryption_key', md5(Config::get('app_key') . session_id()));
    }
}
// very important!!! otherwise requests are queued while waiting for session file to be unlocked
session_write_close();
// form submit in progress...
if (isset($_POST['url'])) {
    $url = $_POST['url'];
    $url = add_http($url);
    header("HTTP/1.1 302 Found");
    header('Location: ' . proxify_url($url));
    exit;
} else {
    if (!isset($_GET['q'])) {
        // must be at homepage - should we redirect somewhere else?
        if (Config::get('index_redirect')) {
            // redirect to...
            header("HTTP/1.1 302 Found");
            header("Location: " . Config::get('index_redirect'));
        } else {
            echo render_template("./templates/main.php", array('version' => Proxy::VERSION));
        }
        exit;
    }
}
// decode q parameter to get the real URL
Exemple #5
0
function vid_player($url, $width, $height, $extension = false)
{
    $path = parse_url($url, PHP_URL_PATH);
    $html5 = false;
    if ($path) {
        $extension = $extension ? $extension : pathinfo($path, PATHINFO_EXTENSION);
        if ($extension == 'mp4' || $extension == 'webm' || $extension == 'ogg') {
            $html5 = true;
        }
    }
    // this better be an absolute url
    $video_url = proxify_url($url);
    if ($html5) {
        $html = '<video width="100%" height="100%" controls autoplay>
			<source src="' . $video_url . '" type="video/' . $extension . '">
			Your browser does not support the video tag.
		</video>';
    } else {
        // encode before embedding it into player's parameters
        $video_url = rawurlencode($video_url);
        $html = '<object id="flowplayer" width="' . $width . '" height="' . $height . '" data="//releases.flowplayer.org/swf/flowplayer-3.2.18.swf" type="application/x-shockwave-flash">
 	 
       	<param name="allowfullscreen" value="true" />
		<param name="wmode" value="transparent" />
        <param name="flashvars" value=\'config={"clip":"' . $video_url . '", "plugins": {"controls": {"autoHide" : false} }}\' />
		
		</object>';
    }
    return $html;
}