Ejemplo n.º 1
0
 public function index()
 {
     if ($this->user) {
         $jobs = \application\models\Jobs::getByField("user_id", $this->user->id);
         echo $this->loadRender("main.html", ["jobs" => $jobs]);
     }
 }
Ejemplo n.º 2
0
 public function log($jobId, $logId)
 {
     try {
         $jobObject = \application\models\Jobs::getByField("id", $jobId);
         if ($this->checkAccess($jobObject[0])) {
             /** @var \application\models\Histories[] $historyArr */
             $historyArr = \application\models\Histories::getByField("id", $logId);
             header("Content-Type: text/plain");
             echo $historyArr[0]->output;
         }
     } catch (\Exception $e) {
         header("Location: /kritbit");
     }
 }
Ejemplo n.º 3
0
 public function force($id)
 {
     $job = \application\models\Jobs::getByField("id", $id);
     if ($job && $job[0]->user_id == $this->user->id) {
         //secuirty check
         if ($job[0]->force_run == 1) {
             $job[0]->force_run = 0;
         } else {
             $job[0]->force_run = 1;
         }
         $job[0]->save();
         header("Location: /kritbit");
     } else {
         header("Location: /kritbit");
     }
 }
Ejemplo n.º 4
0
 /**
  * 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();
             }
         }
     }
 }