def __check_external_modules(): """ check external libraries if they are installed Returns: True if success otherwise None """ external_modules = ["argparse", "netaddr", "requests", "paramiko", "texttable", "socks", "win_inet_pton", "flask", "sqlalchemy"] for module in external_modules: try: __import__(module) except Exception: __die_failure("pip install -r requirements.txt ---> " + module + " not installed!") default_config = _builder(_core_config(), _core_default_config()) if not os.path.exists(default_config["home_path"]): try: os.mkdir(default_config["home_path"]) os.mkdir(default_config["tmp_path"]) os.mkdir(default_config["results_path"]) except Exception: __die_failure("cannot access the directory {0}".format( default_config["home_path"])) if not os.path.exists(default_config["tmp_path"]): try: os.mkdir(default_config["tmp_path"]) except Exception: __die_failure("cannot access the directory {0}".format( default_config["results_path"])) if not os.path.exists(default_config["results_path"]): try: os.mkdir(default_config["results_path"]) except Exception: __die_failure("cannot access the directory {0}".format( default_config["results_path"])) if default_config["database_type"] == "sqlite": try: if os.path.isfile(default_config["home_path"]+"/"+default_config["database_name"]): pass else: from database.sqlite_create import sqlite_create_tables sqlite_create_tables() except Exception: __die_failure("cannot access the directory {0}".format( default_config["home_path"])) elif default_config["database_type"] == "mysql": try: from database.mysql_create import mysql_create_tables, mysql_create_database mysql_create_database() mysql_create_tables() except Exception: __die_failure(messages("en", "database_connection_failed")) else: __die_failure(messages("en", "invalid_database")) return True
def check_dependencies(): if python_version() == 2: sys.exit( color.color("red") + "[X] " + color.color("yellow") + "Python2 is No longer supported!" + color.color("reset")) # check os compatibility from config import nettacker_paths, nettacker_database_config external_modules = open( nettacker_paths()["requirements_path"]).read().split('\n') for module_name in external_modules: try: __import__( module_name.split('==')[0] if 'library_name=' not in module_name else module_name.split('library_name=')[1].split( )[0]) except Exception: if 'is_optional=true' not in module_name: sys.exit( color.color("red") + "[X] " + color.color("yellow") + "pip3 install -r requirements.txt ---> " + module_name.split('#')[0].strip() + " not installed!" + color.color("reset")) logo() from core.alert import messages if not ('linux' in os_name() or 'darwin' in os_name()): die_failure(messages("error_platform")) if not os.path.exists(nettacker_paths()["home_path"]): try: os.mkdir(nettacker_paths()["home_path"]) os.mkdir(nettacker_paths()["tmp_path"]) os.mkdir(nettacker_paths()["results_path"]) except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["home_path"])) if not os.path.exists(nettacker_paths()["tmp_path"]): try: os.mkdir(nettacker_paths()["tmp_path"]) except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["results_path"])) if not os.path.exists(nettacker_paths()["results_path"]): try: os.mkdir(nettacker_paths()["results_path"]) except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["results_path"])) if nettacker_database_config()["DB"] == "sqlite": try: if not os.path.isfile(nettacker_paths()["database_path"]): from database.sqlite_create import sqlite_create_tables sqlite_create_tables() except Exception: die_failure("cannot access the directory {0}".format( nettacker_paths()["home_path"])) elif nettacker_database_config()["DB"] == "mysql": try: from database.mysql_create import (mysql_create_tables, mysql_create_database) mysql_create_database() mysql_create_tables() except Exception: die_failure(messages("database_connection_failed")) elif nettacker_database_config()["DB"] == "postgres": try: from database.postgres_create import postgres_create_database postgres_create_database() except Exception: die_failure(messages("database_connection_failed")) else: die_failure(messages("invalid_database"))