Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

sfwebui: Add button to download scan logs as CSV (#1336)

bcolese8045e5b5012
diff --git a/sfwebui.py b/sfwebui.py
index 73290c8f..e4079cd8 100644
--- a/sfwebui.py
+++ b/sfwebui.py
@@ -314,6 +314,44 @@ class SpiderFootWebUi:
# USER INTERFACE PAGES
#
+ @cherrypy.expose
+ def scanexportlogs(self, id, dialect="excel"):
+ """Get scan log
+
+ Args:
+ id (str): scan ID
+ dialect (str): CSV style
+
+ Returns:
+ string: scan logs in CSV format
+ """
+ dbh = SpiderFootDb(self.config)
+
+ try:
+ data = dbh.scanLogs(id, None, None, True)
+ except Exception:
+ return self.error("Scan ID not found.")
+
+ if not data:
+ return self.error("Scan ID not found.")
+
+ fileobj = StringIO()
+ parser = csv.writer(fileobj, dialect=dialect)
+ parser.writerow(["Date", "Component", "Type", "Event", "Event ID"])
+ for row in data:
+ parser.writerow([
+ time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(row[0] / 1000)),
+ str(row[1]),
+ str(row[2]),
+ str(row[3]),
+ row[4]
+ ])
+
+ cherrypy.response.headers['Content-Disposition'] = f"attachment; filename=SpiderFoot-{id}.log.csv"
+ cherrypy.response.headers['Content-Type'] = "application/csv"
+ cherrypy.response.headers['Pragma'] = "no-cache"
+ return fileobj.getvalue().encode('utf-8')
+
@cherrypy.expose
def scaneventresultexport(self, id, type, filetype="csv", dialect="excel"):
"""Get scan event result data in CSV format
diff --git a/spiderfoot/templates/scaninfo.tmpl b/spiderfoot/templates/scaninfo.tmpl
index 5baec44f..13bdbd5d 100644
--- a/spiderfoot/templates/scaninfo.tmpl
+++ b/spiderfoot/templates/scaninfo.tmpl
@@ -34,6 +34,7 @@
</div>
<div class="btn-group pull-right" role="group">
<button id='btn-refresh' rel="tooltip" title="Refresh" class="btn btn-success btn-default" onClick='refresh()'><i class='glyphicon glyphicon-refresh glyphicon glyphicon-white'></i></button>
+ <button id='btn-download-logs' rel="tooltip" data-title="Download Scan Logs" class="btn btn-default download-button" onClick='downloadLogs("${id}")'><i class='glyphicon glyphicon-download-alt glyphicon glyphicon-white'></i></a>
<a id='btn-export' rel="tooltip" data-title="Export Data" class="btn btn-default dropdown-toggle download-button" data-toggle="dropdown"><i class='glyphicon glyphicon-download-alt glyphicon glyphicon-white'></i></a>
<ul class="dropdown-menu">
<li><a class='link' onClick='exportEventData("${id}", currentType, "csv")'>CSV</a></li>
@@ -130,7 +131,7 @@
function navTo(target) {
var targets = [ "btn-browse", "btn-info", "btn-log",
- "btn-export", "btn-viz", "btn-status", "btn-graph" ]
+ "btn-export", "btn-download-logs", "btn-viz", "btn-status", "btn-graph" ]
for (var i = 0; i < targets.length; i++) {
if (targets[i] == target) {
$("#" + targets[i]).addClass("active");
@@ -163,6 +164,7 @@
$("#modifyactions").hide();
$("#loader").show();
$("#btn-export").show();
+ $("#btn-download-logs").hide();
$("#btn-refresh").show();
$("#btn-search").show();
$("#scanreminder").hide();
@@ -220,6 +222,7 @@
$("#scansummary-content").remove();
$("#loader").show();
$("#btn-export").show();
+ $("#btn-download-logs").hide();
$("#btn-refresh").show();
$("#btn-search").hide();
$("#btn-graph").show();
@@ -298,6 +301,7 @@
$("#scansummary-content").remove();
$("#loader").show();
$("#btn-export").hide();
+ $("#btn-download-logs").hide();
$("#btn-refresh").hide();
$("#btn-search").hide();
$("#scanreminder").show();
@@ -391,6 +395,7 @@
$("#loader").show();
$("#btn-search").hide();
$("#btn-export").hide();
+ $("#btn-download-logs").show();
$("#scanreminder").hide();
navTo("btn-log");
refresh = function() { viewScanLog(instanceId); }
@@ -426,6 +431,7 @@
navTo("btn-browse");
$("#loader").show();
$("#btn-export").show();
+ $("#btn-download-logs").hide();
$("#btn-refresh").show();
$("#btn-search").show();
$("#scanreminder").hide();
@@ -463,6 +469,7 @@
$("#loader").show();
navTo("btn-browse");
$("#btn-export").show();
+ $("#btn-download-logs").hide();
$("#btn-refresh").show();
$("#btn-search").show();
$("#customtabview").show();
@@ -648,6 +655,15 @@
}
}
+ function downloadLogs(instanceId) {
+ $("#loader").show();
+ sf.log("Loading logs for scan: " + instanceId);
+ var efr = document.getElementById('exportframe');
+ var urlBase = '${docroot}/scanexportlogs?id=';
+ efr.src = urlBase + instanceId;
+ $("#loader").fadeOut(500);
+ }
+
// Download the data currently being viewed
function exportEventData(instanceId, eventType, fileType) {
$("#loader").show();
@@ -688,6 +704,7 @@
$("#scansummary-content").remove();
$("#loader").show();
$("#btn-export").hide();
+ $("#btn-download-logs").hide();
$("#btn-refresh").show();
$("#btn-search").hide();
$("#scanreminder").hide();