コード例 #1
0
ファイル: ProxifyPlugin.php プロジェクト: yizhl/php-proxy
 public function onCompleted(ProxyEvent $event)
 {
     // to be used when proxifying all the relative links
     $this->base_url = $event['request']->getUri();
     $response = $event['response'];
     $str = $response->getContent();
     // let's remove all frames??
     $str = preg_replace('@<iframe[^>]+>.*?<\\/iframe>@is', '', $str);
     // let's replace page titles with something custom
     if (Config::get('replace_title')) {
         $str = preg_replace('/<title[^>]*>(.*?)<\\/title>/ims', '<title>' . Config::get('replace_title') . '</title>', $str);
     }
     // css
     $str = preg_replace_callback('@:\\s*url\\s*\\((?:\'|"|)(.*?)(?:\'|"|)\\)@im', array($this, 'css_url'), $str);
     // https://developer.mozilla.org/en-US/docs/Web/CSS/@import
     // TODO: what about @import directives that are outside <style>?
     $str = preg_replace_callback('/@import (\'|")(.*?)\\1/i', array($this, 'css_import'), $str);
     // html
     $str = preg_replace_callback('@href\\s*=\\s*(["\'])(.+?)\\1@im', array($this, 'html_href'), $str);
     //$str = preg_replace_callback('@src=["|\']([^"\']+)["|\']@i', array($this, 'html_src'), $str);
     $str = preg_replace_callback('@src\\s*=\\s*(["|\'])(.+?)\\1@i', array($this, 'html_src'), $str);
     // sometimes form action is empty - which means a postback to the current page
     $str = preg_replace_callback('@<form[^>]*action=(["\'])(.*?)\\1[^>]*>@i', array($this, 'form_action'), $str);
     //$str = str_replace('document.forms[0]', 'document.forms[1]', $str);
     $response->setContent($str);
 }
コード例 #2
0
ファイル: Proxy.php プロジェクト: athlon1600/php-proxy
 public function forward(Request $request, $url)
 {
     // change request URL
     $request->setUrl($url);
     // prepare request and response objects
     $this->request = $request;
     $this->response = new Response();
     $options = array(CURLOPT_CONNECTTIMEOUT => 10, CURLOPT_TIMEOUT => 0, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_SSL_VERIFYPEER => false, CURLOPT_SSL_VERIFYHOST => false, CURLOPT_FOLLOWLOCATION => false, CURLOPT_AUTOREFERER => false);
     // this is probably a good place to add custom curl options that way other critical options below would overwrite that
     $config_options = Config::get('curl', array());
     $options = array_merge_custom($options, $config_options);
     $options[CURLOPT_HEADERFUNCTION] = array($this, 'header_callback');
     $options[CURLOPT_WRITEFUNCTION] = array($this, 'write_callback');
     // Notify any listeners that the request is ready to be sent, and this is your last chance to make any modifications.
     $this->dispatcher->dispatch('request.before_send', new ProxyEvent(array('request' => $this->request, 'response' => $this->response)));
     // We may not even need to send this request if response is already available somewhere (CachePlugin)
     if ($this->request->params->has('request.complete')) {
         // do nothing?
     } else {
         // any plugin might have changed our URL by this point
         $options[CURLOPT_URL] = $this->request->getUri();
         // fill in the rest of cURL options
         $options[CURLOPT_HTTPHEADER] = explode("\r\n", $this->request->getRawHeaders());
         $options[CURLOPT_CUSTOMREQUEST] = $this->request->getMethod();
         $options[CURLOPT_POSTFIELDS] = $this->request->getRawBody();
         $ch = curl_init();
         curl_setopt_array($ch, $options);
         // fetch the status - if exception if throw any at callbacks, then the error will be supressed
         $result = @curl_exec($ch);
         // there must have been an error if at this point
         if (!$result) {
             $error = sprintf('(%d) %s', curl_errno($ch), curl_error($ch));
             throw new \Exception($error);
         }
         // we have output waiting in the buffer?
         $this->response->setContent($this->output_buffer);
         // saves memory I would assume?
         $this->output_buffer = null;
     }
     $this->dispatcher->dispatch('request.complete', new ProxyEvent(array('request' => $this->request, 'response' => $this->response)));
     return $this->response;
 }
