2017 © Pedro Peláez
 

symfony-bundle front-controller-security-bundle

Allows for easy ip based security for front controllers in Symfony2

image

michaelesmith/front-controller-security-bundle

Allows for easy ip based security for front controllers in Symfony2

  • Wednesday, December 11, 2013
  • by michaelesmith
  • Repository
  • 1 Watchers
  • 0 Stars
  • 111 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 2 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

FrontControllerSecurityBundle

What is FrontControllerSecurityBundle?

It provides a simple way to secure probably a development front controller on a production machine to a specific set of ip addresses., (*2)

Installation

The recommended way to install the FrontControllerSecurityBundle is through composer., (*3)

If you don't have Composer yet, download it following the instructions on http://getcomposer.org/ or just run the following command:, (*4)

curl -s http://getcomposer.org/installer | php

Just create a composer.json file for your project:, (*5)

``` json { "require": { "michaelesmith/front-controller-security-bundle": "dev-master" } }, (*6)


For more info on composer see https://github.com/composer/composer If you want to be able to use the provided cli tasks to view, add and remove ips you need to enable the bundle in your AppKernel.php ``` php if ('dev' == $this->getEnvironment()) { $bundles[] = new MS\Bundle\FrontControllerSecurityBundle\MSFrontControllerSecurityBundle(); } ```` Usage --------------- ### Configure directly in your front controller ``` php //web/app_dev.php $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; $security = new \MS\Bundle\FrontControllerSecurityBundle\Security\IPChecker(); $security->addIP('127.0.0.1', null, 'loopback'); $security->addIPRange('10.0.0.1', '10.0.0.255', null, 'remote office'); if(isset($_SERVER['HTTP_CLIENT_IP']) || isset($_SERVER['HTTP_X_FORWARDED_FOR']) || !$security->isAuthorized(@$_SERVER['REMOTE_ADDR'])){ header('HTTP/1.0 403 Forbidden'); exit(sprintf('You are not allowed to access this file. Maybe you are looking for <a href="%1$s">%1$s</a>. Check %2$s for more information.', 'http://' . $_SERVER['HTTP_HOST'], basename(__FILE__))); } require_once __DIR__.'/../app/AppKernel.php'; $kernel = new AppKernel('dev', true); $kernel->loadClassCache(); $request = Request::createFromGlobals(); $response = $kernel->handle($request); $response->send(); $kernel->terminate($request, $response);

Configure using a file

``` php //web/app_dev.php, (*7)

$loader = require_once __DIR__.'/../app/bootstrap.php.cache';

$security = new \MS\Bundle\FrontControllerSecurityBundle\Security\IPChecker();
$security->addIP('127.0.0.1', null, 'loopback');
$security->addFile(__DIR__ . '/.app_dev.security.json');

if(isset($_SERVER['HTTP_CLIENT_IP']) || isset($_SERVER['HTTP_X_FORWARDED_FOR']) || !$security->isAuthorized(@$_SERVER['REMOTE_ADDR'])){
    header('HTTP/1.0 403 Forbidden');
    exit(sprintf('You are not allowed to access this file. Maybe you are looking for <a href="%1$s">%1$s</a>. Check %2$s for more information.', 'http://' . $_SERVER['HTTP_HOST'], basename(__FILE__)));
}

...

You can add this file to your version control if you want everyone to share the same or ignore it and configure what you want on the server. This bundle includes some command tasks to help in this respect: * front-controller:security:ip:list * front-controller:security:ip:add * front-controller:security:ip:remove ### Configure using APC caching ``` php //web/app_dev.php $loader = require_once __DIR__.'/../app/bootstrap.php.cache'; if(!function_exists('apc_fetch') || !($security = apc_fetch('ms.app_dev.security'))){ $security = new \MS\Bundle\FrontControllerSecurityBundle\Security\IPChecker(); $security->addIP('127.0.0.1', null, 'loopback'); $security->addFile(__DIR__ . '/.app_dev.security.json'); if(function_exists('apc_store')){ apc_store('ms.app_dev.security', $security); } } if(isset($_SERVER['HTTP_CLIENT_IP']) || isset($_SERVER['HTTP_X_FORWARDED_FOR']) || !$security->isAuthorized(@$_SERVER['REMOTE_ADDR'])){ header('HTTP/1.0 403 Forbidden'); exit(sprintf('You are not allowed to access this file. Maybe you are looking for <a href="%1$s">%1$s</a>. Check %2$s for more information.', 'http://' . $_SERVER['HTTP_HOST'], basename(__FILE__))); } ...

The Versions

11/12 2013

dev-master

9999999-dev http://michaelsmithonline.blogspot.com/p/front-controller-security-bundle.html

Allows for easy ip based security for front controllers in Symfony2

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

security front controller