public function execute($parameters, $db) { var_dump($db); $commands = array(); $dir = __DIR__; if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != "base.php" && $entry != "cli_methods.php") { $s1 = explode("cli_", $entry); $s2 = explode(".php", $s1[1]); if (sizeof($s2) == 2) { require_once "{$dir}/{$entry}"; $command = $s2[0]; $className = "cli_{$command}"; $class = new $className(); if (is_a($class, "cliCommand")) { $commands[] = $command; } } } } closedir($handle); } sort($commands); CLI::out("|g|Commands available: |n|" . implode(", ", $commands)); }
public function execute($parameters, $db) { global $base; chdir($base); if (sizeof($parameters) == 0 || $parameters[0] == "") { CLI::out("Usage: |g|help <command>|n| To see a list of commands, use: |g|list", true); } $command = $parameters[0]; switch ($command) { case "all": // Cleanup old sessions $db->execute("delete from zz_users_sessions where validTill < now()"); $killsLastHour = $db->queryField("select count(*) count from zz_killmails where insertTime > date_sub(now(), interval 1 hour)", "count"); Storage::store("KillsLastHour", $killsLastHour); $db->execute("delete from zz_analytics where dttm < date_sub(now(), interval 24 hour)"); $fc = new FileCache("{$base}/cache/queryCache/"); $fc->cleanUp(); break; case "killsLastHour": $killsLastHour = $db->queryField("select count(*) count from zz_killmails where insertTime > date_sub(now(), interval 1 hour)", "count"); Storage::store("KillsLastHour", $killsLastHour); break; case "fileCacheClean": $fc = new FileCache(); $fc->cleanUp(); break; } }
public function execute($parameters, $db) { // Fix unknown group ID's $result = $db->query("select distinct killID from zz_participants where groupID != vGroupID and isVictim = 1 limit 1", array(), 0); foreach ($result as $row) { $killID = $row["killID"]; $shipTypeID = $db->queryField("select shipTypeID from zz_participants where killID = {$killID} and isVictim = 1", "shipTypeID"); if ($shipTypeID == 0) { continue; } $groupID = Info::getGroupID($shipTypeID); echo "Updating {$killID} to {$groupID}\n"; $db->execute("update zz_participants set vGroupID = {$groupID} where killID = {$killID}"); } CLI::out(sizeof($result) . " done!", true); }
public function execute($parameters, $db) { if (sizeof($parameters) == 0 || $parameters[0] == "") { CLI::out("Usage: |g|recentStatsAndRanks <type>|n| To see a list of commands, use: |g|methods calculateAllTimeStatsAndRanks", true); } $command = $parameters[0]; switch ($command) { case "all": self::stats($db); self::ranks($db); break; case "ranks": self::ranks($db); break; case "stats": self::stats($db); break; } }
public function execute($parameters, $db) { if (sizeof($parameters) == 0 || $parameters[0] == "") { CLI::out("Usage: |g|help <command>|n| To see a list of commands, use: |g|list", true); } $command = $parameters[0]; $base = __DIR__; $fileName = "{$base}/cli_{$command}.php"; if (!file_exists($fileName)) { CLI::out("|r|Error running {$command}|n|. Please use list to show all commands, or help <command> to see information on how to use the command", true); } require_once $fileName; $className = "cli_{$command}"; $class = new $className(); if (!is_a($class, "cliCommand")) { CLI::out("|r| Module {$command} does not implement interface cliCommand", true); } $descr = $class->getDescription(); CLI::out("|g|{$command}:|n| {$descr}"); }
/** * Creates a json file of ships to be used on the star map page * @return [type] [description] */ public function generateShipDataFile($db) { CLI::out('|g|Loading ships|n|'); //get a list of all the published ships $ships_results = $db->query('SELECT ccp_invTypes.typeID, typeName, groupName, COALESCE(valueInt, valueFloat) AS metaLevel FROM ccp_invTypes INNER JOIN ccp_invGroups ON ccp_invGroups.groupID = ccp_invTypes.groupID INNER JOIN ccp_dgmTypeAttributes ON ccp_dgmTypeAttributes.typeID = ccp_invTypes.typeID AND ccp_dgmTypeAttributes.attributeID = 633 WHERE (categoryID IN (6, 23, 40) AND ccp_invTypes.published = 1 AND ccp_invGroups.published = 1 OR ccp_invTypes.groupID = 29)'); $ships = array(); foreach ($ships_results as $ship) { $ships[$ship['typeID']] = array('name' => $ship['typeName'], 'group' => strtolower(str_replace(' ', '-', $ship['groupName'])), 'meta' => $this->meta_names[$ship['metaLevel']]); } //create the new file asset $this->writeStaticData('starmap-ships', $ships); }
public function execute($parameters, $db) { if (Util::isMaintenanceMode()) { return; } @($apiRowID = $parameters[0]); $notRecentKillID = Storage::retrieve("notRecentKillID", 0); $apiRow = $db->queryRow("select * from zz_api_characters where apiRowID = :id", array(":id" => $apiRowID), 0); $maxKillID = $apiRow["maxKillID"]; $beforeKillID = 0; if (!$apiRow) { CLI::out("|r|No such apiRowID: {$apiRowID}", true); } $keyID = trim($apiRow["keyID"]); $vCode = $db->queryField("select vCode from zz_api where keyID = :keyID", "vCode", array(":keyID" => $keyID)); $isDirector = $apiRow["isDirector"]; $charID = $apiRow["characterID"]; if ($keyID == "" || $vCode == "") { die("no keyID or vCode"); } $pheal = null; try { do { $pheal = Util::getPheal($keyID, $vCode); $charCorp = $isDirector == "T" ? 'corp' : 'char'; $pheal->scope = $charCorp; $result = null; // Update last checked $db->execute("update zz_api_characters set errorCode = 0, lastChecked = now() where apiRowID = :id", array(":id" => $apiRowID)); $params = array(); if ($isDirector != "T") { $params['characterID'] = $charID; } if ($beforeKillID > 0) { $params['beforeKillID'] = $beforeKillID; } if ($isDirector == "T") { $result = $pheal->KillMails($params); } else { $result = $pheal->KillMails($params); } $cachedUntil = $result->cached_until; if ($cachedUntil == "" || !$cachedUntil) { $cachedUntil = date("Y-m-d H:i:s", time() + 3600); } $db->execute("UPDATE zz_api_characters SET cachedUntil = :cachedUntil, errorCount = 0, errorCode = 0 WHERE apiRowID = :id", array(":id" => $apiRowID, ":cachedUntil" => $cachedUntil)); $keyID = trim($keyID); $file = "/var/killboard/zkb_killlogs/{$keyID}_{$charID}_{$beforeKillID}.xml"; @unlink($file); $aff = Api::processRawApi($keyID, $charID, $result); if ($aff > 0) { $keyID = "{$keyID}"; while (strlen($keyID) < 8) { $keyID = " " . $keyID; } Log::log("KeyID: {$keyID} ({$charCorp}) added {$aff} kill" . ($aff == 1 ? "" : "s")); } $beforeKillID = 0; foreach ($result->kills as $kill) { $killID = $kill->killID; if ($beforeKillID == 0) { $beforeKillID = $killID; } else { $beforeKillID = min($beforeKillID, $killID); } } if ($beforeKillID < $notRecentKillID) { $db->execute("update zz_api_characters set cachedUntil = date_add(cachedUntil, interval 2 hour) where apiRowID = :id", array(":id" => $apiRowID)); } $hour = date("H"); if ($hour >= 12 && $hour <= 15) { @error_log($pheal->xml, 3, $file); } else { if ($aff > 0) { @error_log($pheal->xml, 3, $file); } } } while ($aff > 25 || $beforeKillID > 0 && $maxKillID == 0); } catch (Exception $ex) { $errorCode = $ex->getCode(); $db->execute("update zz_api_characters set cachedUntil = date_add(now(), interval 1 hour), errorCount = errorCount + 1, errorCode = :code where apiRowID = :id", array(":id" => $apiRowID, ":code" => $errorCode)); switch ($errorCode) { case 119: case 120: // Don't log it break; case 201: // Character does not belong to account. // Character does not belong to account. case 222: // API has expired // API has expired case 221: // Invalid access, delete the toon from the char list until later re-verification // Invalid access, delete the toon from the char list until later re-verification case 220: // Invalid Corporation Key. Key owner does not fullfill role requirements anymore. // Invalid Corporation Key. Key owner does not fullfill role requirements anymore. case 403: // New error code for invalid API $db->execute("delete from zz_api_characters where apiRowID = :id", array(":id" => $apiRowID)); break; case 1001: $db->execute("update zz_api_characters set cachedUntil = date_add(now(), interval 10 minute) where apiRowID = :id", array(":id" => $apiRowID)); break; default: Log::log($keyID . " " . $ex->getCode() . " " . $ex->getMessage()); } return; } }
private static function stats($db) { CLI::out("|g|Stats calculation started"); $db->execute("set session wait_timeout = 600"); // Fix unknown group ID's echo "Updating groups...\n"; $result = $db->query("select distinct shipTypeID from zz_participants where groupID = 0 and shipTypeID != 0"); foreach ($result as $row) { $shipTypeID = $row["shipTypeID"]; $groupID = Info::getGroupID($shipTypeID); if ($groupID == null) { $groupID = 0; } if ($groupID == 0) { continue; } echo "Updating {$shipTypeID} to {$groupID}\n"; $db->execute("update zz_participants set groupID = {$groupID} where groupID = 0 and shipTypeID = {$shipTypeID}"); } echo "Finished updating groups...\n"; $db->execute("create table if not exists zz_stats_recent like zz_stats"); $db->execute("truncate zz_stats_recent"); try { self::recalc('faction', 'factionID', true, $db); self::recalc('alli', 'allianceID', true, $db); self::recalc('corp', 'corporationID', true, $db); self::recalc('pilot', 'characterID', true, $db); self::recalc('group', 'groupID', true, $db); self::recalc('ship', 'shipTypeID', true, $db); self::recalc('system', 'solarSystemID', false, $db); self::recalc('region', 'regionID', false, $db); } catch (Exception $e) { print_r($e); } }
public function execute($parameters, $db) { CLI::out("Priming the cache"); Primer::cachePrimer(); }
public function execute($parameters, $db) { if (Util::isMaintenanceMode()) { return; } $totalCount = 0; $data = ""; // Build the feeds from Admin's tracker list $adminID = Db::queryField("select id from zz_users where username = '******'", "id", array()); $trackers = Db::query("select locker, content from zz_users_config where locker like 'tracker_%' and id = :id", array(":id" => $adminID), 0); $feeds = array(); foreach ($trackers as $row) { $entityType = str_replace("tracker_", "", $row["locker"]); $entities = json_decode($row["content"], true); foreach ($entities as $entity) { $id = (int) $entity["id"]; $feed = array(); $feed["id"] = $id; $feed["entityType"] = $entityType; $locker = "feed.{$entityType}.{$id}.lastFetchTime"; $dontFetchThis = $db->queryField("select count(*) count from zz_users_config where locker = :locker and id = :adminID and content >= date_sub(now(), interval 1 hour)", "count", array(":locker" => $locker, ":adminID" => $adminID), 0); if ($dontFetchThis) { continue; } $locker = "feed.{$entityType}.{$id}.lastKillTime"; $lastKillTime = $db->queryField("select content from zz_users_config where locker = :locker and id = :adminID", "content", array(":locker" => $locker, ":adminID" => $adminID), 0); if ($lastKillTime == "") { $lastKillTime = null; } $feed["lastKillTime"] = $lastKillTime; $feed["url"] = "https://zkillboard.com/api/{$entityType}ID/{$id}/"; $feeds[] = $feed; } } if (sizeof($feeds) == 0) { return; } // Nothing to fetch... foreach ($feeds as $feed) { $id = $feed["id"]; $baseurl = $feed["url"]; $entityType = $feed["entityType"]; CLI::out("Fetching for |g|{$baseurl}|n|"); $lastKillTime = $feed["lastKillTime"]; do { $insertCount = 0; $url = "{$baseurl}orderDirection/asc/"; if ($lastKillTime != null && $lastKillTime != 0) { $url .= "startTime/" . preg_replace('/[^0-9]/', '', $lastKillTime) . "/"; } CLI::out($url); $fetchedData = self::fetchUrl($url); if ($fetchedData == "") { CLI::out("|r|Remote server returned an invalid response, moving along after 15 seconds...|n|"); sleep(15); continue; } $data = json_decode($fetchedData); $insertCount = 0; foreach ($data as $kill) { if (isset($kill->_stringValue)) { unset($kill->_stringValue); } if ($kill == "") { continue; } $hash = Util::getKillHash(null, $kill); $json = json_encode($kill); $killID = $kill->killID; $source = "zKB Feed Fetch"; $lastKillTime = $kill->killTime; //echo "$killID $lastKillTime\n"; $insertCount += $db->execute("INSERT IGNORE INTO zz_killmails (killID, hash, source, kill_json) VALUES (:killID, :hash, :source, :kill_json)", array(":killID" => $killID, ":hash" => $hash, ":source" => $source, ":kill_json" => $json)); } $locker = "feed.{$entityType}.{$id}.lastKillTime"; $db->execute("replace into zz_users_config values (:adminID, :locker, :content)", array(":adminID" => $adminID, ":locker" => $locker, ":content" => $lastKillTime)); $locker = "feed.{$entityType}.{$id}.lastFetchTime"; $db->execute("replace into zz_users_config values (:adminID, :locker, now())", array(":adminID" => $adminID, ":locker" => $locker)); $totalCount += $insertCount; CLI::out("Inserted |g|{$insertCount}|n|/|g|" . sizeof($data) . "|n| kills..."); Log::log("Inserted {$insertCount} new kills from {$url}"); } while ($insertCount > 0 || sizeof($data) >= 50); } if ($totalCount > 0) { CLI::out("Inserted a total of |g|" . number_format($totalCount, 0) . "|n| kills."); } }
public function execute($parameters, $db) { if (sizeof($parameters) == 0 || $parameters[0] == "") { CLI::out("Usage: |g|help <command>|n| To see a list of commands, use: |g|list", true); } $command = $parameters[0]; switch ($command) { case "add": if (isset($parameters[1])) { $url = $parameters[1]; } else { $validTypes = array("pilot", "corp", "alliance"); CLI::out("|g|You are now adding a feed with the quick feed creator(TM), if you already have a feed you want to add, use add <feed> instead.|n|"); retryekid: $ekid = CLI::prompt("Do you have the EVE-KILL ID for the entity you want to add?", "yes"); if ($ekid != "yes" && $ekid != "no") { CLI::out("|r|Error, call type is not supported. Please retry|n|"); goto retryekid; } if ($ekid == "no") { $validTypes = array("pilotname", "corpname", "alliancename"); } retryCall: CLI::out("|g|Valid calls:|n| " . implode(", ", $validTypes)); $type = CLI::prompt("Type of call. |g|(Refer to the above list)|n|"); if (!in_array($type, $validTypes)) { CLI::out("|r|Error, call type is not supported. Please retry|n|"); goto retryCall; } if ($ekid == "yes") { $nameID = CLI::prompt("ID of entity you wish to add"); } else { $nameID = urlencode(CLI::prompt("Name of the entity you with to add")); } retryApi: $all = CLI::prompt("All Kills?", "yes"); if ($all != "yes" && $all != "no") { CLI::out("|r|Error, call type is not supported. Please retry|n|"); goto retryApi; } $apiOnly = null; if ($all == "yes") { $apiOnly = "&allkills"; } $domain = CLI::prompt("Enter URL of the killboard you're fetching from. |g|Ex. eve-kill.net|n|", "eve-kill.net"); $url = "http://{$domain}/?a=idfeed&{$type}={$nameID}{$apiOnly}"; } if (filter_var($url, FILTER_VALIDATE_URL)) { $db->execute("INSERT INTO zz_feeds (url, edkStyle) VALUES (:url, 1)", array(":url" => $url)); CLI::out("Now inserting |g|{$url}|n| to the database.", true); } else { CLI::out("|r|Invalid URL, please try again|n|", true); } break; case "remove": $id = NULL; if (isset($parameters[1])) { $id = $parameters[1]; } if (is_null($id)) { CLI::out("Please refer to feed list to show all the feeds you have added to your board. To remove one, use: |g|feed remove <id>|n|"); } elseif (!is_numeric($id)) { CLI::out("|r|ID needs to be an int..|n|"); } else { $url = $db->queryField("SELECT url FROM zz_feeds WHERE id = :id AND edkStyle = 1", "url", array(":id" => $id)); if (is_null($url)) { CLI::out("|r|Feed is already removed.", true); } CLI::out("Removing feed: |g|{$url}"); $db->execute("DELETE FROM zz_feeds WHERE id = :id", array(":id" => $id)); } break; case "list": $list = $db->query("SELECT * FROM zz_feeds WHERE edkStyle = 1"); foreach ($list as $url) { CLI::out($url["id"] . "::|g|" . $url["url"]); } break; case "fetch": CLI::out("|g|Initiating feed fetching|n|"); $doSleep = false; $size = 1; $count = 1; $feeds = $db->query("SELECT id, url, lastFetchTime FROM zz_feeds WHERE edkStyle IS true", array(), 0); if (sizeof($feeds) > 1) { $doSleep = true; $size = sizeof($feeds); } foreach ($feeds as $feed) { $url = $feed["url"]; $lastFetchTime = strtotime($feed["lastFetchTime"]) + 600; $currentTime = time(); $insertCount = 0; if ($lastFetchTime <= $currentTime) { CLI::out("Fetching from |g|{$url}|n|"); try { $data = self::fetchUrl($url); $xml = new SimpleXMLElement($data, null, false, "", false); $result = new \Pheal\Core\Result($xml); $insertCount = self::processAPI($result, $db); $db->execute("UPDATE zz_feeds SET lastFetchTime = :time WHERE url = :url", array(":time" => date("Y-m-d H:i:s"), ":url" => $url)); if ($insertCount > 0) { CLI::out("Inserted |g|{$insertCount}|n| new kills from |g|{$url}|n|"); Log::log("Inserted {$insertCount} new kills from {$url}"); } else { CLI::out("No new kills from |r|{$url}|n|"); } } catch (Exception $ex) { CLI::out("|r|Error with {$url}: " . $ex->getMessage()); } if ($doSleep && $size != $count) { CLI::out("|g|Sleeping for 10 seconds|n| before fetching another url.. (Otherwise we're hammering..)"); sleep(10); // yes yes, 10 seconds of sleeping, what?! this is only here to stop hammering. Feel free to hammer tho by commenting this, but you'll just get banned.. } $count++; } } break; } }
function listCommands() { $commands = array(); $dir = __DIR__ . "/cli/"; if ($handle = opendir($dir)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != ".." && $entry != "base.php" && $entry != "cli_methods.php") { $s1 = explode("cli_", $entry); $s2 = explode(".php", @$s1[1]); if (sizeof($s2) == 2) { require_once "{$dir}/{$entry}"; $command = $s2[0]; $className = "cli_{$command}"; $class = new $className(); if (is_a($class, "cliCommand")) { $commands[] = $command; } } } } closedir($handle); } sort($commands); CLI::out(implode(" ", $commands), true); }