Skip to content

Commit

Permalink
- #84, #138 improved "character selection" on login page (expired coo…
Browse files Browse the repository at this point in the history
…kies are deleted, character panel layout improvements)

- added new "Server info panel" to the login page
- added new cronjob to delete expired cookie authentication data
  • Loading branch information
exodus4d committed May 2, 2016
1 parent ef8f566 commit 8900276
Show file tree
Hide file tree
Showing 16 changed files with 439 additions and 92 deletions.
7 changes: 5 additions & 2 deletions app/cron.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ importSystemData = Cron\CcpSystemsUpdate->importSystemData, @hourly
; disable outdated maps
deactivateMapData = Cron\MapUpdate->deactivateMapData, @hourly

; delete character log data
deleteLogData = Cron\CharacterUpdate->deleteLogData, @hourly

; delete disabled maps
deleteMapData = Cron\MapUpdate->deleteMapData, @downtime

; delete character log data
deleteLogData = Cron\CharacterUpdate->deleteLogData, @hourly
; delete expired character cookie authentication data
deleteAuthenticationData = Cron\CharacterUpdate->deleteAuthenticationData, @downtime
2 changes: 1 addition & 1 deletion app/main/controller/appcontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function init(\Base $f3) {
// characters from cookies
$f3->set('cookieCharacters', $this->getCookieByName(self::COOKIE_PREFIX_CHARACTER, true));
$f3->set('getCharacterGrid', function($characters){
return ( ((12 / count($characters)) <= 4) ? 4 : (12 / count($characters)) );
return ( ((12 / count($characters)) <= 3) ? 3 : (12 / count($characters)) );
});
}

