Exemple #1
0
 /**
  * Work out how deep the "opened" tree is.
  */
 public function getDepth()
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     $server = $this->getServer();
     # If we are not logged in
     if (!$server->isLoggedIn(null)) {
         return 0;
     }
     static $depths = array();
     if (!isset($depths[$server->getIndex()])) {
         $max = 0;
         # BaseDN are open, so we start at 1.
         foreach ($this->entries as $dn) {
             $basedepth = count(pla_explode_dn($server->getContainerPath($dn->getDN(), '/')));
             $depth = 0;
             $depth = count(pla_explode_dn($dn->getDN())) + 1 - $basedepth;
             if ($depth > $max) {
                 $max = $depth;
             }
         }
         $depths[$server->getIndex()] = $max;
     }
     return $depths[$server->getIndex()];
 }
Exemple #2
0
 /**
  * This function will take the DN, convert it to lowercase and strip unnessary
  * commas. This result will be used as the index for the tree object.
  * Any display of a DN should use the object->dn entry, not the index.
  * The reason we need to do this is because:
  * uid=User A,ou=People,c=AU and
  * uid=User B, ou=PeOpLe, c=au
  * are infact in the same branch, but PLA will show them inconsistently.
  *
  * @param dn DN to clean
  * @return dn Lowercase clean DN
  */
 private function indexDN($dn)
 {
     if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
         debug_log('Entered (%%)', 33, 0, __FILE__, __LINE__, __METHOD__, $fargs);
     }
     $index = strtolower(implode(',', pla_explode_dn($dn)));
     if (DEBUG_ENABLED) {
         debug_log('Result (%s)', 1, 0, __FILE__, __LINE__, __METHOD__, $index);
     }
     return $index;
 }
<?php

/*
 * delete_form.php
 * Displays a last chance confirmation form to delete a dn.
 *
 * Variables that come in as GET vars:
 *  - dn (rawurlencoded)
 *  - server_id
 */
require 'common.php';
$dn = $_GET['dn'];
$encoded_dn = rawurlencode($dn);
$server_id = $_GET['server_id'];
$rdn = pla_explode_dn($dn);
$rdn = $rdn[0];
$server_name = $servers[$server_id]['name'];
if (is_server_read_only($server_id)) {
    pla_error("You cannot perform updates while server is in read-only mode");
}
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.");
$children = get_container_contents($server_id, $dn);
$has_children = count($children) > 0 ? true : false;
?>

