public static function ValidateLogin(&$ErrorMessage, $SelfURL) { $Mode = Filter_Input(INPUT_GET, 'openid_mode', FILTER_SANITIZE_SPECIAL_CHARS); if ($Mode === 'error') { $ErrorMessage = Filter_Input(INPUT_GET, 'openid_error', FILTER_SANITIZE_STRING); if (empty($ErrorMessage)) { $ErrorMessage = 'Something went wrong.'; } return false; } else { if ($Mode !== 'id_res') { $ErrorMessage = 'Invalid OpenID mode.'; return false; } } // See http://openid.net/specs/openid-authentication-2_0.html#positive_assertions $Arguments = Filter_Input_Array(INPUT_GET, array('openid_ns' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => '/^http:\\/\\/specs\\.openid\\.net\\/auth\\/2\\.0$/')), 'openid_op_endpoint' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => '/^' . Preg_Quote(self::STEAM_LOGIN, '/') . '$/')), 'openid_claimed_id' => array('filter' => FILTER_VALIDATE_REGEXP, 'options' => array('regexp' => '/^https?:\\/\\/steamcommunity.com\\/openid\\/id\\/(7656119[0-9]{10})\\/?$/')), 'openid_identity' => FILTER_SANITIZE_URL, 'openid_return_to' => FILTER_SANITIZE_URL, 'openid_response_nonce' => FILTER_SANITIZE_STRING, 'openid_assoc_handle' => FILTER_SANITIZE_SPECIAL_CHARS, 'openid_signed' => FILTER_SANITIZE_SPECIAL_CHARS, 'openid_sig' => FILTER_SANITIZE_SPECIAL_CHARS)); if (!Is_Array($Arguments)) { $ErrorMessage = 'Invalid arguments.'; return false; } else { if (In_Array(null || false, $Arguments)) { $ErrorMessage = 'One of the arguments is invalid and/or missing.'; return false; } else { if ($Arguments['openid_claimed_id'] !== $Arguments['openid_identity']) { $ErrorMessage = 'Claimed id must match your identity.'; return false; } else { if (strpos($Arguments['openid_return_to'], $SelfURL) !== 0) { $ErrorMessage = 'Invalid return uri.'; return false; } } } } if (Preg_Match('/^https?:\\/\\/steamcommunity.com\\/openid\\/id\\/(7656119[0-9]{10})\\/?$/', $Arguments['openid_identity'], $CommunityID) === 1) { $CommunityID = $CommunityID[1]; } else { $ErrorMessage = 'Failed to find your CommunityID. If this issue persists, please contact us.'; return false; } $Arguments['openid_mode'] = 'check_authentication'; // Add mode for verification $c = cURL_Init(); cURL_SetOpt_Array($c, array(CURLOPT_USERAGENT => 'Steam Database Party OpenID Login', CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => self::STEAM_LOGIN, CURLOPT_CONNECTTIMEOUT => 6, CURLOPT_TIMEOUT => 6, CURLOPT_POST => true, CURLOPT_POSTFIELDS => $Arguments)); $Response = cURL_Exec($c); cURL_Close($c); if (Preg_Match('/is_valid\\s*:\\s*true/', $Response) === 1) { return $CommunityID; } // If we reach here, then it failed $ErrorMessage = 'Failed to verify your login with Steam, it could be down. Check Steam\'s status at http://steamstat.us.'; return false; }
public function __construct($MakeMojangNewsRequest = false) { $Checks = array(array('Name' => 'session', 'Callback' => 'CheckSession', 'Timeout' => 6, 'URL' => 'https://sessionserver.mojang.com/'), array('Name' => 'website', 'Callback' => 'CheckWebsite', 'Timeout' => 7, 'URL' => 'https://minecraft.net/'), array('Name' => 'skins', 'Callback' => 'CheckSkins', 'Timeout' => 5, 'URL' => 'http://textures.minecraft.net/texture/a116e69a845e227f7ca1fdde8c357c8c821ebd4ba619382ea4a1f87d4ae94')); if ($MakeMojangNewsRequest) { $Checks[] = array('Name' => 'news', 'Callback' => '', 'Timeout' => 4, 'URL' => 'http://status.mojang.com/news'); } $Requests = array(); $Master = cURL_Multi_Init(); foreach ($Checks as $Check) { $Slave = $this->CreateSlave($Check['URL'], $Check['Timeout']); if ($Check['Name'] === 'login') { cURL_SetOpt_Array($Slave, array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => '{"agent":"Minecraft","clientToken":"","username":"******","password":"******"}', CURLOPT_HTTPHEADER => array('Content-Type: application/json'))); } cURL_Multi_Add_Handle($Master, $Slave); $Requests[(int) $Slave] = array('Name' => $Check['Name'], 'Callback' => $Check['Callback']); } unset($Checks); echo 'Doing a thing' . PHP_EOL; do { while (($Exec = cURL_Multi_Exec($Master, $Running)) === CURLM_CALL_MULTI_PERFORM) { } if ($Exec !== CURLM_OK) { break; } while ($Done = cURL_Multi_Info_Read($Master)) { $Slave = $Done['handle']; $Request = $Requests[(int) $Slave]; $Name = $Request['Name']; $Code = cURL_GetInfo($Slave, CURLINFO_HTTP_CODE); $Data = cURL_Multi_GetContent($Slave); echo $Name . ' - HTTP ' . $Code . PHP_EOL; //cURL_Multi_Remove_Handle( $Master, $Slave ); if ($Name === 'news') { HandleNews($Data, isset($Done['error']) ? 0 : $Code); } else { if (isset($Done['error'])) { $this->Report[$Name] = array('status' => self::STATUS_OFFLINE, 'title' => 'cURL Error'); } else { if ($Code === 0) { $this->Report[$Name] = array('status' => self::STATUS_OFFLINE, 'title' => 'Timed Out'); } else { if ($Code !== ($Name === 'realms' ? 401 : 200)) { $Set = false; if ($Name === 'login' && !empty($Data)) { $a = $Data; $Data = JSON_Decode($Data, true); if (JSON_Last_Error() === JSON_ERROR_NONE && Array_Key_Exists('error', $Data)) { if ($Data['error'] === 'Internal Server Error') { $Set = 'Server Error'; } else { $Set = Array_Key_Exists('errorMessage', $Data) ? $Data['errorMessage'] : $Data['error']; if (StrLen($Set) > 23) { $Set = SubStr($Set, 0, 23) . '...'; } } $this->Report[$Name] = array('status' => self::STATUS_OFFLINE, 'title' => $Set); } } if ($Set === false) { $this->Report[$Name] = array('status' => self::STATUS_OFFLINE, 'title' => 'HTTP Error ' . $Code); } unset($Set); } else { if ($this->{$Request['Callback']}($Data) !== true) { $this->Report[$Name] = array('status' => self::STATUS_OFFLINE, 'title' => 'Unexpected Response'); } else { if (cURL_GetInfo($Slave, CURLINFO_TOTAL_TIME) > 1.5) { $this->Report[$Name] = array('status' => self::STATUS_PERF_DEGRADATION, 'title' => 'Quite Slow'); } else { $this->Report[$Name] = array('status' => self::STATUS_ONLINE, 'title' => 'Online'); } } } } } } /*if( $this->SessionID !== false ) { echo 'Got it ' . $Name . PHP_EOL; $SlaveNew = $this->CreateSlave( 'https://sessionserver.mojang.com/session/minecraft/join', 3 ); cURL_SetOpt_Array( $SlaveNew, Array( CURLOPT_POST => true, CURLOPT_POSTFIELDS => '{"accessToken":"' . $this->SessionID . '"}', CURLOPT_HTTPHEADER => Array( 'Content-Type: application/json' ) ) ); $this->SessionID = false; $Requests[ (int)$SlaveNew ] = Array( 'Name' => 'session_auth', 'Callback' => 'CheckSessionReal' ); cURL_Multi_Add_Handle( $Master, $SlaveNew ); unset( $SlaveNew ); }*/ cURL_Multi_Remove_Handle($Master, $Slave); cURL_Close($Slave); unset($Request, $Slave, $Data, $Code); } if ($Running) { cURL_Multi_Select($Master, 3.0); } } while ($Running); cURL_Multi_Close($Master); if (Array_Key_Exists('legacy_session', $this->Report)) { if ($this->Report['legacy_session']['status'] !== self::STATUS_ONLINE && $this->Report['session']['status'] === self::STATUS_ONLINE) { $this->Report['session']['status'] = $this->Report['legacy_session']['status']; $this->Report['session']['title'] = 'Legacy ' . $this->Report['legacy_session']['title']; } unset($this->Report['legacy_session']); } if ($this->AccessToken !== false) { $Slave = $this->CreateSlave('https://sessionserver.mojang.com/session/minecraft/join', 3); cURL_SetOpt_Array($Slave, array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => '{"accessToken":"' . $this->AccessToken . '","selectedProfile":"' . $this->SelectedProfile . '","serverId":0}', CURLOPT_HTTPHEADER => array('Content-Type: application/json'))); $Data = cURL_Exec($Slave); $Code = cURL_GetInfo($Slave, CURLINFO_HTTP_CODE); cURL_Close($Slave); if ($Code !== 0 && $Code !== 200) { $Data = JSON_Decode($Data, true); if (JSON_Last_Error() === JSON_ERROR_NONE && Is_Array($Data) && Array_Key_Exists('error', $Data)) { $Set = $Data['error']; if (StrLen($Set) > 23) { $Set = SubStr($Set, 0, 23) . '...'; } $this->Report['session'] = array('status' => self::STATUS_OFFLINE, 'title' => $Set); } } } }