mirror of https://github.com/MISP/misp-modules
fix: Avoid issues when some config fields are not set
parent
752fbde5ee
commit
dc7463a67e
|
@ -70,11 +70,15 @@ def handler(q=False):
|
||||||
r = {"results": []}
|
r = {"results": []}
|
||||||
|
|
||||||
if request.get('config'):
|
if request.get('config'):
|
||||||
if request['config'].get('cache').lower() == "yes":
|
if request['config'].get('cache') and request['config']['cache'].lower() == "yes":
|
||||||
submitcache = True
|
submitcache = True
|
||||||
if len(request['config'].get('cache_directory').strip()) > 0:
|
if request['config'].get('import_related_hashes') and request['config']['import_related_hashes'].lower() == "yes":
|
||||||
if os.access(request['config'].get('cache_directory'), os.W_OK):
|
import_related_hashes = True
|
||||||
submitcache_directory = request['config'].get('cache_directory')
|
if submitcache:
|
||||||
|
cache_directory = request['config'].get('cache_directory')
|
||||||
|
if cache_directory and len(cache_directory) > 0:
|
||||||
|
if os.access(cache_directory, os.W_OK):
|
||||||
|
submitcache_directory = cache_directory
|
||||||
else:
|
else:
|
||||||
ErrorMSG = "Cache directory is not writable. Please fix it before."
|
ErrorMSG = "Cache directory is not writable. Please fix it before."
|
||||||
log.debug(str(ErrorMSG))
|
log.debug(str(ErrorMSG))
|
||||||
|
@ -86,12 +90,10 @@ def handler(q=False):
|
||||||
misperrors['error'] = ErrorMSG
|
misperrors['error'] = ErrorMSG
|
||||||
return misperrors
|
return misperrors
|
||||||
else:
|
else:
|
||||||
log.debug("Cache option is set to " + request['config'].get('cache') + ". You are not using the internal cache system and this is NOT recommended!")
|
log.debug("Cache option is set to " + str(submitcache) + ". You are not using the internal cache system and this is NOT recommended!")
|
||||||
log.debug("Please, consider to turn on the cache setting it to 'Yes' and specifing a writable directory for the cache directory option.")
|
log.debug("Please, consider to turn on the cache setting it to 'Yes' and specifing a writable directory for the cache directory option.")
|
||||||
try:
|
try:
|
||||||
response = apiosintDS.request(entities=tosubmit, cache=submitcache, cachedirectory=submitcache_directory, verbose=True)
|
response = apiosintDS.request(entities=tosubmit, cache=submitcache, cachedirectory=submitcache_directory, verbose=True)
|
||||||
if request['config'].get('import_related_hashes').lower() == "yes":
|
|
||||||
import_related_hashes = True
|
|
||||||
r["results"] += reversed(apiosintParser(response, import_related_hashes))
|
r["results"] += reversed(apiosintParser(response, import_related_hashes))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
log.debug(str(e))
|
log.debug(str(e))
|
||||||
|
|
Loading…
Reference in New Issue