diff --git a/backend/code_parser.py b/backend/code_parser.py index 9644d87..35b1765 100644 --- a/backend/code_parser.py +++ b/backend/code_parser.py @@ -48,7 +48,7 @@ def save_analysis_to_db(self, source, title, links, error): session.add(analysis_result) session.commit() except Exception as e: - print(f"Error saving analysis to database: {e}") + logging.error(f"Error saving analysis to database: {e}") finally: session.close() diff --git a/backend/pipeline_manager.py b/backend/pipeline_manager.py index e1ea77e..1d3a308 100644 --- a/backend/pipeline_manager.py +++ b/backend/pipeline_manager.py @@ -1,5 +1,6 @@ import openai import requests +import logging from database.models import DocumentAnalysis from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker @@ -8,6 +9,9 @@ engine = create_engine(DATABASE_URL) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) +# Configure logging +logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') + class PipelineManager: def __init__(self): pass @@ -22,7 +26,7 @@ def autogpt_task(self, task): ) return response.choices[0].text.strip() except Exception as e: - print(f"Error during autogpt_task: {e}") + logging.error(f"Error during autogpt_task: {e}") return "" def pinocchio_fact_check(self, text): @@ -33,16 +37,17 @@ def pinocchio_fact_check(self, text): "key": "YOUR_API_KEY" } response = requests.get(url, params=params) - if response.status_code == 200: - result = response.json() - if "claims" in result: - return result["claims"] - else: - return "No claims found." + response.raise_for_status() + result = response.json() + if "claims" in result: + return result["claims"] else: - return f"Error: {response.status_code}" + return "No claims found." + except requests.exceptions.HTTPError as e: + logging.error(f"HTTP error during pinocchio_fact_check: {e}") + return f"Error: {e}" except Exception as e: - print(f"Error during pinocchio_fact_check: {e}") + logging.error(f"Error during pinocchio_fact_check: {e}") return "" def save_analysis_to_db(self, source, title, links, error): @@ -57,7 +62,7 @@ def save_analysis_to_db(self, source, title, links, error): session.add(analysis_result) session.commit() except Exception as e: - print(f"Error saving analysis to database: {e}") + logging.error(f"Error saving analysis to database: {e}") finally: session.close() diff --git a/chatbot/app.py b/chatbot/app.py index d97e3e3..0810c0c 100644 --- a/chatbot/app.py +++ b/chatbot/app.py @@ -39,6 +39,7 @@ from kafka import KafkaProducer, KafkaConsumer import os +import logging app = Flask(__name__) @@ -46,13 +47,16 @@ engine = create_engine(DATABASE_URL) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) +# Configure logging +logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s') + def scan_network(): try: # Placeholder function for scanning network devices = ["Device1", "Device2", "Device3"] return devices except Exception as e: - print(f"Error during network scanning: {e}") + logging.error(f"Error during network scanning: {e}") return [] def deploy_exploit(target): @@ -62,7 +66,7 @@ def deploy_exploit(target): return "Exploit deployed successfully!" return "Exploit deployment failed." except Exception as e: - print(f"Error during exploit deployment: {e}") + logging.error(f"Error during exploit deployment: {e}") return "Exploit deployment failed." def save_scan_results_to_db(source, title, links, error): @@ -77,7 +81,7 @@ def save_scan_results_to_db(source, title, links, error): session.add(scan_result) session.commit() except Exception as e: - print(f"Error saving scan results to database: {e}") + logging.error(f"Error saving scan results to database: {e}") finally: session.close() @@ -104,7 +108,7 @@ def deploy_exploit_endpoint(): threat_intelligence = RealTimeThreatIntelligence(api_key=os.getenv("REAL_TIME_THREAT_INTELLIGENCE_API_KEY")) monitoring = RealTimeMonitoring(threat_intelligence_module=threat_intelligence) except Exception as e: - print(f"Error initializing real-time threat intelligence and monitoring modules: {e}") + logging.error(f"Error initializing real-time threat intelligence and monitoring modules: {e}") # Initialize and integrate new modules in the main function try: @@ -138,13 +142,13 @@ def deploy_exploit_endpoint(): code_parser = CodeParser("sample_code") pipeline_manager = PipelineManager() except Exception as e: - print(f"Error initializing modules: {e}") + logging.error(f"Error initializing modules: {e}") # Integrate the ThreatIntelligence module with RealTimeMonitoring try: monitoring.threat_intelligence_module = advanced_threat_intelligence except Exception as e: - print(f"Error integrating ThreatIntelligence module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating ThreatIntelligence module with RealTimeMonitoring: {e}") # Add real-time threat data analysis using the ThreatIntelligence module async def analyze_threat_data(): @@ -153,14 +157,14 @@ async def analyze_threat_data(): analyzed_data = advanced_threat_intelligence.process_data(threat_data) return analyzed_data except Exception as e: - print(f"Error analyzing threat data: {e}") + logging.error(f"Error analyzing threat data: {e}") # Update the RealTimeThreatIntelligence initialization to include the ThreatIntelligence module try: threat_intelligence_module = RealTimeThreatIntelligence(api_key="YOUR_API_KEY") threat_intelligence_module.threat_intelligence = advanced_threat_intelligence except Exception as e: - print(f"Error updating RealTimeThreatIntelligence initialization: {e}") + logging.error(f"Error updating RealTimeThreatIntelligence initialization: {e}") # Add real-time threat data monitoring using the ThreatIntelligence module async def monitor_threat_data(): @@ -170,85 +174,85 @@ async def monitor_threat_data(): if threat["severity"] > 0.8: monitoring.trigger_alert(threat) except Exception as e: - print(f"Error monitoring threat data: {e}") + logging.error(f"Error monitoring threat data: {e}") # Integrate the AutomatedIncidentResponse module with RealTimeMonitoring try: monitoring.automated_incident_response = automated_incident_response except Exception as e: - print(f"Error integrating AutomatedIncidentResponse module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating AutomatedIncidentResponse module with RealTimeMonitoring: {e}") # Integrate the AIRedTeaming module with RealTimeMonitoring try: monitoring.ai_red_teaming = ai_red_teaming except Exception as e: - print(f"Error integrating AIRedTeaming module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating AIRedTeaming module with RealTimeMonitoring: {e}") # Integrate the APTSimulation module with RealTimeMonitoring try: monitoring.apt_simulation = apt_simulation() except Exception as e: - print(f"Error integrating APTSimulation module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating APTSimulation module with RealTimeMonitoring: {e}") # Integrate the PredictiveAnalytics module with RealTimeMonitoring try: monitoring.predictive_analytics = predictive_analytics except Exception as e: - print(f"Error integrating PredictiveAnalytics module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating PredictiveAnalytics module with RealTimeMonitoring: {e}") # Integrate the MachineLearningAI module with RealTimeMonitoring try: monitoring.machine_learning_ai = machine_learning_ai except Exception as e: - print(f"Error integrating MachineLearningAI module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating MachineLearningAI module with RealTimeMonitoring: {e}") # Integrate the DataVisualization module with RealTimeMonitoring try: monitoring.data_visualization = data_visualization except Exception as e: - print(f"Error integrating DataVisualization module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating DataVisualization module with RealTimeMonitoring: {e}") # Integrate the CloudExploitation module with RealTimeMonitoring try: monitoring.cloud_exploitation = cloud_exploitation except Exception as e: - print(f"Error integrating CloudExploitation module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating CloudExploitation module with RealTimeMonitoring: {e}") # Integrate the IoTExploitation module with RealTimeMonitoring try: monitoring.iot_exploitation = iot_exploitation except Exception as e: - print(f"Error integrating IoTExploitation module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating IoTExploitation module with RealTimeMonitoring: {e}") # Integrate the QuantumComputing module with RealTimeMonitoring try: monitoring.quantum_computing = quantum_computing except Exception as e: - print(f"Error integrating QuantumComputing module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating QuantumComputing module with RealTimeMonitoring: {e}") # Integrate the EdgeComputing module with RealTimeMonitoring try: monitoring.edge_computing = edge_computing except Exception as e: - print(f"Error integrating EdgeComputing module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating EdgeComputing module with RealTimeMonitoring: {e}") # Integrate the ServerlessComputing module with RealTimeMonitoring try: monitoring.serverless_computing = serverless_computing except Exception as e: - print(f"Error integrating ServerlessComputing module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating ServerlessComputing module with RealTimeMonitoring: {e}") # Integrate the MicroservicesArchitecture module with RealTimeMonitoring try: monitoring.microservices_architecture = microservices_architecture except Exception as e: - print(f"Error integrating MicroservicesArchitecture module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating MicroservicesArchitecture module with RealTimeMonitoring: {e}") # Integrate the CloudNativeApplications module with RealTimeMonitoring try: monitoring.cloud_native_applications = cloud_native_applications except Exception as e: - print(f"Error integrating CloudNativeApplications module with RealTimeMonitoring: {e}") + logging.error(f"Error integrating CloudNativeApplications module with RealTimeMonitoring: {e}") # Add tool tips and advanced help options for all functions def add_tool_tips(): @@ -340,7 +344,7 @@ def setup_message_queue(): channel.queue_declare(queue='task_queue', durable=True) return channel except Exception as e: - print(f"Error setting up message queue: {e}") + logging.error(f"Error setting up message queue: {e}") return None def send_message(channel, message): @@ -352,21 +356,21 @@ def send_message(channel, message): properties=pika.BasicProperties( delivery_mode=2, # make message persistent )) - print(f"Sent message: {message}") + logging.info(f"Sent message: {message}") except Exception as e: - print(f"Error sending message: {e}") + logging.error(f"Error sending message: {e}") def receive_message(channel): def callback(ch, method, properties, body): - print(f"Received message: {body}") + logging.info(f"Received message: {body}") ch.basic_ack(delivery_tag=method.delivery_tag) try: channel.basic_consume(queue='task_queue', on_message_callback=callback) - print('Waiting for messages. To exit press CTRL+C') + logging.info('Waiting for messages. To exit press CTRL+C') channel.start_consuming() except Exception as e: - print(f"Error receiving message: {e}") + logging.error(f"Error receiving message: {e}") def setup_kafka(): try: @@ -374,23 +378,23 @@ def setup_kafka(): consumer = KafkaConsumer('my_topic', bootstrap_servers='localhost:9092', auto_offset_reset='earliest', enable_auto_commit=True, group_id='my-group') return producer, consumer except Exception as e: - print(f"Error setting up Kafka: {e}") + logging.error(f"Error setting up Kafka: {e}") return None, None def send_message_to_kafka(producer, topic, message): try: producer.send(topic, message.encode('utf-8')) producer.flush() - print(f"Sent message to Kafka topic {topic}: {message}") + logging.info(f"Sent message to Kafka topic {topic}: {message}") except Exception as e: - print(f"Error sending message to Kafka: {e}") + logging.error(f"Error sending message to Kafka: {e}") def receive_message_from_kafka(consumer): try: for message in consumer: - print(f"Received message from Kafka: {message.value.decode('utf-8')}") + logging.info(f"Received message from Kafka: {message.value.decode('utf-8')}") except Exception as e: - print(f"Error receiving message from Kafka: {e}") + logging.error(f"Error receiving message from Kafka: {e}") if __name__ == "__main__": channel = setup_message_queue() diff --git a/chatbot/chatbot.py b/chatbot/chatbot.py index 7e16794..1d78c05 100644 --- a/chatbot/chatbot.py +++ b/chatbot/chatbot.py @@ -51,11 +51,15 @@ import pika from kafka import KafkaProducer, KafkaConsumer +import logging DATABASE_URL = "sqlite:///document_analysis.db" engine = create_engine(DATABASE_URL) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) +# Configure logging +logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') + def get_response(user_input): """Handle user input and provide responses.""" responses = { @@ -86,13 +90,13 @@ def handle_vulnerability_scanning(): session.add(scan_result) session.commit() except Exception as e: - print(f"Error saving scan results to database: {e}") + logging.error(f"Error saving scan results to database: {e}") finally: session.close() return vulnerabilities except Exception as e: - print(f"Error during vulnerability scanning: {e}") + logging.error(f"Error during vulnerability scanning: {e}") return [] def handle_exploit_deployment(target): @@ -112,13 +116,13 @@ def handle_exploit_deployment(target): session.add(exploit_result) session.commit() except Exception as e: - print(f"Error saving exploit deployment results to database: {e}") + logging.error(f"Error saving exploit deployment results to database: {e}") finally: session.close() return "Exploit deployed successfully!" if result else "Exploit deployment failed." except Exception as e: - print(f"Error during exploit deployment: {e}") + logging.error(f"Error during exploit deployment: {e}") return "Exploit deployment failed." def setup_kafka(): diff --git a/core/email_server/EmailServer.py b/core/email_server/EmailServer.py index 5ce4f24..c0356f9 100644 --- a/core/email_server/EmailServer.py +++ b/core/email_server/EmailServer.py @@ -2,6 +2,7 @@ import os import socket import threading +import logging from email.mime.image import MIMEImage from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText @@ -17,6 +18,9 @@ default_image = 'FlowSteering/assets/PerturbatedImages/DjiPerturbClassForward.png' # Server configuration +# Configure logging +logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') + def receive_complete_data( client_socket): # This function is used to receive the complete data from the client, adjust the parameters as needed based on your network conditions received_data = b"" @@ -80,7 +84,7 @@ def Save_Email_To_Recipient(client_socket, data, msg, requests, subject, sender, else: body = msg.get_payload() except Exception as e: - print(f"Error processing email message: {e}") + logging.error(f"Error processing email message: {e}") client_socket.sendall("Error processing email message".encode('utf-8')) return @@ -166,7 +170,8 @@ def Check_Inbox(client_socket, sender): # This function is used to check the inb img = MIMEImage(f.read()) img.add_header("Content-Disposition", "attachment", filename=filename) msg.attach(img) - except: + except Exception as e: + logging.error(f"Error sending image: {e}") print('network error, sending default image instead of the original image') with open(default_image,"rb") as f: img = MIMEImage(f.read()) diff --git a/database/models.py b/database/models.py index fc8bad8..52cc02f 100644 --- a/database/models.py +++ b/database/models.py @@ -1,6 +1,7 @@ from sqlalchemy import create_engine, Column, String, Integer, Text from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker +import logging Base = declarative_base() @@ -31,6 +32,9 @@ class DocumentAnalysis(Base): from modules.alerts_notifications import AlertsNotifications from modules.apt_simulation import APTSimulation +# Configure logging +logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(levelname)s - %(message)s') + # Verification of component connections def verify_component_connections(): try: @@ -38,40 +42,40 @@ def verify_component_connections(): session = SessionLocal() session.execute('SELECT 1') session.close() - print("Database connection verified.") + logging.info("Database connection verified.") # Check app components if not all([monitoring, threat_intelligence, advanced_threat_intelligence, predictive_analytics, automated_incident_response, ai_red_teaming, apt_simulation, machine_learning_ai, data_visualization, blockchain_logger, cloud_exploitation, iot_exploitation, quantum_computing, edge_computing, serverless_computing, microservices_architecture, cloud_native_applications]): raise ValueError("App component connection check failed") - print("App components connection verified.") + logging.info("App components connection verified.") # Check backend components if not all([CodeParser, PipelineManager]): raise ValueError("Backend component connection check failed") - print("Backend components connection verified.") + logging.info("Backend components connection verified.") # Check chatbot components if not all([scan_network, deploy_exploit, handle_vulnerability_scanning, handle_exploit_deployment]): raise ValueError("Chatbot component connection check failed") - print("Chatbot components connection verified.") + logging.info("Chatbot components connection verified.") # Check dashboard components if not all([malware_analysis, social_engineering]): raise ValueError("Dashboard component connection check failed") - print("Dashboard components connection verified.") + logging.info("Dashboard components connection verified.") # Check exploits components if not all([deploy_exploit2, deploy_exploit_ios]): raise ValueError("Exploits component connection check failed") - print("Exploits components connection verified.") + logging.info("Exploits components connection verified.") # Check modules components if not all([AlertsNotifications, APTSimulation]): raise ValueError("Modules component connection check failed") - print("Modules components connection verified.") + logging.info("Modules components connection verified.") except Exception as e: - print(f"Component connection verification failed: {e}") + logging.error(f"Component connection verification failed: {e}") # Run verification verify_component_connections()