function add_api_key($link, $uid, $keyID, $vCode, $name, $notes = "")
{
    $apikey = make_short_key($link, $keyID, $vCode, $uid);
    $ID = check_saved_key($link, $apikey, $uid);
    if ($ID) {
        return $ID . "<321>Api Code Already added";
    }
    if (!$name) {
        $name = "No Name Set";
    }
    $name = mysql_real_escape_string($name, $link);
    $keyInfo = cache_api_retrieve($link, "/account/APIKeyInfo.xml.aspx", array("keyID" => $keyID, "vCode" => $vCode), 5 * 60)->value;
    echo $keyInfo->error;
    if ($keyInfo->error) {
        if ($keyInfo->error == 222) {
            return "0<321>Api Key expired";
        } else {
            if ($keyInfo->error == 203) {
                return "0<321>Api vCode or Id Incorrect";
            } else {
                return "0<321>Unable to load API. Verify the key is correct and not expired.";
            }
        }
        return false;
    }
    $type = (string) $keyInfo->result->key["type"];
    $notes = mysql_real_escape_string($notes, $link);
    foreach ($keyInfo->result->key->rowset->row as $char) {
        if (isset($char["characterName"])) {
            if (isset($characters)) {
                $characters .= "<br/>" . $char["characterName"] . "," . $char["characterId"];
            } else {
                $characters = $char["characterName"] . "," . $char["characterId"];
            }
        }
    }
    $keyID = mysql_real_escape_string($apikey, $link);
    $sql = "INSERT INTO " . DB_PREFIX . "keyInformation (apiKey,userID,keyName,characters,type,notes) VALUES ('{$keyID}','{$uid}','{$name}','{$characters}','{$type}','{$notes}')";
    $result = mysql_query($sql, $link);
    if (!$result) {
        echo "QUERY: '{$sql}'\n\n" . mysql_error() . "\n\nBacktrace:\n";
        debug_print_backtrace();
        exit;
    }
    if (mysql_affected_rows($link)) {
        return mysql_insert_id($link) . "<321>Api Key successfully added";
    }
}
function add_api_key($Db, $uid, $keyID, $vCode, $name, $notes = "")
{
    $apikey = make_short_key($Db, $keyID, $vCode, $uid);
    $ID = check_saved_key($apikey, $uid);
    if ($ID) {
        return ["result" => "failure", "id" => $ID, "response" => "Api Code Already added"];
    }
    if (!$name) {
        $name = "No Name Set";
    }
    $keyInfo = cache_api_retrieve($Db, "/account/APIKeyInfo.xml.aspx", array("keyID" => $keyID, "vCode" => $vCode), 5 * 60)->value;
    echo $keyInfo->error;
    if ($keyInfo->error) {
        if ($keyInfo->error == 222) {
            return ["result" => "failure", "response" => "Api Key expired"];
        } else {
            if ($keyInfo->error == 203) {
                return ["result" => "failure", "response" => "Api vCode or Id Incorrect"];
            } else {
                return ["result" => "failure", "response" => "Unable to load API. Verify the key is correct and not expired."];
            }
        }
        return false;
    }
    $type = (string) $keyInfo->result->key["type"];
    foreach ($keyInfo->result->key->rowset->row as $char) {
        if (isset($char["characterName"])) {
            if (isset($characters)) {
                $characters .= "<br/>" . $char["characterName"] . "," . $char["characterId"];
            } else {
                $characters = $char["characterName"] . "," . $char["characterId"];
            }
        }
    }
    $result = $Db->insert("keyInformation", ['apiKey' => $apikey, 'userID' => $uid, 'keyName' => $name, 'characters' => $characters, 'type' => $type, 'notes' => $notes]);
    if (!$result) {
        return false;
    } else {
        return ["id" => $Db->lastid, "response" => "Api Key successfully added"];
    }
}
 public function skills()
 {
     //print_r($dB);
     $sql = getenv('DB_HOST');
     $sql_u = getenv('DB_USERNAME');
     $sql_p = getenv('DB_PASSWORD');
     $db = getenv('DB_DATABASE');
     $Db = new eveApi\eveDb($sql, $sql_u, $sql_p, $db);
     $userid = 4526453;
     $apikey = "REcp21O2Djg2uSfv5ioLLpGuJyeVh4rxrd3sdk8V1TDGRpNSuzXTAk67gsoGh6MJ";
     $chid = 93501378;
     $charSelect = true;
     //$charSelect = false;
     //require_once("login.php");
     $_SESSION['redirect'] = "index.php";
     $cookielogin = false;
     if (isset($_GET['newapi'])) {
         clear_api_cookie();
     }
     // load variables n such - defined here temporary before being set to constants later on
     if (isset($_GET['usid'])) {
         $userid = trim($_GET['usid']);
     }
     if (isset($_GET['apik'])) {
         $apikey = trim($_GET['apik']);
     }
     if (isset($_GET['chid'])) {
         $chid = trim($_GET['chid']);
     }
     if (isset($_GET['key'])) {
         $short_api_key = trim($_GET['key']);
     }
     /*if (!login_load_creds($Db, (isset($userid) && isset($apikey) || isset($short_api_key)))) {
     	// handle cookie stuff
     	if (isset($_COOKIE["api"]) && ($_COOKIE["api"] != "") && !isset($userid) && !isset($short_api_key)) { // if a cookie was present, and we were not passed args via get, try to use what is in the cookie
     		$login = explode(',',$_COOKIE["api"]);
     		$cookielogin = true;
     		if ($login[0] == "api") {
     			$userid = trim($login[1]);
     			$apikey = trim($login[2]);
     			if (count($login) > 3)
     				$chid = trim($login[3]);
     		} else 
     			$short_api_key = trim($login[1]);
     			
     		$_GET['save'] = "1";
     	}
     } else 
     		$_GET['save'] = "1";*/
     if (isset($short_api_key)) {
         // get stored apikey
         $charSelect = false;
         $ret = retrieve_api_key($Db->link, $short_api_key);
         if ($ret != null) {
             $chid = $ret["chid"];
             $userid = $ret["usid"];
             $apikey = $ret["apik"];
         } else {
             unset($short_api_key);
             // invalid key
             $cookielogin = false;
         }
     }
     if (!isset($chid) && isset($_GET['chid'])) {
         $chid = trim($_GET['chid']);
         $charSelect = true;
     }
     define("COOKIE_LOGIN", $cookielogin);
     if ((!isset($apikey) || !isset($userid)) && !isset($short_api_key)) {
         $info = "";
         if (isset($_GET['fittingid'])) {
             $result = mysql_query("SELECT * FROM " . DB_PREFIX . FITTINGS_TABLE . " WHERE keyv=\"" . mysql_real_escape_string($_GET['fittingid']) . "\"", $Db->link);
             if ($result != false && mysql_num_rows($result) > 0) {
                 // yay! got a cached value
                 $row = mysql_fetch_assoc($result);
                 mysql_free_result($result);
                 $info = "Your ability to use the fitting '{$row['name']}' ({$row['ship']}) will be shown after you log in.";
             }
             $Db->close();
         }
         api_input($info);
         // die
     }
     define("USER_ID", $userid);
     define("API_KEY", isset($_GET['oldkey']) && $_GET['oldkey'] == "1" ? "old_{$apikey}" : $apikey);
     $multiplechars = false;
     if (strpos(API_KEY, "old_") === 0) {
         // old api key, must load characters and other horseshit
         $keyinfo = 1;
         $chars = $Db->fetchApiChars(USER_ID, API_KEY);
         if (!$chars) {
             fatal_error("Unable to load API. Verify the key is correct and not expired.");
         }
         $keys = array_keys($chars);
         define("KEY_MASK", isFullApi($Db->link, $keys[0], USER_ID, API_KEY) ? 268435455 : 8);
         $multiplechars = count($chars) > 1;
         if (!$multiplechars) {
             $chid = $keys[0];
         }
         if (isset($chid)) {
             foreach ($chars as $ch_id => $char) {
                 if ($ch_id == $chid) {
                     define("CHAR_NAME", $char["name"]);
                 }
             }
             if (!defined("CHAR_NAME")) {
                 fatal_error("The character ID was not found on this account.");
             }
         }
         define("CORP_MODE", false);
         define("KEY_TYPE", "Account");
     } else {
         // modern fancy ass keys ////////////////////////
         $keyInfo = eveApi\cache_api_retrieve($Db->link, "/account/APIKeyInfo.xml.aspx", array("keyID" => USER_ID, "vCode" => API_KEY), 5 * 60)->value;
         if ($keyInfo->error) {
             fatal_error("Unable to load API. Verify the key is correct and not expired.");
         }
         define("KEY_MASK", (double) $keyInfo->result->key["accessMask"]);
         $multiplechars = count($keyInfo->result->key->rowset->row) > 1;
         if (!$multiplechars) {
             $chid = (string) $keyInfo->result->key->rowset->row[0]["characterID"];
         }
         if (isset($chid)) {
             $char = $keyInfo->api->xpath("//row[@characterID='{$chid}']");
             if (count($char) == 0) {
                 fatal_error("The character ID was not found on this account.");
             }
             define("CHAR_NAME", (string) $char[0]["characterName"]);
         }
         define("KEY_TYPE", (string) $keyInfo->result->key["type"]);
         if (KEY_TYPE == "Corporation") {
             define("CORP_MODE", true);
             define("CORP_ID", (string) $keyInfo->result->key->rowset->row[0]["corporationID"]);
             define("CORP_NAME", (string) $keyInfo->result->key->rowset->row[0]["corporationName"]);
             $multiplechars = false;
         } else {
             define("CORP_MODE", false);
         }
     }
     if (isset($short_api_key) && $charSelect) {
         $urlAuthInfo = "key={$short_api_key}&chid={$chid}";
     } elseif (isset($short_api_key) && !$charSelect) {
         $urlAuthInfo = "key={$short_api_key}";
     } else {
         $urlAuthInfo = (isset($chid) ? "chid={$chid}&" : "") . "usid=" . USER_ID . "&apik=" . API_KEY;
     }
     define("FULL_URL", "?" . $urlAuthInfo . (isset($_GET['save']) && $_GET['save'] == "1" ? "&save=1" : ""));
     /* . ((!isset($_GET['view']) && isset($_GET['fittingid'])) ? "&fittingid=$_GET[fittingid]" : "")*/
     if ($multiplechars && !isset($chid)) {
         // must resolve a character id
         if (!isset($chars)) {
             $chars = $Db->fetchApiChars(USER_ID, API_KEY);
         }
         character_select($Db, $chars);
     }
     define("CHAR_ID", $chid);
     define("USER_NAME", CORP_MODE ? CORP_NAME : CHAR_NAME);
     // set to corp name or char name depending on key type
     if (!CORP_MODE && isset($_GET['save']) && $_GET['save'] == "1") {
         // save api key into a cookie if present
         if (isset($short_api_key)) {
             $auth = "key,{$short_api_key}";
         } else {
             $auth = "api," . USER_ID . "," . API_KEY . "," . CHAR_ID;
         }
         setcookie("api", $auth, time() + 60 * 60 * 24 * 30);
     }
     // load pages into registered_pages (all pages),eligible_pages (supported by key type),enabled_pages
     require_once "audit.pages.php";
     if (isset($_GET['makeshorturl'])) {
         $key = make_short_key($Db->link, USER_ID, API_KEY, CHAR_NAME, CHAR_ID);
         if ($key) {
             header("Location: " . SELF_URL . "key={$key}" . (isset($_GET['view']) ? "&view=" . $_GET['view'] : ""));
             die("<html><body><a href=\"" . SELF_URL . "key={$key}" . (isset($_GET['view']) ? "&view=" . $_GET['view'] : "") . "\">Click here to continue.</a><body></html>");
         } else {
             fatal_error("Unable to create key.", "Please try again later.", true);
         }
     }
     $infobar = "<span class=\"infobar\">&lt;&nbsp;";
     $getpage = "none";
     if (isset($_GET['view'])) {
         $getpage = trim($_GET['view']);
         if (!isset($eligible_pages[$getpage])) {
             $getpage = "none";
         }
     }
     foreach ($eligible_pages as $name => $page) {
         if (isset($enabled_pages[$name])) {
             if ($getpage == "none") {
                 $getpage = $name;
             }
             if ($name != $getpage) {
                 $infobar .= "<a href=\"" . FULL_URL . "&view={$name}\">{$name}</a>";
             } else {
                 $infobar .= "<span class=\"current_page\">{$name}</span>";
             }
         } else {
             $infobar .= "<span class=\"disabled_page\">{$name}</span>";
         }
         $infobar .= "&nbsp;";
     }
     if ($getpage == "none") {
         fatal_error("This API has no pages that the Jackknife can display.");
     }
     define("PAGE_VIEW", $getpage);
     $infobar .= "|&nbsp;";
     $infobar .= "<a href=\"" . SELF_URL . "newapi\">new api</a>&nbsp;";
     if ($multiplechars && $charSelect) {
         if (isset($short_api_key)) {
             $infobar .= "<a href=\"" . SELF_URL . "key={$short_api_key}\">char select</a>&nbsp;";
         } else {
             $infobar .= "<a href=\"" . SELF_URL . "usid=" . USER_ID . "&apik=" . API_KEY . (isset($_GET['save']) && $_GET['save'] == "1" ? "&save=1" : "") . "\">char select</a>&nbsp;";
         }
     }
     if (!isset($short_api_key)) {
         $infobar .= "<a href=\"" . FULL_URL . "&makeshorturl&view=" . PAGE_VIEW . "\">short url</a>&nbsp;";
     }
     //$infobar.="|&nbsp;".get_loginbar().get_api_bar();
     $infobar .= "&gt;&nbsp;<b>" . strtoupper(KEY_TYPE);
     $infobar .= "</b></span>";
     //$infobar .=get_form_divs();
     //////// FINAL OUTPUT
     if (PAGE_VIEW == "onepage") {
         insert_header("Ataglance for " . USER_NAME);
         echo $infobar . "<br>";
         $next = 1;
         $time_start2 = microtime_float();
         foreach ($enabled_pages as $name => $page) {
             if ($page == "onepage") {
                 continue;
             }
             $error = !$page->GetOutput($Db);
             if ($error) {
                 //fatal_error("API: " . $page->Output);
             } else {
                 echo "<br>";
                 echo "<a name=\"s" . ($next - 1) . "\"></a>";
                 echo "<span style=\"font-size: 70%\"><a href=\"#s{$next}\">skip to next section</a></span><br>";
                 $next++;
                 echo "<h2>" . ucfirst($name) . "</h2>";
                 if ($page->Header != "") {
                     echo $page->Header . "<br>";
                 }
                 echo $page->Output . "<hr>";
             }
         }
         echo "<a name=\"s" . ($next - 1) . "\"></a>";
         $time_end2 = microtime_float();
         $time_exec = $time_end2 - $time_start2;
         echo "<br><span style=\"font-size:80%;\"><a href=\"#top\">top</a></span><br>\n";
         echo "<span style=\"font-size:80%;\">";
         if ($Db->queries != 0) {
             echo "\n" . $Db->queries . " queries<br>";
         }
         echo "exec time: {$time_exec} s<br>";
         echo "</span>";
         echo "</body></html>";
     } else {
         $page = $eligible_pages[PAGE_VIEW];
         $error = "";
         print_r($page->GetOutput($Db));
         exit;
         $error = !$page->GetOutput($Db);
         echo $infobar . "<br>";
         if ($error) {
             fatal_error("API: " . $page->Output, "", true);
         } else {
             $page->SetHeaders();
             insert_header($page->Title);
             if ($page->Updated) {
                 echo "<span class=\"updated_text\">" . $page->Updated . "</span><br>";
             }
             if ($page->Header != "") {
                 echo $page->Header . "<br>";
             } else {
                 echo "<span style=\"font-size:450%\">" . USER_NAME . "</span><br>";
             }
             echo $page->Output . "<br>";
             echo $page->Times . "<br>";
             echo "</body></html>";
         }
     }
     //print_r($chars);
     echo "FInal";
 }
