Esempio n. 1
0
 public function actionIndex()
 {
     $this->_ts3group = XenForo_Application::getOptions()->ts3gw2auth_verified_group;
     $this->_ts3server = XenForo_Application::getOptions()->ts3gw2auth_ts3server;
     $this->_ts3port = XenForo_Application::getOptions()->ts3gw2auth_ts3port;
     $this->_ts3sqport = XenForo_Application::getOptions()->ts3gw2auth_ts3serverquery;
     $this->_ts3user = XenForo_Application::getOptions()->ts3gw2auth_ts3username;
     $this->_ts3pass = XenForo_Application::getOptions()->ts3gw2auth_ts3password;
     $this->_gw2world = XenForo_Application::getOptions()->ts3gw2auth_worldid;
     $this->_ts3prefix = XenForo_Application::getOptions()->ts3gw2auth_keyprefix;
     require_once "library/Moturdrn/TS3GW2Auth/Includes/TeamSpeak3/ts3admin.class.php";
     $tsAdmin = new ts3admin($this->_ts3server, $this->_ts3sqport);
     if ($tsAdmin->getElement('success', $tsAdmin->connect())) {
         $tsAdmin->login($this->_ts3user, $this->_ts3pass);
         $tsAdmin->selectServer($this->_ts3port);
     } else {
         throw $this->responseException($this->responseError('There was an error connecting to the TeamSpeak Server.', 400));
     }
     $visitor = XenForo_Visitor::getInstance();
     $session = XenForo_Session::startPublicSession();
     $sessionId = $session->getSessionId();
     $session->set('last_ts3_id', '');
     $session->set('last_ts3_dbid', 0);
     $session->set('remove_old_auths', false);
     if ($_SERVER['REMOTE_ADDR']) {
         $ipaddress = $_SERVER['REMOTE_ADDR'];
     }
     $tsId = $this->_input->filterSingle('tsid', XenForo_Input::UINT);
     if (!$tsId) {
         throw $this->responseException($this->responseError('You must supply a valid Teamspeak ID', 400));
     }
     $ts3_user = $tsAdmin->clientDBInfo($tsId);
     if ($ts3_user['success'] != 1) {
         throw $this->responseException($this->responseError('You must supply a valid Teamspeak ID', 400));
     }
     $ts3_user = $ts3_user['data'];
     $ts3_user_ip = $ts3_user['client_lastip'];
     $ts3_nickname = $ts3_user['client_nickname'];
     if ($ts3_user_ip != $ipaddress) {
         throw $this->responseException($this->responseError('Last TS IP and current IP are different, please verify whilst TS is connected.', 400));
     }
     $keyname = $this->_ts3prefix . uniqid();
     /**     @var $authWriter Moturdrn_TS3GW2Auth_DataWriter_Auth   * */
     $authWriter = XenForo_DataWriter::create('Moturdrn_TS3GW2Auth_DataWriter_Auth');
     if ($this->_getAuthModel()->getAuthByTS3UId($ts3_user['client_unique_identifier'])) {
         $authWriter->setExistingData($ts3_user['client_unique_identifier']);
     } else {
         $authWriter->set('ts3_uniqueid', $ts3_user['client_unique_identifier']);
         $authWriter->set('ts3_dbid', $ts3_user['client_database_id']);
         $authWriter->set('gw2_name', '');
         $authWriter->set('gw2_account_guid', '');
         $authWriter->set('gw2_apikey', '');
         $authWriter->set('gw2_world', '');
         $authWriter->set('last_check', strtotime("now"));
     }
     $authWriter->set('sessionid', $sessionId);
     $authWriter->set('keyname', $keyname);
     $authWriter->preSave();
     $authWriter->save();
     /**     @var $logWriter Moturdrn_TS3GW2Auth_DataWriter_Log   * */
     $logWriter = XenForo_DataWriter::create('Moturdrn_TS3GW2Auth_DataWriter_Log');
     $logWriter->set('date', strtotime("now"));
     $logWriter->set('ts3_uniqueid', $ts3_user['client_unique_identifier']);
     $logWriter->set('ts3_dbid', $ts3_user['client_database_id']);
     $logWriter->set('message', 'Verification Start');
     $logWriter->set('apikey', '');
     $logWriter->set('apidata', '');
     $logWriter->set('extradata', "Expected Key Name: {$keyname}");
     $logWriter->preSave();
     $logWriter->save();
     $viewParams = array('keyname' => $keyname, 'ts3_nickname' => $ts3_nickname, 'sessionId' => $sessionId);
     $session->set('last_ts3_id', $ts3_user['client_unique_identifier']);
     $session->set('last_ts3_dbid', $ts3_user['client_database_id']);
     return $this->responseView('Moturdrn_TS3GW2Auth_ViewPublic_Index', 'Moturdrn_TS3GW2Auth_Index', $viewParams);
 }