|
17 | 17 | #
|
18 | 18 | # You should have received a copy of the GNU Affero General Public License
|
19 | 19 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
20 |
| - |
21 |
| -import abc |
22 | 20 | import pathlib
|
23 | 21 | import signal
|
24 | 22 | import sys
|
@@ -189,38 +187,16 @@ def main():
|
189 | 187 | signal.signal(signal.SIGINT, handle_signal)
|
190 | 188 | signal.signal(signal.SIGTERM, handle_signal)
|
191 | 189 |
|
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) |
195 | 191 | arg_parser.add_argument("-t", "--test", default=False, action="store_true", help="Test mode")
|
196 | 192 | 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") |
216 | 196 | args = arg_parser.parse_args()
|
217 | 197 |
|
218 | 198 | # 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) |
224 | 200 |
|
225 | 201 | # Load helpers
|
226 | 202 | for helper in iterate_helpers(importlib.resources.files(__package__).joinpath(HELPERS_DIR)):
|
@@ -255,18 +231,20 @@ def main():
|
255 | 231 | log.info("MISP module %s (type=%s) imported", module_name, module_type.name)
|
256 | 232 |
|
257 | 233 | # 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) |
270 | 248 |
|
271 | 249 | service = [
|
272 | 250 | (r"/modules", ListModules),
|
|
0 commit comments