Example #1
0
 /**
  * Class constructor. Called on every page load.
  * @param $keyID integer
  * @param $vCode string
  * @param $user object/integer
  * @param $db PDO object
  */
 public function __construct($keyID, $vCode, $user, $db)
 {
     /** Saving the database into the db param */
     $this->_db = $db;
     /** Determining if we're live or a cronjob -- */
     if (is_object($user)) {
         /** We're dealing with a live user */
         $this->_userID = $user->getUserID();
     } else {
         $this->_userID = $user;
     }
     /** Saving the API key keyID and vCode */
     $this->_keyID = $keyID;
     $this->_vCode = $vCode;
     /** Creating a new Phealng object */
     $pheal = new Pheal($keyID, $vCode, 'account');
     /** Starting a Phealng lookup */
     try {
         $response = $pheal->APIKeyInfo();
         /** Checking to see if we received a valid response */
         if (!isset($response->code) && $response->key->accessMask & MINIMUM_API_MASK) {
             $this->_keyStatus = 1;
             $this->_accessMask = $response->key->accessMask;
             $this->_keyExpiration = $response->key->expires;
             $this->_keyType = $response->key->type;
             if ($response->key->expires == null) {
                 $this->_keyExpiration = 'No Expiration';
             } else {
                 $this->_keyExpiration = $response->key->expires;
             }
             $response2 = $pheal->AccountStatus();
             if ($response2->paidUntil == null) {
                 $this->_accountStatus = "Account Unsubscribed";
             } else {
                 $this->_accountStatus = $response2->paidUntil;
             }
             $i = 1;
             foreach ($response->key->characters as $character) {
                 if ($character->allianceID == "0") {
                     $allianceID = 0;
                     $allianceName = "No Alliance";
                 } else {
                     $allianceID = $character->allianceID;
                     $allianceName = $character->allianceName;
                 }
                 $this->_characters[$i] = array('characterName' => $character->characterName, 'characterID' => $character->characterID, 'corporationName' => $character->corporationName, 'corporationID' => $character->corporationID, 'allianceName' => $allianceName, 'allianceID' => $allianceID);
                 $i++;
             }
         } else {
             $this->_keyStatus = 0;
             $this->keyError = $this->parseKeyError($response->code, 'code');
         }
     } catch (\Pheal\Exceptions\PhealException $e) {
         $this->keyError = $this->parseKeyError($e, 'exception');
         $this->_keyStatus = 0;
         $_SESSION['alert'] = new Alert('danger', 'API Key Error', $e->getMessage());
     }
 }
 public function __construct($keyID, $vcode, $user, $db)
 {
     $this->db = $db;
     if (is_object($user)) {
         $this->uid = $user->getUID();
     } else {
         $this->uid = $user;
     }
     $this->keyID = $keyID;
     $this->vcode = $vcode;
     $pheal = new Pheal($keyID, $vcode, 'account');
     try {
         $response = $pheal->APIKeyInfo();
         if (!isset($response->code) and $response->key->accessMask & MINIMUM_API) {
             $this->keyStatus = 1;
             $this->accessMask = $response->key->accessMask;
             $this->expires = $response->key->expires;
             $this->keyType = $response->key->type;
             if ($response->key->expires == NULL) {
                 $this->expires = 'No Expiration';
             } else {
                 $this->expires = $response->key->expires;
             }
             $response2 = $pheal->AccountStatus();
             if ($response2->paidUntil == NULL) {
                 $this->accountStatus = "Account Unsubscribed";
             } else {
                 $this->accountStatus = $response2->paidUntil;
             }
             $i = 1;
             foreach ($response->key->characters as $character) {
                 if ($character->allianceID == "0") {
                     $allianceID = 0;
                     $allianceName = "No Alliance";
                 } else {
                     $allianceID = $character->allianceID;
                     $allianceName = $character->allianceName;
                 }
                 $this->characters[$i] = array('characterName' => $character->characterName, 'characterID' => $character->characterID, 'corporationName' => $character->corporationName, 'corporationID' => $character->corporationID, 'allianceName' => $allianceName, 'allianceID' => $allianceID);
                 $i++;
             }
         } else {
             $this->keyStatus = 0;
             $this->keyError = $this->parseKeyError($response->code, 'code');
         }
     } catch (\Pheal\Exceptions\PhealException $e) {
         $this->keyError = $this->parseKeyError($e, 'exception');
         $this->keyStatus = 0;
         setAlert('danger', 'API Key Error', $e->getMessage());
     }
 }
