protected function evaluate() { $phpVersion = Platform::getPhpVersion(); $this->setStateText(sprintf(mt('setup', 'You are running PHP version %s.'), $phpVersion)); list($operator, $requiredVersion) = $this->getCondition(); return version_compare($phpVersion, $requiredVersion, $operator); }
protected function evaluate() { list($configDirective, $value) = $this->getCondition(); $configValue = Platform::getPhpConfig($configDirective); $this->setStateText($configValue ? sprintf(mt('setup', 'The PHP config `%s\' is set to "%s".'), $configDirective, $configValue) : sprintf(mt('setup', 'The PHP config `%s\' is not defined.'), $configDirective)); return is_bool($value) ? $configValue == $value : $configValue === $value; }
/** * Create and add elements to this form * * @param array $formData The data sent by the user */ public function createElements(array $formData) { $dbChoices = array(); if (Platform::hasMysqlSupport()) { $dbChoices['mysql'] = 'MySQL'; } if (Platform::hasPostgresqlSupport()) { $dbChoices['pgsql'] = 'PostgreSQL'; } if (Platform::hasMssqlSupport()) { $dbChoices['mssql'] = 'MSSQL'; } if (Platform::hasOracleSupport()) { $dbChoices['oracle'] = 'Oracle'; } if (Platform::hasOciSupport()) { $dbChoices['oci'] = 'Oracle (OCI8)'; } $offerSsl = false; $offerPostgres = false; $offerMysql = false; $dbChoice = isset($formData['db']) ? $formData['db'] : key($dbChoices); if ($dbChoice === 'pgsql') { $offerPostgres = true; } elseif ($dbChoice === 'mysql') { $offerMysql = true; if (version_compare(Platform::getPhpVersion(), '5.4.0', '>=')) { $offerSsl = true; } } $socketInfo = ''; if ($offerPostgres) { $socketInfo = $this->translate('For using unix domain sockets, specify the path to the unix domain socket directory'); } elseif ($offerMysql) { $socketInfo = $this->translate('For using unix domain sockets, specify localhost'); } $this->addElement('text', 'name', array('required' => true, 'label' => $this->translate('Resource Name'), 'description' => $this->translate('The unique name of this resource'))); $this->addElement('select', 'db', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('Database Type'), 'description' => $this->translate('The type of SQL database'), 'multiOptions' => $dbChoices)); $this->addElement('text', 'host', array('required' => true, 'label' => $this->translate('Host'), 'description' => $this->translate('The hostname of the database') . ($socketInfo ? '. ' . $socketInfo : ''), 'value' => 'localhost')); $this->addElement('number', 'port', array('description' => $this->translate('The port to use'), 'label' => $this->translate('Port'), 'preserveDefault' => true, 'required' => $offerPostgres, 'value' => $offerPostgres ? 5432 : null)); $this->addElement('text', 'dbname', array('required' => true, 'label' => $this->translate('Database Name'), 'description' => $this->translate('The name of the database to use'))); $this->addElement('text', 'username', array('required' => true, 'label' => $this->translate('Username'), 'description' => $this->translate('The user name to use for authentication'))); $this->addElement('password', 'password', array('renderPassword' => true, 'label' => $this->translate('Password'), 'description' => $this->translate('The password to use for authentication'))); $this->addElement('text', 'charset', array('description' => $this->translate('The character set for the database'), 'label' => $this->translate('Character Set'))); $this->addElement('checkbox', 'persistent', array('description' => $this->translate('Check this box for persistent database connections. Persistent connections are not closed at the' . ' end of a request, but are cached and re-used. This is experimental'), 'label' => $this->translate('Persistent'))); if ($offerSsl) { $this->addElement('checkbox', 'use_ssl', array('autosubmit' => true, 'label' => $this->translate('Use SSL'), 'description' => $this->translate('Whether to encrypt the connection or to authenticate using certificates'))); if (isset($formData['use_ssl']) && $formData['use_ssl']) { $this->addElement('text', 'ssl_key', array('label' => $this->translate('SSL Key'), 'description' => $this->translate('The client key file path'))); $this->addElement('text', 'ssl_cert', array('label' => $this->translate('SSL Certificate'), 'description' => $this->translate('The certificate file path'))); $this->addElement('text', 'ssl_ca', array('label' => $this->translate('SSL CA'), 'description' => $this->translate('The CA certificate file path'))); $this->addElement('text', 'ssl_capath', array('label' => $this->translate('SSL CA Path'), 'description' => $this->translate('The trusted CA certificates in PEM format directory path'))); $this->addElement('text', 'ssl_cipher', array('label' => $this->translate('SSL Cipher'), 'description' => $this->translate('The list of permissible ciphers'))); } } return $this; }
/** * @see Form::createElements() */ public function createElements(array $formData) { $storageTypes = array(); $storageTypes['ini'] = $this->translate('File System (INI Files)'); if (Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) { $storageTypes['db'] = $this->translate('Database'); } $storageTypes['none'] = $this->translate('Don\'t Store Preferences'); $this->addElement('select', 'store', array('required' => true, 'label' => $this->translate('User Preference Storage Type'), 'multiOptions' => $storageTypes)); }
public function createElements(array $formData) { $this->addElement('text', 'name', array('required' => true, 'value' => 'icinga', 'label' => $this->translate('Backend Name'), 'description' => $this->translate('The identifier of this backend'))); $resourceTypes = array(); if (Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) { $resourceTypes['ido'] = 'IDO'; } // $resourceTypes['livestatus'] = 'Livestatus'; $this->addElement('select', 'type', array('required' => true, 'label' => $this->translate('Backend Type'), 'description' => $this->translate('The data source used for retrieving monitoring information'), 'multiOptions' => $resourceTypes)); }
protected function evaluate() { $moduleName = $this->getCondition(); if (Platform::extensionLoaded($moduleName)) { $this->setStateText(sprintf(mt('setup', 'The PHP module %s is available.'), $this->getAlias() ?: $moduleName)); return true; } else { $this->setStateText(sprintf(mt('setup', 'The PHP module %s is missing.'), $this->getAlias() ?: $moduleName)); return false; } }
protected function evaluate() { $classNameOrPath = $this->getCondition(); if (Platform::classExists($classNameOrPath)) { $this->setStateText(sprintf(mt('setup', 'The %s is available.', 'setup.requirement.class'), $this->getAlias() ?: $classNameOrPath . ' ' . mt('setup', 'class', 'setup.requirement.class'))); return true; } else { $this->setStateText(sprintf(mt('setup', 'The %s is missing.', 'setup.requirement.class'), $this->getAlias() ?: $classNameOrPath . ' ' . mt('setup', 'class', 'setup.requirement.class'))); return false; } }
/** * Return an array containing the tab definitions for all supported types * * Using array_keys on this array or isset allows to check whether a * requested type is supported * * @return array */ public function getSupportedTypes() { $supportedTypes = array(); if (Platform::extensionLoaded('gd')) { $supportedTypes[self::TYPE_PDF] = array('name' => 'pdf', 'label' => 'PDF', 'icon' => 'file-pdf', 'urlParams' => array('format' => 'pdf')); } $supportedTypes[self::TYPE_CSV] = array('name' => 'csv', 'label' => 'CSV', 'icon' => 'file-excel', 'urlParams' => array('format' => 'csv')); if (Platform::extensionLoaded('json')) { $supportedTypes[self::TYPE_JSON] = array('name' => 'json', 'label' => 'JSON', 'icon' => 'img/icons/json.png', 'urlParams' => array('format' => 'json')); } return $supportedTypes; }
/** * Create and add elements to this form * * @param array $formData The data sent by the user */ public function createElements(array $formData) { $dbChoices = array(); if (Platform::hasMysqlSupport()) { $dbChoices['mysql'] = 'MySQL'; } if (Platform::hasPostgresqlSupport()) { $dbChoices['pgsql'] = 'PostgreSQL'; } if (Platform::hasMssqlSupport()) { $dbChoices['mssql'] = 'MSSQL'; } if (Platform::hasOracleSupport()) { $dbChoices['oracle'] = 'Oracle'; } if (Platform::hasOciSupport()) { $dbChoices['oci'] = 'Oracle (OCI8)'; } $offerPostgres = false; $offerMysql = false; if (isset($formData['db'])) { if ($formData['db'] === 'pgsql') { $offerPostgres = true; } elseif ($formData['db'] === 'mysql') { $offerMysql = true; } } else { $dbChoice = key($dbChoices); if ($dbChoice === 'pgsql') { $offerPostgres = true; } elseif ($dbChoices === 'mysql') { $offerMysql = true; } } $socketInfo = ''; if ($offerPostgres) { $socketInfo = $this->translate('For using unix domain sockets, specify the path to the unix domain socket directory'); } elseif ($offerMysql) { $socketInfo = $this->translate('For using unix domain sockets, specify localhost'); } $this->addElement('text', 'name', array('required' => true, 'label' => $this->translate('Resource Name'), 'description' => $this->translate('The unique name of this resource'))); $this->addElement('select', 'db', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('Database Type'), 'description' => $this->translate('The type of SQL database'), 'multiOptions' => $dbChoices)); $this->addElement('text', 'host', array('required' => true, 'label' => $this->translate('Host'), 'description' => $this->translate('The hostname of the database') . ($socketInfo ? '. ' . $socketInfo : ''), 'value' => 'localhost')); $this->addElement('number', 'port', array('description' => $this->translate('The port to use'), 'label' => $this->translate('Port'), 'preserveDefault' => true, 'required' => $offerPostgres, 'value' => $offerPostgres ? 5432 : null)); $this->addElement('text', 'dbname', array('required' => true, 'label' => $this->translate('Database Name'), 'description' => $this->translate('The name of the database to use'))); $this->addElement('text', 'username', array('required' => true, 'label' => $this->translate('Username'), 'description' => $this->translate('The user name to use for authentication'))); $this->addElement('password', 'password', array('required' => true, 'renderPassword' => true, 'label' => $this->translate('Password'), 'description' => $this->translate('The password to use for authentication'))); $this->addElement('text', 'charset', array('description' => $this->translate('The character set for the database'), 'label' => $this->translate('Character Set'))); $this->addElement('checkbox', 'persistent', array('description' => $this->translate('Check this box for persistent database connections. Persistent connections are not closed at the' . ' end of a request, but are cached and re-used. This is experimental'), 'label' => $this->translate('Persistent'))); return $this; }
private final function __construct() { if (Platform::isCli()) { $this->isCli = true; return; } $this->session = Session::getSession(); $stored = $this->session->get('messages'); if (is_array($stored)) { $this->messages = $stored; $this->session->set('messages', array()); $this->session->write(); } }
/** * Create the notification instance */ private final function __construct() { if (Platform::isCli()) { $this->isCli = true; return; } $this->session = Session::getSession(); $messages = $this->session->get(self::SESSION_KEY); if (is_array($messages)) { $this->messages = $messages; $this->session->delete(self::SESSION_KEY); $this->session->write(); } }
/** * Create new object and try to identify the timezone */ public function __construct() { if (self::$success !== null) { return; } if (Platform::isCli() === false && array_key_exists(self::$cookieName, $_COOKIE)) { list($offset, $dst) = explode(',', $_COOKIE[self::$cookieName]); $timezoneName = timezone_name_from_abbr('', (int) $offset, (int) $dst); self::$success = (bool) $timezoneName; if (self::$success === true) { self::$offset = $offset; self::$timezoneName = $timezoneName; } } }
/** * @see Form::createElements() */ public function createElements(array $formData) { if (isset($formData['type']) && $formData['type'] === 'external' && !isset($_SERVER['REMOTE_USER'])) { $this->info($this->translate('You\'re currently not authenticated using any of the web server\'s authentication ' . 'mechanisms. Make sure you\'ll configure such, otherwise you\'ll not be able to ' . 'log into Icinga Web 2.'), false); } $backendTypes = array(); if (Platform::hasMysqlSupport() || Platform::hasPostgresqlSupport()) { $backendTypes['db'] = $this->translate('Database'); } if (Platform::extensionLoaded('ldap')) { $backendTypes['ldap'] = 'LDAP'; } $backendTypes['external'] = $this->translate('External'); $this->addElement('select', 'type', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('Authentication Type'), 'description' => $this->translate('The type of authentication to use when accessing Icinga Web 2'), 'multiOptions' => $backendTypes)); }
/** * @see Form::createElements() */ public function createElements(array $formData) { $dbChoices = array(); if (Platform::hasMysqlSupport()) { $dbChoices['mysql'] = 'MySQL'; } if (Platform::hasPostgresqlSupport()) { $dbChoices['pgsql'] = 'PostgreSQL'; } $this->addElement('text', 'name', array('required' => true, 'label' => $this->translate('Resource Name'), 'description' => $this->translate('The unique name of this resource'))); $this->addElement('select', 'db', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('Database Type'), 'description' => $this->translate('The type of SQL database'), 'multiOptions' => $dbChoices)); $this->addElement('text', 'host', array('required' => true, 'label' => $this->translate('Host'), 'description' => $this->translate('The hostname of the database'), 'value' => 'localhost')); $this->addElement('number', 'port', array('required' => true, 'preserveDefault' => true, 'label' => $this->translate('Port'), 'description' => $this->translate('The port to use'), 'value' => !array_key_exists('db', $formData) || $formData['db'] === 'mysql' ? 3306 : 5432)); $this->addElement('text', 'dbname', array('required' => true, 'label' => $this->translate('Database Name'), 'description' => $this->translate('The name of the database to use'))); $this->addElement('text', 'username', array('required' => true, 'label' => $this->translate('Username'), 'description' => $this->translate('The user name to use for authentication'))); $this->addElement('password', 'password', array('required' => true, 'renderPassword' => true, 'label' => $this->translate('Password'), 'description' => $this->translate('The password to use for authentication'))); return $this; }
/** * {@inheritdoc} * * @return $this */ public function createElements(array $formData) { $this->addElement('select', 'logging_log', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('Logging Type'), 'description' => $this->translate('The type of logging to utilize.'), 'multiOptions' => array('syslog' => 'Syslog', 'file' => $this->translate('File', 'app.config.logging.type'), 'none' => $this->translate('None', 'app.config.logging.type')))); if (!isset($formData['logging_log']) || $formData['logging_log'] !== 'none') { $this->addElement('select', 'logging_level', array('required' => true, 'label' => $this->translate('Logging Level'), 'description' => $this->translate('The maximum logging level to emit.'), 'multiOptions' => array(Logger::$levels[Logger::ERROR] => $this->translate('Error', 'app.config.logging.level'), Logger::$levels[Logger::WARNING] => $this->translate('Warning', 'app.config.logging.level'), Logger::$levels[Logger::INFO] => $this->translate('Information', 'app.config.logging.level'), Logger::$levels[Logger::DEBUG] => $this->translate('Debug', 'app.config.logging.level')))); } if (false === isset($formData['logging_log']) || $formData['logging_log'] === 'syslog') { $this->addElement('text', 'logging_application', array('required' => true, 'label' => $this->translate('Application Prefix'), 'description' => $this->translate('The name of the application by which to prefix syslog messages.'), 'requirement' => $this->translate('The application prefix must not contain whitespace.'), 'value' => 'icingaweb2', 'validators' => array(array('Regex', false, array('pattern' => '/^\\S+$/', 'messages' => array('regexNotMatch' => $this->translate('The application prefix must not contain whitespace.'))))))); if (!isset($formData['logging_log']) || $formData['logging_log'] === 'syslog') { if (Platform::isWindows()) { /* @see https://secure.php.net/manual/en/function.openlog.php */ $this->addElement('hidden', 'logging_facility', array('value' => 'user', 'disabled' => true)); } else { $facilities = array_keys(SyslogWriter::$facilities); $this->addElement('select', 'logging_facility', array('required' => true, 'label' => $this->translate('Facility'), 'description' => $this->translate('The syslog facility to utilize.'), 'value' => 'user', 'multiOptions' => array_combine($facilities, $facilities))); } } } elseif (isset($formData['logging_log']) && $formData['logging_log'] === 'file') { $this->addElement('text', 'logging_file', array('required' => true, 'label' => $this->translate('File path'), 'description' => $this->translate('The full path to the log file to write messages to.'), 'value' => '/var/log/icingaweb2/icingaweb2.log', 'validators' => array('WritablePathValidator'))); } return $this; }
private final function __construct() { $session = Session::getSession(); if (!is_array($session->get('messages'))) { $session->messages = array(); } if (Platform::isCli()) { $this->is_cli = true; } }
protected function evaluate() { $phpOS = Platform::getOperatingSystemName(); $this->setStateText(sprintf(mt('setup', 'You are running PHP on a %s system.'), ucfirst($phpOS))); return strtolower($phpOS) === strtolower($this->getCondition()); }
protected function evaluate() { return Platform::classExists($this->getCondition()); }
/** * @see Form::createElements() */ public function createElements(array $formData) { $backendTypes = array(); $backendType = isset($formData['type']) ? $formData['type'] : null; if (isset($this->resources['db'])) { $backendTypes['db'] = $this->translate('Database'); } if (isset($this->resources['ldap']) && ($backendType === 'ldap' || Platform::extensionLoaded('ldap'))) { $backendTypes['ldap'] = 'LDAP'; $backendTypes['msldap'] = 'ActiveDirectory'; } $externalBackends = array_filter($this->config->toArray(), function ($authBackendCfg) { return isset($authBackendCfg['backend']) && $authBackendCfg['backend'] === 'external'; }); if ($backendType === 'external' || empty($externalBackends)) { $backendTypes['external'] = $this->translate('External'); } if ($backendType === null) { $backendType = key($backendTypes); } $this->addElement('select', 'type', array('ignore' => true, 'required' => true, 'autosubmit' => true, 'label' => $this->translate('Backend Type'), 'description' => $this->translate('The type of the resource to use for this authenticaton provider'), 'multiOptions' => $backendTypes)); if (isset($formData['force_creation']) && $formData['force_creation']) { // In case another error occured and the checkbox was displayed before $this->addElement($this->getForceCreationCheckbox()); } $this->addElements($this->getBackendForm($backendType)->createElements($formData)->getElements()); }
/** * @see Form::createElemeents() */ public function createElements(array $formData) { $resourceType = isset($formData['type']) ? $formData['type'] : 'db'; $resourceTypes = array('file' => $this->translate('File'), 'livestatus' => 'Livestatus', 'ssh' => $this->translate('SSH Identity')); if ($resourceType === 'ldap' || Platform::hasLdapSupport()) { $resourceTypes['ldap'] = 'LDAP'; } if ($resourceType === 'db' || Platform::hasDatabaseSupport()) { $resourceTypes['db'] = $this->translate('SQL Database'); } $this->addElement('select', 'type', array('required' => true, 'autosubmit' => true, 'label' => $this->translate('Resource Type'), 'description' => $this->translate('The type of resource'), 'multiOptions' => $resourceTypes, 'value' => $resourceType)); if (isset($formData['force_creation']) && $formData['force_creation']) { // In case another error occured and the checkbox was displayed before $this->addElement($this->getForceCreationCheckbox()); } $this->addElements($this->getResourceForm($resourceType)->createElements($formData)->getElements()); }
/** * Set up how to handle StartTLS connections * * @throws LdapException In case the LDAPRC environment variable cannot be set */ protected function prepareTlsEnvironment() { // TODO: allow variable known CA location (system VS Icinga) if (Platform::isWindows()) { putenv('LDAPTLS_REQCERT=never'); } else { if ($this->validateCertificate) { $ldap_conf = $this->getConfigDir('ldap_ca.conf'); } else { $ldap_conf = $this->getConfigDir('ldap_nocert.conf'); } putenv('LDAPRC=' . $ldap_conf); // TODO: Does not have any effect if (getenv('LDAPRC') !== $ldap_conf) { throw new LdapException('putenv failed'); } } }
/** * Constructor * * @param string $baseDir Icinga Web 2 base directory * @param string $configDir Path to Icinga Web 2's configuration files */ protected function __construct($baseDir = null, $configDir = null) { if ($baseDir === null) { $baseDir = dirname($this->getBootstrapDirectory()); } $this->baseDir = $baseDir; $this->appDir = $baseDir . '/application'; $this->vendorDir = $baseDir . '/library/vendor'; $this->libDir = realpath(__DIR__ . '/../..'); $this->setupAutoloader(); if ($configDir === null) { $configDir = getenv('ICINGAWEB_CONFIGDIR'); if ($configDir === false) { $configDir = Platform::isWindows() ? $baseDir . '/config' : '/etc/icingaweb2'; } } $canonical = realpath($configDir); $this->configDir = $canonical ? $canonical : $configDir; set_include_path(implode(PATH_SEPARATOR, array($this->vendorDir, get_include_path()))); Benchmark::measure('Bootstrap, autoloader registered'); Icinga::setApp($this); require_once dirname(__FILE__) . '/functions.php'; }
protected function prepareTlsEnvironment() { $strict_tls = true; // TODO: allow variable known CA location (system VS Icinga) if (Platform::isWindows()) { // putenv('LDAP...') } else { if ($strict_tls) { $ldap_conf = $this->getConfigDir('ldap_ca.conf'); } else { $ldap_conf = $this->getConfigDir('ldap_nocert.conf'); } putenv('LDAPRC=' . $ldap_conf); if (getenv('LDAPRC') !== $ldap_conf) { throw new Exception('putenv failed'); } } }
/** * Fail if Icinga has not been called on CLI * * @throws ProgrammingError * @return void */ private function assertRunningOnCli() { if (Platform::isCli()) { return; } throw new ProgrammingError('Icinga is not running on CLI'); }