当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpFoundation\IpUtils类代码示例

本文整理汇总了PHP中Symfony\Component\HttpFoundation\IpUtils的典型用法代码示例。如果您正苦于以下问题:PHP IpUtils类的具体用法?PHP IpUtils怎么用?PHP IpUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IpUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAnIpv6WithOptionDisabledIpv6

 /**
  * @expectedException \RuntimeException
  * @requires extension sockets
  */
 public function testAnIpv6WithOptionDisabledIpv6()
 {
     if (defined('AF_INET6')) {
         $this->markTestSkipped('Only works when PHP is compiled with the option "disable-ipv6".');
     }
     IpUtils::checkIp('2a01:198:603:0:396e:4789:8e99:890f', '2a01:198:603:0::/65');
 }
开发者ID:qasem2rubik,项目名称:laravel,代码行数:11,代码来源:IpUtilsTest.php

示例2: indexAction

 /**
  * @Route("/", name = "index")
  * @Template()
  */
 public function indexAction()
 {
     try {
         // Redirect admin and local users to secure area
         // TODO: Make the local network rule configurable (turned off by default)
         if (true === $this->get('security.context')->isGranted('ROLE_ADMIN') || true === IpUtils::checkIp($this->getRequest()->getClientIp(), '192.168.0.0/16') || $this->getRequest()->getClientIp() === '127.0.0.1') {
             return $this->redirect($this->generateUrl('admin_index'));
         }
     } catch (\Exception $e) {
     }
     return array();
 }
开发者ID:jca,项目名称:AlbumBundle,代码行数:16,代码来源:DefaultController.php

示例3: validateRequest

 protected function validateRequest(Request $request)
 {
     // is the Request safe?
     if (!$request->isMethodSafe()) {
         throw new AccessDeniedHttpException();
     }
     // does the Request come from a trusted IP?
     $trustedIps = array_merge($this->getLocalIpAddresses(), $request->getTrustedProxies());
     $remoteAddress = $request->server->get('REMOTE_ADDR');
     if (IpUtils::checkIp($remoteAddress, $trustedIps)) {
         return;
     }
     // is the Request signed?
     // we cannot use $request->getUri() here as we want to work with the original URI (no query string reordering)
     if ($this->signer->check($request->getSchemeAndHttpHost() . $request->getBaseUrl() . $request->getPathInfo() . (null !== ($qs = $request->server->get('QUERY_STRING')) ? '?' . $qs : ''))) {
         return;
     }
     throw new AccessDeniedHttpException();
 }
开发者ID:TuxCoffeeCorner,项目名称:tcc,代码行数:19,代码来源:FragmentListener.php

示例4: postReceiveAction

 /**
  * @Route("/_api/post-receive")
  * @param Request $request
  * @return JsonResponse
  * @Method("POST")
  */
 public function postReceiveAction(Request $request)
 {
     $this->path = $this->getParameter('amp_deploy.log_path');
     if (!file_exists($this->path)) {
         mkdir($this->path);
     }
     $this->logPath = $this->path . 'amp_deploy.log';
     $now = new \DateTime();
     $this->log('Push received at: ' . $now->format('d.m.Y H:i:s'));
     // get expected ip range from github
     $http = new Client();
     $resp = $http->get('https://api.github.com/meta');
     $data = json_decode($resp->getBody());
     // is IP in range?
     if (!IpUtils::checkIp($request->getClientIp(), $data->hooks)) {
         $this->log('ERROR: Invalid source IP: ' . $request->getClientIp());
         return new JsonResponse(['error' => 'Invalid source IP: ' . $request->getClientIp()], 403);
     }
     // check sha1 secret
     $sig = 'sha1=' . hash_hmac('sha1', $request->getContent(), $this->getParameter('amp_deploy.github_secret'));
     if ($sig != $request->headers->get('X-Hub-Signature')) {
         $this->log('Invalid hash: ' . $sig . PHP_EOL);
         return new JsonResponse(['error' => 'Invalid hash: ' . $sig], 403);
     }
     try {
         // Decode the payload json string
         $payload = json_decode($request->get('payload'));
     } catch (\Exception $e) {
         $this->log('ERROR: ' . $e->__toString());
         return new JsonResponse(['error' => 'Malformed json'], 400);
     }
     // Pushed to master?
     $log = ['Author' => $payload->head_commit->author, 'Commit_message' => $payload->head_commit->message, 'Timestamp' => $payload->head_commit->timestamp];
     if ($payload->ref === 'refs/heads/master') {
         $log['status'] = 'Master push detected, deploying';
         // Run the deploy script
         shell_exec($this->getParameter('amp_deploy.deploy_script') . ' > ' . $this->logPath . ' 2>&1 &');
     } else {
         $log['status'] = 'Not master branch push';
     }
     $this->log($log);
     return new JsonResponse($log, 200);
 }
