示例#1
0
 public function getDeleteKey($keyID, $delete_all_info = false)
 {
     // Ensure that this user may access the data for $keyID
     if (!\Auth::isSuperUser()) {
         if (!in_array($keyID, Session::get('valid_keys'))) {
             App::abort(404);
         }
     }
     // Ensure the user is allowed to delete this key
     if (!\Auth::hasAccess('key_manager')) {
         App::abort(404);
     }
     // Get the full key and vCode
     $key = SeatKey::where('keyID', $keyID)->first();
     if (!$key) {
         App::abort(404);
     }
     // Based on delete_all_info, we will either just delete the key,
     // or all of the information associated with it
     switch ((bool) $delete_all_info) {
         case true:
             // Check if we can determine if this is a corporation or account/char key.
             $type = \EveAccountAPIKeyInfo::where('keyID', $keyID)->pluck('type');
             // Check if the type is set
             if ($type) {
                 // For corporation keys, we will delete corporation stuff, duhr
                 if ($type == "Corporation") {
                     // Most of the data for corporations is stored with the corporationID
                     // as key. To get this ID, we need to find the character attached to
                     // this key, and then the corporation for that character
                     $characters = BaseApi::findKeyCharacters($keyID);
                     $corporationID = BaseApi::findCharacterCorporation($characters[0]);
                     // With the corporationID now known, go ahead and cleanup the database
                     \EveCorporationAccountBalance::where('corporationID', $corporationID)->delete();
                     \EveCorporationAssetList::where('corporationID', $corporationID)->delete();
                     \EveCorporationAssetListContents::where('corporationID', $corporationID)->delete();
                     \EveCorporationAssetListLocations::where('corporationID', $corporationID)->delete();
                     \EveCorporationContactListAlliance::where('corporationID', $corporationID)->delete();
                     \EveCorporationContactListCorporate::where('corporationID', $corporationID)->delete();
                     \EveCorporationContracts::where('corporationID', $corporationID)->delete();
                     \EveCorporationContractsItems::where('corporationID', $corporationID)->delete();
                     \EveCorporationCorporationSheet::where('corporationID', $corporationID)->delete();
                     \EveCorporationCorporationSheetDivisions::where('corporationID', $corporationID)->delete();
                     \EveCorporationCorporationSheetWalletDivisions::where('corporationID', $corporationID)->delete();
                     \EveCorporationIndustryJobs::where('corporationID', $corporationID)->delete();
                     \EveCorporationMarketOrders::where('corporationID', $corporationID)->delete();
                     \EveCorporationMedals::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberMedals::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityGrantableRoles::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityGrantableRolesAtBase::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityGrantableRolesAtHQ::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityGrantableRolesAtOther::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityLog::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityRoles::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityRolesAtBase::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityRolesAtHQ::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityRolesAtOther::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberSecurityTitles::where('corporationID', $corporationID)->delete();
                     \EveCorporationMemberTracking::where('corporationID', $corporationID)->delete();
                     \EveCorporationShareholderCharacters::where('corporationID', $corporationID)->delete();
                     \EveCorporationShareholderCorporations::where('corporationID', $corporationID)->delete();
                     \EveCorporationStandingsAgents::where('corporationID', $corporationID)->delete();
                     \EveCorporationStandingsFactions::where('corporationID', $corporationID)->delete();
                     \EveCorporationStandingsNPCCorporations::where('corporationID', $corporationID)->delete();
                     \EveCorporationStarbaseDetail::where('corporationID', $corporationID)->delete();
                     \EveCorporationStarbaseList::where('corporationID', $corporationID)->delete();
                     \EveCorporationWalletJournal::where('corporationID', $corporationID)->delete();
                     \EveCorporationWalletTransactions::where('corporationID', $corporationID)->delete();
                 } else {
                     // And for character stuff, we delete character stuff
                     // Here we need to be careful now. It may happen that we have more than 1 key
                     // for a character, so we have to be aware of this. It adds a factor of
                     // complexity to the whole thing.
                     $characters = BaseApi::findKeyCharacters($keyID);
                     // Now that we know about all of the characters, we will loop over them and check
                     // that we only have 1 key for them. If more than one keys have this character, we will
                     // simply ignore the cleanup and add a message about it
                     foreach ($characters as $id => $character) {
                         // Check how many keys know about this character
                         if (\EveAccountAPIKeyInfoCharacters::where('characterID', $character)->count() > 1) {
                             // Write a log entry about this
                             \Log::warning('Character ' . $character . ' is recorded on another key and will not been cleaned up');
                             // Remove this character from $characters
                             unset($characters[$id]);
                         }
                     }
                     // So we now have an array of characterID's that can be cleaned up. Lets do that
                     if (count($characters) > 0) {
                         \EveCharacterAccountBalance::whereIn('characterID', $characters)->delete();
                         \EveCharacterAssetList::whereIn('characterID', $characters)->delete();
                         \EveCharacterAssetListContents::whereIn('characterID', $characters)->delete();
                         \EveCharacterCharacterSheet::whereIn('characterID', $characters)->delete();
                         \EveCharacterCharacterSheetSkills::whereIn('characterID', $characters)->delete();
                         \EveCharacterContactList::whereIn('characterID', $characters)->delete();
                         \EveCharacterContactListAlliance::whereIn('characterID', $characters)->delete();
                         \EveCharacterContactListCorporate::whereIn('characterID', $characters)->delete();
                         \EveCharacterContactNotifications::whereIn('characterID', $characters)->delete();
                         \EveCharacterContracts::whereIn('characterID', $characters)->delete();
                         \EveCharacterContractsItems::whereIn('characterID', $characters)->delete();
                         \EveCharacterIndustryJobs::whereIn('characterID', $characters)->delete();
                         // Intentionally ignoring the mail related information as this has a lot of overlap
                         // and is almost always usefull
                         \EveCharacterMarketOrders::whereIn('characterID', $characters)->delete();
                         \EveCharacterPlanetaryColonies::whereIn('characterID', $characters)->delete();
                         \EveCharacterPlanetaryLinks::whereIn('characterID', $characters)->delete();
                         \EveCharacterPlanetaryPins::whereIn('characterID', $characters)->delete();
                         \EveCharacterPlanetaryRoutes::whereIn('characterID', $characters)->delete();
                         \EveCharacterResearch::whereIn('characterID', $characters)->delete();
                         \EveCharacterSkillInTraining::whereIn('characterID', $characters)->delete();
                         \EveCharacterSkillQueue::whereIn('characterID', $characters)->delete();
                         \EveCharacterStandingsAgents::whereIn('characterID', $characters)->delete();
                         \EveCharacterStandingsFactions::whereIn('characterID', $characters)->delete();
                         \EveCharacterStandingsNPCCorporations::whereIn('characterID', $characters)->delete();
                         \EveCharacterUpcomingCalendarEvents::whereIn('characterID', $characters)->delete();
                         \EveCharacterWalletJournal::whereIn('characterID', $characters)->delete();
                         \EveCharacterWalletTransactions::whereIn('characterID', $characters)->delete();
                     }
                 }
                 // Finally, delete the key and redirect
                 $key->delete();
                 // Delete the information that we have for this key too
                 \EveAccountAPIKeyInfo::where('keyID', $keyID)->delete();
                 \EveAccountAPIKeyInfoCharacters::where('keyID', $keyID)->delete();
                 return Redirect::action('ApiKeyController@getAll')->with('success', 'Key has been deleted');
             } else {
                 // So, we are unable to determine the key type, so maybe this is
                 // a invalid one or whatever. Just get rid of it.
                 // Delete the API Key
                 $key->delete();
                 // Delete the information that we have for this key too
                 \EveAccountAPIKeyInfo::where('keyID', $keyID)->delete();
                 \EveAccountAPIKeyInfoCharacters::where('keyID', $keyID)->delete();
                 return Redirect::action('ApiKeyController@getAll')->with('success', 'Key has been deleted');
             }
             break;
         case false:
             // Delete the API Key
             $key->delete();
             // Delete the information that we have for this key too
             \EveAccountAPIKeyInfo::where('keyID', $keyID)->delete();
             \EveAccountAPIKeyInfoCharacters::where('keyID', $keyID)->delete();
             return Redirect::action('ApiKeyController@getAll')->with('success', 'Key has been deleted');
             break;
     }
 }
