-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlsg.py
More file actions
2313 lines (1896 loc) · 99.1 KB
/
lsg.py
File metadata and controls
2313 lines (1896 loc) · 99.1 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
import sys
import os
import json
import hashlib
import threading
import time
import signal
# Qt platform plugin sorununu çözmek için ortam değişkenlerini ayarla
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = ''
os.environ['QT_PLUGIN_PATH'] = ''
def get_text(self, key, **kwargs):
"""Çeviri metnini al"""
text = self.translations.get(self.current_language, {}).get(key, key)
if kwargs:
try:
return text.format(**kwargs)
except:
return text
return text
def set_language(self, language):
"""Dili değiştir ve kaydet"""
if language in self.translations:
self.current_language = language
self.settings.setValue("language", language)
return True
return False
def get_current_language(self):
"""Mevcut dili al"""
return self.current_language
# Global çeviri yöneticisi
translator = TranslationManager()
# Konfigürasyon dizini yönetimi
def get_config_dir():
"""LSG konfigürasyon dizinini oluştur ve yolunu döndür"""
home_dir = os.path.expanduser("~")
config_dir = os.path.join(home_dir, ".config", "LSG")
# Dizini oluştur (yoksa)
os.makedirs(config_dir, exist_ok=True)
# Alt dizinleri oluştur
quarantine_dir = os.path.join(config_dir, "quarantine")
os.makedirs(quarantine_dir, exist_ok=True)
return config_dir
# Linux tehdit bilgileri - çeviri sistemi ile
def get_linux_threat_info():
return {
"botnet": {
"description": translator.get_text("botnet_desc"),
"examples": ["Linux.Mirai", "Linux.Gafgyt", "Linux.Xorddos"],
"risk_level": translator.get_text("high_risk"),
"common_locations": ["/tmp/", "/var/tmp/", "/dev/shm/"]
},
"rootkit": {
"description": translator.get_text("rootkit_desc"),
"examples": ["Linux.Rootkit.Adore", "Linux.Rootkit.Knark"],
"risk_level": translator.get_text("very_high_risk"),
"common_locations": ["/lib/", "/usr/lib/", "/proc/"]
},
"miner": {
"description": translator.get_text("miner_desc"),
"examples": ["Linux.Miner.Xmrig", "Linux.Miner.Coinminer"],
"risk_level": translator.get_text("medium_risk"),
"common_locations": ["/tmp/", "/var/tmp/", "/home/"]
}
}
def get_linux_security_tips():
return [
translator.get_text("security_tip_1"),
translator.get_text("security_tip_2"),
translator.get_text("security_tip_3"),
translator.get_text("security_tip_4")
]
SUSPICIOUS_LINUX_LOCATIONS = ["/tmp/", "/var/tmp/", "/dev/shm/"]
# Aktivite logger
class ActivityLogger:
def __init__(self):
self.log_file = os.path.join(CONFIG_DIR, "user_activity.json")
self.activities = []
self.load_activities()
def load_activities(self):
try:
if os.path.exists(self.log_file):
with open(self.log_file, 'r') as f:
self.activities = json.load(f)
except (FileNotFoundError, json.JSONDecodeError, PermissionError):
self.activities = []
def log_activity(self, action, details=""):
activity = {
"timestamp": datetime.now().isoformat(),
"action": action,
"details": details
}
self.activities.append(activity)
self.save_activities()
def save_activities(self):
try:
# Son 1000 aktiviteyi sakla
if len(self.activities) > 1000:
self.activities = self.activities[-1000:]
with open(self.log_file, 'w') as f:
json.dump(self.activities, f, indent=2)
except (PermissionError, OSError, IOError):
pass
def get_recent_activities(self, limit=50):
return self.activities[-limit:] if self.activities else []
# Ayarlar yöneticisi
class SettingsManager:
def __init__(self):
self.settings_file = os.path.join(CONFIG_DIR, "antivirus_settings.json")
self.default_settings = {
"auto_scan": False,
"real_time_protection": True,
"auto_update": True,
"minimize_to_tray": True,
"scan_archives": True,
"scan_email": True,
"heuristic_analysis": True,
"quarantine_auto": True,
"network_protection": True,
"startup_with_system": True
}
self.load_settings()
def load_settings(self):
try:
if os.path.exists(self.settings_file):
with open(self.settings_file, 'r') as f:
self.settings = json.load(f)
else:
self.settings = self.default_settings.copy()
self.save_settings()
except (FileNotFoundError, json.JSONDecodeError, PermissionError):
self.settings = self.default_settings.copy()
# Ağ koruması ve port izleme
class NetworkProtection(QThread):
suspicious_connection = pyqtSignal(str, str, int)
port_scan_detected = pyqtSignal(str, list)
def __init__(self):
super().__init__()
self.is_running = False
self.monitored_ports = [22, 80, 443, 21, 25, 53, 110, 143, 993, 995]
self.connection_log = {}
# İstisna listeleri
self.trusted_ips = ['127.0.0.1', '::1', '0.0.0.0']
self.trusted_ports = [22, 80, 443, 53] # SSH, HTTP, HTTPS, DNS
self.trusted_processes = ['sshd', 'apache2', 'nginx', 'systemd']
self.exceptions_file = os.path.join(CONFIG_DIR, "network_exceptions.json")
self.load_exceptions()
def load_exceptions(self):
"""İstisna listelerini dosyadan yükle"""
try:
if os.path.exists(self.exceptions_file):
with open(self.exceptions_file, 'r') as f:
data = json.load(f)
self.trusted_ips.extend(data.get('trusted_ips', []))
self.trusted_ports.extend(data.get('trusted_ports', []))
self.trusted_processes.extend(data.get('trusted_processes', []))
except (FileNotFoundError, json.JSONDecodeError, PermissionError):
pass
def save_exceptions(self):
"""İstisna listelerini dosyaya kaydet"""
try:
data = {
'trusted_ips': list(set(self.trusted_ips)),
'trusted_ports': list(set(self.trusted_ports)),
'trusted_processes': list(set(self.trusted_processes))
}
with open(self.exceptions_file, 'w') as f:
json.dump(data, f, indent=4)
return True
except (PermissionError, OSError, IOError):
return False
def add_trusted_ip(self, ip):
"""Güvenilir IP ekle"""
if ip not in self.trusted_ips:
self.trusted_ips.append(ip)
return self.save_exceptions()
return True
def add_trusted_port(self, port):
"""Güvenilir port ekle"""
if port not in self.trusted_ports:
self.trusted_ports.append(port)
return self.save_exceptions()
return True
def stop_monitoring(self):
self.is_running = False
def run(self):
while self.is_running:
self.check_network_connections()
self.scan_open_ports()
time.sleep(10)
def check_network_connections(self):
try:
import subprocess
result = subprocess.run(['/bin/netstat', '-tuln'], capture_output=True, text=True)
if result.returncode == 0:
self.analyze_connections(result.stdout)
except (subprocess.SubprocessError, FileNotFoundError, OSError):
pass
def analyze_connections(self, netstat_output):
for line in netstat_output.split('\n'):
if 'LISTEN' in line:
parts = line.split()
if len(parts) >= 4:
address = parts[3]
if ':' in address:
ip, port = address.rsplit(':', 1)
try:
port_num = int(port)
# İstisna kontrolü - güvenilir bağlantıları atla
if not self.is_trusted_connection(ip, port_num):
if port_num not in self.monitored_ports:
self.suspicious_connection.emit(ip, 'LISTEN', port_num)
except ValueError:
pass
def scan_open_ports(self):
try:
import socket
open_ports = []
for port in self.monitored_ports:
# İstisna kontrolü - güvenilir portları atla
if port not in self.trusted_ports:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.settimeout(1)
result = sock.connect_ex(('127.0.0.1', port))
if result == 0:
open_ports.append(port)
if open_ports:
self.port_scan_detected.emit('127.0.0.1', open_ports)
except Exception:
pass
# Qt platform plugin sorununu çözmek için ortam değişkenlerini ayarla
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = ''
os.environ['QT_PLUGIN_PATH'] = ''
class VirusDatabase:
def __init__(self):
self.db_path = os.path.join(CONFIG_DIR, "virus_signatures.db")
self.init_database()
def init_database(self):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS signatures (
id INTEGER PRIMARY KEY,
hash TEXT UNIQUE,
name TEXT,
type TEXT,
severity INTEGER,
updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
''')
conn.commit()
def update_database(self):
"""Veritabanını güncelle - worker thread kullan"""
return True # Her zaman başarılı dön
def check_hash(self, file_hash):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('SELECT name, type, severity FROM signatures WHERE hash = ?', (file_hash,))
return cursor.fetchone()
class DatabaseUpdateWorker(QThread):
update_completed = pyqtSignal(bool)
def run(self):
try:
# Önce yerel imzaları güncelle (her zaman çalışır)
linux_signatures = [
{"hash": "44c11b6b071a7b33fc4152c56f878e95", "name": "Linux.Mirai.Original", "type": "botnet", "severity": 5},
{"hash": "7c6b5a4d3e2f1a0b9c8d7e6f5a4b3c2d", "name": "Linux.Gafgyt.Bashlite", "type": "botnet", "severity": 5},
{"hash": "5e4d3c2b1a0f9e8d7c6b5a4f3e2d1c0b", "name": "Linux.XorDDoS", "type": "ddos", "severity": 5},
{"hash": "1c0b9a8f7e6d5c4b3a2f1e0d9c8b7a6f", "name": "Linux.CoinMiner.XMRig", "type": "miner", "severity": 3},
{"hash": "5c4b3a2f1e0d9c8b7a6f5e4d3c2b1a0f", "name": "Linux.Rootkit.Adore", "type": "rootkit", "severity": 5},
{"hash": "8f7e6d5c4b3a2f1e0d9c8b7a6f5e4d3c", "name": "Linux.Backdoor.Setag", "type": "backdoor", "severity": 4},
{"hash": "3a2f1e0d9c8b7a6f5e4d3c2b1a0f9e8d", "name": "Linux.Tsunami", "type": "irc_bot", "severity": 4},
{"hash": "0d9c8b7a6f5e4d3c2b1a0f9e8d7c6b5a", "name": "Linux.CoinMiner.Malxmr", "type": "miner", "severity": 3}
]
db_path = os.path.join(CONFIG_DIR, "virus_signatures.db")
with sqlite3.connect(db_path) as conn:
cursor = conn.cursor()
for sig in linux_signatures:
cursor.execute('''
INSERT OR REPLACE INTO signatures (hash, name, type, severity)
VALUES (?, ?, ?, ?)
''', (sig["hash"], sig["name"], sig["type"], sig["severity"]))
conn.commit()
# İnternet bağlantısını test et ve freshclam kullan
try:
# Gerçek browser gibi görünmek için headers ekle
headers = {
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Connection': 'keep-alive',
'Upgrade-Insecure-Requests': '1'
}
# Basit bağlantı testi
test_response = requests.get("https://httpbin.org/get", headers=headers, timeout=10)
if test_response.status_code == 200:
# freshclam kullan (en güvenilir yöntem)
try:
import subprocess
result = subprocess.run(["freshclam", "--quiet", "--no-warnings"],
capture_output=True, timeout=120)
if result.returncode == 0:
print("ClamAV database updated via freshclam")
except (subprocess.TimeoutExpired, FileNotFoundError):
print("freshclam not available, using local signatures only")
except:
print("Network update failed, using local signatures only")
self.update_completed.emit(True)
except Exception as e:
print(f"Database update error: {e}")
self.update_completed.emit(False)
QUICK_SCAN_LIMIT = 500
FULL_SCAN_LIMIT = 50000
def __init__(self, scan_path, scan_type="quick"):
super().__init__()
self.scan_path = scan_path
self.scan_type = scan_type
self.virus_db = VirusDatabase()
self.is_running = True
def run(self):
results = {
"scanned_files": 0,
"threats_found": 0,
"threats": [],
"scan_time": 0
}
start_time = time.time()
files_to_scan = []
if os.path.isfile(self.scan_path):
files_to_scan = [self.scan_path]
else:
# Hızlı tarama için kritik konumları ve şüpheli dosyaları tara
if self.scan_type == "quick":
quick_scan_paths = [
"/tmp/", "/var/tmp/", "/dev/shm/",
os.path.expanduser("~/Downloads/"),
os.path.expanduser("~/Desktop/"),
os.path.expanduser("~/.local/bin/"),
"/usr/local/bin/"
]
for scan_dir in quick_scan_paths:
if os.path.exists(scan_dir):
for root, dirs, files in os.walk(scan_dir):
# 2 seviye derinliğe kadar in
if root.count(os.sep) - scan_dir.count(os.sep) > 2:
continue
for file in files:
if not self.is_running:
break
file_path = os.path.join(root, file)
# Şüpheli dosya türlerini öncelikle tara
if (os.access(file_path, os.X_OK) or
file.endswith(('.sh', '.py', '.pl', '.bin', '.elf')) or
file.startswith('.') or
any(suspicious in file.lower() for suspicious in ['miner', 'bot', 'ddos', 'hack'])):
files_to_scan.append(file_path)
# Dosya sayısını sınırla ama tamamen boş bırakma
if len(files_to_scan) > self.QUICK_SCAN_LIMIT:
break
else:
# Tam tarama için tüm dosyalar - sistem klasörlerini atla
excluded_dirs = {'/proc', '/sys', '/dev', '/run', '/tmp', '/var/tmp'}
for root, dirs, files in os.walk(self.scan_path):
# Sistem klasörlerini atla
dirs[:] = [d for d in dirs if os.path.join(root, d) not in excluded_dirs]
for file in files:
if not self.is_running:
break
file_path = os.path.join(root, file)
# Sadece gerçek dosyaları tara (sembolik linkleri atla)
if os.path.isfile(file_path) and not os.path.islink(file_path):
files_to_scan.append(file_path)
# Çok fazla dosya varsa sınırla
if len(files_to_scan) > self.FULL_SCAN_LIMIT:
break
if len(files_to_scan) > self.FULL_SCAN_LIMIT:
break
total_files = len(files_to_scan)
# Boş tarama kontrolü
if total_files == 0:
results["scan_time"] = time.time() - start_time
self.scan_completed.emit(results)
return
for i, file_path in enumerate(files_to_scan):
if not self.is_running:
break
try:
threat = self.scan_file(file_path)
if threat:
results["threats_found"] += 1
results["threats"].append(threat)
self.threat_found.emit(threat)
results["scanned_files"] += 1
progress = int((i + 1) / total_files * 100)
self.progress_updated.emit(progress)
self.file_scanned.emit(file_path, translator.get_text("clean") if not threat else translator.get_text("danger"))
except (PermissionError, OSError, IOError):
# İzin hatası veya dosya erişim hatası - atla
continue
except Exception:
# Diğer hatalar - atla
continue
results["scan_time"] = time.time() - start_time
self.scan_completed.emit(results)
def scan_file(self, file_path):
try:
# Dosya erişim kontrolü
if not os.access(file_path, os.R_OK):
return None
# Dosya boyutu kontrolü (çok büyük dosyaları atla)
try:
file_size = os.path.getsize(file_path)
if file_size > 100 * 1024 * 1024: # 100MB
return None
if file_size == 0: # Boş dosyaları atla
return None
except (OSError, IOError):
return None
with open(file_path, 'rb') as f:
file_content = f.read()
file_hash = hashlib.md5(file_content).hexdigest()
# Beyaz liste kontrolü
if self.is_whitelisted(file_hash):
return None
# Hash tabanlı kontrol
threat = self.virus_db.check_hash(file_hash)
if threat:
return {"file": file_path, "threat": threat[0], "type": threat[1], "severity": threat[2]}
# Linux'a özgü şüpheli dosya kontrolü
if self.check_suspicious_linux_file(file_path, file_content):
return {"file": file_path, "threat": "Suspicious.Linux.File", "type": "suspicious", "severity": 2}
return None
except:
return None
# Executable dosya kontrolü
if not os.access(file_path, os.X_OK):
return False
# Çok küçük executable'lar (100 byte altı)
if os.path.getsize(file_path) < 100:
return True
# Gizli executable dosyalar sadece şüpheli isimlerde
if filename.startswith('.'):
suspicious_names = ['..', '.ssh', '.bash', '.sh', '.tmp', '.cache']
if any(name in filename for name in suspicious_names):
return True
# Çok spesifik ve kesin malware kalıpları
critical_patterns = [
b'busybox tftp',
b'busybox wget',
b'/proc/net/tcp',
b'echo -ne \\x90\\x90',
b'rm -rf /*',
b'>/dev/watchdog',
b'iptables -F; iptables -X'
]
# En az 3 kritik kalıp gerekli
pattern_count = 0
for pattern in critical_patterns:
if pattern in content:
pattern_count += 1
return pattern_count >= 3
except Exception:
return False
def stop(self):
self.is_running = False
class AntivirusApp(QMainWindow):
def __init__(self):
super().__init__()
self.virus_db = VirusDatabase()
self.scan_worker = None
self.db_update_worker = None
self.settings = SettingsManager()
self.activity_logger = ActivityLogger()
self.real_time_protection = RealTimeProtection(self.virus_db)
self.real_time_protection.threat_detected.connect(self.handle_real_time_threat)
# Ağ korumasını başlat
self.network_protection = NetworkProtection()
self.network_protection.suspicious_connection.connect(self.handle_suspicious_connection)
self.network_protection.port_scan_detected.connect(self.handle_port_scan)
# Sistem başlangıcından çalışıp çalışmadığını kontrol et
self.started_from_startup = '--startup' in sys.argv
self.init_ui()
self.apply_dark_theme()
if QSystemTrayIcon.isSystemTrayAvailable():
self.create_tray_icon()
self.load_settings_to_ui()
# Gerçek zamanlı korumayı başlat
if self.settings.get('real_time_protection'):
self.real_time_protection.start_protection()
# Ağ korumasını başlat
if self.settings.get('network_protection'):
self.network_protection.start_monitoring()
# Koruma UI'sini güncelle
self.update_protection_ui()
# Sidebar ikonunu güncelle
self.update_sidebar_icon()
# Sistem başlangıcından geliyorsa tray'e gizle
if self.started_from_startup:
self.hide()
# Socket server başlat (tek instance için)
self.start_socket_server()
def init_ui(self):
self.setWindowTitle(translator.get_text("main_title"))
self.setGeometry(100, 100, 1200, 800)
# Ana pencere ikonu - başlangıçta aktif koruma varsayalım
self.setWindowIcon(get_current_icon(True))
# Ana widget
central_widget = QWidget()
self.setCentralWidget(central_widget)
# Ana layout
main_layout = QHBoxLayout(central_widget)
# Sol panel (menü)
self.create_sidebar()
main_layout.addWidget(self.sidebar, 1)
# Sağ panel (içerik)
self.content_area = QStackedWidget()
self.content_area.setObjectName("contentArea")
main_layout.addWidget(self.content_area, 4)
self.create_status_bar()
def create_sidebar(self):
self.sidebar = QWidget()
self.sidebar.setObjectName("sidebar")
self.sidebar.setMaximumWidth(250)
sidebar_layout = QVBoxLayout(self.sidebar)
# Sidebar ikonu
self.sidebar_icon_label = QLabel()
self.sidebar_icon_label.setObjectName("sidebarIcon")
self.sidebar_icon_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
self.update_sidebar_icon()
title = QLabel("Linux SecureGuard")
title.setObjectName("sidebarTitle")
title.setAlignment(Qt.AlignmentFlag.AlignCenter)
sidebar_layout.addWidget(self.sidebar_icon_label)
sidebar_layout.addWidget(title)
# Koruma durumu
self.protection_card = self.create_status_card(translator.get_text("protection"), translator.get_text("active"), "active")
cards_layout.addWidget(self.protection_card)
# Son tarama
self.last_scan_card = self.create_status_card(translator.get_text("last_scan"), translator.get_text("not_done_yet"), "warning")
cards_layout.addWidget(self.last_scan_card)
# Tehdit sayısı - tıklanabilir
self.threat_card = self.create_status_card(translator.get_text("threats_count"), "0", "active")
self.threat_card.mousePressEvent = lambda event: self.show_quarantine_page()
self.threat_card.setCursor(Qt.CursorShape.PointingHandCursor)
cards_layout.addWidget(self.threat_card)
layout.addLayout(cards_layout)
# Koruma kontrolü
protection_group = QGroupBox(translator.get_text("real_time_protection"))
protection_layout = QHBoxLayout(protection_group)
self.protection_status_label = QLabel(f"{translator.get_text('status')}: {translator.get_text('active')}")
self.protection_status_label.setStyleSheet("color: #4a9d5f; font-weight: bold; font-size: 14px;")
self.toggle_protection_btn = QPushButton(translator.get_text("stop_protection"))
self.toggle_protection_btn.setObjectName("dangerButton")
self.toggle_protection_btn.clicked.connect(self.toggle_protection)
protection_layout.addWidget(self.protection_status_label)
protection_layout.addWidget(self.toggle_protection_btn)
layout.addWidget(protection_group)
# Hızlı eylemler
actions_group = QGroupBox(translator.get_text("quick_actions"))
actions_layout = QHBoxLayout(actions_group)
quick_scan_btn = QPushButton(translator.get_text("quick_scan"))
quick_scan_btn.clicked.connect(self.start_quick_scan_from_dashboard)
full_scan_btn = QPushButton(translator.get_text("full_scan"))
full_scan_btn.setObjectName("infoButton")
full_scan_btn.clicked.connect(self.start_full_scan_from_dashboard)
actions_layout.addWidget(quick_scan_btn)
actions_layout.addWidget(full_scan_btn)
layout.addWidget(actions_group)
layout.addStretch()
self.content_area.addWidget(dashboard)
def create_network_page(self):
network_page = QWidget()
layout = QVBoxLayout(network_page)
title = QLabel(translator.get_text("network_protection"))
title.setStyleSheet("font-size: 24px; font-weight: bold; color: #4a9d5f; margin-bottom: 20px;")
layout.addWidget(title)
# Ağ durumu
network_status_group = QGroupBox(translator.get_text("network_status"))
status_layout = QVBoxLayout(network_status_group)
self.network_status_label = QLabel(translator.get_text("network_protection_active"))
self.network_status_label.setStyleSheet("color: #4a9d5f; font-weight: bold; font-size: 14px;")
status_layout.addWidget(self.network_status_label)
# Port durumu
self.port_status_table = QTableWidget()
self.port_status_table.setColumnCount(3)
self.port_status_table.setHorizontalHeaderLabels([translator.get_text("port"), translator.get_text("status"), translator.get_text("service")])
self.port_status_table.horizontalHeader().setStretchLastSection(True)
status_layout.addWidget(self.port_status_table)
layout.addWidget(network_status_group)
# Ağ aktivitesi
activity_group = QGroupBox(translator.get_text("network_activity"))
activity_layout = QVBoxLayout(activity_group)
self.network_activity_table = QTableWidget()
self.network_activity_table.setColumnCount(4)
self.network_activity_table.setHorizontalHeaderLabels([translator.get_text("time"), translator.get_text("ip_address"), translator.get_text("port"), translator.get_text("status")])
self.network_activity_table.horizontalHeader().setStretchLastSection(True)
activity_layout.addWidget(self.network_activity_table)
layout.addWidget(activity_group)
# İstisna yönetimi
exceptions_group = QGroupBox(translator.get_text("exceptions"))
exceptions_layout = QVBoxLayout(exceptions_group)
# Güvenilir IP'ler
trusted_ips_layout = QHBoxLayout()
trusted_ips_layout.addWidget(QLabel(translator.get_text("trusted_ips")))
self.trusted_ip_input = QLineEdit()
self.trusted_ip_input.setPlaceholderText("IP address (e.g: 192.168.1.1)")
add_ip_btn = QPushButton(translator.get_text("add_ip"))
add_ip_btn.clicked.connect(self.add_trusted_ip_ui)
add_ip_btn.setObjectName("addButton")
trusted_ips_layout.addWidget(self.trusted_ip_input)
trusted_ips_layout.addWidget(add_ip_btn)
exceptions_layout.addLayout(trusted_ips_layout)
# Güvenilir portlar
trusted_ports_layout = QHBoxLayout()
trusted_ports_layout.addWidget(QLabel(translator.get_text("trusted_ports")))
self.trusted_port_input = QLineEdit()
self.trusted_port_input.setPlaceholderText("Port number (e.g: 8080)")
add_port_btn = QPushButton(translator.get_text("add_port"))
add_port_btn.clicked.connect(self.add_trusted_port_ui)
add_port_btn.setObjectName("addButton")
trusted_ports_layout.addWidget(self.trusted_port_input)
trusted_ports_layout.addWidget(add_port_btn)
exceptions_layout.addLayout(trusted_ports_layout)
# İstisna listesi
self.exceptions_table = QTableWidget()
self.exceptions_table.setColumnCount(3)
self.exceptions_table.setHorizontalHeaderLabels([translator.get_text("type"), translator.get_text("value"), translator.get_text("action")])
self.exceptions_table.horizontalHeader().setStretchLastSection(True)
exceptions_layout.addWidget(self.exceptions_table)
layout.addWidget(exceptions_group)
# Ağ kontrolleri
controls_layout = QHBoxLayout()
refresh_btn = QPushButton(translator.get_text("refresh"))
refresh_btn.clicked.connect(self.refresh_network_status)
refresh_btn.setObjectName("refreshButton")
block_ip_btn = QPushButton(translator.get_text("block_ip"))
block_ip_btn.clicked.connect(self.block_suspicious_ip)
block_ip_btn.setObjectName("dangerButton")
controls_layout.addWidget(refresh_btn)
controls_layout.addWidget(block_ip_btn)
controls_layout.addStretch()
layout.addLayout(controls_layout)
self.content_area.addWidget(network_page)
def create_scan_page(self):
scan_page = QWidget()
layout = QVBoxLayout(scan_page)
# Başlık
title = QLabel(translator.get_text("system_scan"))
title.setObjectName("pageTitle")
layout.addWidget(title)
# Tarama seçenekleri
scan_options = QGroupBox(translator.get_text("scan_options"))
options_layout = QVBoxLayout(scan_options)
# Tarama türü
scan_type_layout = QHBoxLayout()
self.quick_scan_radio = QRadioButton(translator.get_text("quick_scan_option"))
self.full_scan_radio = QRadioButton(translator.get_text("full_scan_option"))
self.custom_scan_radio = QRadioButton(translator.get_text("custom_scan_option"))
self.quick_scan_radio.setChecked(True)
scan_type_layout.addWidget(self.quick_scan_radio)
scan_type_layout.addWidget(self.full_scan_radio)
scan_type_layout.addWidget(self.custom_scan_radio)
options_layout.addLayout(scan_type_layout)
# Özel klasör seçimi
folder_layout = QHBoxLayout()
self.folder_path = QLineEdit()
self.folder_path.setPlaceholderText(translator.get_text("select_folder"))
browse_btn = QPushButton(translator.get_text("browse"))
browse_btn.clicked.connect(self.browse_folder)
folder_layout.addWidget(self.folder_path)
folder_layout.addWidget(browse_btn)
options_layout.addLayout(folder_layout)
layout.addWidget(scan_options)
# Tarama kontrolü
control_layout = QHBoxLayout()
self.start_scan_btn = QPushButton(translator.get_text("start_scan"))
self.start_scan_btn.clicked.connect(self.start_scan_from_page)
# QSS ile stillendirilecek
self.stop_scan_btn = QPushButton(translator.get_text("stop_scan"))
self.stop_scan_btn.clicked.connect(self.stop_scan)
self.stop_scan_btn.setEnabled(False)
self.stop_scan_btn.setObjectName("dangerButton")
control_layout.addWidget(self.start_scan_btn)
control_layout.addWidget(self.stop_scan_btn)
layout.addLayout(control_layout)
# İlerleme çubuğu
self.progress_bar = QProgressBar()
self.progress_bar.setVisible(False)
layout.addWidget(self.progress_bar)
# Tarama sonuçları
results_group = QGroupBox(translator.get_text("scan_results"))
results_layout = QVBoxLayout(results_group)
self.results_table = QTableWidget()
self.results_table.setColumnCount(3)
self.results_table.setHorizontalHeaderLabels([translator.get_text("file"), translator.get_text("status"), translator.get_text("threat_type")])
self.results_table.horizontalHeader().setStretchLastSection(True)
self.results_table.verticalHeader().setVisible(False)
self.results_table.setAlternatingRowColors(True)
self.results_table.setSelectionBehavior(QAbstractItemView.SelectionBehavior.SelectRows)
self.results_table.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeMode.Stretch)
self.results_table.horizontalHeader().setSectionResizeMode(1, QHeaderView.ResizeMode.ResizeToContents)
self.results_table.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeMode.ResizeToContents)
self.results_table.verticalHeader().setSectionResizeMode(QHeaderView.ResizeMode.ResizeToContents)
results_layout.addWidget(self.results_table)
layout.addWidget(results_group)
self.content_area.addWidget(scan_page)
def create_quarantine_page(self):
quarantine_page = QWidget()
layout = QVBoxLayout(quarantine_page)
title = QLabel(translator.get_text("quarantine_management"))
title.setStyleSheet("font-size: 24px; font-weight: bold; color: #4a9d5f; margin-bottom: 20px;")
layout.addWidget(title)
# Karantina tablosu
self.quarantine_table = QTableWidget()
self.quarantine_table.setColumnCount(4)
self.quarantine_table.setHorizontalHeaderLabels([translator.get_text("file"), translator.get_text("threat"), translator.get_text("date"), translator.get_text("actions")])
layout.addWidget(self.quarantine_table)
# Karantina eylemleri
actions_layout = QHBoxLayout()
restore_btn = QPushButton(translator.get_text("restore"))
restore_btn.clicked.connect(self.restore_from_quarantine)
delete_btn = QPushButton(translator.get_text("delete_permanent"))
delete_btn.clicked.connect(self.delete_from_quarantine)
whitelist_btn = QPushButton(translator.get_text("add_exception"))
whitelist_btn.clicked.connect(self.add_to_whitelist)
restore_btn.setObjectName("restoreButton")
delete_btn.setObjectName("dangerButton")
whitelist_btn.setObjectName("infoButton")
actions_layout.addWidget(restore_btn)
actions_layout.addWidget(delete_btn)
actions_layout.addWidget(whitelist_btn)
actions_layout.addStretch()
layout.addLayout(actions_layout)
self.content_area.addWidget(quarantine_page)
def create_threats_page(self):
threats_page = QWidget()
layout = QVBoxLayout(threats_page)
title = QLabel(translator.get_text("linux_threats"))
title.setStyleSheet("font-size: 24px; font-weight: bold; color: #4a9d5f; margin-bottom: 20px;")
layout.addWidget(title)
# Scroll area oluştur
scroll = QScrollArea()
scroll_widget = QWidget()
scroll_layout = QVBoxLayout(scroll_widget)
# Tehdit türleri
threat_info = get_linux_threat_info()
for threat_type, info in threat_info.items():
threat_group = QGroupBox(f"{threat_type.upper()} - {info['risk_level']} Risk")
threat_layout = QVBoxLayout(threat_group)
# Açıklama
desc_label = QLabel(info['description'])
desc_label.setWordWrap(True)
desc_label.setStyleSheet("color: #cccccc; margin: 5px;")
threat_layout.addWidget(desc_label)
# Örnekler
examples_text = "Examples: " if translator.get_current_language() == "en" else "Örnekler: "
examples_label = QLabel(f"{examples_text}{', '.join(info['examples'])}")
examples_label.setWordWrap(True)
examples_label.setStyleSheet("color: #b8860b; font-weight: bold; margin: 5px;")
threat_layout.addWidget(examples_label)
# Yaygın konumlar
locations_text = "Common Locations: " if translator.get_current_language() == "en" else "Yaygın Konumlar: "
locations_label = QLabel(f"{locations_text}{', '.join(info['common_locations'])}")
locations_label.setWordWrap(True)
locations_label.setStyleSheet("color: #cc6666; margin: 5px;")
threat_layout.addWidget(locations_label)
scroll_layout.addWidget(threat_group)
# Güvenlik ipuçları
tips_group = QGroupBox(translator.get_text("security_tips"))
tips_layout = QVBoxLayout(tips_group)
security_tips = get_linux_security_tips()
for tip in security_tips:
tip_label = QLabel(f"• {tip}")
tip_label.setStyleSheet("color: #4a9d5f; margin: 3px;")
tips_layout.addWidget(tip_label)
scroll_layout.addWidget(tips_group)
# Şüpheli konumlar
locations_group = QGroupBox(translator.get_text("suspicious_locations"))
locations_layout = QVBoxLayout(locations_group)
locations_text = "\n".join([f"• {loc}" for loc in SUSPICIOUS_LINUX_LOCATIONS])
locations_label = QLabel(locations_text)
locations_label.setStyleSheet("color: #cc6666; margin: 5px;")
locations_layout.addWidget(locations_label)
scroll_layout.addWidget(locations_group)
scroll.setWidget(scroll_widget)
scroll.setWidgetResizable(True)
layout.addWidget(scroll)
self.content_area.addWidget(threats_page)
def create_settings_page(self):
settings_page = QWidget()
layout = QVBoxLayout(settings_page)
title = QLabel(translator.get_text("settings"))
title.setStyleSheet("font-size: 24px; font-weight: bold; color: #4a9d5f; margin-bottom: 20px;")
layout.addWidget(title)
# Genel ayarlar