/** * Show a user */ public function showAction() { $this->assertPermission('config/authentication/users/show'); $userName = $this->params->getRequired('user'); $backend = $this->getUserBackend($this->params->getRequired('backend')); $user = $backend->select(array('user_name', 'is_active', 'created_at', 'last_modified'))->where('user_name', $userName)->fetchRow(); if ($user === false) { $this->httpNotFound(sprintf($this->translate('User "%s" not found'), $userName)); } $memberships = $this->loadMemberships(new User($userName))->select(); $filterEditor = Widget::create('filterEditor')->setQuery($memberships)->setSearchColumns(array('group_name'))->preserveParams('limit', 'sort', 'dir', 'view', 'backend', 'user')->ignoreParams('page')->handleRequest($this->getRequest()); $memberships->applyFilter($filterEditor->getFilter()); $this->setupFilterControl($filterEditor); $this->setupPaginationControl($memberships); $this->setupLimitControl(); $this->setupSortControl(array('group_name' => $this->translate('Group')), $memberships); if ($this->hasPermission('config/authentication/groups/edit')) { $extensibleBackends = $this->loadUserGroupBackends('Icinga\\Data\\Extensible'); $this->view->showCreateMembershipLink = !empty($extensibleBackends); } else { $this->view->showCreateMembershipLink = false; } $this->view->user = $user; $this->view->backend = $backend; $this->view->memberships = $memberships; $this->createShowTabs($backend->getName(), $userName)->activate('user/show'); if ($this->hasPermission('config/authentication/groups/edit')) { $removeForm = new Form(); $removeForm->setUidDisabled(); $removeForm->addElement('hidden', 'user_name', array('isArray' => true, 'value' => $userName, 'decorators' => array('ViewHelper'))); $removeForm->addElement('hidden', 'redirect', array('value' => Url::fromPath('user/show', array('backend' => $backend->getName(), 'user' => $userName)), 'decorators' => array('ViewHelper'))); $removeForm->addElement('button', 'btn_submit', array('escape' => false, 'type' => 'submit', 'class' => 'link-like', 'value' => 'btn_submit', 'decorators' => array('ViewHelper'), 'label' => $this->view->icon('trash'), 'title' => $this->translate('Cancel this membership'))); $this->view->removeForm = $removeForm; } }
/** * Recurse the given form and return the descriptions for it and all of its subforms * * @param Form $form The form to recurse * * @return array */ protected function recurseForm(Form $form) { $descriptions = array($form->getDescriptions()); foreach ($form->getSubForms() as $subForm) { $descriptions[] = $this->recurseForm($subForm); } return call_user_func_array('array_merge', $descriptions); }
/** * Recurse the given form and return the notifications for it and all of its subforms * * @param Form $form The form to recurse * * @return array */ protected function recurseForm(Form $form) { $notifications = $form->getNotifications(); foreach ($form->getSubForms() as $subForm) { $notifications = $notifications + $this->recurseForm($subForm); } return $notifications; }
/** * Validate the resource configuration by trying to connect with it * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidResource(Form $form) { $result = ResourceFactory::createResource(new ConfigObject($form->getValues()))->inspect(); if ($result->hasError()) { $form->addError(sprintf('%s (%s)', $form->translate('Connectivity validation failed, connection to the given resource not possible.'), $result->getError())); } // TODO: display diagnostics in $result->toArray() to the user return !$result->hasError(); }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { $backend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig())); $result = $backend->inspect(); if ($result->hasError()) { $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $result->getError())); } // TODO: display diagnostics in $result->toArray() to the user return !$result->hasError(); }
/** * Validate the resource configuration by trying to connect with it * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidResource(Form $form) { try { $resource = ResourceFactory::createResource(new ConfigObject($form->getValues())); $resource->getConnection()->getConnection(); } catch (Exception $e) { $form->addError($form->translate('Connectivity validation failed, connection to the given resource not possible.')); return false; } return true; }
/** * Recurse the given form and return the notifications for it and all of its subforms * * @param Form $form The form to recurse * * @return array */ protected function recurseForm(Form $form) { $notifications = $form->getNotifications(); foreach ($form->getSubForms() as $subForm) { foreach ($this->recurseForm($subForm) as $type => $messages) { foreach ($messages as $message) { $notifications[$type][] = $message; } } } return $notifications; }
/** * Validate the resource configuration by trying to connect with it * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidResource(Form $form) { try { $resource = ResourceFactory::createResource(new ConfigObject($form->getValues())); $resource->bind(); } catch (Exception $e) { $msg = $form->translate('Connectivity validation failed, connection to the given resource not possible.'); if ($error = $e->getMessage()) { $msg .= ' (' . $error . ')'; } $form->addError($msg); return false; } return true; }
/** * Validate the given form data and check whether a BIND-request is successful * * @param array $data The data to validate * * @return bool */ public function isValid($data) { if (false === parent::isValid($data)) { return false; } return true; }
/** * Validate the given form data and check whether the wizard's requirements are fulfilled * * @param array $data The data to validate * * @return bool */ public function isValid($data) { if (false === parent::isValid($data)) { return false; } return $this->wizard->getRequirements()->fulfilled(); }
/** * Setup the given page that is either going to be displayed or validated * * @param Form $page The page to setup * @param Request $request The current request */ public function setupPage(Form $page, Request $request) { if ($page->getName() === 'setup_requirements') { $page->setRequirements($this->getRequirements()); } elseif ($page->getName() === 'setup_monitoring_summary') { $page->setSummary($this->getSetup()->getSummary()); $page->setSubjectTitle(mt('monitoring', 'the monitoring module', 'setup.summary.subject')); } elseif ($this->getDirection() === static::FORWARD && ($page->getName() === 'setup_monitoring_ido' || $page->getName() === 'setup_monitoring_livestatus')) { if (($authDbResourceData = $this->getPageData('setup_auth_db_resource')) !== null && $authDbResourceData['name'] === $request->getPost('name') || ($configDbResourceData = $this->getPageData('setup_config_db_resource')) !== null && $configDbResourceData['name'] === $request->getPost('name') || ($ldapResourceData = $this->getPageData('setup_ldap_resource')) !== null && $ldapResourceData['name'] === $request->getPost('name')) { $page->error(mt('monitoring', 'The given resource name is already in use.')); } } }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { try { $ldapUserBackend = UserBackend::create(null, new ConfigObject($form->getValues())); $ldapUserBackend->assertAuthenticationPossible(); } catch (AuthenticationException $e) { if (($previous = $e->getPrevious()) !== null) { $form->addError($previous->getMessage()); } else { $form->addError($e->getMessage()); } return false; } catch (Exception $e) { $form->addError(sprintf($form->translate('Unable to validate authentication: %s'), $e->getMessage())); return false; } return true; }
/** * {@inheritdoc} */ public function addSubmitButton() { parent::addSubmitButton(); if (($submit = $this->getElement('btn_submit')) !== null) { $class = $submit->getAttrib('class'); $submit->setAttrib('class', empty($class) ? 'autofocus' : $class . ' autofocus'); } return $this; }
/** * {@inheritdoc} */ public function getRedirectUrl() { $redirectUrl = parent::getRedirectUrl(); // TODO(el): Forms should provide event handling. This is quite hackish $formData = $this->getRequestData(); if ($this->wasSent($formData) && (!$this->getSubmitLabel() || $this->isSubmitted()) && $this->isValid($formData)) { $this->getResponse()->setAutoRefreshInterval(1); } return $redirectUrl; }
/** * {@inheritdoc} * * Values from subforms are directly added to the returned values array instead of being grouped by the subforms' * names. */ public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); foreach (array_keys($this->_subForms) as $name) { // Zend returns values from subforms grouped by their names, but we want them flat $values = array_merge($values, $values[$name]); unset($values[$name]); } return $values; }
/** * {@inheritdoc} */ public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); if ($values['themes_default'] === 'Icinga') { $values['themes_default'] = null; } if (!$values['themes_disabled']) { $values['themes_disabled'] = null; } return $values; }
/** * {@inheritdoc} */ public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); if (isset($values['url']) && $values['url']) { $url = Url::fromPath($values['url']); if (!$url->isExternal() && ($relativePath = $url->getRelativeUrl())) { $values['url'] = $relativePath; } } return $values; }
/** * {@inheritdoc} */ public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); if ($values['themes_default'] === '' || $values['themes_default'] === StyleSheet::DEFAULT_THEME) { $values['themes_default'] = null; } if (!$values['themes_disabled']) { $values['themes_disabled'] = null; } return $values; }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { /** * @var $result Inspection */ $result = UserBackend::create(null, new ConfigObject($form->getValues()))->inspect(); if ($result->hasError()) { $form->addError($result->getError()); } // TODO: display diagnostics in $result->toArray() to the user return !$result->hasError(); }
/** * Recurse the given form and return the descriptions for it and all of its subforms * * @param Form $form The form to recurse * @param mixed $entirelyRequired Set by reference, true means all elements in the hierarchy are * required, false only a partial subset and null none at all * @param bool $elementsPassed Whether there were any elements passed during the recursion until now * * @return array */ protected function recurseForm(Form $form, &$entirelyRequired = null, $elementsPassed = false) { $requiredLabels = array(); if ($form->getRequiredCue() !== null) { $partiallyRequired = $partiallyOptional = false; foreach ($form->getElements() as $element) { if (!in_array($element->getType(), $this->blacklist)) { if (!$element->isRequired()) { $partiallyOptional = true; if ($entirelyRequired) { $entirelyRequired = false; } } else { $partiallyRequired = true; if (($label = $element->getDecorator('label')) !== false) { $requiredLabels[] = $label; } } } } if (!$elementsPassed) { $elementsPassed = $partiallyRequired || $partiallyOptional; if ($entirelyRequired === null && $partiallyRequired) { $entirelyRequired = !$partiallyOptional; } } elseif ($entirelyRequired === null && $partiallyRequired) { $entirelyRequired = false; } } $descriptions = array($form->getDescriptions()); foreach ($form->getSubForms() as $subForm) { $descriptions[] = $this->recurseForm($subForm, $entirelyRequired, $elementsPassed); } if ($entirelyRequired) { foreach ($requiredLabels as $label) { $label->setRequiredSuffix(''); } } return call_user_func_array('array_merge', $descriptions); }
/** * {@inheritdoc} */ public function getValues($suppressArrayNotation = false) { $values = parent::getValues($suppressArrayNotation); if (isset($values['url']) && $values['url']) { $url = Url::fromPath($values['url']); if ($url->getBasePath() === $this->getRequest()->getBasePath()) { $values['url'] = $url->getRelativeUrl(); } else { $values['url'] = $url->getAbsoluteUrl(); } } return $values; }
/** * Validate the given form data and check whether a BIND-request is successful * * @param array $data The data to validate * * @return bool */ public function isValid($data) { if (false === parent::isValid($data)) { return false; } if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) { if (false === LdapResourceForm::isValidResource($this)) { $this->addSkipValidationCheckbox(); return false; } } return true; }
/** * Run the configured backend's inspection checks and show the result, if necessary * * This will only run any validation if the user pushed the 'backend_validation' button. * * @param array $formData * * @return bool */ public function isValidPartial(array $formData) { if (isset($formData['backend_validation']) && parent::isValid($formData)) { if (!$this->validateConfiguration(true)) { return false; } $this->info($this->translate('The configuration has been successfully validated.')); } elseif (!isset($formData['backend_validation'])) { // This is usually done by isValid(Partial), but as we're not calling any of these... $this->populate($formData); } return true; }
/** * {@inheritdoc} */ public function isValid($formData) { $valid = parent::isValid($formData); if (!$valid) { return false; } $oldPasswordEl = $this->getElement('old_password'); if (!$this->backend->authenticate($this->Auth()->getUser(), $oldPasswordEl->getValue())) { $oldPasswordEl->addError($this->translate('Old password is invalid')); $this->markAsError(); return false; } return true; }
/** * Check whether it's possible to connect to the database server * * This will only run the check if the user pushed the 'backend_validation' button. * * @param array $formData * * @return bool */ public function isValidPartial(array $formData) { if (isset($formData['backend_validation']) && parent::isValid($formData)) { try { $db = new DbTool($this->getValues()); $db->checkConnectivity(); } catch (PDOException $e) { $this->warning(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $e->getMessage())); return false; } $this->info($this->translate('The configuration has been successfully validated.')); } return true; }
/** * Validate the given form data and check whether it's possible to connect to the database server * * @param array $data The data to validate * * @return bool */ public function isValid($data) { if (false === parent::isValid($data)) { return false; } if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) { try { $db = new DbTool($this->getValues()); $db->checkConnectivity(); } catch (PDOException $e) { $this->addError($e->getMessage()); $this->addSkipValidationCheckbox(); return false; } } return true; }
/** * Return whether the given values are valid * * @param array $formData The data to validate * * @return bool */ public function isValid($formData) { if (!parent::isValid($formData)) { return false; } if (!isset($formData['skip_validation']) || !$formData['skip_validation']) { $configObject = new ConfigObject($this->getValues()); if (!DbResourceForm::isValidResource($this, $configObject)) { $this->addSkipValidationCheckbox($this->translate('Check this to not to validate connectivity with the given database server.')); return false; } elseif (!BackendConfigForm::isValidIdoSchema($this, $configObject) || !BackendConfigForm::isValidIdoInstance($this, $configObject)) { $this->addSkipValidationCheckbox($this->translate('Check this to not to validate the IDO schema in the given database.')); return false; } } return true; }
/** * Run the configured backend's inspection checks and show the result, if necessary * * This will only run any validation if the user pushed the 'backend_validation' button. * * @param array $formData * * @return bool */ public function isValidPartial(array $formData) { if (isset($formData['backend_validation']) && parent::isValid($formData)) { $inspection = ResourceConfigForm::inspectResource($this); if ($inspection !== null) { $join = function ($e) use(&$join) { return is_string($e) ? $e : join("\n", array_map($join, $e)); }; $this->addElement('note', 'inspection_output', array('order' => 0, 'value' => '<strong>' . $this->translate('Validation Log') . "</strong>\n\n" . join("\n", array_map($join, $inspection->toArray())), 'decorators' => array('ViewHelper', array('HtmlTag', array('tag' => 'pre', 'class' => 'log-output'))))); if ($inspection->hasError()) { $this->warning(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $inspection->getError())); return false; } } $this->info($this->translate('The configuration has been successfully validated.')); } return true; }
/** * Validate the configuration by creating a backend and requesting the user count * * @param Form $form The form to fetch the configuration values from * * @return bool Whether validation succeeded or not */ public static function isValidUserBackend(Form $form) { try { $dbUserBackend = new DbUserBackend(ResourceFactory::createResource($form->getResourceConfig())); if ($dbUserBackend->select()->where('is_active', true)->count() < 1) { $form->addError($form->translate('No active users found under the specified database backend')); return false; } } catch (Exception $e) { $form->addError(sprintf($form->translate('Using the specified backend failed: %s'), $e->getMessage())); return false; } return true; }
public function isValid($data) { if (false === parent::isValid($data)) { return false; } if (false === isset($data['skip_validation']) || $data['skip_validation'] == 0) { $configObject = new ConfigObject($this->getValues()); if (false === DbResourceForm::isValidResource($this, $configObject)) { $this->addSkipValidationCheckbox($this->translate('Check this to not to validate connectivity with the given database server')); return false; } elseif (false === BackendConfigForm::isValidIdoSchema($this, $configObject)) { $this->addSkipValidationCheckbox($this->translate('Check this to not to validate the ido schema')); return false; } elseif (false === BackendConfigForm::isValidIdoInstance($this, $configObject)) { $this->addSkipValidationCheckbox($this->translate('Check this to not to validate the ido instance')); return false; } } return true; }