/** * Implements the onLoginScriptEnd listener method. * * @param iMSCP_Events_Event $event */ public function onLoginScriptEnd($event) { // Say Hello World on the login page set_page_message('i-MSCP HelloWorld plugin says: Hello World', 'info'); // Stop the propagation of this event to prevent execution of any other plugin that also listen on it. $event->stopPropagation(); }
/** * Credentials authentication handler * * @param iMSCP_Events_Event $event * @return iMSCP_Authentication_Result * @throws iMSCP_Exception_Database */ function login_credentials($event) { $username = !empty($_POST['uname']) ? encode_idna(clean_input($_POST['uname'])) : ''; $password = !empty($_POST['upass']) ? clean_input($_POST['upass']) : ''; if (empty($username) || empty($password)) { if (empty($username)) { $message[] = tr('The username field is empty.'); } if (empty($password)) { $message[] = tr('The password field is empty.'); } } if (!isset($message)) { $stmt = exec_query('SELECT admin_id, admin_name, admin_pass, admin_type, email, created_by FROM admin WHERE admin_name = ?', $username); if (!$stmt->rowCount()) { $result = new iMSCP_Authentication_Result(iMSCP_Authentication_Result::FAILURE_IDENTITY_NOT_FOUND, null, tr('Unknown username.')); } else { $identity = $stmt->fetchRow(PDO::FETCH_OBJ); $dbPassword = $identity->admin_pass; if ($dbPassword != md5($password) && crypt($password, $dbPassword) != $dbPassword) { $result = new iMSCP_Authentication_Result(iMSCP_Authentication_Result::FAILURE_CREDENTIAL_INVALID, null, tr('Bad password.')); } else { if (strpos($dbPassword, '$') !== 0) { # Not a password encrypted with crypt(), then re-encrypt it exec_query('UPDATE admin SET admin_pass = ? WHERE admin_id = ?', array(cryptPasswordWithSalt($password), $identity->admin_id)); write_log(sprintf('Info: Password for user %s has been re-encrypted using the best available algorithm', $identity->admin_name), E_USER_NOTICE); } $result = new iMSCP_Authentication_Result(iMSCP_Authentication_Result::SUCCESS, $identity); $event->stopPropagation(); } } } else { $result = new iMSCP_Authentication_Result(count($message) == 2 ? iMSCP_Authentication_Result::FAILURE_CREDENTIAL_EMPTY : iMSCP_Authentication_Result::FAILURE_CREDENTIAL_INVALID, null, $message); } return $result; }
/** * onBeforeAuthentication event listener * * @param iMSCP_Events_Event $event * @return null|string */ public function onBeforeAuthentication($event) { if ($this->isWaiting() || $this->isBlocked()) { $event->stopPropagation(); return $this->getLastMessage(); } $this->recordAttempt(); return null; }
/** * onBeforeProtectPlugin event listener * * @param iMSCP_Events_Event $event * @return void */ public function onBeforeProtectPlugin(iMSCP_Events_Event $event) { if ($event->getParam('pluginName') !== $this->getName()) { set_page_message(tr('This action is not permitted in demo version.'), 'warning'); $event->stopPropagation(); } }
/** * Check plugin compatibility * * @param iMSCP_Events_Event $event */ protected function checkCompat($event) { if ($event->getParam('pluginName') == $this->getName()) { if (version_compare($event->getParam('pluginManager')->getPluginApiVersion(), '0.2.10', '<')) { set_page_message(tr('Your i-MSCP version is not compatible with this plugin. Try with a newer version.'), 'error'); $event->stopPropagation(); } } }
/** * Check plugin compatibility * * @param iMSCP_Events_Event $event */ protected function checkCompat(iMSCP_Events_Event $event) { if ($event->getParam('pluginName') == $this->getName()) { $config = iMSCP_Registry::get('config'); if (isset($config['WEBMAIL_PACKAGES']) && !in_array('Roundcube', getWebmailList())) { set_page_message(tr('This plugin require the i-MSCP Roundcube package.'), 'error'); $event->stopPropagation(); } } }