function get_ldap_connection() { $ldapconn = ldap_connect(LDAP_HOST); $auth = new MozillaAuthAdapter(); if (!isset($_SERVER["PHP_AUTH_USER"])) { ask(); wail_and_bail(); } else { // Check for validity of login if ($auth->check_valid_user($_SERVER["PHP_AUTH_USER"])) { $user_dn = $auth->user_to_dn($_SERVER["PHP_AUTH_USER"]); $password = $_SERVER["PHP_AUTH_PW"]; } else { wail_and_bail(); } } if (!ldap_bind($ldapconn, $user_dn, $_SERVER['PHP_AUTH_PW'])) { wail_and_bail(); die(ldap_error($ldapconn)); } return $ldapconn; }
<?php require_once 'init.php'; require_once 'config.php'; require_once 'country_codes.php'; error_reporting(E_ERROR); $edit = new MozillaEditingAdapter(); $auth = new MozillaAuthAdapter(); $search = new MozillaSearchAdapter($ldapconn); $ldap_char_blacklist = array("*", "&", "|", "(", ")", "="); $user = str_replace($ldap_char_blacklist, "", $_SERVER["PHP_AUTH_USER"]); $is_admin = $auth->is_phonebook_admin($ldapconn, $auth->user_to_dn($user)); if (isset($_REQUEST["edit_mail"]) && $is_admin) { $edit_user = str_replace($ldap_char_blacklist, "", $_REQUEST["edit_mail"]); } else { $edit_user = $auth->user_to_email($user); } $user_search = $search->query_users("mail={$edit_user}", "dc=mozilla"); $user_data = $user_search[0]; if (!empty($_POST)) { $new_user_data = array(); foreach ($editable_fields as $editable_field) { if (isset($_POST[$editable_field])) { if (in_array($editable_field, $MONKEY_FREE_ARRAY)) { $_POST[$editable_field][0] = trim(preg_replace('/[^\\p{L}\\s]/u', '', $_POST[$editable_field][0])); } $new_user_data[$editable_field] = $_POST[$editable_field]; } if (isset($new_user_data["other"][0])) { $new_user_data["other"][0] = strip_tags($new_user_data["other"][0]); }
<?php require_once "init.php"; require_once "config.php"; require_once "preprocessors-attr.inc"; $auth = new MozillaAuthAdapter(); $search = new MozillaSearchAdapter($ldapconn); $keyword = isset($_GET["query"]) ? $_GET["query"] : '*'; $exact = isset($_GET["exact_search"]) ? true : false; $entries = normalize($search->search_users($keyword, $exact = $exact)); $attr_preps = get_attr_preprocessors(); $preprocess_attr_functions = array(); foreach ($entries as &$entry) { foreach ($entry as $name => $attribute) { $prep = isset($attr_preps[$name]) ? $attr_preps[$name] : NULL; if (!isset($preprocess_attr_functions[$prep])) { $preprocess_attr_functions[$prep] = function_exists($prep); } if ($preprocess_attr_functions[$prep]) { $entry[$name] = call_user_func($prep, $attribute); } } $search->preprocess_entry($entry); } $format = isset($_GET["format"]) ? $_GET["format"] : "json"; if (!in_array($format, $output_formats) || !file_exists("output-{$format}.inc")) { $format = "json"; } require_once "output-{$format}.inc"; $function = "output_{$format}"; $dn = $auth->user_to_dn($_SERVER["PHP_AUTH_USER"]);
<?php require_once "init.php"; $people = array(); $orphans = array(); $everyone = array(); $tree = new MozillaTreeAdapter($everyone); $auth = new MozillaAuthAdapter(); $data = array(); foreach ($tree->conf as $conf) { $search = ldap_search($ldapconn, $conf["ldap_search_base"], $conf["ldap_search_filter"], $conf["ldap_search_attributes"]); $data = array_merge($data, ldap_get_entries($ldapconn, $search)); } $tree_view_roots = $tree->roots; foreach ($data as $person) { $mail = $person['mail'][0]; $everyone[$mail] = $tree->process_entry($person); // If a user has a manager, try to find their place in the tree. // Unless they're a root themselves. if (!in_array($mail, $tree_view_roots) && !empty($person["manager"][0])) { $manager = $auth->dn_to_email($person["manager"][0]); if (empty($people[$manager])) { $people[$manager] = array($mail); } else { $people[$manager][] = $mail; } } elseif (!empty($mail) && !in_array($mail, $tree_view_roots)) { // Person is an orphan. $orphans[] = $mail; } }