Example #1
0
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'));
        }
    }
}
	* Present the only template, if there is only one.

Creating and editing entries use two objects:
* A template object which describes how the template should be rendered (and what values should asked for, etc)
* A page object, which is responsible for actually sending out the HTML to the browser.

So:
* we init a new TemplateRender object
* we init a new Template object
* set the DN or container on the template object
	* If setting the DN, this in turn should read the "old values" from the LDAP server
* If we are not on the first page (ie: 2nd, 3rd, 4th step, etc), we should accept the post values that we have obtained thus far

* Finally submit the update to "update_confirm", or the create to "create", when complete.
*/
require './common.php';
$request = array();
$request['dn'] = get_request('dn', 'REQUEST');
$request['page'] = new TemplateRender($app['server']->getIndex(), get_request('template', 'REQUEST', false, null));
# If we have a DN, then this is to edit the entry.
if ($request['dn']) {
    $app['server']->dnExists($request['dn']) or error(sprintf('%s (%s)', _('No such entry'), pretty_print_dn($request['dn'])), 'error', 'index.php');
    $request['page']->setDN($request['dn']);
    $request['page']->accept();
} else {
    if ($app['server']->isReadOnly()) {
        error(_('You cannot perform updates while server is in read-only mode'), 'error', 'index.php');
    }
    $request['page']->setContainer(get_request('container', 'REQUEST'));
    $request['page']->accept();
}
Example #3
0
$request['dnDST'] = get_request('dn_dst');
$ldap = array();
$ldap['SRC'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_src'));
$ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst'));
# Error checking
if (!trim($request['dnDST'])) {
    error(_('You left the destination DN blank.'), 'error', 'index.php');
}
if ($ldap['DST']->isReadOnly()) {
    error(_('Destination server is currently READ-ONLY.'), 'error', 'index.php');
}
if ($ldap['DST']->dnExists($request['dnDST'])) {
    error(sprintf(_('The destination entry (%s) already exists.'), pretty_print_dn($request['dnDST'])), 'error', 'index.php');
}
if (!$ldap['DST']->dnExists($ldap['DST']->getContainer($request['dnDST']))) {
    error(sprintf(_('The destination container (%s) does not exist.'), pretty_print_dn($ldap['DST']->getContainer($request['dnDST']))), 'error', 'index.php');
}
if (pla_compare_dns($request['dnSRC'], $request['dnDST']) == 0 && $ldap['SRC']->getIndex() == $ldap['DST']->getIndex()) {
    error(_('The source and destination DN are the same.'), 'error', 'index.php');
}
$request['recursive'] = get_request('recursive') == 'on' ? true : false;
$request['remove'] = get_request('remove') == 'yes' ? true : false;
if ($request['recursive']) {
    $filter = get_request('filter', 'POST', false, '(objectClass=*)');
    # Build a tree similar to that of the tree browser to give to r_copy_dn
    $ldap['tree'] = array();
    printf('<h3 class="title">%s%s</h3>', _('Copying '), $request['dnSRC']);
    printf('<h3 class="subtitle">%s</h3>', _('Recursive copy progress'));
    print '<br /><br />';
    print '<small>';
    printf('%s...', _('Building snapshot of tree to copy'));
Example #4
0
$dn_dst = $_POST['new_dn'];
$do_recursive = isset($_POST['recursive']) && $_POST['recursive'] == 'on' ? true : false;
$do_remove = isset($_POST['remove']) && $_POST['remove'] == 'yes' ? true : false;
include './header.php';
# Error checking
if (0 == strlen(trim($dn_dst))) {
    pla_error(_('You left the destination DN blank.'));
}
if (pla_compare_dns($dn_src, $dn_dst) == 0 && $server_id_src == $server_id_dst) {
    pla_error(_('The source and destination DN are the same.'));
}
if ($ldapserver_dst->dnExists($dn_dst)) {
    pla_error(sprintf(_('The destination entry (%s) already exists.'), pretty_print_dn($dn_dst)));
}
if (!$ldapserver_dst->dnExists(get_container($dn_dst))) {
    pla_error(sprintf(_('The destination container (%s) does not exist.'), pretty_print_dn(get_container($dn_dst))));
}
if ($do_recursive) {
    $filter = isset($_POST['filter']) ? $_POST['filter'] : '(objectClass=*)';
    # Build a tree similar to that of the tree browser to give to r_copy_dn
    $snapshot_tree = array();
    print '<body>';
    printf('<h3 class="title">%s%s</h3>', _('Copying '), htmlspecialchars($dn_src));
    printf('<h3 class="subtitle">%s</h3>', _('Recursive copy progress'));
    print '<br /><br />';
    print '<small>';
    print _('Building snapshot of tree to copy... ');
    flush();
    $snapshot_tree = build_tree($ldapserver_src, $dn_src, array(), $filter);
    printf('<span style="color:green">%s</span><br />', _('Success'));
    flush();
Example #5
0
 protected function get_formatted_dn($entry, $level)
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     if ($level < 0) {
         return pretty_print_dn($entry->getDN());
     } else {
         return draw_formatted_dn($this->getServer(), $entry);
     }
 }
Example #6
0
 */
/**
 */
require './common.php';
# The DNs we are working with
$request = array();
$request['dnSRC'] = get_request('dn_src');
$request['dnDST'] = get_request('dn_dst');
$ldap = array();
$ldap['SRC'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_src'));
$ldap['DST'] = $_SESSION[APPCONFIG]->getServer(get_request('server_id_dst'));
if (!$ldap['SRC']->dnExists($request['dnSRC'])) {
    error(sprintf('%s (%s)', _('No such entry.'), pretty_print_dn($request['dnSRC'])), 'error', 'index.php');
}
if (!$ldap['DST']->dnExists($request['dnDST'])) {
    error(sprintf('%s (%s)', _('No such entry.'), pretty_print_dn($request['dnDST'])), 'error', 'index.php');
}
$request['pageSRC'] = new PageRender($ldap['SRC']->getIndex(), get_request('template', 'REQUEST', false, 'none'));
$request['pageSRC']->setDN($request['dnSRC']);
$request['pageSRC']->accept();
$request['templateSRC'] = $request['pageSRC']->getTemplate();
$request['pageDST'] = new PageRender($ldap['DST']->getIndex(), get_request('template', 'REQUEST', false, 'none'));
$request['pageDST']->setDN($request['dnDST']);
$request['pageDST']->accept();
$request['templateDST'] = $request['pageDST']->getTemplate();
# Get a list of all attributes.
$attrs_all = array_unique(array_merge($request['templateSRC']->getAttributeNames(), $request['templateDST']->getAttributeNames()));
$request['pageSRC']->drawTitle(_('Comparing the following DNs'));
echo '<br/>';
echo '<table class="entry" width=100% border=0>';
echo '<tr class="heading">';
Example #7
0
    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 (is_null($dn)) {
    pla_error(_('You must specify a DN'));
}
if (!$ldapserver->dnExists($dn)) {
    pla_error(sprintf(_('No such entry: %s'), '<b>' . pretty_print_dn($dn) . '</b>'));
}
# Check the user-defined custom callback first.
if (run_hook('pre_entry_delete', array('server_id' => $ldapserver->server_id, 'dn' => $dn))) {
    $del_result = $ldapserver->delete($dn);
} else {
    pla_error(sprintf(_('Could not delete the entry: %s'), '<b>' . pretty_print_dn($dn) . '</b>'));
}
if ($del_result) {
    # Custom callback
    run_hook('post_entry_delete', array('server_id' => $ldapserver->server_id, 'dn' => $dn));
    include './header.php';
    echo '<body>';
    echo '<script type="text/javascript" language="javascript">parent.left_frame.location.reload();</script>';
    echo '<br /><br />';
    printf('<center>' . _('Entry %s deleted successfully.') . '</center>', '<b>' . pretty_print_dn($dn) . '</b>');
    echo '</body>';
} else {
    pla_error(sprintf(_('Could not delete the entry: %s'), '<b>' . pretty_print_dn($dn) . '</b>'), $ldapserver->error(), $ldapserver->errno());
}
echo '</html>';
Example #8
0
$encoded_dn_dst = rawurlencode($dn_dst);
$server_id_src = isset($_POST['server_id_src']) ? $_POST['server_id_src'] : '';
$server_id_dst = isset($_POST['server_id_dst']) ? $_POST['server_id_dst'] : '';
$ldapserver_src = $ldapservers->Instance($server_id_src);
if (!$ldapserver_src->haveAuthInfo()) {
    pla_error(_('Not enough information to login to server. Please check your configuration.'));
}
$ldapserver_dst = $ldapservers->Instance($server_id_dst);
if (!$ldapserver_src->haveAuthInfo()) {
    pla_error(_('Not enough information to login to server. Please check your configuration.'));
}
if (!$ldapserver_src->dnExists($dn_src)) {
    pla_error(sprintf(_('No such entry: %s'), pretty_print_dn($dn_src)));
}
if (!$ldapserver_dst->dnExists($dn_dst)) {
    pla_error(sprintf(_('No such entry: %s'), pretty_print_dn($dn_dst)));
}
$friendly_attrs = process_friendly_attr_table();
$attrs_src = $ldapserver_src->getDNAttrs($dn_src, false, $config->GetValue('deref', 'view'));
$attrs_dst = $ldapserver_dst->getDNAttrs($dn_dst, false, $config->GetValue('deref', 'view'));
# Get a list of all attributes.
$attrs_all = array_keys($attrs_src);
foreach ($attrs_dst as $key => $val) {
    if (!in_array($key, $attrs_all)) {
        $attrs_all[] = $key;
    }
}
include './header.php';
?>

<body>
/**
 * This function displays the LDAP tree for all the servers that you have
 * in config.php. We read the session variable 'tree' to know which
 * dns are expanded or collapsed. No query string parameters are expected,
 * however, you can use a '#' offset to scroll to a given dn. The syntax is
 * tree.php#<server_id>_<rawurlencoded dn>, so if I wanted to scroll to
 * dc=example,dc=com for server 3, the URL would be:
 *	tree.php#3_dc%3Dexample%2Cdc%3Dcom
 */
function draw_server_tree()
{
    if (DEBUG_ENABLED) {
        debug_log('draw_server_tree(): Entered with ()', 33);
    }
    global $ldapserver;
    global $recently_timed_out_servers;
    global $config;
    static $tm = null;
    $server_id = $ldapserver->server_id;
    $tree = get_cached_item($ldapserver->server_id, 'tree');
    # Does this server want mass deletion available?
    if ($ldapserver->isMassDeleteEnabled()) {
        echo '<form name="mass_delete" action="mass_delete.php" method="post" target="right_frame">';
        printf('<input type="hidden" name="server_id" value="%s" />', $ldapserver->server_id);
        echo "\n\n";
    }
    echo '<table class="tree" cellspacing="0">';
    echo '<tr class="server">';
    printf('<td class="icon"><img src="images/server.png" alt="%s" /></td>', _('Server'));
    printf('<td colspan="99"><a name="%s"></a>', $ldapserver->server_id);
    printf('<nobr>%s ', htmlspecialchars($ldapserver->name));
    if ($ldapserver->haveAuthInfo() && $ldapserver->auth_type != 'config') {
        printf('<acronym title="%s"><img width=14 height=14 src="images/timeout.png" alt="timeout" /></acronym>', sprintf(_('Inactivity will log you off at %s'), strftime('%H:%M', time() + $ldapserver->session_timeout * 60)));
    }
    echo '</nobr></td></tr>';
    /* do we have what it takes to authenticate here, or do we need to
       present the user with a login link (for 'cookie' and 'session' auth_types)? */
    if ($ldapserver->haveAuthInfo()) {
        if ($ldapserver->connect(false)) {
            $schema_href = sprintf('schema.php?server_id=%s" target="right_frame', $ldapserver->server_id);
            $search_href = sprintf('search.php?server_id=%s" target="right_frame', $ldapserver->server_id);
            $refresh_href = sprintf('refresh.php?server_id=%s', $ldapserver->server_id);
            $logout_href = get_custom_file($ldapserver->server_id, 'logout.php', '') . '?server_id=' . $ldapserver->server_id;
            $info_href = sprintf('server_info.php?server_id=%s', $ldapserver->server_id);
            $import_href = sprintf('ldif_import_form.php?server_id=%s', $ldapserver->server_id);
            $export_href = sprintf('export_form.php?server_id=%s', $ldapserver->server_id);
            # Draw the quick-links below the server name:
            echo '<tr><td colspan="100" class="links">';
            echo '<nobr>';
            echo '( ';
            printf('<a title="%s %s" href="%s">%s</a> | ', _('View schema for'), $ldapserver->name, $schema_href, _('schema'));
            printf('<a title="%s %s" href="%s">%s</a> | ', _('search'), $ldapserver->name, $search_href, _('search'));
            printf('<a title="%s %s" href="%s">%s</a> | ', _('Refresh all expanded containers for'), $ldapserver->name, $refresh_href, _('refresh'));
            printf('<a title="%s" target="right_frame" href="%s">%s</a> | ', _('View server-supplied information'), $info_href, _('info'));
            printf('<a title="%s" target="right_frame" href="%s">%s</a> | ', _('Import entries from an LDIF file'), $import_href, _('import'));
            printf('<a href="%s" target="right_frame">%s</a>', $export_href, _('export'));
            if ($ldapserver->auth_type != 'config') {
                printf(' | <a title="%s" href="%s" target="right_frame">%s</a>', _('Logout of this server'), $logout_href, _('logout'));
            }
            echo ' )</nobr></td></tr>';
            if ($ldapserver->auth_type != 'config') {
                $logged_in_dn = $ldapserver->getLoggedInDN();
                echo '<tr><td class="links" colspan="100"><nobr>' . _('Logged in as: ');
                if ($ldapserver->getDNBase($logged_in_dn) == $logged_in_dn) {
                    $logged_in_branch = '';
                    $logged_in_dn_array = array();
                } else {
                    $logged_in_branch = preg_replace('/,' . $ldapserver->getDNBase($logged_in_dn) . '$/', '', $logged_in_dn);
                    $logged_in_dn_array = explode(',', $logged_in_branch);
                }
                $logged_in_dn_array[] = $ldapserver->getDNBase($logged_in_dn);
                $rdn = $logged_in_dn;
                if (strcasecmp('anonymous', $logged_in_dn)) {
                    foreach ($logged_in_dn_array as $rdn_piece) {
                        printf('<a class="logged_in_dn" href="template_engine.php?server_id=%s&amp;dn=%s" target="right_frame">%s</a>', $server_id, rawurlencode($rdn), pretty_print_dn($rdn_piece));
                        if ($rdn_piece != end($logged_in_dn_array)) {
                            echo ',';
                        }
                        $rdn = substr($rdn, 1 + strpos($rdn, ','));
                    }
                } else {
                    echo 'Anonymous';
                }
                echo '</nobr></td></tr>';
            }
            if ($ldapserver->isReadOnly()) {
                printf('<tr><td class="links" colspan="100"><nobr>(%s)</nobr></td></tr>', _('read only'));
            }
            $javascript_forms = '';
            $javascript_id = 0;
            $tree_plm = '';
            if ($config->GetValue('appearance', 'tree_plm') && !isset($tm)) {
                $tm = new TreeMenu();
                $tm->setDirroot(JSDIR . 'phplayersmenu/');
                $tm->setIcondir(HTDOCDIR . '/images/');
                $tm->setIconwww('images/');
                $tm->setImgwww(JSDIR . 'phplayersmenu/menuimages/');
            }
            foreach ($ldapserver->getBaseDN() as $base_dn) {
                # Did we get a base_dn for this server somehow?
                if ($base_dn) {
                    # is the root of the tree expanded already?
                    if (isset($tree['browser'][$base_dn]['open']) && $tree['browser'][$base_dn]['open']) {
                        $expand_href = sprintf('collapse.php?server_id=%s&amp;dn=%s', $ldapserver->server_id, rawurlencode($base_dn));
                        $expand_img = 'images/minus.png';
                        $expand_alt = '-';
                        $child_count = number_format(count($tree['browser'][$base_dn]['children']));
                    } else {
                        /* Check if the LDAP server is not yet initialized
                           (ie, the base DN configured in config.php does not exist) */
                        if (!$ldapserver->dnExists($base_dn)) {
                            $javascript_id++;
                            printf('<tr><td class="spacer"></td><td><img src="images/unknown.png" /></td><td colspan="98">%s</td></tr>', pretty_print_dn($base_dn));
                            /* Move this form and add it to the end of the html - otherwise the javascript
                               doesnt work when isMassDeleteEnabled returning true. */
                            $javascript_forms .= sprintf('<form name="create_base_form_%s" method="post" action="template_engine.php" target="right_frame">', $javascript_id);
                            $javascript_forms .= sprintf('<input type="hidden" name="template" value="custom" />');
                            $javascript_forms .= sprintf('<input type="hidden" name="server_id" value="%s" />', $ldapserver->server_id);
                            $javascript_forms .= sprintf('<input type="hidden" name="container" value="%s" />', htmlspecialchars($rdn));
                            $javascript_forms .= sprintf('<input type="hidden" name="rdn" value="%s" />', get_rdn($base_dn));
                            $javascript_forms .= sprintf('</form>');
                            printf('<tr><td class="spacer"></td><td colspan="98"><small>%s<a href="javascript:document.create_base_form_%s.submit()">%s</a></small></td></tr>', _('This base entry does not exist.'), $javascript_id, _('Create it?'));
                            continue;
                        } else {
                            $expand_href = sprintf('expand.php?server_id=%s&amp;dn=%s', $ldapserver->server_id, rawurlencode($base_dn));
                            $expand_img = 'images/plus.png';
                            $expand_alt = '+';
                            # $size_limit = $config->GetValue('search','size_limit');
                            $size_limit = -1;
                            if ($ldapserver->isLowBandwidth()) {
                                $child_count = null;
                            } else {
                                $children = $ldapserver->getContainerContents($base_dn, $size_limit + 1, '(objectClass=*)', $config->GetValue('deref', 'tree'));
                                $child_count = count($children);
                                #								if ($child_count > $size_limit)
                                #									$child_count = $size_limit.'+';
                            }
                        }
                    }
                    $create_href = sprintf('create_form.php?server_id=%s&amp;container=%s', $ldapserver->server_id, rawurlencode($base_dn));
                    $edit_href = sprintf('template_engine.php?server_id=%s&amp;dn=%s', $ldapserver->server_id, rawurlencode($base_dn));
                    $icon = isset($tree['browser'][$base_dn]['icon']) ? $tree['browser'][$base_dn]['icon'] : get_icon($ldapserver, $base_dn);
                    # Shall we draw the "mass-delete" checkbox?
                    if ($ldapserver->isMassDeleteEnabled()) {
                        printf('<td><input type="checkbox" name="mass_delete[%s]" /></td>', htmlspecialchars($base_dn));
                    }
                    if ($config->GetValue('appearance', 'tree_plm')) {
                        $tree_plm .= sprintf(".|%s|%s|%s|%s|%s|%s\n", pretty_print_dn($base_dn) . ($child_count ? ' (' . $child_count . ')' : ''), $edit_href, $base_dn, $icon, 'right_frame', 0);
                    } else {
                        echo '<tr>';
                        printf('<td class="expander"><a href="%s"><img src="%s" alt="%s" /></a></td>', $expand_href, $expand_img, $expand_alt);
                        printf('<td class="icon"><a href="%s" target="right_frame"><img src="images/%s" alt="img" /></a></td>', $edit_href, $icon);
                        printf('<td class="rdn" colspan="98"><nobr><a href="%s" target="right_frame">%s</a>', $edit_href, pretty_print_dn($base_dn));
                        if ($child_count) {
                            printf(' <span class="count">(%s)</span>', $child_count);
                        }
                        echo '</nobr></td>';
                        echo '</tr>';
                    }
                } else {
                    // end if( $base_dn )
                    # The server refuses to give out the base dn
                    printf('<tr><td class="spacer"></td><td colspan="98"><small>%s<br />%s<br /><b>%s</b></small></td></tr>', _('Could not determine the root of your LDAP tree.'), _('It appears that the LDAP server has been configured to not reveal its root.'), _('Please specify it in config.php'));
                    # Proceed to the next server. We cannot draw anything else for this server.
                    continue;
                }
                flush();
                if ($config->GetValue('appearance', 'tree_plm')) {
                    foreach ($children as $child_dn) {
                        $tree_plm .= draw_tree_plm($child_dn, $ldapserver);
                    }
                } else {
                    # Is the root of the tree expanded already?
                    if (isset($tree['browser'][$base_dn]['open']) && $tree['browser'][$base_dn]['open']) {
                        if ($ldapserver->isShowCreateEnabled() && count($tree['browser'][$base_dn]['children']) > 10) {
                            draw_create_link($ldapserver->server_id, $base_dn, -1, urlencode($base_dn));
                        }
                        foreach ($tree['browser'][$base_dn]['children'] as $child_dn) {
                            draw_tree_html($child_dn, $ldapserver, 0);
                        }
                        if (!$ldapserver->isReadOnly()) {
                            echo '<tr><td class="spacer"></td></tr>';
                            if ($ldapserver->isShowCreateEnabled()) {
                                draw_create_link($ldapserver->server_id, $base_dn, -1, urlencode($base_dn));
                            }
                        }
                    }
                }
            }
            // foreeach
            if ($config->GetValue('appearance', 'tree_plm')) {
                $tm->setMenuStructureString($tree_plm);
                $tm->parseStructureForMenu('pla_tree_' . $ldapserver->server_id);
                $tm->setTreeMenuTheme('');
                $tm->newTreeMenu('pla_tree_' . $ldapserver->server_id);
                echo '<tr><td colspan=99>' . $tm->getTreeMenu('pla_tree_' . $ldapserver->server_id) . '</td></tr>';
            }
        } else {
            // end if( $ldapserver->connect(false) )
            # could not connect to LDAP server
            printf('<tr><td class="spacer"></td><td><img src="images/warning_small.png" alt="%s" /></td><td colspan="99"><small><span style="color:red">%s</span></small></td></tr>', _('warning'), _('Could not connect to LDAP server.'));
            if ($ldapserver->auth_type != 'config') {
                $logout_href = sprintf('%s?server_id=%s', get_custom_file($ldapserver->server_id, 'logout.php', ''), $ldapserver->server_id);
                printf('<tr><td class="spacer"></td><td class="spacer"></td><td colspan="99"><small><a target="right_frame" href="%s">%s</a></small></td></tr>', $logout_href, _('logout'));
            }
            # Proceed to the next server in the list. We cannot do anything mroe here.
            return;
        }
    } else {
        // end if $ldapserver->haveAuthInfo()
        /* We don't have enough information to login to this server
           Draw the "login..." link */
        $login_href = sprintf('%s?server_id=%s', get_custom_file($ldapserver->server_id, 'login_form.php', ''), $ldapserver->server_id);
        printf('<tr class="login"><td class="spacer"></td><td><a href="%s" target="right_frame"><img src="images/uid.png" align="top" alt="%s" /></a></td><td colspan="99"><a href="%s" target="right_frame">%s</a></td></tr>', $login_href, _('login'), $login_href, _('Login...'));
        # If the server recently timed out display the message
        if (in_array($ldapserver->server_id, $recently_timed_out_servers)) {
            printf('<tr><td class="spacer"></td><td colspan="100" class="links">%s</td></tr>', _('(Session timed out. Automatically logged out.)'));
        }
    }
    if ($ldapserver->isMassDeleteEnabled() && !$config->GetValue('appearance', 'tree_plm')) {
        printf('<tr><td colspan="99"><input type="submit" value="%s" /></td></tr>', _('Delete Checked Entries'));
        echo '<!-- The end of the mass deletion form -->';
        echo '</table>';
        echo '</form>';
    } else {
        echo '</table>';
    }
    echo "\n\n";
    if (isset($javascript_forms) && $javascript_forms) {
        echo "<!-- Forms for javascript submit to call to create base_dns -->\n";
        echo $javascript_forms;
        echo "<!-- The end of the forms for javascript submit to call to create base_dns -->\n";
    }
}
Example #10
0
/**
 * 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;
}
Example #11
0
// $Header: /cvsroot/phpldapadmin/phpldapadmin/tools/unit_test.php,v 1.20 2005/07/16 16:23:28 wurley Exp $
/**
 * @package phpLDAPadmin
 */
/**
 */
include './common.php';
include './header.php';
echo "<pre>";
require_once realpath('functions.php');
// test DN sorting
if (false) {
    $dns = array("ou=people,dc=example,dc=com", "cn=Admin,ou=People,dc=example,dc=com", "cn=Joe,ou=people,dc=example,dc=com", "dc=example,dc=com", "cn=Fred,ou=people,dc=example,dc=org", "cn=Dave,ou=people,dc=example,dc=org", "dc=com");
    usort($dns, "pla_compare_dns");
    foreach ($dns as $dn) {
        echo pretty_print_dn($dn) . "<br>";
    }
}
// test pla_verbose_error() using ldap_error_codes.txt
if (false) {
    for ($i = 0; $i < 255; $i++) {
        $num = "0x" . str_pad(dechex($i), 2, "0", STR_PAD_LEFT);
        var_dump($num);
        print_r(pla_verbose_error($num));
    }
}
// tests is_dn_string()
if (false) {
    $dn_strs = array(' cn=joe,dc=example,dc=com', 'cn = joe, dc= example, dc =com', '  cn=asdf asdf, ou= foo bar, o =foo bar, dc=com', 'cn=True!=False,dc=example,dc=com');
    $not_dn_strs = array(' asdf asdf ', '== asdf asdf ', ' = = = = = = = =');
    echo "All should be true:\n";
Example #12
0
/**
 * 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 = '&lt;' . _('none') . '&gt;';
                    $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;
}
Example #13
0
<?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'));
}
Example #14
0
<table class="delete_confirm">
<tr>
	<td>
	<?php 
    echo _('Are you sure you want to permanently delete this object?');
    ?>
<br />
	<br />
	<nobr><acronym title="<?php 
    echo _('Distinguished Name');
    ?>
"><?php 
    echo _('DN');
    ?>
</acronym>:  <b><?php 
    echo pretty_print_dn($dn);
    ?>
</b></nobr><br />
	<nobr><?php 
    echo _('Server');
    ?>
: <b><?php 
    echo htmlspecialchars($ldapserver->name);
    ?>
</b></nobr><br />
	<br />

	<table width="100%">
	<tr>
		<td>
			<center>
$pjs = array();
# REMOVE THSE @todo
$today = date('U');
$shadow_before_today_attrs = arrayLower(array('shadowLastChange', 'shadowMin'));
$shadow_after_today_attrs = arrayLower(array('shadowMax', 'shadowExpire', 'shadowWarning', 'shadowInactive'));
$shadow_format_attrs = array_merge($shadow_before_today_attrs, $shadow_after_today_attrs);
# END REMOVE
# If we have a DN, then this is to edit the entry.
if (isset($_REQUEST['dn'])) {
    $dn = $_GET['dn'];
    $decoded_dn = rawurldecode($dn);
    $encoded_dn = rawurlencode($decoded_dn);
    if (!$ldapserver->haveAuthInfo()) {
        pla_error(_('Not enough information to login to server. Please check your configuration.'));
    }
    $ldapserver->dnExists($dn) or pla_error(sprintf(_('No such entry: %s'), pretty_print_dn($dn)));
    $rdn = get_rdn($dn);
    $attrs = $ldapserver->getDNAttrs($dn, false, $config->GetValue('deref', 'view'));
    $modified_attrs = isset($_REQUEST['modified_attrs']) ? $_REQUEST['modified_attrs'] : false;
    $show_internal_attrs = isset($_REQUEST['show_internal_attrs']) ? true : false;
    # If an entry has more children than this, stop searching and display this amount with a '+'
    $max_children = 100;
} else {
    $dn = '';
    $rdn = '';
    $encoded_dn = '';
    if ($_REQUEST['template'] == 'custom') {
        include TMPLDIR . 'template_header.php';
        require TMPLDIR . 'creation/custom.php';
        die;
    } else {