/** * Get the RDN of this tree items DN. * * @return RDN The RDN of this items DN. */ public function getRDN() { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); } return get_rdn($this->getDn(), 0, true); }
* @subpackage Page * @see update.php */ /** */ require './common.php'; $request = array(); $request['dn'] = get_request('dn', 'REQUEST', true); if (!$request['dn'] || !$app['server']->dnExists($request['dn'])) { error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); } $request['page'] = new PageRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, 'none')); $request['page']->setDN($request['dn']); $request['page']->accept(); $request['template'] = $request['page']->getTemplate(); $request['page']->drawTitle(get_rdn($request['template']->getDN())); $request['page']->drawSubTitle(); # Confirm the updates if (count($request['template']->getLDAPmodify(true))) { echo '<center>'; echo _('Do you want to make these changes?'); echo '<br /><br />'; echo "\n\n"; echo '<form action="cmd.php" method="post">'; echo '<input type="hidden" name="cmd" value="update" />'; printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="dn" value="%s" />', htmlspecialchars($request['dn'])); echo "\n"; $request['page']->drawHiddenAttributes(); echo '<table class="result_table">'; echo "\n";
* Variables that come in via GET variables * - dn (rawurlencoded) * * @package phpLDAPadmin */ /** */ require './common.php'; if ($ldapserver->isReadOnly()) { pla_error(_('You cannot perform updates while server is in read-only mode')); } if (!$ldapserver->haveAuthInfo()) { pla_error(_('Not enough information to login to server. Please check your configuration.')); } $dn = $_GET['dn']; $rdn = get_rdn($dn); $attrs = $ldapserver->getDNAttrs($dn); $select_server_html = server_select_list($ldapserver->server_id, true, 'dest_server_id'); $children = $ldapserver->getContainerContents($dn); include './header.php'; # Draw some javaScrpt to enable/disable the filter field if this may be a recursive copy if (is_array($children) && count($children) > 0) { ?> <script type="text/javascript" language="javascript"> //<!-- function toggle_disable_filter_field(recursive_checkbox) { if (recursive_checkbox.checked) { recursive_checkbox.form.remove.disabled = false; recursive_checkbox.form.filter.disabled = false;
function copy_dn($ldapserver_src, $ldapserver_dst, $dn_src, $dn_dst) { if (DEBUG_ENABLED) { debug_log('copy_dn: Entered with (%s,%s,%s,%s)', 17, $ldapserver_src->server_id, $ldapserver_dst->server_id, $dn_src, $dn_dst); } $new_entry = $ldapserver_src->getDNAttrs($dn_src); # modify the prefix-value (ie "bob" in cn=bob) to match the destination DN's value. $rdn_attr = substr($dn_dst, 0, strpos($dn_dst, '=')); $rdn_value = get_rdn($dn_dst); $rdn_value = substr($rdn_value, strpos($rdn_value, '=') + 1); $new_entry[$rdn_attr] = $rdn_value; # don't need a dn attribute in the new entry unset($new_entry['dn']); # Check the user-defined custom call back first if (run_hook('pre_entry_create', array('server_id' => $ldapserver_dst->server_id, 'dn' => $dn_dst, 'attrs' => $new_entry))) { $add_result = $ldapserver_dst->add($dn_dst, $new_entry); if (!$add_result) { run_hook('post_entry_create', array('server_id' => $ldapserver_dst->server_id, 'dn' => $dn_dst, 'attrs' => $new_entry)); echo '</small><br /><br />'; pla_error(_('Failed to copy DN: ') . $dn_dst, $ldapserver_dst->error(), $ldapserver_dst->errno()); } return $add_result; } else { return false; } }
function copy_dn($serverSRC, $serverDST, $dnSRC, $dnDST, $remove) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $request = array(); $request['pageSRC'] = new PageRender($serverSRC->getIndex(), get_request('template', 'REQUEST', false, 'none')); $request['pageSRC']->setDN($dnSRC); $request['pageSRC']->accept(); $request['pageDST'] = new PageRender($serverDST->getIndex(), get_request('template', 'REQUEST', false, 'none')); $request['pageDST']->setContainer($serverDST->getContainer($dnDST)); $request['pageDST']->accept(); $request['templateSRC'] = $request['pageSRC']->getTemplate(); $request['templateDST'] = $request['pageDST']->getTemplate(); $request['templateDST']->copy($request['pageSRC']->getTemplate(), get_rdn($dnDST, 0)); # Create of move the entry if ($remove) { return $serverDST->rename($request['templateSRC']->getDN(), $request['templateDST']->getRDN(), $serverDST->getContainer($dnDST), true); } else { return $serverDST->add($request['templateDST']->getDN(), $request['templateDST']->getLDAPadd()); } }
/** * Recursively descend on the given dn and draw the tree in html * * @param dn $dn Current dn. * @param int $level Level to start drawing (start to -1) */ protected function draw_item($item, $level) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $server = $this->getServer(); # Get entry to display as node $entry = $this->getEntry($item); # If the entry doesnt exist, we'll add it. if (!$entry) { $this->addEntry($item); $entry = $this->getEntry($item); } # If the entry doesnt exist in the server, then return here with an empty string. if (!$entry) { return; } # Get our children. $child_count = $this->readChildrenNumber($item); $rdn = get_rdn($item); $dnENCODE = rawurlencode($item); $href['expand'] = htmlspecialchars(sprintf('cmd.php?cmd=expand&server_id=%s&dn=%s', $server->getIndex(), $dnENCODE)); $href['collapse'] = htmlspecialchars(sprintf('cmd.php?cmd=collapse&server_id=%s&dn=%s', $server->getIndex(), $dnENCODE)); $href['edit'] = htmlspecialchars(sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', $server->getIndex(), $dnENCODE)); echo '<tr class="option">'; printf('<td class="spacer" colspan=%s></td>', $level + 2); # Is this node expanded? (deciding whether to draw "+" or "-") if ($entry->isOpened()) { if (!$child_count && !$this->getServer()->isShowCreateEnabled()) { printf('<td class="expander"><img src="%s/minus.png" alt="-" /></td>', IMGDIR); } else { printf('<td class="expander"><a href="%s"><img src="%s/minus.png" alt="-" /></a></td>', $href['collapse'], IMGDIR); } } else { if ($child_count !== false && !$child_count && !$this->getServer()->isShowCreateEnabled()) { printf('<td class="expander"><img src="%s/minus.png" alt="-" /></td>', IMGDIR); } else { printf('<td class="expander"><a href="%s"><img src="%s/plus.png" alt="+" /></a></td>', $href['expand'], IMGDIR); } } printf('<td class="icon"><a href="%s" id="node_%s_%s"><img src="%s/%s" alt="img" /></a></td>', $href['edit'], $server->getIndex(), preg_replace('/=/', '_', base64_encode($item)), IMGDIR, $entry->getIcon()); printf('<td class="phplm" width=100%% colspan="%s"><span style="white-space: nowrap;">', $this->getDepth() + 3 - $level); printf('<a href="%s">%s</a>', $href['edit'], $this->get_formatted_dn($entry, $level)); if ($child_count) { printf(' <span class="count">(%s)</span>', $child_count); } echo '</span></td></tr>'; if ($entry->isOpened()) { /* Draw the "create new" link at the top of the tree list if there are more than 10 * entries in the listing for this node. */ if (!$server->isReadOnly() && count($entry->getChildren()) > 10 && $this->getServer()->isShowCreateEnabled()) { $this->draw_create_link($rdn, $level, $dnENCODE); } foreach ($entry->getChildren() as $dnChildEntry) { $this->draw_item($dnChildEntry, $level + 1); } # Always draw the "create new" link at the bottom of the listing if (!$server->isReadOnly() && !$entry->isLeaf() && $this->getServer()->isShowCreateEnabled()) { $this->draw_create_link($rdn, $level, $dnENCODE); } } if (DEBUG_ENABLED) { debug_log('Leaving (%s,%s)', 33, 0, __FILE__, __LINE__, __METHOD__, $item, $level); } }
$query['filter'] = $_SESSION[APPCONFIG]->getValue('modify_member', 'posixfilter'); $attr = $_SESSION[APPCONFIG]->getValue('modify_member', 'posixattr'); } else { $query['filter'] = $_SESSION[APPCONFIG]->getValue('modify_member', 'filter'); $attr = $_SESSION[APPCONFIG]->getValue('modify_member', 'attr'); } $query['attrs'] = array($attr); $possible_values = array(); foreach ($app['server']->getBaseDN() as $base) { $query['base'] = $base; $possible_values = array_merge($possible_values, $app['server']->query($query, null)); } usort($possible_values, 'pla_compare_dns'); $request['page']->drawTitle(sprintf('%s <b>%s</b>', _('Modify group'), get_rdn($request['dn']))); $request['page']->drawSubTitle(); printf('%s <b>%s</b> %s <b>%s</b>:', _('There are'), count($current_members), _('members in group'), htmlspecialchars(get_rdn($request['dn']))); $possible_members = array(); for ($i = 0; $i < count($possible_values); $i++) { if (preg_match("/^" . $request['attr'] . "\$/i", $_SESSION[APPCONFIG]->getValue('modify_member', 'posixgroupattr'))) { $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member', 'posixattr')][0]; } else { $possible_members[$i] = $possible_values[$i][$_SESSION[APPCONFIG]->getValue('modify_member', 'attr')]; } } # Show only user that are not already in group. $possible_members = array_diff($possible_members, $current_members); usort($possible_members, 'pla_compare_dns'); /* Draw form with select boxes, left for all possible members and * right one for those that belong to group */ # Modifications will be sent to update_confirm which takes care of rest of the processing echo '<br />';
# Check if the entry exists. if (!$request['dn'] || !$app['server']->dnExists($request['dn'])) { error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); } $request['page'] = new TemplateRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, 'none')); $request['page']->setDN($request['dn']); $request['page']->accept(true); $request['template'] = $request['page']->getTemplate(); /* if ($request['attribute']->isReadOnly()) error(sprintf(_('The attribute (%s) is in readonly mode.'),$request['attr']),'error','index.php'); */ # Render the form if (get_request('meth', 'REQUEST') != 'ajax') { # Render the form. $request['page']->drawTitle(sprintf('%s <b>%s</b> %s <b>%s</b>', _('Add new'), $request['attr'], _('value to'), get_rdn($request['dn']))); $request['page']->drawSubTitle(); if (!strcasecmp($request['attr'], 'objectclass')) { echo '<form action="cmd.php" method="post" class="new_value" name="entry_form">'; echo '<input type="hidden" name="cmd" value="add_oclass_form" />'; } else { echo '<form action="cmd.php" method="post" class="new_value" name="entry_form" enctype="multipart/form-data" onSubmit="return submitForm(this)">'; if ($_SESSION[APPCONFIG]->getValue('confirm', 'update')) { echo '<input type="hidden" name="cmd" value="update_confirm" />'; } else { echo '<input type="hidden" name="cmd" value="update" />'; } } printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="dn" value="%s" />', htmlspecialchars($request['dn'])); echo '<center>';
/** * Displays a form for renaming an LDAP entry. * * @package phpLDAPadmin * @subpackage Page */ /** */ require './common.php'; # The DN we are working with $request = array(); $request['dn'] = get_request('dn', 'GET'); $request['template'] = get_request('template', 'GET'); $request['page'] = new PageRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, 'none')); $request['page']->setDN($request['dn']); $request['page']->accept(); # Render the form $request['page']->drawTitle(sprintf('%s <b>%s</b>', _('Rename'), get_rdn($request['dn']))); $request['page']->drawSubTitle(); echo '<center>'; printf('%s <b>%s</b> %s:<br /><br />', _('Rename'), get_rdn($request['dn']), _('to a new object')); echo '<form action="cmd.php?cmd=rename" method="post" />'; printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="dn" value="%s" />', rawurlencode($request['dn'])); printf('<input type="hidden" name="template" value="%s" />', $request['template']); printf('<input type="text" name="new_rdn" size="30" value="%s" />', get_rdn($request['dn'])); printf('<input type="submit" value="%s" />', _('Rename')); echo '</form>'; echo '</center>'; echo "\n";
public function drawTitle($title = null) { if (DEBUGTMP) { printf('<font size=-2>%s</font><br />', __METHOD__); } if (is_null($title)) { switch ($this->getMode()) { case 'creation': $title = _('Create Object'); break; case 'modification': $title = htmlspecialchars(get_rdn($this->dn)); break; default: $title = 'Title'; } } parent::drawTitle($title); }
if ($ldapserver->isReadOnly()) { pla_error(_('You cannot perform updates while server is in read-only mode')); } if (!$ldapserver->haveAuthInfo()) { pla_error(_('Not enough information to login to server. Please check your configuration.')); } $dn = $_POST['dn']; if (!$dn) { pla_error(_('You must specify a DN')); } if (!$ldapserver->dnExists($dn)) { pla_error(sprintf(_('No such entry: %s'), htmlspecialchars($dn))); } include './header.php'; echo '<body>'; printf('<h3 class="title">' . _('Deleting %s') . '</h3>', htmlspecialchars(get_rdn($dn))); printf('<h3 class="subtitle">%s</h3>', _('Recursive delete progress')); echo '<br /><br />'; echo '<small>'; flush(); # prevent script from bailing early on a long delete @set_time_limit(0); $del_result = pla_rdelete($ldapserver, $dn); echo '</small><br />'; if ($del_result) { echo '<script language="javascript">parent.left_frame.location.reload();</script>'; printf(_('Entry %s and sub-tree deleted successfully.'), '<b>' . htmlspecialchars($dn) . '</b>'); } else { pla_error(sprintf(_('Could not delete the entry: %s'), htmlspecialchars($dn)), $ldapserver->error(), $ldapserver->errno()); } function pla_rdelete($ldapserver, $dn)
} $ldap['attrs']['must'] = array_unique($ldap['attrs']['must']); /* Build a list of the attributes that this new objectClass requires, * but that the object does not currently contain */ $ldap['attrs']['need'] = array(); foreach ($ldap['attrs']['must'] as $attr) { if (is_null($request['template']->getAttribute($attr))) { array_push($ldap['attrs']['need'], $attribute_factory->newAttribute($attr, array('values' => array()), $app['server']->getIndex())); } } # Mark all the need attributes as shown foreach ($ldap['attrs']['need'] as $index => $values) { $ldap['attrs']['need'][$index]->show(); } if (count($ldap['attrs']['need']) > 0) { $request['page']->drawTitle(sprintf('%s <b>%s</b>', _('Add new objectClass to'), get_rdn($request['dn']))); $request['page']->drawSubTitle(); echo '<div style="text-align: center">'; printf('<small><b>%s: </b>%s <b>%s</b> %s %s</small>', _('Instructions'), _('In order to add these objectClass(es) to this entry, you must specify'), count($ldap['attrs']['need']), _('new attributes'), _('that this objectClass requires.')); echo '<br /><br />'; echo '<form action="cmd.php" method="post" id="entry_form">'; echo '<div>'; if ($_SESSION[APPCONFIG]->getValue('confirm', 'update')) { echo '<input type="hidden" name="cmd" value="update_confirm" />'; } else { echo '<input type="hidden" name="cmd" value="update" />'; } printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="dn" value="%s" />', htmlspecialchars($request['dn'])); echo '</div>'; echo '<table class="entry" cellspacing="0" border="0" style="margin-left: auto; margin-right: auto;">';
# Check if the entry exists. if (!$request['dn'] || !$app['server']->dnExists($request['dn'])) { error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); } $request['page'] = new TemplateRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, null)); $request['page']->setDN($request['dn']); $request['page']->accept(true); $request['template'] = $request['page']->getTemplate(); /* if ($request['attribute']->isReadOnly()) error(sprintf(_('The attribute (%s) is in readonly mode.'),$request['attr']),'error','index.php'); */ # Render the form if (!strcasecmp($request['attr'], 'objectclass') || get_request('meth', 'REQUEST') != 'ajax') { # Render the form. $request['page']->drawTitle(sprintf('%s <b>%s</b> %s <b>%s</b>', _('Add new'), htmlspecialchars($request['attr']), _('value to'), htmlspecialchars(get_rdn($request['dn'])))); $request['page']->drawSubTitle(); if (!strcasecmp($request['attr'], 'objectclass')) { echo '<form action="cmd.php" method="post" class="new_value" id="entry_form">'; echo '<div>'; echo '<input type="hidden" name="cmd" value="add_oclass_form" />'; } else { echo '<form action="cmd.php" method="post" class="new_value" id="entry_form" enctype="multipart/form-data" onsubmit="return submitForm(this)">'; echo '<div>'; if ($_SESSION[APPCONFIG]->getValue('confirm', 'update')) { echo '<input type="hidden" name="cmd" value="update_confirm" />'; } else { echo '<input type="hidden" name="cmd" value="update" />'; } } printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex());
*/ require 'common.php'; $dn = rawurldecode($_GET['dn']); $server_id = $_GET['server_id']; $format = $_GET['format']; $scope = $_GET['scope'] ? $_GET['scope'] : 'base'; check_server_id($server_id) or pla_error("Bad server_id: " . htmlspecialchars($server_id)); have_auth_info($server_id) or pla_error("Not enough information to login to server. Please check your configuration."); $objects = pla_ldap_search($server_id, 'objectClass=*', $dn, array(), $scope, false); $server_name = $servers[$server_id]['name']; $server_host = $servers[$server_id]['host']; //echo "<pre>"; //print_r( $objects ); //exit; $rdn = get_rdn($dn); $friendly_rdn = get_rdn($dn, 1); switch ($format) { case 'win': $br = "\r\n"; break; case 'mac': $br = "\r"; break; case 'unix': default: $br = "\n"; break; } if (!$objects) { pla_error("Search on dn (" . htmlspecialchars($dn) . ") came back empty"); }
if (isset($_POST['filter'])) { preg_replace('/\\s+/', '', $_POST['filter']); $attributes = split(',', preg_replace('/\\s+/', '', $_POST['attributes'])); } else { $attributes = array(); } # add system attributes if needed if (isset($_POST['sys_attr'])) { array_push($attributes, '*'); array_push($attributes, '+'); } isset($_POST['exporter_id']) or pla_error(_('You must choose an export format.')); $exporter_id = $_POST['exporter_id']; isset($exporters[$exporter_id]) or pla_error(_('Invalid export format')); # Initialisation of other variables $friendly_rdn = get_rdn($base_dn, 1); $extension = $exporters[$exporter_id]['extension']; # default case not really needed switch ($format) { case 'win': $br = "\r\n"; break; case 'mac': $br = "\r"; break; case 'unix': default: $br = "\n"; } # get the decoree,ie the source $plaLdapExporter = new PlaLdapExporter($ldapserver->server_id, $filter, $base_dn, $scope, $attributes);
/** * Recursively descend on the given dn and draw the tree in plm * * @param dn $dn Current dn. * @param object $LDAPServer LDAPServer object * @param int $level Level to start drawing (defaults to 2) * @todo: Currently draw PLM only shows the first 50 entries of the base children - possibly the childrens children too. Have disabed the size_limit on the base - need to check that it doesnt affect non PLM tree viewer and children where size > size_limit. */ function draw_tree_plm($dn, $ldapserver, $level = 2) { if (DEBUG_ENABLED) { debug_log('draw_tree_plm(): Entered with (%s,%s,%s)', 33, $dn, $ldapserver, $level); } global $config; $tree = get_cached_item($ldapserver->server_id, 'tree'); $encoded_dn = rawurlencode($dn); #$expand_href = sprintf('expand.php?server_id=%s&dn=%s',$ldapserver->server_id,$encoded_dn); $edit_href = sprintf('template_engine.php?server_id=%s&dn=%s', $ldapserver->server_id, $encoded_dn); #$img_src = sprintf('images/%s',$tree['browser'][$dn]['icon']); $rdn = get_rdn($dn); $dots = ''; for ($i = 1; $i <= $level; $i++) { $dots .= '.'; } # Have we tranversed this part of the tree yet? if (isset($tree['browser'][$dn]['open'])) { $tree_plm = sprintf("%s|%s|%s|%s|%s|%s|%s\n", $dots, $rdn . ' (' . number_format(count($tree['browser'][$dn]['children'])) . ')', $edit_href, $dn, $tree['browser'][$dn]['icon'], 'right_frame', isset($tree['browser'][$dn]['open']) ? $tree['browser'][$dn]['open'] : 0); foreach ($tree['browser'][$dn]['children'] as $dn) { $tree_plm .= draw_tree_plm($dn, $ldapserver, $level + 1); } } else { $size_limit = $config->GetValue('search', 'size_limit'); $child_count = count($ldapserver->getContainerContents($dn, $size_limit + 1, '(objectClass=*)', $config->GetValue('deref', 'tree'))); if ($child_count > $size_limit) { $child_count = $size_limit . '+'; } if ($child_count) { $tree_plm = sprintf("%s|%s|%s|%s|%s|%s|%s|%s\n", $dots, $rdn . ' (' . $child_count . ')', $edit_href, $dn, $tree['browser'][$dn]['icon'], 'right_frame', isset($tree['browser'][$dn]['open']) ? $tree['browser'][$dn]['open'] : 0, $child_count); } else { $tree_plm = sprintf("%s|%s|%s|%s|%s|%s|%s|%s\n", $dots, $rdn . ' (0)', $edit_href, $dn, $tree['browser'][$dn]['icon'], 'right_frame', isset($tree['browser'][$dn]['open']) ? $tree['browser'][$dn]['open'] : 0, $child_count); } } if (DEBUG_ENABLED) { debug_log('draw_tree_plm(): Returning (%s)', 33, $tree_plm); } return $tree_plm; }
$request['page']->drawSubTitle(); printf('<script type="text/javascript" language="javascript" src="%sdnChooserPopup.js"></script>', JSDIR); echo '<center>'; printf('%s <b>%s</b> %s:<br /><br />', _('Copy'), get_rdn($request['dn']), _('to a new object')); echo '<form action="cmd.php" method="post" name="copy_form">'; echo '<input type="hidden" name="cmd" value="copy" />'; printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="server_id_src" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="dn_src" value="%s" />', htmlspecialchars($request['dn'])); echo "\n"; echo '<table style="border-spacing: 10px">'; echo '<tr>'; printf('<td><acronym title="%s">%s</acronym>:</td>', _('The full DN of the new entry to be created when copying the source entry'), _('Destination DN')); echo '<td>'; printf('<input type="text" name="dn_dst" size="45" value="%s" />', htmlspecialchars($request['dn'])); draw_chooser_link('copy_form.dn_dst', 'true', get_rdn($request['dn'])); echo '</td>'; echo '</tr>'; echo "\n"; printf('<tr><td>%s:</td><td>%s</td></tr>', _('Destination Server'), server_select_list($app['server']->getIndex(), true, 'server_id_dst')); echo "\n"; # We search all children, not only the visible children in the tree $request['children'] = $app['server']->getContainerContents($request['dn']); if (count($request['children']) > 0) { echo '<tr>'; printf('<td><label for="recursive">%s</label>:</td>', _('Recursive copy')); echo '<td><input type="checkbox" id="recursive" name="recursive" onClick="copy_field_toggle(this)" />'; printf('<small>(%s)</small></td>', _('Recursively copy all children of this object as well.')); echo '</tr>'; echo "\n"; echo '<tr>';
function copy_dn($source_server_id, $source_dn, $dest_server_id, $dest_dn) { global $ds; $ds = pla_ldap_connect($dest_server_id) or pla_error("Could not connect to LDAP server"); $attrs = get_object_attrs($source_server_id, $source_dn); $new_entry = $attrs; // modify the prefix-value (ie "bob" in cn=bob) to match the destination DN's value. $rdn_attr = substr($dest_dn, 0, strpos($dest_dn, '=')); $rdn_value = get_rdn($dest_dn); $rdn_value = substr($rdn_value, strpos($rdn_value, '=') + 1); $new_entry[$rdn_attr] = $rdn_value; // don't need a dn attribute in the new entry unset($new_entry['dn']); $add_result = @ldap_add($ds, $dest_dn, $new_entry); if (!$add_result) { echo "</small><br /><br />"; pla_error("Failed to copy {$source_dn} (server: {$source_server_id}) to " . "{$dest_dn} (server: {$dest_server_id})", ldap_error($ds), ldap_errno($ds)); } return $add_result; }
*/ require './common.php'; # The DN we are working with $request = array(); $request['dn'] = get_request('dn', 'GET'); # Check if the entry exists. if (!$request['dn'] || !$app['server']->dnExists($request['dn'])) { error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); } $request['page'] = new TemplateRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, null)); $request['page']->setDN($request['dn']); $request['page']->accept(true); $request['template'] = $request['page']->getTemplate(); # Render the form if (get_request('meth', 'REQUEST') != 'ajax') { $request['page']->drawTitle(sprintf('%s <b>%s</b>', _('Add new attribute'), get_rdn($request['dn']))); $request['page']->drawSubTitle(); echo '<div style="text-align: center;">'; if (count($request['template']->getAvailAttrs())) { # If we have more than the configured entries, we'll separate our input to the old ways. if (count($request['template']->getAvailAttrs()) > $_SESSION[APPCONFIG]->getValue('appearance', 'max_add_attrs')) { $attr = array(); $attr['avail'] = array(); $attr['binary'] = array(); foreach ($request['template']->getAvailAttrs() as $attribute) { if ($app['server']->isAttrBinary($attribute->getName())) { array_push($attr['binary'], $attribute); } else { array_push($attr['avail'], $attribute); } }
*/ require './common.php'; # The DN we are working with $request = array(); $request['dn'] = get_request('dn', 'GET'); $request['page'] = new PageRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, 'none')); $request['page']->setDN($request['dn']); $request['page']->accept(); $request['template'] = $request['page']->getTemplate(); # Check if the entry exists. if (!$request['dn'] || !$app['server']->dnExists($request['dn'])) { system_message(array('title' => _('Entry does not exist'), 'body' => sprintf('%s (%s)', _('The entry does not exist'), $request['dn']), 'type' => 'error'), 'index.php'); } # We search all children, not only the visible children in the tree $request['children'] = $app['server']->getContainerContents($request['dn'], null, 0, '(objectClass=*)', LDAP_DEREF_NEVER); printf('<h3 class="title">%s %s</h3>', _('Delete'), htmlspecialchars(get_rdn($request['dn']))); printf('<h3 class="subtitle">%s: <b>%s</b> %s: <b>%s</b></h3>', _('Server'), $app['server']->getName(), _('Distinguished Name'), $request['dn']); echo "\n"; echo '<center>'; if (count($request['children'])) { printf('<b>%s</b><br /><br />', _('Permanently delete all children also?')); $search['href'] = htmlspecialchars(sprintf('cmd.php?cmd=query_engine&server_id=%s&filter=%s&base=%s&scope=sub&query=none&format=list', $app['server']->getIndex(), rawurlencode('objectClass=*'), rawurlencode($request['dn']))); $query = array(); $query['base'] = $request['dn']; $query['scope'] = 'sub'; $query['attrs'] = array('dn'); $query['size_limit'] = 0; $query['deref'] = LDAP_DEREF_NEVER; $request['search'] = $app['server']->query($query, null); echo '<table class="forminput" border="0">'; echo '<tr>';
/** * Gets a DN string using the user-configured tree_display_format string to format it. */ function draw_formatted_dn($ldapserver, $dn) { if (DEBUG_ENABLED) { debug_log('draw_formatted_dn(): Entered with (%s,%s)', 1, $ldapserver->server_id, $dn); } global $config; $format = $config->GetValue('appearance', 'tree_display_format'); preg_match_all("/%[a-zA-Z_0-9]+/", $format, $tokens); $tokens = $tokens[0]; foreach ($tokens as $token) { if (0 == strcasecmp($token, '%dn')) { $format = str_replace($token, pretty_print_dn($dn), $format); } elseif (0 == strcasecmp($token, '%rdn')) { $format = str_replace($token, pretty_print_dn(get_rdn($dn)), $format); } elseif (0 == strcasecmp($token, '%rdnvalue')) { $rdn = get_rdn($dn); $rdn_value = explode('=', $rdn, 2); $rdn_value = $rdn_value[1]; $format = str_replace($token, $rdn_value, $format); } else { $attr_name = str_replace('%', '', $token); $attr_values = $ldapserver->getDNAttr($dn, $attr_name); if (null == $attr_values) { $display = 'none'; } elseif (is_array($attr_values)) { $display = htmlspecialchars(implode(', ', $attr_values)); } else { $display = htmlspecialchars($attr_values); } $format = str_replace($token, $display, $format); } } return $format; }
/** * Gets a DN string using the user-configured tree_display_format string to format it. */ function draw_formatted_dn($server, $entry) { if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) { debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs); } $dn = $entry->getDn(); $formats = $_SESSION[APPCONFIG]->getValue('appearance', 'tree_display_format'); foreach ($formats as $format) { $has_none = false; preg_match_all('/%[a-zA-Z_0-9]+/', $format, $tokens); $tokens = $tokens[0]; if (DEBUG_ENABLED) { debug_log('The tokens are (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $tokens); } foreach ($tokens as $token) { if (strcasecmp($token, '%dn') == 0) { $format = str_replace($token, pretty_print_dn($dn), $format); } elseif (strcasecmp($token, '%rdn') == 0) { $format = str_replace($token, pretty_print_dn($entry->getRDN()), $format); } elseif (strcasecmp($token, '%rdnvalue') == 0) { $rdn = get_rdn($dn, 0, true); $rdn_value = explode('=', $rdn, 2); $rdn_value = $rdn_value[1]; $format = str_replace($token, $rdn_value, $format); } else { $attr_name = str_replace('%', '', $token); $attr_values = $server->getDNAttrValue($dn, $attr_name); if (is_null($attr_values) || count($attr_values) <= 0) { $display = '<' . _('none') . '>'; $has_none = true; } elseif (is_array($attr_values)) { $display = implode(', ', $attr_values); } else { $display = $attr_values; } $format = str_replace($token, $display, $format); } } # If this format has all values available, use it. Otherwise, try the next one if (!$has_none) { return $format; } } return $format; }
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); } }
# The DN we are working with $request = array(); $request['dn'] = get_request('dn', 'GET'); # Check if the entry exists. if (!$request['dn'] || !$app['server']->dnExists($request['dn'])) { error(sprintf(_('The entry (%s) does not exist.'), $request['dn']), 'error', 'index.php'); } $request['page'] = new PageRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, 'none')); $request['page']->setDN($request['dn']); $request['page']->accept(); # Render the form $request['page']->drawTitle(sprintf('%s <b>%s</b>', _('Compare another DN with'), get_rdn($request['dn']))); $request['page']->drawSubTitle(); printf('<script type="text/javascript" language="javascript" src="%sdnChooserPopup.js"></script>', JSDIR); echo '<center>'; printf('%s <b>%s</b> %s<br />', _('Compare'), get_rdn($request['dn']), _('with ')); echo '<form action="cmd.php" method="post" name="compare_form">'; echo '<input type="hidden" name="cmd" value="compare" />'; printf('<input type="hidden" name="server_id" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="server_id_src" value="%s" />', $app['server']->getIndex()); printf('<input type="hidden" name="dn_src" value="%s" />', htmlspecialchars($request['dn'])); echo "\n"; echo '<table style="border-spacing: 10px">'; echo '<tr>'; printf('<td><acronym title="%s">%s</acronym>:</td>', _('Compare this DN with another'), _('Destination DN')); echo '<td>'; echo '<input type="text" name="dn_dst" size="45" value="" />'; draw_chooser_link('compare_form.dn_dst', 'true', ''); echo '</td>'; echo '</tr>'; echo "\n";
</center> <?php flush(); ?> <?php if ($results) { foreach ($results as $dn => $attrs) { ?> <?php $encoded_dn = rawurlencode($dn); ?> <?php $rdn = utf8_decode(get_rdn($dn)); ?> <div class="search_result"> <a href="edit.php?server_id=<?php echo $server_id; ?> &dn=<?php echo $encoded_dn; ?> "> <?php echo htmlspecialchars($rdn); ?> </a> </div> <table class="attrs">
} echo '<table class="result_box" width="100%" border="1">'; 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) {
protected function drawFormReadWriteValueGidAttribute($attribute, $i) { if (DEBUGTMP) { printf('<font size=-2>%s</font><br />', __METHOD__); } $this->drawFormReadWriteValueAttribute($attribute, $i); $server = $this->getServer(); $val = $attribute->getValue($i); # If this is a gidNumber on a non-PosixGroup entry, lookup its name and description for convenience if ($this->template->getDN() && !in_array_ignore_case('posixGroup', $this->getServer()->getDNAttrValue($this->template->getDN(), 'objectclass'))) { $query['filter'] = sprintf('(&(objectClass=posixGroup)(gidNumber=%s))', $val); $query['attrs'] = array('dn', 'description'); # Reorganise our base, so that our base is first $bases = array_unique(array_merge(array($server->getContainerTop($this->template->getDN())), $server->getBaseDN())); # Search our bases, until we find a match. foreach ($bases as $base) { $query['base'] = $base; $group = $this->getServer()->query($query, null); if (count($group) > 0) { echo '<br />'; $group = array_pop($group); $group_dn = $group['dn']; $group_name = explode('=', get_rdn($group_dn)); $group_name = $group_name[1]; $href = sprintf('cmd.php?cmd=template_engine&server_id=%s&dn=%s', $this->getServerID(), rawurlencode($group_dn)); echo '<small>'; printf('<a href="%s">%s</a>', htmlspecialchars($href), $group_name); $description = isset($group['description']) ? $group['description'] : null; if (is_array($description)) { foreach ($description as $item) { printf(' (%s)', $item); } } else { printf(' (%s)', $description); } echo '</small>'; break; } } } }
$dns2 = array('dc=example, dc=com', 'cn=joe,dc=example,dc=com', 'CN =joe,dc=Example2,dc =com', 'cn= 2bob, dc= example,dc =com'); for ($i = 0; $i < count($dns1); $i++) { var_dump(pla_compare_dns($dns1[$i], $dns2[$i])); echo "\n"; } } // testing get_rdn() if (false) { echo "Should be uid=bäb: "; echo get_rdn("uid=bäb,ou=People-copy1,ou=People-copy2,ou=People2,dc=example,dc=com"); echo "<br>\n"; echo "Should be dc=com: "; echo get_rdn("dc=com"); echo "<br>\n"; echo "Should be Fred: "; echo get_rdn("Fred"); echo "<br>\n"; } // testing get_container() if (false) { echo "Should be ou=People-copy1,ou=People-copy2,ou=People2,dc=example,dc=com: "; var_dump(get_container("uid=bäb,ou=People-copy1,ou=People-copy2,ou=People2,dc=example,dc=com")); echo "<br>\n"; echo "Should be null: "; var_dump(get_container("dc=com")); echo "<br>\n"; echo "Should be null: "; var_dump(get_container("Fred")); echo "<br>\n"; } // tests pla_explode_dn()
*/ $friendly_attrs = process_friendly_attr_table(); # Iterate over each entry $i = 0; 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)]));
public function readEntry() { static $haveVersion = false; if ($lines = $this->nextLines()) { # If we have a version line. if (!$haveVersion && preg_match('/^version:/', $lines[0])) { list($text, $version) = $this->getAttrValue(array_shift($lines)); if ($version != 1) { return $this->error(sprintf('%s %s', _('LDIF import only suppports version 1'), $version), $lines); } $haveVersion = true; $lines = $this->nextLines(); } $server = $this->getServer(); # The first line should be the DN if (preg_match('/^dn:/', $lines[0])) { list($text, $dn) = $this->getAttrValue(array_shift($lines)); # The second line should be our changetype if (preg_match('/^changetype:[ ]*(delete|add|modrdn|moddn|modify)/i', $lines[0])) { $attrvalue = $this->getAttrValue($lines[0]); $changetype = $attrvalue[1]; array_shift($lines); } else { $changetype = 'add'; } $this->template = new Template($this->server_id, null, null, $changetype); switch ($changetype) { case 'add': $rdn = get_rdn($dn); $container = $server->getContainer($dn); $this->template->setContainer($container); $this->template->accept(); $this->getAddDetails($lines); $this->template->setRDNAttributes($rdn); return $this->template; break; case 'modify': if (!$server->dnExists($dn)) { return $this->error(sprintf('%s %s', _('DN does not exist'), $dn), $lines); } $this->template->setDN($dn); $this->template->accept(false, true); return $this->getModifyDetails($lines); break; case 'moddn': case 'modrdn': if (!$server->dnExists($dn)) { return $this->error(sprintf('%s %s', _('DN does not exist'), $dn), $lines); } $this->template->setDN($dn); $this->template->accept(); return $this->getModRDNAttributes($lines); break; default: if (!$server->dnExists($dn)) { return $this->error(_('Unkown change type'), $lines); } } } else { return $this->error(_('A valid dn line is required'), $lines); } } else { return false; } }