Remove bin script, use cleaner way. Fix last commit.

pull/40/head
Raphaël Vinot 2016-08-12 12:35:33 +02:00
parent 99749d4de2
commit 59b16950f7
12 changed files with 34 additions and 39 deletions

View File

@ -10,3 +10,5 @@ pyeupi
ipasn-redis
asnhistory
git+https://github.com/Rafiot/uwhoisd.git@testing#egg=uwhois&subdirectory=client
pillow
pytesseract

View File

@ -1,26 +0,0 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Core MISP expansion modules loader and web service
#
# Copyright (C) 2016 Alexandre Dulaunoy
# Copyright (C) 2016 CIRCL - Computer Incident Response Center Luxembourg
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import sys
from misp_modules import main
if __name__ == '__main__':
sys.exit(main())

View File

@ -32,7 +32,7 @@ import argparse
import re
try:
from . import modules
from .modules import *
HAS_PACKAGE_MODULES = True
except Exception as e:
print(e)
@ -47,6 +47,7 @@ except Exception as e:
log = logging.getLogger('misp-modules')
def handle_signal(sig, frame):
IOLoop.instance().add_callback(IOLoop.instance().stop)
@ -95,8 +96,12 @@ def load_package_helpers():
continue
helpername = path.replace('misp_modules.helpers.', '')
mhandlers[helpername] = helper
helpers.append(helpername)
log.info('Helper loaded {}'.format(helpername))
selftest = mhandlers[helpername].selftest()
if selftest is None:
helpers.append(helpername)
log.info('Helper loaded {}'.format(helpername))
else:
log.info('Helpers failed {} due to {}'.format(helpername, selftest))
return mhandlers, helpers
@ -113,7 +118,7 @@ def load_modules(mod_dir):
if filename == '__init__.py':
continue
modulename = filename.split(".")[0]
moduletype = os.path.split(modulesdir)[1]
moduletype = os.path.split(mod_dir)[1]
try:
mhandlers[modulename] = importlib.import_module(os.path.basename(root) + '.' + modulename)
except Exception as e:
@ -144,8 +149,10 @@ def load_package_modules():
class ListModules(tornado.web.RequestHandler):
def get(self):
global mhandlers
global loaded_modules
ret = []
for module in modules:
for module in loaded_modules:
x = {}
x['name'] = module
x['type'] = mhandlers['type:' + module]
@ -158,17 +165,19 @@ class ListModules(tornado.web.RequestHandler):
class QueryModule(tornado.web.RequestHandler):
def post(self):
global mhandlers
jsonpayload = self.request.body.decode('utf-8')
x = json.loads(jsonpayload)
log.debug('MISP QueryModule request {0}'.format(jsonpayload))
ret = mhandlers[x['module']].handler(q=jsonpayload)
self.write(json.dumps(ret))
def main():
global mhandlers
global loaded_modules
signal.signal(signal.SIGINT, handle_signal)
signal.signal(signal.SIGTERM, handle_signal)
if os.path.dirname(__file__) in ['.', '']:
os.chdir('../')
argParser = argparse.ArgumentParser(description='misp-modules server')
argParser.add_argument('-t', default=False, action='store_true', help='Test mode')
argParser.add_argument('-s', default=False, action='store_true', help='Run a system install (package installed via pip)')
@ -180,12 +189,13 @@ def main():
log = init_logger()
if args.s:
load_package_helpers()
mhandlers, modules = load_package_modules()
mhandlers, loaded_modules = load_package_modules()
else:
modulesdir = 'misp_modules/modules'
helpersdir = 'misp_modules/helpers'
os.chdir(os.path.dirname(__file__))
modulesdir = 'modules'
helpersdir = 'helpers'
load_helpers(helpersdir=helpersdir)
mhandlers, modules = load_modules(modulesdir)
mhandlers, loaded_modules = load_modules(modulesdir)
service = [(r'/modules', ListModules), (r'/query', QueryModule)]
application = tornado.web.Application(service)

View File

@ -1 +1,3 @@
from .expansion import *
from .import_mod import *
from .export_mod import *

View File

@ -1,2 +1,2 @@
__all__ = ['asn_history', 'circl_passivedns', 'circl_passivessl', 'cve', 'dns',
'eupi', 'ipasn', 'passivetotal', 'sourcecache']
'eupi', 'ipasn', 'passivetotal', 'sourcecache', 'whois']

View File

@ -1,7 +1,10 @@
# -*- coding: utf-8 -*-
import json
from uwhois import Uwhois
try:
from uwhois import Uwhois
except ImportError:
print("uwhois module not installed.")
misperrors = {'error': 'Error'}
mispattributes = {'input': ['domain', 'ip-src', 'ip-dst'], 'output': ['freetext']}

View File

@ -0,0 +1 @@
__all__ = ['testexport']

View File

@ -0,0 +1 @@
__all__ = ['testimport', 'ocr']

View File

@ -33,5 +33,7 @@ setup(
'pyeupi',
'ipasn-redis',
'asnhistory',
'pillow',
'pytesseract',
]
)