Example #1
0
 public static function findConversations()
 {
     $locker = "Social:lastSocialTime";
     $lastSocialTime = Storage::retrieve($locker, null);
     if ($lastSocialTime == null) {
         $result = Db::query("select killID, insertTime from zz_killmails where killID > 0 and processed = 1 and insertTime >= date_sub(now(), interval 10 minute)", array(), 0);
     } else {
         $result = Db::query("select killID, insertTime from zz_killmails where killID > 0 and processed = 1 and insertTime >= :last", array(":last" => $lastSocialTime), 0);
     }
     foreach ($result as $row) {
         $lastSocialTime = $row["insertTime"];
         self::beSocial($row["killID"]);
     }
     Storage::store($locker, $lastSocialTime);
 }
 public function getGlobals()
 {
     global $showAds;
     $result = array();
     if (isset($_SESSION["loggedin"])) {
         $u = User::getUserInfo();
         $config = UserConfig::getAll();
         foreach ($config as $key => $val) {
             $this->addGlobal($result, $key, $val);
         }
         $this->addGlobal($result, "sessionusername", $u["username"]);
         $this->addGlobal($result, "sessionuserid", $u["id"]);
         $this->addGlobal($result, "sessionadmin", (bool) $u["admin"]);
         $this->addGlobal($result, "sessionmoderator", (bool) $u["moderator"]);
     }
     $this->addGlobal($result, "killsLastHour", Storage::retrieve("KillsLastHour", 0));
     $this->addGlobal($result, "showAds", $showAds);
     return $result;
 }
Example #3
0
 private static function apiPercentage($db)
 {
     $percentage = Storage::retrieve("LastHourPercentage", 10);
     $row = $db->queryRow("select sum(if(errorCode = 0, 1, 0)) good, sum(if(errorCode != 0, 1, 0)) bad from zz_api_characters");
     $good = $row["good"];
     $bad = $row["bad"];
     if ($bad > ($bad + $good) * ($percentage / 100)) {
         if ($percentage > 15) {
             Log::irc("|r|API gone haywire?  Over {$percentage}% of API's reporting an error atm.");
         }
         $percentage += 5;
     } else {
         if ($bad < ($bad + $good) * (($percentage - 5) / 100)) {
             $percentage -= 5;
         }
     }
     if ($percentage < 10) {
         $percentage = 10;
     }
     Storage::store("LastHourPercentage", $percentage);
 }
 public function execute($parameters, $db)
 {
     global $stompServer, $stompUser, $stompPassword;
     // Ensure the class exists
     if (!class_exists("Stomp")) {
         die("ERROR! Stomp not installed!  Check the README to learn how to install Stomp...\n");
     }
     $stomp = new Stomp($stompServer, $stompUser, $stompPassword);
     $stompKey = "StompSend::lastFetch";
     $lastFetch = date("Y-m-d H:i:s", time() - 12 * 3600);
     $lastFetch = Storage::retrieve($stompKey, $lastFetch);
     $stompCount = 0;
     $timer = new Timer();
     while ($timer->stop() < 60000) {
         if (Util::isMaintenanceMode()) {
             return;
         }
         $result = $db->query("SELECT killID, insertTime, kill_json FROM zz_killmails WHERE insertTime > :lastFetch AND processed > 0 ORDER BY killID limit 1000", array(":lastFetch" => $lastFetch), 0);
         foreach ($result as $kill) {
             $lastFetch = max($lastFetch, $kill["insertTime"]);
             if (!empty($kill["kill_json"])) {
                 if ($kill["killID"] > 0) {
                     $stompCount++;
                     $destinations = self::getDestinations($kill["kill_json"]);
                     foreach ($destinations as $destination) {
                         $stomp->send($destination, $kill["kill_json"]);
                     }
                 }
                 $data = json_decode($kill["kill_json"], true);
                 $json = json_encode(array("solarSystemID" => $data["solarSystemID"], "killID" => $data["killID"], "characterID" => $data["victim"]["characterID"], "corporationID" => $data["victim"]["corporationID"], "allianceID" => $data["victim"]["allianceID"], "shipTypeID" => $data["victim"]["shipTypeID"], "killTime" => $data["killTime"]));
                 $stomp->send("/topic/starmap.systems.active", $json);
             }
         }
         Storage::store($stompKey, $lastFetch);
         sleep(5);
     }
     if ($stompCount > 0) {
         Log::log("Stomped {$stompCount} killmails");
     }
 }
