Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/unnecessary-joins-8614
Browse files Browse the repository at this point in the history
  • Loading branch information
lippserd committed Mar 11, 2015
2 parents 0286641 + ba0154a commit 2286ab1
Show file tree
Hide file tree
Showing 78 changed files with 1,989 additions and 715 deletions.
5 changes: 3 additions & 2 deletions AUTHORS
@@ -1,5 +1,6 @@
Alexander Fuhr <alexander.fuhr@netways.de>
Alexander Klimov <alexander.klimov@netways.de>
ayoubabid <ayoubabid@users.noreply.github.com>
baufrecht <baufrecht@users.noreply.github.com>
Bernd Erk <bernd.erk@icinga.org>
Boden Garman <boden.garman@spintel.net.au>
Expand All @@ -11,8 +12,9 @@ Goran Rakic <grakic@devbase.net>
Gunnar Beutner <gunnar.beutner@netways.de>
Jannis Moßhammer <jannis.mosshammer@netways.de>
Johannes Meyer <johannes.meyer@netways.de>
Marius Hein <marius.hein@netways.de>
Louis Sautier <sautier.louis@gmail.com>
Marcus Cobden <marcus@marcuscobden.co.uk>
Marius Hein <marius.hein@netways.de>
Markus Frosch <markus@lazyfrosch.de>
Matthias Jentsch <matthias.jentsch@netways.de>
Michael Friedrich <michael.friedrich@netways.de>
Expand All @@ -22,4 +24,3 @@ Sylph Lin <sylph.lin@gmail.com>
Thomas Gelf <thomas.gelf@netways.de>
Tom Ford <exptom@users.noreply.github.com>
Ulf Lange <mopp@gmx.net>
ayoubabid <ayoubabid@users.noreply.github.com>
20 changes: 10 additions & 10 deletions application/controllers/ConfigController.php
Expand Up @@ -135,22 +135,23 @@ public function modulesAction()

public function moduleAction()
{
$name = $this->getParam('name');
$app = Icinga::app();
$manager = $app->getModuleManager();
$name = $this->getParam('name');
if ($manager->hasInstalled($name)) {
$this->view->moduleData = Icinga::app()
->getModuleManager()
->select()
->from('modules')
->where('name', $name)
->fetchRow();
$module = new Module($app, $name, $manager->getModuleDir($name));
$this->view->moduleData = $manager->select()->from('modules')->where('name', $name)->fetchRow();
if ($manager->hasLoaded($name)) {
$module = $manager->getModule($name);
} else {
$module = new Module($app, $name, $manager->getModuleDir($name));
}

$this->view->module = $module;
$this->view->tabs = $module->getConfigTabs()->activate('info');
} else {
$this->view->module = false;
$this->view->tabs = null;
}
$this->view->tabs = $module->getConfigTabs()->activate('info');
}

