Spaces:
Running
Running
Update pages/Analysis.py
Browse files- pages/Analysis.py +296 -304
pages/Analysis.py
CHANGED
@@ -1,5 +1,3 @@
|
|
1 |
-
# pages/Analysis.py
|
2 |
-
|
3 |
import streamlit as st
|
4 |
from utils.functions import (
|
5 |
get_phone_info,
|
@@ -20,7 +18,6 @@ def extract_urls(message):
|
|
20 |
r'(https?://[^\s]+)|(www\.[^\s]+)'
|
21 |
)
|
22 |
urls = url_pattern.findall(message)
|
23 |
-
# Spłaszcz listę
|
24 |
urls = [url[0] or url[1] for url in urls]
|
25 |
return urls
|
26 |
|
@@ -40,8 +37,7 @@ def check_urls_with_phishtank(urls):
|
|
40 |
if in_database and valid:
|
41 |
phishing_urls.append(url)
|
42 |
else:
|
43 |
-
|
44 |
-
pass
|
45 |
except Exception as e:
|
46 |
st.error(f"Błąd podczas sprawdzania URL w PhishTank: {e}")
|
47 |
return phishing_urls
|
@@ -49,7 +45,7 @@ def check_urls_with_phishtank(urls):
|
|
49 |
def check_urls_with_safe_browsing(urls):
|
50 |
api_key = os.getenv('GOOGLE_SAFE_BROWSING_API_KEY')
|
51 |
if not api_key:
|
52 |
-
return None
|
53 |
unsafe_urls = []
|
54 |
headers = {'Content-Type': 'application/json'}
|
55 |
client_body = {
|
@@ -75,333 +71,329 @@ def check_urls_with_safe_browsing(urls):
|
|
75 |
matches = data.get('matches', [])
|
76 |
unsafe_urls = [match['threat']['url'] for match in matches]
|
77 |
else:
|
78 |
-
# Obsługa błędów
|
79 |
st.error(f"Błąd podczas komunikacji z Google Safe Browsing API: {response.status_code}")
|
80 |
except Exception as e:
|
81 |
st.error(f"Błąd podczas sprawdzania URL w Google Safe Browsing: {e}")
|
82 |
return unsafe_urls
|
83 |
|
84 |
-
def
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
'report_button': "Zgłoś numer jako oszustwo",
|
96 |
-
'history_header': "Historia Analiz",
|
97 |
-
'phone_input_label': "Numer telefonu nadawcy (z kodem kierunkowym kraju, np. +48123456789):",
|
98 |
-
'additional_info_header': "Dodatkowe Informacje",
|
99 |
-
'frequency_label': "Jak często otrzymujesz wiadomości od tego numeru?",
|
100 |
-
'frequency_options': ('Pierwszy raz', 'Sporadycznie', 'Regularnie'),
|
101 |
-
'last_received_label': "Kiedy ostatnio otrzymałeś podobną wiadomość?",
|
102 |
-
'last_received_options': ('Dziś', 'W ciągu ostatniego tygodnia', 'W ciągu ostatniego miesiąca', 'Dłużej'),
|
103 |
-
'confidence_level_label': "Jak bardzo jesteś pewny, że wiadomość jest autentyczna?",
|
104 |
-
'confidence_level_help': "1: Bardzo mało pewny, 5: Bardzo pewny",
|
105 |
-
'unexpected_label': "Czy otrzymanie tej wiadomości było dla Ciebie niespodziewane?",
|
106 |
-
'unexpected_options': ('Tak', 'Nie'),
|
107 |
-
'additional_notes_label': "Dodatkowe uwagi lub informacje (opcjonalnie)",
|
108 |
-
'phone_info_header': "Informacje o numerze telefonu",
|
109 |
-
'country_label': "Kraj",
|
110 |
-
'operator_label': "Operator",
|
111 |
-
'unable_to_retrieve': "Nie można uzyskać informacji o numerze telefonu.",
|
112 |
-
'red_flags_found': "Znaleziono następujące potencjalne czerwone flagi:",
|
113 |
-
'remember_caution': "📌 Pamiętaj: Bądź ostrożny z wiadomościami od nieznanych nadawców.",
|
114 |
-
'number_reported': "Numer został zgłoszony jako oszustwo.",
|
115 |
-
'number_already_reported': "Numer został już wcześniej zgłoszony jako oszustwo.",
|
116 |
-
'invalid_number': "Podany numer telefonu jest nieprawidłowy.",
|
117 |
-
'failed_to_parse': "Nie udało się przetworzyć numeru telefonu. Upewnij się, że jest w poprawnym formacie.",
|
118 |
-
'url_analysis_header': "🔗 Analiza URL",
|
119 |
-
'extracted_urls': "Wyodrębnione URL z wiadomości:",
|
120 |
-
'no_urls_found': "Brak URL w wiadomości.",
|
121 |
-
'checking_urls_phishtank': "Sprawdzanie URL w PhishTank...",
|
122 |
-
'phishtank_warning': "Następujące URL są oznaczone jako phishing przez PhishTank:",
|
123 |
-
'no_phishtank_threats': "Brak zagrożeń phishingowych według PhishTank.",
|
124 |
-
'checking_urls_safe_browsing': "Sprawdzanie URL w Google Safe Browsing...",
|
125 |
-
'safe_browsing_warning': "Następujące URL są oznaczone jako niebezpieczne przez Google Safe Browsing:",
|
126 |
-
'no_safe_browsing_threats': "Brak zagrożeń według Google Safe Browsing.",
|
127 |
-
'api_key_missing': "Brak klucza API dla usługi: {}",
|
128 |
-
'analyzing_message': "Analizowanie wiadomości za pomocą modelu AI...",
|
129 |
-
'form_submitted': "Formularz został wysłany.",
|
130 |
-
'starting_phone_analysis': "Rozpoczynam analizę numeru telefonu...",
|
131 |
-
'checking_fake_numbers': "Sprawdzam, czy numer jest w bazie fałszywych numerów...",
|
132 |
-
'performing_simple_checks': "Przeprowadzam proste sprawdzenia heurystyczne...",
|
133 |
-
'starting_url_analysis': "Rozpoczynam analizę URL..."
|
134 |
-
},
|
135 |
-
'German': {
|
136 |
-
'header': "📊 SMS-Analyse",
|
137 |
-
'content': "Hier ist die Schnittstelle zur Analyse von SMS-Nachrichten. Geben Sie unten den Inhalt der Nachricht ein, um zu überprüfen, ob es sich um einen potenziellen Betrug handelt.",
|
138 |
-
'input_placeholder': "Geben Sie den SMS-Inhalt ein...",
|
139 |
-
'analyze_button': "Nachricht analysieren",
|
140 |
-
'result_positive': "Warnung: Die Nachricht könnte ein Betrug sein!",
|
141 |
-
'result_negative': "Die Nachricht scheint sicher zu sein.",
|
142 |
-
'report_button': "Nummer als Betrug melden",
|
143 |
-
'history_header': "Analyseverlauf",
|
144 |
-
'phone_input_label': "Telefonnummer des Absenders (mit Ländervorwahl, z.B. +49123456789):",
|
145 |
-
'additional_info_header': "Zusätzliche Informationen",
|
146 |
-
'frequency_label': "Wie oft erhalten Sie Nachrichten von dieser Nummer?",
|
147 |
-
'frequency_options': ('Zum ersten Mal', 'Gelegentlich', 'Regelmäßig'),
|
148 |
-
'last_received_label': "Wann haben Sie zuletzt eine ähnliche Nachricht erhalten?",
|
149 |
-
'last_received_options': ('Heute', 'In der letzten Woche', 'Im letzten Monat', 'Länger her'),
|
150 |
-
'confidence_level_label': "Wie sicher sind Sie, dass die Nachricht authentisch ist?",
|
151 |
-
'confidence_level_help': "1: Sehr unsicher, 5: Sehr sicher",
|
152 |
-
'unexpected_label': "War der Erhalt dieser Nachricht für Sie unerwartet?",
|
153 |
-
'unexpected_options': ('Ja', 'Nein'),
|
154 |
-
'additional_notes_label': "Zusätzliche Anmerkungen oder Informationen (optional)",
|
155 |
-
'phone_info_header': "Informationen zur Telefonnummer",
|
156 |
-
'country_label': "Land",
|
157 |
-
'operator_label': "Anbieter",
|
158 |
-
'unable_to_retrieve': "Informationen zur Telefonnummer können nicht abgerufen werden.",
|
159 |
-
'red_flags_found': "Folgende potenzielle Warnsignale wurden gefunden:",
|
160 |
-
'remember_caution': "📌 Denken Sie daran: Seien Sie vorsichtig bei Nachrichten von unbekannten Absendern.",
|
161 |
-
'number_reported': "Nummer wurde als Betrug gemeldet.",
|
162 |
-
'number_already_reported': "Nummer wurde bereits als Betrug gemeldet.",
|
163 |
-
'invalid_number': "Die angegebene Telefonnummer ist ungültig.",
|
164 |
-
'failed_to_parse': "Die Telefonnummer konnte nicht verarbeitet werden. Stellen Sie sicher, dass sie im richtigen Format ist.",
|
165 |
-
'url_analysis_header': "🔗 URL-Analyse",
|
166 |
-
'extracted_urls': "Aus der Nachricht extrahierte URLs:",
|
167 |
-
'no_urls_found': "Keine URLs in der Nachricht gefunden.",
|
168 |
-
'checking_urls_phishtank': "Überprüfe URLs mit PhishTank...",
|
169 |
-
'phishtank_warning': "Folgende URLs sind von PhishTank als Phishing markiert:",
|
170 |
-
'no_phishtank_threats': "Keine Phishing-Bedrohungen laut PhishTank.",
|
171 |
-
'checking_urls_safe_browsing': "Überprüfe URLs mit Google Safe Browsing...",
|
172 |
-
'safe_browsing_warning': "Folgende URLs sind von Google Safe Browsing als unsicher markiert:",
|
173 |
-
'no_safe_browsing_threats': "Keine Bedrohungen laut Google Safe Browsing.",
|
174 |
-
'api_key_missing': "API-Schlüssel für Dienst fehlt: {}",
|
175 |
-
'analyzing_message': "Analysiere Nachricht mit AI-Modell...",
|
176 |
-
'form_submitted': "Formular wurde eingereicht.",
|
177 |
-
'starting_phone_analysis': "Beginne Analyse der Telefonnummer...",
|
178 |
-
'checking_fake_numbers': "Überprüfe, ob die Nummer in der Betrugsdatenbank ist...",
|
179 |
-
'performing_simple_checks': "Führe einfache heuristische Prüfungen durch...",
|
180 |
-
'starting_url_analysis': "Beginne URL-Analyse..."
|
181 |
-
},
|
182 |
-
'English': {
|
183 |
-
'header': "📊 SMS Analysis",
|
184 |
-
'content': "Here is the interface for analyzing SMS messages. Enter the content of the message below to check if it is a potential fraud.",
|
185 |
-
'input_placeholder': "Enter SMS content...",
|
186 |
-
'analyze_button': "Analyze Message",
|
187 |
-
'result_positive': "Warning: The message may be a fraud!",
|
188 |
-
'result_negative': "The message appears to be safe.",
|
189 |
-
'report_button': "Report number as fraud",
|
190 |
-
'history_header': "Analysis History",
|
191 |
-
'phone_input_label': "Sender's phone number (with country code, e.g., +123456789):",
|
192 |
-
'additional_info_header': "Additional Information",
|
193 |
-
'frequency_label': "How often do you receive messages from this number?",
|
194 |
-
'frequency_options': ('First time', 'Occasionally', 'Regularly'),
|
195 |
-
'last_received_label': "When did you last receive a similar message?",
|
196 |
-
'last_received_options': ('Today', 'Within the last week', 'Within the last month', 'Longer ago'),
|
197 |
-
'confidence_level_label': "How confident are you that the message is authentic?",
|
198 |
-
'confidence_level_help': "1: Very unsure, 5: Very confident",
|
199 |
-
'unexpected_label': "Was receiving this message unexpected for you?",
|
200 |
-
'unexpected_options': ('Yes', 'No'),
|
201 |
-
'additional_notes_label': "Additional notes or information (optional)",
|
202 |
-
'phone_info_header': "Phone Number Information",
|
203 |
-
'country_label': "Country",
|
204 |
-
'operator_label': "Operator",
|
205 |
-
'unable_to_retrieve': "Unable to retrieve phone number information.",
|
206 |
-
'red_flags_found': "The following potential red flags were found:",
|
207 |
-
'remember_caution': "📌 Remember: Be cautious with messages from unknown senders.",
|
208 |
-
'number_reported': "Number has been reported as fraud.",
|
209 |
-
'number_already_reported': "Number has already been reported as fraud.",
|
210 |
-
'invalid_number': "The provided phone number is invalid.",
|
211 |
-
'failed_to_parse': "Failed to parse the phone number. Ensure it is in the correct format.",
|
212 |
-
'url_analysis_header': "🔗 URL Analysis",
|
213 |
-
'extracted_urls': "Extracted URLs from the message:",
|
214 |
-
'no_urls_found': "No URLs found in the message.",
|
215 |
-
'checking_urls_phishtank': "Checking URLs with PhishTank...",
|
216 |
-
'phishtank_warning': "The following URLs are flagged as phishing by PhishTank:",
|
217 |
-
'no_phishtank_threats': "No phishing threats detected by PhishTank.",
|
218 |
-
'checking_urls_safe_browsing': "Checking URLs with Google Safe Browsing...",
|
219 |
-
'safe_browsing_warning': "The following URLs are flagged as unsafe by Google Safe Browsing:",
|
220 |
-
'no_safe_browsing_threats': "No threats detected by Google Safe Browsing.",
|
221 |
-
'api_key_missing': "API key missing for service: {}",
|
222 |
-
'analyzing_message': "Analyzing message using AI model...",
|
223 |
-
'form_submitted': "Form has been submitted.",
|
224 |
-
'starting_phone_analysis': "Starting phone number analysis...",
|
225 |
-
'checking_fake_numbers': "Checking if the number is in the fraud database...",
|
226 |
-
'performing_simple_checks': "Performing simple heuristic checks...",
|
227 |
-
'starting_url_analysis': "Starting URL analysis..."
|
228 |
-
}
|
229 |
-
}
|
230 |
|
231 |
-
|
|
|
|
|
|
|
|
|
|
|
232 |
|
233 |
-
|
234 |
-
|
|
|
|
|
|
|
|
|
235 |
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
247 |
|
248 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
249 |
|
250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
251 |
frequency = st.selectbox(
|
252 |
-
|
253 |
-
|
254 |
)
|
255 |
last_received = st.selectbox(
|
256 |
-
|
257 |
-
|
258 |
)
|
259 |
confidence_level = st.slider(
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
value=3,
|
264 |
-
help=translations['confidence_level_help']
|
265 |
)
|
266 |
unexpected = st.radio(
|
267 |
-
|
268 |
-
|
269 |
-
)
|
270 |
-
additional_notes = st.text_area(
|
271 |
-
label=translations['additional_notes_label'],
|
272 |
-
height=100
|
273 |
)
|
|
|
274 |
|
275 |
-
submitted = st.form_submit_button(
|
276 |
|
277 |
if submitted:
|
278 |
-
st.write(translations['form_submitted']) # Diagnostyka
|
279 |
if not message.strip():
|
280 |
-
st.error(
|
281 |
elif not phone_number.strip():
|
282 |
-
st.error(
|
283 |
else:
|
284 |
-
# Informacje o numerze telefonu
|
285 |
-
st.write(translations['starting_phone_analysis']) # Diagnostyka
|
286 |
-
country, operator = get_phone_info(phone_number)
|
287 |
-
if country and operator:
|
288 |
-
st.subheader(translations['phone_info_header'])
|
289 |
-
st.write(f"- **{translations['country_label']}:** {country}")
|
290 |
-
st.write(f"- **{translations['operator_label']}:** {operator}")
|
291 |
-
else:
|
292 |
-
st.write(translations['unable_to_retrieve'])
|
293 |
-
|
294 |
-
# Sprawdzenie, czy numer jest w bazie fałszywych numerów
|
295 |
-
st.write(translations['checking_fake_numbers']) # Diagnostyka
|
296 |
-
if is_fake_number(phone_number):
|
297 |
-
st.warning(translations['result_positive'])
|
298 |
-
fraud_detected = True
|
299 |
-
else:
|
300 |
-
st.info(translations['result_negative'])
|
301 |
-
fraud_detected = False
|
302 |
-
|
303 |
-
# Przeprowadź proste sprawdzenia heurystyczne
|
304 |
-
st.write(translations['performing_simple_checks']) # Diagnostyka
|
305 |
-
warnings = simple_checks(message, language)
|
306 |
-
if warnings:
|
307 |
-
st.warning(translations['red_flags_found'])
|
308 |
-
for warn in warnings:
|
309 |
-
st.write(f"- {warn}")
|
310 |
-
|
311 |
-
# Zbierz dodatkowe informacje
|
312 |
additional_info = f"""
|
313 |
-
**{
|
314 |
-
|
315 |
-
**{
|
316 |
-
|
317 |
-
**{
|
318 |
-
|
319 |
-
**{translations['unexpected_label']}** {unexpected}
|
320 |
-
|
321 |
-
**{translations['additional_notes_label']}** {additional_notes}
|
322 |
"""
|
|
|
323 |
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
st.write(translations['extracted_urls'])
|
330 |
-
for url in urls:
|
331 |
-
st.write(f"- {url}")
|
332 |
-
|
333 |
-
# Sprawdzanie URL w PhishTank
|
334 |
-
st.write(translations['checking_urls_phishtank'])
|
335 |
-
phishing_urls_phishtank = check_urls_with_phishtank(urls)
|
336 |
-
if phishing_urls_phishtank:
|
337 |
-
st.warning(translations['phishtank_warning'])
|
338 |
-
for url in phishing_urls_phishtank:
|
339 |
-
st.write(f"- {url}")
|
340 |
-
else:
|
341 |
-
st.write(translations['no_phishtank_threats'])
|
342 |
-
|
343 |
-
# Sprawdzanie URL w Google Safe Browsing
|
344 |
-
st.write(translations['checking_urls_safe_browsing'])
|
345 |
-
phishing_urls_safe_browsing = check_urls_with_safe_browsing(urls)
|
346 |
-
if phishing_urls_safe_browsing is None:
|
347 |
-
st.warning(translations['api_key_missing'].format('Google Safe Browsing'))
|
348 |
-
elif phishing_urls_safe_browsing:
|
349 |
-
st.warning(translations['safe_browsing_warning'])
|
350 |
-
for url in phishing_urls_safe_browsing:
|
351 |
-
st.write(f"- {url}")
|
352 |
-
else:
|
353 |
-
st.write(translations['no_safe_browsing_threats'])
|
354 |
-
else:
|
355 |
-
st.write(translations['no_urls_found'])
|
356 |
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
try:
|
365 |
-
analysis_text, risk_text, recommendations_text = analyze_message(
|
366 |
-
message, phone_number, additional_info, api_key, language
|
367 |
-
)
|
368 |
-
st.subheader("📑 " + translations['header'])
|
369 |
-
st.markdown(analysis_text)
|
370 |
-
st.subheader("⚠️ " + translations['red_flags_found'])
|
371 |
-
st.markdown(risk_text)
|
372 |
-
st.subheader("✅ " + translations['remember_caution'])
|
373 |
-
st.markdown(recommendations_text)
|
374 |
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
update_stats(fraud_detected=fraud_detected)
|
380 |
-
except Exception as e:
|
381 |
-
st.error(f"Błąd podczas aktualizacji statystyk: {e}")
|
382 |
-
fraud_detected = False
|
383 |
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
|
|
388 |
|
389 |
-
|
|
|
390 |
|
391 |
-
|
392 |
-
|
393 |
-
if st.button(translations['report_button']):
|
394 |
-
try:
|
395 |
-
parsed_number = parse(phone_number, None)
|
396 |
-
if is_valid_number(parsed_number):
|
397 |
-
success = add_fake_number(phone_number)
|
398 |
-
if success:
|
399 |
-
st.success(translations['number_reported'])
|
400 |
-
else:
|
401 |
-
st.info(translations['number_already_reported'])
|
402 |
-
else:
|
403 |
-
st.error(translations['invalid_number'])
|
404 |
-
except NumberParseException:
|
405 |
-
st.error(translations['failed_to_parse'])
|
406 |
-
except Exception as e:
|
407 |
-
st.error(f"Wystąpił błąd: {e}")
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from utils.functions import (
|
3 |
get_phone_info,
|
|
|
18 |
r'(https?://[^\s]+)|(www\.[^\s]+)'
|
19 |
)
|
20 |
urls = url_pattern.findall(message)
|
|
|
21 |
urls = [url[0] or url[1] for url in urls]
|
22 |
return urls
|
23 |
|
|
|
37 |
if in_database and valid:
|
38 |
phishing_urls.append(url)
|
39 |
else:
|
40 |
+
st.warning(f"Błąd podczas sprawdzania URL w PhishTank: {response.status_code}")
|
|
|
41 |
except Exception as e:
|
42 |
st.error(f"Błąd podczas sprawdzania URL w PhishTank: {e}")
|
43 |
return phishing_urls
|
|
|
45 |
def check_urls_with_safe_browsing(urls):
|
46 |
api_key = os.getenv('GOOGLE_SAFE_BROWSING_API_KEY')
|
47 |
if not api_key:
|
48 |
+
return None
|
49 |
unsafe_urls = []
|
50 |
headers = {'Content-Type': 'application/json'}
|
51 |
client_body = {
|
|
|
71 |
matches = data.get('matches', [])
|
72 |
unsafe_urls = [match['threat']['url'] for match in matches]
|
73 |
else:
|
|
|
74 |
st.error(f"Błąd podczas komunikacji z Google Safe Browsing API: {response.status_code}")
|
75 |
except Exception as e:
|
76 |
st.error(f"Błąd podczas sprawdzania URL w Google Safe Browsing: {e}")
|
77 |
return unsafe_urls
|
78 |
|
79 |
+
def analyze_sms(message, phone_number, additional_info, language):
|
80 |
+
st.subheader(get_translation('sms_analysis_header', language))
|
81 |
+
|
82 |
+
# Informacje o numerze telefonu
|
83 |
+
country, operator = get_phone_info(phone_number)
|
84 |
+
if country and operator:
|
85 |
+
st.write(get_translation('phone_info', language))
|
86 |
+
st.write(f"- {get_translation('country_label', language)}: {country}")
|
87 |
+
st.write(f"- {get_translation('operator_label', language)}: {operator}")
|
88 |
+
else:
|
89 |
+
st.write(get_translation('unable_to_retrieve', language))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
90 |
|
91 |
+
# Sprawdzenie, czy numer jest w bazie fałszywych numerów
|
92 |
+
if is_fake_number(phone_number):
|
93 |
+
st.warning(get_translation('number_reported_warning', language))
|
94 |
+
fraud_detected = True
|
95 |
+
else:
|
96 |
+
fraud_detected = False
|
97 |
|
98 |
+
# Przeprowadź proste sprawdzenia heurystyczne
|
99 |
+
warnings = simple_checks(message, language)
|
100 |
+
if warnings:
|
101 |
+
st.warning(get_translation('red_flags_found', language))
|
102 |
+
for warn in warnings:
|
103 |
+
st.write(f"- {warn}")
|
104 |
|
105 |
+
# Analiza URL
|
106 |
+
urls = extract_urls(message)
|
107 |
+
if urls:
|
108 |
+
st.subheader(get_translation('url_analysis_header', language))
|
109 |
+
st.write(get_translation('extracted_urls', language))
|
110 |
+
for url in urls:
|
111 |
+
st.write(f"- {url}")
|
112 |
+
|
113 |
+
# Sprawdzanie URL w PhishTank
|
114 |
+
phishing_urls_phishtank = check_urls_with_phishtank(urls)
|
115 |
+
if phishing_urls_phishtank:
|
116 |
+
st.warning(get_translation('phishtank_warning', language))
|
117 |
+
for url in phishing_urls_phishtank:
|
118 |
+
st.write(f"- {url}")
|
119 |
+
else:
|
120 |
+
st.write(get_translation('no_phishtank_threats', language))
|
121 |
+
|
122 |
+
# Sprawdzanie URL w Google Safe Browsing
|
123 |
+
phishing_urls_safe_browsing = check_urls_with_safe_browsing(urls)
|
124 |
+
if phishing_urls_safe_browsing is None:
|
125 |
+
st.warning(get_translation('api_key_missing', language).format('Google Safe Browsing'))
|
126 |
+
elif phishing_urls_safe_browsing:
|
127 |
+
st.warning(get_translation('safe_browsing_warning', language))
|
128 |
+
for url in phishing_urls_safe_browsing:
|
129 |
+
st.write(f"- {url}")
|
130 |
+
else:
|
131 |
+
st.write(get_translation('no_safe_browsing_threats', language))
|
132 |
+
|
133 |
+
# Analiza wiadomości z użyciem modelu AI
|
134 |
+
api_key = os.getenv('SAMBANOVA_API_KEY')
|
135 |
+
if not api_key:
|
136 |
+
st.error(get_translation('api_key_missing', language).format('SambaNova'))
|
137 |
+
else:
|
138 |
+
with st.spinner(get_translation('analyzing_message', language)):
|
139 |
+
try:
|
140 |
+
analysis_text, risk_text, recommendations_text = analyze_message(
|
141 |
+
message, phone_number, additional_info, api_key, language
|
142 |
+
)
|
143 |
+
st.subheader(get_translation('message_analysis_header', language))
|
144 |
+
st.markdown(analysis_text)
|
145 |
+
st.subheader(get_translation('risk_assessment_header', language))
|
146 |
+
st.markdown(risk_text)
|
147 |
+
st.subheader(get_translation('user_recommendations_header', language))
|
148 |
+
st.markdown(recommendations_text)
|
149 |
+
|
150 |
+
# Aktualizacja statystyk na podstawie oceny ryzyka
|
151 |
+
try:
|
152 |
+
match = re.search(r'(\d+)/10', risk_text)
|
153 |
+
fraud_detected = int(match.group(1)) >= 7 if match else fraud_detected
|
154 |
+
update_stats(fraud_detected=fraud_detected)
|
155 |
+
except Exception as e:
|
156 |
+
st.error(f"Błąd podczas aktualizacji statystyk: {e}")
|
157 |
|
158 |
+
# Dodanie analizy do historii
|
159 |
+
add_to_history(message, phone_number, analysis_text, risk_text, recommendations_text)
|
160 |
+
except Exception as e:
|
161 |
+
st.error(f"Błąd podczas analizy wiadomości: {e}")
|
162 |
+
|
163 |
+
st.info(get_translation('remember_caution', language))
|
164 |
+
|
165 |
+
# Zgłoszenie numeru jako oszustwo
|
166 |
+
if fraud_detected:
|
167 |
+
if st.button(get_translation('report_button', language)):
|
168 |
+
try:
|
169 |
+
parsed_number = parse(phone_number, None)
|
170 |
+
if is_valid_number(parsed_number):
|
171 |
+
success = add_fake_number(phone_number)
|
172 |
+
if success:
|
173 |
+
st.success(get_translation('number_reported', language))
|
174 |
+
else:
|
175 |
+
st.info(get_translation('number_already_reported', language))
|
176 |
+
else:
|
177 |
+
st.error(get_translation('invalid_number', language))
|
178 |
+
except NumberParseException:
|
179 |
+
st.error(get_translation('failed_to_parse', language))
|
180 |
+
|
181 |
+
def analyze_email(email_content, sender_email, language):
|
182 |
+
st.subheader(get_translation('email_analysis_header', language))
|
183 |
+
st.write(get_translation('email_analysis_in_progress', language))
|
184 |
+
# Tutaj możesz dodać logikę analizy e-maili
|
185 |
+
|
186 |
+
def analyze_website(url, language):
|
187 |
+
st.subheader(get_translation('website_analysis_header', language))
|
188 |
+
st.write(get_translation('website_analysis_in_progress', language))
|
189 |
+
# Tutaj możesz dodać logikę analizy stron internetowych
|
190 |
+
|
191 |
+
def show_history(language):
|
192 |
+
st.subheader(get_translation('history_header', language))
|
193 |
+
st.write(get_translation('history_in_progress', language))
|
194 |
+
# Tutaj możesz dodać logikę wyświetlania historii analiz
|
195 |
+
|
196 |
+
def show_statistics(language):
|
197 |
+
st.subheader(get_translation('statistics_header', language))
|
198 |
+
st.write(get_translation('statistics_in_progress', language))
|
199 |
+
# Tutaj możesz dodać logikę wyświetlania statystyk
|
200 |
+
|
201 |
+
def get_translation(key, language):
|
202 |
+
translations = {
|
203 |
+
'Polish': {
|
204 |
+
'sms_analysis_header': "Analiza SMS",
|
205 |
+
'email_analysis_header': "Analiza E-mail",
|
206 |
+
'website_analysis_header': "Analiza Strony Internetowej",
|
207 |
+
'history_header': "Historia Analiz",
|
208 |
+
'statistics_header': "Statystyki",
|
209 |
+
'phone_info': "Informacje o numerze telefonu:",
|
210 |
+
'country_label': "Kraj",
|
211 |
+
'operator_label': "Operator",
|
212 |
+
'unable_to_retrieve': "Nie można uzyskać informacji o numerze telefonu.",
|
213 |
+
'number_reported_warning': "Ostrzeżenie: Ten numer został wcześniej zgłoszony jako oszustwo!",
|
214 |
+
'red_flags_found': "Znaleziono następujące potencjalne czerwone flagi:",
|
215 |
+
'url_analysis_header': "Analiza URL",
|
216 |
+
'extracted_urls': "Wyodrębnione URL z wiadomości:",
|
217 |
+
'phishtank_warning': "Następujące URL są oznaczone jako phishing przez PhishTank:",
|
218 |
+
'no_phishtank_threats': "Brak zagrożeń phishingowych według PhishTank.",
|
219 |
+
'api_key_missing': "Brak klucza API dla usługi: {}.",
|
220 |
+
'safe_browsing_warning': "Następujące URL są oznaczone jako niebezpieczne przez Google Safe Browsing:",
|
221 |
+
'no_safe_browsing_threats': "Brak zagrożeń według Google Safe Browsing.",
|
222 |
+
'analyzing_message': "Analizowanie wiadomości za pomocą modelu AI...",
|
223 |
+
'message_analysis_header': "Analiza treści wiadomości:",
|
224 |
+
'risk_assessment_header': "Ocena ryzyka oszustwa:",
|
225 |
+
'user_recommendations_header': "Zalecenia dla użytkownika:",
|
226 |
+
'remember_caution': "📌 Pamiętaj: Bądź ostrożny z wiadomościami od nieznanych nadawców.",
|
227 |
+
'report_button': "Zgłoś numer jako oszustwo",
|
228 |
+
'number_reported': "Numer został zgłoszony jako oszustwo.",
|
229 |
+
'number_already_reported': "Numer został już wcześniej zgłoszony jako oszustwo.",
|
230 |
+
'invalid_number': "Podany numer telefonu jest nieprawidłowy.",
|
231 |
+
'failed_to_parse': "Nie udało się przetworzyć numeru telefonu. Upewnij się, że jest w poprawnym formacie.",
|
232 |
+
'email_analysis_in_progress': "Funkcja analizy e-maili jest w trakcie implementacji.",
|
233 |
+
'website_analysis_in_progress': "Funkcja analizy stron internetowych jest w trakcie implementacji.",
|
234 |
+
'history_in_progress': "Funkcja wyświetlania historii analiz jest w trakcie implementacji.",
|
235 |
+
'statistics_in_progress': "Funkcja wyświetlania statystyk jest w trakcie implementacji.",
|
236 |
+
'analysis_center_title': "Centrum Analizy Zagrożeń",
|
237 |
+
'select_analysis_type': "Wybierz typ analizy:",
|
238 |
+
'additional_info_header': "Dodatkowe Informacje",
|
239 |
+
'frequency_label': "Jak często otrzymujesz wiadomości od tego numeru?",
|
240 |
+
'frequency_options': ('Pierwszy raz', 'Sporadycznie', 'Regularnie'),
|
241 |
+
'last_received_label': "Kiedy ostatnio otrzymałeś podobną wiadomość?",
|
242 |
+
'last_received_options': ('Dziś', 'W ciągu ostatniego tygodnia', 'W ciągu ostatniego miesiąca', 'Dłużej'),
|
243 |
+
'confidence_level_label': "Jak bardzo jesteś pewny, że wiadomość jest autentyczna?",
|
244 |
+
'confidence_level_help': "1: Bardzo mało pewny, 5: Bardzo pewny",
|
245 |
+
'unexpected_label': "Czy otrzymanie tej wiadomości było dla Ciebie niespodziewane?",
|
246 |
+
'unexpected_options': ('Tak', 'Nie'),
|
247 |
+
'additional_notes_label': "Dodatkowe uwagi lub informacje (opcjonalnie)",
|
248 |
+
'analyze_button': "Analizuj",
|
249 |
+
'enter_sms_content': "Wprowadź treść SMS",
|
250 |
+
'sender_phone_number': "Numer telefonu nadawcy (z kodem kierunkowym kraju, np. +48123456789)",
|
251 |
+
'enter_email_content': "Wprowadź treść e-maila",
|
252 |
+
'sender_email_address': "Adres e-mail nadawcy",
|
253 |
+
'enter_website_url': "Wprowadź adres URL strony do analizy"
|
254 |
+
},
|
255 |
+
'English': {
|
256 |
+
'sms_analysis_header': "SMS Analysis",
|
257 |
+
'email_analysis_header': "Email Analysis",
|
258 |
+
'website_analysis_header': "Website Analysis",
|
259 |
+
'history_header': "Analysis History",
|
260 |
+
'statistics_header': "Statistics",
|
261 |
+
'phone_info': "Phone number information:",
|
262 |
+
'country_label': "Country",
|
263 |
+
'operator_label': "Operator",
|
264 |
+
'unable_to_retrieve': "Unable to retrieve phone number information.",
|
265 |
+
'number_reported_warning': "Warning: This number has been previously reported as fraud!",
|
266 |
+
'red_flags_found': "The following potential red flags were found:",
|
267 |
+
'url_analysis_header': "URL Analysis",
|
268 |
+
'extracted_urls': "Extracted URLs from the message:",
|
269 |
+
'phishtank_warning': "The following URLs are flagged as phishing by PhishTank:",
|
270 |
+
'no_phishtank_threats': "No phishing threats detected by PhishTank.",
|
271 |
+
'api_key_missing': "API key missing for service: {}.",
|
272 |
+
'safe_browsing_warning': "The following URLs are flagged as unsafe by Google Safe Browsing:",
|
273 |
+
'no_safe_browsing_threats': "No threats detected by Google Safe Browsing.",
|
274 |
+
'analyzing_message': "Analyzing message using AI model...",
|
275 |
+
'message_analysis_header': "Message Content Analysis:",
|
276 |
+
'risk_assessment_header': "Fraud Risk Assessment:",
|
277 |
+
'user_recommendations_header': "User Recommendations:",
|
278 |
+
'remember_caution': "📌 Remember: Be cautious with messages from unknown senders.",
|
279 |
+
'report_button': "Report number as fraud",
|
280 |
+
'number_reported': "Number has been reported as fraud.",
|
281 |
+
'number_already_reported': "Number has already been reported as fraud.",
|
282 |
+
'invalid_number': "The provided phone number is invalid.",
|
283 |
+
'failed_to_parse': "Failed to parse the phone number. Ensure it is in the correct format.",
|
284 |
+
'email_analysis_in_progress': "Email analysis function is under development.",
|
285 |
+
'website_analysis_in_progress': "Website analysis function is under development.",
|
286 |
+
'history_in_progress': "Analysis history function is under development.",
|
287 |
+
'statistics_in_progress': "Statistics display function is under development.",
|
288 |
+
'analysis_center_title': "Threat Analysis Center",
|
289 |
+
'select_analysis_type': "Select analysis type:",
|
290 |
+
'additional_info_header': "Additional Information",
|
291 |
+
'frequency_label': "How often do you receive messages from this number?",
|
292 |
+
'frequency_options': ('First time', 'Occasionally', 'Regularly'),
|
293 |
+
'last_received_label': "When did you last receive a similar message?",
|
294 |
+
'last_received_options': ('Today', 'Within the last week', 'Within the last month', 'Longer ago'),
|
295 |
+
'confidence_level_label': "How confident are you that the message is authentic?",
|
296 |
+
'confidence_level_help': "1: Very unsure, 5: Very confident",
|
297 |
+
'unexpected_label': "Was receiving this message unexpected for you?",
|
298 |
+
'unexpected_options': ('Yes', 'No'),
|
299 |
+
'additional_notes_label': "Additional notes or information (optional)",
|
300 |
+
'analyze_button': "Analyze",
|
301 |
+
'enter_sms_content': "Enter SMS content",
|
302 |
+
'sender_phone_number': "Sender's phone number (with country code, e.g., +123456789)",
|
303 |
+
'enter_email_content': "Enter email content",
|
304 |
+
'sender_email_address': "Sender's email address",
|
305 |
+
'enter_website_url': "Enter website URL to analyze"
|
306 |
+
},
|
307 |
+
'German': {
|
308 |
+
# Dodaj tłumaczenia dla języka niemieckiego
|
309 |
+
# Add German translations here
|
310 |
+
}
|
311 |
+
}
|
312 |
+
return translations.get(language, translations['English']).get(key, key)
|
313 |
|
314 |
+
def show_analysis(language):
|
315 |
+
st.title(get_translation('analysis_center_title', language))
|
316 |
+
|
317 |
+
analysis_type = st.sidebar.radio(
|
318 |
+
get_translation('select_analysis_type', language),
|
319 |
+
(
|
320 |
+
get_translation('sms_analysis_header', language),
|
321 |
+
get_translation('email_analysis_header', language),
|
322 |
+
get_translation('website_analysis_header', language),
|
323 |
+
get_translation('history_header', language),
|
324 |
+
get_translation('statistics_header', language)
|
325 |
+
)
|
326 |
+
)
|
327 |
+
|
328 |
+
if analysis_type == get_translation('sms_analysis_header', language):
|
329 |
+
with st.form("sms_form"):
|
330 |
+
message = st.text_area(get_translation('enter_sms_content', language), height=150)
|
331 |
+
phone_number = st.text_input(get_translation('sender_phone_number', language))
|
332 |
+
|
333 |
+
st.subheader(get_translation('additional_info_header', language))
|
334 |
frequency = st.selectbox(
|
335 |
+
get_translation('frequency_label', language),
|
336 |
+
get_translation('frequency_options', language)
|
337 |
)
|
338 |
last_received = st.selectbox(
|
339 |
+
get_translation('last_received_label', language),
|
340 |
+
get_translation('last_received_options', language)
|
341 |
)
|
342 |
confidence_level = st.slider(
|
343 |
+
get_translation('confidence_level_label', language),
|
344 |
+
1, 5, 3,
|
345 |
+
help=get_translation('confidence_level_help', language)
|
|
|
|
|
346 |
)
|
347 |
unexpected = st.radio(
|
348 |
+
get_translation('unexpected_label', language),
|
349 |
+
get_translation('unexpected_options', language)
|
|
|
|
|
|
|
|
|
350 |
)
|
351 |
+
additional_notes = st.text_area(get_translation('additional_notes_label', language), height=100)
|
352 |
|
353 |
+
submitted = st.form_submit_button(get_translation('analyze_button', language))
|
354 |
|
355 |
if submitted:
|
|
|
356 |
if not message.strip():
|
357 |
+
st.error(get_translation('enter_sms_content', language))
|
358 |
elif not phone_number.strip():
|
359 |
+
st.error(get_translation('sender_phone_number', language))
|
360 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
361 |
additional_info = f"""
|
362 |
+
**{get_translation('frequency_label', language)}**: {frequency}
|
363 |
+
**{get_translation('last_received_label', language)}**: {last_received}
|
364 |
+
**{get_translation('confidence_level_label', language)}**: {confidence_level}/5
|
365 |
+
**{get_translation('unexpected_label', language)}**: {unexpected}
|
366 |
+
**{get_translation('additional_notes_label', language)}**: {additional_notes}
|
|
|
|
|
|
|
|
|
367 |
"""
|
368 |
+
analyze_sms(message, phone_number, additional_info, language)
|
369 |
|
370 |
+
elif analysis_type == get_translation('email_analysis_header', language):
|
371 |
+
with st.form("email_form"):
|
372 |
+
email_content = st.text_area(get_translation('enter_email_content', language), height=150)
|
373 |
+
sender_email = st.text_input(get_translation('sender_email_address', language))
|
374 |
+
submitted = st.form_submit_button(get_translation('analyze_button', language))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
375 |
|
376 |
+
if submitted:
|
377 |
+
if not email_content.strip():
|
378 |
+
st.error(get_translation('enter_email_content', language))
|
379 |
+
elif not sender_email.strip():
|
380 |
+
st.error(get_translation('sender_email_address', language))
|
381 |
+
else:
|
382 |
+
analyze_email(email_content, sender_email, language)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
383 |
|
384 |
+
elif analysis_type == get_translation('website_analysis_header', language):
|
385 |
+
with st.form("website_form"):
|
386 |
+
url = st.text_input(get_translation('enter_website_url', language))
|
387 |
+
submitted = st.form_submit_button(get_translation('analyze_button', language))
|
|
|
|
|
|
|
|
|
388 |
|
389 |
+
if submitted:
|
390 |
+
if not url.strip():
|
391 |
+
st.error(get_translation('enter_website_url', language))
|
392 |
+
else:
|
393 |
+
analyze_website(url, language)
|
394 |
|
395 |
+
elif analysis_type == get_translation('history_header', language):
|
396 |
+
show_history(language)
|
397 |
|
398 |
+
elif analysis_type == get_translation('statistics_header', language):
|
399 |
+
show_statistics(language)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|