예제 #1
0
 public function postUploadLatestResponse(Request $request)
 {
     $input = $request->input('response');
     $ec = ExecutedCommand::latest();
     $ec->response = $input;
     if ($ec->save()) {
         return response()->json(['message' => 'reponse_uploaded_successfully']);
     } else {
         return $this->internalServerErrorJsonResponse('Unable to upload response');
     }
 }
 public function postEnqueueCommand(Request $request)
 {
     $initial = ExecutedCommand::latest();
     $input = $request->only(['command']);
     try {
         $success = CommandQueue::enqueue($input['command']);
     } catch (CommandParserException $e) {
         return $this->unableToParseJsonResponse($e->getMessage());
     }
     if (!$success) {
         return $this->internalServerErrorJsonResponse('Unable to enqueue command correctly');
     }
     // Command enqueued successfully, now wait for response
     $getResponse = function () use($initial) {
         $result = ExecutedCommand::latest();
         if ($result && $result->response && (!$initial || $result->timestamp !== $initial->timestamp)) {
             return response()->json($result);
         } else {
             return null;
         }
     };
     return $this->serveLongPolling($getResponse, response()->json(['response' => 'none']));
 }