/**
Expand All @@ -163,7 +164,6 @@ public function moduleenableAction()
$manager = Icinga::app()->getModuleManager();
try {
$manager->enableModule($module);
$manager->loadModule($module);
Notification::success(sprintf($this->translate('Module "%s" enabled'), $module));
$this->rerenderLayout()->reloadCss()->redirectNow('config/modules');
} catch (Exception $e) {
Expand Down
Expand Up @@ -53,7 +53,7 @@ public function createElements(array $formData)
return @preg_match($value, '') !== false;
});
$callbackValidator->setMessage(
$this->translate('"%value%" is not a valid regular expression'),
$this->translate('"%value%" is not a valid regular expression.'),
Zend_Validate_Callback::INVALID_VALUE
);
$this->addElement(
Expand All @@ -62,9 +62,10 @@ public function createElements(array $formData)
array(
'label' => $this->translate('Filter Pattern'),
'description' => $this->translate(
'The regular expression to use to strip specific parts off from usernames.'
. ' Leave empty if you do not want to strip off anything'
'The filter to use to strip specific parts off from usernames.'
. ' Leave empty if you do not want to strip off anything.'
),
'requirement' => $this->translate('The filter pattern must be a valid regular expression.'),
'validators' => array($callbackValidator)
)
);
Expand Down
58 changes: 48 additions & 10 deletions application/forms/Config/Authentication/LdapBackendForm.php
Expand Up @@ -55,7 +55,7 @@ public function createElements(array $formData)
'required' => true,
'label' => $this->translate('Backend Name'),
'description' => $this->translate(
'The name of this authentication provider that is used to differentiate it from others'
'The name of this authentication provider that is used to differentiate it from others.'
)
)
);
Expand All @@ -64,8 +64,10 @@ public function createElements(array $formData)
'resource',
array(
'required' => true,
'label' => $this->translate('LDAP Resource'),
'description' => $this->translate('The resource to use for authenticating with this provider'),
'label' => $this->translate('LDAP Connection'),
'description' => $this->translate(
'The LDAP connection to use for authenticating with this provider.'
),
'multiOptions' => false === empty($this->resources)
? array_combine($this->resources, $this->resources)
: array()
Expand All @@ -77,18 +79,48 @@ public function createElements(array $formData)
array(
'required' => true,
'label' => $this->translate('LDAP User Object Class'),
'description' => $this->translate('The object class used for storing users on the ldap server'),
'description' => $this->translate('The object class used for storing users on the LDAP server.'),
'value' => 'inetOrgPerson'
)
);
$this->addElement(
'text',
'filter',
array(
'allowEmpty' => true,
'label' => $this->translate('LDAP Filter'),
'description' => $this->translate(
'An additional filter to use when looking up users using the specified connection. '
. 'Leave empty to not to use any additional filter rules.'
),
'requirement' => $this->translate(
'The filter needs to be expressed as standard LDAP expression, without'
. ' outer parentheses. (e.g. &(foo=bar)(bar=foo) or foo=bar)'
),
'validators' => array(
array(
'Callback',
false,
array(
'callback' => function ($v) {
return strpos($v, '(') !== 0;
},
'messages' => array(
'callbackValue' => $this->translate('The filter must not be wrapped in parantheses.')
)
)
)
)
)
);
$this->addElement(
'text',
'user_name_attribute',
array(
'required' => true,
'label' => $this->translate('LDAP User Name Attribute'),
'description' => $this->translate(
'The attribute name used for storing the user name on the ldap server'
'The attribute name used for storing the user name on the LDAP server.'
),
'value' => 'uid'
)
Expand All @@ -106,10 +138,10 @@ public function createElements(array $formData)
'base_dn',
array(
'required' => false,
'label' => $this->translate('Base DN'),
'label' => $this->translate('LDAP Base DN'),
'description' => $this->translate(
'The path where users can be found on the ldap server. Leave ' .
'empty to select all users available on the specified resource.'
'The path where users can be found on the LDAP server. Leave ' .
'empty to select all users available using the specified connection.'
)
)
);
Expand Down Expand Up @@ -142,11 +174,17 @@ public static function isValidAuthenticationBackend(Form $form)
ResourceFactory::createResource($form->getResourceConfig()),
$form->getElement('user_class')->getValue(),
$form->getElement('user_name_attribute')->getValue(),
$form->getElement('base_dn')->getValue()
$form->getElement('base_dn')->getValue(),
$form->getElement('filter')->getValue()
);
$ldapUserBackend->assertAuthenticationPossible();
} catch (AuthenticationException $e) {
$form->addError($e->getMessage());
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()));
Expand Down
1 change: 1 addition & 0 deletions application/forms/Config/General/LoggingConfigForm.php
Expand Up @@ -66,6 +66,7 @@ public function createElements(array $formData)
'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(
Expand Down
12 changes: 11 additions & 1 deletion application/forms/Config/Resource/FileResourceForm.php
Expand Up @@ -3,6 +3,7 @@

namespace Icinga\Forms\Config\Resource;

use Zend_Validate_Callback;
use Icinga\Web\Form;

/**
Expand Down Expand Up @@ -42,13 +43,22 @@ public function createElements(array $formData)
'validators' => array('ReadablePathValidator')
)
);
$callbackValidator = new Zend_Validate_Callback(function ($value) {
return @preg_match($value, '') !== false;
});
$callbackValidator->setMessage(
$this->translate('"%value%" is not a valid regular expression.'),
Zend_Validate_Callback::INVALID_VALUE
);
$this->addElement(
'text',
'fields',
array(
'required' => true,
'label' => $this->translate('Pattern'),
'description' => $this->translate('The regular expression by which to identify columns')
'description' => $this->translate('The pattern by which to identify columns.'),
'requirement' => $this->translate('The column pattern must be a valid regular expression.'),
'validators' => array($callbackValidator)
)
);

Expand Down
11 changes: 10 additions & 1 deletion application/layouts/scripts/body.phtml
Expand Up @@ -29,7 +29,16 @@ if ($notifications->hasMessages()) {
}
?></ul>
<div id="logo" data-base-target="_main">
<img aria-hidden="true" src="<?= $this->href('img/logo_icinga-inv.png') ?>" class="logo" alt="<?= t('Dashboard') ?>" />
<?= $this->qlink(
'',
'/dashboard',
null,
array(
'icon' => '../logo_icinga-inv.png',
'aria-hidden' => 'true',
'tabindex' => -1
)
); ?>
</div>
</div>

Expand Down
6 changes: 3 additions & 3 deletions application/views/scripts/config/module.phtml
Expand Up @@ -2,9 +2,6 @@
<?= $this->tabs ?>
</div>
<div class="content">
<h1 tabindex="-1">
<?= $this->escape($module->getTitle()) ?>
</h1>
<?php if (! $module): ?>
<?= $this->translate('There is no such module installed.') ?>
<?php return; endif ?>
Expand All @@ -14,6 +11,9 @@
$permissions = $module->getProvidedPermissions();
$state = $moduleData->enabled ? ($moduleData->loaded ? 'enabled' : 'failed') : 'disabled'
?>
<h1 tabindex="-1">
<?= $this->escape($module->getTitle()) ?>
</h1>
<table class="avp">
<tr>
<th><?= $this->escape($this->translate('Name')) ?></th>
Expand Down
2 changes: 1 addition & 1 deletion library/Icinga/Application/Modules/Manager.php
Expand Up @@ -252,7 +252,7 @@ public function enableModule($name)
}

/**
* Disable the given module and remove it's enabled state
* Disable the given module and remove its enabled state
*
* @param string $name The name of the module to disable
*
Expand Down
25 changes: 24 additions & 1 deletion library/Icinga/Application/Modules/Module.php
Expand Up @@ -113,6 +113,13 @@ class Module
*/
private $triedToLaunchConfigScript = false;