Example #5
0
function runCron($command, $interval, $args)
{
    global $base;
    $curTime = time();
    if (is_array($args)) {
        array_unshift($args, $command);
    } else {
        if ($args != "") {
            $args = explode(" ", "{$command} {$args}");
        } else {
            $args = array($command);
        }
    }
    $cronName = implode(".", $args);
    $locker = "lastCronRun.{$cronName}";
    $lastRun = (int) Storage::retrieve($locker, 0);
    $dateFormat = "D M j G:i:s T Y";
    if ($curTime - $lastRun < $interval) {
        // No need to say we're not running...
        return;
    }
    Log::log("Cron {$cronName} running at " . date($dateFormat, $curTime));
    Storage::store($locker, $curTime);
    $pid = pcntl_fork();
    if ($pid < 0) {
        Storage::store($locker, $lastRun);
        return;
    }
    if ($pid != 0) {
        return;
    }
    putenv("SILENT_CLI=1");
    pcntl_exec("{$base}/cliLock.sh", $args);
    Storage::store($locker, $lastRun);
    die("Executing {$command} failed!");
}
Example #6
0
        if (strpos($key, 'Name') !== false) {
            $pageTitle[] = $value;
        }
    }
    $pageTitle = implode(',', $pageTitle);
    $pageType = 'subdomain';
} else {
    $topPoints = array();
    $topIsk = Stats::getTopIsk(array('cacheTime' => 15 * 60, 'pastSeconds' => 7 * 86400, 'limit' => 5));
    $topPods = array();
    $top = array();
    $top[] = json_decode(Storage::retrieve('TopChars', [], 900), true);
    $top[] = json_decode(Storage::retrieve('TopCorps', [], 900), true);
    $top[] = json_decode(Storage::retrieve('TopAllis', [], 900), true);
    $top[] = json_decode(Storage::retrieve('TopShips', [], 900), true);
    $top[] = json_decode(Storage::retrieve('TopSystems', [], 900), true);
    // get latest kills
    $kills = Kills::getKills(array('cacheTime' => 60, 'limit' => 50));
    // Collect active PVP stats
    $types = ['characterID', 'corporationID', 'allianceID', 'shipTypeID', 'solarSystemID', 'regionID'];
    $activePvP = [];
    foreach ($types as $type) {
        $result = Stats::getDistinctCount($type, []);
        if ($result <= 1) {
            continue;
        }
        $type = str_replace('ID', '', $type);
        if ($type == 'shipType') {
            $type = 'Ship';
        } elseif ($type == 'solarSystem') {
            $type = 'System';
Example #7
0
 public static function getNotification()
 {
     return Storage::retrieve('notification', null);
 }
Example #8
0
 /**
  * Enters values into the lookup table that are not generally found on the market.
  *
  * @pararm $todaysLookup string Today's lookup value
  */
 protected static function doPopulateRareItemPrices($todaysLookup)
 {
     global $mdb;
     $isDone = (bool) Storage::retrieve($todaysLookup, false);
     if ($isDone) {
         return;
     }
     // Base lookups for today have been populated - do it here to allow later recursion
     Storage::store($todaysLookup, 'true');
     $motherships = $mdb->find('information', ['type' => 'typeID', 'groupID' => 659]);
     if (sizeof($motherships) == 0) {
         exit('no motherships, bailing');
     }
     // Haven't loaded all data yet, bail!
     foreach ($motherships as $mothership) {
         $typeID = $mothership['typeid'];
         if ($typeID == 3514) {
             continue;
         }
         static::setPrice($typeID, 20000000000);
         // 20b
     }
     static::setPrice(3514, 100000000000);
     // Revenant, 100b
     $titans = $mdb->find('information', ['type' => 'typeID', 'groupID' => 30]);
     if (sizeof($titans) == 0) {
         exit('no titans, bailing');
     }
     // Haven't loaded all data yet, bail!
     foreach ($titans as $titan) {
         $typeID = $titan['typeid'];
         static::setPrice($typeID, 100000000000);
         // 100b
     }
     // We don't need daily prices on the following ships...
     Db::execute('delete from zz_item_price_lookup where typeID in (2834, 3516, 11375, 33397, 32788, 2836, 3518, 32790, 33395, 32209, 33673, 33675, 11940, 11942, 635, 11011, 25560, 13202, 26840, 11936, 11938, 26842)');
     $tourneyFrigates = array(2834, 3516, 11375);
     foreach ($tourneyFrigates as $typeID) {
         static::setPrice($typeID, 80000000000);
     }
     // 80b
     static::setPrice(33397, 120000000000);
     // Chremoas, 120b
     static::setPrice(32788, 100000000000);
     // Cambion, 100b
     static::setPrice(2836, 150000000000);
     // Adrestia, 150b
     static::setPrice(3518, 90000000000);
     // Vangel, 90b
     static::setPrice(32790, 100000000000);
     // Etana, 100b
     static::setPrice(33395, 125000000000);
     // Moracha, 125b
     static::setPrice(32209, 100000000000);
     // Mimir, 100b
     // AT XII Prizes
     static::setPrice(33675, 120000000000);
     // Chameleon
     static::setPrice(33673, 100000000000);
     // Whiptail
     // AT XIII Prizes
     static::setPrice(35871, 140000000000);
     // Fiend
     static::setPrice(35779, 120000000000);
     // Imp
     // Rare CCP Ships (1 trillion! cuz why not)
     static::setPrice(9860, 1000000000000);
     // Polaris
     static::setPrice(11019, 1000000000000);
     // Cockroach
     $rareCruisers = array(11940, 11942, 635, 11011, 25560);
     foreach ($rareCruisers as $typeID) {
         static::setPrice($typeID, 500000000000);
     }
     // 500b
     $rareBattleships = array(13202, 26840, 11936, 11938, 26842);
     foreach ($rareBattleships as $typeID) {
         static::setPrice($typeID, 750000000000);
     }
     // 750b
     // Clear all older lookup entries and leave today's lookup entries
     Db::execute("delete from zz_storage where locker not like '{$todaysLookup}%' and locker like 'CREST-Market%'");
 }
 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;
     }
 }
Example #10
0
 public static function getMaintenanceReason()
 {
     return Storage::retrieve("MaintenanceReason", "");
 }
Example #11
0
$markdown = file_get_contents($path);
// Load the markdown parser
$parsedown = new Parsedown();
$output = $parsedown->text($markdown);
if ($page == 'payments') {
    global $adFreeMonthCost;
    $output = str_replace('{cost}', $adFreeMonthCost, $output);
}
if ($page == 'statistics') {
    // Replace certain tags with different data
    $info = array();
    $info['kills'] = number_format($redis->get('zkb:totalKills'), 0);
    $info['crest'] = number_format($redis->get('zkb:crestRemaining'), 0);
    $info['total'] = number_format(Storage::retrieve('actualKills'), 0, '.', ',');
    $info['percentage'] = number_format($info['total'] / $info['kills'] * 100, 2, '.', ',');
    $info['NextWalletFetch'] = Storage::retrieve('NextWalletFetch');
    foreach ($info as $k => $d) {
        $output = str_replace('{' . $k . '}', $d, $output);
    }
    $info['apistats'] = [];
    //Db::query("select errorCode, count(*) count from zz_api_log where requestTime >= date_sub(now(), interval 1 hour) group by 1");
    $apitable = '
	<table class="table table-striped table-hover table-bordered">
	  <tr><th>Error</th><th>Count</th></tr>';
    foreach ($info['apistats'] as $data) {
        $apitable .= '<tr>';
        $apitable .= '<td>';
        if ($data['errorCode'] == null) {
            $apitable .= 'No error';
        } else {
            $apitable .= $data['errorCode'];
Example #12
0
<?php

require_once '../init.php';
global $mdb;
$lastWalletFetch = Storage::retrieve('NextWalletFetch');
$time = strtotime($lastWalletFetch);
if ($time >= time()) {
    exit;
}
if (Util::is904Error()) {
    return;
}
global $walletApis;
if (!is_array($walletApis)) {
    return;
}
foreach ($walletApis as $api) {
    $type = $api['type'];
    $keyID = $api['keyID'];
    $vCode = $api['vCode'];
    $charID = $api['charID'];
    $pheal = Util::getPheal($keyID, $vCode, true);
    $arr = array('characterID' => $charID, 'rowCount' => 1000);
    if ($type == 'char') {
        $q = $pheal->charScope->WalletJournal($arr);
    } elseif ($type == 'corp') {
        $q = $pheal->corpScope->WalletJournal($arr);
    } else {
        continue;
    }
    if (count($q->transactions)) {
Example #13
0
 public static function fetchApis()
 {
     global $baseDir;
     Db::execute("delete from zz_api_characters where isDirector = ''");
     // Minor cleanup
     $fetchesPerSecond = (int) Storage::retrieve("APIFetchesPerSecond", 30);
     $timer = new Timer();
     $maxTime = 60 * 1000;
     while ($timer->stop() < $maxTime) {
         if (Util::isMaintenanceMode()) {
             return;
         }
         $allChars = Db::query("select apiRowID, cachedUntil from zz_api_characters where errorCount < 10 and cachedUntil < date_sub(now(), interval 10 second) order by cachedUntil, keyID, characterID limit {$fetchesPerSecond}", array(), 0);
         $total = sizeof($allChars);
         $iterationCount = 0;
         if ($total == 0) {
             sleep(1);
         } else {
             foreach ($allChars as $char) {
                 if (Util::isMaintenanceMode()) {
                     return;
                 }
                 if ($timer->stop() > $maxTime) {
                     return;
                 }
                 $apiRowID = $char["apiRowID"];
                 Db::execute("update zz_api_characters set cachedUntil = date_add(if(cachedUntil=0, now(), cachedUntil), interval 5 minute), lastChecked = now() where apiRowID = :id", array(":id" => $apiRowID));
                 $m = $iterationCount % $fetchesPerSecond;
                 $command = "flock -w 60 {$baseDir}/cache/locks/preFetch.{$m} php5 {$baseDir}/cli.php apiFetchKillLog {$apiRowID}";
                 $command = escapeshellcmd($command);
                 exec("{$command} >/dev/null 2>/dev/null &");
                 $iterationCount++;
                 if ($m == 0) {
                     sleep(1);
                 }
             }
         }
     }
 }
Example #14
0
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
$topPoints = array();
$topIsk = json_decode(Storage::retrieve("TopIsk"), true);
$topPods = json_decode(Storage::retrieve("TopPods"), true);
$topPointList = json_decode(Storage::retrieve("TopPoints"), true);
if (is_array($topPointList)) {
    $topPoints = Kills::getKillsDetails($topPointList);
}
$p = array();
$p["limit"] = 5;
$p["pastSeconds"] = 3 * 86400;
$p["kills"] = true;
$top = array();
$top[] = json_decode(Storage::retrieve("Top3dayChars"), true);
$top[] = json_decode(Storage::retrieve("Top3dayCorps"), true);
$top[] = json_decode(Storage::retrieve("Top3dayAlli"), true);
// get latest kills
$killsLimit = 50;
$kills = Kills::getKills(array("limit" => $killsLimit));
$app->render("index.html", array("topPods" => $topPods, "topIsk" => $topIsk, "topPoints" => $topPoints, "topKillers" => $top, "kills" => $kills, "page" => 1, "pageType" => "kills", "pager" => true));
Example #15
0
    $url = $q[0]["url"];
    $app->render("/components/stacktrace.html", array("stacktrace" => $trace, "url" => $url));
});
// API
$app->get("/api/stats/:flags+/", function ($flags) use($app) {
    include "view/apistats.php";
});
$app->get("/api/dna(/:flags+)/", function ($flags = null) use($app) {
    include "view/apidna.php";
});
$app->get("/api/:input+", function ($input) use($app) {
    include "view/api.php";
});
// Kills in the last hour
$app->get("/killslasthour/", function () use($app) {
    echo number_format(Storage::retrieve("KillsLastHour", null));
});
// Post
$app->get("/post/", function () use($app) {
    include "view/postmail.php";
});
$app->post("/post/", function () use($app) {
    include "view/postmail.php";
});
// Autocomplete
$app->map("/autocomplete/", function () use($app) {
    include "view/autocomplete.php";
})->via("POST");
// EVE-KILL kill_detail intercept
$app->get("/evekilldetailintercept/:id/", function ($id) use($app) {
    include "view/evekilldetailintercept.php";
Example #16
0
<?php

/* zKillboard
 * Copyright (C) 2012-2013 EVE-KILL Team and EVSCO.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
$info = array();
if ($page == "statistics") {
    $info["kills"] = Storage::retrieve("KillCount");
    $info["ignored"] = Db::queryField("select count(*) count from zz_killmails where processed = 3", "count", array(), 300);
    $info["total"] = Storage::retrieve("ActualKillCount");
    //$info["apicallsprhour"] = json_encode(Db::query("select hour(requestTime) as x, count(*) as y from ( select requestTime from zz_api_log where requestTime >= date_sub(now(), interval 24 hour)) as foo group by 1 order by requestTime", array(), 300));
    //var_dump($info);
}
$info["pointValues"] = Points::getPointValues();
$app->render("information.html", array("pageview" => $page, "info" => $info));