Centralized IP Handler (#2624)

This commit is contained in:
Matt Kilgore 2021-02-25 20:08:52 -05:00 committed by GitHub
parent 023871ef86
commit 8cc207b139
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 2 deletions

View File

@ -54,7 +54,7 @@ class CreateDiscussionController extends AbstractCreateController
protected function data(ServerRequestInterface $request, Document $document)
{
$actor = $request->getAttribute('actor');
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
$ipAddress = $request->getAttribute('ipAddress');
$discussion = $this->bus->dispatch(
new StartDiscussion($actor, Arr::get($request->getParsedBody(), 'data', []), $ipAddress)

View File

@ -55,7 +55,7 @@ class CreatePostController extends AbstractCreateController
$actor = $request->getAttribute('actor');
$data = Arr::get($request->getParsedBody(), 'data', []);
$discussionId = Arr::get($data, 'relationships.discussion.data.id');
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
$ipAddress = $request->getAttribute('ipAddress');
$post = $this->bus->dispatch(
new PostReply($discussionId, $actor, $data, $ipAddress)

View File

@ -55,6 +55,7 @@ class InstalledApp implements AppInterface
$pipe = new MiddlewarePipe;
$pipe->pipe(new HttpMiddleware\ProcessIp());
$pipe->pipe(new BasePath($this->basePath()));
$pipe->pipe(new OriginalMessages);
$pipe->pipe(

View File

@ -0,0 +1,26 @@
<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Http\Middleware;
use Illuminate\Support\Arr;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface as Middleware;
use Psr\Http\Server\RequestHandlerInterface;
class ProcessIp implements Middleware
{
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$ipAddress = Arr::get($request->getServerParams(), 'REMOTE_ADDR', '127.0.0.1');
return $handler->handle($request->withAttribute('ipAddress', $ipAddress));
}
}