Skip to content

Commit

Permalink
Added tJob execution status messages
Browse files Browse the repository at this point in the history
  • Loading branch information
avinash-sudhodanan committed Nov 29, 2017
1 parent 6af76b7 commit 0376098
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 36 deletions.
35 changes: 8 additions & 27 deletions ess.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
from pprint import pprint
from zapv2 import ZAPv2
import os
import requests

torm_api="localhost:37000"
target = '0.0.0.0' #indicates in which IP address the API listents to
por = 80 #indicates the port in
api_version='r3' #represents the current version of the API
Expand Down Expand Up @@ -131,36 +133,15 @@ def delete_secjob(secjob_id):

@app.route('/ess/api/'+api_version+'/tjobs/<int:tjob_id>/exec', methods = ['GET'])
def execute_tjob(tjob_id):
if tjob_id==1:
proc = subprocess.Popen("docker run dockernash/tjob-tomato-norm:v1", stdout=subprocess.PIPE, shell=True)
#proc.wait()
(result,err) =proc.communicate()
proc.wait()
print type(result)
print len(result)
if "OK" in result:
return jsonify( { 'result': "tJob execution successful" } )
else:
#TODO detech child process from parent
return jsonify( { 'result': "tJob execution successful"})
elif tjob_id==11:
proc = subprocess.Popen("docker run dockernash/tjob-tomato-mal:v1", stdout=subprocess.PIPE, shell=True)
#proc.wait()
(result,err) =proc.communicate()
proc.wait()
print type(result)
print len(result)
if "OK" in result:
return jsonify( { 'result': "tJob execution successful" } )
else:
#TODO detach child process from parent
return jsonify( { 'result': "tJob execution successful" } )
else:
return jsonify( { 'result': "No tJob found with the provided id" })
# response=r = requests.post("http://"+torm_api+"/api/tjob/"+tjob_id+"/exec", json={}, headers={"Accept": "application/json, text/plain, */*","Accept-Encoding" : "gzip, deflate", "Accept-Language":"en-US,en;q=0.5","Connection":"keep-alive","Content-Length":2,"content-type":"application/json","Host":"localhost:37000","Referer":"http://localhost:37000/","User-Agent":"Mozilla/5.0 (X11; Ubuntu; Linux) Gecko/20100101 Firefox/57.0"})
req=requests.Session()
response= req.post("http://"+torm_api+"/api/tjob/"+str(tjob_id)+"/exec", json={})

return jsonify( { 'result': str(response.json()["result"]).strip(), 'logIndex':str(response.json()["logIndex"]).strip(),'getStat_url':"http://"+torm_api+"/api/tjob/"+str(tjob_id)+"/exec/"+str(response.json()["logIndex"]).strip()+"result"})

@app.route('/ess/api/'+api_version+'/secjobs/<int:secjob_id>/exec', methods = ['GET'])
def execute_secjob(secjob_id):
all_tjob_urls=zap.core.urls
all_tjob_urls=list(set(zap.core.urls))
insecure_urls=[]
for url in all_tjob_urls:
if not url.startswith("https"):
Expand Down
57 changes: 48 additions & 9 deletions templates/ess.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/md5.js"></script>

<script>
api_version="r3";
//Function to send API request with the entered tjob id
function addTJobId(){
return "/ess/api/r3/secjobs/"+$("#tjobid").val()+"/exec";
return "/ess/api/"+api_version+"/secjobs/"+$("#tjobid").val()+"/exec";
}

function changeProgress(element,percentage){
Expand Down Expand Up @@ -44,7 +45,7 @@
}
//Send SecJob
function sendSecJob(){
url= "/ess/api/r3/secjobs";
url= "/ess/api/"+api_version+"/secjobs";
postbody={id: 0, name: $("#secjobname").val(), vulns:[],tJobId:$("#tjobid").val(),maxRunTimeInMins:10}
$.ajax({
type: "POST",
Expand All @@ -62,9 +63,51 @@
toast("SecJob Creation Failed! Please check your connection",4000);
alert(errMsg);
}
});
});

}

function executeTJob(tjobid){
url_start_exec= "/ess/api/"+api_version+"/tjobs/"+tjobid.toString()+"/exec";
toast("Starting Executing TJob with id: "+tjobid.toString(),4000);
start_exec=$.ajax({
type: "GET",
url: url_start_exec,
// The key needs to match your method's input parameter (case-sensitive).
dataType: "json",
success: function(result){
if(result.result=="IN PROGRESS"){
toast("TJob Execution IN PROGRESS!",4000);
get_exec_progress=$.ajax({
type: "GET",
url: result.getStat_url,
// The key needs to match your method's input parameter (case-sensitive).
dataType: "json",
success: function(result1){
if(result1.result=="EXECUTING TEST"){
toast("TJob Execution state is EXECUTING TEST!",4000);
}

},
failure: function(errMsg) {
toast("TJob Execution Failed",4000);
alert(errMsg);
}
});
console.log(get_exec_progress)
}

},
failure: function(errMsg) {
toast("TJob Execution Failed",4000);
alert(errMsg);
}
});



}

function addToSecJobList(secjob){


Expand All @@ -74,8 +117,7 @@
$("#exe-sjob").click(function(){
secjobExecStat="<h5 align=\"center\">SecJob Execution</h5><div class=\"collection\"><a href=\"#!\" class=\"collection-item\">TJob Execution Status<div class=\"progress\"><div class=\"determinate\" style=\"width: 0%\"></div></div></a><a href=\"#!\" class=\"collection-item\"> Analyzing Generated HTTP traffic <div class=\"progress\"><div class=\"determinate\" style=\"width: 0%\"></div></div></a><a href=\"#!\" class=\"collection-item\">Insecure URLs </a></div>"
showSecJobExecStat(this,secjobExecStat);
executeTJob();
showReport(this);
executeTJob(secjob.tJobId,this);
});
}

Expand All @@ -84,10 +126,7 @@

$(position).parent().parent().append(exec_stats);
}
function executeTJob(){
}
function getInsecUrls(){
}


//Function that triggers upon clicking tjob creation button
$(document).ready(function(){
Expand Down

0 comments on commit 0376098

Please sign in to comment.