2016-03-14 20:40:06 +01:00
import json
from url_archiver import url_archiver
misperrors = { ' error ' : ' Error ' }
mispattributes = { ' input ' : [ ' link ' ] , ' output ' : [ ' link ' ] }
moduleinfo = { ' version ' : ' 0.1 ' , ' author ' : ' Alexandre Dulaunoy ' , ' description ' : ' Module to cache web pages of analysis reports, OSINT sources. The module returns a link of the cached page. ' }
2016-03-16 20:02:03 +01:00
moduleconfig = [ ' archivepath ' ]
2016-03-14 20:40:06 +01:00
def handler ( q = False ) :
if q is False :
return False
request = json . loads ( q )
2016-03-16 20:02:03 +01:00
if ( request . get ( ' config ' ) ) :
archive_path = request [ ' config ' ] [ ' archivepath ' ]
else :
archive_path = ' /tmp/ '
2016-03-14 20:40:06 +01:00
if request . get ( ' link ' ) :
tocache = request [ ' link ' ]
archiver = url_archiver . Archive ( archive_path = archive_path )
archiver . fetch ( url = tocache )
mispattributes [ ' output ' ] = [ ' link ' ]
else :
misperrors [ ' error ' ] = " Link is missing "
return misperrors
r = { ' results ' : [ { ' types ' : mispattributes [ ' output ' ] , ' values ' : tocache } ] }
return r
def introspection ( ) :
return mispattributes
def version ( ) :
2016-03-16 20:02:03 +01:00
moduleinfo [ ' config ' ] = moduleconfig
2016-03-14 20:40:06 +01:00
return moduleinfo