Example #1
0
 /**
  *
  */
 public function postPaste()
 {
     $postData = $this->app->request->post("paste");
     $timeout = $this->app->request->post("timeout");
     if (isset($_SESSION["characterName"])) {
         $user = $this->app->Users->getUserByName($_SESSION["characterName"]);
         $userID = $user["id"];
         $hash = md5(time() . $_SESSION["characterName"] . $_SESSION["characterID"]);
         $this->app->paste->createPaste($hash, $userID, $postData, $timeout);
         $this->app->redirect("/paste/{$hash}/");
     } else {
         render("/paste/paste.twig", array("error" => "Error, you need to be logged in to post data"));
     }
 }
Example #2
0
 /**
  * Tries to autologin the person
  */
 public function tryAutologin()
 {
     $cookieName = $this->config->getConfig("name", "cookies");
     $cookieData = $this->app->getEncryptedCookie($cookieName, false);
     if (!empty($cookieData) && !isset($_SESSION["loggedIn"])) {
         $userData = $this->getUserDataByLoginHash($cookieData);
         if ($userData) {
             $_SESSION["characterName"] = $userData["characterName"];
             $_SESSION["characterID"] = $userData["characterID"];
             $_SESSION["loggedIn"] = true;
             // Using $app to redirect causes a weird bug in slim, so use a header Location: instead
             header("Location: " . $this->app->request->getPath());
         }
     }
 }
Example #3
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = SeriisApp::getInstance();
     // Check if composer is in the dir
     if (!file_exists(__DIR__ . "/../../composer.phar")) {
         $output->writeln("Composer doesn't exist, downloading it");
         $composer = $app->cURL->getData("https://getcomposer.org/composer.phar", 0);
         file_put_contents(__DIR__ . "/../../composer.phar", $composer);
     }
     $output->writeln("Updating composer");
     exec("php " . __DIR__ . "/../../composer.phar update -o");
     // Generate an optimized loader
     $output->writeln("Generating Optimized Loader");
     $loaderCode = $this->generateOptimizedLoader($app);
     file_put_contents(__DIR__ . "/../OptimizedLoader.php", $loaderCode);
     // Update SeriisApp
     $SeriisAppCode = $this->generateSeriisApp();
     $output->writeln("Generating SeriisApp");
     file_put_contents(__DIR__ . "/../SeriisApp.php", $SeriisAppCode);
     // Do more stuff (Clear cache?)
 }
Example #4
0
 /**
  * Inserts data into the slim flasher.
  *
  * @static
  *
  * @param string $logType the type of logging, debug, info, warning, error
  * @param string $logMessage the message for the log
  */
 public function flasher($logType, $logMessage)
 {
     $this->app->flash($logType, $logMessage);
 }
Example #5
0
/**
 * Quick access to rendering templates, json, xml and probably more down the line.
 *
 * @param string $templateFile
 * @param array $dataArray
 * @param null $status
 * @param string $contentType
 */
