add export-import of a list

pull/1/head
Raphaël Vinot 2014-04-14 19:18:12 +02:00
parent 93ddd4cf50
commit 07b66ad05f
2 changed files with 28 additions and 9 deletions

View File

@ -99,7 +99,7 @@ class PyMISP(object):
""" """
Search via the Rest API Search via the Rest API
""" """
search = self.url + '/events/restSearch/download/{}/{}/{}/{}/{}' search = self.url + '/restSearch/download/{}/{}/{}/{}/{}'
val = self.__prepare_rest_search(values, not_values).replace('/', '|') val = self.__prepare_rest_search(values, not_values).replace('/', '|')
tag = self.__prepare_rest_search(tags, not_tags).replace(':', ';') tag = self.__prepare_rest_search(tags, not_tags).replace(':', ';')
if len(val) == 0: if len(val) == 0:

View File

@ -10,22 +10,41 @@ url_dest = 'https://misppriv.circl.lu'
source = None source = None
destination = None destination = None
def init(): def init():
global source global source
global destination global destination
source = PyMISP(url_source, src, 'xml') source = PyMISP(url_source, src, 'xml')
destination = PyMISP(url_dest, dest, 'xml') destination = PyMISP(url_dest, dest, 'xml')
def _to_utf8(request):
to_return = None
if 'json' in request.headers['content-type']:
to_return = request.json()
else:
to_return = request.text.encode('utf-8')
return to_return
def copy_event(event_id): def copy_event(event_id):
r_src = source.get_event(event_id) r_src = source.get_event(event_id)
if 'json' in r_src.headers['content-type']: to_send = _to_utf8(r_src)
to_send = r_src.json() return destination.add_event(to_send)
else:
to_send = r_src.text.encode('utf-8')
r_dst = destination.add_event(to_send) def export_osint():
#print r_dst.text # Warning: does not exports the samples/attachements
osint = source.search(tags='OSINT')
return _to_utf8(osint)
def list_copy(filename):
with open(filename, 'r') as f:
for l in f:
l = int(l.strip())
copy_event(l)
if __name__ == '__main__': if __name__ == '__main__':
init() init()
copy_event(0000) list_copy('list')