Skip to content

Commit 218536e

Browse files
committed
start implementing comments using reporting API
1 parent 86cc163 commit 218536e

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

web/analysis/views.py

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,45 +1977,36 @@ def pcapstream(request, task_id, conntuple):
19771977

19781978
@conditional_login_required(login_required, settings.WEB_AUTHENTICATION)
19791979
def comments(request, task_id):
1980-
if request.method == "POST" and settings.COMMENTS:
1981-
comment = request.POST.get("commentbox", "")
1982-
if not comment:
1983-
return render(request, "error.html", {"error": "No comment provided."})
1980+
if request.method != "POST" or not settings.COMMENTS:
1981+
return render(request, "error.html", {"error": "Invalid Method"})
19841982

1985-
if enabledconf["mongodb"]:
1986-
report = mongo_find_one(
1987-
ANALYSIS_COLL, {INFO_ID_KEY: int(task_id)}, {"info.comments": 1, ID_KEY: 0}, sort=[(ID_KEY, -1)]
1988-
)
1989-
if es_as_db:
1990-
query = es.search(index=get_analysis_index(), query=get_query_by_info_id(task_id))["hits"]["hits"][0]
1991-
report = query["_source"]
1992-
esid = query["_id"]
1993-
esidx = query["_index"]
1994-
if "comments" in report["info"]:
1995-
curcomments = report["info"]["comments"]
1996-
else:
1997-
curcomments = []
1998-
buf = {}
1999-
buf["Timestamp"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
2000-
escape_map = {
2001-
"&": "&",
2002-
'"': """,
2003-
"'": "'",
2004-
"<": "&lt;",
2005-
">": "&gt;",
2006-
"\n": "<br />",
2007-
}
2008-
buf["Data"] = "".join(escape_map.get(thechar, thechar) for thechar in comment)
2009-
# status can be posted/removed
2010-
buf["Status"] = "posted"
2011-
curcomments.insert(0, buf)
2012-
if enabledconf["mongodb"]:
2013-
mongo_update_one(ANALYSIS_COLL, {INFO_ID_KEY: int(task_id)}, {"$set": {"info.comments": curcomments}})
2014-
if es_as_db:
2015-
es.update(index=esidx, id=esid, body={"doc": {"info": {"comments": curcomments}}})
2016-
return redirect("report", task_id=task_id)
1983+
comment = request.POST.get("commentbox", "")
1984+
if not comment:
1985+
return render(request, "error.html", {"error": "No comment provided."})
1986+
1987+
task_id = int(task_id)
1988+
report = reports.summary(task_id)
1989+
if "comments" in report.info:
1990+
curcomments = report["info"]["comments"]
1991+
else:
1992+
curcomments = []
1993+
buf = {}
1994+
buf["Timestamp"] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
1995+
escape_map = {
1996+
"&": "&amp;",
1997+
'"': "&quot;",
1998+
"'": "&apos;",
1999+
"<": "&lt;",
2000+
">": "&gt;",
2001+
"\n": "<br />",
2002+
}
2003+
buf["Data"] = "".join(escape_map.get(thechar, thechar) for thechar in comment)
2004+
# status can be posted/removed
2005+
buf["Status"] = "posted"
2006+
curcomments.insert(0, buf)
20172007

2018-
return render(request, "error.html", {"error": "Invalid Method"})
2008+
# TODO need an info update API for this
2009+
raise NotImplementedError()
20192010

20202011

20212012
@conditional_login_required(login_required, settings.WEB_AUTHENTICATION)

0 commit comments

Comments
 (0)