Example #1
0
 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     switch ($ma->getAction()) {
         case 'delete_for_user':
             $input = $ma->getInput();
             if (isset($input['users_id'])) {
                 $user = new User();
                 $user->getFromDB($input['users_id']);
                 foreach ($ids as $id) {
                     if ($input['users_id'] == Session::getLoginUserID()) {
                         if ($item->deleteByCriteria(array('users_id' => $input['users_id'], 'itemtype' => $id))) {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($user->getErrorMessage(ERROR_ON_ACTION));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($user->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
 function AuthUser($loginname, $passwd)
 {
     global $feedback;
     if (!function_exists("ldap_connect")) {
         return false;
     }
     if (!$this->ldap_conn) {
         $this->ldap_conn = ldap_connect($this->ldap_server, $this->ldap_port);
     }
     if ($GLOBALS['sys_ldap_version']) {
         ldap_set_option($this->ldap_conn, LDAP_OPT_PROTOCOL_VERSION, $GLOBALS['sys_ldap_version']);
     }
     $dn = plugin_ldapextauth_getdn($this, $loginname);
     if (empty($dn)) {
         $GLOBALS['ldap_auth_failed'] = true;
         return false;
     }
     $u = user_get_object_by_name($loginname);
     if ($u) {
         // User exists in DB
         if (@ldap_bind($this->ldap_conn, $dn, $passwd)) {
             // Password from form is valid in LDAP
             if (session_login_valid_dbonly($loginname, $passwd, false)) {
                 // Also according to DB
                 $GLOBALS['ldap_auth_failed'] = false;
                 return true;
             } else {
                 // Passwords mismatch, update DB's
                 $u->setPasswd($passwd);
                 $GLOBALS['ldap_auth_failed'] = false;
                 return true;
             }
         } else {
             // Wrong password according to LDAP
             $feedback = _('Invalid Password Or User Name');
             $GLOBALS['ldap_auth_failed'] = true;
             return false;
         }
     } else {
         // User doesn't exist in DB yet
         if (@ldap_bind($this->ldap_conn, $dn, $passwd)) {
             // User authenticated
             // Now get her info
             if ($this->ldap_kind == "AD") {
                 $res = ldap_search($this->ldap_conn, $this->base_dn, "sAMAccountName=" . $loginname);
             } else {
                 $res = ldap_read($this->ldap_conn, $dn, "objectclass=*");
             }
             $info = ldap_get_entries($this->ldap_conn, $res);
             $ldapentry = $info[0];
             $mappedinfo = plugin_ldapextauth_mapping($ldapentry);
             // Insert into DB
             $u = new User();
             $unix_name = $loginname;
             $firstname = '';
             $lastname = '';
             $password1 = $passwd;
             $password2 = $passwd;
             $email = '';
             $mail_site = 1;
             $mail_va = 0;
             $language_id = 1;
             $timezone = 'GMT';
             $jabber_address = '';
             $jabber_only = 0;
             $theme_id = 1;
             $unix_box = '';
             $address = '';
             $address2 = '';
             $phone = '';
             $fax = '';
             $title = '';
             $ccode = 'US';
             $send_mail = false;
             if ($mappedinfo['firstname']) {
                 $firstname = $mappedinfo['firstname'];
             }
             if ($mappedinfo['lastname']) {
                 $lastname = $mappedinfo['lastname'];
             }
             if ($mappedinfo['email']) {
                 $email = $mappedinfo['email'];
             }
             if ($mappedinfo['language_id']) {
                 $language_id = $mappedinfo['language_id'];
             }
             if ($mappedinfo['timezone']) {
                 $timezone = $mappedinfo['timezone'];
             }
             if ($mappedinfo['jabber_address']) {
                 $jabber_address = $mappedinfo['jabber_address'];
             }
             if ($mappedinfo['address']) {
                 $address = $mappedinfo['address'];
             }
             if ($mappedinfo['address2']) {
                 $address2 = $mappedinfo['address2'];
             }
             if ($mappedinfo['phone']) {
                 $phone = $mappedinfo['phone'];
             }
             if ($mappedinfo['fax']) {
                 $fax = $mappedinfo['fax'];
             }
             if ($mappedinfo['title']) {
                 $title = $mappedinfo['title'];
             }
             if ($mappedinfo['ccode']) {
                 $ccode = $mappedinfo['ccode'];
             }
             if ($mappedinfo['themeid']) {
                 $theme_id = $mappedinfo['themeid'];
             }
             if (!$u->create($unix_name, $firstname, $lastname, $password1, $password2, $email, $mail_site, $mail_va, $language_id, $timezone, $jabber_address, $jabber_only, $theme_id, $unix_box, $address, $address2, $phone, $fax, $title, $ccode, $send_mail)) {
                 $GLOBALS['ldap_auth_failed'] = true;
                 $feedback = "<br>Error Creating User: "******"<br>Error Activating User: " . $u->getErrorMessage();
                 return false;
             }
             $GLOBALS['ldap_auth_failed'] = false;
             $GLOBALS['ldap_first_login'] = true;
             return true;
         } else {
             $GLOBALS['ldap_auth_failed'] = true;
             $feedback = _('Invalid Password Or User Name');
             return false;
             // Probably ignored, but just in case
         }
     }
 }