Skip to content

Commit

Permalink
Update api.py
Browse files Browse the repository at this point in the history
  • Loading branch information
tUn4 authored and jbremer committed Oct 9, 2018
1 parent 4461a4d commit a27e795
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cuckoo/apps/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,9 @@ def tasks_delete(task_id):
@app.route("/v1/tasks/report/<int:task_id>")
@app.route("/tasks/report/<int:task_id>/<report_format>")
@app.route("/v1/tasks/report/<int:task_id>/<report_format>")
def tasks_report(task_id, report_format="json"):
@app.route("/tasks/report/<int:task_id>/<report_format>/<elements>")
@app.route("/v1/tasks/report/<int:task_id>/<report_format>/<elements>")
def tasks_report(task_id, report_format="json", elements=""):
formats = {
"json": "report.json",
"html": "report.html",
Expand Down Expand Up @@ -381,8 +383,17 @@ def tasks_report(task_id, report_format="json"):
return json_error(404, "Report not found")

if report_format == "json":
response = make_response(open(report_path, "rb").read())
response.headers["Content-Type"] = "application/json"
report_content = open(report_path, "rb").read()
if(elements != ""):
try:
from flask import json
response = make_response(json.dumps(json.loads(report_content)[elements]))
response.headers["Content-Type"] = "application/json"
except:
return json_error(404, "'{0}' not found".format(elements))
else:
response = make_response(report_content)
response.headers["Content-Type"] = "application/json"
return response
else:
return open(report_path, "rb").read()
Expand Down

0 comments on commit a27e795

Please sign in to comment.