function render($templateFile, $dataArray = array(), $status = null, $contentType = null)
{
    $app = \Seriis\SeriisApp::getInstance();
    $app->out->render($templateFile, $dataArray, $status, $contentType);
}
Example #6
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $table = prompt("Table to create model for");
     $this->description["description"] = prompt("Description");
     if (!$table) {
         $output->writeln("Error, table name is not supplied.");
         exit;
     }
     // Setup the path and make sure it doesn't already exist
     $path = __DIR__ . "/../Model/Database/{$table}.php";
     if (file_exists($path)) {
         return $output->writeln("Error, file already exists");
     }
     // Load app
     $app = \Seriis\SeriisApp::getInstance();
     // Load the table, if it exists in the first place
     $tableColums = $app->Db->query("SHOW COLUMNS FROM {$table}");
     // Generate the start of the model code
     $class = new PhpClass();
     $class->setQualifiedName("Seriis\\Model\\Database\\{$table}")->setProperty(PhpProperty::create("app")->setVisibility("private")->setDescription("The Slim Application"))->setProperty(PhpProperty::create("db")->setVisibility("private")->setDescription("The database connection"))->setMethod(PhpMethod::create("__construct")->addParameter(PhpParameter::create("app")->setType("SeriisApp"))->setBody("\$this->app = \$app;\n\r\n                \$this->db = \$app->Db;\n"))->setDescription($this->description)->declareUse("Seriis\\SeriisApp");
     $nameFields = array();
     $idFields = array();
     foreach ($tableColums as $get) {
         // This is for the getByName selector(s)
         if (stristr($get["Field"], "name")) {
             $nameFields[] = $get["Field"];
         }
         // This is for the getByID selector(s)
         if (strstr($get["Field"], "ID")) {
             $idFields[] = $get["Field"];
         }
     }
     // Get generator
     foreach ($nameFields as $name) {
         // get * by Name
         $class->setMethod(PhpMethod::create("getAllBy" . ucfirst($name))->addParameter(PhpParameter::create($name))->setVisibility("public")->setBody("return \$this->db->query(\"SELECT * FROM {$table} WHERE {$name} = :{$name}\", array(\":{$name}\" => \${$name}));"));
     }
     foreach ($idFields as $id) {
         // get * by ID,
         $class->setMethod(PhpMethod::create("getAllBy" . ucfirst($id))->addParameter(PhpParameter::create($id)->setType("int"))->setVisibility("public")->setBody("return \$this->db->query(\"SELECT * FROM {$table} WHERE {$id} = :{$id}\", array(\":{$id}\" => \${$id}));"));
     }
     foreach ($nameFields as $name) {
         foreach ($tableColums as $get) {
             // If the fields match, skip it.. no reason to get/set allianceID where allianceID = allianceID
             if ($get["Field"] == $name) {
                 continue;
             }
             // Skip the id field
             if ($get["Field"] == "id") {
                 continue;
             }
             $class->setMethod(PhpMethod::create("get" . ucfirst($get["Field"]) . "By" . ucfirst($name))->addParameter(PhpParameter::create($name))->setVisibility("public")->setBody("return \$this->db->queryField(\"SELECT {$get["Field"]} FROM {$table} WHERE {$name} = :{$name}\", \"{$get["Field"]}\", array(\":{$name}\" => \${$name}));"));
         }
     }
     foreach ($idFields as $id) {
         foreach ($tableColums as $get) {
             // If the fields match, skip it.. no reason to get/set allianceID where allianceID = allianceID
             if ($get["Field"] == $id) {
                 continue;
             }
             // Skip the id field
             if ($get["Field"] == "id") {
                 continue;
             }
             $class->setMethod(PhpMethod::create("get" . ucfirst($get["Field"]) . "By" . ucfirst($id))->addParameter(PhpParameter::create($id))->setVisibility("public")->setBody("return \$this->db->queryField(\"SELECT {$get["Field"]} FROM {$table} WHERE {$id} = :{$id}\", \"{$get["Field"]}\", array(\":{$id}\" => \${$id}));"));
         }
     }
     // Update generator
     foreach ($nameFields as $name) {
         foreach ($tableColums as $get) {
             // If the fields match, skip it.. no reason to get/set allianceID where allianceID = allianceID
             if ($get["Field"] == $name) {
                 continue;
             }
             // Skip the id field
             if ($get["Field"] == "id") {
                 continue;
             }
             $class->setMethod(PhpMethod::create("update" . ucfirst($get["Field"]) . "By" . ucfirst($name))->addParameter(PhpParameter::create($get["Field"]))->addParameter(PhpParameter::create($name))->setVisibility("public")->setBody("\$exists = \$this->db->queryField(\"SELECT {$get["Field"]} FROM {$table} WHERE {$name} = :{$name}\", \"{$get["Field"]}\", array(\":{$name}\" => \${$name}));\r\n                     if(!empty(\$exists)){\r\n                        \$this->db->execute(\"UPDATE {$table} SET {$get["Field"]} = :{$get["Field"]} WHERE {$name} = :{$name}\", array(\":{$name}\" => \${$name}, \":{$get["Field"]}\" => \${$get["Field"]}));}\r\n                    "));
         }
     }
     foreach ($idFields as $id) {
         foreach ($tableColums as $get) {
             // If the fields match, skip it.. no reason to get/set allianceID where allianceID = allianceID
             if ($get["Field"] == $id) {
                 continue;
             }
             // Skip the id field
             if ($get["Field"] == "id") {
                 continue;
             }
             $class->setMethod(PhpMethod::create("update" . ucfirst($get["Field"]) . "By" . ucfirst($id))->addParameter(PhpParameter::create($get["Field"]))->addParameter(PhpParameter::create($id))->setVisibility("public")->setBody("\$exists = \$this->db->queryField(\"SELECT {$get["Field"]} FROM {$table} WHERE {$id} = :{$id}\", \"{$get["Field"]}\", array(\":{$id}\" => \${$id}));\r\n                     if(!empty(\$exists))\r\n                     {\r\n                        \$this->db->execute(\"UPDATE {$table} SET {$get["Field"]} = :{$get["Field"]} WHERE {$id} = :{$id}\", array(\":{$id}\" => \${$id}, \":{$get["Field"]}\" => \${$get["Field"]}));}\r\n                    "));
         }
     }
     // Global insert generator (Yes it's ugly as shit..)
     $inserter = "public function insertInto" . ucfirst($table) . "(";
     foreach ($tableColums as $field) {
         // Skip the ID field
         if ($field["Field"] == "id") {
             continue;
         }
         $inserter .= "\${$field["Field"]}, ";
     }
     $inserter = rtrim(trim($inserter), ",") . ")";
     $inserter .= "{";
     $inserter .= "\$this->db->execute(\"INSERT INTO {$table} (";
     foreach ($tableColums as $field) {
         if ($field["Field"] == "id") {
             continue;
         }
         $inserter .= $field["Field"] . ", ";
     }
     $inserter = rtrim(trim($inserter), ",") . ") ";
     $inserter .= "VALUES (";
     foreach ($tableColums as $field) {
         if ($field["Field"] == "id") {
             continue;
         }
         $inserter .= ":" . $field["Field"] . ", ";
     }
     $inserter = rtrim(trim($inserter), ",") . ")\", ";
     $inserter .= "array(";
     foreach ($tableColums as $field) {
         if ($field["Field"] == "id") {
             continue;
         }
         $inserter .= "\":" . $field["Field"] . "\" => \${$field["Field"]}, ";
     }
     $inserter = rtrim(trim($inserter), ",") . "));";
     $inserter .= "}}";
     $generator = new CodeFileGenerator();
     $code = $generator->generate($class);
     $code = rtrim(trim($code), "}");
     $code .= $inserter;
     $formatter = new Formatter();
     $code = $formatter->format($code);
     file_put_contents($path, $code);
     chmod($path, 0777);
     $output->writeln("Model created: {$path}");
 }
