本文整理汇总了PHP中AuthLdap类的典型用法代码示例。如果您正苦于以下问题:PHP AuthLdap类的具体用法?PHP AuthLdap怎么用?PHP AuthLdap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AuthLdap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pdfLdapForm
static function pdfLdapForm(PluginPdfSimplePDF $pdf, Group $item)
{
if (Session::haveRight("config", "r") && AuthLdap::useAuthLdap()) {
$pdf->setColumnsSize(100);
$pdf->displayTitle(__('LDAP directory link'));
$pdf->displayText('<b>' . sprintf(__('%1$s: %2$s'), __('User attribute containing its groups') . '</b>', $item->getField('ldap_field')));
$pdf->displayText('<b>' . sprintf(__('%1$s: %2$s'), __('Attribute value') . '</b>', $item->getField('ldap_value')));
$pdf->displayText('<b>' . sprintf(__('%1$s: %2$s'), __('Group DN') . '</b>', $item->getField('ldap_group_dn')));
$pdf->displaySpace();
}
}
示例2: buildLdapFilter
/**
* @param $authldap AuthLDAP object
**/
private static function buildLdapFilter(AuthLdap $authldap)
{
//Build search filter
$counter = 0;
$filter = '';
if (!empty($_SESSION['ldap_import']['criterias']) && $_SESSION['ldap_import']['interface'] == self::SIMPLE_INTERFACE) {
foreach ($_SESSION['ldap_import']['criterias'] as $criteria => $value) {
if ($value != '') {
$begin = 0;
$end = 0;
if (($length = strlen($value)) > 0) {
if ($value[0] == '^') {
$begin = 1;
}
if ($value[$length - 1] == '$') {
$end = 1;
}
}
if ($begin || $end) {
// no Toolbox::substr, to be consistent with strlen result
$value = substr($value, $begin, $length - $end - $begin);
}
$counter++;
$filter .= '(' . $authldap->fields[$criteria] . '=' . ($begin ? '' : '*') . $value . ($end ? '' : '*') . ')';
}
}
} else {
$filter = "(" . $authldap->getField("login_field") . "=*)";
}
//If time restriction
$begin_date = isset($_SESSION['ldap_import']['begin_date']) && !empty($_SESSION['ldap_import']['begin_date']) ? $_SESSION['ldap_import']['begin_date'] : NULL;
$end_date = isset($_SESSION['ldap_import']['end_date']) && !empty($_SESSION['ldap_import']['end_date']) ? $_SESSION['ldap_import']['end_date'] : NULL;
$filter .= self::addTimestampRestrictions($begin_date, $end_date);
$ldap_condition = $authldap->getField('condition');
//Add entity filter and filter filled in directory's configuration form
return "(&" . (isset($_SESSION['ldap_import']['entity_filter']) ? $_SESSION['ldap_import']['entity_filter'] : '') . " {$filter} {$ldap_condition})";
}
示例3: useAuthExt
/**
* Is an external authentication used ?
*
* @return boolean
**/
static function useAuthExt()
{
//Get all the ldap directories
if (AuthLdap::useAuthLdap()) {
return true;
}
if (AuthMail::useAuthMail()) {
return true;
}
if (!empty($CFG_GLPI["x509_email_field"])) {
return true;
}
// Existing auth method
if (!empty($CFG_GLPI["ssovariables_id"])) {
return true;
}
// Using CAS server
if (!empty($CFG_GLPI["cas_host"])) {
return true;
}
return false;
}
示例4: isEntityDirectoryConfigured
/**
* @since version 0.84 (before in entitydata.class)
*
* @param $entities_id
**/
static function isEntityDirectoryConfigured($entities_id)
{
$entity = new self();
if ($entity->getFromDB($entities_id) && $entity->getField('authldaps_id') > 0) {
return true;
}
//If there's a directory marked as default
if (AuthLdap::getDefault()) {
return true;
}
return false;
}
示例5: showLDAPForm
/**
* @param $ID
**/
function showLDAPForm($ID)
{
$options = array();
$this->initForm($ID, $options);
echo "<form name='groupldap_form' id='groupldap_form' method='post' action='" . $this->getFormURL() . "'>";
echo "<div class='spaced'><table class='tab_cadre_fixe'>";
if (Group::canUpdate() && Session::haveRight("user", User::UPDATEAUTHENT) && AuthLdap::useAuthLdap()) {
echo "<tr class='tab_bg_1'>";
echo "<th colspan='2' class='center'>" . __('In users') . "</th></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Attribute of the user containing its groups') . "</td>";
echo "<td>";
Html::autocompletionTextField($this, "ldap_field");
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Attribute value') . "</td>";
echo "<td>";
Html::autocompletionTextField($this, "ldap_value");
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<th colspan='2' class='center'>" . __('In groups') . "</th>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . __('Group DN') . "</td>";
echo "<td>";
Html::autocompletionTextField($this, "ldap_group_dn");
echo "</td></tr>";
}
$options = array('colspan' => 1, 'candel' => false);
$this->showFormButtons($options);
}
示例6: unset
}
if (!isset($_SESSION["ldap_server"])) {
if (isset($_POST["ldap_server"])) {
$_SESSION["ldap_server"] = $_POST["ldap_server"];
} else {
Html::redirect($CFG_GLPI["root_doc"] . "/front/ldap.php");
}
}
if (!AuthLdap::testLDAPConnection($_SESSION["ldap_server"])) {
unset($_SESSION["ldap_server"]);
echo "<div class='center b'>" . __('Unable to connect to the LDAP directory') . "<br>";
echo "<a href='" . $_SERVER['PHP_SELF'] . "?next=listservers'>" . __('Back') . "</a></div>";
} else {
if (!isset($_SESSION["ldap_group_filter"])) {
$_SESSION["ldap_group_filter"] = '';
}
if (!isset($_SESSION["ldap_group_filter2"])) {
$_SESSION["ldap_group_filter2"] = '';
}
if (isset($_GET["order"])) {
$_SESSION["ldap_sortorder"] = $_GET["order"];
}
if (!isset($_SESSION["ldap_sortorder"])) {
$_SESSION["ldap_sortorder"] = "ASC";
}
AuthLdap::displayLdapFilter($_SERVER['PHP_SELF'], false);
AuthLdap::showLdapGroups($_SERVER['PHP_SELF'], $_GET['start'], 0, $_SESSION["ldap_group_filter"], $_SESSION["ldap_group_filter2"], $_SESSION["glpiactive_entity"], $_SESSION["ldap_sortorder"]);
}
}
}
Html::footer();
示例7: search
function search($query)
{
$userlist = array();
$ldapinfo = array();
$combined_userlist = array();
foreach (preg_split('/\\n/', $this->getConfig()->get('basedn')) as $i => $dn) {
$dn = trim($dn);
$servers = $this->getConfig()->get('servers');
$serversa = preg_split('/\\s+/', $servers);
$sd = $this->getConfig()->get('shortdomain');
$sda = preg_split('/;|,/', $sd);
$bind_dn = $this->getConfig()->get('bind_dn');
$bind_dna = preg_split('/\\n/', $bind_dn);
$bind_pw = $this->getConfig()->get('bind_pw');
$bind_pwa = preg_split('/;|,/', $bind_pw);
$ldapinfo[] = array('dn' => trim($dn), 'sd' => trim($sda[$i]), 'servers' => trim($serversa[$i]), 'bind_dn' => trim($bind_dna[$i]), 'bind_pw' => trim($bind_pwa[$i]));
}
foreach ($ldapinfo as $data) {
$ldap = new AuthLdap();
$ldap->serverType = 'ActiveDirectory';
$ldap->server = preg_split('/;|,/', $data['servers']);
$ldap->dn = $data['dn'];
$ldap->searchUser = $data['bind_dn'];
$ldap->searchPassword = $data['bind_pw'];
if ($ldap->connect()) {
$filter = "(&(objectCategory=person)(objectClass=user)(|(sAMAccountName={q}*)(firstName={q}*)(lastName={q}*)(displayName={q}*)))";
if ($userlist = $ldap->getUsers($query, array('sAMAccountName', 'sn', 'givenName', 'displayName', 'mail', 'telephoneNumber', 'distinguishedName'), $filter)) {
//echo 'userlist: ' . json_encode($userlist);
$temp_userlist = $this->multi_re_key($userlist, array('sAMAccountName', 'givenName', 'sn', 'displayName', 'mail', 'telephoneNumber', 'distinguishedName'), array('username', 'first', 'last', 'full', 'email', 'phone', 'dn'));
$combined_userlist = array_merge($combined_userlist, $temp_userlist);
}
} else {
$conninfo[] = array(false, $data['sd'] . " error: " . $ldap->ldapErrorCode . " - " . $ldap->ldapErrorText);
}
}
return $combined_userlist;
}
示例8: syncEntity
/**
* @param $pid
* @param $data
* @param $server
* @param $prof
* @param $verb
* @param $mail
**/
function syncEntity($pid, $data, $server, $prof, $verb, $mail)
{
global $DB, $LANG, $CFG_GLPI;
// Re-establish DB connexion - mandatory in each forked process
if (!DBConnection::switchToMaster()) {
echo " {$pid}: lost DB connection\n";
return 0;
}
// Server from entity (if not given from option)
if ($data['authldaps_id'] > 0) {
$server = $data['authldaps_id'];
}
$entity = new Entity();
if ($entity->getFromDB($id = $data['id'])) {
$tps = microtime(true);
if ($verb) {
echo " {$pid}: Synchonizing entity '" . $entity->getField('completename') . "' ({$id}, mail={$mail})\n";
}
$sql = "SELECT DISTINCT glpi_users.*\n FROM glpi_users\n INNER JOIN glpi_profiles_users\n ON (glpi_profiles_users.users_id = glpi_users.id\n AND glpi_profiles_users.entities_id = {$id}";
if ($prof > 0) {
$sql .= " AND glpi_profiles_users.profiles_id = {$prof}";
}
$sql .= ")\n WHERE glpi_users.authtype = " . Auth::LDAP;
if ($server > 0) {
$sql .= " AND glpi_users.auths_id = {$server}";
}
$users = array();
$results = array(AuthLDAP::USER_IMPORTED => 0, AuthLDAP::USER_SYNCHRONIZED => 0, AuthLDAP::USER_DELETED_LDAP => 0);
$req = $DB->request($sql);
$i = 0;
$nb = $req->numrows();
foreach ($req as $row) {
$i++;
$result = AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $row['name']), AuthLDAP::ACTION_SYNCHRONIZE, $row['auths_id']);
if ($result) {
$results[$result['action']] += 1;
$users[$row['id']] = $row['name'];
if ($result['action'] == AuthLDAP::USER_SYNCHRONIZED) {
if ($verb) {
echo " {$pid}: User '" . $row['name'] . "' synchronized ({$i}/{$nb})\n";
}
} else {
if ($verb) {
echo " {$pid}: User '" . $row['name'] . "' deleted\n";
}
}
} else {
if ($verb) {
echo " {$pid}: Problem with LDAP for user '" . $row['name'] . "'\n";
}
}
}
$tps = microtime(true) - $tps;
printf(" %d: Entity '%s' - Synchronized: %d, Deleted from LDAP: %d, Time: %.2f\"\n", $pid, $entity->getField('completename'), $results[AuthLDAP::USER_SYNCHRONIZED], $results[AuthLDAP::USER_DELETED_LDAP], $tps);
if ($mail) {
$report = '';
$user = new User();
foreach ($users as $id => $name) {
if ($user->getFromDB($id)) {
$logs = Log::getHistoryData($user, 0, $_SESSION['glpilist_limit'], "`date_mod`='" . $_SESSION['glpi_currenttime'] . "'");
if (count($logs)) {
$report .= "\n{$name} (" . $user->getName() . ")\n";
foreach ($logs as $log) {
$report .= "\t";
if ($log['field']) {
$report .= $log['field'] . ": ";
}
$report .= Html::clean($log['change']) . "\n";
}
}
} else {
$report .= "\n" . $name . "\n\t deleted\n";
}
}
if ($report) {
$report = "Synchronization of already imported users\n " . "Entité: " . $entity->getField('completename') . "\n " . "Date: " . Html::convDateTime($_SESSION['glpi_currenttime']) . "\n " . $report;
$entdata = new Entity();
$mmail = new NotificationMail();
$mmail->AddCustomHeader("Auto-Submitted: auto-generated");
$mmail->From = $CFG_GLPI["admin_email"];
$mmail->FromName = "GLPI";
$mmail->Subject = "[GLPI] LDAP directory link";
$mmail->Body = $report . "\n--\n" . $CFG_GLPI["mailing_signature"];
if ($mail & 1 && $entdata->getFromDB($entity->getField('id')) && $entdata->fields['admin_email']) {
$mmail->AddAddress($entdata->fields['admin_email']);
} else {
if ($mail & 1 && $verb) {
echo " {$pid}: No address found for email entity\n";
}
$mail = $mail & 2;
}
if ($mail & 2 && $CFG_GLPI['admin_email']) {
//.........这里部分代码省略.........
示例9: AuthLdap
<?php
include '../../../inc/includes.php';
Session::checkRight("config", "w");
$authldap = new AuthLdap();
$authldap->getFromDB($_POST['value']);
$filter = "(" . $authldap->getField("login_field") . "=*)";
$ldap_condition = $authldap->getField('condition');
echo "(& {$filter} {$ldap_condition})";
示例10: foreach
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$ids[] = $key;
}
}
$softdictionnayrule->replayRulesOnExistingDB(0, 0, $ids);
break;
case "force_user_ldap_update":
checkRight("user", "w");
$user = new User();
$ids = array();
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$user->getFromDB($key);
if ($user->fields["authtype"] == Auth::LDAP || $user->fields["authtype"] == Auth::EXTERNAL) {
AuthLdap::ldapImportUserByServerId(array('method' => AuthLDAP::IDENTIFIER_LOGIN, 'value' => $user->fields["name"]), 1, $user->fields["auths_id"]);
}
}
}
break;
case "add_transfer_list":
if (!isset($_SESSION['glpitransfer_list'])) {
$_SESSION['glpitransfer_list'] = array();
}
if (!isset($_SESSION['glpitransfer_list'][$_POST["itemtype"]])) {
$_SESSION['glpitransfer_list'][$_POST["itemtype"]] = array();
}
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$_SESSION['glpitransfer_list'][$_POST["itemtype"]][$key] = $key;
}
示例11: unset
GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkRight("user", User::IMPORTEXTAUTHUSERS);
Html::header(__('LDAP directory link'), $_SERVER['PHP_SELF'], "admin", "user", "ldap");
if (isset($_SESSION["ldap_sortorder"])) {
unset($_SESSION["ldap_sortorder"]);
}
AuthLdap::manageValuesInSession(array(), true);
echo "<div class='center'><table class='tab_cadre'>";
echo "<tr><th>" . __('Bulk import users from a LDAP directory') . "</th></tr>";
echo "<tr class='tab_bg_1'><td class='center b'>" . "<a href='ldap.import.php?mode=1&action=show'>" . __('Synchronizing already imported users') . "</a></td></tr>";
echo "<tr class='tab_bg_1'><td class='center b'>" . "<a href='ldap.import.php?mode=0&action=show'>" . __('Import new users') . "</a></td> </tr>";
echo "</table></div>";
Html::footer();
示例12: isEntityDirectoryConfigured
static function isEntityDirectoryConfigured($entities_id)
{
$entitydatas = new EntityData();
if ($entitydatas->getFromDB($entities_id) && $entitydatas->getField('authldaps_id') != NOT_AVAILABLE) {
return true;
}
//If there's a directory marked as default
if (AuthLdap::getDefault()) {
return true;
}
return false;
}
示例13: showLDAPForm
function showLDAPForm($target, $ID)
{
global $LANG;
if (!haveRight("group", "r")) {
return false;
}
if ($ID > 0) {
$this->check($ID, 'r');
} else {
// Create item
$this->check(-1, 'w');
}
echo "<form name='groupldap_form' id='groupldap_form' method='post' action='{$target}'>";
echo "<div class='spaced'><table class='tab_cadre_fixe'>";
if (haveRight("config", "r") && AuthLdap::useAuthLdap()) {
echo "<tr class='tab_bg_1'>";
echo "<td colspan='2' class='center'>" . $LANG['setup'][256] . " : </td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . $LANG['setup'][260] . " : </td>";
echo "<td>";
autocompletionTextField($this, "ldap_field");
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . $LANG['setup'][601] . " : </td>";
echo "<td>";
autocompletionTextField($this, "ldap_value");
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td colspan='2' class='center'>" . $LANG['setup'][257] . " : </td>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
echo "<td>" . $LANG['setup'][261] . " : </td>";
echo "<td>";
autocompletionTextField($this, "ldap_group_dn");
echo "</td></tr>";
}
$options = array('colspan' => 1, 'candel' => false);
$this->showFormButtons($options);
echo "</table></div></form>";
}
示例14: Auth
}
echo "\n";
}
} else {
echo "No OCS server\n";
}
}
// Check Auth connections
$auth = new Auth();
$auth->getAuthMethods();
$ldap_methods = $auth->authtypes["ldap"];
if (count($ldap_methods)) {
echo "Check LDAP servers:";
foreach ($ldap_methods as $method) {
echo " " . $method['name'];
if (AuthLdap::tryToConnectToServer($method, $method["rootdn"], decrypt($method["rootdn_passwd"], GLPIKEY))) {
echo "_OK";
} else {
echo "_PROBLEM";
$ok = false;
}
echo "\n";
}
} else {
echo "No LDAP server\n";
}
// TODO Check mail server : cannot open a mail connexion / only ping server ?
// TODO check CAS url / check url using socket ?
}
echo "\n";
if ($ok) {
示例15: header
This file is part of GLPI.
GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
if (strpos($_SERVER['PHP_SELF'], "ldapdaterestriction.php")) {
include '../inc/includes.php';
header("Content-Type: text/html; charset=UTF-8");
Html::header_nocache();
}
if (!defined('GLPI_ROOT')) {
die("Can not acces directly to this file");
}
Session::checkLoginUser();
AuthLdap::showDateRestrictionForm($_POST);