Ejemplo n.º 1
0
function pla_rdelete($server_id, $dn)
{
    $children = get_container_contents($server_id, $dn);
    global $ds;
    $ds = pla_ldap_connect($server_id);
    if (!is_array($children) || count($children) == 0) {
        echo "<nobr>Deleting " . htmlspecialchars($dn) . "...";
        flush();
        if (ldap_delete($ds, $dn)) {
            echo " <span style=\"color:green\">Success</span></nobr><br />\n";
            return true;
        } else {
            pla_error("Failed to delete dn: " . htmlspecialchars(utf8_decode($dn)), ldap_error($ds), ldap_errno($ds));
        }
    } else {
        foreach ($children as $child_dn) {
            pla_rdelete($server_id, $child_dn);
        }
        echo "<nobr>Deleting " . htmlspecialchars($dn) . "...";
        flush();
        if (ldap_delete($ds, $dn)) {
            echo " <span style=\"color:green\">Success</span></nobr><br />\n";
            return true;
        } else {
            pla_errror("Failed to delete dn: " . htmlspecialchars(utf8_decode($dn)), ldap_error($ds), ldap_errno($ds));
        }
    }
}
<?php

/* 
 * server_info.php
 * Fetches and displays all information that it can from the specified server
 * 
 * Variables that come in as GET vars:
 *  - server_id
 */
require 'common.php';
$server_id = $_GET['server_id'];
$server_name = $servers[$server_id]['name'];
$ds = pla_ldap_connect($server_id) or pla_error("Could not connect or authenticate to LDAP server");
$r = @ldap_read($ds, '', 'objectClass=*', array('+'));
if (!$r) {
    pla_error("Could not fetch any information from the server");
}
$entry = @ldap_first_entry($ds, $r);
$attrs = @ldap_get_attributes($ds, $entry);
$count = @ldap_count_entries($ds, $r);
//echo "<pre>"; print_r( $attrs ); echo "</pre>";
include 'header.php';
?>

<h3 class="title">Server info for <?php 
echo htmlspecialchars($server_name);
?>
</h3>
<h3 class="subtitle">Server reports the following information about itself</h3>

