Example #1
0
 /**
  * @depends testIfFileNotExist
  */
 public function testFileCreateAndSaveData()
 {
     $this->storage->store($this->storeArray);
     $this->assertFileExists($this->fullpath, 'File exist already');
     $testString = serialize($this->storeArray);
     $this->assertStringEqualsFile($this->fullpath, $testString, 'Equals string which we set and what we create by hand');
 }
Example #2
0
 /**
  * function that load packages and register them in storage
  * @param integer
  * @return void
  **/
 public static function load(int $group) : bool
 {
     $packages = Database::query(TABLE_PACKAGE_TO_GROUP, ['packageid'], '`groupid` = ' . $group);
     $list = [];
     $store = [];
     foreach ($packages as $package) {
         $list[] = $package['packageid'];
     }
     if (!empty($list)) {
         $packages = Database::query(TABLE_PACKAGE, ['*'], '`packageid` IN ( ' . implode(', ', $list) . ' )');
         foreach ($packages as $package) {
             if (file_exists(DIR_PACKAGES . '/' . $package['repertory'] . '/confs.php')) {
                 require DIR_PACKAGES . '/' . $package['repertory'] . '/confs.php';
             }
             if (file_exists(DIR_PACKAGES . '/' . $package['repertory'] . '/models')) {
                 Document::get(DIR_PACKAGES . '/' . $package['repertory'] . '/models');
             }
             if (file_exists(DIR_PACKAGES . '/' . $package['repertory'] . '/controllers')) {
                 Document::get(DIR_PACKAGES . '/' . $package['repertory'] . '/controllers');
             }
             $store[] = $package;
         }
     }
     Storage::store(['packages' => $store]);
     return true;
 }
Example #3
0
 public function __construct($args)
 {
     //$script = file_get_contents(LIB . "/OrongoScript/Tests/test.osc");
     //$parser = new OrongoScriptParser($script);
     //$parser->startParser();
     require 'TerminalPlugin.php';
     Plugin::hookTerminalPlugin(new TerminalPlugin());
     $stored = Plugin::getSettings($args['auth_key']);
     //Access the settings in the array.
     if (isset($stored['example_setting_2']) && $stored['example_setting_2']) {
         $this->injectHTML = true;
         $this->htmlToInject = $stored['example_setting_1'];
     } else {
         $this->injectHTML = false;
     }
     $store_string = 'this is a variable';
     $bool = Storage::store('a_storage_key', $store_string, true);
     if ($bool) {
         //This will fail and return false, because overwrite = false
         $bool2 = Storage::store('a_storage_key', 'will this overwrite?', false);
         if ($bool2 == false) {
             //This wil return: this is a variable
             $returnString = Storage::get('a_storage_key');
             //Delete the storage
             Storage::delete('a_storage_key');
         }
     }
 }
Example #4
0
 /**
  * Fetches the given URL and parses products and stores them.
  *
  * @return int Number of processed products.
  * @exception Exception
  */
 static function parse($url)
 {
     $fp = @fopen($url, 'r');
     if (!$fp) {
         throw new \Exception("Could not open url: " . $url);
     }
     $result = 0;
     $start = false;
     $xml = '';
     while (!feof($fp)) {
         // Get onle line
         $buffer = fgets($fp);
         if (strpos($buffer, '<product>') !== false) {
             $start = true;
         }
         if ($start) {
             $xml .= $buffer;
         }
         if (strpos($buffer, '</product>') !== false) {
             $start = false;
             if (Storage::store(self::product($xml))) {
                 $result++;
             }
             $xml = "";
         }
     }
     fclose($fp);
     if ($start) {
         throw new \Exception("Could not find </product>");
     }
     if (!$result) {
         throw new \Exception("No products found.");
     }
     return $result;
 }
 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;
     }
 }
Example #6
0
 /**
  * listen to write event.
  */
 public static function write_hook($params)
 {
     if (\OCP\App::isEnabled('files_versions')) {
         $path = $params[\OC\Files\Filesystem::signal_param_path];
         if ($path != '') {
             Storage::store($path);
         }
     }
 }
