Exemple #1
0
 def _store_in_db(self, scan, reaper=False, notes=None, tags=None):
   if reaper and not self._getSetting("reaper.store", False):
     return
   # Hash calculation to prevent duplicates
   sha1=codecs.encode(hashlib.sha1(json.dumps(scan).encode('utf-8')).digest(), "hex").decode("utf-8")
   if not db.p_queryData(self.collection, {'sha1': sha1}):
     data={"scan": scan, "sha1": sha1}
     if type(notes) == str: data["notes"] = notes
     if type(tags) == list: data["tags"]  = tags
     db.p_addEntry(self.collection, data)
     return True
   return False
Exemple #2
0
 def onCVEAction(self, cve, action, **args):
   if args["current_user"].is_authenticated():
     if   action == "save":
       data = db.p_queryOne(self.collectionName, {'cve': cve})
       user = args["current_user"].get_id()
       # Ensure the entry exists
       if not data: db.p_addEntry(self.collectionName, {"cve": cve, "notes": []})
       # Get note if exists:
       self._deleteIfExists(cve, user, int(args["fields"]["id"][0]))
       # Add note
       nid = db.p_readSetting(self.collectionName, "last_note") + 1
       db.p_addToList(self.collectionName, {'cve': cve}, "notes", {'id': nid, 'user': user, 'notes': args["fields"]["text"][0]})
       # Update last note id
       db.p_writeSetting(self.collectionName, "last_note", nid)
       return True
     elif action == "delete":
       user = args["current_user"].get_id()
       self._deleteIfExists(cve, user, int(args["fields"]["id"][0]))
       return True