parent
7a1dbd5334
commit
427cb2c050
|
@ -9,6 +9,7 @@ use Icinga\Module\Director\Forms\IcingaHostSelfServiceForm;
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaHost;
|
||||||
use Icinga\Module\Director\Objects\IcingaZone;
|
use Icinga\Module\Director\Objects\IcingaZone;
|
||||||
use Icinga\Module\Director\Settings;
|
use Icinga\Module\Director\Settings;
|
||||||
|
use Icinga\Module\Director\Util;
|
||||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||||
use ipl\Html\Html;
|
use ipl\Html\Html;
|
||||||
|
|
||||||
|
@ -86,6 +87,39 @@ class SelfServiceController extends ActionController
|
||||||
->add($form);
|
->add($form);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ticketAction()
|
||||||
|
{
|
||||||
|
if (!$this->getRequest()->isApiRequest()) {
|
||||||
|
throw new NotFoundError('Not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$key = $this->params->getRequired('key');
|
||||||
|
$host = IcingaHost::loadWithApiKey($key, $this->db());
|
||||||
|
if ($host->isTemplate()) {
|
||||||
|
throw new NotFoundError('Got invalid API key "%s"', $key);
|
||||||
|
}
|
||||||
|
$name = $host->getObjectName();
|
||||||
|
|
||||||
|
if ($host->getResolvedProperty('has_agent') !== 'y') {
|
||||||
|
throw new NotFoundError('The host "%s" is not an agent', $name);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->sendPowerShellResponse(
|
||||||
|
Util::getIcingaTicket(
|
||||||
|
$name,
|
||||||
|
$this->api()->getTicketSalt()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
if ($e instanceof NotFoundError) {
|
||||||
|
$this->sendPowerShellError($e->getMessage(), 404);
|
||||||
|
} else {
|
||||||
|
$this->sendPowerShellError($e->getMessage(), 500);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected function sendPowerShellResponse($response)
|
protected function sendPowerShellResponse($response)
|
||||||
{
|
{
|
||||||
if ($this->getRequest()->getHeader('X-Director-Accept') === 'text/plain') {
|
if ($this->getRequest()->getHeader('X-Director-Accept') === 'text/plain') {
|
||||||
|
|
Loading…
Reference in New Issue