Пример #1
0
 public function doGet()
 {
     error_log("Running the ProxyServlet.");
     global $config;
     $this->noHeaders = true;
     $context = new GadgetContext('GADGET');
     // those should be doable in one statement, but php seems to still evauluate the second ? and : pair,
     // so throws an error about undefined index on post, even though it found it in get ... odd bug
     $url = isset($_GET['url']) ? $_GET['url'] : false;
     if (!$url) {
         $url = isset($_POST['url']) ? $_POST['url'] : false;
     }
     $url = urldecode($url);
     $method = isset($_GET['httpMethod']) ? $_GET['httpMethod'] : false;
     if (!$method) {
         $method = isset($_POST['httpMethod']) ? $_POST['httpMethod'] : 'GET';
     }
     if (!$url) {
         header("HTTP/1.0 400 Bad Request", true);
         echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
     }
     $gadgetSigner = new $config['gadget_signer']();
     $proxyHandler = new ProxyHandler($context);
     if (!empty($_GET['output']) && $_GET['output'] == 'js') {
         $proxyHandler->fetchJson($url, $gadgetSigner, $method);
     } else {
         $proxyHandler->fetch($url, $gadgetSigner, $method);
     }
 }
Пример #2
0
 public function doGet()
 {
     try {
         // Make sure the HttpServlet doesn't overwrite our headers
         $this->noHeaders = true;
         $context = new GadgetContext('GADGET');
         $url = isset($_GET['url']) ? $_GET['url'] : (isset($_POST['url']) ? $_POST['url'] : false);
         $url = urldecode($url);
         if (!$url) {
             header("HTTP/1.0 400 Bad Request", true);
             echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
         }
         $proxyHandler = new ProxyHandler($context);
         $proxyHandler->fetch($url);
     } catch (Exception $e) {
         // catch all exceptions and give a 500 server error
         header("HTTP/1.0 500 Internal Server Error");
         echo "<h1>Internal server error</h1><p>" . $e->getMessage() . "</p>";
     }
 }
 public function doGet()
 {
     try {
         $this->noHeaders = true;
         $context = new GadgetContext('GADGET');
         // those should be doable in one statement, but php seems to still evauluate the second ? and : pair,
         // so throws an error about undefined index on post, even though it found it in get ... odd bug
         $url = isset($_GET['url']) ? $_GET['url'] : false;
         if (!$url) {
             $url = isset($_POST['url']) ? $_POST['url'] : false;
         }
         // $url = urldecode($url);
         $method = isset($_GET['httpMethod']) ? $_GET['httpMethod'] : false;
         if (!$method) {
             $method = isset($_POST['httpMethod']) ? $_POST['httpMethod'] : 'GET';
         }
         if (!$url) {
             header("HTTP/1.0 400 Bad Request", true);
             echo "<html><body><h1>400 - Missing url parameter</h1></body></html>";
         }
         $signingFetcherFactory = $gadgetSigner = false;
         if (!empty($_GET['authz']) || !empty($_POST['authz'])) {
             $gadgetSigner = Config::get('security_token_signer');
             $gadgetSigner = new $gadgetSigner();
             $signingFetcherFactory = new SigningFetcherFactory(Config::get("private_key_file"));
         }
         $proxyHandler = new ProxyHandler($context, $signingFetcherFactory);
         if (!empty($_GET['output']) && $_GET['output'] == 'js') {
             $proxyHandler->fetchJson($url, $gadgetSigner, $method);
         } else {
             $proxyHandler->fetch($url, $gadgetSigner, $method);
         }
     } catch (Exception $e) {
         // catch all exceptions and give a 500 server error
         header("HTTP/1.0 500 Internal Server Error");
         echo "<h1>Internal server error</h1><p>" . $e->getMessage() . "</p>";
     }
 }