<?php 
include 'header.php';
?>
<body>
}
// 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()
if (false) {
    var_dump(pla_explode_dn("cn=<stuff>,dc=example,dc=<com>"));
}
if (false) {
    $password = '******';
    foreach (array('md5', 'md5crypt', 'sha', 'ssha', 'smd5', 'crypt', 'clear') as $enc_type) {
        $crypted_password = password_hash($password, $enc_type);
        print "[" . $enc_type . "] " . $crypted_password . "<br />";
        print "  Test: " . (password_check($crypted_password, $password) ? "passed" : "failed");
        print "\n";
        //unset($crypted_password);
        flush();
    }
}
if (true) {
    $secret = "foobar";
    $passwords = array('fun!244A', 'asdf', 'dc=stuff,ou=things', 'y()ikes');
/**
 * Reverses a DN such that the top-level RDN is first and the bottom-level RDN is last
 * For example:
 * <code>
 *   cn=Brigham,ou=People,dc=example,dc=com
 * </code>
 * Becomes:
 * <code>
 *   dc=com,dc=example,ou=People,cn=Brigham
 * </code>
 * This makes it possible to sort lists of DNs such that they are grouped by container.
 *
 * @param string $dn The DN to reverse
 *
 * @return string The reversed DN
 *
 * @see pla_compare_dns
 */
function pla_reverse_dn($dn)
{
    if (DEBUG_ENABLED) {
        debug_log('pla_reverse_dn(): Entered with (%s)', 1, $dn);
    }
    foreach (pla_explode_dn($dn) as $key => $branch) {
        // pla_expode_dn returns the array with an extra count attribute, we can ignore that.
        if ($key === "count") {
            continue;
        }
        if (isset($rev)) {
            $rev = $branch . "," . $rev;
        } else {
            $rev = $branch;
        }
    }
    return $rev;
}
/**
 * Reverses a DN such that the top-level RDN is first and the bottom-level RDN is last
 * For example:
 * <code>
 *   cn=Brigham,ou=People,dc=example,dc=com
 * </code>
 * Becomes:
 * <code>
 *   dc=com,dc=example,ou=People,cn=Brigham
 * </code>
 * This makes it possible to sort lists of DNs such that they are grouped by container.
 *
 * @param string The DN to reverse
 * @return string The reversed DN
 *
 * @see pla_compare_dns
 * @see pla_explode_dns
 */
function pla_reverse_dn($dn)
{
    if (DEBUG_ENABLED && (($fargs = func_get_args()) || ($fargs = 'NOARGS'))) {
        debug_log('Entered (%%)', 1, 0, __FILE__, __LINE__, __METHOD__, $fargs);
    }
    return implode(',', array_reverse(pla_explode_dn($dn)));
}
/**
 * Recursively descend on the given dn and draw the tree in html
 */
function draw_tree_html($dn, $server_id, $level = 0)
{
    global $servers, $tree, $tree_icons, $lang;
    $id = $server_id;
    $encoded_dn = rawurlencode($dn);
    $expand_href = "expand.php?server_id={$id}&amp;dn={$encoded_dn}";
    $collapse_href = "collapse.php?server_id={$id}&amp;dn={$encoded_dn}";
    $edit_href = "edit.php?server_id={$id}&amp;dn={$encoded_dn}";
    // should never happen, but just in case
    if (!isset($tree_icons[$server_id][$dn])) {
        $tree_icons[$server_id][$dn] = get_icon($server_id, $dn);
    }
    $img_src = 'images/' . $tree_icons[$server_id][$dn];
    $rdn = pla_explode_dn($dn);
    $rdn = $rdn[0];
    echo '<tr>';
    for ($i = 0; $i <= $level; $i++) {
        echo '<td class="spacer"></td>' . "\n";
    }
    // is this node expanded? (deciding whether to draw "+" or "-")
    if (isset($tree[$server_id][$dn])) {
        ?>
		<td class="expander">
			<nobr>
			<a href="<?php 
        echo $collapse_href;
        ?>
"><img src="images/minus.png" alt="plus" /></a>
			</nobr>
		</td>
		<?php 
        $object_count = ' <span class="count">(' . count($tree[$server_id][$dn]) . ')</span>';
    } else {
        ?>
	
		<td class="expander">
			<nobr>
			<a href="<?php 
        echo $expand_href;
        ?>
"><img src="images/plus.png" alt="minus" /></a>
			</nobr>
		</td>
		<?php 
        $object_count = '';
    }
    ?>
	

	<td class="icon">
		<a href="<?php 
    echo $edit_href;
    ?>
"
		   target="right_frame"
		   name="<?php 
    echo $server_id;
    ?>
_<?php 
    echo $encoded_dn;
    ?>
"><img src="<?php 
    echo $img_src;
    ?>
" /></a>
	</td>
	<td class="rdn" colspan="<?php 
    echo 97 - $level;
    ?>
">
		<nobr>
			<a href="<?php 
    echo $edit_href;
    ?>
"
				target="right_frame"><?php 
    echo htmlspecialchars(utf8_decode($rdn));
    ?>
</a>
				<?php 
    echo $object_count;
    ?>
		</nobr>
	</td>
	</tr>

	<?php 
    if (isset($tree[$server_id][$dn]) && is_array($tree[$server_id][$dn])) {
        foreach ($tree[$server_id][$dn] as $dn) {
            draw_tree_html($dn, $server_id, $level + 1);
        }
        // print the "Create New object" link.
        $create_href = "create_form.php?server_id={$server_id}&amp;container={$encoded_dn}";
        echo '<tr>';
        for ($i = 0; $i <= $level; $i++) {
            echo '<td class="spacer"></td>';
        }
        echo '<td class="spacer"></td>';
        echo '<td class="icon"><a href="' . $create_href . '" target="right_frame"><img src="images/star.png" /></a></td>';
        echo '<td class="create" colspan="' . (97 - $level) . '"><a href="' . $create_href . '" target="right_frame" title="' . $lang['create_new_entry_in'] . ' ' . $rdn . '">' . $lang['create_new'] . '</a></td></tr>';
    }
    echo '</tr>';
}
require 'common.php';
$dn = rawurldecode($_POST['dn']);
$server_id = $_POST['server_id'];
$new_rdn = $_POST['new_rdn'];
$new_rdn = utf8_encode($new_rdn);
if (is_server_read_only($server_id)) {
    pla_error("You cannot perform updates while server is in read-only mode");
}
if (is_server_read_only($server_id)) {
    pla_error("You cannot perform updates while server is in read-only mode");
}
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.");
$ds = pla_ldap_connect($server_id) or pla_error("Could not connect to LDAP sever");
// build the container string
$old_rdn = pla_explode_dn($dn);
$container = $old_rdn[1];
for ($i = 2; $i < count($old_rdn) - 1; $i++) {
    $container .= ',' . $old_rdn[$i];
}
if (!$container) {
    pla_error("Error: Container is null!");
}
if (!ldap_rename($ds, $dn, $new_rdn, $container, false)) {
    pla_error("Error: Could not rename the object.", ldap_error($ds), ldap_errno($ds));
} else {
    // update the session tree to reflect the name change
    session_start();
    if (session_is_registered('tree')) {
        $tree = $_SESSION['tree'];
        $tree_icons = $_SESSION['tree_icons'];
Exemple #9
0
 foreach ($all_attrs as $i => $attr_name) {
     if ($ldapserver->isAttrBinary($attr_name)) {
         unset($all_attrs[$i]);
         $binary_attrs[] = $attr_name;
     }
 }
 /* If we trim any attrs out above, then we will have a gap in the index
    sequence and will get an "undefined index" error below. This prevents
    that from happening. */
 $all_attrs = array_values($all_attrs);
 /* add the required attribute based on the RDN provided by the user
    (ie, if the user specifies "cn=Bob" for their RDN, make sure "cn" is
    in the list of required attributes. */
 $rdn_attr = trim(substr($rdn, 0, strpos($rdn, '=')));
 $rdn_value = trim(substr($rdn, strpos($rdn, '=') + 1));
 $rdn_value = @pla_explode_dn($rdn);
 $rdn_value = @explode('=', $rdn_value[0], 2);
 $rdn_value = @$rdn_value[1];
 if (in_array($rdn_attr, $all_attrs) && !in_array($rdn_attr, $required_attrs)) {
     $required_attrs[] = $rdn_attr;
 }
 printf('<h4>%s</h4>', _('Step 2 of 2: Specify attributes and values'));
 echo '<form action="create.php" method="post" enctype="multipart/form-data">';
 echo '<input type="hidden" name="step" value="2" />';
 printf('<input type="hidden" name="new_dn" value="%s" />', htmlspecialchars($dn));
 printf('<input type="hidden" name="new_rdn" value="%s" />', htmlspecialchars($rdn));
 printf('<input type="hidden" name="container" value="%s" />', htmlspecialchars($container));
 printf('<input type="hidden" name="server_id" value="%s" />', $ldapserver->server_id);
 printf('<input type="hidden" name="object_classes" value="%s" />', rawurlencode(serialize($oclasses)));
 echo '<table class="edit_dn" cellspacing="0">';
 printf('<tr><th colspan="2">%s</th></tr>', _('Required Attributes'));
function get_container($dn)
{
    $rdn = pla_explode_dn($dn);
    $container = $rdn[1];
    for ($i = 2; $i < count($rdn) - 1; $i++) {
        $container .= ',' . $rdn[$i];
    }
    return $container;
}