function get_ldap_cn($user, $debug = 0) { try { if (!($ds = get_ldap_connection())) { throw new Exception('Unable to connect to LDAP Server'); } $dn = "mail={$user}, o=com, dc=mozilla"; //the object itself instead of the top search level as in ldap_search $filter = "(objectclass=inetOrgPerson)"; // this command requires some filter $justthese = array("cn"); //the attributes to pull, which is much more efficient than pulling all attributes if you don't do this if (!($sr = ldap_read($ds, $dn, $filter, $justthese))) { throw new Exception('Incorrect Username or filter'); } if (!($entry = ldap_get_entries($ds, $sr))) { throw new Exception('Unable to find LDAP entry for ' . $user); } if ($debug != 0) { echo $entry[0]["cn"][0] . " is the name in LDAP for " . $user; } ldap_close($ds); return $entry[0]["cn"][0]; } catch (Exception $e) { echo 'Oops! I countered the following error: ', $e->getMessage(), "\n"; } }
function change_pass($user, $new_pass) { global $config; global $ldap_connection; get_ldap_connection($config['user'], $config['pass']); if ($ldap_connection) { $filter = "(sAMAccountName={$user})"; $result = ldap_search($ldap_connection, $config['domain_dn'], $filter); ldap_sort($ldap_connection, $result, "sn"); $info = ldap_get_entries($ldap_connection, $result); $isLocked = $info[0]["lockoutTime"]; if ($isLocked > 0) { return msg('account_locked'); } $userDn = $info[0]["distinguishedname"][0]; $userdata["unicodePwd"] = iconv("UTF-8", "UTF-16LE", '"' . $new_pass . '"'); $result = ldap_mod_replace($ldap_connection, $userDn, $userdata); if (!$result) { return msg(ldap_error($ldap_connection)); } } else { return msg("wrong_admin"); } close_ldap_connection(); return ""; }
<?php require_once 'init.php'; $ldap = get_ldap_connection(); include 'tableau_trusted.php'; if (add_tableau_user($_SERVER["PHP_AUTH_USER"], $_SERVER["PHP_AUTH_PW"], get_ldap_cn($_SERVER["PHP_AUTH_USER"]), 'interactor', 'none', '0', 0)) { $trusted_url = login_tableau($_SERVER["PHP_AUTH_USER"], TABLEAU_SERVER, 'workbooks'); // echo '<meta http-equiv="refresh" content="2;url=' . $trusted_url . '">'; } else { echo "Failed attempt to create user: "******"PHP_AUTH_USER"]; }
ini_set("display_errors", 1); ini_set("memory_limit", "64M"); if (!defined('MEMCACHE_ENABLED')) { define("MEMCACHE_ENABLED", true); } require_once "config.php"; require_once "functions.php"; require_once "constants.php"; require_once "FirePHPCore/fb.php"; ob_start(); if (class_exists("Memcache") && MEMCACHE_ENABLED) { $memcache_on = true; } else { $memcache_on = false; } $ldapconn = get_ldap_connection(); if ($memcache_on) { $memcache = new Memcache(); if (empty($memcache_servers)) { $memcache_servers = array('localhost:11211'); } if (!defined('MEMCACHE_PREFIX')) { define('MEMCACHE_PREFIX', 'phonebook:'); } foreach ($memcache_servers as $mc_server) { list($host, $port) = explode(':', $mc_server, 2); $memcache->addServer($host, $port); } } /* * A `user' is an identifier that uniquely represents a user. This could be a