data = $data; } public function apply() { $success = $this->createBackendsIni(); $success &= $this->createResourcesIni(); return $success; } protected function createBackendsIni() { $config = array(); $config[$this->data['backendConfig']['name']] = array( 'type' => $this->data['backendConfig']['type'], 'resource' => $this->data['resourceConfig']['name'] ); try { Config::fromArray($config) ->setConfigFile(Config::resolvePath('modules/monitoring/backends.ini')) ->saveIni(); } catch (Exception $e) { $this->backendIniError = $e; return false; } $this->backendIniError = false; return true; } protected function createResourcesIni() { $resourceConfig = $this->data['resourceConfig']; $resourceName = $resourceConfig['name']; unset($resourceConfig['name']); try { $config = Config::app('resources', true); $config->setSection($resourceName, $resourceConfig); $config->saveIni(); } catch (Exception $e) { $this->resourcesIniError = $e; return false; } $this->resourcesIniError = false; return true; } public function getSummary() { $pageTitle = '

' . mt('monitoring', 'Monitoring Backend', 'setup.page.title') . '

'; $backendDescription = '

' . sprintf( mt( 'monitoring', 'Icinga Web 2 will retrieve information from your monitoring environment' . ' using a backend called "%s" and the specified resource below:' ), $this->data['backendConfig']['name'] ) . '

'; $resourceTitle = null; $resourceHtml = null; if ($this->data['resourceConfig']['type'] === 'db') { $resourceTitle = '

' . mt('monitoring', 'Database Resource') . '

'; $resourceHtml = '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . '' . ''; if (defined('\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT') && isset($this->data['resourceConfig']['ssl_do_not_verify_server_cert']) && $this->data['resourceConfig']['ssl_do_not_verify_server_cert'] ) { $resourceHtml .= '' . '' . '' . '' . ''; } if (isset($this->data['resourceConfig']['ssl_key']) && $this->data['resourceConfig']['ssl_key']) { $resourceHtml .= '' .'' . '' . '' . ''; } if (isset($this->data['resourceConfig']['ssl_cert']) && $this->data['resourceConfig']['ssl_cert']) { $resourceHtml .= '' . '' . '' . '' . ''; } if (isset($this->data['resourceConfig']['ssl_ca']) && $this->data['resourceConfig']['ssl_ca']) { $resourceHtml .= '' . '' . '' . '' . ''; } if (isset($this->data['resourceConfig']['ssl_capath']) && $this->data['resourceConfig']['ssl_capath']) { $resourceHtml .= '' . '' . '' . '' . ''; } if (isset($this->data['resourceConfig']['ssl_cipher']) && $this->data['resourceConfig']['ssl_cipher']) { $resourceHtml .= '' . '' . '' . '' . ''; } $resourceHtml .= '' . '' . '
' . t('Resource Name') . '' . $this->data['resourceConfig']['name'] . '
' . t('Database Type') . '' . $this->data['resourceConfig']['db'] . '
' . t('Host') . '' . $this->data['resourceConfig']['host'] . '
' . t('Port') . '' . $this->data['resourceConfig']['port'] . '
' . t('Database Name') . '' . $this->data['resourceConfig']['dbname'] . '
' . t('Username') . '' . $this->data['resourceConfig']['username'] . '
' . t('Password') . '' . str_repeat('*', strlen($this->data['resourceConfig']['password'])) . '
' . t('SSL Do Not Verify Server Certificate') . '' . $this->data['resourceConfig']['ssl_do_not_verify_server_cert'] . '
' . t('SSL Key') . '' . $this->data['resourceConfig']['ssl_key'] . '
' . t('SSL Cert') . '' . $this->data['resourceConfig']['ssl_cert'] . '
' . t('CA') . '' . $this->data['resourceConfig']['ssl_ca'] . '
' . t('CA Path') . '' . $this->data['resourceConfig']['ssl_capath'] . '
' . t('Cipher') . '' . $this->data['resourceConfig']['ssl_cipher'] . '
'; } return $pageTitle . '
' . $backendDescription . $resourceTitle . $resourceHtml . '
'; } public function getReport() { $report = array(); if ($this->backendIniError === false) { $report[] = sprintf( mt('monitoring', 'Monitoring backend configuration has been successfully written to: %s'), Config::resolvePath('modules/monitoring/backends.ini') ); } elseif ($this->backendIniError !== null) { $report[] = sprintf( mt( 'monitoring', 'Monitoring backend configuration could not be written to: %s. An error occured:' ), Config::resolvePath('modules/monitoring/backends.ini') ); $report[] = sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->backendIniError)); } if ($this->resourcesIniError === false) { $report[] = sprintf( mt('monitoring', 'Resource configuration has been successfully updated: %s'), Config::resolvePath('resources.ini') ); } elseif ($this->resourcesIniError !== null) { $report[] = sprintf( mt('monitoring', 'Resource configuration could not be udpated: %s. An error occured:'), Config::resolvePath('resources.ini') ); $report[] = sprintf(mt('setup', 'ERROR: %s'), IcingaException::describe($this->resourcesIniError)); } return $report; } }