Example #4
0
define("CHAR_ID", $chid);
define("USER_NAME", CORP_MODE ? CORP_NAME : CHAR_NAME);
// set to corp name or char name depending on key type
if (!CORP_MODE && isset($_GET['save']) && $_GET['save'] == "1") {
    // save api key into a cookie if present
    if (isset($short_api_key)) {
        $auth = "key,{$short_api_key}";
    } else {
        $auth = "api," . USER_ID . "," . API_KEY . "," . CHAR_ID;
    }
    setcookie("api", $auth, time() + 60 * 60 * 24 * 30);
}
// load pages into registered_pages (all pages),eligible_pages (supported by key type),enabled_pages
require_once "audit.pages.php";
if (isset($_GET['makeshorturl'])) {
    $key = make_short_key($Db, USER_ID, API_KEY, CHAR_NAME, CHAR_ID);
    if ($key) {
        header("Location: " . SELF_URL . "key={$key}" . (isset($_GET['view']) ? "&view=" . $_GET['view'] : ""));
        die("<html><body><a href=\"" . SELF_URL . "key={$key}" . (isset($_GET['view']) ? "&view=" . $_GET['view'] : "") . "\">Click here to continue.</a><body></html>");
    } else {
        fatal_error("Unable to create key.", "Please try again later.", true);
    }
}
$infobar = "<span id='infobar' class=\"infobar\">&lt;&nbsp;";
$getpage = "none";
if (isset($_GET['view'])) {
    $getpage = trim($_GET['view']);
    if (!isset($eligible_pages[$getpage])) {
        $getpage = "none";
    }
}