コード例 #1
0
ファイル: rdelete.php プロジェクト: dannylsl/phpLDAPadmin
function pla_rdelete($server, $dn)
{
    # We delete all children, not only the visible children in the tree
    $children = $server->getContainerContents($dn, null, 0, '(objectClass=*)', LDAP_DEREF_NEVER);
    if (!is_array($children) || count($children) == 0) {
        printf('<span style="white-space: nowrap;">%s %s...', _('Deleting'), $dn);
        if ($server->delete($dn)) {
            printf(' <span style="color:green">%s</span></span><br />', _('Success'));
            return true;
        } else {
            system_message(array('title' => _('Could not delete the entry.') . sprintf(' (%s)', pretty_print_dn($dn)), 'body' => ldap_error_msg($server->getErrorMessage(null), $server->getErrorNum(null)), 'type' => 'error'));
        }
    } else {
        foreach ($children as $child_dn) {
            pla_rdelete($server, $child_dn);
        }
        printf('<span style="white-space: nowrap;">%s %s...', _('Deleting'), $dn);
        if ($server->delete($dn)) {
            printf(' <span style="color:green">%s</span></span><br />', _('Success'));
            return true;
        } else {
            system_message(array('title' => _('Could not delete the entry.') . sprintf(' (%s)', pretty_print_dn($dn)), 'body' => ldap_error_msg($server->getErrorMessage(null), $server->getErrorNum(null)), 'type' => 'error'));
        }
    }
}
コード例 #2
0
ファイル: rename.php プロジェクト: dannylsl/phpLDAPadmin
$request['rdnDST'] = get_request('new_rdn', 'REQUEST');
$request['container'] = $app['server']->getContainer($request['dnSRC']);
# Error checking
if (!$app['server']->isBranchRenameEnabled()) {
    # We search all children, not only the visible children in the tree
    $children = $app['server']->getContainerContents($request['dnSRC'], null, 0, '(objectClass=*)', LDAP_DEREF_NEVER);
    if (count($children) > 0) {
        error(_('You cannot rename an entry which has children entries (eg, the rename operation is not allowed on non-leaf entries)'), 'error', 'index.php');
    }
}
$request['dnDST'] = sprintf('%s,%s', $request['rdnDST'], $request['container']);
if ($request['dnDST'] == $request['dnSRC']) {
    error(_('You did not change the RDN'), 'error', 'index.php');
}
$rdnattr = array();
$rdnattr['SRC'] = explode('=', $request['dnSRC']);
$rdnattr['SRC'] = $rdnattr['SRC'][0];
$new_dn_value = explode('=', $request['rdnDST'], 2);
$rdnattr['DST'] = $new_dn_value[0];
if (count($new_dn_value) != 2 || !isset($new_dn_value[1])) {
    error(_('Invalid RDN value'), 'error', 'index.php');
}
$deleteoldrdn = $rdnattr['SRC'] == $rdnattr['DST'];
$success = $app['server']->rename($request['dnSRC'], $request['rdnDST'], $request['container'], $deleteoldrdn);
if ($success) {
    $rename_message = sprintf('%s', _('Rename successful!'));
    $redirect_url = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s&template=%s', $app['server']->getIndex(), rawurlencode($request['dnDST']), get_request('template', 'REQUEST'));
    system_message(array('title' => _('Rename Entry'), 'body' => $rename_message, 'type' => 'info'), $redirect_url);
} else {
    system_message(array('title' => _('Could not rename the entry.'), 'body' => ldap_error_msg($app['server']->getErrorMessage(null), $app['server']->getErrorNum(null)), 'type' => 'error'));
}
コード例 #3
0
 /**
  * Modify objects
  */
 public function modify($dn, $attrs, $method = null)
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     # Check our unique attributes.
     if (!$this->checkUniqueAttrs($dn, $attrs)) {
         return false;
     }
     $result = false;
     $summary = array();
     $current_attrs = $this->getDNAttrValues($dn, $method, LDAP_DEREF_NEVER, array('*'));
     # Go through our attributes and call our hooks for each attribute changing its value
     foreach ($attrs as $attr => $values) {
         # For new attributes
         if (count($values) && !isset($current_attrs[$attr])) {
             if (!run_hook('pre_attr_add', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'newvalue' => $values))) {
                 unset($attrs[$attr]);
                 system_message(array('title' => _('Attribute not added'), 'body' => sprintf('%s (<b>%s</b>)', _('Hook pre_attr_add prevented attribute from being added'), $attr), 'type' => 'warn'));
             } else {
                 $summary['add'][$attr]['new'] = $values;
             }
             # For modify attributes
         } elseif (count($values)) {
             if (!run_hook('pre_attr_modify', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'oldvalue' => $current_attrs[$attr], 'newvalue' => $values))) {
                 unset($attrs[$attr]);
                 system_message(array('title' => _('Attribute not modified'), 'body' => sprintf('%s (<b>%s</b>)', _('Hook pre_attr_modify prevented attribute from being modified'), $attr), 'type' => 'warn'));
             } else {
                 $summary['modify'][$attr]['new'] = $values;
                 $summary['modify'][$attr]['old'] = $current_attrs[$attr];
             }
             # For delete attributes
         } else {
             if (!run_hook('pre_attr_delete', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'oldvalue' => $current_attrs[$attr]))) {
                 unset($attrs[$attr]);
                 system_message(array('title' => _('Attribute not deleted'), 'body' => sprintf('%s (<b>%s</b>)', _('Hook pre_attr_delete prevented attribute from being deleted'), $attr), 'type' => 'warn'));
             } else {
                 $summary['delete'][$attr]['old'] = $current_attrs[$attr];
             }
         }
     }
     if (!count($attrs)) {
         return false;
     }
     if (run_hook('pre_entry_modify', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attrs' => $attrs))) {
         $result = @ldap_modify($this->connect($method), $dn, $attrs);
         if ($result) {
             run_hook('post_entry_modify', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attrs' => $attrs));
             foreach (array('add', 'modify', 'delete') as $mode) {
                 if (isset($summary[$mode])) {
                     foreach ($summary[$mode] as $attr => $values) {
                         switch ($mode) {
                             case 'add':
                                 run_hook(sprintf('post_attr_%s', $mode), array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'newvalue' => $values['new']));
                                 break;
                             case 'modify':
                                 run_hook(sprintf('post_attr_%s', $mode), array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'oldvalue' => $values['old'], 'newvalue' => $values['new']));
                                 break;
                             case 'delete':
                                 run_hook(sprintf('post_attr_%s', $mode), array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attr' => $attr, 'oldvalue' => $values['old']));
                                 break;
                             default:
                                 debug_dump_backtrace(sprintf('Unkown mode %s', $mode), 1);
                         }
                     }
                 }
             }
         } else {
             system_message(array('title' => _('Could not perform ldap_modify operation.'), 'body' => ldap_error_msg($this->getErrorMessage($method), $this->getErrorNum($method)), 'type' => 'error'));
         }
     }
     return $result;
 }
