@@ -1977,45 +1977,36 @@ def pcapstream(request, task_id, conntuple):
1977
1977
1978
1978
@conditional_login_required (login_required , settings .WEB_AUTHENTICATION )
1979
1979
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" })
1984
1982
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
- "<" : "<" ,
2005
- ">" : ">" ,
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
+ "&" : "&" ,
1997
+ '"' : """ ,
1998
+ "'" : "'" ,
1999
+ "<" : "<" ,
2000
+ ">" : ">" ,
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 )
2017
2007
2018
- return render (request , "error.html" , {"error" : "Invalid Method" })
2008
+ # TODO need an info update API for this
2009
+ raise NotImplementedError ()
2019
2010
2020
2011
2021
2012
@conditional_login_required (login_required , settings .WEB_AUTHENTICATION )
0 commit comments