Example #7
0
 /**
  * listen to write event.
  */
 public static function write_hook($params)
 {
     if (\OCP\Config::getSystemValue('files_versions', Storage::DEFAULTENABLED) == 'true') {
         $path = $params[\OC\Files\Filesystem::signal_param_path];
         if ($path != '') {
             Storage::store($path);
         }
     }
 }
Example #8
0
 /**
  * function that load librairies
  * @param void
  * @return bool
  **/
 public static function loadLibs() : bool
 {
     $libs = [];
     foreach (get_defined_constants() as $constant => $value) {
         if (preg_match('#^LIB_[A-Z_]+$#', $constant)) {
             require_once constant($constant);
             $libs[] = ['name' => constant($constant), 'realname' => $constant];
         }
     }
     Storage::store(['libs' => $libs]);
     return true;
 }
Example #9
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);
 }
Example #10
0
 public function execute($parameters, $db)
 {
     $p = array();
     $p["limit"] = 5;
     $p["pastSeconds"] = 3 * 86400;
     $p["kills"] = true;
     Storage::store("Top3dayChars", json_encode(Info::doMakeCommon("Top Characters - Last 3 Days", "characterID", Stats::getTopPilots($p))));
     Storage::store("Top3dayCorps", json_encode(Info::doMakeCommon("Top Corporations - Last 3 Days", "corporationID", Stats::getTopCorps($p))));
     Storage::store("Top3dayAlli", json_encode(Info::doMakeCommon("Top Alliances - Last 3 Days", "allianceID", Stats::getTopAllis($p))));
     Storage::store("TopIsk", json_encode(Stats::getTopIsk(array("pastSeconds" => 3 * 86400, "limit" => 5))));
     Storage::store("TopPods", json_encode(Stats::getTopIsk(array("groupID" => 29, "pastSeconds" => 3 * 86400, "limit" => 5))));
     Storage::store("TopPoints", json_encode(Stats::getTopPoints("killID", array("losses" => true, "pastSeconds" => 3 * 86400, "limit" => 5))));
     Storage::store("KillCount", $db->queryField("select count(*) count from zz_killmails", "count"));
     Storage::store("ActualKillCount", $db->queryField("select count(*) count from zz_killmails where processed = 1", "count"));
 }
 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 #12
0
 /**
  * Remember owner and the owner path of the source file.
  * If the file already exists, then it was a upload of a existing file
  * over the web interface and we call Storage::store() directly
  *
  * @param array $params array with oldpath and newpath
  *
  */
 public static function pre_renameOrCopy_hook($params)
 {
     if (\OCP\App::isEnabled('files_versions')) {
         // if we rename a movable mount point, then the versions don't have
         // to be renamed
         $absOldPath = \OC\Files\Filesystem::normalizePath('/' . \OCP\User::getUser() . '/files' . $params['oldpath']);
         $manager = \OC\Files\Filesystem::getMountManager();
         $mount = $manager->find($absOldPath);
         $internalPath = $mount->getInternalPath($absOldPath);
         if ($internalPath === '' and $mount instanceof \OC\Files\Mount\MoveableMount) {
             return;
         }
         $view = new \OC\Files\View(\OCP\User::getUser() . '/files');
         if ($view->file_exists($params['newpath'])) {
             Storage::store($params['newpath']);
         } else {
             Storage::setSourcePathAndUser($params['oldpath']);
         }
     }
 }
Example #13
0
<?php

/**
 * User: Dacascas
 * Date: 31/01/2016
 * Time: 22:56
 */
include_once 'lib/conf.php';
include_once 'lib/class.php';
$storage = new Storage('bee.txt');
if (isset($_REQUEST['reset'])) {
    $storage->store('');
    Response::redirect('/');
}
if ($storage->isEmpty()) {
    $bees = new BeeBuilder($config);
    $bees->createBees();
    $storage->store($bees);
} else {
    $bees = $storage->get();
}
if (isset($_REQUEST['bee'])) {
    $bees = new BeeHit($bees);
    $bees = $bees->hit($_REQUEST['bee']);
    $storage->store($bees);
}
echo new Response($bees);
Example #14
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%'");
 }