/**
* Whether this module has been registered
*
* @var bool
*/
private $registered = false;

/**
* Provided permissions
*
Expand Down Expand Up @@ -279,6 +286,10 @@ public function __construct(ApplicationBootstrap $app, $name, $basedir)
*/
public function register()
{
if ($this->registered) {
return true;
}

$this->registerAutoloader();
try {
$this->launchRunScript();
Expand All @@ -291,10 +302,22 @@ public function register()
);
return false;
}

$this->registerWebIntegration();
$this->registered = true;
return true;
}

/**
* Return whether this module has been registered
*
* @return bool
*/
public function isRegistered()
{
return $this->registered;
}

/**
* Test for an enabled module by name
*
Expand Down Expand Up @@ -913,7 +936,7 @@ protected function includeScript($file)
*/
protected function launchConfigScript()
{
if ($this->triedToLaunchConfigScript) {
if ($this->triedToLaunchConfigScript || !$this->registered) {
return;
}
$this->triedToLaunchConfigScript = true;
Expand Down
15 changes: 10 additions & 5 deletions library/Icinga/Application/Platform.php
Expand Up @@ -182,19 +182,24 @@ public static function getPhpConfig($option)
}

/**
* Return whether the given Zend framework class exists
* Return whether the given class exists
*
* @param string $name The name of the class to check
*
* @return bool
*/
public static function zendClassExists($name)
public static function classExists($name)
{
if (@class_exists($name)) {
return true;
}

return (@include str_replace('_', '/', $name) . '.php') !== false;
if (strpos($name, '_') !== false) {
// Assume it's a Zend-Framework class
return (@include str_replace('_', '/', $name) . '.php') !== false;
}

return false;
}

/**
Expand All @@ -206,7 +211,7 @@ public static function zendClassExists($name)
*/
public static function hasMysqlSupport()
{
return static::extensionLoaded('mysql') && static::zendClassExists('Zend_Db_Adapter_Pdo_Mysql');
return static::extensionLoaded('mysql') && static::classExists('Zend_Db_Adapter_Pdo_Mysql');
}

/**
Expand All @@ -218,6 +223,6 @@ public static function hasMysqlSupport()
*/
public static function hasPostgresqlSupport()
{
return static::extensionLoaded('pgsql') && static::zendClassExists('Zend_Db_Adapter_Pdo_Pgsql');
return static::extensionLoaded('pgsql') && static::classExists('Zend_Db_Adapter_Pdo_Pgsql');
}
}
7 changes: 6 additions & 1 deletion library/Icinga/Authentication/Backend/DbUserBackend.php
Expand Up @@ -96,10 +96,15 @@ protected function getPasswordHash($username)
'SELECT password_hash FROM icingaweb_user WHERE name = :name AND active = 1'
);
}

$stmt->execute(array(':name' => $username));
$stmt->bindColumn(1, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);
return is_resource($lob) ? stream_get_contents($lob) : $lob;
if (is_resource($lob)) {
$lob = stream_get_contents($lob);
}

return $this->conn->getDbType() === 'pgsql' ? pg_unescape_bytea($lob) : $lob;
}

/**
Expand Down

0 comments on commit 2286ab1

Please sign in to comment.