|
import streamlit as st |
|
from PurpleTeamIDS import analyze_security_log |
|
|
|
class Dashboard: |
|
def __init__(self): |
|
|
|
self.threats = [] |
|
|
|
def render_main_content(self): |
|
""" |
|
This function will render the main content of the dashboard. |
|
It will include the threat analysis results and any visual components. |
|
""" |
|
|
|
st.title("Cybersecurity IDS Dashboard") |
|
st.markdown(""" |
|
<p style="font-size:18px;">This dashboard provides insights into real-time security logs and threat analysis. |
|
Use the sidebar to enter your Hugging Face API token to enable threat analysis using AI.</p> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
self.render_threat_analysis_history() |
|
|
|
def render_threat_analysis_history(self): |
|
""" |
|
This function renders the history of threat analysis for the user. |
|
It will display the most recent threats that have been detected. |
|
""" |
|
st.subheader("Recent Threat Analysis") |
|
|
|
if not self.threats: |
|
st.write("No threats detected yet.") |
|
else: |
|
for threat in self.threats: |
|
st.markdown(f"### {threat['type']}") |
|
st.write(f"**Description**: {threat['description']}") |
|
st.write(f"**Detected at**: {threat['timestamp']}") |
|
st.write(f"**Risk Level**: {threat['risk_level']}") |
|
st.write("---") |
|
|
|
def threat_analysis(self, log): |
|
""" |
|
This function takes a log, processes it to detect threats, and adds it to the list of detected threats. |
|
""" |
|
|
|
threat_data = analyze_security_log(log) |
|
|
|
|
|
self.process_new_threat(threat_data) |
|
|
|
def process_new_threat(self, threat_data): |
|
""" |
|
Adds new threat data to the list of threats. |
|
You can modify this method to store data in a database or other persistence layer. |
|
""" |
|
threat = { |
|
'type': threat_data.get('type', 'Unknown'), |
|
'description': threat_data.get('description', 'No description available'), |
|
'timestamp': threat_data.get('timestamp', 'Unknown'), |
|
'risk_level': threat_data.get('risk_level', 'Low') |
|
} |
|
|
|
|
|
self.threats.insert(0, threat) |
|
|
|
def render_sidebar(self): |
|
""" |
|
Render the sidebar content for user interactions like entering the API token |
|
""" |
|
st.sidebar.header("Configuration") |
|
st.sidebar.text_input("Enter API Token", type="password", key="api_token") |