コード例 #4
0
 public function accept()
 {
     $server = $this->getServer();
     # Get the data to be exported
     $query = array();
     $base = get_request('dn', 'REQUEST');
     $query['baseok'] = true;
     $query['filter'] = get_request('filter', 'REQUEST', false, 'objectclass=*');
     $query['scope'] = get_request('scope', 'REQUEST', false, 'base');
     $query['deref'] = $_SESSION[APPCONFIG]->getValue('deref', 'export');
     $query['size_limit'] = 0;
     $attrs = get_request('attributes', 'REQUEST');
     $attrs = preg_replace('/\\s+/', '', $attrs);
     if ($attrs) {
         $query['attrs'] = explode(',', $attrs);
     } else {
         $query['attrs'] = array('*');
     }
     if (get_request('sys_attr')) {
         if (!in_array('*', $query['attrs'])) {
             array_push($query['attrs'], '*');
         }
         array_push($query['attrs'], '+');
     }
     if (!$base) {
         $bases = $server->getBaseDN();
     } else {
         $bases = array($base);
     }
     foreach ($bases as $base) {
         $query['base'] = $base;
         $time_start = utime();
         $this->results[$base] = $server->query($query, null);
         $time_end = utime();
         usort($this->results[$base], 'pla_compare_dns');
         $this->resultsdata[$base]['time'] = round($time_end - $time_start, 2);
         # If no result, there is a something wrong
         if (!$this->results[$base] && $server->getErrorNum(null)) {
             system_message(array('title' => _('Encountered an error while performing search.'), 'body' => ldap_error_msg($server->getErrorMessage(null), $server->getErrorNum(null)), 'type' => 'error'));
         }
         $this->items += count($this->results[$base]);
     }
     $this->resultsdata['scope'] = $query['scope'];
     $this->resultsdata['filter'] = $query['filter'];
     $this->resultsdata['attrs'] = $query['attrs'];
     # Other settings
     switch (get_request('format', 'POST', false, 'unix')) {
         case 'win':
             $this->br = "\r\n";
             break;
         case 'mac':
             $this->br = "\r";
             break;
         case 'unix':
         default:
             $this->br = "\n";
     }
     if (get_request('compress', 'REQUEST') == 'on') {
         $this->compress = true;
     }
 }