开发者ID:Ampisoft,项目名称:DeployBundle,代码行数:49,代码来源:GitHubController.php

示例5: isFromTrustedProxy

 private function isFromTrustedProxy()
 {
     return self::$trustedProxies && IpUtils::checkIp($this->server->get('REMOTE_ADDR'), self::$trustedProxies);
 }
开发者ID:mesushan,项目名称:FirstRepo,代码行数:4,代码来源:Request.php

示例6: getClientIps

 /**
  * Returns the client IP addresses.
  *
  * In the returned array the most trusted IP address is first, and the
  * least trusted one last. The "real" client IP address is the last one,
  * but this is also the least trusted one. Trusted proxies are stripped.
  *
  * Use this method carefully; you should use getClientIp() instead.
  *
  * @return array The client IP addresses
  *
  * @see getClientIp()
  */
 public function getClientIps()
 {
     $ip = $this->server->get('REMOTE_ADDR');
     if (!self::$trustedProxies) {
         return array($ip);
     }
     if (!self::$trustedHeaders[self::HEADER_CLIENT_IP] || !$this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
         return array($ip);
     }
     $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
     $clientIps[] = $ip;
     // Complete the IP chain with the IP the request actually came from
     $ip = $clientIps[0];
     // Fallback to this when the client IP falls into the range of trusted proxies
     // Eliminate all IPs from the forwarded IP chain which are trusted proxies
     foreach ($clientIps as $key => $clientIp) {
         // Remove port on IPv4 address (unfortunately, it does happen)
         if (preg_match('{((?:\\d+\\.){3}\\d+)\\:\\d+}', $clientIp, $match)) {
             $clientIps[$key] = $clientIp = $match[1];
         }
         if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
             unset($clientIps[$key]);
         }
     }
     // Now the IP chain contains only untrusted proxies and the client IP
     return $clientIps ? array_reverse($clientIps) : array($ip);
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:40,代码来源:Request.php

示例7: normalizeAndFilterClientIps

 private function normalizeAndFilterClientIps(array $clientIps, $ip)
 {
     $clientIps[] = $ip;
     // Complete the IP chain with the IP the request actually came from
     $firstTrustedIp = null;
     foreach ($clientIps as $key => $clientIp) {
         // Remove port (unfortunately, it does happen)
         if (preg_match('{((?:\\d+\\.){3}\\d+)\\:\\d+}', $clientIp, $match)) {
             $clientIps[$key] = $clientIp = $match[1];
         }
         if (!filter_var($clientIp, FILTER_VALIDATE_IP)) {
             unset($clientIps[$key]);
             continue;
         }
         if (IpUtils::checkIp($clientIp, self::$trustedProxies)) {
             unset($clientIps[$key]);
             // Fallback to this when the client IP falls into the range of trusted proxies
             if (null === $firstTrustedIp) {
                 $firstTrustedIp = $clientIp;
             }
         }
     }
     // Now the IP chain contains only untrusted proxies and the client IP
     return $clientIps ? array_reverse($clientIps) : array($firstTrustedIp);
 }
开发者ID:timpressive,项目名称:art-auction,代码行数:25,代码来源:Request.php

示例8: getClientIps

 /**
  * Returns the client IP addresses.
  *
  * In the returned array the most trusted IP address is first, and the
  * least trusted one last. The "real" client IP address is the last one,
  * but this is also the least trusted one. Trusted proxies are stripped.
  *
  * Use this method carefully; you should use getClientIp() instead.
  *
  * @return array The client IP addresses
  *
  * @see getClientIp()
  */
 public function getClientIps()
 {
     $ip = $this->server->get('REMOTE_ADDR');
     if (!self::$trustedProxies) {
         return array($ip);
     }
     if (!self::$trustedHeaders[self::HEADER_CLIENT_IP] || !$this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
         return array($ip);
     }
     $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
     $clientIps[] = $ip;
     // Complete the IP chain with the IP the request actually came from
     $trustedProxies = !self::$trustedProxies ? array($ip) : self::$trustedProxies;
     $ip = $clientIps[0];
     // Fallback to this when the client IP falls into the range of trusted proxies
     // Eliminate all IPs from the forwarded IP chain which are trusted proxies
     foreach ($clientIps as $key => $clientIp) {
         if (IpUtils::checkIp($clientIp, $trustedProxies)) {
             unset($clientIps[$key]);
         }
     }
     // Now the IP chain contains only untrusted proxies and the client IP
     return $clientIps ? array_reverse($clientIps) : array($ip);
 }
开发者ID:farhan4648gul,项目名称:hercules-cp-laravel,代码行数:37,代码来源:Request.php

示例9: AppKernel

use Symfony\Component\HttpFoundation\Request;
use LoginCidadao\CoreBundle\Security\Compatibility\RamseyUuidFeatureSet;
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
$loader = (require_once __DIR__ . '/../app/bootstrap.php.cache');
Debug::enable();
require_once __DIR__ . '/../app/AppKernel.php';
$kernel = new AppKernel('dev', true);
$uuidFactory = new \Ramsey\Uuid\UuidFactory(new RamseyUuidFeatureSet());
\Ramsey\Uuid\Uuid::setFactory($uuidFactory);
$generator = new \Qandidate\Stack\UuidRequestIdGenerator();
$stack = new \Qandidate\Stack\RequestId($kernel, $generator);
$kernel->loadClassCache();
try {
    $path = implode(DIRECTORY_SEPARATOR, array($kernel->getRootDir(), 'config', 'parameters.yml'));
    $params = Yaml::parse(file_get_contents($path));
    Request::setTrustedProxies($params['parameters']['trusted_proxies']);
} catch (Exception $ex) {
    http_response_code(500);
    exit('Invalid configuration');
}
$request = Request::createFromGlobals();
$allowed = $params['parameters']['dev_allowed'];
if (!IpUtils::checkIp($request->getClientIp(), $allowed)) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file.');
}
$response = $stack->handle($request);
$response->send();
$kernel->terminate($request, $response);
开发者ID:redelivre,项目名称:login-cidadao,代码行数:31,代码来源:app_dev.php

示例10: header

<?php

use Symfony\Component\HttpFoundation\IpUtils;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Debug\Debug;
/**
 * @var Composer\Autoload\ClassLoader $loader
 */
$loader = (require __DIR__ . '/../app/autoload.php');
// If you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);
// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP']) || isset($_SERVER['HTTP_X_FORWARDED_FOR']) || !(IpUtils::checkIp(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1', '192.168.0.0/16')) || php_sapi_name() === 'cli-server')) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check ' . basename(__FILE__) . ' for more information.');
}
Debug::enable();
$kernel = new AppKernel('dev', true);
$kernel->loadClassCache();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
开发者ID:KinderJugendringBonn,项目名称:jugendstadtplan,代码行数:26,代码来源:app_dev.php

