SelfService: allow to specify global zones

fixes #997
This commit is contained in:
Thomas Gelf 2017-07-13 15:04:59 +02:00
parent 2ca7f26b49
commit 3574cec487
2 changed files with 35 additions and 20 deletions

View File

@ -15,10 +15,15 @@ use ipl\Html\Html;
class SelfServiceController extends ActionController
{
/** @var bool */
protected $isApified = true;
/** @var bool */
protected $requiresAuthentication = false;
/** @var Settings */
protected $settings;
protected function assertApiPermission()
{
// no permission required, we'll check the API key
@ -196,7 +201,7 @@ class SelfServiceController extends ActionController
$key = $this->params->getRequired('key');
$host = IcingaHost::loadWithApiKey($key, $db);
$settings = new Settings($db);
$settings = $this->getSettings();
$params = [
'fetch_agent_name' => $settings->get('self-service/agent_name') === 'hostname',
'fetch_agent_fqdn' => $settings->get('self-service/agent_name') === 'fqdn',
@ -210,7 +215,7 @@ class SelfServiceController extends ActionController
$params['allow_updates'] = $settings->get('self-service/allow_updates') === 'y';
$params['agent_listen_port'] = $host->getAgentListenPort();
if ($hashes = $settings->get('self-service/installer_hashes')) {
$params['installer_hashes'] = json_decode($hashes);
$params['installer_hashes'] = $hashes;
}
if ($settings->get('self-service/install_nsclient') === 'y') {
@ -245,6 +250,7 @@ class SelfServiceController extends ActionController
}
$db = $this->db();
$settings = $this->getSettings();
$name = $host->getObjectName();
if ($host->getSingleResolvedProperty('has_agent') !== 'y') {
$this->sendPowerShellError(sprintf(
@ -266,13 +272,7 @@ class SelfServiceController extends ActionController
$params['agent_add_firewall_rule'] = $host
->getSingleResolvedProperty('master_should_connect') === 'y';
$zdb = $db->getDbAdapter();
$params['global_zones'] = $zdb->fetchCol(
$zdb->select()->from('icinga_zone', 'object_name')
->where('disabled = ?', 'n')
->where('is_global = ?', 'y')
->order('object_name')
);
$params['global_zones'] = $settings->get('self-service/global_zones');
$zone = IcingaZone::load($zoneName, $db);
$master = $db->getDeploymentEndpoint();
@ -301,4 +301,13 @@ class SelfServiceController extends ActionController
}
}
}
protected function getSettings()
{
if ($this->settings === null) {
$this->settings = new Settings($this->db());
}
return $this->settings;
}
}

View File

@ -133,11 +133,6 @@ class SelfServiceSettingsForm extends DirectorForm
]);
$hashes = $settings->getStoredOrDefaultValue('self-service/installer_hashes');
if ($hashes) {
$hashes = json_decode($hashes);
} else {
$hashes = null;
}
$this->addElement('extensibleSet', 'installer_hashes', [
'label' => $this->translate('Installer Hashes'),
'description' => $this->translate(
@ -152,8 +147,8 @@ class SelfServiceSettingsForm extends DirectorForm
'value' => $hashes,
]);
$this->addElement('extensibleSet', 'installer_hashes', [
'label' => $this->translate('Installer Hashes'),
$this->addElement('extensibleSet', 'global_zones', [
'label' => $this->translate('Global Zones'),
'description' => $this->translate(
'To ensure downloaded packages are build by the Icinga Team'
. ' and not compromised by third parties, you will be able'
@ -163,7 +158,8 @@ class SelfServiceSettingsForm extends DirectorForm
. ' the downloaded MSI package is not matching one of the'
. ' provided hashes of this setting'
),
'value' => $hashes,
'multiOptions' => $this->enumGlobalZones(),
'value' => $settings->getStoredOrDefaultValue('self-service/global_zones'),
]);
$this->addElement('text', 'icinga_service_user', [
@ -238,6 +234,19 @@ class SelfServiceSettingsForm extends DirectorForm
return $this;
}
protected function enumGlobalZones()
{
$db = $this->getDb()->getDbAdapter();
$zones = $db->fetchCol(
$db->select()->from('icinga_zone', 'object_name')
->where('disabled = ?', 'n')
->where('is_global = ?', 'y')
->order('object_name')
);
return array_combine($zones, $zones);
}
public function setSettings(Settings $settings)
{
$this->settings = $settings;
@ -252,9 +261,6 @@ class SelfServiceSettingsForm extends DirectorForm
$value = null;
}
if (is_array($value)) {
$value = json_encode($value);
}
$this->settings->set("self-service/$key", $value);
}