Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
179 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Balemy\LdapCommander\Modules\RawQuery; | ||
|
||
use Yiisoft\FormModel\FormModel; | ||
use Yiisoft\Validator\Rule\Required; | ||
use Yiisoft\Validator\RulesProviderInterface; | ||
|
||
|
||
class QueryForm extends FormModel implements RulesProviderInterface | ||
{ | ||
public string $query = ''; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getRules(): iterable | ||
{ | ||
$rules = []; | ||
$rules['query'] = [new Required()]; | ||
return $rules; | ||
} | ||
|
||
public function getFormName(): string | ||
{ | ||
return 'RawQueryForm'; | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Balemy\LdapCommander\Modules\RawQuery; | ||
|
||
use Balemy\LdapCommander\ApplicationParameters; | ||
use Balemy\LdapCommander\Modules\Session\Session; | ||
use Balemy\LdapCommander\Modules\UserManager\UserForm; | ||
use Balemy\LdapCommander\Modules\UserManager\UserFormSchema; | ||
use Balemy\LdapCommander\Service\WebControllerService; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Yiisoft\Assets\AssetManager; | ||
use Yiisoft\FormModel\FormHydrator; | ||
use Yiisoft\Http\Method; | ||
use Yiisoft\Router\UrlGeneratorInterface; | ||
use Yiisoft\Session\Flash\FlashInterface; | ||
use Yiisoft\Session\SessionInterface; | ||
use Yiisoft\Validator\ValidatorInterface; | ||
use Yiisoft\Yii\View\ViewRenderer; | ||
|
||
final class RawQueryController | ||
{ | ||
public function __construct(public ViewRenderer $viewRenderer, | ||
public WebControllerService $webService, | ||
public UrlGeneratorInterface $urlGenerator, | ||
public SessionInterface $session, | ||
public ValidatorInterface $validator, | ||
public FormHydrator $formHydrator, | ||
public AssetManager $assetManager, | ||
public FlashInterface $flash, | ||
public ApplicationParameters $applicationParameters, | ||
) | ||
{ | ||
$this->viewRenderer = $viewRenderer->withViewPath(__DIR__ . '/Views/'); | ||
} | ||
|
||
/** | ||
* @psalm-suppress PossiblyInvalidArgument | ||
*/ | ||
public function index(ServerRequestInterface $request, FormHydrator $formHydrator): ResponseInterface | ||
{ | ||
$queryForm = new QueryForm(); | ||
$results = []; | ||
|
||
if ($request->getMethod() === Method::POST && | ||
$formHydrator->populate($queryForm, $request->getParsedBody()) && $this->validator->validate($queryForm)->isValid()) { | ||
|
||
$session = Session::getCurrentSession(); | ||
$query = trim($queryForm->query); | ||
$results = $session->lrConnection->query()->rawFilter($query)->select(['dn'])->paginate(); | ||
} | ||
|
||
return $this->viewRenderer->render('index', [ | ||
'urlGenerator' => $this->urlGenerator, | ||
'queryForm' => $queryForm, | ||
'results' => $results | ||
]); | ||
} | ||
|
||
} |
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,75 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @var \Yiisoft\View\WebView $this | ||
* @var \Balemy\LdapCommander\ApplicationParameters $applicationParameters | ||
* @var \Yiisoft\Router\UrlGeneratorInterface $urlGenerator | ||
* @var \Yiisoft\Router\CurrentRoute $currentRoute | ||
* @var Csrf $csrf | ||
* @var \Balemy\LdapCommander\Modules\RawQuery\QueryForm $queryForm | ||
* @var string[] $results | ||
*/ | ||
|
||
use Yiisoft\FormModel\Field; | ||
use Yiisoft\Html\Html; | ||
use Yiisoft\Html\Tag\Form; | ||
use Yiisoft\Yii\View\Csrf; | ||
|
||
$this->setTitle($applicationParameters->getName()); | ||
?> | ||
|
||
<div class="row"> | ||
<div class="col-md-9"> | ||
<h1>Execute LDAP Query</h1> | ||
<p class="lead"> | ||
</p> | ||
|
||
<br> | ||
|
||
<?= Html::form()->post($urlGenerator->generate('raw-query'))->csrf($csrf)->open() ?> | ||
|
||
<div class="row"> | ||
<div class="col-sm-12"> | ||
<?= Field::textarea($queryForm, 'query') ?> | ||
</div> | ||
</div> | ||
<?= Field::submitButton() | ||
->tabindex(3) | ||
->content('Execute') ?> | ||
|
||
<?= Form::tag()->close(); ?> | ||
|
||
|
||
<?php if (!empty($results)): ?> | ||
<br> | ||
<br> | ||
<table class="table"> | ||
<tr> | ||
<th>DN</th> | ||
<th>Object Class</th> | ||
</tr> | ||
|
||
<?php foreach ($results as $result): ?> | ||
<?php | ||
array_shift($result['objectclass']); | ||
?> | ||
<tr> | ||
<td> | ||
<?= Html::a(Html::encode($result['dn']), $urlGenerator->generate('entity-edit', [], ['dn' => $result['dn']])) ?> | ||
</td> | ||
<td><?= implode(', ', $result['objectclass']) ?></td> | ||
</tr> | ||
<?php endforeach; ?> | ||
|
||
</table> | ||
|
||
|
||
<?php endif; ?> | ||
|
||
</div> | ||
|
||
|
||
</div> | ||
|
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