Expand Down
40 changes: 39 additions & 1 deletion app/main/controller/ccp/sso.php
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public function verifyCharacterData($accessToken){
* @param array $additionalOptions
* @return mixed|null
*/
protected function getEndpoints($accessToken, $additionalOptions = []){
protected function getEndpoints($accessToken = '', $additionalOptions = []){
$crestUrl = self::getCrestEndpoint();
$additionalOptions['contentType'] = 'application/vnd.ccp.eve.Api-v3+json';
$endpoint = $this->getEndpoint($accessToken, $crestUrl, $additionalOptions);
Expand Down Expand Up @@ -645,6 +645,44 @@ protected function updateCharacter($characterData){
return $characterModel;
}

/**
* get CREST server status (online/offline)
* @return \stdClass object
*/
public function getCrestServerStatus(){
$endpoints = $this->getEndpoints();

// set default status e.g. Endpoints don´t work
$data = (object) [];
$data->crestOffline = true;
$data->serverName = 'EVE ONLINE';
$data->serviceStatus = [
'eve' => 'offline',
'server' => 'offline',
];
$data->userCounts = [
'eve' => 0
];

$endpoint = $this->walkEndpoint('', $endpoints, ['serverName']);
if( !empty($endpoint) ){
$data->crestOffline = false;
$data->serverName = (string) $endpoint;
}
$endpoint = $this->walkEndpoint('', $endpoints, ['serviceStatus']);
if( !empty($endpoint) ){
$data->crestOffline = false;
$data->serviceStatus = (new Mapper\CrestServiceStatus($endpoint))->getData();
}

$endpoint = $this->walkEndpoint('', $endpoints, ['userCounts']);
if( !empty($endpoint) ){
$data->crestOffline = false;
$data->userCounts = (new Mapper\CrestUserCounts($endpoint))->getData();
}
return $data;
}

/**
* check response "Header" data for errors
* @param $headers
Expand Down
73 changes: 52 additions & 21 deletions app/main/controller/controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Controller;
use Controller\Api as Api;
use Controller\Ccp\Sso;
use Model;
use DB;

Expand Down Expand Up @@ -242,29 +243,34 @@ protected function getCookieCharacters($cookieData = []){

// validate expire data
// validate token
if(
!$characterAuth->dry() &&
strtotime($characterAuth->expires) >= $currentTime->getTimestamp() &&
hash_equals($characterAuth->token, hash('sha256', $data[1]))
){
// cookie information is valid
// -> try to update character information from CREST
// e.g. Corp has changed, this also ensures valid "access_token"
/**
* @var $character Model\CharacterModel
*/
$character = $characterAuth->characterId;
$updateStatus = $character->updateFromCrest();

// check if character still has user (is not the case of "ownerHash" changed
// check if character is still authorized to log in (e.g. corp/ally or config has changed
// -> do NOT remove cookie on failure. This can be a temporary problem (e.g. CREST is down,..)
if( !$characterAuth->dry() ){
if(
empty($updateStatus) &&
$character->hasUserCharacter() &&
$character->isAuthorized()
strtotime($characterAuth->expires) >= $currentTime->getTimestamp() &&
hash_equals($characterAuth->token, hash('sha256', $data[1]))
){
$characters[$name] = $character;
// cookie information is valid
// -> try to update character information from CREST
// e.g. Corp has changed, this also ensures valid "access_token"
/**
* @var $character Model\CharacterModel
*/
$character = $characterAuth->characterId;
$updateStatus = $character->updateFromCrest();

// check if character still has user (is not the case of "ownerHash" changed
// check if character is still authorized to log in (e.g. corp/ally or config has changed
// -> do NOT remove cookie on failure. This can be a temporary problem (e.g. CREST is down,..)
if(
empty($updateStatus) &&
$character->hasUserCharacter() &&
$character->isAuthorized()
){
$characters[$name] = $character;
}
}else{
// clear existing authentication data from DB
$characterAuth->erase();
$invalidCookie = true;
}
}else{
$invalidCookie = true;
Expand Down Expand Up @@ -371,6 +377,31 @@ public function logOut(\Base $f3){
}
}

/**
* get EVE server status from CREST
* @param \Base $f3
*/
public function getEveServerStatus(\Base $f3){
$return = (object) [];
$return->error = [];

// server status can be cached for some seconds
$cacheKey = 'eve_server_status';
if( !$f3->exists($cacheKey) ){
$sso = new Sso();
$return->status = $sso->getCrestServerStatus();

if( !$return->status->crestOffline ){
$f3->set($cacheKey, $return, 60);
}
}else{
// get from cache
$return = $f3->get($cacheKey);
}

echo json_encode($return);
}

/**
* check weather the page is IGB trusted or not
* @return boolean
Expand Down
35 changes: 31 additions & 4 deletions app/main/cron/characterupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,53 @@ class CharacterUpdate {
/**
* delete all character log data
* >> php index.php "/cron/deleteLogData"
* @param $f3
* @param \Base $f3
*/
function deleteLogData($f3){

DB\Database::instance()->getDB('PF');

/**
* @var $characterLogModel Model\CharacterLogModel
*/
$characterLogModel = Model\BasicModel::getNew('CharacterLogModel', 0);

// find "old" character logs
// find expired character logs
$characterLogs = $characterLogModel->find([
'TIMESTAMPDIFF(SECOND, updated, NOW() ) > :lifetime',
':lifetime' => (int)$f3->get('PATHFINDER.CACHE.CHARACTER_LOG')
]);

if(is_object($characterLogs)){
foreach($characterLogs as $characterLog){
// delete log and all cached values
$characterLog->erase();
}
}
}

/**
* delete expired character authentication data
* authentication data is used for cookie based login
* >> php index.php "/cron/deleteAuthenticationData"
* @param $f3
*/
function deleteAuthenticationData($f3){
DB\Database::instance()->getDB('PF');

/**
* @var $authenticationModel Model\CharacterAuthenticationModel
*/
$authenticationModel = Model\BasicModel::getNew('CharacterAuthenticationModel', 0);

// find expired authentication data
$authentications = $authenticationModel->find([
'(expires - NOW()) <= 0'
]);

if(is_object($authentications)){
foreach($authentications as $authentication){
$authentication->erase();
}
}
}

}
19 changes: 19 additions & 0 deletions app/main/data/mapper/crestservicestatus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Created by PhpStorm.
* User: Exodus
* Date: 01.05.2016
* Time: 19:17
*/

namespace Data\Mapper;


class CrestServiceStatus extends AbstractIterator {

protected static $map = [
'dust' => 'dust',
'eve' => 'eve',
'server' => 'server'
];
}
18 changes: 18 additions & 0 deletions app/main/data/mapper/crestusercounts.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Created by PhpStorm.
* User: Exodus
* Date: 01.05.2016
* Time: 19:42
*/

namespace Data\Mapper;


class CrestUserCounts extends AbstractIterator {

protected static $map = [
'dust' => 'dust',
'eve' => 'eve'
];
}
1 change: 1 addition & 0 deletions js/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define(['jquery'], function($) {
img: 'public/img/', // path for images
// user API
getCaptcha: 'api/user/getCaptcha', // ajax URL - get captcha image
getServerStatus: 'api/user/getEveServerStatus', // ajax URL - get EVE-Online server status
sendInviteKey: 'api/user/sendInvite', // ajax URL - send registration key
getCookieCharacterData: 'api/user/getCookieCharacter', // ajax URL - get character data from cookie
logIn: 'api/user/logIn', // ajax URL - login
Expand Down
Loading

0 comments on commit 8900276

Please sign in to comment.