Esempio n. 1
0
 public function execute(array $deferred, array $data, $targetRunTime, &$status)
 {
     $optionModel = XenForo_Model::create('XenForo_Model_Option');
     $optionModel->updateOption('dppa_adsense_password', XenForo_Application::generateRandomString(32));
     $optionModel->rebuildOptionCache();
     return false;
 }
Esempio n. 2
0
 /**
  * Generates an arbtirary length salt
  *
  * @return string
  */
 public static function generateSalt($length = null)
 {
     if (!$length) {
         $length = self::DEFAULT_SALT_LENGTH;
     }
     return XenForo_Application::generateRandomString($length);
 }
Esempio n. 3
0
 protected function _genKey($userId)
 {
     $randomKey = XenForo_Application::generateRandomString(10);
     $db = XenForo_Application::getDb();
     $db->query('UPDATE xf_user
         SET gen_key = ' . $db->quote($randomKey) . '
         WHERE user_id = ' . $userId . '');
 }
Esempio n. 4
0
 protected function _postSave()
 {
     parent::_postSave();
     // update sourcebans if we updated the groups
     if ($this->get('option_id') == 'AWickham_SourceBansSync_Groups') {
         if (is_array(unserialize($this->get('option_value'))) && !array_key_exists('newInstall', unserialize($this->get('option_value')))) {
             // create a group model
             $xfUserGroupModel = XenForo_Model::create('XenForo_Model_UserGroup');
             // create a user model
             $xfUserModel = XenForo_Model::create('XenForo_Model_User');
             // create an admin model
             $sbAdminModel = new AWickham_SourceBansSync_Model_SourceBans_Admin();
             // delete the users out of sourcebans that don't exist in xenforo
             $sbAdmins = $sbAdminModel->fetchAll();
             foreach ($sbAdmins as $sbAdmin) {
                 $xfUser = $xfUserModel->getUserBySteamId($sbAdmin['authid']);
                 if (!$xfUser || !$xfUserModel->getSourceBansGroups($xfUser, unserialize($this->get('option_value')))) {
                     $sbAdminModel->delete($xfUser['user_id'], $sbAdmin['authid']);
                 }
             }
             // loop through all the groups
             foreach (unserialize($this->get('option_value')) as $userGroupId => $sbGroups) {
                 //$userGroup = $userGroupModel->getUserGroupById($userGroupId);
                 $users = $xfUserGroupModel->getUserIdsInUserGroup($userGroupId);
                 foreach ($users as $user => $inGroup) {
                     $identities = $xfUserModel->getIdentities($user);
                     // pay attention to this user, they have a steam id
                     if ($identities && array_key_exists('Steam', $identities)) {
                         // check to see if the user exists in source bans
                         $sbUser = $sbAdminModel->fetchBySteamId($identities['Steam']);
                         // get the user
                         $xfUser = $xfUserModel->getFullUserById($user);
                         // figure out the groups
                         list($gid, $srvGroupsId, $serverGroupId) = $xfUserModel->getSourceBansGroups($xfUser, unserialize($this->get('option_value')));
                         // add the user to source bans
                         if (!$sbUser) {
                             if ($gid && $srvGroupsId && $serverGroupId) {
                                 // add the user
                                 $insertValues = array('user' => $xfUser['username'], 'email' => $xfUser['email'], 'authid' => $identities['Steam'], 'password' => XenForo_Application::generateRandomString(8), 'gid' => $gid, 'srvgroups_id' => $srvGroupsId, 'server_group_id' => $serverGroupId, 'validate' => '', 'extraflags' => 0);
                                 $sbAdminModel->insert($xfUser['user_id'], $insertValues);
                             }
                         } else {
                             if (!$gid || !$srvGroupsId || !$serverGroupId) {
                                 // remove the user from source bans
                                 $sbAdminModel->delete($xfUser, $identities['Steam']);
                             } else {
                                 $updateArray = array('user' => $xfUser['username'], 'email' => $xfUser['email'], 'gid' => $gid, 'srvgroups_id' => $srvGroupsId, 'server_group_id' => $serverGroupId);
                                 $sbAdminModel->update($identities['Steam'], $updateArray);
                             }
                         }
                     }
                 }
             }
         }
         // rehash the sourcebans servers
         AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
     }
 }
 /**
  * Create new secret.
  * 16 characters, randomly chosen from the allowed base32 characters.
  *
  * @param int $secretLength
  * @return string
  */
 public function createSecret($secretLength = 16)
 {
     $validChars = $this->_getBase32LookupTable();
     unset($validChars[32]);
     $random = XenForo_Application::generateRandomString($secretLength);
     $secret = '';
     for ($i = 0; $i < $secretLength; $i++) {
         $secret .= $validChars[ord($random[$i]) & 0x1f];
     }
     return $secret;
 }
Esempio n. 6
0
 public function triggerVerification($context, array $user, $ip, array &$providerData)
 {
     $length = 6;
     $random = XenForo_Application::generateRandomString(4, true);
     $code = ((ord($random[0]) & 0x7f) << 24 | (ord($random[1]) & 0xff) << 16 | (ord($random[2]) & 0xff) << 8 | ord($random[3]) & 0xff) % pow(10, $length);
     $code = str_pad($code, $length, '0', STR_PAD_LEFT);
     $providerData['code'] = $code;
     $providerData['codeGenerated'] = time();
     $mail = XenForo_Mail::create('two_step_login_email', array('code' => $code, 'user' => $user, 'ip' => $ip), $user['language_id']);
     $mail->send($user['email'], $user['username']);
     return array();
 }
Esempio n. 7
0
 public function generateInitialData(array $user, array $setupData)
 {
     $codes = array();
     $total = 10;
     $length = 9;
     $random = XenForo_Application::generateRandomString(4 * $total, true);
     for ($i = 0; $i < $total; $i++) {
         $offset = $i * 4;
         // 4 bytes for each set
         $code = ((ord($random[$offset + 0]) & 0x7f) << 24 | (ord($random[$offset + 1]) & 0xff) << 16 | (ord($random[$offset + 2]) & 0xff) << 8 | ord($random[$offset + 3]) & 0xff) % pow(10, $length);
         $code = str_pad($code, $length, '0', STR_PAD_LEFT);
         $codes[] = $code;
     }
     return array('codes' => $codes, 'used' => array());
 }
 /**
  * Resets the specified user's parental control password and emails the password to the parent if requested.
  *
  * @param integer $userId
  * @param boolean $sendEmail
  *
  * @return string New password
  */
 public function resetParentPassword($userId, $sendEmail = true)
 {
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $dw->setExistingData($userId);
     $password = XenForo_Application::generateRandomString(8);
     $auth = XenForo_Authentication_Abstract::createDefault();
     $dw->set('parent_scheme_class', $auth->getClassName());
     $dw->set('parent_data', $auth->generate($password));
     $dw->save();
     $user = $dw->getMergedData();
     if ($sendEmail) {
         $params = array('user' => $user, 'password' => $password, 'boardTitle' => XenForo_Application::get('options')->boardTitle, 'boardUrl' => XenForo_Application::get('options')->boardUrl);
         $mail = XenForo_Mail::create('th_lost_password_reset_parentalcontrol', $params, $user['language_id']);
         $mail->send($user['parent_email'], (string) new XenForo_Phrase('th_parent_of_x_parentalcontrol', array('username' => $user['username'])));
     }
     return $password;
 }
Esempio n. 9
0
 protected function _postSave()
 {
     parent::_postSave();
     // get the source bans admin model
     $sbAdminModel = new AWickham_SourceBansSync_Model_SourceBans_Admin();
     $xfUserModel = XenForo_Model::create('XenForo_Model_User');
     $xfUserExternalModel = XenForo_Model::create('XenForo_Model_UserExternal');
     // get the user's new identities
     $identities = unserialize($this->get('identities'));
     // only do this if the steam id is set
     if ($identities && array_key_exists('steam', $identities)) {
         // check to see if the user exists in source bans
         $sbUser = $sbAdminModel->fetchBySteamId($xfUserModel->toSteamId($this->_currentSteamId));
         // add the user to source bans
         if (!$sbUser) {
             // figure out the groups
             list($gid, $srvgroups_id, $serverGroupId) = $xfUserModel->getSourceBansGroups($this, XenForo_Application::get('options')->AWickham_SourceBansSync_Groups);
             if ($gid && $srvgroups_id && $serverGroupId) {
                 // add the user
                 $insertValues = array('user' => $this->get('username'), 'email' => $this->get('email'), 'authid' => $xfUserModel->toSteamId($identities['steam']['provider_key']), 'password' => XenForo_Application::generateRandomString(8), 'gid' => $gid, 'srvgroups_id' => $srvgroups_id, 'server_group_id' => $serverGroupId, 'validate' => '', 'extraflags' => 0);
                 $sbAdminModel->insert($this->get('user_id'), $insertValues);
                 // rehash the sourcebans servers
                 AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
             }
         } else {
             // update the user if anything we care about changed
             if ($this->isChanged('user_group_id') || $this->isChanged('secondary_group_ids') || $this->isChanged('email') || $this->isChanged('username') || array_key_exists('steam', $this->_identities) && $this->_identities['steam'] != $identities['steam']) {
                 // figure out the groups
                 list($gid, $srvgroups_id, $serverGroupId) = $xfUserModel->getSourceBansGroups($this, XenForo_Application::get('options')->AWickham_SourceBansSync_Groups);
                 if (!$gid || !$srvgroups_id || !$serverGroupId) {
                     // remove the user from source bans
                     $sbAdminModel->delete($this->get('user_id'), $xfUserModel->toSteamId($this->_currentSteamId));
                 } else {
                     $updateArray = array('user' => $this->get('username'), 'email' => $this->get('email'), 'authid' => $xfUserModel->toSteamId($identities['steam']['provider_key']), 'gid' => $gid, 'srvgroups_id' => $srvgroups_id, 'server_group_id' => $serverGroupId);
                     $sbAdminModel->update($xfUserModel->toSteamId($this->_currentSteamId), $updateArray);
                 }
                 // rehash the sourcebans servers
                 AWickham_SourceBansSync_Model_SourceBans_Rcon::rehash();
             }
         }
     }
 }
Esempio n. 10
0
 /**
  * Pre-save default setting.
  */
 protected function _preSaveDefaults()
 {
     if (is_array($this->_secondaryGroups)) {
         $primaryGroupKey = array_search($this->get('user_group_id'), $this->_secondaryGroups);
         if ($primaryGroupKey !== false) {
             unset($this->_secondaryGroups[$primaryGroupKey]);
         }
         $this->set('secondary_group_ids', implode(',', $this->_secondaryGroups));
     }
     if ($this->isChanged('scheme_class', 'xf_user_authenticate') || $this->isChanged('data', 'xf_user_authenticate')) {
         $this->set('remember_key', XenForo_Application::generateRandomString(40));
         $this->set('password_date', XenForo_Application::$time);
     }
     if (!$this->get('csrf_token')) {
         $this->set('csrf_token', XenForo_Application::generateRandomString(40));
     }
 }
Esempio n. 11
0
 /**
  * Resets the specified user's password and emails the password to them if requested.
  *
  * @param integer $userId
  * @param boolean $sendEmail
  *
  * @return string New password
  */
 public function resetPassword($userId, $sendEmail = true)
 {
     $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $dw->setExistingData($userId);
     $password = XenForo_Application::generateRandomString(8);
     $password = strtr($password, array('I' => 'i', 'l' => 'L', '0' => 'O', 'o' => 'O'));
     $password = trim($password, '_-');
     $auth = XenForo_Authentication_Abstract::createDefault();
     $dw->set('scheme_class', $auth->getClassName());
     $dw->set('data', $auth->generate($password));
     $dw->save();
     $user = $dw->getMergedData();
     if ($sendEmail) {
         $params = array('user' => $user, 'password' => $password, 'boardTitle' => XenForo_Application::get('options')->boardTitle, 'boardUrl' => XenForo_Application::get('options')->boardUrl);
         $mail = XenForo_Mail::create('user_lost_password_reset', $params, $user['language_id']);
         $mail->send($user['email'], $user['username']);
     }
     return $password;
 }
Esempio n. 12
0
 /**
  * Generates a session-specific CSRF token.
  *
  * @return string
  */
 public function generateSessionCsrf()
 {
     $csrf = XenForo_Application::generateRandomString(16);
     $this->set('sessionCsrf', $csrf);
     return $csrf;
 }
Esempio n. 13
0
 /**
  *
  * @param array $contact
  * @param array $user
  * @return array|boolean|null $user
  */
 public function pullContact(array $contact, $user = null)
 {
     $xenOptions = XenForo_Application::get('options');
     /* @var $userModel XenForo_Model_User */
     $userModel = $this->getModelFromCache('XenForo_Model_User');
     if ($user === null) {
         $user = $userModel->getUserByContactId($contact['Id']);
     }
     if (!$user && !empty($contact['Email'])) {
         $user = $userModel->getUserByEmail($contact['Email'], array('join' => XenForo_Model_User::FETCH_USER_PROFILE));
         if ($user && !empty($user['infusionsoft_contact_id_th'])) {
             return;
         }
     }
     $lastUpdated = ThemeHouse_Infusionsoft_Helper_InfusionsoftApi::getDateAsTimestamp($contact['LastUpdated']);
     if ($user && !empty($user['infusionsoft_last_updated_th']) && $user['infusionsoft_last_updated_th'] == $lastUpdated) {
         return $user;
     }
     if (!$user) {
         if (empty($contact['Groups'])) {
             return false;
         } else {
             $groups = explode(',', $contact['Groups']);
             if (!array_intersect($groups, $xenOptions->th_infusionsoftApi_importUserTags)) {
                 return false;
             }
         }
     }
     /* @var $writer XenForo_DataWriter_User */
     $writer = XenForo_DataWriter::create('XenForo_DataWriter_User');
     $writer->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
     if ($user) {
         $writer->setExistingData($user);
     }
     $writer->set('infusionsoft_contact_id_th', $contact['Id']);
     $writer->set('infusionsoft_last_updated_th', $lastUpdated);
     if (!$user) {
         if ($xenOptions->registrationDefaults) {
             $writer->bulkSet($xenOptions->registrationDefaults, array('ignoreInvalidFields' => true));
         }
         $name = $this->getFullNameFromContact($contact);
         $input = array('user_group_id' => XenForo_Model_User::$defaultRegisteredGroupId, 'language_id' => XenForo_Visitor::getInstance()->get('language_id'), 'user_state' => 'valid', 'username' => $name);
         $i = 1;
         while ($userModel->getUserByName($input['username'])) {
             $input['username'] = $name . ' ' . $i;
             $i++;
         }
         $writer->bulkSet($input);
         $password = XenForo_Application::generateRandomString(8);
         $password = strtr($password, array('I' => 'i', 'l' => 'L', '0' => 'O', 'o' => 'O'));
         $password = trim($password, '_-');
         $writer->setPassword($password);
     }
     if (!empty($contact['Email'])) {
         $writer->set('email', $contact['Email']);
         if ($xenOptions->gravatarEnable && XenForo_Model_Avatar::gravatarExists($contact['Email'])) {
             $writer->set('gravatar', $contact['Email']);
         }
     } else {
         $writer->setOption(ThemeHouse_Infusionsoft_Extend_XenForo_DataWriter_User::OPTION_INFUSIONSOFT_API_IMPORT, true);
         $writer->set('email', '');
     }
     if (!empty($contact['Groups'])) {
         $writer->set('infusionsoft_contact_group_ids_th', $contact['Groups']);
     } else {
         $writer->set('infusionsoft_contact_group_ids_th', '');
     }
     $writer->save();
     $user = $writer->getMergedData();
     /* @var $promotionModel XenForo_Model_UserGroupPromotion */
     $promotionModel = $this->getModelFromCache('XenForo_Model_UserGroupPromotion');
     $promotionModel->updatePromotionsForUser($user);
     return $user;
 }
Esempio n. 14
0
 public function createTrustedKey($userId, $trustedUntil = null)
 {
     if ($trustedUntil === null) {
         $trustedUntil = XenForo_Application::$time + 86400 * 30;
     }
     $key = XenForo_Application::generateRandomString(32);
     $this->_getDb()->query("\n\t\t\tINSERT IGNORE INTO xf_user_tfa_trusted\n\t\t\t\t(user_id, trusted_key, trusted_until)\n\t\t\tVALUES\n\t\t\t\t(?, ?, ?)\n\t\t", array($userId, $key, $trustedUntil));
     return $key;
 }
Esempio n. 15
0
 public function massImportUsers(array $users, &$errors = array())
 {
     $db = $this->_getDb();
     foreach ($users as $userId => $user) {
         $existingUser = array();
         if (!empty($user['email'])) {
             $existingUser = $this->getUserByEmail($user['email']);
         }
         /* @var $dw XenForo_DataWriter_User */
         $dw = XenForo_DataWriter::create('XenForo_DataWriter_User');
         $dw->setOption(XenForo_DataWriter_User::OPTION_ADMIN_EDIT, true);
         $xenOptions = XenForo_Application::get('options');
         if (isset($user['user_id']) && $xenOptions->th_userImpEx_allowUserIdSet) {
             $dw->disableUserIdVerification();
         }
         if ($existingUser) {
             $dw->setExistingData($existingUser);
         }
         if (!empty($user['custom_fields']) && is_array($user['custom_fields'])) {
             $dw->setCustomFields($user['custom_fields']);
             unset($user['custom_fields']);
         }
         if (isset($user['password'])) {
             $dw->setPassword($user['password']);
             unset($user['password']);
         } elseif ($dw->isInsert()) {
             if ($xenOptions->th_userImpEx_randomPassword) {
                 $password = XenForo_Application::generateRandomString(8);
                 $password = strtr($password, array('I' => 'i', 'l' => 'L', '0' => 'O', 'o' => 'O'));
                 $password = trim($password, '_-');
                 $dw->setPassword($password);
             }
             $auth = XenForo_Authentication_Abstract::create('XenForo_Authentication_NoPassword');
             $dw->set('scheme_class', $auth->getClassName());
             $dw->set('data', $auth->generate(''), 'xf_user_authenticate');
         }
         if (!isset($user['user_group_id']) && $dw->isInsert()) {
             $dw->set('user_group_id', XenForo_Model_User::$defaultRegisteredGroupId);
         }
         if (!isset($user['language_id']) && $dw->isInsert()) {
             $dw->set('language_id', XenForo_Visitor::getInstance()->get('language_id'));
         }
         $fieldNames = $dw->getFieldNames();
         foreach ($fieldNames as $fieldName) {
             if (isset($user[$fieldName])) {
                 $dw->set($fieldName, $user[$fieldName]);
             }
         }
         $dwErrors = $dw->getErrors();
         if ($dwErrors) {
             $users[$userId]['dwErrors'] = $dwErrors;
         } else {
             $dw->preSave();
             $dwErrors = $dw->getErrors();
             if ($dwErrors) {
                 $users[$userId]['dwErrors'] = $dwErrors;
             } else {
                 unset($users[$userId]);
                 $dw->save();
             }
         }
     }
     return $users;
 }
Esempio n. 16
0
 public function createTrustedKey($userId, $trustedUntil = null)
 {
     if ($trustedUntil === null) {
         $trustedUntil = XenForo_Application::$time + 86400 * 30;
         // jitter between 0 and 96 hours (4 days). This attempts to reduce situations where multiple
         // devices all expire at almost identical times
         $offsetJitter = mt_rand(0, 4 * 24) * 3600;
         $trustedUntil += $offsetJitter;
     }
     $key = XenForo_Application::generateRandomString(32);
     $this->_getDb()->query("\r\n\t\t\tINSERT IGNORE INTO xf_user_tfa_trusted\r\n\t\t\t\t(user_id, trusted_key, trusted_until)\r\n\t\t\tVALUES\r\n\t\t\t\t(?, ?, ?)\r\n\t\t", array($userId, $key, $trustedUntil));
     return $key;
 }