Skip to content

Commit

Permalink
RemoteAccessManager: Allow when accessing from CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
jelen07 committed May 24, 2017
1 parent 432f1e8 commit 46d11e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Expand Up @@ -45,6 +45,7 @@ public function loadConfiguration()
'blacklist' => $config['blacklist'],
'key' => $config['secretKey'],
'mode' => $config['allowAll'],
'consoleMode' => $builder->parameters['consoleMode'],
'handler' => new $config['handler'],
])
->addTag('run', TRUE)
Expand Down
12 changes: 11 additions & 1 deletion src/RemoteAccessManager/RemoteAccessManager.php
Expand Up @@ -7,6 +7,7 @@
use Nette\Http\IRequest;
use Nette\SmartObject;
use SixtyEightPublishers\Application\RemoteAccessManager\Handler\IAccessHandler;
use Tracy\Debugger;

/**
* @method RemoteAccessManager onAccess()
Expand Down Expand Up @@ -36,6 +37,9 @@ class RemoteAccessManager implements IRemoteAccessManager
/** @var bool|true */
private $mode;

/** @var bool|false */
private $consoleMode;

/** @var \SixtyEightPublishers\Application\RemoteAccessManager\Handler\IAccessHandler */
private $handler;

Expand All @@ -51,14 +55,16 @@ class RemoteAccessManager implements IRemoteAccessManager
* @param string|array $whitelist
* @param string $key
* @param bool|TRUE $mode
* @param bool|FALSE $consoleMode
* @param IAccessHandler $handler
*/
public function __construct(IRequest $request, $blacklist = [], $whitelist = [], $mode = self::ALLOWED_ALL, $key = self::COOKIE_SECRET, IAccessHandler $handler)
public function __construct(IRequest $request, $blacklist = [], $whitelist = [], $mode = self::ALLOWED_ALL, $key = self::COOKIE_SECRET, $consoleMode = FALSE, IAccessHandler $handler)
{
$this->request = $request;
$this->blacklist = $blacklist;
$this->whitelist = $whitelist;
$this->mode = $mode;
$this->consoleMode = $consoleMode;
$this->key = $key;
$this->handler = $handler;

Expand All @@ -78,6 +84,10 @@ public function process()
*/
private function isAllowed() : bool
{
if ($this->consoleMode) {
return TRUE;
}

$addr = $this->request->getRemoteAddress() ?: php_uname('n');
$secret = $this->request->getCookie($this->key);

Expand Down

0 comments on commit 46d11e0

Please sign in to comment.