function checkAPIPheal($apikey, $vcode, $char)
{
    try {
        $phealAPI = new Pheal($apikey, $vcode, "account");
        $response = $phealAPI->APIKeyInfo();
        //add parameters
        $accessMask = $response->key->accessMask;
        $expiry = $response->key->expires;
        $apichars = array();
        foreach ($response->key->characters as $row2) {
            $char_api = $row2->characterID;
            array_push($apichars, $char_api);
        }
        if ($accessMask == "" && $response) {
            return -4;
            //api key does not exist
        } else {
            if ($accessMask != '82317323' && $accessMask != '1073741823' && $response) {
                return -3;
                //api key has invalid permissions
            } else {
                if (!in_array($char, $apichars) && $response) {
                    return -2;
                    //character does not belong to API key
                } else {
                    if (!isset($expiry) && $response) {
                        return -1;
                        //key has expired
                    } else {
                        return 1;
                        //everything is ok
                    }
                }
            }
        }
    } catch (\Pheal\Exceptions\PhealException $e) {
        echo sprintf("an exception was caught! Type: %s Message: %s", get_class($e), $e->getMessage());
    }
}
Example #4
0
     $check_char_belong_session = mysqli_query($con, "SELECT * FROM V_user_characters WHERE username = '******' AND character_eve_idcharacter = '{$character_get}' ORDER BY character_eve_idcharacter") or die(mysqli_error($con));
     if (mysqli_num_rows($check_char_belong_session) == 0) {
         echo "Invalid character ID";
     }
 } else {
     echo "<table class='table table-striped table-bordered table-hover' id='dataTables-example'>";
     echo "<tr><th></th>" . "<th>Name</th>" . "<th align = 'right'>ISK Balance</td>" . "<th align = 'right'>Assets Value</th>" . "<th align = 'right'>Escrow</th>" . "<th align = 'right'>Sell Orders</th></tr>";
     //if an API is not found or has invalid permissions we delete that api and any corresponding characters from the DB
     $apilist_user = mysqli_query($con, "SELECT api.apikey, api.vcode, characters.eve_idcharacter FROM api\n                join characters on characters.api_apikey = api.apikey\n                join aggr on aggr.character_eve_idcharacter = characters.eve_idcharacter\n                join user on aggr.user_iduser = user.iduser\n                where user.username = '******'");
     $idActiveuser = utils::mysqli_result(mysqli_query($con, "SELECT iduser FROM user WHERE username = '******'"), 0, 0);
     while ($apis = mysqli_fetch_array($apilist_user)) {
         $apikey2 = $apis['apikey'];
         $vcode2 = $apis['vcode'];
         $char2 = $apis['eve_idcharacter'];
         $phealAPI = new Pheal($apikey2, $vcode2, "account");
         $response = $phealAPI->APIKeyInfo();
         //add parameters
         // If curl_exec() fails/throws an error, the function will return false
         if (!isset($response) || $response == "") {
             // Could add some 404 headers here
             echo "Error getting API Key Info. Eve's API Server might be offline. Try refreshing this page.";
             exit;
         } else {
             $accessMask = $response->key->accessMask;
             $charName = utils::mysqli_result(mysqli_query($con, "SELECT name FROM characters WHERE eve_idcharacter = {$char2} "), 0, 0);
             if ($accessMask != '82317323' && $accessMask != '1073741823' && $accessMask != "") {
                 //invalid access mask or API not found. Delete API from account:
                 //$delete_char_account = mysqli_query($con, "DELETE FROM aggr WHERE user_iduser = '******' AND character_eve_idcharacter = '$char2'");
                 //$remove_character = mysqli_query($con, "DELETE FROM characters WHERE eve_idcharacter = '$char2'") or die(mysqli_error($con));
                 //$delete_api = mysqli_query($con, "DELETE FROM api WHERE apikey = '$apikey2' and vcode = '$vcode2'")
                 //    or die(mysqli_error($con));