コード例 #3
0
ファイル: index.php プロジェクト: TylerWolfe/php-proxy-app
        // use user plugin from /plugins/
        require_once './plugins/' . $plugin_class . '.php';
    } else {
        if (class_exists('\\Proxy\\Plugin\\' . $plugin_class)) {
            // does the native plugin from php-proxy package with such name exist?
            $plugin_class = '\\Proxy\\Plugin\\' . $plugin_class;
        }
    }
    // otherwise plugin_class better be loaded already through composer.json and match namespace exactly \\Vendor\\Plugin\\SuperPlugin
    $proxy->getEventDispatcher()->addSubscriber(new $plugin_class());
}
try {
    // request sent to index.php
    $request = Request::createFromGlobals();
    // remove all GET parameters such as ?q=
    $request->get->clear();
    // forward it to some other URL
    $response = $proxy->forward($request, $url);
    // if that was a streaming response, then everything was already sent and script will be killed before it even reaches this line
    $response->send();
} catch (Exception $ex) {
    // if the site is on server2.proxy.com then you may wish to redirect it back to proxy.com
    if (Config::get("error_redirect")) {
        $url = render_string(Config::get("error_redirect"), array('error_msg' => rawurlencode($ex->getMessage())));
        // Cannot modify header information - headers already sent
        header("HTTP/1.1 302 Found");
        header("Location: {$url}");
    } else {
        echo render_template("./templates/main.php", array('url' => $url, 'error_msg' => $ex->getMessage(), 'version' => Proxy::VERSION));
    }
}
コード例 #4
0
 public function onCompleted(ProxyEvent $event)
 {
     // to be used when proxifying all the relative links
     $this->base_url = $event['request']->getUri();
     $response = $event['response'];
     $str = $response->getContent();
     $content_type = $response->headers->get('content-type');
     // DO NOT do any proxification on .js files
     if ($content_type == 'text/javascript' || $content_type == 'application/javascript' || $content_type == 'application/x-javascript') {
         return;
     }
     // let's remove all frames?? does not protect against the frames created dynamically via javascript
     $str = preg_replace('@<iframe[^>]*>[^<]*<\\/iframe>@is', '', $str);
     // let's replace page titles with something custom
     if (Config::get('replace_title')) {
         $str = preg_replace('/<title[^>]*>(.*?)<\\/title>/ims', '<title>' . Config::get('replace_title') . '</title>', $str);
     }
     /* css
     		if {1} is not there then youtube breaks for some reason
     		*/
     $str = preg_replace_callback('@[^a-z]{1}url\\s*\\((?:\'|"|)(.*?)(?:\'|"|)\\)@im', array($this, 'css_url'), $str);
     // https://developer.mozilla.org/en-US/docs/Web/CSS/@import
     // TODO: what about @import directives that are outside <style>?
     $str = preg_replace_callback('/@import (\'|")(.*?)\\1/i', array($this, 'css_import'), $str);
     // html .*? just in case href is empty...
     $str = preg_replace_callback('@href\\s*=\\s*(["\'])(.*?)\\1@im', array($this, 'html_href'), $str);
     /*
     src= can be empty - then what?
     */
     $str = preg_replace_callback('@src\\s*=\\s*(["|\'])(.*?)\\1@i', array($this, 'html_src'), $str);
     // sometimes form action is empty - which means a postback to the current page
     $str = preg_replace_callback('@<form[^>]*action=(["\'])(.*?)\\1[^>]*>@i', array($this, 'form_action'), $str);
     //$str = str_replace('document.forms[0]', 'document.forms[1]', $str);
     $response->setContent($str);
 }
コード例 #5
0
ファイル: helpers.php プロジェクト: athlon1600/php-proxy
function url_decrypt($url, $key = false)
{
    $url = Config::get('url_mode') ? base64_url_decode($url) : rawurldecode($url);
    if ($key) {
        $url = str_rot_pass($url, $key, true);
    } else {
        if (Config::get('encryption_key')) {
            $url = str_rot_pass($url, Config::get('encryption_key'), true);
        }
    }
    return $url;
}
コード例 #6
0
ファイル: helpers.php プロジェクト: yizhl/php-proxy
function base64_decrypt($data, $key = false)
{
    $data = base64_url_decode($data);
    if ($key) {
        $data = str_rot_pass($data, $key, true);
    } else {
        if (Config::get('encryption_key')) {
            $data = str_rot_pass($data, Config::get('encryption_key'), true);
        }
    }
    return $data;
}