SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
sfwebui: Merge scandelete and scandeletemulti URL routes into scandelete (#1196)
bcolesd55496f69f42
diff --git a/dyn/scandelete.tmpl b/dyn/scandelete.tmplindex 5c2fd2b3..ccec8651 100644--- a/dyn/scandelete.tmpl+++ b/dyn/scandelete.tmpl@@ -2,20 +2,16 @@<div class="alert alert-danger"><h4>Confirm Deletion</h4><br>-% if id != None:-Please confirm you wish to delete the scan '${name}'<br><br>-<a class='btn btn-danger' href='${docroot}/scandelete?id=${id}&confirm=1'>Confirm Deletion</a>-% endif-% if len(ids) > 0:+% if len(id) > 0:Please confirm you wish to delete the scans:<br /><ul>-% for nm in names:- <li>${nm}</li>+% for scan_name in names:+ <li>${scan_name}</li>% endfor-<% idlist = ','.join(ids) %>+<% idlist = ','.join(id) %></ul><br />-<a class='btn btn-danger' href='${docroot}/scandeletemulti?ids=${idlist}&confirm=1'>Confirm Deletion</a>+<a class='btn btn-danger' href='${docroot}/scandelete?id=${idlist}&confirm=1'>Confirm Deletion</a>% endif</div><%include file="FOOTER.tmpl"/>diff --git a/sfwebui.py b/sfwebui.pyindex 1469da86..9c174cdb 100644--- a/sfwebui.py+++ b/sfwebui.py@@ -723,31 +723,38 @@ class SpiderFootWebUi:return templ.render(message=message, docroot=self.docroot, version=__version__)def scandelete(self, id, confirm=None):- """Delete a scan+ """Delete scan(s)Args:- id (str): scan ID+ id (str): comma separated list of scan IDsconfirm (str): specify any value (except None) to confirm deletion of the scanReturns:- None+ str: JSON responseRaises:HTTPRedirect: redirect to scan list page"""dbh = SpiderFootDb(self.config)- res = dbh.scanInstanceGet(id)+ names = list()+ ids = id.split(',')- 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')+ for scan_id in ids:+ res = dbh.scanInstanceGet(scan_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.")+ names.append(str(res[0]))- return self.error("Scan ID not found.")+ if res[5] in ["RUNNING", "STARTING", "STARTED"]:+ return self.error("You cannot delete running scans.")if confirm:- dbh.scanInstanceDelete(id)+ for scan_id in ids:+ dbh.scanInstanceDelete(scan_id)if cherrypy.request.headers and 'application/json' in cherrypy.request.headers.get('Accept'):cherrypy.response.headers['Content-Type'] = "application/json; charset=utf-8"@@ -756,51 +763,10 @@ class SpiderFootWebUi:raise cherrypy.HTTPRedirect(f"{self.docroot}/")templ = Template(filename='dyn/scandelete.tmpl', lookup=self.lookup)- return templ.render(id=id, name=str(res[0]), version=__version__,- names=list(), ids=list(),- pageid="SCANLIST", docroot=self.docroot)+ return templ.render(id=ids, names=names, pageid="SCANLIST", docroot=self.docroot, version=__version__)scandelete.exposed = True- def scandeletemulti(self, ids, confirm=None):- """Delete a scan-- Args:- ids (str): comma separated list of scan IDs- confirm: TBD-- Returns:- None-- Raises:- HTTPRedirect: redirect to scan list page- """-- dbh = SpiderFootDb(self.config)- names = list()-- for id in ids.split(','):- res = dbh.scanInstanceGet(id)- if not res:- continue- 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(f"{self.docroot}/")-- 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, version=__version__)-- scandeletemulti.exposed = True-def savesettings(self, allopts, token, configFile=None):"""Save settings, also used to completely reset them to defaultdiff --git a/static/js/spiderfoot.scanlist.js b/static/js/spiderfoot.scanlist.jsindex 5e668647..2c4ebe1f 100644--- a/static/js/spiderfoot.scanlist.js+++ b/static/js/spiderfoot.scanlist.js@@ -60,7 +60,7 @@if (ids != false) {sf.log("Deleting scans: " + ids.join(','));- window.location.href = docroot + '/scandeletemulti?ids=' + ids.join(',');+ window.location.href = docroot + '/scandelete?id=' + ids.join(',');}}diff --git a/test/unit/test_spiderfootwebui.py b/test/unit/test_spiderfootwebui.pyindex 475ae2d3..0f99f285 100644--- a/test/unit/test_spiderfootwebui.py+++ b/test/unit/test_spiderfootwebui.py@@ -273,16 +273,7 @@ class TestSpiderFootWebUi(unittest.TestCase):sfwebui = SpiderFootWebUi(self.web_default_options, opts)scan_delete = sfwebui.scandelete("example scan id", None)self.assertIsInstance(scan_delete, str)-- @unittest.skip("todo")- def test_scandeletemulti(self):- """- Test scandeletemulti(self, ids, confirm=None)- """- opts = self.default_options- opts['__modules__'] = dict()- sfwebui = SpiderFootWebUi(self.web_default_options, opts)- scan_delete = sfwebui.scandeletemulti("example scan id", None)+ scan_delete = sfwebui.scandelete("example scan id", 1)self.assertIsInstance(scan_delete, str)@unittest.skip("todo")