Skip to content

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

Export/Import API key functionality.

Steve Micalleff4e86d676b7e
diff --git a/dyn/opts.tmpl b/dyn/opts.tmpl
index 3a0c5023..4bb9659b 100644
--- a/dyn/opts.tmpl
+++ b/dyn/opts.tmpl
@@ -22,6 +22,15 @@
activeTab = tab;
}
+ function getFile(elemId) {
+ var elem = document.getElementById(elemId);
+ if(elem && document.createEvent) {
+ var evt = document.createEvent("MouseEvents");
+ evt.initEvent("click", true, false);
+ elem.dispatchEvent(evt);
+ }
+ }
+
</script>
<h2>Settings</h2>
% if updated:
@@ -31,12 +40,15 @@
Settings updated. These will take effect the next time you run a scan.
</div>
% endif
-<form class="form" action='${docroot}/savesettings' method='POST'>
+<form class="form" action='${docroot}/savesettings' id=savesettingsform method='POST' enctype="multipart/form-data">
<div style='text-align: left'>
<input type=hidden id='allopts' name='allopts' value=''>
<input type=hidden id='token' name='token' value="${token}">
- <button onClick='clearSettings();' class='btn btn-danger'>Reset to Factory Default</button>
+ <input type="file" name='configFile' id="configFile" style='display:none' onChange='$("#savesettingsform").submit()' />
<button onClick='saveSettings();' class='btn btn-primary'>Save Changes</button>
+ <button onClick='getFile("configFile"); return false;' class='btn btn-info'>Import API Keys</button>
+ <button onClick='javascript:window.location.href="${docroot}/optsexport?pattern=api_key"; return false' class='btn btn-info'>Export API Keys</button>
+ <button onClick='clearSettings();' class='btn btn-danger'>Reset to Factory Default</button>
<br><br>
</div>
diff --git a/sfwebui.py b/sfwebui.py
index 17fba235..d7e4da09 100644
--- a/sfwebui.py
+++ b/sfwebui.py
@@ -401,6 +401,25 @@ class SpiderFootWebUi:
opts.exposed = True
+ # Export configuration
+ def optsexport(self, pattern):
+ sf = SpiderFoot(self.config)
+ conf = sf.configSerialize(self.config)
+ content = ""
+ for opt in sorted(conf):
+ if ":_" in opt or opt.startswith("_"):
+ continue
+ if not pattern:
+ content += opt + "=" + str(conf[opt]) + "\n"
+ else:
+ if pattern in opt:
+ content += opt + "=" + str(conf[opt]) + "\n"
+ cherrypy.response.headers['Content-Disposition'] = 'attachment; filename="SpiderFoot.cfg"'
+ cherrypy.response.headers['Content-Type'] = "text/plain"
+ return content
+
+ optsexport.exposed = True
+
# Settings
def optsraw(self):
ret = dict()
@@ -473,9 +492,25 @@ class SpiderFootWebUi:
scandeletemulti.exposed = True
# Save settings, also used to completely reset them to default
- def savesettings(self, allopts, token):
-# if str(token) != str(self.token):
-# return self.error("Invalid token (" + str(self.token) + ").")
+ def savesettings(self, allopts, token, configFile=None):
+ if str(token) != str(self.token):
+ return self.error("Invalid token (" + str(self.token) + ").")
+
+ if configFile: # configFile seems to get set even if a file isn't uploaded
+ if configFile.file:
+ contents = configFile.file.read()
+ try:
+ tmp = dict()
+ for line in contents.split("\n"):
+ if "=" not in line:
+ continue
+ l = line.strip().split("=")
+ if len(l) == 1:
+ l[1] = ""
+ tmp[l[0]] = l[1]
+ allopts = json.dumps(tmp)
+ except BaseException as e:
+ return self.error("Failed to parse input file. Was it generated from SpiderFoot? (" + str(e) + ")")
try:
dbh = SpiderFootDb(self.config)
@@ -495,7 +530,7 @@ class SpiderFootWebUi:
# the current system config.
sf = SpiderFoot(self.config)
self.config = sf.configUnserialize(cleanopts, currentopts)
- dbh.configSet(sf.configSerialize(currentopts))
+ dbh.configSet(sf.configSerialize(self.config))
except Exception as e:
return self.error("Processing one or more of your inputs failed: " + str(e))
@@ -529,7 +564,7 @@ class SpiderFootWebUi:
# the current system config.
sf = SpiderFoot(self.config)
self.config = sf.configUnserialize(cleanopts, currentopts)
- dbh.configSet(sf.configSerialize(currentopts))
+ dbh.configSet(sf.configSerialize(self.config))
except Exception as e:
return json.dumps(["ERROR", "Processing one or more of your inputs failed: " + str(e)])