Пример #1
0
 def do_list(self, args):
     try:
         # call UForge API
         printer.out("Getting scans for [" + self.login + "] ...")
         myScannedInstances = self.api.Users(self.login).Scannedinstances.Getall(Includescans="true")
         myScannedInstances = myScannedInstances.scannedInstances.scannedInstance
         if myScannedInstances is None or len(myScannedInstances) == 0:
             printer.out("No scans available")
             return
         print scan_utils.scan_table(myScannedInstances).draw() + "\n"
         printer.out("Found " + str(len(myScannedInstances)) + " scans")
     except ArgumentParserError as e:
         printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
         self.help_list()
     except Exception as e:
         return hammr_utils.handle_uforge_exception(e)
Пример #2
0
 def do_delete(self, args):
     try:
         doParser = self.arg_delete()
         try:
             doArgs = doParser.parse_args(shlex.split(args))
         except SystemExit as e:
             return
         # call UForge API
         searchedScanType = 'scan'
         extraInfo = "Retrieving scan with id [" + doArgs.id + "] ..."
         if doArgs.scantype:
             if doArgs.scantype != 'scan' and doArgs.scantype != 'instance' and doArgs.scantype != 'all':
                 printer.out(
                     "ERROR: scantype can only be 'scan', 'instance' or 'all' not: '" + doArgs.scantype + "'",
                     printer.ERROR)
                 return
             searchedScanType = doArgs.scantype
         if searchedScanType != 'instance' and doArgs.scansonly:
             printer.out(
                 "ERROR: 'scansonly' can only be used with 'instance' scantype but not with '" + searchedScanType + "'",
                 printer.ERROR)
             return
         if searchedScanType == 'instance':
             extraInfo = "Retrieving scan instance with id [" + doArgs.id + "] ..."
         else:
             if searchedScanType == 'all':
                 extraInfo = 'Retrieving all scan instances and associated scans'
         printer.out(extraInfo)
         myScannedInstances = self.api.Users(self.login).Scannedinstances.Getall(Includescans="true")
         myScannedInstances = myScannedInstances.scannedInstances.scannedInstance
         if myScannedInstances is None or len(myScannedInstances) == 0:
             printer.out("Nothing found")
             return
         if searchedScanType == 'all':
             print scan_utils.scan_table(myScannedInstances).draw() + "\n"
             if generics_utils.query_yes_no("Do you really want to delete all scan instances"):
                 printer.out("Please wait...")
                 self.api.Users(self.login).Scannedinstances().Deleteall()
                 printer.out("All instances and scans deleted", printer.OK)
             return
         for myScannedInstance in myScannedInstances:
             if searchedScanType == 'instance' and str(myScannedInstance.dbId) == doArgs.id:
                 print scan_utils.scan_table([myScannedInstance]).draw() + "\n"
                 if doArgs.scansonly:
                     extraInfo = "Do you really want to delete all scans in instance with id " + str(doArgs.id)
                 else:
                     extraInfo = "Do you really want to delete scan instance with id " + str(
                         doArgs.id) + " and all associated scans"
                 if generics_utils.query_yes_no(extraInfo):
                     printer.out("Please wait...")
                     if doArgs.scansonly:
                         self.api.Users(self.login).Scannedinstances(doArgs.id).Scans().Deleteall()
                         printer.out("Instance scans deleted", printer.OK)
                     else:
                         self.api.Users(self.login).Scannedinstances(doArgs.id).Delete()
                         printer.out("Instance deleted", printer.OK)
                     return
                 return
             if searchedScanType == 'scan':
                 for scan in myScannedInstance.scans.scan:
                     if str(scan.dbId) == doArgs.id:
                         print scan_utils.scan_table([myScannedInstance], scan).draw() + "\n"
                         if generics_utils.query_yes_no(
                                         "Do you really want to delete scan with id " + str(doArgs.id)):
                             printer.out("Please wait...")
                             self.api.Users(self.login).Scannedinstances(myScannedInstance.dbId).Scans(
                                 doArgs.id).Delete()
                             printer.out("Scan deleted", printer.OK)
                         return
         printer.out("Scan not found", printer.ERROR)
     except ArgumentParserError as e:
         printer.out("ERROR: In Arguments: " + str(e), printer.ERROR)
         self.help_delete()
     except Exception as e:
         return hammr_utils.handle_uforge_exception(e)