<?php 
Ejemplo n.º 3
0
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.");
// special case for binary attributes (like jpegPhoto and userCertificate):
// we must go read the data from the file and override $val with the binary data
if ($is_binary_val) {
    $file = $_FILES['val']['tmp_name'];
    $f = fopen($file, 'r');
    $binary_data = fread($f, filesize($file));
    fclose($f);
    $val = $binary_data;
}
// Automagically hash new userPassword attributes according to the
// chosen in config.php.
if (0 == strcasecmp($attr, 'userpassword')) {
    if ($servers[$server_id]['default_hash'] != '') {
        $enc_type = $servers[$server_id]['default_hash'];
        $new_val = password_hash($new_val, $enc_type);
        $val = $new_val;
    }
}
$ds = pla_ldap_connect($server_id) or pla_error("Could not connect to LDAP server");
$new_entry = array($attr => $val);
$result = @ldap_mod_add($ds, $dn, $new_entry);
if ($result) {
    header("Location: edit.php?server_id={$server_id}&dn={$encoded_dn}&updated_attr={$encoded_attr}");
} else {
    pla_error("Failed to add the attribute.", ldap_error($ds), ldap_errno($ds));
}
require 'common.php';
$container = isset($_GET['container']) ? rawurldecode($_GET['container']) : false;
$server_id = isset($_GET['server_id']) ? $_GET['server_id'] : false;
$return_form_element = $_GET['form_element'];
include "header.php";
echo "<h3 class=\"subtitle\">Automagic Entry Chooser</h3>\n";
if ($container) {
    echo "Server: <b>" . htmlspecialchars($servers[$server_id]['name']) . "</b><br />\n";
    echo "Looking in: <b>" . htmlspecialchars($container) . "</b><br />\n";
}
/* Has the use already begun to descend into a specific server tree? */
if ($server_id !== false && $container !== false) {
    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.");
    pla_ldap_connect($server_id) or pla_error("Coult not connect to LDAP server.");
    $dn_list = get_container_contents($server_id, $container);
    $base_dn = $servers[$server_id]['base'];
    if (!$base_dn) {
        $base_dn = try_to_get_root_dn($server_id);
    }
    if ($container == $base_dn) {
        $parent_container = false;
        $up_href = "entry_chooser.php?form_element={$return_form_element}";
    } else {
        $parent_container = get_container($container);
        $up_href = "entry_chooser.php?form_element={$return_form_element}&amp;server_id={$server_id}&amp;container=" . rawurlencode($parent_container);
    }
    echo "&nbsp;<a href=\"{$up_href}\" style=\"text-decoration:none\">" . "<img src=\"images/up.png\"> Back Up...</a><br />\n";
    if (count($dn_list) == 0) {
        echo "&nbsp;&nbsp;&nbsp;(no entries)<br />\n";
Ejemplo n.º 5
0
$dn = rawurldecode($_POST['dn']);
$encoded_dn = rawurlencode($dn);
$update_array = $_POST['update_array'];
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.");
is_array($update_array) or pla_error("update_array is malformed. This might be a phpLDAPadmin bug. Please report it.");
// check for delete attributes (indicated by the attribute entry appearing like this: attr => ''
foreach ($update_array as $attr => $val) {
    if (!is_array($val)) {
        if ($val == '') {
            $update_array[$attr] = array();
        } else {
            $update_array[$attr] = $val;
        }
    } else {
        foreach ($val as $i => $v) {
            $update_array[$attr][$i] = $v;
        }
    }
}
$ds = pla_ldap_connect($server_id);
$res = @ldap_modify($ds, $dn, $update_array);
if ($res) {
    $redirect_url = "edit.php?server_id={$server_id}&dn={$encoded_dn}";
    foreach ($update_array as $attr => $junk) {
        $redirect_url .= "&modified_attrs[]={$attr}";
    }
    header("Location: {$redirect_url}");
} else {
    pla_error("Could not perform ldap_modify operation.", ldap_error($ds), ldap_errno($ds));
}
Ejemplo n.º 6
0
 */
require 'common.php';
$dn = rawurldecode($_POST['dn']);
$encoded_dn = rawurlencode($dn);
$new_oclass = $_POST['new_oclass'];
$server_id = $_POST['server_id'];
$new_attrs = $_POST['new_attrs'];
if (is_server_read_only($server_id)) {
    pla_error($lang['no_updates_in_read_only_mode']);
}
check_server_id($server_id) or pla_error($lang['bad_server_id']);
have_auth_info($server_id) or pla_error($lang['not_enough_login_info']);
$new_entry = array();
$new_entry['objectClass'] = $new_oclass;
$new_attrs_entry = array();
$new_oclass_entry = array('objectClass' => $new_oclass);
if (is_array($new_attrs) && count($new_attrs) > 0) {
    foreach ($new_attrs as $attr => $val) {
        $new_entry[$attr] = $val;
    }
}
//echo "<pre>";
//print_r( $new_entry );
//exit;
$ds = pla_ldap_connect($server_id) or pla_error($lang['could_not_connect']);
$add_res = @ldap_mod_add($ds, $dn, $new_entry);
if (!$add_res) {
    pla_error($lang['could_not_perform_ldap_mod_add'], ldap_error($ds), ldap_errno($ds));
} else {
    header("Location: edit.php?server_id={$server_id}&dn={$encoded_dn}");
}
Ejemplo n.º 7
0
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;
}
function get_schema_syntaxes($server_id)
{
    static $cache;
    // cache the schema to prevent multiple schema fetches from LDAP server
    if (isset($cache[$server_id])) {
        //echo "Using syntax cache.<br />";
        return $cache[$server_id];
    }
    $ds = pla_ldap_connect($server_id);
    if (!$ds) {
        return false;
    }
    // get all the attributeTypes
    $result = @ldap_read($ds, 'cn=subschema', '(objectClass=*)', array('ldapSyntaxes'), 0, 200, 0, LDAP_DEREF_ALWAYS);
    if (!$result) {
        $result = @ldap_read($ds, 'cn=schema', '(objectClass=*)', array('ldapSyntaxes'), 0, 200, 0, LDAP_DEREF_ALWAYS);
    }
    if ($result) {
        $raw = ldap_get_entries($ds, $result);
    } else {
        return array();
    }
    // build the array of attributes
    $syntaxes = array();
    for ($i = 0; $i < $raw[0]['ldapsyntaxes']['count']; $i++) {
        $syntax = $raw[0]['ldapsyntaxes'][$i];
        preg_match("/[\\s]+([\\d\\.]+)[\\s]+/", $syntax, $oid);
        preg_match("/[\\s]+DESC[\\s]+'([\\)\\(:?\\.a-zA-Z0-9\\-_ ]+)'/", $syntax, $description);
        $key = strtolower(trim($oid[1]));
        if (!$key) {
            continue;
        }
        $syntaxes[$key] = array();
        $syntaxes[$key]['description'] = $description[1];
    }
    ksort($syntaxes);
    // cache the schema to prevent multiple schema fetches from LDAP server
    $cache[$server_id] = $syntaxes;
    return $syntaxes;
}
Ejemplo n.º 9
0
function try_to_get_root_dn($server_id)
{
    if (!have_auth_info($server_id)) {
        return false;
    }
    $ds = pla_ldap_connect($server_id);
    if (!$ds) {
        return false;
    }
    $r = @ldap_read($ds, '', 'objectClass=*', array('namingContexts'));
    if (!$r) {
        return false;
    }
    $r = @ldap_get_entries($ds, $r);
    if (isset($r[0]['namingcontexts'][0])) {
        $root_dn = $r[0]['namingcontexts'][0];
        return $root_dn;
    } else {
        return false;
    }
}