forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update front controllers with better logic and support for environmen…
…t specific middlewares
- Loading branch information
1 parent
2a9390a
commit 2a8923f
Showing
10 changed files
with
244 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
/** | ||
* @package Mautic | ||
* @copyright 2016 Mautic Contributors. All rights reserved. | ||
* @author Mautic | ||
* @link http://mautic.org | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\Middleware\Dev; | ||
|
||
use Mautic\Middleware\PrioritizedMiddlewareInterface; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class IpRestrictMiddleware implements HttpKernelInterface, PrioritizedMiddlewareInterface | ||
{ | ||
const PRIORITY = 20; | ||
|
||
/** | ||
* @var HttpKernelInterface | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $allowedIps; | ||
|
||
/** | ||
* CatchExceptionMiddleware constructor. | ||
* | ||
* @param HttpKernelInterface $app | ||
*/ | ||
public function __construct(HttpKernelInterface $app) | ||
{ | ||
$this->app = $app; | ||
$this->allowedIps = ['127.0.0.1', 'fe80::1', '::1']; | ||
|
||
if (isset($_SERVER['MAUTIC_DEV_HOSTS'])) { | ||
$localIps = explode(' ', $_SERVER['MAUTIC_DEV_HOSTS']); | ||
$this->allowedIps = array_merge($this->allowedIps, $localIps); | ||
} | ||
} | ||
|
||
/** | ||
* This check prevents access to debug front controllers | ||
* that are deployed by accident to production servers. | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) | ||
{ | ||
if (in_array($request->getClientIp(), $this->allowedIps)) { | ||
return $this->app->handle($request, $type, $catch); | ||
} | ||
|
||
return new Response('You are not allowed to access this file.', 403); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getPriority() | ||
{ | ||
return self::PRIORITY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
/** | ||
* @package Mautic | ||
* @copyright 2016 Mautic Contributors. All rights reserved. | ||
* @author Mautic | ||
* @link http://mautic.org | ||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html | ||
*/ | ||
|
||
namespace Mautic\Middleware; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
|
||
class VersionCheckMiddleware implements HttpKernelInterface, PrioritizedMiddlewareInterface | ||
{ | ||
const PRIORITY = 10; | ||
|
||
const MAUTIC_MINIMUM_PHP = '5.6.19'; | ||
const MAUTIC_MAXIMUM_PHP = '7.0.999'; | ||
|
||
/** | ||
* @var HttpKernelInterface | ||
*/ | ||
protected $app; | ||
|
||
/** | ||
* CatchExceptionMiddleware constructor. | ||
* | ||
* @param HttpKernelInterface $app | ||
*/ | ||
public function __construct(HttpKernelInterface $app) | ||
{ | ||
$this->app = $app; | ||
} | ||
|
||
/** | ||
* Check Minimum / Maximum PHP versions | ||
* | ||
* {@inheritdoc} | ||
*/ | ||
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) | ||
{ | ||
// Are we running the minimum version? | ||
if (version_compare(PHP_VERSION, self::MAUTIC_MINIMUM_PHP, 'lt')) { | ||
return new Response('Your server does not meet the minimum PHP requirements. Mautic requires PHP version '.self::MAUTIC_MINIMUM_PHP.' while your server has '.PHP_VERSION.'. Please contact your host to update your PHP installation.', 500); | ||
} | ||
|
||
// Are we running a version newer than what Mautic supports? | ||
if (version_compare(PHP_VERSION, self::MAUTIC_MAXIMUM_PHP, 'gt')) { | ||
return new Response('Mautic does not support PHP version '.PHP_VERSION.' at this time. To use Mautic, you will need to downgrade to an earlier version.', 500); | ||
} | ||
|
||
return $this->app->handle($request, $type, $catch); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getPriority() | ||
{ | ||
return self::PRIORITY; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.