public void SendComplete(string taskId) { Debug.WriteLine($"[+] SendComplete - Sending task complete for {taskId}"); SCTaskResp completeResponse = new SCTaskResp(taskId, "{\"completed\": true}"); this.PostResponse(completeResponse); }
public void SendError(string taskId, string error) { Debug.WriteLine($"[+] SendError - Sending error for {taskId}: {error}"); SCTaskResp errorResponse = new SCTaskResp(taskId, "{\"completed\": true, \"status\": \"error\", \"user_output\": \"" + error + "\"}"); this.PostResponse(errorResponse); }
/// <summary> /// Post a response to the Apfell endpoint /// </summary> /// <param name="taskresp">The response to post to the endpoint</param> /// <returns>String with the Apfell server's reply</returns> public string PostResponse(SCTaskResp taskresp) { string endpoint = this.endpoint + "responses/" + taskresp.id; try // Try block for HTTP requests { // Encrypt json to send to server string json = JsonConvert.SerializeObject(taskresp); string result = HTTP.Post(endpoint, json); Debug.WriteLine($"[-] PostResponse - Got response for task {taskresp.id}: {result}"); if (result.Contains("success")) { // If it was successful, return the result return(result); } else { // If we didn't get success, retry and increment counter while (retry < 20) { Debug.WriteLine($"[!] PostResponse - ERROR: Unable to post task response for {taskresp.id}, retrying..."); Thread.Sleep(this.sleep); this.PostResponse(taskresp); } retry++; throw (new Exception("[!] PostResponse - ERROR: Retries exceeded")); } } catch (Exception e) // Catch exceptions from HTTP request or retry exceeded { return(e.Message); } }