def app_init(debug=False): hxtool_global.initialize() # Log early init/failures to stdout console_log = logging.StreamHandler(sys.stdout) console_log.setFormatter( logging.Formatter( '[%(asctime)s] {%(module)s} {%(threadName)s} %(levelname)s - %(message)s' )) logger.addHandler(console_log) #app.logger.addHandler(console_log) # If we're debugging use a static key if debug: app.secret_key = 'B%PT>65`)x<3_CRC3S~D6CynM7^F~:j0'.encode( default_encoding) logger.setLevel(logging.DEBUG) logger.debug("Running in debug mode.") else: app.secret_key = crypt_generate_random(32) logger.setLevel(logging.INFO) hxtool_global.hxtool_config = hxtool_config( combine_app_path(hxtool_vars.data_path, 'conf.json')) # Initialize configured log handlers for log_handler in hxtool_global.hxtool_config.log_handlers(): logger.addHandler(log_handler) hxtool_global.hxtool_db = init_db() # TODO: Disabled for now # Enable X15 integration if config options are present #if hxtool_global.hxtool_config['x15']: # from hxtool_x15_db import hxtool_x15 # hxtool_global.hxtool_x15_object = hxtool_x15() # Initialize the scheduler hxtool_global.hxtool_scheduler = hxtool_scheduler( hxtool_global.hxtool_config['scheduler']['thread_count']) hxtool_global.hxtool_scheduler.start() # Initialize background API sessions hxtool_global.hxtool_scheduler.initialize_task_api_sessions() # Load tasks from the database after the task API sessions have been initialized hxtool_global.hxtool_scheduler.load_from_database() with open(combine_app_path("static", "alert_types.json")) as f: hxtool_global.hx_alert_types = json.load(f) f.close() app.config['SESSION_COOKIE_NAME'] = "hxtool_session" app.permanent_session_lifetime = datetime.timedelta(days=7) app.session_interface = hxtool_session_interface( app, expiration_delta=hxtool_global.hxtool_config['network'] ['session_timeout'])
parser.add_argument('-v', '--version', action='version', version='HXTool version {}'.format(hxtool_vars.__version__)) try: args = parser.parse_args() except: parser.exit(1) hxtool_global.initialize() # Log early init/failures to stdout console_log = logging.StreamHandler(sys.stdout) console_log.setFormatter(logging.Formatter('[%(asctime)s] {%(module)s} {%(threadName)s} %(levelname)s - %(message)s')) logger.addHandler(console_log) hxtool_global.hxtool_config = hxtool_config(combine_app_path(hxtool_vars.data_path, 'conf.json')) if args.clear_sessions: print("Clearing sessions from the database and exiting.") hxtool_db = init_db() for s in hxtool_db.sessionList(): hxtool_db.sessionDelete(s['session_id']) hxtool_db.close() hxtool_db = None exit(0) elif args.clear_saved_tasks: print("WARNING! WARNING! WARNING!") print("This will clear ALL saved tasks in the database for ALL profiles!") try: f = raw_input except NameError:
def app_init(debug = False): hxtool_global.initialize() # Log early init/failures to stdout console_log = logging.StreamHandler(sys.stdout) console_log.setFormatter(logging.Formatter('[%(asctime)s] {%(module)s} {%(threadName)s} %(levelname)s - %(message)s')) logger.addHandler(console_log) #app.logger.addHandler(console_log) # If we're debugging use a static key if debug: app.secret_key = 'B%PT>65`)x<3_CRC3S~D6CynM7^F~:j0'.encode(default_encoding) logger.setLevel(logging.DEBUG) logger.debug("Running in debug mode.") else: app.secret_key = crypt_generate_random(32) logger.setLevel(logging.INFO) hxtool_global.hxtool_config = hxtool_config(combine_app_path(hxtool_vars.data_path, 'conf.json')) # Initialize configured log handlers for log_handler in hxtool_global.hxtool_config.log_handlers(): logger.addHandler(log_handler) # Init DB # Disable the write cache altogether - too many issues reported with it enabled. hxtool_global.hxtool_db = hxtool_db(combine_app_path(hxtool_vars.data_path, 'hxtool.db'), apicache = hxtool_global.hxtool_config.get_child_item('apicache', 'enabled', False), apicache_refresh_interval = hxtool_global.hxtool_config.get_child_item('apicache', 'refresh_interval'), write_cache_size = 0) # Enable X15 integration if config options are present if hxtool_global.hxtool_config['x15']: from hxtool_x15_db import hxtool_x15 hxtool_global.hxtool_x15_object = hxtool_x15() # Initialize the scheduler hxtool_global.hxtool_scheduler = hxtool_scheduler(hxtool_global.hxtool_config['scheduler']['thread_count']) hxtool_global.hxtool_scheduler.start() # Initialize background API sessions hxtool_global.hxtool_scheduler.initialize_task_api_sessions() # Load tasks from the database after the task API sessions have been initialized hxtool_global.hxtool_scheduler.load_from_database() app.config['SESSION_COOKIE_NAME'] = "hxtool_session" app.permanent_session_lifetime = datetime.timedelta(days=7) app.session_interface = hxtool_session_interface(app, expiration_delta=hxtool_global.hxtool_config['network']['session_timeout']) if hxtool_global.hxtool_config['apicache']: if 'enabled' in hxtool_global.hxtool_config['apicache']: if hxtool_global.hxtool_config['apicache']['enabled']: for profile in hxtool_global.hxtool_db.profileList(): if profile['profile_id'] in hxtool_global.hxtool_scheduler.task_hx_api_sessions: hxtool_global.apicache[profile['profile_id']] = hxtool_api_cache(hxtool_global.hxtool_scheduler.task_hx_api_sessions[profile['profile_id']], profile['profile_id'], hxtool_global.hxtool_config['apicache']['intervals'], hxtool_global.hxtool_config['apicache']['types']) else: logger.info("No background credential for {}, not starting apicache".format(profile['profile_id'])) set_svg_mimetype()