def get_sc4(sc4, itemtype): try: alt = get_alt(itemtype) if alt == 'dashboards': alt2 = 'tabs' else: alt2 = alt url = sc4['url'] token = sc4['token'] cookie = str(sc4['sessionID']) result = connect.sc4_connect(itemtype, 'init', url=url, token=token, cookie=cookie) if result is None: print "There are no SC4 %s for this server instance" % alt return None print "\n\t {ID, Name, Description}" for v in result[alt2]: print "\t {"+str(v['id'])+","+str(v['name'])+","+str(v['description'])+"}" return result except Exception, e: print "\nError: " + str(e) return
def export_sc4(sc4, itemtype, all=None): try: alt = get_alt(itemtype) url = sc4['url'] token = sc4['token'] cookie = str(sc4['sessionID']) if not os.path.exists('sc4/'+alt): os.makedirs('sc4/'+alt) response = connect.sc4_connect(itemtype, 'init', url=url, token=token, cookie=cookie) if all is True: sc4Exportid = 'all' else: sc4Exportid = raw_input("\nPlease enter the ID of the %s you wish to export " "(type \"all\" to export all): " % itemtype) if alt == 'dashboards': alt2 = 'tabs' else: alt2 = alt if sc4Exportid == 'all': for v in response[alt2]: input = {'id': v['id']} print "Exporting %s %s" % (itemtype, v['id']) action = 'export' if itemtype == 'dashboard': input = {'id': v['id'], 'exportType': 'full'} action = 'exportTab' elif itemtype == 'policy': action = 'exportNessusPolicy' data = connect.sc4_connect(itemtype, action, input, url=url, token=token, cookie=cookie) with open('sc4/'+alt+'/'+v['id']+'.xml', 'w') as f: f.write(data) return else: for v in response[alt2]: if v['id'] == sc4Exportid: input = {'id': v['id']} print "Exporting %s %s" % (itemtype, v['id']) action = 'export' if itemtype == 'dashboard': input = {'id': v['id'], 'exportType': 'full'} action = 'exportTab' elif itemtype == 'policy': action = 'exportNessusPolicy' data = connect.sc4_connect(itemtype, action, input, url=url, token=token, cookie=cookie) with open('sc4/'+alt+'/'+v['id']+'.xml', 'w')as f: f.write(data) return except Exception, e: print "\nError: " + str(e) return
def import_sc4(sc4, itemtype, all=None): try: alt = get_alt(itemtype) if not os.path.exists('sc4/'+alt): if not os.path.exists('sc5/'+alt): print "There are no %s to import" % itemtype url = sc4['url'] token = sc4['token'] cookie = str(sc4['sessionID']) if all is True: sc4Import = 'all' else: sc4Import = raw_input("\nPlease enter the ID and version of the %s you wish to import, " "type \"all\" to import all (Example: sc4/1 or sc5/2): ") % type print "" if sc4Import == 'all': files = glob.glob('sc4/'+alt+'/*.xml') files = files + glob.glob('sc5/'+alt+'/*.xml') for v in files: print "Importing "+v with open(v, 'rb') as in_file: file_content = in_file.read() content = connect.sc4_connect('file', 'upload', url=url, token=token, cookie=cookie, filename=v, filecontent=file_content) action = 'import' if itemtype == 'dashboard': action = 'importTab' elif itemtype == 'policy': action = 'importNessusPolicy' connect.sc4_connect(itemtype, action, input={'filename': content}, url=url, token=token, cookie=cookie) return else: sc4Import = sc4Import.split('\\') file_name = sc4Import[0]+'/'+alt+'/'+sc4Import[1]+'.xml' print "\nImporting "+file_name with open(file_name, 'rb') as in_file: file_content = in_file.read() content = connect.sc4_connect('file', 'upload', url=url, token=token, cookie=cookie, filename=file_name, filecontent=file_content) action = 'import' if itemtype == 'dashboard': action = 'importTab' elif itemtype == 'policy': action = 'importNessusPolicy' connect.sc4_connect(itemtype, action, input={'filename': content}, url=url, token=token, cookie=cookie) return except Exception, e: print "\nError: " + str(e) return