Commit 158256a1 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes: #2668 ldapdump fonctionnality should be moved into is own plugin

parent f4326678
<?php
class ldapDump extends simplePlugin
{
static function plInfo()
{
return array(
'plShortName' => _('LDAP'),
'plDescription' => _('LDAP Dump'),
'plObjectType' => array('special'),
'plPriority' => 99,
'plProvidedAcls' => parent::generatePlProvidedAcls(self::getAttributesInfo())
);
}
static function getAttributesInfo ()
{
return array(
'main' => array(
'name' => _('LDAP Dump'),
'class' => array('fullwidth'),
'attrs' => array(
new FakeAttribute('dump')
),
'template' => get_template_path('ldapdump.tpl', TRUE, dirname(__FILE__))
),
);
}
function __construct(&$config, $dn = NULL, $object = NULL)
{
parent::__construct($config, $dn, $object);
$this->dump = NULL;
}
function execute()
{
if ($this->dump === NULL) {
$ui = get_userinfo();
if (preg_match('/r/', $ui->get_category_permissions($this->acl_base, 'all'))) {
$ldap = $this->config->get_ldap_link();
$ldap->cat($this->dn);
if ($attrs = $ldap->fetch()) {
$this->dump = array($this->dumpLdapNode($attrs, $this->config->current['BASE']));
} else {
$this->dump = array();
}
} else {
$this->dump = FALSE;
}
}
$smarty = get_smarty();
$smarty->assign('usePrototype', 'true');
return parent::execute();
}
function dumpLdapNode($attrs, $parent_dn = '')
{
$node = array(
'dn' => $attrs['dn'],
'name' => preg_replace('/,'.preg_quote($parent_dn).'$/', '', $attrs['dn']),
'attrs' => array(),
'subnodes' => array(),
);
for ($i = 0; $i < $attrs['count']; $i++) {
$key = $attrs[$i];
$node['attrs'][$key] = $attrs[$key];
unset($node['attrs'][$key]['count']);
}
$ldap = $this->config->get_ldap_link();
$ldap->cd($attrs['dn']);
$ldap->ls();
while ($attrs = $ldap->fetch()) {
$node['subnodes'][$attrs['dn']] = $this->dumpLdapNode($attrs, $node['dn']);
}
return $node;
}
}
?>
<div id="{$sectionId}" class="plugin_section{$sectionClasses}">
<span class="legend">
{$section}
</span>
<div>
{if $attributes.dump}
{function name=printNodes}
<ul>
{foreach from=$nodes key=key item=node}
{if isset($node.img)}
<li style="list-style-image:url('{$node.img}');">
{else}
<li>
{/if}
<a href="#" onclick="Effect.toggle('toggle_{$key}', 'blind', {literal}{ duration: 0.3 }{/literal}); return false;">
{$node.name}
</a>
<div id="toggle_{$key}" style="overflow: visible; display: none;">
<table class="listingTable">
<tbody>
{foreach from=$node.attrs key=label item=values}
{foreach from=$values item=value}
<tr>
<th>{$label}</th>
<td>{$value}</td>
</tr>
{/foreach}
{/foreach}
</tbody>
</table>
</div>
{call name=printNodes nodes=$node.subnodes}
</li>
{/foreach}
</ul>
{/function}
{call name=printNodes nodes=$attributes.dump}
{else}
<img alt="{t}Insufficient rights{/t}" src="images/small-error.png" class="center"/>&nbsp;
<b>You have insufficient rights for using this tab</b>
{/if}
</div>
</div>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment