/** * Send password recovery for a user. * * @param $email email of the user * * @return nothing : send email or display error message **/ function forgetPassword($email) { global $CFG_GLPI; echo "<div class='center'>"; if ($this->getFromDBbyEmail($email, "`glpi_users`.`is_active`\n AND NOT `glpi_users`.`is_deleted`\n AND (`glpi_users`.`begin_date` IS NULL\n OR `glpi_users`.`begin_date` < NOW())\n AND (`glpi_users`.`end_date` IS NULL\n OR `glpi_users`.`end_date` > NOW())")) { // Send token if auth DB or not external auth defined if ($this->fields["authtype"] == Auth::DB_GLPI || !Auth::useAuthExt()) { if (NotificationMail::isUserAddressValid($email)) { $input['password_forget_token'] = sha1(Toolbox::getRandomString(30)); $input['password_forget_token_date'] = $_SESSION["glpi_currenttime"]; $input['id'] = $this->fields['id']; $this->update($input); // Notication on root entity (glpi_users.entities_id is only a pref) NotificationEvent::raiseEvent('passwordforget', $this, array('entities_id' => 0)); QueuedMail::forceSendFor($this->getType(), $this->fields['id']); _e('An email has been sent to your email address. The email contains information for reset your password.'); } else { _e('Invalid email address'); } } else { _e("The authentication method configuration doesn't allow you to change your password."); } } else { _e('Email address not found.'); } echo "<br>"; echo "<a href=\"" . $CFG_GLPI['root_doc'] . "/index.php\">" . __s('Back') . "</a>"; echo "</div>"; }
/** * Check zombie crontask * * @param $task for log **/ static function cronWatcher($task) { global $CFG_GLPI, $DB; $cron_status = 0; // Crontasks running for more than 1 hour or 2 frequency $query = "SELECT *\n FROM `glpi_crontasks`\n WHERE `state` = '" . self::STATE_RUNNING . "'\n AND ((unix_timestamp(`lastrun`) + 2 * `frequency` < unix_timestamp(now()))\n OR (unix_timestamp(`lastrun`) + 2*" . HOUR_TIMESTAMP . " < unix_timestamp(now())))"; $crontasks = array(); foreach ($DB->request($query) as $data) { $crontasks[$data['id']] = $data; } if (count($crontasks)) { $task = new self(); $task->getFromDBByQuery("WHERE `itemtype` = 'Crontask' AND `name` = 'watcher'"); if (NotificationEvent::raiseEvent("alert", $task, array('items' => $crontasks))) { $cron_status = 1; $task->addVolume(1); } QueuedMail::forceSendFor($task->getType(), $task->fields['id']); } return 1; }
/** * Restore an item put in the dustbin in the database. * * @param $input array the _POST vars returned by the item form when press restore * @param $history boolean do history log ? (default 1) * * @return boolean : true on success **/ function restore(array $input, $history = 1) { if (!$this->getFromDB($input[static::getIndexName()])) { return false; } if (isset($input['restore'])) { $input['_restore'] = $input['restore']; unset($input['restore']); } // Store input in the object to be available in all sub-method / hook $this->input = $input; Plugin::doHook("pre_item_restore", $this); if ($this->restoreInDB()) { $this->addMessageOnRestoreAction(); if ($this->dohistory && $history) { $changes[0] = 0; $changes[1] = $changes[2] = ""; $logaction = Log::HISTORY_RESTORE_ITEM; if ($this->useDeletedToLockIfDynamic() && $this->isDynamic()) { $logaction = Log::HISTORY_UNLOCK_ITEM; } Log::history($this->input["id"], $this->getType(), $changes, 0, $logaction); } $this->post_restoreItem(); Plugin::doHook("item_restore", $this); if ($this->mailqueueonaction) { QueuedMail::forceSendFor($this->getType(), $this->fields['id']); } return true; } return false; }