File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python
2+
3+ class NmapDBPlugin (object ):
4+ def __init__ (self ):
5+ self .dbname = 'nmapdb'
6+ self .store = 'reports'
7+
8+ def db_insert (self , dict_data ):
9+ raise NotImplementedError
10+ def db_update (self , id ):
11+ raise NotImplementedError
12+ def db_delete (self , id ):
13+ raise NotImplementedError
14+ def db_get (self , id ):
15+ raise NotImplementedError
16+ def db_find (self , key ):
17+ raise NotImplementedError
Original file line number Diff line number Diff line change 11#!/usr/bin/env python
22from libnmap .plugins .dbplugin import NmapDBPlugin
33from pymongo import MongoClient
4+ from bson .objectid import ObjectId
45
56class NmapMongoPlugin (NmapDBPlugin ):
67 def __init__ (self , ** kwargs ):
@@ -10,3 +11,20 @@ def __init__(self, **kwargs):
1011
1112 def db_insert (self , dict_data ):
1213 self .collection .insert (dict_data )
14+
15+ def db_get (self , report_id = None ):
16+ rid = report_id
17+ if report_id is not None and isinstance (report_id , str ):
18+ rid = ObjectId (report_id )
19+
20+ if isinstance (rid , ObjectId ):
21+ r = self .collection .find ({ '_id' : rid })
22+ else :
23+ r = self .collection .find ()
24+ return r
25+
26+ def db_delete (self , report_id = None ):
27+ if report_id is not None and isinstance (report_id , str ):
28+ ir = self .collection .remove ({ '_id' : ObjectId (report_id )})
29+ else :
30+ r = self .collection .remove ({ '_id' : report_id })
You can’t perform that action at this time.
0 commit comments