示例#1
0
     $config_ldap->redirectToList();
 } else {
     if (isset($_POST["test_ldap"])) {
         $config_ldap->getFromDB($_POST["id"]);
         if (AuthLdap::testLDAPConnection($_POST["id"])) {
             //TRANS: %s is the description of the test
             $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test successful: %s'), sprintf(__('Main server %s'), $config_ldap->fields["name"]));
         } else {
             //TRANS: %s is the description of the test
             $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test failed: %s'), sprintf(__('Main server %s'), $config_ldap->fields["name"]));
         }
         Html::back();
     } else {
         if (isset($_POST["test_ldap_replicate"])) {
             $replicate = new AuthLdapReplicate();
             $replicate->getFromDB($_POST["ldap_replicate_id"]);
             if (AuthLdap::testLDAPConnection($_POST["id"], $_POST["ldap_replicate_id"])) {
                 //TRANS: %s is the description of the test
                 $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test successful: %s'), sprintf(__('Replicate %s'), $replicate->fields["name"]));
             } else {
                 //TRANS: %s is the description of the test
                 $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test failed: %s'), sprintf(__('Replicate %s'), $replicate->fields["name"]));
             }
             Html::back();
         } else {
             if (isset($_POST["add_replicate"])) {
                 $replicate = new AuthLdapReplicate();
                 unset($_POST["next"]);
                 unset($_POST["id"]);
                 $replicate->add($_POST);
                 Html::back();
示例#2
0
 } else {
     if (isset($_POST["test_ldap"])) {
         $config_ldap->getFromDB($_POST["id"]);
         if (AuthLdap::testLDAPConnection($_POST["id"])) {
             //TRANS: %s is the description of the test
             $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test successful: %s'), sprintf(__('Main server %s'), $config_ldap->fields["name"]));
         } else {
             //TRANS: %s is the description of the test
             $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test failed: %s'), sprintf(__('Main server %s'), $config_ldap->fields["name"]));
         }
         Html::back();
     } else {
         if (isset($_POST["test_ldap_replicate"])) {
             foreach ($_POST["test_ldap_replicate"] as $replicate_id => $value) {
                 $replicate = new AuthLdapReplicate();
                 $replicate->getFromDB($replicate_id);
                 if (AuthLdap::testLDAPConnection($_POST["id"], $replicate_id)) {
                     //TRANS: %s is the description of the test
                     $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test successful: %s'), sprintf(__('Replicate %s'), $ldap->fields["name"]));
                 } else {
                     //TRANS: %s is the description of the test
                     $_SESSION["LDAP_TEST_MESSAGE"] = sprintf(__('Test failed: %s'), sprintf(__('Replicate %s'), $ldap->fields["name"]));
                 }
             }
             Html::back();
         } else {
             if (isset($_POST["add_replicate"])) {
                 $replicate = new AuthLdapReplicate();
                 unset($_POST["next"]);
                 unset($_POST["id"]);
                 $replicate->add($_POST);
示例#3
0
 /** Test a LDAP connection
  *
  * @param $auths_id     ID of the LDAP server
  * @param $replicate_id use a replicate if > 0 (default -1)
  *
  * @return  boolean connection succeeded ?
  **/
 static function testLDAPConnection($auths_id, $replicate_id = -1)
 {
     $config_ldap = new self();
     $res = $config_ldap->getFromDB($auths_id);
     $ldap_users = array();
     // we prevent some delay...
     if (!$res) {
         return false;
     }
     //Test connection to a replicate
     if ($replicate_id != -1) {
         $replicate = new AuthLdapReplicate();
         $replicate->getFromDB($replicate_id);
         $host = $replicate->fields["host"];
         $port = $replicate->fields["port"];
     } else {
         //Test connection to a master ldap server
         $host = $config_ldap->fields['host'];
         $port = $config_ldap->fields['port'];
     }
     $ds = self::connectToServer($host, $port, $config_ldap->fields['rootdn'], Toolbox::decrypt($config_ldap->fields['rootdn_passwd'], GLPIKEY), $config_ldap->fields['use_tls'], $config_ldap->fields['deref_option']);
     if ($ds) {
         return true;
     }
     return false;
 }