2016-09-24 08:17:51 +01:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
|
|
use App\Helpers\MiscHelper;
|
|
|
|
|
use Closure;
|
2016-09-24 09:34:08 +01:00
|
|
|
|
use Illuminate\Foundation\Application;
|
2016-09-24 08:17:51 +01:00
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
|
|
class CheckMaxPostSizeExceeded
|
|
|
|
|
{
|
2016-09-24 09:34:08 +01:00
|
|
|
|
/**
|
|
|
|
|
* The application instance.
|
|
|
|
|
*
|
|
|
|
|
* @var \Illuminate\Foundation\Application
|
|
|
|
|
*/
|
|
|
|
|
protected $app;
|
|
|
|
|
|
2016-09-24 08:17:51 +01:00
|
|
|
|
protected $exclude = [
|
|
|
|
|
'/admin/photos/analyse/*',
|
2016-10-03 15:57:58 +01:00
|
|
|
|
'/admin/photos/flip/*',
|
2016-09-28 20:13:18 +01:00
|
|
|
|
'/admin/photos/regenerate-thumbnails/*',
|
|
|
|
|
'/admin/photos/rotate/*'
|
2016-09-24 08:17:51 +01:00
|
|
|
|
];
|
|
|
|
|
|
2016-09-24 09:34:08 +01:00
|
|
|
|
/**
|
|
|
|
|
* Create a new middleware instance.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Foundation\Application $app
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(Application $app)
|
|
|
|
|
{
|
|
|
|
|
$this->app = $app;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 08:17:51 +01:00
|
|
|
|
public function handle(Request $request, Closure $next)
|
|
|
|
|
{
|
2016-09-24 09:34:08 +01:00
|
|
|
|
if (
|
|
|
|
|
$this->isRunningInConsole() ||
|
|
|
|
|
$this->isReading($request) ||
|
|
|
|
|
$this->shouldPassThrough($request)
|
|
|
|
|
)
|
2016-09-24 08:17:51 +01:00
|
|
|
|
{
|
2016-09-24 09:34:08 +01:00
|
|
|
|
return $next($request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check post limit and see if it may have been exceeded
|
|
|
|
|
$postLimit = MiscHelper::convertToBytes(ini_get('post_max_size'));
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > $postLimit) ||
|
|
|
|
|
(empty($_POST) && empty($_REQUEST))
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
$request->session()->flash('error', trans('global.post_max_exceeded'));
|
|
|
|
|
return back();
|
2016-09-24 08:17:51 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-24 09:34:08 +01:00
|
|
|
|
protected function isRunningInConsole()
|
|
|
|
|
{
|
|
|
|
|
return $this->app->runningInConsole();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Determine if the HTTP request uses a ‘read’ verb.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
protected function isReading(Request $request)
|
|
|
|
|
{
|
|
|
|
|
return in_array($request->method(), ['HEAD', 'GET', 'OPTIONS']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function shouldPassThrough(Request $request)
|
2016-09-24 08:17:51 +01:00
|
|
|
|
{
|
|
|
|
|
foreach ($this->exclude as $exclude)
|
|
|
|
|
{
|
|
|
|
|
if ($exclude !== '/') {
|
|
|
|
|
$exclude = trim($exclude, '/');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($request->is($exclude)) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|