Пример #4
0
 public function __construct($options)
 {
     if (isset($options['proxyBaseUri'])) {
         $this->_proxyBaseUri = $options['proxyBaseUri'];
     }
     if (!isset($options['bufferedContentTypes'])) {
         $options['bufferedContentTypes'] = array('text/html', 'text/css', 'text/javascript', 'application/javascript');
     }
     if (isset($options['anchorTarget'])) {
         $this->_anchorTarget = $options['anchorTarget'];
     }
     parent::__construct($options);
     // build base URI
     $translatedUri = $this->getTranslatedUri();
     $parsed_url = parse_url($translatedUri);
     if (!isset($parsed_url['scheme'])) {
         $parsed_url['scheme'] = 'http';
     }
     $path = isset($parsed_url['path']) ? $parsed_url['path'] : '/';
     $this->_baseUri = self::unparse_url_base($parsed_url) . $path;
 }
Пример #5
0
</center>
</body>
</html>
<?php 
    // You've probably seen this in other servers ;)
    echo str_repeat("<!-- a padding to disable MSIE and Chrome friendly error page -->\n", 6);
    exit;
}
if (!@(include __DIR__ . '/../ProxyHandler.class.php')) {
    sendBadGateWay('Could not load proxy');
}
/* EXPECTED RESPONSE:
{
   "object_or_array": "object",
   "empty": false,
   "parse_time_nanoseconds": <int>,
   "validate": true,
   "size": 1
}
*/
$proxy = new ProxyHandler(array('proxyUri' => 'http://validate.jsontest.com', 'requestMethod' => 'POST', 'data' => 'json=' . json_encode(array('some_key' => 'some_value'))));
// Prevents cURL from hanging on errors
$proxy->setCurlOption(CURLOPT_CONNECTTIMEOUT, 1);
$proxy->setCurlOption(CURLOPT_TIMEOUT, 5);
// Check for a success
if ($proxy->execute()) {
    //print_r($proxy->getCurlInfo()); // Uncomment to see request info
} else {
    sendBadGateWay($proxy->getCurlError());
}
$proxy->close();
Пример #6
0
 public function setClientHeader($headerName, $value)
 {
     if (substr($headerName, 0, 3) !== 'Cf-') {
         parent::setClientHeader($headerName, $value);
     }
 }
Пример #7
0
<?php

if (!@(include __DIR__ . '/../ProxyHandler.class.php')) {
    die('Could not load proxy');
}
$proxy = new ProxyHandler('http://internal.example.org');
// Check for a success
if ($proxy->execute()) {
    //print_r($proxy->getCurlInfo()); // Uncomment to see request info
} else {
    echo $proxy->getCurlError();
}
$proxy->close();
Пример #8
0
<?php

if (!@(include __DIR__ . '/../ProxyHandler.class.php')) {
    die('Could not load proxy');
}
$proxy = new ProxyHandler('https://raw.github.com/chricke/php5rp_ng/master/README.md');
// Prevents cURL from hanging on errors
$proxy->setCurlOption(CURLOPT_CONNECTTIMEOUT, 1);
$proxy->setCurlOption(CURLOPT_TIMEOUT, 5);
// This ignores HTTPS certificate verification, libcurl decided not to bundle ca certs anymore.
// Alternatively, specify CURLOPT_CAINFO, or CURLOPT_CAPATH if you have access to your cert(s)
$proxy->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
// Check for a success
if ($proxy->execute()) {
    //print_r($proxy->getCurlInfo()); // Uncomment to see request info
} else {
    echo $proxy->getCurlError();
}
$proxy->close();
Пример #9
0
<?php

/**
 * User: dbroqua
 * Date: 01/01/16
 * Time: 14:47
 */
require_once "./libs/libs.php";
require_once "./libs/ProxyHandler.class.php";
$str = file_get_contents('./conf.json');
$json = json_decode($str, true);
if (isset($_GET['camId'])) {
    $proxy = new ProxyHandler(array('proxyUri' => $json[$_GET['camId']]['scheme'] . $json[$_GET['camId']]['login'] . ':' . $json[$_GET['camId']]['password'] . '@' . $json[$_GET['camId']]['host'] . ':' . $json[$_GET['camId']]['port'] . '/cam/', 'requestUri' => ''));
    // Check for a success
    if ($proxy->execute()) {
        print_r($proxy->getCurlInfo());
        // Uncomment to see request info
    } else {
        echo $proxy->getCurlError();
    }
    $proxy->close();
}