public function cron() { if (!function_exists('user_delete')) { include $phpbb_root_path . 'includes/functions_user.' . $phpEx; } $cronlog = new Logging(); //cronlog("Starting"); // This script will take a while. We should disable max_execution_time. @ini_set('max_execution_time', 900); if ($config['eveapi_validation']) { // ******************************************************************* // ** STANDINGS START ************************************************ // ******************************************************************* $characterID = 0; $standingsCharacterAPI = array(); if ($config['eveapi_s_masterswitch'] && $config['eveapi_s_character'] && $config['eveapi_s_charactername'] != "") { $standingsCharacterAPI = eveapi_getStandingsCharacterAPI(); $pheal = new \Pheal\Pheal($standingsCharacterAPI['keyID'], $standingsCharacterAPI['vCode']); try { $result = $pheal->accountScope->APIKeyInfo(); if ($result->key->accessMask & 16 && ($result->key->type == "Character" || $result->key->type == "Account")) { foreach ($result->key->characters as $character) { if (strtolower($character->characterName) == strtolower($standingsCharacterAPI['characterName'])) { $characterID = $character->characterID; $characterName = $character->characterName; } } } else { cronlog("Wrong accessMask", "Standings Character -> " . $standingsCharacterAPI['characterName']); } } catch (\Pheal\Exceptions\PhealHTTPException $e) { // HTTP error cronlog('EVE API HTTP error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealAPIException $e) { // API error cronlog('EVE API Key error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealConnectionException $e) { // Connection error cronlog('EVE API Connection error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealException $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (Exception $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } if ($characterID > 0) { try { $result = $pheal->charScope->contactList(array("characterID" => $characterID)); //cronlog("Removing old Character-level standings"); $db->sql_query('DELETE FROM ' . TBL_EVEAPI_STANDINGS . ' WHERE standingsType = ' . EVEAPI_STANDINGSTYPE_CHARACTER); foreach ($result->contactList as $contact) { if ($contact->contactID < 10000000) { continue; } // Filter out NPCs (agents) if ($contact->standing != -10 && $contact->standing != -5 && $contact->standing != 0 && $contact->standing != 5 && $contact->standing != 10) { continue; } $sql = 'INSERT INTO ' . TBL_EVEAPI_STANDINGS . ' ' . $db->sql_build_array('INSERT', array("standingsName" => $contact->contactName, "standingsAmount" => $contact->standing, "standingsType" => EVEAPI_STANDINGSTYPE_CHARACTER)); $db->sql_query($sql); } //cronlog("New Character-level standings successfully imported!", "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealHTTPException $e) { // HTTP error cronlog('EVE API HTTP error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealAPIException $e) { // API error cronlog('EVE API Key error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealConnectionException $e) { // Connection error cronlog('EVE API Connection error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealException $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (Exception $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } } } $characterID = 0; if ($config['eveapi_s_masterswitch'] && ($config['eveapi_s_corporation'] || $config['eveapi_s_alliance']) && $config['eveapi_s_charactername'] != "" && $config['eveapi_s_corp_keyid'] > 0 && $config['eveapi_s_corp_vcode'] != "") { if (empty($standingsCharacterAPI)) { $standingsCharacterAPI = eveapi_getStandingsCharacterAPI(); } $pheal = new \Pheal\Pheal($config['eveapi_s_corp_keyid'], $config['eveapi_s_corp_vcode']); $characterID = 0; try { $result = $pheal->accountScope->APIKeyInfo(); if ($result->key->accessMask & 16 && $result->key->type == "Corporation" && strtolower($result->key->characters[0]->characterName) == strtolower($standingsCharacterAPI['characterName'])) { $characterID = $result->key->characters[0]->characterID; } else { cronlog("Wrong accessMask", "Standings Character -> " . $standingsCharacterAPI['characterName']); } } catch (\Pheal\Exceptions\PhealHTTPException $e) { // HTTP error cronlog('EVE API HTTP error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealAPIException $e) { // API error cronlog('EVE API Key error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealConnectionException $e) { // Connection error cronlog('EVE API Connection error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealException $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (Exception $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } if ($characterID > 0) { try { $result = $pheal->corpScope->contactList(); //cronlog("Removing old Corporation-level standings"); $db->sql_query('DELETE FROM ' . TBL_EVEAPI_STANDINGS . ' WHERE standingsType = ' . EVEAPI_STANDINGSTYPE_CORPORATION); if ($config['eveapi_s_corporation']) { foreach ($result->corporateContactList as $contact) { if ($contact->standing != -10 && $contact->standing != -5 && $contact->standing != 0 && $contact->standing != 5 && $contact->standing != 10) { continue; } $sql = 'INSERT INTO ' . TBL_EVEAPI_STANDINGS . ' ' . $db->sql_build_array('INSERT', array("standingsName" => $contact->contactName, "standingsAmount" => $contact->standing, "standingsType" => EVEAPI_STANDINGSTYPE_CORPORATION)); $db->sql_query($sql); } //cronlog("New Corporation-level standings successfully imported!", "Standings Character -> " . $standingsCharacterAPI['characterName']); } //cronlog("Removing old Alliance-level standings"); $db->sql_query('DELETE FROM ' . TBL_EVEAPI_STANDINGS . ' WHERE standingsType = ' . EVEAPI_STANDINGSTYPE_ALLIANCE); if ($config['eveapi_s_alliance']) { foreach ($result->allianceContactList as $contact) { if ($contact->standing != -10 && $contact->standing != -5 && $contact->standing != 0 && $contact->standing != 5 && $contact->standing != 10) { continue; } $sql = 'INSERT INTO ' . TBL_EVEAPI_STANDINGS . ' ' . $db->sql_build_array('INSERT', array("standingsName" => $contact->contactName, "standingsAmount" => $contact->standing, "standingsType" => EVEAPI_STANDINGSTYPE_ALLIANCE)); $db->sql_query($sql); } //cronlog("New Alliance-level standings successfully imported!", "Standings Character -> " . $standingsCharacterAPI['characterName']); } } catch (\Pheal\Exceptions\PhealHTTPException $e) { // HTTP error cronlog('EVE API HTTP error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealAPIException $e) { // API error cronlog('EVE API Key error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealConnectionException $e) { // Connection error cronlog('EVE API Connection error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (\Pheal\Exceptions\PhealException $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } catch (Exception $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), "Standings Character -> " . $standingsCharacterAPI['characterName']); } } } // ******************************************************************* // ** STANDINGS END ************************************************** // ******************************************************************* // Get rid of old Jabber access //cronlog("Clearing ejabberd accesslist"); $sql = 'DELETE FROM eveapi_jabber WHERE userID > 0 '; $db->sql_query($sql); // ******************************************************************* // ** ACTUAL CRONJOB START ******************************************* // ******************************************************************* if ($config['eveapi_ts_masterswitch']) { $nickname = $config['eveapi_ts_nickname']; if (eveapi_validateMixedalphanumeric($nickname) != 1) { $nickname = "Cyerus"; } try { $ts3_VirtualServer = TeamSpeak3::factory("serverquery://" . $config["eveapi_ts_username"] . ":" . $config["eveapi_ts_password"] . "@" . $config["eveapi_ts_ip"] . ":" . $config["eveapi_ts_port_query"] . "/?server_port=" . $config["eveapi_ts_port_server"] . "&nickname=" . $nickname); } catch (TeamSpeak3_Exception $e) { cronlog('TeamSpeak error: ' . $e->getCode() . ' -> ' . $e->getMessage()); $ts3_VirtualServer = false; } } if ($config['eveapi_ts_masterswitch'] && $ts3_VirtualServer || $config['eveapi_jabber_masterswitch']) { $sql = 'SELECT user_id, username, eveapi_keyid, eveapi_vcode, eveapi_ts FROM ' . USERS_TABLE . ' WHERE user_type = 0 ORDER BY username'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (!empty($row["eveapi_keyid"]) && !empty($row["eveapi_vcode"])) { try { $characterInfo = eveapi_checkThisCharacter($row['eveapi_keyid'], $row['eveapi_vcode'], $row['username']); if (empty($characterInfo["error"])) { $eveapi_forumGroups = array(); $eveapi_TSGroups = array(); $sql = "UPDATE " . USERS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tSET user_character_id = '" . (int) $characterInfo["info"]["characterId"] . "'\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE user_id = " . (int) $row['user_id']; $db->sql_query($sql); if (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember']) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $eveapi_TSGroups = $characterInfo["TSGroups"]; $extraGroups = eveapi_setForumGroups($row['user_id'], $eveapi_forumGroups, $row['username']); if ($config['eveapi_ts_masterswitch'] && !empty($row['eveapi_ts'])) { eveapi_setTeamSpeakGroups($row['eveapi_ts'], $eveapi_TSGroups, $row['username'], $ts3_VirtualServer, $extraGroups["TS"]); } if ($config['eveapi_jabber_masterswitch']) { if ($config['eveapi_ejabber_switch']) { eveapi_setJabberAccess($row['user_id'], $characterInfo['jabber'], $extraGroups['jabber'], $row['username']); } if ($config['eveapi_openfire_switch']) { eveapi_setOpenFireAccess($row['user_id'], $characterInfo['openfire'], $extraGroups['openfire'], $row['username']); } } } else { // no valid forumgroups found, probably meaning the user isn't part of any entity and should be disabled eveapi_disableForumAccount($row['user_id'], $row['username'], $row['eveapi_ts'], INACTIVE_EVEAPI_NONMEMBER, $ts3_VirtualServer); } } else { // error reported by eveapi_checkThisCharacter(), now use $characterInfo["disable"] to determine whether or not to disable. if ($characterInfo["disable"]) { eveapi_disableForumAccount($row['user_id'], $row['username'], $row['eveapi_ts'], INACTIVE_EVEAPI_INVALID, $ts3_VirtualServer); } } } catch (\Pheal\Exceptions\PhealHTTPException $e) { // HTTP error cronlog('EVE API HTTP error: ' . $e->getCode() . ' -> ' . $e->getMessage(), $row['username']); } catch (\Pheal\Exceptions\PhealAPIException $e) { // API error cronlog('EVE API Key error: ' . $e->getCode() . ' -> ' . $e->getMessage(), $row['username']); } catch (\Pheal\Exceptions\PhealConnectionException $e) { // Connection error cronlog('EVE API Connection error: ' . $e->getCode() . ' -> ' . $e->getMessage(), $row['username']); } catch (\Pheal\Exceptions\PhealException $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), $row['username']); } catch (Exception $e) { // Any other error, in other words "Unknown error" cronlog('EVE API Generic error: ' . $e->getCode() . ' -> ' . $e->getMessage(), $row['username']); } } else { // Disable user, no valid API information found! eveapi_disableForumAccount($row['user_id'], $row['username'], $row['eveapi_ts'], INACTIVE_EVEAPI_INVALID, $ts3_VirtualServer); } } $db->sql_freeresult($result); } else { cronlog("Quiting the cronjob, as no connection to the TeamSpeak 3 server could be made while TeamSpeak 3 Integration is enabled."); } // ******************************************************************* // ** ACTUAL CRONJOB END ********************************************* // ******************************************************************* } cronlog("Finished Successfully"); }
while ($row = $db->sql_fetchrow($result)) { if (!empty($row["eveapi_keyid"]) && !empty($row["eveapi_vcode"])) { $characterInfo = eveapi_checkThisCharacter($row['eveapi_keyid'], $row['eveapi_vcode'], $row['username']); if (empty($characterInfo["error"])) { $eveapi_forumGroups = array(); $eveapi_TSGroups = array(); if (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember']) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $eveapi_TSGroups = $characterInfo["TSGroups"]; $extraGroups = eveapi_setForumGroups($row['user_id'], $eveapi_forumGroups, $row['username']); if ($config['eveapi_ts_masterswitch'] && !empty($row['eveapi_ts'])) { eveapi_setTeamSpeakGroups($row['eveapi_ts'], $eveapi_TSGroups, $row['username'], $ts3_VirtualServer, $extraGroups["TS"]); } if ($config['eveapi_jabber_masterswitch']) { if ($config['eveapi_ejabber_switch']) { eveapi_setJabberAccess($row['user_id'], $characterInfo['jabber'], $extraGroups['jabber'], $row['username']); } if ($config['eveapi_openfire_switch']) { eveapi_setOpenFireAccess($row['user_id'], $characterInfo['openfire'], $extraGroups['openfire'], $row['username']); } } } else { // no valid forumgroups found, probably meaning the user isn't part of any entity and should be disabled eveapi_disableForumAccount($row['user_id'], $row['username'], $row['eveapi_ts'], INACTIVE_EVEAPI_NONMEMBER, $ts3_VirtualServer); } } else { // error reported by eveapi_checkThisCharacter(), now use $characterInfo["disable"] to determine whether or not to disable. if ($characterInfo["disable"]) { eveapi_disableForumAccount($row['user_id'], $row['username'], $row['eveapi_ts'], INACTIVE_EVEAPI_INVALID, $ts3_VirtualServer); } }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $cache; global $phpbb_root_path, $phpbb_admin_path, $phpEx, $table_prefix, $file_uploads; global $phpbb_dispatcher, $request; global $phpbb_container; $user->add_lang(array('posting', 'ucp', 'acp/users')); $this->tpl_name = 'acp_users'; $error = array(); $username = utf8_normalize_nfc(request_var('username', '', true)); $user_id = request_var('u', 0); $submit = isset($_POST['update']) && !isset($_POST['cancel']) ? true : false; $form_name = 'omni/eveapi/user'; add_form_key($form_name); // Show user selection mask if (!$username && !$user_id) { $this->page_title = 'SELECT_USER'; $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=select_user&field=username&select_single=true'))); return; } if (!$user_id) { $sql = 'SELECT user_id FROM ' . USERS_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tWHERE username_clean = '" . $db->sql_escape(utf8_clean_string($username)) . "'"; $result = $db->sql_query($sql); $user_id = (int) $db->sql_fetchfield('user_id'); $db->sql_freeresult($result); if (!$user_id) { trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); } } // Generate content for all modes $sql = 'SELECT u.*, s.* FROM ' . USERS_TABLE . ' u LEFT JOIN ' . SESSIONS_TABLE . ' s ON (s.session_user_id = u.user_id) WHERE u.user_id = ' . $user_id . ' ORDER BY s.session_time DESC'; $result = $db->sql_query_limit($sql, 1); $user_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$user_row) { trigger_error($user->lang['NO_USER'] . adm_back_link($this->u_action), E_USER_WARNING); } // Generate overall "header" for user admin $s_form_options = ''; // Build modes dropdown list $sql = 'SELECT module_mode, module_auth FROM ' . MODULES_TABLE . "\n\t\t\t\t\t\t\t\t\t\t\t\tWHERE module_basename = 'acp_eveapi_user'\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND module_enabled = 1\n\t\t\t\t\t\t\t\t\t\t\t\t\tAND module_class = 'acp'\n\t\t\t\t\t\t\t\t\t\t\t\tORDER BY left_id, module_mode"; $result = $db->sql_query($sql); $dropdown_modes = array(); while ($row = $db->sql_fetchrow($result)) { if (!$this->p_master->module_auth_self($row['module_auth'])) { continue; } $dropdown_modes[$row['module_mode']] = true; } $db->sql_freeresult($result); foreach ($dropdown_modes as $module_mode => $null) { $selected = $mode == $module_mode ? ' selected="selected"' : ''; $s_form_options .= '<option value="' . $module_mode . '"' . $selected . '>' . $user->lang['ACP_USER_' . strtoupper($module_mode)] . '</option>'; } $template->assign_vars(array('U_BACK' => $this->u_action, 'U_MODE_SELECT' => append_sid("{$phpbb_admin_path}index.{$phpEx}", "i={$id}&u={$user_id}"), 'U_ACTION' => $this->u_action . '&u=' . $user_id, 'S_FORM_OPTIONS' => $s_form_options, 'MANAGED_USERNAME' => $user_row['username'])); // Prevent normal users/admins change/view founders if they are not a founder by themselves if ($user->data['user_type'] != USER_FOUNDER && $user_row['user_type'] == USER_FOUNDER) { trigger_error($user->lang['NOT_MANAGE_FOUNDER'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->page_title = $user_row['username'] . ' :: ' . $user->lang('ACP_USER_' . strtoupper($mode)); switch ($mode) { case 'eveapi_account': include $phpbb_root_path . 'includes/functions_user.' . $phpEx; $user->add_lang('mods/info_acp_eveapi'); $data = array('username' => utf8_normalize_nfc(request_var('user', $user_row['username'], true)), 'eveapi_keyid' => request_var('eveapi_keyid', $user_row['eveapi_keyid'], true), 'eveapi_vcode' => request_var('eveapi_vcode', $user_row['eveapi_vcode'], true)); if ($submit) { $check_ary = array('eveapi_keyid' => array(array('string', false, 1, 15)), 'eveapi_vcode' => array(array('string', false, 64, 64))); $check_ary['username'] = array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username')); $error = validate_data($data, $check_ary); if (!sizeof($error) && $config['eveapi_validation']) { $eveapi_teamSpeakGroups = array(); $characterInfo = eveapi_checkThisCharacter($data['eveapi_keyid'], $data['eveapi_vcode'], $data['username']); if (empty($characterInfo["error"])) { if (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember']) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $eveapi_teamSpeakGroups = $characterInfo["TSGroups"]; $extraGroups = eveapi_setForumGroups($user->data['user_id'], $eveapi_forumGroups, $data['username']); if ($config['eveapi_jabber_masterswitch']) { if ($config['eveapi_ejabber_switch']) { eveapi_setJabberAccess($user_row['user_id'], $characterInfo['jabber'], $extraGroups['jabber'], $data['username']); } if ($config['eveapi_openfire_switch']) { eveapi_setOpenFireAccess($user_row['user_id'], $characterInfo['openfire'], $extraGroups['openfire'], $data['username']); } } } else { $error[] = 'This character is not permitted to have an account on this forum.'; } } else { $error = array_merge($error, $characterInfo["error"]); } } $sql_ary = array('user_character_id' => isset($characterInfo["info"]["characterId"]) ? (int) $characterInfo["info"]["characterId"] : 0, 'username' => $data['username'], 'username_clean' => utf8_clean_string($data['username']), 'eveapi_keyid' => $data['eveapi_keyid'], 'eveapi_vcode' => $data['eveapi_vcode']); if ($data['username'] != $user_row['username']) { add_log('user', $user_row['user_id'], 'LOG_USER_UPDATE_NAME', $user_row['username'], $data['username']); } if ($data['eveapi_keyid'] != $user_row['eveapi_keyid'] || $data['eveapi_vcode'] != $user_row['eveapi_vcode']) { add_log('user', $user_row['user_id'], 'User has updated his/her EVE API information.', $user_row['username'], $data['eveapi_keyid'] . " -> " . $data['eveapi_vcode']); } $message = 'EVEAPI_UPDATED'; if (sizeof($sql_ary)) { $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user_row['user_id']; $db->sql_query($sql); add_log('admin', 'LOG_USER_USER_UPDATE', $data['username']); } } $inactive_reason = ''; if ($user_row['user_type'] == USER_INACTIVE) { $inactive_reason = $user->lang['INACTIVE_REASON_UNKNOWN']; switch ($user_row['user_inactive_reason']) { case INACTIVE_REGISTER: $inactive_reason = $user->lang['INACTIVE_REASON_REGISTER']; break; case INACTIVE_PROFILE: $inactive_reason = $user->lang['INACTIVE_REASON_PROFILE']; break; case INACTIVE_MANUAL: $inactive_reason = $user->lang['INACTIVE_REASON_MANUAL']; break; case INACTIVE_REMIND: $inactive_reason = $user->lang['INACTIVE_REASON_REMIND']; break; case INACTIVE_EVEAPI_INVALID: $inactive_reason = $user->lang['EVEAPI_INVALID_API_KEY']; break; case INACTIVE_EVEAPI_NONMEMBER: $inactive_reason = $user->lang['EVEAPI_NOT_ALLOWED_ACCOUNT']; break; } } $template->assign_vars(array('S_EVEAPI_REGISTER' => true, 'USER' => $data['username'], 'EVEAPI_KEYID' => $data['eveapi_keyid'], 'EVEAPI_VCODE' => $data['eveapi_vcode'], 'EVEAPI_ACCESSMASK' => eveapi_getAccessMask(), 'L_NAME_CHARS_EXPLAIN' => $user->lang($config['allow_name_chars'] . '_EXPLAIN', $user->lang('CHARACTERS', (int) $config['min_name_chars']), $user->lang('CHARACTERS', (int) $config['max_name_chars'])), 'L_EVEAPI_ACCOUNT' => $user->lang['UCP_EVEAPI_ACCOUNT'], 'S_USER_INACTIVE' => $user_row['user_type'] == USER_INACTIVE ? true : false, 'USER_INACTIVE_REASON' => $inactive_reason)); break; case 'eveapi_jabber': $user->add_lang('mods/info_acp_eveapi'); if ($submit) { $characterInfo = eveapi_checkThisCharacter($user_row['eveapi_keyid'], $user_row['eveapi_vcode'], $user_row['username']); if (empty($characterInfo["error"]) && (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember'])) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $extraGroups = eveapi_setForumGroups($user_row['user_id'], $eveapi_forumGroups, $user_row['username']); $password = eveapi_randomString(8); $result = eveapi_setOpenFireAccess($user_row['user_id'], $characterInfo['openfire'], $extraGroups['openfire'], $user_row['username'], $password); if ($result) { $user_row['user_jabber_password'] = $password; } else { $error[] = $user->lang['JABBER_REGISTRATION_FAILED']; } } } $clean_username = str_replace(array(" ", "'"), array("_", "_"), $user_row['username']); $template->assign_vars(array('S_EVEAPI_JABBER' => true, 'JABBER_USERNAME' => $clean_username, 'JABBER_PASSWORD' => $user_row['user_jabber_password'], 'JABBER_HOST' => $config['eveapi_jabber_hostname'], 'L_EVEAPI_JABBER' => $user->lang['UCP_EVEAPI_JABBER'], 'L_JABBER' => $user->lang['EVEAPI_JABBER_REGISTER'], 'L_JABBER_EXPLAIN' => $user->lang['EVEAPI_JABBER_EXPLAIN'], 'L_JABBER_USERNAME' => $user->lang['EVEAPI_JABBER_USERNAME'], 'L_JABBER_PASSWORD' => $user->lang['EVEAPI_JABBER_PASSWORD'], 'L_JABBER_HOST' => $user->lang['EVEAPI_JABBER_HOST'])); break; case 'eveapi_ts': $user->add_lang('mods/info_acp_eveapi'); if ($submit) { try { $nickname = $config['eveapi_ts_nickname']; if (eveapi_validateMixedalphanumeric($nickname) != 1) { $nickname = "phpBBbot"; } $ts3_VirtualServer = TeamSpeak3::factory("serverquery://" . $config["eveapi_ts_username"] . ":" . $config["eveapi_ts_password"] . "@" . $config["eveapi_ts_ip"] . ":" . $config["eveapi_ts_port_query"] . "/?server_port=" . $config["eveapi_ts_port_server"] . "&nickname=" . $nickname); } catch (Exception $e) { $error[] = $user->lang['TEAMSPEAK_CONNECTION_FAILED']; } $eveapi_ts = eveapi_getTeamSpeakUID($user_row['username'], $ts3_VirtualServer); if (empty($eveapi_ts)) { $error[] = $user->lang['TEAMSPEAK_USERNAME_NOT_FOUND']; } else { if (empty($user_row["eveapi_keyid"]) || empty($user_row["eveapi_vcode"])) { $error[] = $user->lang['TEAMSPEAK_NO_API']; } else { $sql_ary = array('eveapi_ts' => $eveapi_ts); $eveapi_teamSpeakGroups = array(); $characterInfo = eveapi_checkThisCharacter($user_row['eveapi_keyid'], $user_row['eveapi_vcode'], $user_row['username']); if (empty($characterInfo["error"]) && (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember'])) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $eveapi_teamSpeakGroups = $characterInfo["TSGroups"]; $extraGroups = eveapi_setForumGroups($user_row['user_id'], $eveapi_forumGroups, $user_row['username']); if ($eveapi_ts != $user_row['eveapi_ts'] && !empty($user_row['eveapi_ts'])) { eveapi_setTeamSpeakGroups($user_row['eveapi_ts'], array(), $user_row['username']); } if ($eveapi_ts != "") { $TSverify = eveapi_setTeamSpeakGroups($eveapi_ts, $eveapi_teamSpeakGroups, $user_row['username'], $ts3_VirtualServer, $extraGroups["TS"]); if ($TSverify !== true) { $error[] = $TSverify; $sql_ary['eveapi_ts'] = $eveapi_ts = ""; } } $user_row['eveapi_ts'] = $eveapi_ts; } $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user_row['user_id']; $db->sql_query($sql); } } } $username = $user_row['username']; if (strlen($username) > 30) { $username = substr($username, 0, 30); } $template->assign_vars(array('S_EVEAPI_TS' => true, 'USERNAME' => $username, 'EVEAPI_TS' => empty($user_row['eveapi_ts']) ? $user->lang['EVEAPI_TEAMSPEAK_UID_EMPTY'] : $user_row['eveapi_ts'], 'L_EVEAPI_TS' => $user->lang['UCP_EVEAPI_TS'], 'L_TEAMSPEAK' => $user->lang['EVEAPI_TEAMSPEAK_REGISTER'], 'L_TEAMSPEAK_EXPLAIN' => $user->lang['EVEAPI_TEAMSPEAK_EXPLAIN'], 'L_TEAMSPEAK_USERNAME' => $user->lang['EVEAPI_TEAMSPEAK_USERNAME'], 'L_TEAMSPEAK_UID' => $user->lang['EVEAPI_TEAMSPEAK_UID'])); break; } // Assign general variables $template->assign_vars(array('S_ERROR' => sizeof($error) ? true : false, 'ERROR_MSG' => sizeof($error) ? implode('<br />', $error) : '')); }
function main($id, $mode) { global $config, $db, $user, $auth, $template, $phpbb_root_path, $phpEx; $submit = !empty($_POST['submit']) ? true : false; $error = $data = array(); $s_hidden_fields = ''; $user->add_lang('mods/info_acp_eveapi'); switch ($mode) { case 'register_account': $this->tpl_name = 'ucp_eveapi_account'; $this->page_title = 'UCP_EVEAPI_ACCOUNT'; $data = array('username' => utf8_normalize_nfc(request_var('username', $user->data['username'], true)), 'eveapi_keyid' => request_var('eveapi_keyid', $user->data['eveapi_keyid'], true), 'eveapi_vcode' => request_var('eveapi_vcode', $user->data['eveapi_vcode'], true)); if ($submit) { $check_ary = array('eveapi_keyid' => array(array('string', false, 1, 15)), 'eveapi_vcode' => array(array('string', false, 64, 64))); if ($auth->acl_get('u_chgname') && $config['allow_namechange']) { $check_ary['username'] = array(array('string', false, $config['min_name_chars'], $config['max_name_chars']), array('username')); } $error = validate_data($data, $check_ary); if (!sizeof($error) && $config['eveapi_validation']) { if (!$auth->acl_get('u_chgname') || !$config['allow_namechange']) { $data['username'] = $user->data['username']; } $eveapi_teamSpeakGroups = array(); $characterInfo = eveapi_checkThisCharacter($data['eveapi_keyid'], $data['eveapi_vcode'], $data['username']); if (empty($characterInfo["error"])) { if (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember']) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $eveapi_teamSpeakGroups = $characterInfo["TSGroups"]; $extraGroups = eveapi_setForumGroups($user->data['user_id'], $eveapi_forumGroups, $data['username']); if ($config['eveapi_jabber_masterswitch']) { if ($config['eveapi_ejabber_switch']) { eveapi_setJabberAccess($user->data['user_id'], $characterInfo['jabber'], $extraGroups['jabber'], $data['username']); } if ($config['eveapi_openfire_switch']) { eveapi_setOpenFireAccess($user->data['user_id'], $characterInfo['openfire'], $extraGroups['openfire'], $data['username']); } } } else { $error[] = 'This character is not permitted to have an account on this forum.'; } } else { $error = array_merge($error, $characterInfo["error"]); } } $sql_ary = array('user_character_id' => isset($characterInfo["info"]["characterId"]) ? (int) $characterInfo["info"]["characterId"] : 0, 'username' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? $data['username'] : $user->data['username'], 'username_clean' => $auth->acl_get('u_chgname') && $config['allow_namechange'] ? utf8_clean_string($data['username']) : $user->data['username_clean'], 'eveapi_keyid' => $data['eveapi_keyid'], 'eveapi_vcode' => $data['eveapi_vcode']); if ($auth->acl_get('u_chgname') && $config['allow_namechange'] && $data['username'] != $user->data['username']) { add_log('user', $user->data['user_id'], 'LOG_USER_UPDATE_NAME', $user->data['username'], $data['username']); } if ($data['eveapi_keyid'] != $user->data['eveapi_keyid'] || $data['eveapi_vcode'] != $user->data['eveapi_vcode']) { add_log('user', $user->data['user_id'], 'User has updated his/her EVE API information.', $user->data['username'], $data['eveapi_keyid'] . " -> " . $data['eveapi_vcode']); } $message = 'EVEAPI_UPDATED'; if (sizeof($sql_ary)) { $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); } } $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => $data['username'], 'EVEAPI_KEYID' => $data['eveapi_keyid'], 'EVEAPI_VCODE' => $data['eveapi_vcode'], 'EVEAPI_ACCESSMASK' => eveapi_getAccessMask(), 'L_USERNAME_EXPLAIN' => sprintf($user->lang[$config['allow_name_chars'] . '_EXPLAIN'], $config['min_name_chars'], $config['max_name_chars']), 'L_TITLE' => $user->lang['UCP_EVEAPI_ACCOUNT'], 'S_EVEAPI_VALIDATE' => $config['eveapi_validation'] ? true : false, 'S_CHANGE_USERNAME' => $config['allow_namechange'] && $auth->acl_get('u_chgname') ? true : false)); break; case 'register_jabber': $this->tpl_name = 'ucp_eveapi_jabber'; $this->page_title = 'UCP_EVEAPI_JABBER'; if (!$config['eveapi_openfire_switch'] && !$config['eveapi_jabber_masterswitch'] || empty($user->data["eveapi_keyid"]) || empty($user->data["eveapi_vcode"])) { $template->assign_vars(array('L_TITLE' => $user->lang['UCP_EVEAPI_JABBER'], 'L_DISABLED' => $user->lang['EVEAPI_JABBER_DISABLED'])); break; } if ($submit) { $characterInfo = eveapi_checkThisCharacter($user->data['eveapi_keyid'], $user->data['eveapi_vcode'], $user->data['username']); if (empty($characterInfo["error"]) && (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember'])) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $extraGroups = eveapi_setForumGroups($user->data['user_id'], $eveapi_forumGroups, $user->data['username']); $password = eveapi_randomString(8); $result = eveapi_setOpenFireAccess($user->data['user_id'], $characterInfo['openfire'], $extraGroups['openfire'], $user->data['username'], $password); if ($result) { $user->data['user_jabber_password'] = $password; } else { $error[] = $user->lang['JABBER_REGISTRATION_FAILED']; } } } $clean_username = str_replace(array(" ", "'"), array("_", "_"), $user->data['username']); $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'JABBER_USERNAME' => $clean_username, 'JABBER_PASSWORD' => $user->data['user_jabber_password'], 'JABBER_HOST' => 'almostawesome.org', 'L_TITLE' => $user->lang['UCP_EVEAPI_JABBER'], 'L_JABBER' => $user->lang['EVEAPI_JABBER_REGISTER'], 'L_JABBER_EXPLAIN' => $user->lang['EVEAPI_JABBER_EXPLAIN'], 'L_JABBER_USERNAME' => $user->lang['EVEAPI_JABBER_USERNAME'], 'L_JABBER_PASSWORD' => $user->lang['EVEAPI_JABBER_PASSWORD'], 'L_JABBER_HOST' => $user->lang['EVEAPI_JABBER_HOST'], 'L_CHANGE_REGISTER' => empty($user->data['user_jabber_password']) ? $user->lang['REGISTER'] : $user->lang['EVEAPI_JABBER_CHANGE_PASSWORD'])); break; case 'register_ts': $this->tpl_name = 'ucp_eveapi_ts'; $this->page_title = 'UCP_EVEAPI_TS'; if (!$config['eveapi_ts_masterswitch']) { $template->assign_vars(array('L_TITLE' => $user->lang['UCP_EVEAPI_TS'], 'L_DISABLED' => $user->lang['EVEAPI_TEAMSPEAK_DISABLED'])); break; } if ($submit) { try { $nickname = $config['eveapi_ts_nickname']; if (eveapi_validateMixedalphanumeric($nickname) != 1) { $nickname = "Cyerus"; } $ts3_VirtualServer = TeamSpeak3::factory("serverquery://" . $config["eveapi_ts_username"] . ":" . $config["eveapi_ts_password"] . "@" . $config["eveapi_ts_ip"] . ":" . $config["eveapi_ts_port_query"] . "/?server_port=" . $config["eveapi_ts_port_server"] . "&nickname=" . $nickname); } catch (Exception $e) { $error[] = $user->lang['TEAMSPEAK_CONNECTION_FAILED']; } $eveapi_ts = eveapi_getTeamSpeakUID($user->data['username'], $ts3_VirtualServer); if (empty($eveapi_ts)) { $error[] = $user->lang['TEAMSPEAK_USERNAME_NOT_FOUND']; } else { if (empty($user->data["eveapi_keyid"]) || empty($user->data["eveapi_vcode"])) { $error[] = $user->lang['TEAMSPEAK_NO_API']; } else { $sql_ary = array('eveapi_ts' => $eveapi_ts); $eveapi_teamSpeakGroups = array(); $characterInfo = eveapi_checkThisCharacter($user->data['eveapi_keyid'], $user->data['eveapi_vcode'], $user->data['username']); if (empty($characterInfo["error"]) && (!empty($characterInfo["forumGroups"]) || empty($characterInfo["forumGroups"]) && $config['eveapi_nonmember'])) { $eveapi_forumGroups = $characterInfo["forumGroups"]; $eveapi_teamSpeakGroups = $characterInfo["TSGroups"]; $extraGroups = eveapi_setForumGroups($user->data['user_id'], $eveapi_forumGroups, $user->data['username']); if ($eveapi_ts != $user->data['eveapi_ts'] && !empty($user->data['eveapi_ts'])) { eveapi_setTeamSpeakGroups($user->data['eveapi_ts'], array(), $user->data['username']); } if ($eveapi_ts != "") { $TSverify = eveapi_setTeamSpeakGroups($eveapi_ts, $eveapi_teamSpeakGroups, $user->data['username'], $ts3_VirtualServer, $extraGroups["TS"]); if ($TSverify !== true) { $error[] = $TSverify; $sql_ary['eveapi_ts'] = $eveapi_ts = ""; } } $user->data['eveapi_ts'] = $eveapi_ts; } $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . ' WHERE user_id = ' . $user->data['user_id']; $db->sql_query($sql); } } } $username = $user->data['username']; if (strlen($username) > 30) { $username = substr($username, 0, 30); } $template->assign_vars(array('ERROR' => sizeof($error) ? implode('<br />', $error) : '', 'USERNAME' => $username, 'EVEAPI_TS' => empty($user->data['eveapi_ts']) ? $user->lang['EVEAPI_TEAMSPEAK_UID_EMPTY'] : $user->data['eveapi_ts'], 'L_TITLE' => $user->lang['UCP_EVEAPI_TS'], 'L_TEAMSPEAK' => $user->lang['EVEAPI_TEAMSPEAK_REGISTER'], 'L_TEAMSPEAK_EXPLAIN' => $user->lang['EVEAPI_TEAMSPEAK_EXPLAIN'], 'L_TEAMSPEAK_USERNAME' => $user->lang['EVEAPI_TEAMSPEAK_USERNAME'], 'L_TEAMSPEAK_UID' => $user->lang['EVEAPI_TEAMSPEAK_UID'])); break; } $template->assign_vars(array('S_HIDDEN_FIELDS' => $s_hidden_fields, 'S_UCP_ACTION' => $this->u_action)); }