Skip to content

Commit 0e0c428

Browse files
committed
WIP
1 parent cdee3fc commit 0e0c428

File tree

1 file changed

+19
-41
lines changed

1 file changed

+19
-41
lines changed

misp_modules/__init__.py

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
#
1818
# You should have received a copy of the GNU Affero General Public License
1919
# along with this program. If not, see <http://www.gnu.org/licenses/>.
20-
21-
import abc
2220
import pathlib
2321
import signal
2422
import sys
@@ -189,38 +187,16 @@ def main():
189187
signal.signal(signal.SIGINT, handle_signal)
190188
signal.signal(signal.SIGTERM, handle_signal)
191189

192-
arg_parser = argparse.ArgumentParser(
193-
description="misp-modules server", formatter_class=argparse.RawTextHelpFormatter
194-
)
190+
arg_parser = argparse.ArgumentParser(description="misp-modules", formatter_class=argparse.RawTextHelpFormatter)
195191
arg_parser.add_argument("-t", "--test", default=False, action="store_true", help="Test mode")
196192
arg_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debugging")
197-
arg_parser.add_argument("-p", "--port", default=6666, help="misp-modules TCP port (default 6666)")
198-
arg_parser.add_argument(
199-
"-l",
200-
"--listen",
201-
default="localhost",
202-
help="misp-modules listen address (default localhost)",
203-
)
204-
arg_parser.add_argument(
205-
"-m",
206-
default=[],
207-
action="append",
208-
help="Register a custom module",
209-
)
210-
arg_parser.add_argument(
211-
"--devel",
212-
default=False,
213-
action="store_true",
214-
help="""Start in development mode, enable debug, start only the module(s) listed in -m.\nExample: -m misp_modules.modules.expansion.bgpranking""",
215-
)
193+
arg_parser.add_argument("-p", "--port", default=6666, help="port (default 6666)")
194+
arg_parser.add_argument("-l", "--listen", default="localhost", help="address (default localhost)")
195+
arg_parser.add_argument("-c", "--custom", default=None, help="custom root")
216196
args = arg_parser.parse_args()
217197

218198
# Initialize
219-
if args.devel:
220-
init_logger(debug=True)
221-
log.info("Launch MISP modules server in development mode. Enable debug, load a list of modules is -m is used.")
222-
else:
223-
init_logger(debug=args.debug)
199+
init_logger(debug=args.debug)
224200

225201
# Load helpers
226202
for helper in iterate_helpers(importlib.resources.files(__package__).joinpath(HELPERS_DIR)):
@@ -255,18 +231,20 @@ def main():
255231
log.info("MISP module %s (type=%s) imported", module_name, module_type.name)
256232

257233
# Load custom modules
258-
for module_type, module in iterate_modules(pathlib.Path("/Users/ortolanis/Downloads/test/")):
259-
# remove extension from name
260-
module_name = module.name.split(".")[0]
261-
try:
262-
imported_module = import_from_path(module_name, str(module_type.joinpath(module.name)))
263-
except ImportError as e:
264-
log.warning("CUSTOM MISP module %s (type=%s) failed: %s", module_name, module_type.name, e)
265-
continue
266-
else:
267-
MODULES_HANDLERS[module_name] = imported_module
268-
MODULES_HANDLERS[f"type:{module_name}"] = module_type.name
269-
log.info("CUSTOM MISP module %s (type=%s) imported", module_name, module_type.name)
234+
if args.custom:
235+
log.info("Parsing custom modules from root directory: %s", args.custom)
236+
for module_type, module in iterate_modules(pathlib.Path(args.custom)):
237+
# remove extension from name
238+
module_name = module.name.split(".")[0]
239+
try:
240+
imported_module = import_from_path(module_name, str(module_type.joinpath(module.name)))
241+
except ImportError as e:
242+
log.warning("CUSTOM MISP module %s (type=%s) failed: %s", module_name, module_type.name, e)
243+
continue
244+
else:
245+
MODULES_HANDLERS[module_name] = imported_module
246+
MODULES_HANDLERS[f"type:{module_name}"] = module_type.name
247+
log.info("CUSTOM MISP module %s (type=%s) imported", module_name, module_type.name)
270248

271249
service = [
272250
(r"/modules", ListModules),

0 commit comments

Comments
 (0)