Skip to content

Commit

Permalink
Move all resource types into subforms
Browse files Browse the repository at this point in the history
refs #6141
  • Loading branch information
majentsch committed May 21, 2014
1 parent c3ef81f commit 4df6133
Show file tree
Hide file tree
Showing 9 changed files with 515 additions and 244 deletions.
2 changes: 1 addition & 1 deletion application/controllers/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function editresourceAction()
if ($oldName !== $name) {
unset($resources->{$oldName});
}
$resources->{$name} = $form->getConfig();
$resources->$name = $form->getConfig();
if ($this->writeConfigFile($resources, 'resources')) {
$this->addSuccessMessage('Resource "' . $name . '" edited.');
$this->redirectNow("config/resource");
Expand Down
1 change: 1 addition & 0 deletions application/controllers/InstallController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public function indexAction()
$wizard = $this->createWizard();

if ($wizard->isSubmittedAndValid()) {
var_dump($wizard->getValues());
$wizard->navigate();
if ($wizard->isFinished()) {
// TODO: Run the installer (Who creates an installer? How do we handle module installers?)
Expand Down
79 changes: 42 additions & 37 deletions application/forms/Config/Resource/DbResourceForm.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Created by PhpStorm.
* User: mjentsch
* Date: 19.05.14
* Time: 17:13
* This file is part of Icinga Web 2.
*
* Icinga Web 2 - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Form\Config\Resource;

Expand All @@ -17,37 +38,7 @@
/**
* Contains the properties needed to create a basic SQL-Database resource.
*/
class DbResourceForm extends Form {

private $resource = null;

/**
* Set the resource configuration to edit.
*
* @param Zend_Config $resource The config to set
*/
public function setResource(Zend_Config $resource)
{
$this->resource = $resource;
}

public function getResource()
{
return $this->resource;
}

public function getConfig()
{
$values = $this->getValues();
$result = array();
foreach ($values as $key => $value) {
$configKey = explode('_', $key, 3);
if (count($configKey) === 3) {
$result[$configKey[2]] = $value;
}
}
return new Zend_Config($result);
}
class DbResourceForm extends ResourceBaseForm {

public function create() {
$this->addElement(
Expand Down Expand Up @@ -124,15 +115,29 @@ public function create() {
);
}

public function getConfig()
{
$values = $this->getValues();
return new Zend_Config(array(
'type' => 'db',
'db' => $values['resource_db_db'],
'host' => $values['resource_db_host'],
'port' => $values['resource_db_port'],
'password' => $values['resource_db_password'],
'username' => $values['resource_db_username'],
'dbname' => $values['resource_db_dbname']
));
}

/**
* Test if this is a valid resource.
*
* @return bool
*/
public function isValidResource()
public function isValidResource($data)
{
try {
$config = $this->getConfig();
$config = $this->createConfig($data);
/*
* It should be possible to run icingaweb without the pgsql or mysql extension or Zend-Pdo-Classes,
* in case they aren't actually used. When the user tries to create a resource that depends on an
Expand Down
83 changes: 83 additions & 0 deletions application/forms/Config/Resource/FileResourceForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga Web 2.
*
* Icinga Web 2 - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Form\Config\Resource;

use Icinga\Web\Form;

/**
* Contains the properties needed to create a basic LDAP resource.
*/
class FileResourceForm extends ResourceBaseForm {

public function create() {
$this->addElement(
'text',
'resource_file_filename',
array(
'required' => true,
'label' => t('Filepath'),
'helptext' => t('The filename to fetch information from'),
'value' => $this->getResource()->get('filename', '')
)
);

$this->addElement(
'text',
'resource_file_fields',
array(
'required' => true,
'label' => t('Pattern'),
'helptext' => t('The regular expression by which to identify columns'),
'value' => $this->getResource()->get('fields', '')
)
);
}

public function isValidResource() {
$config = $this->getConfig();

if (!file_exists($config->filename)) {
$this->addErrorMessage(
t('Connectivity validation failed, the provided file does not exist.')
);
return false;
}
}

public function getConfig()
{
$values = $this->getValues();
return new Zend_Config(array(
'type' => 'file',
'root_dn' => $values['resource_file_filename'],
'hostname' => $values['resource_file_fields']
));
}
}
87 changes: 36 additions & 51 deletions application/forms/Config/Resource/LdapResourceForm.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,42 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* Created by PhpStorm.
* User: mjentsch
* Date: 19.05.14
* Time: 17:22
* This file is part of Icinga Web 2.
*
* Icinga Web 2 - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*
*/
// {{{ICINGA_LICENSE_HEADER}}}


namespace Icinga\Form\Config\Resource;

use Exception;
use Icinga\Web\Form;
use Zend_Config;

/**
* Contains the properties needed to create a basic LDAP resource.
*/
class LdapResourceForm extends Form {

private $resource = null;

/**
* Set the resource configuration to edit.
*
* @param Zend_Config $resource The config to set
*/
public function setResource(Zend_Config $resource)
{
$this->resource = $resource;
}

public function getResource()
{
return $this->resource;
}

public function getConfig()
{
$values = $this->getValues();
$result = array();
foreach ($values as $key => $value) {
$configKey = explode('_', $key, 3);
if (count($configKey) === 3) {
$result[$configKey[2]] = $value;
}
}
return new Zend_Config($result);
}
class LdapResourceForm extends ResourceBaseForm {

public function create() {
$this->addElement(
Expand Down Expand Up @@ -95,21 +86,15 @@ public function create() {
);
}

/**
* Test if this is a valid resource.
*
* @return bool
*/
public function isValidResource()
public function getConfig()
{
$config = $this->getConfig();
try {
$resource = ResourceFactory::createResource($config);
$resource->connect();
} catch (Exception $e) {
$this->addErrorMessage(t('Connectivity validation failed, connection to the given resource not possible.'));
return false;
}
return true;
$values = $this->getValues();
return new Zend_Config(array(
'type' => 'ldap',
'hostname' => $values['resource_ldap_hostname'],
'root_dn' => $values['resource_ldap_root_dn'],
'bind_dn' => $values['resource_ldap_bind_dn'],
'bind_pw' => $values['resource_ldap_bind_pw']
));
}
}

0 comments on commit 4df6133

Please sign in to comment.