Example #15
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 #16
0
if ($i % 15 != 0) {
    exit;
}
$p = array();
$numDays = 7;
$p['limit'] = 10;
$p['pastSeconds'] = $numDays * 86400;
$p['kills'] = true;
Storage::store('Kills5b+', json_encode(Kills::getKills(array('iskValue' => 5000000000), true, false)));
Storage::store('Kills10b+', json_encode(Kills::getKills(array('iskValue' => 10000000000), true, false)));
Storage::store('TopChars', json_encode(Info::doMakeCommon('Top Characters', 'characterID', getStats('characterID'))));
Storage::store('TopCorps', json_encode(Info::doMakeCommon('Top Corporations', 'corporationID', getStats('corporationID'))));
Storage::store('TopAllis', json_encode(Info::doMakeCommon('Top Alliances', 'allianceID', getStats('allianceID'))));
Storage::store('TopShips', json_encode(Info::doMakeCommon('Top Ships', 'shipTypeID', getStats('shipTypeID'))));
Storage::store('TopSystems', json_encode(Info::doMakeCommon('Top Systems', 'solarSystemID', getStats('solarSystemID'))));
Storage::store('TopIsk', json_encode(Stats::getTopIsk(array('pastSeconds' => $numDays * 86400, 'limit' => 5))));
// Cleanup old sessions
Db::execute('delete from zz_users_sessions where validTill < now()');
// Keep the account balance table clean
Db::execute('delete from zz_account_balance where balance = 0');
// Cleanup subdomain stuff
Db::execute('update zz_subdomains set adfreeUntil = null where adfreeUntil < now()');
Db::execute("update zz_subdomains set banner = null where banner = ''");
Db::execute("delete from zz_subdomains where adfreeUntil is null and banner is null and (alias is null or alias = '')");
// Expire change expirations
Db::execute('update zz_users set change_expiration = null, change_hash = null where change_expiration < date_sub(now(), interval 3 day)');
function getStats($column)
{
    $result = Stats::getTop($column, ['isVictim' => false, 'pastSeconds' => 604800]);
    return $result;
}
Example #17
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);
 }
Example #18
0
}
$minute = date('i');
if (!in_array('-f', $argv) && $minute != 15) {
    return;
}
$p = array();
$numDays = 7;
$p['limit'] = 10;
$p['pastSeconds'] = $numDays * 86400;
$p['kills'] = true;
Storage::store('Kills5b+', json_encode(Kills::getKills(array('iskValue' => 5000000000.0), true, false)));
Storage::store('Kills10b+', json_encode(Kills::getKills(array('iskValue' => 10000000000.0), true, false)));
Storage::store('TopChars', json_encode(Info::doMakeCommon('Top Characters', 'characterID', getStats('pilot', 'characterID'))));
Storage::store('TopCorps', json_encode(Info::doMakeCommon('Top Corporations', 'corporationID', getStats('corp', 'corporationID', false))));
Storage::store('TopAllis', json_encode(Info::doMakeCommon('Top Alliances', 'allianceID', getStats('alli', 'allianceID'))));
Storage::store('TopShips', json_encode(Info::doMakeCommon('Top Ships', 'shipTypeID', getStats('ship', 'shipTypeID'))));
Storage::store('TopSystems', json_encode(Info::doMakeCommon('Top Systems', 'solarSystemID', getStats('system', 'solarSystemID'))));
Storage::store('TopIsk', json_encode(Stats::getTopIsk(array('pastSeconds' => $numDays * 86400, 'limit' => 5))));
Storage::store('TopPods', json_encode(Stats::getTopIsk(array('groupID' => 29, 'pastSeconds' => $numDays * 86400, 'limit' => 5))));
Storage::store('TopPoints', json_encode(Stats::getTopPoints('killID', array('losses' => true, 'pastSeconds' => $numDays * 86400, 'limit' => 5))));
// Clean up the related killmails cache
$cache = new FileCache($baseDir . '/cache/related/');
$cache->cleanUp();
// Cleanup the overall file cache
$fc = new FileCache();
$fc->cleanup();
function getStats($type, $column)
{
    $result = Stats::getTop($column, ['isVictim' => false, 'pastSeconds' => 604800]);
    return $result;
}