# Copyright (C) 2025 James Brotosky, Brandon Wickline # # 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 . #TODO Continue implementing logger #TODO Add input sanitation and CSV injection prevention #TODO Continue OTP and Local approval rewrites #TODO Explore pywin32 #TODO Fix Requirements.txt #TODO Create Generic system_config.json for gitea import argparse import json import logging import os import dotenv import urllib3 import utils.menus as menus from services.API import AirlockAPIWrapper from services.security import getAPI from services.setup import setup urllib3.disable_warnings( urllib3.exceptions.InsecureRequestWarning ) def main(): #Determine working directory, setup directory, configure logging, sent env, get API and URL if not already stored working_dir = setup() logger = logging.getLogger(__name__) dotenv.load_dotenv(dotenv_path=working_dir / ".env") try: url = os.getenv("URL") username = os.getenv("USERNAME") if not url: raise ValueError("Missing URL in environment variables.") if not username: raise ValueError("Missing USERNAME in environment variables.") logger.debug(f"Retrieved URL: {url}") logger.debug(f"Retrieved Username: {username}") except ValueError as e: logger.error(f"Configuration error: {e}", exc_info=True) raise api = AirlockAPIWrapper( base_url=str(os.getenv("URL")), api_key = getAPI(username, "AirlockTools"), ) parser = argparse.ArgumentParser(description="Program for Managing Airlock via API & CMD") parser.add_argument("--monitor", action="store_true", help="Run in non-interactive mode") # Add other arguments as needed args = parser.parse_args() if args.monitor: # Non-interactive logic logger.info("Running non-interactively to start monitoring Airlock Changes") """ os.makedirs("scheduling", exist_ok=True) os.makedirs("OTP/HTML", exist_ok=True) os.makedirs("OTP/PARQ", exist_ok=True) os.makedirs("Local_Approval/HTML", exist_ok=True) os.makedirs("Local_Approval/PARQ", exist_ok=True) register_function("monitorOTP", utils.otpfunctions.monitorOTP) register_function("monitorLA", la.scheduleAddingLAHashes) register_function("updateAuditPolicies", utils.policyfunctions.updateAuditPoliciesFromEnforcementPolices) if not os.path.exists("scheduling\\jobs.json"): recurring_job("monitorOTP", "monitorOTP", interval=60, unit="seconds", args=[url, pups]) recurring_job("monitorLA", "monitorLA", interval=50, unit="seconds", args=[url, policy_relationship_map, bad_publisher_list, pups, threat_tolerance_constant]) recurring_job("updateAuditPolicies", "updateAudit", interval=5, unit="minutes", args=[url, policy_relationship_map]) else: reload_jobs() start_scheduler() """ else: # Interactive logic raw = os.getenv("POLICY_MAP_ENF_AUD", "{}") try: # Escape backslashes before parsing escaped = raw.encode('unicode_escape').decode('utf-8') badpathparts = json.loads(escaped) except Exception as e: logging.error(f"Failed to parse BAD_PATH_PARTS: {e}") badpathparts = [] print(badpathparts) menus.menu_main(api) if __name__ == "__main__": main()