Example #7
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Enable the garbage collector since this is a long running process
     //gc_enable();
     // Get the slim instance
     $app = SeriisApp::getInstance();
     $run = true;
     $cnt = 0;
     $cronjobs = scandir(__DIR__ . '/Cronjobs/');
     do {
         $cnt++;
         if ($cnt > 50) {
             //gc_collect_cycles();
             $cnt = 0;
         }
         foreach ($cronjobs as $key => $cron) {
             // Unset anything that isn't .php!
             if (!preg_match('/^(.+)\\.php$/', $cron, $match)) {
                 unset($cronjobs[$key]);
                 continue;
             }
             if (isset($match[1])) {
                 $name = $match[1];
                 $md5 = md5($name);
                 // If the script is currently running, skip to the next script
                 if ($app->Cache->get($md5 . '_pid') !== false) {
                     $pid = $app->Cache->get($md5 . '_pid');
                     $status = pcntl_waitpid($pid, $status, WNOHANG);
                     if ($status == -1) {
                         $app->Cache->delete($md5 . '_pid');
                     }
                     usleep(500000);
                     //continue;
                 }
                 // Get last time this cronjob ran
                 $lastRan = $app->Cache->get($md5) > 0 ? $app->Cache->get($md5) : 0;
                 // Current Time
                 $currentTime = time();
                 // Load the cronjobs class and get the information needed
                 $import = '\\Seriis\\Task\\Cronjobs\\' . $name;
                 $class = new $import();
                 $interval = $class->getRunTimes();
                 // If the current time is larger than the lastRunTime and Interval, then we run it again!
                 if ($currentTime > $lastRan + $interval) {
                     $time = time();
                     $output->writeln("Time: {$time}: Running {$name} (Interval: {$interval})");
                     try {
                         // Time to fork it all!
                         $pid = pcntl_fork();
                         if ($pid === 0) {
                             // Get the PID
                             $pid = getmypid();
                             // Tell the cache that we're running the cronjobs will automatically remove it from the cache once they're done
                             $app->Cache->set($md5 . '_pid', $pid);
                             // Execute the cronjob
                             $class->execute($pid, $md5);
                             exit;
                         }
                         // Tell the cache when we ran last!
                         $app->Cache->set($md5, time());
                     } catch (\Exception $e) {
                         $output->writeln("ERROR!! (pid: " . getmypid() . ") " . $e->getMessage());
                         $run = false;
                         posix_kill(getmygid(), 9);
                         exit;
                     }
                 }
             }
             // Sleep for 500 milliseconds, so we don't go nuts with CPU
             usleep(500000);
         }
     } while ($run === true);
 }
Example #8
0
 /**
  * Sets up the task (Setup $this->crap and such here)
  */
 public function setUp()
 {
     $this->app = \Seriis\SeriisApp::getInstance();
 }
Example #9
0
 public function __construct()
 {
     $this->app = SeriisApp::getInstance();
     $this->stomp = new \Stomp($this->app->baseConfig->getConfig("server", "stomp"), $this->app->baseConfig->getConfig("username", "stomp"), $this->app->baseConfig->getConfig("password", "stomp"));
 }