Skip to content

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

sfwebui: add sf.log() JavaScript logging function

Brendan Colesa170aa5739d7
diff --git a/dyn/scaninfo.tmpl b/dyn/scaninfo.tmpl
index 02082755..85b23900 100644
--- a/dyn/scaninfo.tmpl
+++ b/dyn/scaninfo.tmpl
@@ -661,6 +661,7 @@
}
if (currentSection == "btn-graph") {
+ sf.log("Loading visualisation for scan: " + instanceId);
efr.src = '${docroot}/scanviz?id=' + instanceId + '&gexf=1';
}
@@ -733,12 +734,12 @@
var status = document.getElementById("scanstatusbadge").innerHTML;
if (status == "ERROR-FAILED" || status == "FINISHED" || status == "ABORTED") {
- console.log("Scan is " + status);
+ sf.log("Scan is " + status);
clearInterval(refreshSummaryInterval);
return;
}
- console.log("Scan is " + status + ". Refreshing scan summary ...");
+ sf.log("Scan is " + status + ". Refreshing scan summary ...");
for (var i = 0; i < dataloaders.length; i++) {
if (!loadersrunning) {
diff --git a/static/js/spiderfoot.js b/static/js/spiderfoot.js
index d5c79918..c8bef72b 100644
--- a/static/js/spiderfoot.js
+++ b/static/js/spiderfoot.js
@@ -12,7 +12,8 @@
var sf = {}
sf.genericError = function(message) {
- alert("Failure: " + message);
+ sf.log(message);
+ alert("Failure: " + message);
}
sf.replace_sfurltag = function(data) {
@@ -92,3 +93,17 @@ sf.updateTooltips = function() {
}
});
}
+
+sf.log = function(message) {
+ if (typeof console == "object" && typeof console.log == "function") {
+ var currentdate = new Date();
+ var pad = function(n){return ("0" + n).slice(-2);}
+ var datetime = currentdate.getFullYear() + "-"
+ + pad(currentdate.getMonth()+1) + "-"
+ + pad(currentdate.getDate()) + " "
+ + pad(currentdate.getHours()) + ":"
+ + pad(currentdate.getMinutes()) + ":"
+ + pad(currentdate.getSeconds());
+ console.log('[' + datetime + '] ' + message);
+ }
+}
diff --git a/static/js/spiderfoot.scanlist.js b/static/js/spiderfoot.scanlist.js
index 0d3884d9..9b642dea 100644
--- a/static/js/spiderfoot.scanlist.js
+++ b/static/js/spiderfoot.scanlist.js
@@ -38,6 +38,7 @@
});
if (ids.length == 0) {
+ sf.log("You need to select at least one scan.");
alert("You need to select at least one scan.");
return false;
}
@@ -49,6 +50,7 @@
ids = getSelected();
if (ids != false) {
+ sf.log("Stopping scans: " + ids.join(','));
window.location.href = docroot + '/stopscanmulti?ids=' + ids.join(',');
}
}
@@ -57,6 +59,7 @@
ids = getSelected();
if (ids != false) {
+ sf.log("Deleting scans: " + ids.join(','));
window.location.href = docroot + '/scandeletemulti?ids=' + ids.join(',');
}
}
@@ -65,6 +68,7 @@
ids = getSelected();
if (ids != false) {
+ sf.log("Re-running scans: " + ids.join(','));
window.location.href = docroot + '/rerunscanmulti?ids=' + ids.join(',');
}
}
@@ -73,6 +77,7 @@
ids = getSelected();
if (!ids) {
+ sf.log("Error: no scan(s) selected");
return;
}
@@ -80,16 +85,19 @@
var efr = document.getElementById('exportframe');
switch(type) {
case "gexf":
+ sf.log("Exporting scans as " + type + ": " + ids.join(','));
efr.src = docroot + '/scanvizmulti?ids=' + ids.join(',');
break;
case "csv":
+ sf.log("Exporting scans as " + type + ": " + ids.join(','));
efr.src = docroot + '/scaneventresultexportmulti?ids=' + ids.join(',');
break;
case "json":
+ sf.log("Exporting scans as " + type + ": " + ids.join(','));
efr.src = docroot + '/scanexportjsonmulti?ids=' + ids.join(',');
break;
default:
- console.log("Invalid export type");
+ sf.log("Error: Invalid export type: " + type);
}
$("#loader").fadeOut(500);
}