-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaestro.pyw
More file actions
1215 lines (1057 loc) · 55.5 KB
/
Copy pathmaestro.pyw
File metadata and controls
1215 lines (1057 loc) · 55.5 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
import lang
import os
import sys
import json
from pathlib import Path
from PyQt5.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
QHBoxLayout, QLabel, QLineEdit, QPushButton,
QListWidget, QListWidgetItem, QFileDialog,
QMessageBox, QGroupBox, QGridLayout, QComboBox,
QRadioButton, QButtonGroup, QCheckBox, QProgressDialog, QSpinBox)
from PyQt5.QtCore import Qt, QSize, QThread, pyqtSignal
from PyQt5.QtGui import QFont, QPixmap, QIcon
import requests
from io import BytesIO
import platform
import shutil
import tarfile
import re
import time
import subprocess
# Dictionary with countries and their code
countries = {
"Австралия": ("au", ""),
"Австрия": ("at", ""),
"Болгария": ("bg", ""),
"Бразилия": ("br", ""),
"Великобритания": ("gb", ""),
"Венгрия": ("hu", ""),
"Германия": ("de", ""),
"Дания": ("dk", ""),
"Исландия": ("is", ""),
"Испания": ("es", ""),
"Канада": ("ca", ""),
"Нидерланды": ("nl", ""),
"Польша": ("pl", ""),
"Россия": ("ru", ""),
"Румыния": ("ro", ""),
"Сингапур": ("sg", ""),
"Словакия": ("sk", ""),
"США": ("us", ""),
"Финляндия": ("fi", ""),
"Франция": ("fr", ""),
"Чехия": ("cz", ""),
"Швейцария": ("ch", ""),
"Швеция": ("se", ""),
"Япония": ("jp", "")
}
class CountryListWidget(QListWidget):
"""Custom list widget for displaying countries"""
def __init__(self, parent=None):
super().__init__(parent)
self.setSelectionMode(QListWidget.MultiSelection)
self.setMinimumHeight(200)
self.setFont(QFont("Segoe UI", 10))
def add_country(self, name, code):
"""Add a country item"""
item = QListWidgetItem(f"{name}")
item.setData(Qt.UserRole, code)
item.setData(Qt.UserRole + 1, name)
self.addItem(item)
def get_selected_countries(self):
"""Get list of selected country codes"""
codes = []
for item in self.selectedItems():
codes.append(item.data(Qt.UserRole))
return codes
class TorUpdaterThread(QThread):
progress = pyqtSignal(str)
finished = pyqtSignal(bool, str)
def __init__(self, channel="stable", archive_path=None):
super().__init__()
self.channel = channel
self.archive_path = archive_path
self.project_folder = Path(__file__).parent.absolute()
self.tor_latest_dir = self.project_folder / "tor"
self.backup_dir = self.project_folder / "backup"
def get_system_info(self):
os_name = platform.system().lower()
arch = platform.machine().lower()
if "windows" in os_name:
os_name = "windows"
elif "linux" in os_name:
os_name = "linux"
elif "darwin" in os_name:
os_name = "macos"
if arch in ["x86_64", "amd64"]:
arch = "x86_64"
elif arch in ["i386", "i686"]:
arch = "i686"
elif arch in ["aarch64", "arm64"]:
arch = "aarch64"
return os_name, arch
def get_bridges(self):
return ["webtunnel [2001:db8:cf6:ce7:c7fc:5a42:72d5:8c8b]:443 D0A1F802127A925F47A7C9713F17A9E1D1292E54 url=https://cdn-131.airstrip1.net/4c5d6e7f8g9h0i1j2k3l4m5n ver=0.0.2",
"webtunnel [2001:db8:50c6:f177:293a:6612:f682:feb0]:443 6736F1245C77FBDCE4252F5711DE3137A7C10125 url=https://www.itssohotrightnow.com/0bc106e5688f206329e24a350b084c43 ver=0.0.4",
"webtunnel [2001:db8:1ecc:edad:a642:10d8:adc1:c886]:443 C2176476CDD39DFAB550BBC94E1DF3980398E5FC url=https://mstdn.plus/Lohguu6eequaethu ver=0.0.2"]
def parse_download_url(self, html_content, os_name, arch, channel):
links = re.findall(r'href="(https://[^"]+tor-expert-bundle-[^"]+\.tar\.gz)"', html_content)
target_pattern = f"tor-expert-bundle-{os_name}-{arch}"
filtered_links = [l for l in links if target_pattern in l]
if not filtered_links:
return None
if channel == "alpha":
result = [l for l in filtered_links if "a" in l.split('/')[-2]]
else:
result = [l for l in filtered_links if "a" not in l.split('/')[-2]]
return result[0] if result else filtered_links[0]
def run(self):
tor_process = None
try:
try:
import subprocess, platform, time
self.progress.emit(T("Остановка всех процессов Tor...", "Stopping all Tor processes..."))
if platform.system().lower() == "windows":
subprocess.run(["taskkill", "/F", "/IM", "tor.exe"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
subprocess.run(["killall", "tor"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
time.sleep(1)
except:
pass
update_info_path = self.project_folder / "update_info.json"
if self.archive_path:
local_filename = Path(self.archive_path)
self.progress.emit(T(f"Использование локального архива: {local_filename.name}...", f"Using local archive: {local_filename.name}..."))
self._extract_and_apply(local_filename)
return
else:
self.progress.emit("Определение системы...")
os_name, arch = self.get_system_info()
base_dir = self.project_folder
if update_info_path.exists():
try:
with open(update_info_path, 'r') as f:
info = json.load(f)
folder_name = info.get('use_folder')
if folder_name and (self.project_folder / folder_name).exists():
base_dir = self.project_folder / folder_name
except:
pass
tor_exe = base_dir / "tor" / ("tor.exe" if os_name == "windows" else "tor")
lyrebird_exe = base_dir / "tor" / "pluggable_transports" / ("lyrebird.exe" if os_name == "windows" else "lyrebird")
if not tor_exe.exists():
found = False
for fallback in [self.project_folder, self.backup_dir, self.project_folder / "tor"]:
t_exe = fallback / "tor" / ("tor.exe" if os_name == "windows" else "tor")
l_exe = fallback / "tor" / "pluggable_transports" / ("lyrebird.exe" if os_name == "windows" else "lyrebird")
if t_exe.exists():
tor_exe, lyrebird_exe = t_exe, l_exe
found = True
break
if not found:
self.finished.emit(False, T("Tor executable не найден. Восстановите файлы или скачайте Tor вручную.", "Tor executable not found. Restore files or download Tor manually."))
return
self.progress.emit(T("Генерация временного torrc...", "Generating temporary torrc..."))
torrc_path = self.project_folder / "temp_torrc"
data_dir = self.project_folder / "temp_data"
data_dir.mkdir(exist_ok=True)
bridges_str = "\n".join([f"Bridge {b}" for b in self.get_bridges()])
torrc_content = f"""
DataDirectory {data_dir}
SocksPort 127.0.0.1:9750
UseBridges 1
ClientTransportPlugin meek_lite,obfs2,obfs3,obfs4,scramblesuit,webtunnel exec {lyrebird_exe}
AvoidDiskWrites 1
ClientOnly 1
{bridges_str}
"""
torrc_path.write_text(torrc_content.strip())
self.progress.emit(T("Запуск Tor для загрузки обновления...", "Starting Tor to download the update..."))
env = os.environ.copy()
if os_name != "windows":
lib_path = str(tor_exe.parent)
env['LD_LIBRARY_PATH'] = f"{lib_path}:{env.get('LD_LIBRARY_PATH', '')}"
os.chmod(tor_exe, 0o755)
if lyrebird_exe.exists():
os.chmod(lyrebird_exe, 0o755)
creation_flags = 0
if os_name == "windows":
creation_flags = subprocess.CREATE_NO_WINDOW
tor_process = subprocess.Popen(
[str(tor_exe), "-f", str(torrc_path)],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
universal_newlines=True,
env=env,
creationflags=creation_flags
)
self.progress.emit(T("Ожидание подключения Tor (Bootstrap)...", "Waiting for Tor connection (Bootstrap)..."))
bootstrapped = False
start_time = time.time()
timeout = 360
while True:
if tor_process.poll() is not None:
break
line = tor_process.stdout.readline()
if not line:
break
if "Bootstrapped 100%" in line:
bootstrapped = True
break
if time.time() - start_time > timeout:
break
if not bootstrapped:
tor_process.terminate()
self.finished.emit(False, T("Не удалось подключиться к сети Tor (таймаут).", "Failed to connect to the Tor network (timeout)."))
return
self.progress.emit(T("Tor подключен. Поиск обновлений...", "Tor connected. Searching for updates..."))
proxies = {
'http': 'socks5h://127.0.0.1:9750',
'https': 'socks5h://127.0.0.1:9750'
}
session = requests.Session()
session.proxies = proxies
response = session.get("https://www.torproject.org/download/tor/")
response.raise_for_status()
download_url = self.parse_download_url(response.text, os_name, arch, self.channel)
if not download_url:
tor_process.terminate()
self.finished.emit(False, T("Не удалось найти ссылку на скачивание.", "Failed to find the download link."))
return
self.progress.emit(T(f"Скачивание обновления: {download_url.split('/')[-1]}...", f"Downloading update: {download_url.split('/')[-1]}..."))
local_filename = self.project_folder / download_url.split('/')[-1]
with session.get(download_url, stream=True) as r:
r.raise_for_status()
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=8192):
f.write(chunk)
if not self.archive_path:
self.progress.emit(T("Остановка временного Tor...", "Stopping temporary Tor..."))
tor_process.terminate()
tor_process.wait()
tor_process = None
self._extract_and_apply(local_filename)
except Exception as e:
if tor_process:
try:
tor_process.terminate()
except:
pass
self.finished.emit(False, T(f"Ошибка при обновлении: {str(e)}", f"Error during update: {str(e)}"))
def _extract_and_apply(self, local_filename):
self.progress.emit(T("Распаковка обновления...", "Extracting update..."))
try:
if self.backup_dir.exists():
shutil.rmtree(self.backup_dir)
self.backup_dir.mkdir(parents=True, exist_ok=True)
for d in ['tor', 'data', 'docs']:
src = self.project_folder / d
if src.exists():
shutil.move(str(src), str(self.backup_dir / d))
except PermissionError as pe:
self.finished.emit(False, T(f"Файлы заняты другим процессом. Закройте ToInet/Tor и попробуйте снова.\nПодробности: {pe}", f"Files are locked by another process. Close ToInet/Tor and try again.\nDetails: {pe}"))
return
if str(local_filename).endswith('.zip'):
import zipfile
with zipfile.ZipFile(local_filename, 'r') as zip_ref:
zip_ref.extractall(self.project_folder)
else:
import tarfile
with tarfile.open(local_filename, "r:gz") as tar:
if hasattr(tarfile, 'data_filter'):
tar.extractall(path=self.project_folder, filter='data')
else:
tar.extractall(path=self.project_folder)
if not self.archive_path:
import os
try: os.remove(local_filename)
except: pass
# FIX: Move tor, data, docs out of tor/ if Tor archive has them nested
import shutil
for d in ['data', 'docs']:
wrong_path = self.project_folder / "tor" / d
right_path = self.project_folder / d
if wrong_path.exists():
if right_path.exists():
shutil.rmtree(str(right_path))
shutil.move(str(wrong_path), str(right_path))
tor_inner = self.project_folder / "tor" / "tor"
tor_exe_inner = self.project_folder / "tor" / "tor" / "tor.exe"
tor_exe_right = self.project_folder / "tor" / "tor.exe"
if tor_exe_inner.exists() and not tor_exe_right.exists():
# Meaning it unpacked to tor/tor/tor.exe
# We should move contents of tor/tor to tor/
temp_tor = self.project_folder / "tor_temp_swap"
shutil.move(str(tor_inner), str(temp_tor))
shutil.rmtree(str(self.project_folder / "tor"))
shutil.move(str(temp_tor), str(self.project_folder / "tor"))
self.progress.emit("Обновление конфигурации...")
update_info_path = self.project_folder / "update_info.json"
info = {}
if update_info_path.exists():
import json
with open(update_info_path, 'r') as f:
info = json.load(f)
if 'use_folder' in info:
del info['use_folder']
info['branch'] = self.channel
import json
with open(update_info_path, 'w') as f:
json.dump(info, f)
self.finished.emit(True, T("Обновление успешно завершено! Изменения вступят в силу после перезапуска.", "Update successfully completed! Changes will take effect after restart."))
class TorrcConfigurator(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Конфигуратор")
self.setMinimumSize(800, 950)
self.setStyleSheet("""
QMainWindow {
background-color: #2b2b2b;
}
QGroupBox {
font-weight: bold;
border: 2px solid #555;
border-radius: 5px;
margin-top: 10px;
padding-top: 10px;
font-size: 12px;
color: #e0e0e0;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 10px;
padding: 0 5px 0 5px;
color: #4CAF50;
}
QLabel {
color: #e0e0e0;
font-size: 11px;
}
QLineEdit {
padding: 5px;
border: 1px solid #555;
border-radius: 3px;
background-color: #3c3c3c;
color: #e0e0e0;
font-size: 11px;
}
QLineEdit:focus {
border-color: #4CAF50;
}
QPushButton {
background-color: #4CAF50;
border: none;
padding: 8px 16px;
border-radius: 4px;
color: white;
font-weight: bold;
font-size: 11px;
}
QPushButton:hover {
background-color: #45a049;
}
QPushButton:pressed {
background-color: #3d8b40;
}
QPushButton#browseBtn {
background-color: #555;
padding: 5px 15px;
}
QPushButton#browseBtn:hover {
background-color: #666;
}
QListWidget {
background-color: #3c3c3c;
border: 1px solid #555;
border-radius: 3px;
color: #e0e0e0;
font-size: 11px;
outline: none;
}
QListWidget::item:selected {
background-color: #4CAF50;
color: white;
}
QListWidget::item:hover {
background-color: #555;
}
QScrollBar:vertical {
border: none;
background-color: #2b2b2b;
width: 10px;
margin: 0px;
}
QScrollBar::handle:vertical {
background-color: #555;
border-radius: 5px;
min-height: 20px;
}
QScrollBar::handle:vertical:hover {
background-color: #666;
}
QRadioButton {
color: #e0e0e0;
font-size: 11px;
spacing: 8px;
}
QRadioButton::indicator {
width: 13px;
height: 13px;
}
QRadioButton::indicator:unchecked {
border: 1px solid #555;
border-radius: 7px;
background-color: #3c3c3c;
}
QRadioButton::indicator:checked {
border: 1px solid #4CAF50;
border-radius: 7px;
background-color: #4CAF50;
}
QComboBox {
padding: 5px;
border: 1px solid #555;
border-radius: 3px;
background-color: #3c3c3c;
color: #e0e0e0;
font-size: 11px;
}
QComboBox::drop-down {
border: none;
}
QComboBox::down-arrow {
image: none;
border-left: 5px solid transparent;
border-right: 5px solid transparent;
border-top: 5px solid #e0e0e0;
margin-right: 5px;
}
QComboBox:hover {
border-color: #4CAF50;
}
""")
# Set default paths
self.current_dir = os.getcwd()
# Determine base tor dir from update_info.json
self.base_tor_dir = self.current_dir
update_info_path = os.path.join(self.current_dir, "update_info.json")
if os.path.exists(update_info_path):
try:
with open(update_info_path, 'r') as f:
info = json.load(f)
folder_name = info.get('use_folder')
if folder_name and os.path.exists(os.path.join(self.current_dir, folder_name)):
self.base_tor_dir = os.path.join(self.current_dir, folder_name)
except:
pass
self.data_dir = os.path.join(self.base_tor_dir, "data")
self.geoip_path = os.path.join(self.base_tor_dir, "data", "geoip")
self.geoipv6_path = os.path.join(self.base_tor_dir, "data", "geoip6")
self.bridges_path = os.path.join(self.current_dir, "bridges.txt")
self.pt_config_path = os.path.join(self.base_tor_dir, "tor", "pluggable_transports", "pt_config.json")
self.init_ui()
def init_ui(self):
"""Initialize the user interface"""
central_widget = QWidget()
self.setCentralWidget(central_widget)
main_layout = QVBoxLayout(central_widget)
main_layout.setSpacing(15)
main_layout.setContentsMargins(20, 20, 20, 20)
# Countries selection group
countries_group = QGroupBox(T("Выбрать страны конечного ip", "Select exit IP countries"))
countries_layout = QVBoxLayout()
countries_layout.setSpacing(10)
# Country list
self.country_list = CountryListWidget()
for name, (code, _) in sorted(countries.items()):
self.country_list.add_country(name, code)
countries_layout.addWidget(self.country_list)
# Selected countries display
self.selected_label = QLabel(T("Выбрано: Ничего", "Selected: None"))
self.selected_label.setStyleSheet("color: #4CAF50; font-weight: bold;")
self.selected_label.setAlignment(Qt.AlignCenter)
self.country_list.itemSelectionChanged.connect(self.update_selected_label)
countries_layout.addWidget(self.selected_label)
countries_group.setLayout(countries_layout)
main_layout.addWidget(countries_group)
# Bridges mode selection group
bridges_mode_group = QGroupBox(T("Режим мостов", "Bridges Mode"))
bridges_mode_layout = QVBoxLayout()
# Radio buttons for bridge modes
self.bridge_mode_group = QButtonGroup()
self.normal_mode_rb = QRadioButton(T("Обычный режим (использовать bridges.txt)", "Normal mode (use bridges.txt)"))
self.normal_mode_rb.setChecked(True)
self.obfs4_mode_rb = QRadioButton(T("Предустановленные obfs4 мосты", "Pre-installed obfs4 bridges"))
self.snowflake_mode_rb = QRadioButton(T("Предустановленные snowflake мосты", "Pre-installed snowflake bridges"))
self.conjure_mode_rb = QRadioButton(T("Предустановленные conjure мосты", "Pre-installed conjure bridges"))
self.meek_mode_rb = QRadioButton(T("Предустановленные meek мосты", "Pre-installed meek bridges"))
self.bridge_mode_group.addButton(self.normal_mode_rb, 0)
self.bridge_mode_group.addButton(self.obfs4_mode_rb, 1)
self.bridge_mode_group.addButton(self.snowflake_mode_rb, 2)
self.bridge_mode_group.addButton(self.conjure_mode_rb, 3)
self.bridge_mode_group.addButton(self.meek_mode_rb, 4)
bridges_mode_layout.addWidget(self.normal_mode_rb)
bridges_mode_layout.addWidget(self.obfs4_mode_rb)
bridges_mode_layout.addWidget(self.snowflake_mode_rb)
bridges_mode_layout.addWidget(self.conjure_mode_rb)
bridges_mode_layout.addWidget(self.meek_mode_rb)
# Connect radio buttons to update UI
self.normal_mode_rb.toggled.connect(self.on_bridge_mode_changed)
self.obfs4_mode_rb.toggled.connect(self.on_bridge_mode_changed)
self.snowflake_mode_rb.toggled.connect(self.on_bridge_mode_changed)
self.conjure_mode_rb.toggled.connect(self.on_bridge_mode_changed)
self.meek_mode_rb.toggled.connect(self.on_bridge_mode_changed)
bridges_mode_group.setLayout(bridges_mode_layout)
main_layout.addWidget(bridges_mode_group)
# Bridges file group (for normal mode)
bridges_file_group = QGroupBox(T("Мосты (для обычного режима)", "Bridges (for normal mode)"))
bridges_file_layout = QGridLayout()
bridges_label = QLabel(T("Файл мостов (bridges.txt):", "Bridges file (bridges.txt):"))
bridges_label.setStyleSheet("font-weight: normal;")
bridges_file_layout.addWidget(bridges_label, 0, 0)
self.bridges_edit = QLineEdit()
self.bridges_edit.setText(self.bridges_path)
self.bridges_edit.setReadOnly(True)
bridges_file_layout.addWidget(self.bridges_edit, 0, 1)
bridges_browse_btn = QPushButton(T("Выбрать", "Browse"))
bridges_browse_btn.setObjectName("browseBtn")
bridges_browse_btn.clicked.connect(self.browse_bridges)
bridges_file_layout.addWidget(bridges_browse_btn, 0, 2)
bridges_file_group.setLayout(bridges_file_layout)
main_layout.addWidget(bridges_file_group)
self.bridges_file_group = bridges_file_group
# Tor directories group
tor_group = QGroupBox(T("Файлы TOR", "TOR Files"))
tor_layout = QGridLayout()
# Data directory
data_label = QLabel(T("Папка Data:", "Data Folder:"))
data_label.setStyleSheet("font-weight: normal;")
tor_layout.addWidget(data_label, 0, 0)
self.data_edit = QLineEdit()
self.data_edit.setText(self.data_dir)
tor_layout.addWidget(self.data_edit, 0, 1)
data_browse_btn = QPushButton(T("Выбрать", "Browse"))
data_browse_btn.setObjectName("browseBtn")
data_browse_btn.clicked.connect(self.browse_data_dir)
tor_layout.addWidget(data_browse_btn, 0, 2)
# GeoIP file
geoip_label = QLabel(T("GeoIP Файл:", "GeoIP File:"))
geoip_label.setStyleSheet("font-weight: normal;")
tor_layout.addWidget(geoip_label, 1, 0)
self.geoip_edit = QLineEdit()
self.geoip_edit.setText(self.geoip_path)
tor_layout.addWidget(self.geoip_edit, 1, 1)
geoip_browse_btn = QPushButton(T("Выбрать", "Browse"))
geoip_browse_btn.setObjectName("browseBtn")
geoip_browse_btn.clicked.connect(lambda: self.browse_file(self.geoip_edit))
tor_layout.addWidget(geoip_browse_btn, 1, 2)
# GeoIPv6 file
geoipv6_label = QLabel(T("GeoIPv6 Файл:", "GeoIPv6 File:"))
geoipv6_label.setStyleSheet("font-weight: normal;")
tor_layout.addWidget(geoipv6_label, 2, 0)
self.geoipv6_edit = QLineEdit()
self.geoipv6_edit.setText(self.geoipv6_path)
tor_layout.addWidget(self.geoipv6_edit, 2, 1)
geoipv6_browse_btn = QPushButton(T("Выбрать", "Browse"))
geoipv6_browse_btn.setObjectName("browseBtn")
geoipv6_browse_btn.clicked.connect(lambda: self.browse_file(self.geoipv6_edit))
tor_layout.addWidget(geoipv6_browse_btn, 2, 2)
tor_group.setLayout(tor_layout)
main_layout.addWidget(tor_group)
# Upstream Proxy group
proxy_group = QGroupBox(T("Прокси для TOR (Upstream Proxy)", "Proxy for TOR (Upstream Proxy)"))
proxy_layout = QGridLayout()
proxy_type_label = QLabel(T("Тип прокси:", "Proxy Type:"))
proxy_layout.addWidget(proxy_type_label, 0, 0)
self.proxy_type_combo = QComboBox()
self.proxy_type_combo.addItems([T("Нет", "None"), "SOCKS4", "SOCKS5", "HTTP/HTTPS"])
proxy_layout.addWidget(self.proxy_type_combo, 0, 1)
proxy_host_label = QLabel(T("Адрес:", "Address:"))
proxy_layout.addWidget(proxy_host_label, 1, 0)
self.proxy_host_edit = QLineEdit()
self.proxy_host_edit.setPlaceholderText("127.0.0.1")
proxy_layout.addWidget(self.proxy_host_edit, 1, 1)
proxy_port_label = QLabel(T("Порт:", "Port:"))
proxy_layout.addWidget(proxy_port_label, 1, 2)
self.proxy_port_edit = QLineEdit()
self.proxy_port_edit.setPlaceholderText("1080")
self.proxy_port_edit.setFixedWidth(60)
proxy_layout.addWidget(self.proxy_port_edit, 1, 3)
proxy_user_label = QLabel(T("Логин:", "Username:"))
proxy_layout.addWidget(proxy_user_label, 2, 0)
self.proxy_user_edit = QLineEdit()
proxy_layout.addWidget(self.proxy_user_edit, 2, 1)
proxy_pass_label = QLabel(T("Пароль:", "Password:"))
proxy_layout.addWidget(proxy_pass_label, 2, 2)
self.proxy_pass_edit = QLineEdit()
self.proxy_pass_edit.setEchoMode(QLineEdit.Password)
proxy_layout.addWidget(self.proxy_pass_edit, 2, 3)
proxy_group.setLayout(proxy_layout)
main_layout.addWidget(proxy_group)
# Tor Update Settings
update_group = QGroupBox(T("Настройки обновления TOR", "TOR Update Settings"))
update_layout = QGridLayout()
branch_label = QLabel(T("Ветка обновления:", "Update Branch:"))
branch_label.setStyleSheet("font-weight: normal;")
update_layout.addWidget(branch_label, 0, 0)
self.branch_combo = QComboBox()
self.branch_combo.addItems(["stable", "alpha"])
update_layout.addWidget(self.branch_combo, 0, 1)
self.autoupdate_cb = QCheckBox(T("Автообновление TOR при запуске ToInet", "Auto-update TOR when ToInet starts"))
self.autoupdate_cb.setStyleSheet("color: #e0e0e0; font-size: 11px;")
self.autoupdate_cb.toggled.connect(self.on_autoupdate_changed)
update_layout.addWidget(self.autoupdate_cb, 1, 0, 1, 2)
update_btn = QPushButton(T("Проверить и обновить", "Check and update"))
update_btn.clicked.connect(self.run_update)
update_layout.addWidget(update_btn, 2, 0)
rollback_btn = QPushButton(T("Откат к бекапу", "Rollback to backup"))
rollback_btn.clicked.connect(self.rollback_update)
update_layout.addWidget(rollback_btn, 2, 1)
archive_btn = QPushButton(T("Установить из архива", "Install from archive"))
archive_btn.clicked.connect(self.install_from_archive)
update_layout.addWidget(archive_btn, 3, 0, 1, 2)
update_group.setLayout(update_layout)
main_layout.addWidget(update_group)
self.load_update_settings()
# Proxy Pool
pool_group = QGroupBox(T("Пул прокси (Load Balancing)", "Proxy Pool (Load Balancing)"))
pool_group.setFont(QFont("Segoe UI", 10))
pool_layout = QHBoxLayout(pool_group)
self.pool_checkbox = QCheckBox(T("Включить пул (запуск нескольких экземпляров)", "Enable Pool (Run multiple instances)"))
self.pool_spinbox = QSpinBox()
self.pool_spinbox.setRange(2, 10)
self.pool_spinbox.setValue(3)
self.pool_spinbox.setEnabled(False)
self.pool_checkbox.toggled.connect(self.pool_spinbox.setEnabled)
pool_layout.addWidget(self.pool_checkbox)
pool_layout.addWidget(QLabel(T("Количество:", "Count:")))
pool_layout.addWidget(self.pool_spinbox)
main_layout.addWidget(pool_group)
self.load_pool_settings()
# Generate button
generate_btn = QPushButton(T("Создать конфигурацию", "Generate Configuration"))
generate_btn.setMinimumHeight(40)
generate_btn.setStyleSheet("""
QPushButton {
background-color: #4CAF50;
font-size: 14px;
font-weight: bold;
}
QPushButton:hover {
background-color: #45a049;
}
""")
generate_btn.clicked.connect(self.generate_torrc)
main_layout.addWidget(generate_btn)
def load_update_settings(self):
update_info_path = os.path.join(self.current_dir, "update_info.json")
if os.path.exists(update_info_path):
try:
with open(update_info_path, 'r') as f:
info = json.load(f)
if info.get('auto_update', False):
self.autoupdate_cb.setChecked(True)
branch = info.get('branch', 'stable')
index = self.branch_combo.findText(branch)
if index >= 0:
self.branch_combo.setCurrentIndex(index)
except:
pass
def load_pool_settings(self):
config_path = os.path.join(self.current_dir, "config.json")
if os.path.exists(config_path):
try:
with open(config_path, 'r', encoding='utf-8') as f:
config = json.load(f)
pool_enabled = config.get("tor_pool_enabled", False)
pool_size = config.get("tor_pool_size", 3)
self.pool_checkbox.setChecked(pool_enabled)
self.pool_spinbox.setValue(pool_size)
except:
pass
def on_autoupdate_changed(self, state):
update_info_path = os.path.join(self.current_dir, "update_info.json")
info = {}
if os.path.exists(update_info_path):
try:
with open(update_info_path, 'r') as f:
info = json.load(f)
except:
pass
info['auto_update'] = self.autoupdate_cb.isChecked()
try:
with open(update_info_path, 'w') as f:
json.dump(info, f)
except:
pass
def install_from_archive(self):
file_path, _ = QFileDialog.getOpenFileName(self, T("Выберите архив Tor", "Select Tor archive"), "", "Archives (*.zip *.tar.gz)")
if file_path:
self.run_update(archive_path=file_path)
def run_update(self, archive_path=None):
branch = self.branch_combo.currentText()
# Save branch preference
self.on_autoupdate_changed(None)
update_info_path = os.path.join(self.current_dir, "update_info.json")
try:
with open(update_info_path, 'r') as f:
info = json.load(f)
info['branch'] = branch
with open(update_info_path, 'w') as f:
json.dump(info, f)
except:
pass
# Check IP only if downloading
if not archive_path:
country_code = None
try:
res = requests.get('http://ip-api.com/json', proxies={'http': 'socks5h://127.0.0.1:9853', 'https': 'socks5h://127.0.0.1:9853'}, timeout=3).json()
country_code = res.get('countryCode')
except:
try:
res = requests.get('http://ip-api.com/json', timeout=3).json()
country_code = res.get('countryCode')
except:
pass
if country_code == 'RU':
QMessageBox.warning(self, T("Внимание", "Warning"), T("Отключите все экземпляры TOR, скачивание из РФ невозможно.", "Disable all TOR instances, downloading from RF is impossible."))
return
elif country_code == 'GB':
reply = QMessageBox.question(self, T("Предупреждение", "Warning"), T("Внимание: скачивание Tor в Великобритании может привлечь внимание госорганов. Продолжить?", "Warning: downloading Tor in the UK may attract the attention of government authorities. Continue?"), QMessageBox.Yes | QMessageBox.No)
if reply == QMessageBox.No:
return
self.progress_dialog = QProgressDialog(T("Подготовка к обновлению...", "Preparing to update..."), T("Отмена", "Cancel"), 0, 0, self)
self.progress_dialog.setWindowTitle(T("Обновление Tor", "Tor Update"))
self.progress_dialog.setWindowModality(Qt.WindowModal)
self.progress_dialog.setCancelButton(None)
self.progress_dialog.setStyleSheet("""
QProgressDialog {
background-color: #2b2b2b;
color: #e0e0e0;
}
QLabel {
color: #e0e0e0;
font-weight: bold;
font-size: 12px;
}
QProgressBar {
border: 1px solid #555;
border-radius: 3px;
background-color: #3c3c3c;
text-align: center;
}
QProgressBar::chunk {
background-color: #4CAF50;
}
""")
self.progress_dialog.show()
self.updater_thread = TorUpdaterThread(channel=branch, archive_path=archive_path)
self.updater_thread.progress.connect(self.update_progress)
self.updater_thread.finished.connect(self.update_finished)
self.updater_thread.start()
def update_progress(self, msg):
if hasattr(self, 'progress_dialog') and self.progress_dialog:
self.progress_dialog.setLabelText(msg)
def update_finished(self, success, msg):
if hasattr(self, 'progress_dialog') and self.progress_dialog:
self.progress_dialog.close()
if success:
QMessageBox.information(self, T("Успех", "Success"), msg)
new_dir = os.path.join(self.current_dir, "tor")
if os.path.exists(new_dir):
self.base_tor_dir = new_dir
self.data_edit.setText(os.path.join(new_dir, "data"))
self.geoip_edit.setText(os.path.join(new_dir, "data", "geoip"))
self.geoipv6_edit.setText(os.path.join(new_dir, "data", "geoip6"))
else:
QMessageBox.critical(self, T("Ошибка", "Error"), msg)
def rollback_update(self):
update_info_path = os.path.join(self.current_dir, "update_info.json")
backup_dir = os.path.join(self.current_dir, "backup")
if not os.path.exists(backup_dir):
QMessageBox.warning(self, T("Ошибка", "Error"), T("Папка backup не найдена. Откат невозможен.", "Backup folder not found. Rollback is impossible."))
return
try:
import subprocess, platform, time
if platform.system().lower() == "windows":
subprocess.run(["taskkill", "/F", "/IM", "tor.exe"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
else:
subprocess.run(["killall", "tor"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
time.sleep(1)
except:
pass
try:
import shutil
# Move from backup to root
for d in ['tor', 'data', 'docs']:
src = os.path.join(backup_dir, d)
dst = os.path.join(self.current_dir, d)
if os.path.exists(src):
if os.path.exists(dst):
shutil.rmtree(dst)
shutil.move(src, dst)
# Delete tor_latest if it exists
tor_latest_dir = os.path.join(self.current_dir, "tor_latest")
if os.path.exists(tor_latest_dir):
shutil.rmtree(tor_latest_dir)
info = {}
if os.path.exists(update_info_path):
with open(update_info_path, 'r') as f:
info = json.load(f)
info['use_folder'] = ''
with open(update_info_path, 'w') as f:
json.dump(info, f)
QMessageBox.information(self, T("Успешно", "Success"), T("Откат выполнен успешно. Файлы восстановлены из бекапа.", "Rollback successful. Files restored from backup."))
self.base_tor_dir = self.current_dir
self.data_edit.setText(os.path.join(self.current_dir, "data"))
self.geoip_edit.setText(os.path.join(self.current_dir, "data", "geoip"))
self.geoipv6_edit.setText(os.path.join(self.current_dir, "data", "geoip6"))
except PermissionError:
QMessageBox.critical(self, T("Ошибка", "Error"), T("Файлы заняты другим процессом. Пожалуйста, закройте ToInet/Tor перед откатом.", "Files are locked by another process. Please close ToInet/Tor before rolling back."))
except Exception as e:
QMessageBox.critical(self, T("Ошибка", "Error"), T(f"Не удалось выполнить откат: {e}", f"Failed to rollback: {e}"))
def on_bridge_mode_changed(self):
"""Handle bridge mode change"""
if self.normal_mode_rb.isChecked():
self.bridges_file_group.setEnabled(True)
else:
self.bridges_file_group.setEnabled(False)
def update_selected_label(self):
"""Update the selected countries label"""
selected = self.country_list.selectedItems()
if selected:
countries_text = []
for item in selected:
name = item.data(Qt.UserRole + 1)
countries_text.append(name)
self.selected_label.setText(f"Выбрано: {', '.join(countries_text)}")
else:
self.selected_label.setText("Выбрано: Ничего")
def browse_bridges(self):
"""Browse for bridges.txt file"""
path, _ = QFileDialog.getOpenFileName(
self, "Выберите файл моста", "", "Text Files (*.txt);;All Files (*)"
)
if path:
self.bridges_edit.setText(path)
def browse_data_dir(self):
"""Browse for data directory"""
path = QFileDialog.getExistingDirectory(self, "Выбрать Data папку")
if path:
self.data_edit.setText(path)
def browse_file(self, line_edit):
"""Browse for any file"""
path, _ = QFileDialog.getOpenFileName(self, "Выбрать Файл")
if path:
line_edit.setText(path)
def load_pt_config(self):
"""Load pluggable transports configuration from JSON file"""
try:
if os.path.exists(self.pt_config_path):
with open(self.pt_config_path, 'r', encoding='utf-8') as f:
return json.load(f)
else:
# Return default config if file not found
return {
"pluggableTransports": {
"lyrebird": "ClientTransportPlugin meek_lite,obfs2,obfs3,obfs4,scramblesuit,webtunnel exec ${pt_path}lyrebird.exe",
"snowflake": "ClientTransportPlugin snowflake exec ${pt_path}lyrebird.exe",
"conjure": "ClientTransportPlugin conjure exec ${pt_path}conjure-client.exe -registerURL https://registration.refraction.network/api"
},
"bridges": {
"meek": [
"meek_lite 192.0.2.20:80 url=https://1603026938.rsc.cdn77.org front=www.phpmyadmin.net utls=HelloRandomizedALPN"
],
"obfs4": [
"obfs4 37.218.245.14:38224 D9A82D2F9C2F65A18407B1D2B764F130847F8B5D cert=bjRaMrr1BRiAW8IE9U5z27fQaYgOhX1UCmOpg2pFpoMvo6ZgQMzLsaTzzQNTlm7hNcb+Sg iat-mode=0",
"obfs4 209.148.46.65:443 74FAD13168806246602538555B5521A0383A1875 cert=ssH+9rP8dG2NLDN2XuFw63hIO/9MNNinLmxQDpVa+7kTOa9/m+tGWT1SmSYpQ9uTBGa6Hw iat-mode=0",
"obfs4 146.57.248.225:22 10A6CD36A537FCE513A322361547444B393989F0 cert=K1gDtDAIcUfeLqbstggjIw2rtgIKqdIhUlHp82XRqNSq/mtAjp1BIC9vHKJ2FAEpGssTPw iat-mode=0",
"obfs4 45.145.95.6:27015 C5B7CD6946FF10C5B3E89691A7D3F2C122D2117C cert=TD7PbUO0/0k6xYHMPW3vJxICfkMZNdkRrb63Zhl5j9dW3iRGiCx0A7mPhe5T2EDzQ35+Zw iat-mode=0",