private function visitEnd() { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 129, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $server = $this->getServer(); $afattrs = $this->getAFAttrs(); # If Mass Actions Enabled if ($_SESSION[APPCONFIG]->getValue('mass', 'enabled')) { $mass_actions = array(_('delete') => 'mass_delete', _('edit') => 'mass_edit'); } $this->drawBaseTabs(); $ado = $this->template->getAttrDisplayOrder(); $counter = 0; $j = 0; foreach ($this->template->results as $base => $results) { $counter++; if (!($show = get_request('show', 'REQUEST'))) { $show = $counter === 1 ? $this->getAjaxRef($base) : null; } printf('<div id="DN%s" style="display: %s">', $this->getAjaxRef($base), $show == $this->getAjaxRef($base) ? 'block' : 'none'); echo '<table class="result_box" border="0" width="100%">'; echo '<tr><td>'; echo '<br/>'; echo '<br/>'; $this->drawResultsTable($base, count($results)); echo '<br/>'; echo '<br/>'; switch (get_request('format', 'REQUEST', false, $_SESSION[APPCONFIG]->getValue('search', 'display'))) { case 'list': foreach ($results as $dndetails) { $dndetails = array_change_key_case($dndetails); # Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto) $this->template->setDN($dndetails['dn']); echo '<table class="result" border="0">'; echo '<tr class="list_title">'; printf('<td class="icon"><img src="%s/%s" alt="icon" /></td>', IMGDIR, get_icon($server->getIndex(), $dndetails['dn'])); printf('<td colspan="2"><a href="cmd.php?cmd=template_engine&server_id=%s&dn=%s">%s</a></td>', $server->getIndex(), $this->template->getDNEncode(), htmlspecialchars(get_rdn($dndetails['dn']))); echo '</tr>'; printf('<tr class="list_item"><td class="blank"> </td><td class="heading">dn</td><td class="value">%s</td></tr>', htmlspecialchars(dn_unescape($dndetails['dn']))); # Iterate over each attribute for this entry foreach (explode(',', $ado) as $attr) { $attr = strtolower($attr); # Ignore DN, we've already displayed it. if ($attr == 'dn') { continue; } if (!isset($dndetails[$attr])) { continue; } # Set our object with our values $afattrs[$attr]->clearValue(); if (is_array($dndetails[$attr])) { $afattrs[$attr]->initValue($dndetails[$attr]); } else { $afattrs[$attr]->initValue(array($dndetails[$attr])); } echo '<tr class="list_item">'; echo '<td class="blank"> </td>'; echo '<td class="heading">'; $this->draw('Name', $afattrs[$attr]); echo '</td>'; echo '<td>'; $this->draw('CurrentValues', $afattrs[$attr]); echo '</td>'; echo '</tr>'; } echo '</table>'; echo '<br/>'; } break; # Display the results. # Display the results. case 'table': if (!$results) { echo _('Search returned no results'); continue; } printf('<form action="cmd.php" method="post" id="massform_%s">', $counter); echo '<div>'; printf('<input type="hidden" name="server_id" value="%s" />', $server->getIndex()); foreach ($this->template->resultsdata[$base]['attrs'] as $attr) { printf('<input type="hidden" name="attrs[]" value="%s" />', $attr); } echo '</div>'; echo '<table class="result_table" border="0">'; echo '<thead class="fixheader">'; echo '<tr class="heading">'; echo '<td> </td>'; echo '<td> </td>'; foreach (explode(',', $ado) as $attr) { echo '<td>'; $this->draw('Name', $afattrs[$attr]); echo '</td>'; } echo '</tr>'; echo '</thead>'; echo '<tbody class="scroll">'; foreach ($results as $dndetails) { $j++; $dndetails = array_change_key_case($dndetails); # Temporarily set our DN, for rendering that leverages our DN (eg: JpegPhoto) $this->template->setDN($dndetails['dn']); printf('<tr class="%s" id="tr_ma_%s" onclick="var cb=document.getElementById(\'ma_%s\'); cb.checked=!cb.checked;">', $j % 2 ? 'even' : 'odd', $j, $j); # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass', 'enabled')) { printf('<td><input type="checkbox" id="ma_%s" name="dn[]" value="%s" onclick="this.checked=!this.checked;" /></td>', $j, $dndetails['dn']); } $href = sprintf('cmd=template_engine&server_id=%s&dn=%s', $server->getIndex(), $this->template->getDNEncode()); printf('<td class="icon"><a href="cmd.php?%s"><img src="%s/%s" alt="icon" /></a></td>', htmlspecialchars($href), IMGDIR, get_icon($server->getIndex(), $dndetails['dn'])); # We'll clone our attribute factory attributes, since we need to add the values to them for rendering. foreach (explode(',', $ado) as $attr) { # If the entry is blank, we'll draw an empty box and continue. if (!isset($dndetails[$attr])) { echo '<td> </td>'; continue; } # Special case for DNs if ($attr == 'dn') { $dn_display = strlen($dndetails['dn']) > 40 ? sprintf('<acronym title="%s">%s...</acronym>', htmlspecialchars($dndetails['dn']), htmlspecialchars(substr($dndetails['dn'], 0, 40))) : htmlspecialchars($dndetails['dn']); printf('<td><a href="cmd.php?%s">%s</a></td>', htmlspecialchars($href), $dn_display); continue; } # Set our object with our values $afattrs[$attr]->clearValue(); if (is_array($dndetails[$attr])) { $afattrs[$attr]->initValue($dndetails[$attr]); } else { $afattrs[$attr]->initValue(array($dndetails[$attr])); } echo '<td>'; $this->draw('CurrentValues', $afattrs[$attr]); echo '</td>'; } echo '</tr>'; } # Is mass action enabled. if ($_SESSION[APPCONFIG]->getValue('mass', 'enabled')) { printf('<tr class="%s">', ++$j % 2 ? 'odd' : 'even'); printf('<td><input type="checkbox" name="allbox" value="1" onclick="CheckAll(1,\'massform_\',%s);" /></td>', $counter); printf('<td colspan="%s">', 2 + count(explode(',', $ado))); foreach ($mass_actions as $display => $action) { printf('<button type="submit" name="cmd" value="%s">%s</button> ', $action, $display); } echo '</td>'; echo '</tr>'; } echo '</tbody>'; echo '</table>'; echo '</form>'; echo "\n\n"; break; default: printf('Have ID [%s], run this query for page [%s]', $this->template_id, $this->page); } echo '</td></tr>'; echo '</table>'; echo '</div>'; echo "\n\n"; } if (get_request('format', 'REQUEST', false, 'table') == 'table') { printf('<script type="text/javascript" src="%sCheckAll.js"></script>', JSDIR); } }
foreach ($results as $dn => $dndetails) { $i++; if ($i <= $start_entry) { continue; } if ($i >= $end_entry) { break; } echo '<div class="search_result">'; echo '<table><tr>'; printf('<td><img src="images/%s" /></td>', get_icon($ldapserver, $dn)); printf('<td><a href="template_engine.php?server_id=%s&dn=%s">%s</a></td>', $ldapserver->server_id, rawurlencode(dn_unescape($dn)), htmlspecialchars(get_rdn($dn))); echo '</tr></table>'; echo '</div>'; echo '<table class="attrs">'; printf('<tr><td class="attr" valign="top">dn</td><td>%s</td></tr>', htmlspecialchars(dn_unescape($dn))); # Iterate over each attribute for this entry foreach ($dndetails as $attr => $values) { # Ignore DN, we've already displayed it. if ($attr == 'dn') { continue; } if ($ldapserver->isAttrBinary($attr)) { $values = array('(binary)'); } if (isset($friendly_attrs[strtolower($attr)])) { $attr = sprintf('<acronym title="Alias for $attr">%s</acronym>', htmlspecialchars($friendly_attrs[strtolower($attr)])); } else { $attr = htmlspecialchars($attr); } echo '<tr>';
/** * Gets a list of child entries for an entry. Given a DN, this function fetches the list of DNs of * child entries one level beneath the parent. For example, for the following tree: * * <code> * dc=example,dc=com * ou=People * cn=Dave * cn=Fred * cn=Joe * ou=More People * cn=Mark * cn=Bob * </code> * * Calling <code>getContainerContents("ou=people,dc=example,dc=com")</code> * would return the following list: * * <code> * cn=Dave * cn=Fred * cn=Joe * ou=More People * </code> * * @param string $dn The DN of the entry whose children to return. * @param int $size_limit (optional) The maximum number of entries to return. * If unspecified, no limit is applied to the number of entries in the returned. * @param string $filter (optional) An LDAP filter to apply when fetching children, example: "(objectClass=inetOrgPerson)" * @return array An array of DN strings listing the immediate children of the specified entry. */ function getContainerContents($dn, $size_limit = 0, $filter = '(objectClass=*)', $deref = LDAP_DEREF_ALWAYS) { $tree = get_cached_item($this->server_id, 'tree'); if (isset($tree['browser'][$dn]['children']) && $filter == '(objectClass=*)') { if (!isset($tree['browser'][$dn]['size_limited']) || !$tree['browser'][$dn]['size_limited']) { return $tree['browser'][$dn]['children']; } } $return = array(); $search = $this->search(null, dn_escape($dn), $filter, array('dn'), 'one', true, $deref, $size_limit > 0 ? $size_limit + 1 : $size_limit); if (!$search) { $tree['browser'][$dn]['children'] = array(); } else { foreach ($search as $searchdn => $entry) { $child_dn = dn_unescape($entry['dn']); $tree['browser'][$child_dn]['icon'] = get_icon($this, $child_dn); $return[] = $child_dn; } usort($return, 'pla_compare_dns'); $tree['browser'][$dn]['children'] = $return; if ($size_limit > 0 && count($tree['browser'][$dn]['children']) > $size_limit) { $tree['browser'][$dn]['size_limited'] = true; } else { if (isset($tree['browser'][$dn]['size_limited'])) { unset($tree['browser'][$dn]['size_limited']); } } } set_cached_item($this->server_id, 'tree', 'null', $tree); if (DEBUG_ENABLED) { debug_log('%s::getContainerContents(): Entered with (%s,%s,%s,%s), Returning (%s)', 17, get_class($this), $dn, $size_limit, $filter, $deref, $return); } return $tree['browser'][$dn]['children']; }
/** * Add objects */ public function add($dn, $entry_array, $method = null) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 17, 0, __FILE__, __LINE__, __METHOD__, $fargs); } foreach ($entry_array as $attr => $val) { $entry_array[$attr] = dn_unescape($val); } $result = false; # Check our unique attributes. if (!$this->checkUniqueAttrs($dn, $entry_array)) { return false; } if (run_hook('pre_entry_create', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attrs' => $entry_array))) { $result = @ldap_add($this->connect($method), dn_escape($dn), $entry_array); if ($result) { # Update the tree $tree = get_cached_item($this->index, 'tree'); # If we created the base, delete it, then add it back if (get_request('create_base')) { $tree->delEntry($dn); } $tree->addEntry($dn); set_cached_item($this->index, 'tree', 'null', $tree); run_hook('post_entry_create', array('server_id' => $this->index, 'method' => $method, 'dn' => $dn, 'attrs' => $entry_array)); } else { system_message(array('title' => _('Could not add the object to the LDAP server.'), 'body' => ldap_error_msg($this->getErrorMessage(null), $this->getErrorNum(null)), 'type' => 'error')); } } return $result; }
echo '<tr><td>'; echo '<br/>'; echo '<table class="result" border="0">'; echo '<tr><td>'; printf(_('There will be %s updates done with this mass update'), sprintf('<b>%s</b>', count($request['update']))); echo '</td></tr>'; echo '</table>'; echo '<br/>'; foreach ($request['update'] as $index => $page) { $template = $page->getTemplate(); echo '<table class="result" border="0">'; echo '<tr class="list_title">'; printf('<td class="icon"><img src="%s/%s" alt="icon" /></td>', IMGDIR, get_icon($app['server']->getIndex(), $template->getDN())); printf('<td colspan="3"><a href="cmd.php?cmd=template_engine&server_id=%s&dn=%s">%s</a></td>', $app['server']->getIndex(), rawurlencode(dn_unescape($template->getDN())), htmlspecialchars(get_rdn($template->getDN()))); echo '</tr>'; printf('<tr class="list_item"><td class="blank"> </td><td class="heading">dn</td><td class="value" style="width: 45%%;">%s</td><td class="value" style="width: 45%%;"><b>%s</b></td></tr>', htmlspecialchars(dn_unescape($template->getDN())), _('Old Value')); foreach ($template->getLDAPmodify(true, $index) as $attribute) { echo '<tr class="list_item">'; echo '<td class="blank"> </td>'; echo '<td class="heading">'; $page->draw('Name', $attribute); echo '</td>'; # Show NEW Values echo '<td><span style="white-space: nowrap;">'; if (!$attribute->getValueCount() || $attribute->isForceDelete()) { printf('<span style="color: red">[%s]</span>', _('attribute deleted')); printf('<input type="hidden" name="mass_values[%s][%s][%s]" value="%s" />', $index, $attribute->getName(), 0, ''); } foreach ($attribute->getValues() as $key => $value) { # For multiple values, we'll highlight the changed ones if (count($attribute->getValues()) > 5 && in_array($value, $attribute->getAddedValues())) {
/** * Explode a DN into an array of its RDN parts. * * NOTE: When a multivalue RDN is passed to ldap_explode_dn, the results returns with 'value + value'; * * <code> * Array ( * [0] => uid=ppratt * [1] => ou=People * [2] => dc=example * [3] => dc=com * ) * </code> * * @param string The DN to explode. * @param int (optional) Whether to include attribute names (see http://php.net/ldap_explode_dn for details) * @return array An array of RDN parts of this format: */ function pla_explode_dn($dn, $with_attributes = 0) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); } global $CACHE; if (isset($CACHE['explode'][$dn][$with_attributes])) { if (DEBUG_ENABLED) { debug_log('Return CACHED result (%s) for (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $CACHE['explode'][$dn][$with_attributes], $dn); } return $CACHE['explode'][$dn][$with_attributes]; } $dn = addcslashes($dn, '<>+";'); # split the dn $result[0] = ldap_explode_dn(dn_escape($dn), 0); $result[1] = ldap_explode_dn(dn_escape($dn), 1); if (!$result[$with_attributes]) { if (DEBUG_ENABLED) { debug_log('Returning NULL - NO result.', 1, 0, __FILE__, __LINE__, __METHOD__); } return array(); } # Remove our count value that ldap_explode_dn returns us. unset($result[0]['count']); unset($result[1]['count']); # Record the forward and reverse entries in the cache. foreach ($result as $key => $value) { # translate hex code into ascii for display $result[$key] = dn_unescape($value); $CACHE['explode'][implode(',', $result[0])][$key] = $result[$key]; $CACHE['explode'][implode(',', array_reverse($result[0]))][$key] = array_reverse($result[$key]); } if (DEBUG_ENABLED) { debug_log('Returning (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $result[$with_attributes]); } return $result[$with_attributes]; }
echo '<td colspan="4">'; printf(_('This request also includes %s children entries.'), count($request['children'])); echo '</td></tr>'; printf('<tr><td colspan="4">%s</td></tr>', sprintf(_('phpLDAPadmin can also recursively delete all %s of the child entries. See below for a list of all the entries that this action will delete. Do you want to do this?'), count($request['children']))); echo '<tr><td colspan="4"> </td></tr>'; printf('<tr><td colspan="4"><small>%s</small></td></tr>', _('Note: this is potentially very dangerous and you do this at your own risk. This operation cannot be undone. Take into consideration aliases, referrals, and other things that may cause problems.')); echo "\n"; echo '<tr><td colspan="4"> </td></tr>'; echo "\n"; printf('<tr><td colspan="4"><center><b>%s</b></center></td></tr>', _('List of entries to be deleted:')); echo '<tr><td colspan="4"> </td></tr>'; $i = 0; echo '<tr><td colspan="4"><center>'; printf('<select size="%s" multiple disabled style="background:white; color:black;width:500px" >', min(10, count($request['delete']))); foreach ($request['delete'] as $key => $value) { printf('<option>%s. %s</option>', ++$i, htmlspecialchars(dn_unescape($value))); } echo '</select>'; echo '</center></td></tr>'; echo "\n"; echo '<tr><td colspan="4"> </td></tr>'; } echo '<tr>'; echo '<td colspan="2" style="width: 50%; text-align: center;">'; echo '<form action="cmd.php" method="post">'; echo '<input type="hidden" name="cmd" value="rdelete" />'; printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); foreach ($request['parent'] as $dn) { printf('<input type="hidden" name="dn[]" value="%s" />', htmlspecialchars($dn)); } printf('<input type="submit" value="%s" />', sprintf(_('Delete all %s objects'), count($request['delete'])));
printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="dn" value="%s" />', $request['template']->getDNEncode(false)); printf('<input type="submit" name="submit" value="%s" %s />', _('Cancel'), isAjaxEnabled() ? sprintf('onclick="return ajDISPLAY(\'BODY\',\'cmd=template_engine&server_id=%s&dn=%s\',\'%s\');"', $app['server']->getIndex(), $request['template']->getDNEncode(), _('Retrieving DN')) : ''); echo '</form>'; echo '</td>'; echo '</tr>'; echo "\n"; echo '</table>'; echo "\n"; echo '<br /><br />'; echo _('List of entries to be deleted:'); echo '<br />'; $i = 0; printf('<select size="%s" multiple disabled style="background:white; color:black;width:500px" >', min(10, count($request['search']))); foreach ($request['search'] as $key => $value) { printf('<option>%s. %s</option>', ++$i, dn_unescape($value['dn'])); } echo '</select>'; echo "\n"; } else { echo '<table class="forminput" border="0">'; printf('<tr><td colspan="4">%s</td></tr>', _('Are you sure you want to permanently delete this object?')); echo '<tr><td colspan="4"> </td></tr>'; printf('<tr><td style="width: 10%%;">%s:</td><td colspan="3" style="width: 75%%;"><b>%s</b></td></tr>', _('Server'), $app['server']->getName()); printf('<tr><td style="width: 10%%;"><acronym title="%s">%s</acronym></td><td colspan="3" style="width: 75%%;"><b>%s</b></td></tr>', _('Distinguished Name'), _('DN'), $request['dn']); echo '<tr><td colspan="4"> </td></tr>'; echo "\n"; echo '<tr>'; echo '<td colspan="2" style="width: 50%; text-align: center;">'; echo '<form action="cmd.php" method="post" id="delete_form">'; echo '<input type="hidden" name="cmd" value="delete" />';
<select size="<?php echo min(10, $sub_tree_count); ?> " multiple disabled style="background:white; color:black;width:500px" > <?php $i = 0; foreach ($s as $dn => $junk) { $i++; ?> <option><?php echo $i; ?> . <?php echo htmlspecialchars(dn_unescape($dn)); ?> </option> <?php } ?> </select> </center> <br /> <?php } else { ?> <center>