public function search() { if (isset($_GET["q"])) { $histories = DB::fetch("\nSELECT\n\tjobs.id as job_id, jobs.jobName, histories.id, run_date, time_taken, result\nFROM histories\nINNER JOIN jobs ON jobs.user_id = ? AND histories.jobs_id = jobs.id\nWHERE output LIKE ?\n", [$this->user->id, "%" . $_GET["q"] . "%"]); echo $this->loadRender("search.html", ["search" => $_GET["q"], "histories" => $histories]); } }
/** * This service will expect a JSON POST data of: * ["data"] => {"nonce": "randomString", "message": "cipherText", "signature": "abcdef"} * Signature will be a sha256 of the message pre-encrypt with nonce appended to the end * ie * {JSON} + nonce + sharedhash * Note: sharedhash should NOT be the sharedkey that is used to encrypt the message * * * Unencrypted cipherText will look like * {"output": "stdout of run", "time_taken": 10, "result": 0} * Just like in most modern programs - a result of anything but 0 indicates an error * * @param $jobId */ public function upload($jobId) { if ($jobId && is_numeric($jobId)) { /** @var \application\models\Jobs $job */ $job = \application\models\Jobs::getByField("id", $jobId); if (!$job) { echo ""; return; } $job = $job[0]; //decrypt message $data = json_decode($_POST["data"], true); $rawMessage = aes_decrypt($job->sharedkey, $data["message"]); /*$rawMessage = str_replace("\\n", "", $rawMessage); $rawMessage = str_replace("\\r", "", $rawMessage); $rawMessage = str_replace("\\", "", $rawMessage);*/ $rawMessage = preg_replace('/[^(\\x20-\\x7F)]*/', '', $rawMessage); // if decryption was successful - // check signature if (hash("sha256", $rawMessage . $data["nonce"] . $job->hash) == $data["signature"]) { // the message is verified $message = json_decode($rawMessage, true); $replayAttackCheck = DB::fetch("SELECT id FROM histories WHERE jobs_id = ? AND nonce = ?", [$job->id, $data["nonce"]]); if (count($replayAttackCheck) == 0) { $history = \application\models\Histories::create($message); $history->run_date = date("Y-m-d H:i:s"); $history->jobs_id = $job->id; $history->nonce = $data["nonce"]; $history->save(); $job->last_result = $history->result; $job->last_run = $history->run_date; $job->save(); } } } }
public function runMigrations() { global $argv; $this->setupDatabaseConnection(); DB::query("CREATE TABLE IF NOT EXISTS migrations (\n\t\t\t\t\t\t\t id INTEGER PRIMARY KEY NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t\t\t migration INTEGER,\n\t\t\t\t\t\t\t ran_at DATETIME\n\t\t\t\t)"); switch ($argv[1]) { case "show": foreach (DB::fetch("SELECT migration, ran_at FROM migrations") as $migration) { echo $migration["migration"] . " => " . $migration["ran_at"] . PHP_EOL; } break; case "count": echo DB::column("SELECT COUNT(id) FROM migrations"); break; case "run": $migrations = DB::fetch("SELECT migration FROM migrations"); $migrationArray = []; foreach ($migrations as $migration) { $migrationArray[] = $migration["migration"]; } foreach (glob("application/migrations/*.php") as $filename) { if (!in_array($filename, $migrationArray)) { try { include $filename; DB::insert("migrations", ["migration" => $filename, "ran_at" => (new \DateTime())->format("Y-m-d")]); } catch (\Exception $e) { echo "[HF_Core] - Migration error - {$e}"; exit(1); } } } break; case "clear": DB::query("DELETE FROM migrations"); break; case "reset": switch ($this->config["DATABASE_TYPE"]) { case "SQLITE": DB::$c = null; unlink($this->config["DATABASE_FILE"]); break; case "MYSQL": DB::query("DROP DATABASE " . $this->config['MYSQL_DBNAME']); DB::query("CREATE DATABASE " . $this->config['MYSQL_DBNAME']); break; } break; } }