diff --git a/examples/copy_list.py b/examples/copy_list.py index e8021e3..87e31b4 100644 --- a/examples/copy_list.py +++ b/examples/copy_list.py @@ -1,24 +1,30 @@ #!/usr/bin/python # -*- coding: utf-8 -*- +import sys from pymisp import PyMISP -from keys import src, dest +from keys import cert, priv -url_source = 'https://misp.circl.lu' -url_dest = 'https://misppriv.circl.lu' -cert_source = 'misp.circl.lu.crt' -cert_dest = 'misppriv.circl.lu.crt' +url_cert = 'https://misp.circl.lu' +url_priv = 'https://misppriv.circl.lu' +cert_cert = 'misp.circl.lu.crt' +cert_priv = 'misppriv.circl.lu.crt' source = None destination = None -def init(): +def init(cert_to_priv=True): global source global destination - source = PyMISP(url_source, src, cert_source, 'xml') - destination = PyMISP(url_dest, dest, cert_dest, 'xml') + print cert_to_priv + if cert_to_priv: + source = PyMISP(url_cert, cert, cert_cert, 'xml') + destination = PyMISP(url_priv, priv, cert_priv, 'xml') + else: + source = PyMISP(url_priv, priv, cert_priv, 'xml') + destination = PyMISP(url_cert, cert, cert_cert, 'xml') def _to_utf8(request): @@ -39,9 +45,25 @@ def copy_event(event_id): def list_copy(filename): with open(filename, 'r') as f: for l in f: - l = int(l.strip()) - print l - copy_event(l) + copy(l) + + +def loop_copy(): + while True: + line = sys.stdin.readline() + copy(line) + + +def copy(eventid): + eventid = eventid.strip() + if len(eventid) == 0 or not eventid.isdigit(): + print 'empty line or NaN.' + return + eventid = int(eventid) + print eventid, 'copying...' + r = copy_event(eventid) + print r.text + print eventid, 'done.' def export_our_org(): @@ -52,8 +74,16 @@ if __name__ == '__main__': import argparse parser = argparse.ArgumentParser( description='Copy the events from one MISP instance to an other.') - parser.add_argument('-f', '--filename', type=str, required=True, + parser.add_argument('-f', '--filename', type=str, help='File containing a list of event id.') + parser.add_argument( + '-l', '--loop', action='store_true', + help='Endless loop: eventid in the terminal and it will be copied.') + parser.add_argument('--priv_to_cert', action='store_false', default=True, + help='Copy from MISP priv to MISP CERT.') args = parser.parse_args() - init() - list_copy(args.filename) + init(args.priv_to_cert) + if args.filename is not None: + list_copy(args.filename) + else: + loop_copy()