Exemple #1
0
 /**
  * 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;
 }
 /**
  * Creates the assigned key to the resource
  *
  * @param ResourceConfigForm $form
  *
  * @return bool
  */
 public static function beforeAdd(ResourceConfigForm $form)
 {
     $configDir = Icinga::app()->getConfigDir();
     $user = $form->getElement('user')->getValue();
     $filePath = $configDir . '/ssh/' . $user;
     if (!file_exists($filePath)) {
         $file = File::create($filePath, 0600);
     } else {
         $form->error(sprintf($form->translate('The private key for the user "%s" is already exists.'), $user));
         return false;
     }
     $file->fwrite($form->getElement('private_key')->getValue());
     $form->getElement('private_key')->setValue($configDir . '/ssh/' . $user);
     return true;
 }
 /**
  * Display a confirmation form to remove a resource
  */
 public function removeresourceAction()
 {
     $this->assertPermission('config/application/resources');
     $this->getTabs()->add('resources/remove', array('label' => $this->translate('Remove Resource'), 'url' => Url::fromRequest()))->activate('resources/remove');
     $form = new ConfirmRemovalForm(array('onSuccess' => function ($form) {
         $configForm = new ResourceConfigForm();
         $configForm->setIniConfig(Config::app('resources'));
         $resource = $form->getRequest()->getQuery('resource');
         try {
             $configForm->remove($resource);
         } catch (InvalidArgumentException $e) {
             Notification::error($e->getMessage());
             return false;
         }
         if ($configForm->save()) {
             Notification::success(sprintf(t('Resource "%s" has been successfully removed'), $resource));
         } else {
             return false;
         }
     }));
     $form->setRedirectUrl('config/resource');
     $form->handleRequest();
     // Check if selected resource is currently used for authentication
     $resource = $this->getRequest()->getQuery('resource');
     $authConfig = Config::app('authentication');
     foreach ($authConfig as $backendName => $config) {
         if ($config->get('resource') === $resource) {
             $form->addDescription(sprintf($this->translate('The resource "%s" is currently utilized for authentication by user backend "%s". ' . 'Removing the resource can result in noone being able to log in any longer.'), $resource, $backendName));
         }
     }
     $this->view->form = $form;
     $this->render('resource/remove');
 }
 /**
  * Return whether the configuration is valid
  *
  * @param   bool    $showLog    Whether to show the validation log
  *
  * @return  bool
  */
 protected function validateConfiguration($showLog = false)
 {
     $inspection = ResourceConfigForm::inspectResource($this);
     if ($inspection !== null) {
         if ($showLog) {
             $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->error(sprintf($this->translate('Failed to successfully validate the configuration: %s'), $inspection->getError()));
             return false;
         }
     }
     $configObject = new ConfigObject($this->getValues());
     if (!BackendConfigForm::isValidIdoSchema($this, $configObject) || !BackendConfigForm::isValidIdoInstance($this, $configObject)) {
         return false;
     }
     if ($this->getValue('db') === 'pgsql') {
         $db = new DbTool($this->getValues());
         $version = $db->connectToDb()->getServerVersion();
         if (version_compare($version, '9.1', '<')) {
             $this->error($this->translate(sprintf('The server\'s version %s is too old. The minimum required version is %s.', $version, '9.1')));
             return false;
         }
     }
     return true;
 }