Ejemplo n.º 1
1
 /**
  * @param string $api_key
  */
 function __construct($key, $secret)
 {
     self::$key = $key;
     self::$secret = $secret;
     // Add the version to all HTTP Requests
     Request::addHeader('User-Agent', "Razorpay-PHP/" . self::VERSION);
 }
Ejemplo n.º 2
1
    public function testToStringFormatsTheRequest()
    {
        $request = new Request('POST', '/resource/123', 'http://example.com');
        $request->setProtocolVersion(1.1);
        $request->addHeader('Content-Type: application/x-www-form-urlencoded');
        $request->setContent('foo=bar&bar=baz');
        $expected = <<<EOF
POST /resource/123 HTTP/1.1
Host: http://example.com
Content-Type: application/x-www-form-urlencoded

foo=bar&bar=baz

EOF;
        $this->assertEquals((string) $request, $expected);
    }
Ejemplo n.º 3
1
 private function setRequest()
 {
     $url = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
     $request = new Request($url, $_SERVER['REQUEST_METHOD']);
     if (isset($_SERVER['HTTP_REFERRER'])) {
         $request->setReferrer($_SERVER['HTTP_REFERRER']);
     }
     $this->ip = $_SERVER['REMOTE_ADDR'];
     //	$request->set ( $_SERVER ['REMOTE_ADDR'] );
     $request->setBody(file_get_contents("php://input"));
     if ($request->getMethod() !== 'POST') {
         parse_str($request->getBody(), $post_vars);
         $request->setPost($post_vars);
     } else {
         $request->setPost($_POST);
     }
     foreach (getallheaders() as $k => $v) {
         $request->addHeader($k, $v);
     }
     $this->request = $request;
 }
Ejemplo n.º 4
1
 /**
  * draw
  *
  * Try draw output layout
  *
  * @return null
  */
 public static function draw()
 {
     $renderTries = 2;
     while ($renderTries--) {
         try {
             ob_start();
             // txt context
             if (self::$_outputContext == 'txt') {
                 Request::addHeader('Content-Type: text/plain');
                 $raw = TextPlainOutput::getContent(self::$_data);
                 // json context
             } else {
                 if (self::$_outputContext == 'json') {
                     Request::addHeader('Content-Type: application/json');
                     $raw = json_encode(self::$_data ? self::$_data : new StdClass());
                     // xml context
                 } else {
                     if (self::$_outputContext == 'xml') {
                         Request::addHeader('Content-Type: application/xml');
                         $raw = XmlOutput::getContent(self::$_data, self::$_XSDSchema, self::$_docType);
                         // html context error
                     } else {
                         if (!self::$_layout) {
                             throw new SystemErrorException(array('title' => 'View error', 'description' => 'Layout is not set'));
                             // html context
                         } else {
                             Request::addHeader('Content-Type: text/html; charset=utf-8');
                             self::_normalizeHtmlContext();
                             extract(self::$_protectedData);
                             extract(self::$_data);
                         }
                     }
                 }
             }
             // set non-html context raw layout
             if (self::$_outputContext != 'html') {
                 self::$_layout = 'raw.phtml';
             }
             require self::$_layout;
         } catch (Exception $e) {
             ob_clean();
             self::assignException($e);
             continue;
         }
         $layoutContent = ob_get_clean();
         break;
     }
     if (!isset($layoutContent) && isset($e)) {
         UnexpectedException::take($e, true);
     }
     Request::sendHeaders();
     echo $layoutContent;
 }
Ejemplo n.º 5
1
 /** 
  * @param Request $request
  */
 protected function updateHeaders($request)
 {
     $content = $request->getContent();
     $contentLength = strlen($content);
     $request->addHeader('Content-Length: ' . $contentLength);
     $request->addHeader('Content-Type: application/xml;charset=UTF-8');
 }
Ejemplo n.º 6
1
 function setHeader($header, $value)
 {
     Request::addHeader($header, $value);
 }
Ejemplo n.º 7
1
 /**
  * @param  string
  * @param  string
  * @param  array
  * @param  mixed|NULL
  * @return Request
  */
 protected function createRequest($method, $url, array $headers, $body = NULL)
 {
     if ($this->baseUrl !== NULL) {
         $url = Helpers::absolutizeUrl($this->baseUrl, $url);
     }
     $request = new Request($method, $url, $headers, $body, $this->getCoder());
     foreach ($this->defaultHeaders as $name => $value) {
         $request->addHeader($name, $value);
     }
     return $request;
 }