示例#2
0
 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;
 }
示例#3
0
文件: BaseAPI.php 项目: boweiliu/seat
 public static function determineAccess($keyID)
 {
     // Locate the key in the db
     $key = \SeatKey::where('keyID', '=', $keyID)->where('isOk', '=', 1)->first();
     if (!$key) {
         return array();
     }
     // Attempt to get the type & accessMask from the database.
     Account\APIKeyInfo::update($keyID, $key->vCode);
     $key_mask_info = \EveAccountAPIKeyInfo::where('keyID', '=', $keyID)->first();
     // Potential cause for #182. Comment out for now.
     // Account\AccountStatus::update($keyID, $key->vCode);
     // If we still can't determine mask information, leave everything
     if (!$key_mask_info) {
         return array();
     }
     // Prepare a return by setting the 'type' key to the key type we have
     $type = $key_mask_info->type == 'Account' ? 'Character' : $key_mask_info->type;
     $return_access = array('type' => $type);
     // Loop over all the masks we have, and return those we have access to for this key
     foreach (\EveApiCalllist::where('type', '=', $type)->get() as $mask) {
         if ($key_mask_info->accessMask & $mask->accessMask) {
             $return_access['access'][] = array('type' => $mask->type, 'name' => $mask->name);
         }
     }
     // Return it all as a nice array
     return $return_access;
 }