Skip to content

Commit 7ee469b

Browse files
committed
2 parents a14cefa + b7064b4 commit 7ee469b

2 files changed

Lines changed: 117 additions & 24 deletions

File tree

sections/analyze.py

Lines changed: 73 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import pandas as pd
21
import polars as pl
3-
import plotly.express as px
42
import streamlit as st
53

64
if "parsed_df" not in st.session_state:
@@ -35,62 +33,114 @@
3533
# ---- FILTRE DATE ----
3634
with col1:
3735
st.markdown("### 📅 Date")
38-
start_date = st.date_input("Date début", min_date)
39-
end_date = st.date_input("Date fin", max_date)
36+
start_date = st.date_input("Start Date", min_date)
37+
end_date = st.date_input("End Date", max_date)
4038

4139
# ---- FILTRE action----
4240
with col2:
4341
st.markdown("### 🔄 Action")
4442
if "action" in data.columns:
45-
unique_action = sorted(data["action"].unique().cast(pl.Utf8).to_list()) # S'assurer du bon format
46-
selected_action= st.selectbox("Sélectionnez un action", ["Tous"] + unique_action)
43+
unique_action = sorted(
44+
data["action"].unique().cast(pl.Utf8).to_list()
45+
) # S'assurer du bon format
46+
selected_action = st.selectbox(
47+
"Select an action", ["All"] + unique_action
48+
)
4749
else:
48-
selected_action= "Tous"
49-
st.warning("Colonne 'action' non trouvée.")
50+
selected_action = "All"
51+
st.warning("Column 'action' not found.")
5052

5153
# ---- FILTRE portdst ----
5254
with col3:
5355
st.markdown("### 🔢 Port")
5456
if "portdst" in data.columns:
55-
min_port, max_port = int(data["portdst"].min()), int(data["portdst"].max())
56-
selected_port = st.slider("Sélectionnez un port destination", min_port, max_port, (min_port, max_port))
57+
min_port, max_port = (
58+
int(data["portdst"].min()),
59+
int(data["portdst"].max()),
60+
)
61+
62+
# Initialize port range in session state if not present
63+
if "port_range" not in st.session_state:
64+
st.session_state.port_range = (min_port, max_port)
65+
66+
# Quick port range selection buttons
67+
col_ports1, col_ports2, col_ports3 = st.columns(3)
68+
69+
# Define button handlers to update session state
70+
def set_well_known():
71+
st.session_state.port_range = (0, 1023)
72+
73+
def set_registered():
74+
st.session_state.port_range = (1024, 49151)
75+
76+
def set_dynamic():
77+
st.session_state.port_range = (49152, 65535)
78+
79+
with col_ports1:
80+
st.button("Well-known (0-1023)", on_click=set_well_known)
81+
82+
with col_ports2:
83+
st.button("Registered (1024-49151)", on_click=set_registered)
84+
85+
with col_ports3:
86+
st.button("Dynamic (49152-65535)", on_click=set_dynamic)
87+
88+
# Custom range slider that uses and updates the session state
89+
selected_port = st.slider(
90+
"Custom port range",
91+
min_port,
92+
max_port,
93+
value=st.session_state.port_range,
94+
key="port_slider",
95+
)
96+
97+
# Update port_range when slider changes
98+
st.session_state.port_range = selected_port
5799
else:
58-
min_port, max_port = 0, 600000 # Valeurs par défaut si la colonne est absente
100+
min_port, max_port = 0, 65535 # Standard TCP/IP port range
59101
selected_port = (min_port, max_port)
60-
st.warning("Colonne 'portdst' non trouvée, valeurs par défaut appliquées.")
102+
st.warning("Column 'portdst' not found, default values applied.")
61103