示例11: getClientIps

 /**
  * Returns the client IP addresses.
  *
  * The most trusted IP address is first, and the less trusted one last.
  * The "real" client IP address is the last one, but this is also the
  * less trusted one.
  *
  * Use this method carefully; you should use getClientIp() instead.
  *
  * @return array The client IP addresses
  *
  * @see getClientIp()
  */
 public function getClientIps()
 {
     $ip = $this->server->get('REMOTE_ADDR');
     if (!self::$trustedProxies) {
         return array($ip);
     }
     if (!self::$trustedHeaders[self::HEADER_CLIENT_IP] || !$this->headers->has(self::$trustedHeaders[self::HEADER_CLIENT_IP])) {
         return array($ip);
     }
     $clientIps = array_map('trim', explode(',', $this->headers->get(self::$trustedHeaders[self::HEADER_CLIENT_IP])));
     $clientIps[] = $ip;
     $trustedProxies = !self::$trustedProxies ? array($ip) : self::$trustedProxies;
     $ip = $clientIps[0];
     foreach ($clientIps as $key => $clientIp) {
         if (IpUtils::checkIp($clientIp, $trustedProxies)) {
             unset($clientIps[$key]);
             continue;
         }
     }
     return $clientIps ? array_reverse($clientIps) : array($ip);
 }
开发者ID:nassafou,项目名称:Filmotheque,代码行数:34,代码来源:Request.php

示例12: checkIps

 /**
  * Checks if the requested ip is valid.
  *
  * @param string       $requestedIp
  * @param string|array $ips
  * @return boolean
  */
 protected function checkIps($requestedIp, $ips)
 {
     $ips = (array) $ips;
     $valid = false;
     $i = 0;
     while ($i < count($ips) && !$valid) {
         $valid = IpUtils::checkIp($requestedIp, $ips[$i]);
         $i++;
     }
     return $valid;
 }
开发者ID:mohammad7293,项目名称:LexikMaintenanceBundle,代码行数:18,代码来源:MaintenanceListener.php

示例13: authenticateClientIp

 /**
  * @param string $clientIp
  *
  * @throws InvalidClientIpException
  */
 public function authenticateClientIp($clientIp)
 {
     if (false === IpUtils::checkIp($clientIp, self::$xsollaSubnets)) {
         throw new InvalidClientIpException(sprintf('Xsolla trusted subnets (%s) doesn\'t contain client IP address (%s). If you use reverse proxy, you should set correct client IPv4 to WebhookRequest. If you are in development environment, you can set $authenticateClientIp = false in $webhookServer->start();', implode(', ', self::$xsollaSubnets), $clientIp));
     }
 }
开发者ID:kokspflanze,项目名称:xsolla-sdk-php,代码行数:11,代码来源:WebhookAuthenticator.php

示例14: isWithinIPRange

 private function isWithinIPRange($ip, $ipRange)
 {
     if (strpos($ipRange, '-') !== false || strpos($ipRange, '*') !== false) {
         return WDLIpUtils::IPInRange($ip, $ipRange);
     }
     if (strpos($ipRange, '/') !== false) {
         return SfIpUtils::checkIp($ip, $ipRange);
     }
     return false;
 }
开发者ID:kissifrot,项目名称:CrawlTrackBundle,代码行数:10,代码来源:CrawlerTracker.php

示例15: authenticateClientIp

 /**
  * @param string $clientIp
  *
  * @throws InvalidClientIpException
  */
 public function authenticateClientIp($clientIp)
 {
     if (false === IpUtils::checkIp($clientIp, self::$xsollaSubnets)) {
         throw new InvalidClientIpException(sprintf('Client IP address (%s) not found in allowed IP addresses whitelist (%s). Please check troubleshooting section in README.md https://github.com/xsolla/xsolla-sdk-php#troubleshooting', $clientIp, implode(', ', self::$xsollaSubnets)));
     }
 }
开发者ID:apigraf,项目名称:xsolla-sdk-php,代码行数:11,代码来源:WebhookAuthenticator.php


注:本文中的Symfony\Component\HttpFoundation\IpUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。