Ejemplo n.º 8
1
 /**
  * Apply cookies for request
  * @param Request $req
  */
 public function applyCookie($req)
 {
     // fetch cookies
     $host = $req->getHeader('host');
     $path = $req->getUrlParam('path');
     $cookies = $this->fetchCookieToSend($host, $path);
     if ($this !== $req) {
         $cookies = array_merge($cookies, $req->fetchCookieToSend($host, $path));
     }
     // add to header
     $req->setHeader('cookie', null);
     foreach (array_chunk(array_values($cookies), 3) as $chunk) {
         $req->addHeader('cookie', implode('; ', $chunk));
     }
 }
Ejemplo n.º 9
1
 public function authorizeClient($clientId, $clientSecret, $scope)
 {
     $query = array('client_id' => $clientId, 'scope' => $scope, 'grant_type' => 'client_credentials');
     $request = new Request(Request::METHOD_POST, '/token/');
     $request->addHeader('Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret));
     $request->setContent(http_build_query($query));
     return $this->send($request, null, false);
 }
Ejemplo n.º 10
1
 public function createRequest($url, $method = 'GET')
 {
     $request = new Request($url, $method);
     $request->addHeader('User-Agent', $this->getAgent());
     return $request;
 }
Ejemplo n.º 11
1
 /**
  * indexAction
  *
  * generate image and stored keystring into storage
  *
  * @return null
  */
 public function indexAction()
 {
     if ($this->_length === 'random') {
         $this->_length = mt_rand(5, 8);
     }
     $keyString = '';
     $fontsPath = APPLICATION . 'resources/protection-image/*.png';
     if (!($fonts = \FsUtils::glob($fontsPath))) {
         throw new \SystemErrorException(array('title' => 'Protection image error', 'description' => 'Fonts in resources not found'));
     }
     $alphabet = '0123456789abcdefghijklmnopqrstuvwxyz';
     $alphabetLength = strlen($alphabet);
     $allowedSymbols = '23456789abcdeghkmnpqsuvxyz';
     if ($this->_foregroundColor === 'random') {
         $this->_foregroundColor = array(mt_rand(0, 150), mt_rand(0, 150), mt_rand(0, 15));
     }
     do {
         $asLen = strlen($allowedSymbols) - 1;
         for ($i = 0; $i < $this->_length; $i++) {
             $keyString .= $allowedSymbols[mt_rand(0, $asLen)];
         }
         $font = imagecreatefrompng($fonts[mt_rand(0, sizeof($fonts) - 1)]);
         imagealphablending($font, true);
         $fFileWidth = imagesx($font);
         $fFileHeight = imagesy($font) - 1;
         $fontMetrics = array();
         $symbol = 0;
         $readingSymbol = false;
         for ($i = 0; $i < $fFileWidth && $symbol < $alphabetLength; $i++) {
             $transparent = imagecolorat($font, $i, 0) >> 24 == 127;
             if (!$readingSymbol && !$transparent) {
                 $fontMetrics[$alphabet[$symbol]] = array('start' => $i);
                 $readingSymbol = true;
                 continue;
             }
             if ($readingSymbol && $transparent) {
                 $fontMetrics[$alphabet[$symbol]]['end'] = $i;
                 $readingSymbol = false;
                 $symbol++;
                 continue;
             }
         }
         $img = imagecreatetruecolor($this->_width, $this->_height);
         imagealphablending($img, true);
         $white = imagecolorallocate($img, 255, 255, 255);
         $black = imagecolorallocate($img, 0, 0, 0);
         imagefilledrectangle($img, 0, 0, $this->_width - 1, $this->_height - 1, $white);
         $x = 1;
         for ($i = 0; $i < $this->_length; $i++) {
             $m = $fontMetrics[$keyString[$i]];
             $y = mt_rand(-$this->_fluctuationAmplitude, $this->_fluctuationAmplitude) + ($this->_height - $fFileHeight) / 2 + 2;
             $shift = 0;
             if ($i > 0) {
                 $shift = 10000;
                 for ($sy = 7; $sy < $fFileHeight - 20; $sy += 1) {
                     for ($sx = $m['start'] - 1; $sx < $m['end']; $sx += 1) {
                         $rgb = imagecolorat($font, $sx, $sy);
                         $opacity = $rgb >> 24;
                         if ($opacity < 127) {
                             $left = $sx - $m['start'] + $x;
                             $py = $sy + $y;
                             if ($py > $this->_height) {
                                 break;
                             }
                             for ($px = min($left, $this->_width - 1); $px > $left - 12 && $px >= 0; $px -= 1) {
                                 $color = imagecolorat($img, $px, $py) & 0xff;
                                 if ($color + $opacity < 190) {
                                     if ($shift > $left - $px) {
                                         $shift = $left - $px;
                                     }
                                     break;
                                 }
                             }
                             break;
                         }
                     }
                 }
                 if ($shift == 10000) {
                     $shift = mt_rand(4, 6);
                 }
             }
             imagecopy($img, $font, $x - $shift, $y, $m['start'], 1, $m['end'] - $m['start'], $fFileHeight);
             $x += $m['end'] - $m['start'] - $shift;
         }
     } while ($x >= $this->_width - 10);
     $center = $x / 2;
     $img2 = imagecreatetruecolor($this->_width, $this->_height);
     $foreground = imagecolorallocate($img2, $this->_foregroundColor[0], $this->_foregroundColor[1], $this->_foregroundColor[2]);
     $background = imagecolorallocate($img2, $this->_backgroundColor[0], $this->_backgroundColor[1], $this->_backgroundColor[2]);
     imagefilledrectangle($img2, 0, 0, $this->_width - 1, $this->_height - 1, $background);
     imagestring($img2, 2, $this->_width - 2, $this->_height - 2, 0, $background);
     // periods
     $rand1 = mt_rand(750000, 1200000) / 10000000;
     $rand2 = mt_rand(750000, 1200000) / 10000000;
     $rand3 = mt_rand(750000, 1200000) / 10000000;
     $rand4 = mt_rand(750000, 1200000) / 10000000;
     // phases
     $rand5 = mt_rand(0, 31415926) / 10000000;
     $rand6 = mt_rand(0, 31415926) / 10000000;
     $rand7 = mt_rand(0, 31415926) / 10000000;
     $rand8 = mt_rand(0, 31415926) / 10000000;
     // amplitudes
     $rand9 = mt_rand(330, 420) / 110;
     $rand10 = mt_rand(330, 450) / 110;
     // wave distortion
     for ($x = 0; $x < $this->_width; $x++) {
         for ($y = 0; $y < $this->_height; $y++) {
             $sx = $x + (sin($x * $rand1 + $rand5) + sin($y * $rand3 + $rand6)) * $rand9 - $this->_width / 2 + $center + 1;
             $sy = $y + (sin($x * $rand2 + $rand7) + sin($y * $rand4 + $rand8)) * $rand10;
             if ($sx < 0 || $sy < 0 || $sx >= $this->_width - 1 || $sy >= $this->_height - 1) {
                 continue;
             } else {
                 $color = imagecolorat($img, $sx, $sy) & 0xff;
                 $color_x = imagecolorat($img, $sx + 1, $sy) & 0xff;
                 $color_y = imagecolorat($img, $sx, $sy + 1) & 0xff;
                 $color_xy = imagecolorat($img, $sx + 1, $sy + 1) & 0xff;
             }
             if ($color == 255 && $color_x == 255 && $color_y == 255 && $color_xy == 255) {
                 continue;
             } else {
                 if ($color == 0 && $color_x == 0 && $color_y == 0 && $color_xy == 0) {
                     $newred = $this->_foregroundColor[0];
                     $newgreen = $this->_foregroundColor[1];
                     $newblue = $this->_foregroundColor[2];
                 } else {
                     $frsx = $sx - floor($sx);
                     $frsy = $sy - floor($sy);
                     $frsx1 = 1 - $frsx;
                     $frsy1 = 1 - $frsy;
                     $newcolor = $color * $frsx1 * $frsy1 + $color_x * $frsx * $frsy1 + $color_y * $frsx1 * $frsy + $color_xy * $frsx * $frsy;
                     if ($newcolor > 255) {
                         $newcolor = 255;
                     }
                     $newcolor = $newcolor / 255;
                     $newcolor0 = 1 - $newcolor;
                     $newred = $newcolor0 * $this->_foregroundColor[0] + $newcolor * 255;
                     $newgreen = $newcolor0 * $this->_foregroundColor[1] + $newcolor * 255;
                     $newblue = $newcolor0 * $this->_foregroundColor[2] + $newcolor * 255;
                 }
             }
             imagesetpixel($img2, $x, $y, imagecolorallocate($img2, $newred, $newgreen, $newblue));
         }
     }
     imagedestroy($img);
     $action = preg_replace('/[^a-z-]+/', '', \Request::getParam('action'));
     $action = 'protection-code' . ($action ? '-' . $action : '');
     \Storage::write($action, $keyString);
     \Request::addHeader('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
     \Request::addHeader('Cache-Control: no-store, no-cache, must-revalidate');
     \Request::addHeader('Cache-Control: post-check=0, pre-check=0');
     \Request::addHeader('Pragma: no-cache');
     \Request::addHeader('Content-Type: image/jpeg');
     \Request::sendHeaders();
     imagejpeg($img2, null, $this->_jpegQuality);
     exit;
 }