Merge branch 'master' into bugfix/drop-zend-config-7147

This commit is contained in:
Johannes Meyer 2014-11-07 14:07:15 +01:00
commit 124f64ad89
13 changed files with 126 additions and 24 deletions

View File

@ -72,10 +72,7 @@ class LdapUserBackend extends UserBackend
$q = $this->conn->select()->from($this->userClass); $q = $this->conn->select()->from($this->userClass);
$result = $q->fetchRow(); $result = $q->fetchRow();
} catch (LdapException $e) { } catch (LdapException $e) {
throw new AuthenticationException( throw new AuthenticationException('Connection not possible.', $e);
'Connection not possible: %s',
$e->getMessage()
);
} }
if (! isset($result)) { if (! isset($result)) {
@ -166,7 +163,7 @@ class LdapUserBackend extends UserBackend
} catch (AuthenticationException $e) { } catch (AuthenticationException $e) {
// Authentication not possible // Authentication not possible
throw new AuthenticationException( throw new AuthenticationException(
'Authentication against backend "%s" not possible: %s', 'Authentication against backend "%s" not possible.',
$this->getName(), $this->getName(),
$e $e
); );

View File

@ -335,9 +335,9 @@ class Connection
public function testCredentials($username, $password) public function testCredentials($username, $password)
{ {
$ds = $this->prepareNewConnection(); $this->connect();
$r = @ldap_bind($ds, $username, $password); $r = @ldap_bind($this->ds, $username, $password);
if ($r) { if ($r) {
Logger::debug( Logger::debug(
'Successfully tested LDAP credentials (%s / %s)', 'Successfully tested LDAP credentials (%s / %s)',
@ -350,7 +350,7 @@ class Connection
'Testing LDAP credentials (%s / %s) failed: %s', 'Testing LDAP credentials (%s / %s) failed: %s',
$username, $username,
'***', '***',
ldap_error($ds) ldap_error($this->ds)
); );
return false; return false;
} }
@ -387,7 +387,19 @@ class Connection
} }
$ds = ldap_connect($this->hostname, $this->port); $ds = ldap_connect($this->hostname, $this->port);
list($cap, $namingContexts) = $this->discoverCapabilities($ds); try {
$capabilities = $this->discoverCapabilities($ds);
list($cap, $namingContexts) = $capabilities;
} catch (LdapException $e) {
// discovery failed, guess defaults
$cap = (object) array(
'supports_ldapv3' => true,
'supports_starttls' => false,
'msCapabilities' => array()
);
$namingContexts = null;
}
$this->capabilities = $cap; $this->capabilities = $cap;
$this->namingContexts = $namingContexts; $this->namingContexts = $namingContexts;
@ -625,7 +637,8 @@ class Connection
if (! $result) { if (! $result) {
throw new LdapException( throw new LdapException(
sprintf( sprintf(
'Capability query failed (%s:%d): %s', 'Capability query failed (%s:%d): %s. Check if hostname and port of the ldap resource are correct '
. ' and if anonymous access is permitted.',
$this->hostname, $this->hostname,
$this->port, $this->port,
ldap_error($ds) ldap_error($ds)
@ -633,6 +646,16 @@ class Connection
); );
} }
$entry = ldap_first_entry($ds, $result); $entry = ldap_first_entry($ds, $result);
if ($entry === false) {
throw new LdapException(
sprintf(
'Capabilities not available (%s:%d): %s. Discovery of root DSE probably not permitted.',
$this->hostname,
$this->port,
ldap_error($ds)
)
);
}
$cap = (object) array( $cap = (object) array(
'supports_ldapv3' => false, 'supports_ldapv3' => false,
@ -640,10 +663,6 @@ class Connection
'msCapabilities' => array() 'msCapabilities' => array()
); );
if ($entry === false) {
// TODO: Is it OK to have no capabilities?
return false;
}
$ldapAttributes = ldap_get_attributes($ds, $entry); $ldapAttributes = ldap_get_attributes($ds, $entry);
$result = $this->cleanupAttributes($ldapAttributes); $result = $this->cleanupAttributes($ldapAttributes);
$cap->supports_ldapv3 = $this->hasCapabilityLdapV3($result); $cap->supports_ldapv3 = $this->hasCapabilityLdapV3($result);

View File

@ -296,7 +296,7 @@ class Monitoring_ListController extends Controller
->order('downtime_scheduled_start', 'DESC'); ->order('downtime_scheduled_start', 'DESC');
$this->applyFilters($query); $this->applyFilters($query);
$this->view->downtimes = $query->paginate();
$this->setupSortControl(array( $this->setupSortControl(array(
'downtime_is_in_effect' => $this->translate('Is In Effect'), 'downtime_is_in_effect' => $this->translate('Is In Effect'),
'downtime_host' => $this->translate('Host / Service'), 'downtime_host' => $this->translate('Host / Service'),
@ -308,6 +308,8 @@ class Monitoring_ListController extends Controller
'downtime_scheduled_end' => $this->translate('Scheduled End'), 'downtime_scheduled_end' => $this->translate('Scheduled End'),
'downtime_duration' => $this->translate('Duration'), 'downtime_duration' => $this->translate('Duration'),
)); ));
$this->view->downtimes = $query->paginate();
$this->view->delDowntimeForm = new DeleteDowntimeCommandForm(); $this->view->delDowntimeForm = new DeleteDowntimeCommandForm();
} }

View File

@ -0,0 +1,55 @@
<?php
class Zend_View_Helper_Customvar extends Zend_View_Helper_Abstract
{
/**
* Create dispatch instance
*
* @return self
*/
public function checkPerformance()
{
return $this;
}
public function customvar($struct)
{
if (is_string($struct) || is_int($struct) || is_float($struct)) {
return $this->view->escape((string) $struct);
} elseif (is_array($struct)) {
return $this->renderArray($struct);
} elseif (is_object($struct)) {
return $this->renderObject($struct);
}
}
protected function renderArray($array)
{
if (empty($array)) {
return '[]';
}
$out = "<ul>\n";
foreach ($array as $val) {
$out .= '<li>' . $this->customvar($val) . "</li>\n";
}
return $out . "</ul>\n";
}
protected function renderObject($object)
{
if (empty($object)) {
return '{}';
}
$out = "{<ul>\n";
foreach ($object as $key => $val) {
$out .= '<li>'
. $this->view->escape($key)
. ' => '
. $this->customvar($val)
. "</li>\n";
}
return $out . "</ul>}";
}
}

View File

@ -67,4 +67,6 @@
<?php endforeach; ?> <?php endforeach; ?>
</tbody> </tbody>
</table> </table>
<h1><?= $this->translate('Resources'); ?></h1>
<a href="<?= $this->href('config/resource'); ?>"><?= $this->translate('Jump to resource configuration'); ?></a>
</div> </div>

View File

@ -3,6 +3,9 @@
<?= $this->tabs->render($this); ?> <?= $this->tabs->render($this); ?>
<div style="margin: 1em" class="dontprint"> <div style="margin: 1em" class="dontprint">
<?= $this->translate('Sort by'); ?> <?= $this->sortControl->render($this); ?> <?= $this->translate('Sort by'); ?> <?= $this->sortControl->render($this); ?>
<?php if (! $this->filterEditor): ?>
<?= $this->filterPreview ?>
<?php endif; ?>
</div> </div>
<?= $this->widget('limiter', array('url' => $this->url, 'max' => $downtimes->count())); ?> <?= $this->widget('limiter', array('url' => $this->url, 'max' => $downtimes->count())); ?>
<?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?> <?= $this->paginationControl($downtimes, null, null, array('preserve' => $this->preserve)); ?>
@ -10,6 +13,7 @@
<?php endif ?> <?php endif ?>
<div class="content"> <div class="content">
<?= $this->filterEditor ?>
<?php if (empty($downtimes)): ?> <?php if (empty($downtimes)): ?>
<?= $this->translate('No downtimes matching the filter'); ?> <?= $this->translate('No downtimes matching the filter'); ?>
</div> </div>

View File

@ -1,8 +1,11 @@
<?php <?php
foreach ($object->customvars as $name => $value) { foreach ($object->customvars as $name => $value) {
printf( printf(
"<tr><th>%s</th><td>%s</td></tr>\n", '<tr><th>%s</th><td class="customvar">%s</td></tr>' . "\n",
$this->escape($name), $this->escape($name),
$this->escape($value) $this->customvar($value)
); );
} }

View File

@ -10,6 +10,7 @@ class CustomvarQuery extends IdoQuery
'customvars' => array( 'customvars' => array(
'varname' => 'cvs.varname', 'varname' => 'cvs.varname',
'varvalue' => 'cvs.varvalue', 'varvalue' => 'cvs.varvalue',
'is_json' => 'cvs.is_json',
), ),
'objects' => array( 'objects' => array(
'host' => 'cvo.name1 COLLATE latin1_general_ci', 'host' => 'cvo.name1 COLLATE latin1_general_ci',
@ -37,6 +38,10 @@ class CustomvarQuery extends IdoQuery
protected function joinBaseTables() protected function joinBaseTables()
{ {
if (version_compare($this->getIdoVersion(), '1.12.0', '<')) {
$this->columnMap['customvars']['is_json'] = '(0)';
}
$this->select->from( $this->select->from(
array('cvs' => $this->prefix . 'customvariablestatus'), array('cvs' => $this->prefix . 'customvariablestatus'),
array() array()

View File

@ -16,6 +16,7 @@ class DowntimeQuery extends IdoQuery
protected $columnMap = array( protected $columnMap = array(
'downtime' => array( 'downtime' => array(
'downtime_author' => 'sd.author_name', 'downtime_author' => 'sd.author_name',
'author' => 'sd.author_name',
'downtime_comment' => 'sd.comment_data', 'downtime_comment' => 'sd.comment_data',
'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)', 'downtime_entry_time' => 'UNIX_TIMESTAMP(sd.entry_time)',
'downtime_is_fixed' => 'sd.is_fixed', 'downtime_is_fixed' => 'sd.is_fixed',

View File

@ -19,6 +19,7 @@ class Customvar extends DataView
return array( return array(
'varname', 'varname',
'varvalue', 'varvalue',
'is_json',
'object_type' 'object_type'
); );
} }

View File

@ -16,6 +16,7 @@ class Downtime extends DataView
return array( return array(
'downtime_objecttype', 'downtime_objecttype',
'downtime_author', 'downtime_author',
'author',
'downtime_comment', 'downtime_comment',
'downtime_entry_time', 'downtime_entry_time',
'downtime_is_fixed', 'downtime_is_fixed',

View File

@ -283,7 +283,8 @@ abstract class MonitoredObject
$query = $this->backend->select()->from('customvar', array( $query = $this->backend->select()->from('customvar', array(
'varname', 'varname',
'varvalue' 'varvalue',
'is_json'
)) ))
->where('object_type', $this->type) ->where('object_type', $this->type)
->where('host_name', $this->host_name); ->where('host_name', $this->host_name);
@ -293,13 +294,16 @@ abstract class MonitoredObject
$this->customvars = array(); $this->customvars = array();
$customvars = $query->getQuery()->fetchPairs(); $customvars = $query->getQuery()->fetchAll();
foreach ($customvars as $name => $value) { foreach ($customvars as $name => $cv) {
$name = ucwords(str_replace('_', ' ', strtolower($name))); $name = ucwords(str_replace('_', ' ', strtolower($cv->varname)));
if ($blacklistPattern && preg_match($blacklistPattern, $name)) { if ($blacklistPattern && preg_match($blacklistPattern, $cv->varname)) {
$value = '***'; $this->customvars[$name] = '***';
} elseif ($cv->is_json) {
$this->customvars[$name] = json_decode($cv->varvalue);
} else {
$this->customvars[$name] = $cv->varvalue;
} }
$this->customvars[$name] = $value;
} }
return $this; return $this;

View File

@ -158,3 +158,11 @@ form.instance-features span.description, form.object-features span.description {
margin: 0 10px 0 0; margin: 0 10px 0 0;
border-spacing: 10px 10px; border-spacing: 10px 10px;
} }
table.avp .customvar ul {
list-style-type: none;
margin: 0;
padding: 0;
padding-left: 1.5em;
}