public static function Update() { // Learn about all of the banned calls that // we are aware of $banned_calls = \EveBannedCall::all(); // For every banned call that we have, prepare // a notification to send foreach ($banned_calls as $banned_call) { // Super users will be receiving this notification, // so loop over the current superusers that we // have foreach (\Auth::findAllUsersWithAccess('superuser') as $super_user) { // Compile the full notification $notification_type = 'API'; $notification_title = 'Banned Call'; $notification_text = 'The SeAT backend has banned the ' . $banned_call->scope . '\\' . $banned_call->api . ' API call for key ' . $banned_call->ownerID . '. Reason: ' . $banned_call->reason . PHP_EOL . 'Key characters: ' . PHP_EOL; // Add some information about the characters on this key foreach (\EveAccountAPIKeyInfoCharacters::where('keyID', $banned_call->ownerID)->get() as $character) { $notification_text .= ' - ' . $character->characterName . PHP_EOL; } // Send the notification BaseNotify::sendNotification($super_user->id, $notification_type, $notification_title, $notification_text); } } }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->info('Finding keys that are not ok.'); // Search the database for keys that are marked as disabled foreach (\SeatKey::where('isOk', '=', 0)->get() as $key) { $this->comment('Key ' . $key->keyID . ' is not ok.'); $this->line('Characters on this key:'); // Print the characters on the affected key foreach (\EveAccountAPIKeyInfoCharacters::where('keyID', '=', $key->keyID)->get() as $character) { $this->line(' ' . $character->characterName); } } }
/** * Execute the console command. * * @return mixed */ public function fire() { // Get the keyID from the commnad arg $keyID = $this->argument('keyID'); $this->info('Searching for key: ' . $keyID); // Search the database for they keyID $characters = \EveAccountAPIKeyInfoCharacters::where('keyID', 'like', '%' . $keyID . '%')->get(); // If we found results, prepare to display them if (count($characters) > 0) { // Loop over the found characters foreach ($characters as $character) { $this->info('Found match: ' . $character->characterName . ' with keyID: ' . $character->keyID); } } else { $this->error('No matches found.'); } }
/** * Execute the console command. * * @return mixed */ public function fire() { // Get the name arg from the commandline $name = $this->argument('name'); $this->info('Searching for term: ' . $name); // Search for keys with the character on it $characters = \EveAccountAPIKeyInfoCharacters::where('characterName', 'like', '%' . $name . '%')->get(); // If there were results from the find, print // them if (count($characters) > 0) { // Loop over the found characeters foreach ($characters as $character) { $this->info('Found match: ' . $character->characterName . ' with keyID: ' . $character->keyID); } } else { $this->error('No matches found.'); } }
protected function getValidCorps($users) { $validCorps = []; $invalid = []; foreach ($users as $u) { $valid_keys = \SeatKey::where('user_id', $u->id)->lists('keyID'); if (!empty($valid_keys)) { $corporation_affiliation = \EveAccountAPIKeyInfoCharacters::whereIn('keyID', $valid_keys)->groupBy('corporationID')->lists('corporationID'); if (!empty($corporation_affiliation)) { $viable = \EveCorporationCorporationSheet::whereIn('corporationID', $corporation_affiliation)->lists('corporationName'); if (!empty($viable)) { $validCorps[] = ['corps' => $viable, 'user' => $u, 'user_groups' => \Auth::getUserGroups($u)]; } } } else { $invalid[] = $u; } } return [$validCorps, $invalid]; }
public static function canAccessCorp($userID, $corpID) { // Get the SeAT user based on the userID $user = \Auth::findUserById($userID); // Determine the keys that the user owns $valid_keys = \SeatKey::where('user_id', $user->id)->lists('keyID'); // Check if we have received any keys in the // previous query if (!empty($valid_keys)) { // Get a list of the corporationID's that the // user is affaliated with $corporation_affiliation = \EveAccountAPIKeyInfoCharacters::whereIn('keyID', $valid_keys)->groupBy('corporationID')->lists('corporationID'); // With the affiliations known, loop over them // matching the affaliated corporationID with // the corporationID in question foreach ($corporation_affiliation as $affiliation) { // If we have a match, return true if ($affiliation == $corpID) { return true; } } } return false; }
public static function Update($keyID, $vCode) { // Start and validate they key pair BaseApi::bootstrap(); BaseApi::validateKeyPair($keyID, $vCode); $scope = 'Account'; $api = 'APIKeyInfo'; // Prepare the Pheal instance $pheal = new Pheal($keyID, $vCode); // Do the actual API call. pheal-ng actually handles some internal // caching too. try { $key_info = $pheal->accountScope->APIKeyInfo(); } catch (\Pheal\Exceptions\APIException $e) { // Some API responses require some rather important actions // SeATs perspective. For eg. Expired keys, IP bans, rate // limits etc. As APIKeyInfo is probably one of the // most called eveapi Updater, we will add the // logic here to check for these types of // responses. // Source: https://api.eveonline.com/Eve/ErrorList.xml.aspx switch ($e->getCode()) { // "API key authentication failure." case 202: // "Authentication failure." // "Authentication failure." case 203: case 204: // "Authentication failure." // "Authentication failure." case 205: // "Authentication failure." // "Authentication failure." case 210: // "Authentication failure (final pass)." // "Authentication failure (final pass)." case 212: // The API is probably entirely wrong. BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Invalid Corporation Key. Key owner does not fullfill role // requirements anymore." // "Invalid Corporation Key. Key owner does not fullfill role // requirements anymore." case 220: // Owner of the corporation key doesnt have hes roles anymore? BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Illegal page request! Please verify the access granted by the key you are using!." // "Illegal page request! Please verify the access granted by the key you are using!." case 221: // Not 100% sure how to handle this one. This call has no // access mask requirement... return; // "Key has expired. Contact key owner for access renewal." // "Key has expired. Contact key owner for access renewal." case 222: // We have a invalid key. Expired or deleted. BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Authentication failure. Legacy API keys can no longer be // used. Please create a new key on support.eveonline.com // and make sure your application supports Customizable // API Keys." // "Authentication failure. Legacy API keys can no longer be // used. Please create a new key on support.eveonline.com // and make sure your application supports Customizable // API Keys." case 223: // The API we are working with is waaaaaay too old. BaseApi::disableKey($keyID, $e->getCode() . ': ' . $e->getMessage()); return; // "Web site database temporarily disabled." // "Web site database temporarily disabled." case 901: // The EVE API Database is apparently down, so mark the // server as 'down' in the cache so that subsequent // calls don't fail because of this. \Cache::put('eve_api_down', true, 30); return; // "EVE backend database temporarily disabled."" // "EVE backend database temporarily disabled."" case 902: // The EVE API Database is apparently down, so mark the // server as 'down' in the cache so that subsequent // calls don't fail because of this. \Cache::put('eve_api_down', true, 30); return; // "Your IP address has been temporarily blocked because it // is causing too many errors. See the cacheUntil // timestamp for when it will be opened again. // IPs that continually cause a lot of errors // in the API will be permanently banned, // please take measures to minimize // problematic API calls from your // application." // "Your IP address has been temporarily blocked because it // is causing too many errors. See the cacheUntil // timestamp for when it will be opened again. // IPs that continually cause a lot of errors // in the API will be permanently banned, // please take measures to minimize // problematic API calls from your // application." case 904: // If we are rate limited, set the status of the eveapi // server to 'down' in the cache so that subsequent // calls don't fail because of this. // Get time of IP ban in minutes, rounded up to the next whole minute $time = round(($e->cached_until_unixtime - $e->request_time_unixtime) / 60, 0, PHP_ROUND_HALF_UP); \Cache::put('eve_api_down', true, $time); return; // We got a problem we don't know what to do with, so log // and throw the exception so that the can debug it. // We got a problem we don't know what to do with, so log // and throw the exception so that the can debug it. default: \Log::error('Call to APIKeyInfo for ' . $keyID . ' failed with: ' . $e->getCode() . ':' . $e->getMessage(), array('src' => __CLASS__)); throw $e; break; } // Process a ban request as needed BaseApi::banCall($api, $scope, $keyID, 0, $e->getCode() . ': ' . $e->getMessage()); return; } catch (\Pheal\Exceptions\PhealException $e) { throw $e; } // Check if the data in the database is still considered up to date. // checkDbCache will return true if this is the case if (!BaseApi::checkDbCache($scope, $api, $key_info->cached_until, $keyID)) { $key_data = \EveAccountAPIKeyInfo::where('keyID', '=', $keyID)->first(); if (!$key_data) { $key_data = new \EveAccountAPIKeyInfo(); } $key_data->keyID = $keyID; $key_data->accessMask = $key_info->key->accessMask; $key_data->type = $key_info->key->type; $key_data->expires = strlen($key_info->key->expires) > 0 ? $key_info->key->expires : null; // hack much? $key_data->save(); // Check if we have any knowledge of any characters for this key. We will remove values from this // array as we move along to determine which characters we should delete that are possibly no // longer on this key $known_characters = array(); foreach (\EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->get() as $character) { $known_characters[] = $character->characterID; } $known_characters = array_flip($known_characters); // Update the key characters foreach ($key_info->key->characters as $character) { // Check if we need to update || insert $character_data = \EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->where('characterID', '=', $character->characterID)->first(); if (!$character_data) { $character_data = new \EveAccountAPIKeyInfoCharacters(); } // else, add/update $character_data->characterID = $character->characterID; $character_data->characterName = $character->characterName; $character_data->corporationID = $character->corporationID; $character_data->corporationName = $character->corporationName; $key_data->characters()->save($character_data); // Remove this characterID from the known_characters as its still on // the key if (array_key_exists($character->characterID, $known_characters)) { unset($known_characters[$character->characterID]); } } // Delete the characters that are no longer part of this key foreach (array_flip($known_characters) as $oldcharacter) { \EveAccountAPIKeyInfoCharacters::where('keyID', '=', $keyID)->where('characterID', '=', $oldcharacter)->delete(); } // Update the cached_until time in the database for this api call BaseApi::setDbCache($scope, $api, $key_info->cached_until, $keyID); } return $key_info; }
public function getSetGroupMain($personid, $characterid) { // Lets do some quick checks to ensure that the person exists if (!SeatPeople::where('personID', $personid)->first()) { return Redirect::action('ApiKeyController@getPeople')->withErrors('Whatever you just tried simply wont work.'); } // Delete the old main SeatPeopleMain::where('personID', $personid)->delete(); $person = SeatPeople::with('main')->where('personID', $personid)->first(); // Get the main information $main = new SeatPeopleMain(); $main->characterID = $characterid; $main->characterName = EveAccountAPIKeyInfoCharacters::where('characterID', $characterid)->pluck('characterName'); $person->main()->save($main); $person->save(); return Redirect::action('ApiKeyController@getPeople')->with('success', 'Group has had its main updated to ' . $main->characterName); }
public static function findCharacterCorporation($characterID) { // Locate the key in the db $character = \EveAccountAPIKeyInfoCharacters::where('characterID', '=', $characterID)->first(); if (!$character) { return; } // Return the characters corporationID return $character->corporationID; }
public function getAjaxIndustry($characterID) { // Check the character existance $character = DB::table('account_apikeyinfo_characters')->where('characterID', $characterID)->first(); // Check if whave knowledge of this character, else, 404 if (count($character) <= 0) { App::abort(404); } // Next, check if the current user has access. Superusers may see all the things, // normal users may only see their own stuffs. . SuperUser() inherits 'recruiter' if (!\Auth::hasAccess('recruiter')) { if (!in_array(EveAccountAPIKeyInfoCharacters::where('characterID', $characterID)->pluck('keyID'), Session::get('valid_keys'))) { App::abort(404); } } // Get current working jobs $current_jobs = DB::table('character_industryjobs as a')->select(DB::raw("\n *, CASE\n when a.stationID BETWEEN 66015148 AND 66015151 then\n (SELECT s.stationName FROM staStations AS s\n WHERE s.stationID=a.stationID-6000000)\n when a.stationID BETWEEN 66000000 AND 66014933 then\n (SELECT s.stationName FROM staStations AS s\n WHERE s.stationID=a.stationID-6000001)\n when a.stationID BETWEEN 66014934 AND 67999999 then\n (SELECT c.stationName FROM `eve_conquerablestationlist` AS c\n WHERE c.stationID=a.stationID-6000000)\n when a.stationID BETWEEN 60014861 AND 60014928 then\n (SELECT c.stationName FROM `eve_conquerablestationlist` AS c\n WHERE c.stationID=a.stationID)\n when a.stationID BETWEEN 60000000 AND 61000000 then\n (SELECT s.stationName FROM staStations AS s\n WHERE s.stationID=a.stationID)\n when a.stationID>=61000000 then\n (SELECT c.stationName FROM `eve_conquerablestationlist` AS c\n WHERE c.stationID=a.stationID)\n else (SELECT m.itemName FROM mapDenormalize AS m\n WHERE m.itemID=a.stationID) end\n AS location,a.stationID AS locID"))->where('a.characterID', $characterID)->where('endDate', '>', date('Y-m-d H:i:s'))->orderBy('endDate', 'asc')->get(); // Get the passed jobs $finished_jobs = DB::table('character_industryjobs as a')->select(DB::raw("\n *, CASE\n when a.stationID BETWEEN 66015148 AND 66015151 then\n (SELECT s.stationName FROM staStations AS s\n WHERE s.stationID=a.stationID-6000000)\n when a.stationID BETWEEN 66000000 AND 66014933 then\n (SELECT s.stationName FROM staStations AS s\n WHERE s.stationID=a.stationID-6000001)\n when a.stationID BETWEEN 66014934 AND 67999999 then\n (SELECT c.stationName FROM `eve_conquerablestationlist` AS c\n WHERE c.stationID=a.stationID-6000000)\n when a.stationID BETWEEN 60014861 AND 60014928 then\n (SELECT c.stationName FROM `eve_conquerablestationlist` AS c\n WHERE c.stationID=a.stationID)\n when a.stationID BETWEEN 60000000 AND 61000000 then\n (SELECT s.stationName FROM staStations AS s\n WHERE s.stationID=a.stationID)\n when a.stationID>=61000000 then\n (SELECT c.stationName FROM `eve_conquerablestationlist` AS c\n WHERE c.stationID=a.stationID)\n else (SELECT m.itemName FROM mapDenormalize AS m\n WHERE m.itemID=a.stationID) end\n AS location,a.stationID AS locID"))->where('a.characterID', $characterID)->where('endDate', '<=', date('Y-m-d H:i:s'))->orderBy('endDate', 'desc')->get(); // Return the view return View::make('character.view.industry')->with('characterID', $characterID)->with('current_jobs', $current_jobs)->with('finished_jobs', $finished_jobs); }
// We can check if the user is authed and if so, get the keyID's // this user is valid for. // We will also get a list of corporation ID's that the user is // affiliated to. This can be used to check the permissions then // later for specific functions such as starbases etc. // We will also check if the user has any director roles in any // of the affiliated corporations. Directors will be allowed to // assign permissions to other members of their corporation if (\Auth::check()) { // Valid API Keys $valid_keys = SeatKey::where('user_id', \Auth::User()->id)->lists('keyID'); Session::put('valid_keys', $valid_keys); // Affiliated corporationID's. if (!empty($valid_keys)) { // Get the list of corporationID's that the user is affiliated with $corporation_affiliation = EveAccountAPIKeyInfoCharacters::whereIn('keyID', $valid_keys)->groupBy('corporationID')->lists('corporationID'); Session::put('corporation_affiliations', $corporation_affiliation); // Determine which corporations the user is a director for if (!empty($corporation_affiliation)) { $is_director = EveCorporationMemberSecurityRoles::whereIn('corporationID', $corporation_affiliation)->where('roleID', '=', '1')->groupBy('corporationID')->lists('corporationID'); Session::put('is_director', $is_director); } } else { // Just to ensure that we dont have some strange errors later, lets // define a empty array in the session for corporation_affiliations Session::put('corporation_affiliations', array()); Session::put('is_director', array()); Session::put('valid_keys', array()); } } });