コード例 #5
0
ファイル: import.php プロジェクト: dannylsl/phpLDAPadmin
$request['page'] = new PageRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, 'none'));
$request['page']->drawTitle(sprintf('<b>%s</b>', _('Import')));
$request['page']->drawSubTitle(sprintf('%s: <b>%s</b> %s: <b>%s %s %s (%s)</b>', _('Server'), $app['server']->getName(), _('File'), $request['import']->getSource('name'), number_format($request['import']->getSource('size')), _('bytes'), $type['description']));
echo '<br />';
# @todo When renaming DNs, the hotlink should point to the new entry on success, or the old entry on failure.
while (!$request['import']->eof()) {
    while ($request['template'] = $request['import']->readEntry()) {
        $edit_href = sprintf('cmd.php?cmd=template_engine&amp;server_id=%s&amp;dn=%s', $app['server']->getIndex(), rawurlencode($request['template']->getDN()));
        $changetype = $request['template']->getType();
        printf('<small>%s <a href="%s">%s</a>', $actionString[$changetype], $edit_href, $request['template']->getDN());
        if ($request['import']->LDAPimport()) {
            printf(' <span style="color:green;">%s</span></small><br />', _('Success'));
        } else {
            printf(' <span style="color:red;">%s</span></small><br /><br />', _('Failed'));
            $errormsg = sprintf('%s <b>%s</b>', $actionErrorMsg[$changetype], $request['template']->getDN());
            $errormsg .= ldap_error_msg($app['server']->getErrorMessage(null), $app['server']->getErrorNum(null));
            system_message(array('title' => _('LDIF text import'), 'body' => $errormsg, 'type' => 'warn'));
        }
    }
    if ($request['import']->error) {
        printf('<small><span style="color:red;">%s: %s</span></small><br />', _('Error'), $request['import']->error['message']);
        echo '<br/>';
        display_pla_parse_error($request['import']);
    }
    if (!$request['continuous_mode']) {
        break;
    }
}
function display_pla_parse_error($request)
{
    $type = $request->getType();
コード例 #6
0
ファイル: delete.php プロジェクト: kangaroot/phpldapadmin
<?php

/**
 * Deletes a DN and presents a "job's done" message.
 *
 * @package phpLDAPadmin
 * @subpackage Page
 */
/**
 */
require './common.php';
# The DNs we are working with
$request = array();
$request['dn'] = get_request('dn', 'REQUEST', true);
if (!$app['server']->dnExists($request['dn'])) {
    error(sprintf('%s (%s)', _('No such entry.'), '<b>' . pretty_print_dn($request['dn']) . '</b>'), 'error', 'index.php');
}
# Delete the entry.
$result = $app['server']->delete($request['dn']);
if ($result) {
    system_message(array('title' => _('Delete DN'), 'body' => _('Successfully deleted DN ') . sprintf('<b>%s</b>', $request['dn']), 'type' => 'info'), sprintf('index.php?server_id=%s', $app['server']->getIndex()));
} else {
    system_message(array('title' => _('Could not delete the entry.') . sprintf(' (%s)', pretty_print_dn($request['dn'])), 'body' => ldap_error_msg($app['server']->getErrorMessage(null), $app['server']->getErrorNum(null)), 'type' => 'error'));
}