2015-12-18 10:51:38 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Icinga\Module\Director\Forms;
|
|
|
|
|
2016-03-07 01:10:56 +01:00
|
|
|
use Exception;
|
2016-03-13 23:48:22 +01:00
|
|
|
use Icinga\Module\Director\Db\Migrations;
|
2016-02-18 20:47:06 +01:00
|
|
|
use Icinga\Module\Director\KickstartHelper;
|
2015-12-18 10:51:38 +01:00
|
|
|
use Icinga\Module\Director\Web\Form\QuickForm;
|
|
|
|
|
|
|
|
class KickstartForm extends QuickForm
|
|
|
|
{
|
|
|
|
protected $db;
|
|
|
|
|
2016-03-13 23:48:22 +01:00
|
|
|
protected $createDbLabel;
|
|
|
|
|
2015-12-18 10:51:38 +01:00
|
|
|
public function setup()
|
|
|
|
{
|
2016-03-13 23:48:22 +01:00
|
|
|
$this->createDbLabel = $this->translate('Create database schema');
|
|
|
|
if (!$this->migrations()->hasSchema()) {
|
|
|
|
|
|
|
|
$this->addHtmlHint($this->translate(
|
|
|
|
'No database schema has been created yet'
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->setSubmitLabel($this->createDbLabel);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
2015-12-18 10:51:38 +01:00
|
|
|
$this->addHtmlHint(
|
|
|
|
$this->translate(
|
2016-02-26 12:42:21 +01:00
|
|
|
'Your installation of Icinga Director has not yet been prepared for deployments.'
|
|
|
|
. ' This kickstart wizard will assist you with setting up the connection to your Icinga 2 server'
|
2015-12-18 10:51:38 +01:00
|
|
|
)
|
|
|
|
);
|
2015-12-21 13:11:38 +01:00
|
|
|
|
|
|
|
$this->addElement('text', 'endpoint', array(
|
|
|
|
'label' => $this->translate('Endpoint Name'),
|
2016-03-07 01:10:56 +01:00
|
|
|
'description' => $this->translate(
|
|
|
|
'This is the name of the Endpoint object (and certificate name) you'
|
|
|
|
. ' created for your ApiListener object. In case you are unsure what'
|
|
|
|
. ' this means please make sure to read the documentation first'
|
|
|
|
),
|
2015-12-21 13:11:38 +01:00
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
|
2015-12-18 10:51:38 +01:00
|
|
|
$this->addElement('text', 'host', array(
|
|
|
|
'label' => $this->translate('Icinga Host'),
|
2016-03-07 01:10:56 +01:00
|
|
|
'description' => $this->translate(
|
|
|
|
'IP address / hostname of your Icinga node. Please note that this'
|
|
|
|
. ' information will only be used for the very first connection to'
|
|
|
|
. ' your Icinga instance. The Director then relies on a correctly'
|
|
|
|
. ' configured Endpoint object. Correctly configures means that either'
|
|
|
|
. ' it\'s name is resolvable or that it\'s host property contains'
|
|
|
|
. ' either an IP address or a resolvable host name. Your Director must'
|
|
|
|
. ' be able to reach this endpoint'
|
|
|
|
),
|
|
|
|
'required' => false,
|
2015-12-18 10:51:38 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->addElement('text', 'port', array(
|
|
|
|
'label' => $this->translate('Port'),
|
|
|
|
'value' => '5665',
|
2016-03-07 01:10:56 +01:00
|
|
|
'description' => $this->translate(
|
|
|
|
'The port you are going to use. The default port 5665 will be used'
|
|
|
|
. ' if none is set'
|
|
|
|
),
|
|
|
|
'required' => false,
|
2015-12-18 10:51:38 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$this->addElement('text', 'username', array(
|
|
|
|
'label' => $this->translate('API user'),
|
2016-03-07 01:10:56 +01:00
|
|
|
'description' => $this->translate(
|
|
|
|
'Your Icinga 2 API username'
|
|
|
|
),
|
2015-12-18 10:51:38 +01:00
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->addElement('password', 'password', array(
|
|
|
|
'label' => $this->translate('Password'),
|
2016-03-07 01:10:56 +01:00
|
|
|
'description' => $this->translate(
|
|
|
|
'The corresponding password'
|
|
|
|
),
|
2015-12-18 10:51:38 +01:00
|
|
|
'required' => true,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function onSuccess()
|
|
|
|
{
|
2016-03-07 01:10:56 +01:00
|
|
|
try {
|
2016-03-13 23:48:22 +01:00
|
|
|
if ($this->getSubmitLabel() === $this->createDbLabel) {
|
|
|
|
$this->migrations()->applyPendingMigrations();
|
|
|
|
return parent::onSuccess();
|
|
|
|
}
|
2016-03-07 01:10:56 +01:00
|
|
|
$kickstart = new KickstartHelper($this->db);
|
|
|
|
$kickstart->setConfig($this->getValues())->run();
|
|
|
|
parent::onSuccess();
|
|
|
|
} catch (Exception $e) {
|
2016-03-13 23:48:22 +01:00
|
|
|
$this->addError($e->getMessage());
|
2016-03-07 01:10:56 +01:00
|
|
|
}
|
2015-12-18 10:51:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function setDb($db)
|
|
|
|
{
|
|
|
|
$this->db = $db;
|
|
|
|
if ($this->object !== null) {
|
|
|
|
$this->object->setConnection($db);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2016-03-13 23:48:22 +01:00
|
|
|
|
|
|
|
protected function migrations()
|
|
|
|
{
|
|
|
|
return new Migrations($this->db);
|
|
|
|
}
|
2015-12-18 10:51:38 +01:00
|
|
|
}
|