File size: 2,680 Bytes
d8a3b6c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #!/usr/bin/env python3
"""
Startup script for the Threat Intelligence Assistant
"""
import os
import sys
import subprocess
import time
from pathlib import Path
def check_dependencies():
"""Check if required dependencies are installed"""
try:
import flask
import requests
import sklearn
import numpy
print("β
All required dependencies are installed")
return True
except ImportError as e:
print(f"β Missing dependency: {e}")
print("Please run: pip install -r requirements.txt")
return False
def check_config():
"""Check if configuration is set up"""
env_file = Path('.env')
if not env_file.exists():
print("β οΈ .env file not found. Creating from template...")
# Create basic .env file
env_content = """# Threat Intelligence Assistant Configuration
ALIENVAULT_API_KEY=your_alienvault_otx_api_key_here
ABUSEIPDB_API_KEY=your_abuseipdb_api_key_here
OPENAI_API_KEY=your_openai_api_key_here
SECRET_KEY=dev-secret-key-change-in-production
FLASK_ENV=development
FLASK_DEBUG=True
"""
with open('.env', 'w') as f:
f.write(env_content)
print("β
Created .env file - Please update with your API keys")
else:
print("β
Configuration file found")
return True
def create_directories():
"""Create necessary directories"""
directories = ['templates', 'static', 'models', 'logs']
for directory in directories:
Path(directory).mkdir(exist_ok=True)
print("β
Created necessary directories")
def main():
"""Main startup function"""
print("π Starting Threat Intelligence Assistant")
print("=" * 50)
# Check dependencies
if not check_dependencies():
sys.exit(1)
# Check configuration
check_config()
# Create directories
create_directories()
print("\nπ§ Starting the application...")
print("π± Web interface will be available at: http://localhost:5000")
print("π API endpoint: http://localhost:5000/analyze")
print("β€οΈ Health check: http://localhost:5000/health")
print("\nπ‘ Tip: Press Ctrl+C to stop the application")
print("=" * 50)
try:
# Import and run the Flask app
from app import app
app.run(debug=True, host='0.0.0.0', port=5000)
except KeyboardInterrupt:
print("\nπ Application stopped by user")
except Exception as e:
print(f"\nβ Error starting application: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()
|