62104
# Vérification des dates sélectionnées
63105
if start_date > end_date:
64-
st.error("La date de début ne peut pas être postérieure à la date de fin.")
106+
st.error("The start date cannot be later than the end date.")
65107
else:
66108
# Conversion des dates en datetime
67-
start_datetime = pl.datetime(start_date.year, start_date.month, start_date.day)
68-
end_datetime = pl.datetime(end_date.year, end_date.month, end_date.day, 23, 59, 59)
109+
start_datetime = pl.datetime(
110+
start_date.year, start_date.month, start_date.day
111+
)
112+
end_datetime = pl.datetime(
113+
end_date.year, end_date.month, end_date.day, 23, 59, 59
114+
)
69115

70116
# ---- APPLICATION DES FILTRES ----
71117
filtered_data = data.filter(
72-
(pl.col("timestamp") >= start_datetime) & (pl.col("timestamp") <= end_datetime)
118+
(pl.col("timestamp") >= start_datetime)
119+
& (pl.col("timestamp") <= end_datetime)
73120
)
74121

75122
# Correction du filtrage par action(forcer conversion Utf8)
76-
if "action" in data.columns and selected_action!= "Tous":
77-
filtered_data = filtered_data.filter(pl.col("action").cast(pl.Utf8) == selected_action)
123+
if "action" in data.columns and selected_action != "All":
124+
filtered_data = filtered_data.filter(
125+
pl.col("action").cast(pl.Utf8) == selected_action
126+
)
78127

79128
# Filtrer par portdst en prenant en compte min/max
80129
if "portdst" in data.columns:
81130
filtered_data = filtered_data.filter(
82-
(pl.col("portdst").cast(pl.Int64) >= selected_port[0]) &
83-
(pl.col("portdst").cast(pl.Int64) <= selected_port[1])
131+
(pl.col("portdst").cast(pl.Int64) >= selected_port[0])
132+
& (pl.col("portdst").cast(pl.Int64) <= selected_port[1])
84133
)
85134

86135
# Affichage des données filtrées
87-
st.write("### 🔍 Data filtred :")
136+
st.write(f"### 🔍 Data filtered : {filtered_data.shape[0]} entries")
88137
st.dataframe(filtered_data)
89138

90139
else:
91-
st.warning("La colonne 'timestamp' n'existe pas ou n'est pas au format datetime.")
140+
st.warning(
141+
"The 'timestamp' column does not exist or is not in datetime format."
142+
)
92143

93144
# Onglet Sankey
94145
with tab2:
95146
st.subheader("Sankey Diagram")
96-

sections/upload.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,50 @@
88
st.title("ShadowLog - Log File Analyzer")
99
st.write("Upload a log file to analyze with the following format :")
1010
st.write(
11-
"timestamp;ipsrc;ipdst;protocole;portsrc;portdst;rule;action;interface;unknown;fw"
11+
"""
12+
<style>
13+
table, th, td {
14+
border: 1px solid black;
15+
border-collapse: collapse;
16+
text-align: center;
17+
}
18+
</style>
19+
<table>
20+
<thead>
21+
<tr>
22+
<th>Column name</th>
23+
<td>timestamp</td>
24+
<td>ipsrc</td>
25+
<td>ipdst</td>
26+
<td>protocole</td>
27+
<td>portsrc</td>
28+
<td>portdst</td>
29+
<td>rule</td>
30+
<td>action</td>
31+
<td>interface</td>
32+
<td>unknown</td>
33+
<td>fw</td>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
<tr>
38+
<th>Format</th>
39+
<td>YYYY-MM-DD HH:MM:SS</td>
40+
<td>str</td>
41+
<td>str</td>
42+
<td>str</td>
43+
<td>int</td>
44+
<td>int</td>
45+
<td>int</td>
46+
<td>str</td>
47+
<td>str</td>
48+
<td>str</td>
49+
<td>int</td>
50+
</tr>
51+
</tbody>
52+
</table>
53+
""",
54+
unsafe_allow_html=True,
1255
)
1356

1457
uploaded_file = st.file_uploader("Choose a log file")

0 commit comments

Comments
 (0)