Example #1
0
    def scandeletemulti(self, ids, confirm=None):
        """Delete a scan

        Args:
            ids (str): comma separated list of scan IDs
            confirm: TBD
        """

        dbh = SpiderFootDb(self.config)
        names = list()

        for id in ids.split(','):
            res = dbh.scanInstanceGet(id)
            names.append(str(res[0]))
            if res is None:
                return self.error("Scan ID not found (" + id + ").")

            if res[5] in ["RUNNING", "STARTING", "STARTED"]:
                return self.error("You cannot delete running scans.")

        if confirm:
            for id in ids.split(','):
                dbh.scanInstanceDelete(id)
            raise cherrypy.HTTPRedirect("/")

        templ = Template(filename='dyn/scandelete.tmpl', lookup=self.lookup)
        return templ.render(id=None, name=None, ids=ids.split(','), names=names,
                            pageid="SCANLIST", docroot=self.docroot)
Example #2
0
    def scandelete(self, id, confirm=None):
        """Delete a scan

        Args:
            id (str): scan ID
            confirm (str): specify any value (except None) to confirm deletion of the scan
        """

        dbh = SpiderFootDb(self.config)
        res = dbh.scanInstanceGet(id)

        if res is None:
            if cherrypy.request.headers and 'application/json' in cherrypy.request.headers.get('Accept'):
                cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"
                return json.dumps(["ERROR", "Scan ID not found."]).encode('utf-8')

            return self.error("Scan ID not found.")

        if confirm:
            dbh.scanInstanceDelete(id)

            if cherrypy.request.headers and 'application/json' in cherrypy.request.headers.get('Accept'):
                cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"
                return json.dumps(["SUCCESS", ""]).encode('utf-8')

            raise cherrypy.HTTPRedirect("/")

        templ = Template(filename='dyn/scandelete.tmpl', lookup=self.lookup)
        return templ.render(id=id, name=str(res[0]),
                            names=list(), ids=list(),
                            pageid="SCANLIST", docroot=self.docroot)
Example #3
0
    def scandelete(self, id):
        """Delete scan(s)

        Args:
            id (str): comma separated list of scan IDs

        Returns:
            str: JSON response
        """
        if not id:
            return self.jsonify_error('404', "No scan specified")

        dbh = SpiderFootDb(self.config)
        ids = id.split(',')

        for scan_id in ids:
            res = dbh.scanInstanceGet(scan_id)
            if not res:
                return self.jsonify_error('404', f"Scan {id} does not exist")

            if res[5] in ["RUNNING", "STARTING", "STARTED"]:
                return self.jsonify_error('400', f"Scan {id} is {res[5]}. You cannot delete running scans.")

        for scan_id in ids:
            dbh.scanInstanceDelete(scan_id)

        return b""
Example #4
0
    def test_scanInstanceDelete(self):
        """
        Test scanInstanceDelete(self, instanceId)
        """
        sfdb = SpiderFootDb(self.default_options, False)
        instance_id = "example instance id"
        sfdb.scanInstanceDelete(instance_id)

        self.assertEqual('TBD', 'TBD')
    def test_scanInstanceDelete_argument_instanceId_of_invalid_type_should_raise_TypeError(self):
        """
        Test scanInstanceDelete(self, instanceId)
        """
        sfdb = SpiderFootDb(self.default_options, False)

        invalid_types = [None, list(), dict(), int()]
        for invalid_type in invalid_types:
            with self.subTest(invalid_type=invalid_type):
                with self.assertRaises(TypeError):
                    sfdb.scanInstanceDelete(invalid_type)