-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwangyu.py
6720 lines (5386 loc) · 299 KB
/
wangyu.py
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
#Author: https://github.com/Azumi67
import os
import subprocess
import platform
import urllib.request
import yaml
import shutil
import colorama
import io
from colorama import Fore, Style
from time import sleep
import sys
import re
import readline
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding="utf-8", errors="replace")
if os.geteuid() != 0:
print("\033[91mThis script must be run as root. Please use sudo -i.\033[0m")
sys.exit(1)
def logo():
logo_path = "/etc/logo2.sh"
try:
subprocess.run(["bash", "-c", logo_path], check=True)
except subprocess.CalledProcessError as e:
return e
return None
BASE_URL = "https://github.com/Azumi67/Wangyu_azumi_UDP/releases/download/cores/"
FILE_NAMES = {
"amd64": {
"tinyvpn": "tinyvpn_amd64",
"udp2raw": "udp2raw_amd64",
"speederv2": "speederv2_amd64"
},
"arm64": {
"tinyvpn": "tinyvpn_arm64",
"udp2raw": "udp2raw_arm64",
"speederv2": "speederv2_arm64"
}
}
def download_file(file_key, destination):
arch = platform.architecture()[0]
if "64bit" in arch:
arch = "amd64"
elif "32bit" in arch:
arch = "arm"
file_name = FILE_NAMES.get(arch, {}).get(file_key)
if file_name:
url = f"{BASE_URL}{file_name}"
temp_destination = destination + "_" + arch
if not os.path.exists(destination):
print(f"Downloading {file_key} ({file_name})...")
subprocess.run(["wget", "-q", "--show-progress", url, "-O", temp_destination])
os.rename(temp_destination, destination)
subprocess.run(["chmod", "+x", destination])
print(f"Downloaded and renamed to {destination}")
else:
print(f"{destination} already exists. Skipping download.")
else:
print(f"Error: No file found for {file_key} with architecture {arch}.")
def make_executable(file_path):
subprocess.run(["chmod", "+x", file_path])
def get_binary_path(component):
base_component = component.split('_')[0]
component_map = {
"tinyvpn": "tinyvpn",
"udp2raw": "udp2raw",
"speederv2": "speederv2",
}
binary_key = component_map.get(base_component, base_component)
return f"/usr/local/bin/{binary_key}"
def create_service(name, command):
binary_path = get_binary_path(name)
if not binary_path or not os.path.exists(binary_path):
print(f"Error: Binary for {name} does not exist. Skipping service creation.")
return
service_path = f"/etc/systemd/system/{name}.service"
service_content = f"""[Unit]
Description={name} service
[Service]
ExecStart={binary_path} {command}
Restart=always
User=root
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open(service_path, "w") as f:
f.write(service_content)
display_notification(f"\n\033[93mCreated {name} service at {service_path}\033[0m")
subprocess.run(["systemctl", "daemon-reload"])
subprocess.run(["systemctl", "enable", name])
subprocess.run(["systemctl", "restart", name])
display_checkmark(f"\033[92mService {name} started and enabled\033[0m")
def display_checkmark(message):
print("\u2714 " + message)
def display_error(message):
print("\u2718 Error: " + message)
def display_notification(message):
print("\u2728 " + message)
def uninstall_proxy_forwarders():
os.system("clear")
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mRemoving \033[92mForwarder...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
service_name = "proxyforwarder"
service_path = f"/etc/systemd/system/{service_name}.service"
binary_path = "/usr/local/bin/proxyforwarder"
daemon_service_path = "/etc/systemd/system/proxyforwarder_daemon.service"
daemon_script_path = "/usr/local/bin/proxyforwarder_daemon.sh"
try:
subprocess.run(["systemctl", "stop", service_name], check=True)
subprocess.run(["systemctl", "disable", service_name], check=True)
except subprocess.CalledProcessError:
print(f"\033[91mWarning: Failed to stop or disable {service_name} (might not exist).\033[0m")
try:
if os.path.exists(service_path):
os.remove(service_path)
display_checkmark(f"\033[92mRemoved service file: {service_path}\033[0m")
else:
print(f"\033[91mWarning: Service file for {service_name} not found.\033[0m")
except Exception as e:
print(f"\033[91mError removing service file: {e}\033[0m")
try:
if os.path.exists(binary_path):
if os.path.isdir(binary_path):
shutil.rmtree(binary_path)
display_checkmark(f"\033[92mRemoved directory: {binary_path}\033[0m")
else:
os.remove(binary_path)
display_checkmark(f"\033[92mRemoved binary file: {binary_path}\033[0m")
else:
print("\033[91mWarning: ProxyForwarder directory or binary not found.\033[0m")
except Exception as e:
print(f"\033[91mError removing ProxyForwarder: {e}\033[0m")
try:
if os.path.exists(daemon_service_path):
os.remove(daemon_service_path)
display_checkmark(f"\033[92mRemoved daemon service file: {daemon_service_path}\033[0m")
else:
print(f"\033[91mWarning: Daemon service file '{daemon_service_path}' not found.\033[0m")
except Exception as e:
print(f"\033[91mError removing daemon service file: {e}\033[0m")
try:
if os.path.exists(daemon_script_path):
os.remove(daemon_script_path)
display_checkmark(f"\033[92mRemoved daemon script: {daemon_script_path}\033[0m")
else:
print(f"\033[91mWarning: Daemon script '{daemon_script_path}' not found.\033[0m")
except Exception as e:
print(f"\033[91mError removing daemon script: {e}\033[0m")
try:
subprocess.run(["systemctl", "daemon-reload"], check=True)
except subprocess.CalledProcessError:
print("\033[91mWarning: Failed to reload systemd daemon.\033[0m")
display_checkmark("\033[92mUninstall completed!\033[0m")
def status_proxy_forwarders():
os.system("clear")
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking TCP Forwarders Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
service_name = "proxyforwarder"
result = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if result.returncode == 0:
print(f"{service_name} is running.\n")
else:
print(f"{service_name} is not running.\n")
print("\n\033[93mRecent logs for ProxyForwarder:\033[0m\n", flush=True)
try:
subprocess.run(["journalctl", "-u", service_name, "--since", "1 hour ago", "--no-pager"], check=True)
except subprocess.CalledProcessError as e:
print(f"Error fetching logs: {e}")
print("\033[93m───────────────────────────────────────\033[0m")
def status_tinyvpn():
os.system("clear")
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking TinyVPN Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
service_name = "tinyvpn"
result = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if result.returncode == 0:
print(f"{service_name} is running.\n")
else:
print(f"{service_name} is not running.\n")
print("\n\033[93mRecent logs for TinyVPN:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", service_name, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def status_udp2raw_server():
os.system("clear")
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking UDP2RAW Server Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
try:
num_ports = int(input("\033[93mHow many \033[92mports do you have? \033[0m").strip())
except ValueError:
print("Invalid input. Please enter a valid number.")
return
for port_num in range(1, num_ports + 1):
service_name = f"udp2raw_{port_num}"
result = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if result.returncode == 0:
print(f"{service_name} is running.\n")
else:
print(f"{service_name} is not running.\n")
print(f"\n\033[93mRecent logs for {service_name}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", service_name, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def status_udp2raw_client():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking UDP2RAW client Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
service_name = "udp2raw"
result = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if result.returncode == 0:
print(f"{service_name} is running.\n")
else:
print(f"{service_name} is not running.\n")
print(f"\n\033[93mRecent logs for {service_name}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", service_name, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def status_speederv2_server():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking UDPSpeeder Server Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
try:
num_clients = int(input("\033[93mHow many \033[92mclients do you have? \033[0m").strip())
except ValueError:
print("Invalid input. Please enter a valid number.")
return
for client_num in range(1, num_clients + 1):
service_name = f"speederv2_{client_num}"
result = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if result.returncode == 0:
print(f"{service_name} is running.\n")
else:
print(f"{service_name} is not running.\n")
print(f"\n\033[93mRecent logs for {service_name}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", service_name, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def status_speederv2_client():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking UDPSpeeder Client Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
service_name = "speederv2"
result = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if result.returncode == 0:
print(f"{service_name} is running.\n")
else:
print(f"{service_name} is not running.\n")
print(f"\n\033[93mRecent logs for {service_name}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", service_name, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def status_udp2raw_speederv2_server():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking UDP2RAW + UDPSpeeder Server Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
try:
num_clients = int(input("\033[93mHow many \033[92mclients do you have?\033[0m ").strip())
except ValueError:
print("Invalid input. Please enter a valid number.")
return
for client_num in range(1, num_clients + 1):
udp2raw_service = f"udp2raw_{client_num}"
speederv2_service = f"speederv2_{client_num}"
udp2raw_status = subprocess.run(["systemctl", "is-active", udp2raw_service], capture_output=True, text=True)
print(f"{udp2raw_service} is {'running' if udp2raw_status.returncode == 0 else 'not running'}.\n")
print(f"\n\033[93mRecent logs for {udp2raw_service}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", udp2raw_service, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
speederv2_status = subprocess.run(["systemctl", "is-active", speederv2_service], capture_output=True, text=True)
print(f"{speederv2_service} is {'running' if speederv2_status.returncode == 0 else 'not running'}.\n")
print(f"\n\033[93mRecent logs for {speederv2_service}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", speederv2_service, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def status_udp2raw_speederv2_client():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking UDP2RAW + UDPSpeeder Client Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
udp2raw_service = "udp2raw"
udp2raw_status = subprocess.run(["systemctl", "is-active", udp2raw_service], capture_output=True, text=True)
print(f"{udp2raw_service} is {'running' if udp2raw_status.returncode == 0 else 'not running'}.\n")
print(f"\n\033[93mRecent logs for {udp2raw_service}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", udp2raw_service, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
speederv2_service = "speederv2"
speederv2_status = subprocess.run(["systemctl", "is-active", speederv2_service], capture_output=True, text=True)
print(f"{speederv2_service} is {'running' if speederv2_status.returncode == 0 else 'not running'}.\n")
print(f"\n\033[93mRecent logs for {speederv2_service}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", speederv2_service, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def show_status_menu():
os.system("clear")
print("\033[92m ^ ^\033[0m")
print("\033[92m(\033[91mO,O\033[92m)\033[0m")
print("\033[92m( ) \033[93mStatus \033[93mMenu\033[0m")
print(
'\033[92m "-"\033[93m═══════════════════════════════════════════════════\033[0m'
)
print("\033[93m╭───────────────────────────────────────╮\033[0m")
while True:
print("1. \033[93mTinyvpn\033[0m")
print("2. \033[96mUDPSpeeder\033[0m")
print("3. \033[92mUDP2RAW\033[0m")
print("4. \033[93mUDP2RAW + UDPSpeeder\033[0m")
print("5. \033[96mProxyforwarder\033[0m")
print("6. \033[92mTinymapper\033[0m")
print("0. \033[97mBack to main menu\033[0m")
print("\033[93m╰───────────────────────────────────────╯\033[0m")
choice = input("Choose an option (0-6): ").strip()
if choice == "1":
status_tinyvpn()
elif choice == "2":
status_speederv2()
elif choice == "3":
status_udp2raw()
elif choice == "4":
status_udp2raw_speederv2()
elif choice == "5":
status_proxy_forwarders()
elif choice == "6":
status_tinymapper()
elif choice == "0":
show_menu()
else:
print("Wrong option. choose a valid number (0-6).")
def status_tinymapper():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mChecking Tinymapper Status...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
try:
num_ports = int(input("\033[93mHow many \033[92mports do you have?\033[0m ").strip())
except ValueError:
print("Invalid input. Please enter a valid number.")
return
for i in range(1, num_ports + 1):
service_name = f"tinymapper_{i}"
result = subprocess.run(["systemctl", "is-active", service_name], capture_output=True, text=True)
if result.returncode == 0:
print(f"{service_name} is running.\n")
else:
print(f"{service_name} is not running.\n")
print(f"\n\033[93mRecent logs for {service_name}:\033[0m\n", flush=True)
subprocess.run(["journalctl", "-u", service_name, "--since", "1h ago", "--no-pager"])
print("\033[93m───────────────────────────────────────\033[0m")
def status_udp2raw_speederv2():
print("\033[93m──────────────────────────────\033[0m")
while True:
print("1)\033[93m Server\033[0m")
print("2)\033[92m Client\033[0m")
print("0) \033[94mback to status menu\033[0m")
print("\033[93m──────────────────────────────\033[0m")
choice = input("Choose an option (0-2): ").strip()
if choice == "1":
status_udp2raw_speederv2_server()
elif choice == "2":
status_udp2raw_speederv2_client()
elif choice == "0":
show_status_menu()
else:
print("Invalid option. Please choose a valid number from 0 to 2.")
def status_udp2raw():
print("\033[93m──────────────────────────────\033[0m")
while True:
print("1)\033[93m Server\033[0m")
print("2)\033[92m Client\033[0m")
print("0)\033[93m back to status menu\033[0m")
print("\033[93m──────────────────────────────\033[0m")
choice = input("Choose an option (0-2): ").strip()
if choice == "1":
status_udp2raw_server()
elif choice == "2":
status_udp2raw_client()
elif choice == "0":
show_status_menu()
else:
print("Invalid option. Please choose a valid number from 0 to 2.")
def status_speederv2():
print("\033[93m──────────────────────────────\033[0m")
while True:
print("1)\033[93m Server\033[0m")
print("2)\033[93m Client\033[0m")
print("0)\033[93m back to status menu\033[0m")
print("\033[93m──────────────────────────────\033[0m")
choice = input("Choose an option (0-2): ").strip()
if choice == "1":
status_speederv2_server()
elif choice == "2":
status_speederv2_client()
elif choice == "0":
show_status_menu()
else:
print("Invalid option. Please choose a valid number from 0 to 2.")
#custom daemon
def restart_tinyvpn_daemon():
print("\033[93m───────────────────────────────────────\033[0m")
print("\033[93mSetting up Custom Daemon for TinyVPN...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
enable_timer = input("\033[93mDo you want to \033[92menable \033[93mthe \033[96mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m").strip().lower()
if enable_timer not in ["yes", "y"]:
print("\033[91mReset timer not enabled. Exiting...\033[0m")
return
while True:
print("\033[93m╭───────────────────────────────────────╮\033[0m")
print("\n\033[93mSelect the time unit for restart interval:\033[0m")
print("1) \033[93mHours\033[0m")
print("2) \033[92mMinutes\033[0m")
print("\033[93m╰───────────────────────────────────────╯\033[0m")
time_unit_choice = input("\033[93mEnter your choice (1 or 2): \033[0m").strip()
if time_unit_choice == "1":
time_unit = "hours"
time_multiplier = 3600
break
elif time_unit_choice == "2":
time_unit = "minutes"
time_multiplier = 60
break
else:
print("\033[91mInvalid choice. select 1 for hours or 2 for minutes.\033[0m")
interval = input(f"\033[93mEnter the number of {time_unit} for restart interval: \033[0m").strip()
if not interval.isdigit() or int(interval) <= 0:
print("\033[91mPlease enter a valid number.\033[0m")
return
interval = int(interval)
total_seconds = interval * time_multiplier
bash_script = f"""
#!/bin/bash
while true; do
sleep {total_seconds} # Interval in seconds
systemctl restart tinyvpn
done
"""
bash_script_path = "/usr/local/bin/tinyvpn_daemon.sh"
with open(bash_script_path, "w") as f:
f.write(bash_script)
os.chmod(bash_script_path, 0o755)
service_file = f"""
[Unit]
Description=TinyVPN Custom Restart Daemon
After=network.target
[Service]
ExecStart={bash_script_path}
Restart=always
User=root
WorkingDirectory=/usr/local/bin
[Install]
WantedBy=multi-user.target
"""
service_file_path = "/etc/systemd/system/tinyvpn_daemon.service"
with open(service_file_path, "w") as f:
f.write(service_file)
subprocess.run(["systemctl", "daemon-reload"])
subprocess.run(["systemctl", "enable", "tinyvpn_daemon.service"])
subprocess.run(["systemctl", "start", "tinyvpn_daemon.service"])
display_checkmark(f"\033[92mTinyVPN restart daemon set up successfully.\033[0m")
def display_subnet_in_box(subnet):
box_width = len(subnet) + 15
print("\033[93m" + "─" * box_width + "\033[0m")
print("\033[93m│ \033[92mSubnet: \033[97m" + subnet + " \033[93m│\033[0m")
print("\033[93m" + "─" * box_width + "\033[0m")
def setup_tinyvpn_server():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mInstalling TinyVPN Server...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
binary_path = get_binary_path("tinyvpn")
if not binary_path or not os.path.exists(binary_path):
download_file("tinyvpn", binary_path)
make_executable(binary_path)
tinyvpnport = input("\033[93mEnter TinyVPN \033[92mport\033[93m:\033[0m ")
subnet = input("\033[93mEnter \033[92msubnet \033[97m(example, 10.22.22.1)\033[93m:\033[0m ")
tun_name = input("\033[93mEnter \033[92mTUN name \033[97m(example, azumi)\033[93m:\033[0m ")
display_subnet_in_box(subnet)
fec_enabled = input("\033[93mDo you want to \033[92menable FEC\033[93m? (\033[92myes\033[93m/\033[91mn\033[97m, default yes)\033[93m:\033[0m ").strip().lower() or "yes"
fec_option = "-f20:10" if fec_enabled in ["yes", "y"] else "--disable-fec"
mode = input("\033[93mEnter \033[92mmode \033[97m(0 or 1, default 1)\033[93m:\033[0m ").strip() or "1"
timeout = input("\033[93mEnter \033[92mtimeout \033[97m(8 or 1, default 1)\033[93m:\033[0m ").strip() or "1"
tun_mtu = input("\033[93mEnter \033[92mTUN MTU \033[97m(default 1250)\033[93m:\033[0m ") or "1250"
password = input("\033[93mEnter\033[92m password\033[93m:\033[0m ")
tinyvpn_command = f"./tinyvpn -s -l0.0.0.0:{tinyvpnport} {fec_option} -k \"{password}\" --sub-net {subnet} --tun {tun_name} --mode {mode} --timeout {timeout} --tun-mtu {tun_mtu}"
create_service("tinyvpn", tinyvpn_command)
setup_keepalive(subnet)
restart_tinyvpn_daemon()
def setup_udp2raw_server():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mInstalling UDP2RAW Server...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
binary_path = get_binary_path("udp2raw")
if not binary_path or not os.path.exists(binary_path):
download_file("udp2raw", binary_path)
make_executable(binary_path)
num_ports = int(input("\033[93mHow many \033[92mports\033[93m do you have?\033[0m "))
for port_num in range(1, num_ports + 1):
print("\033[93m───────────────────────────────────────\033[0m")
print(f"\033[93mConfiguring Port\033[96m {port_num}\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
tunnel_port = input("\033[93mEnter \033[92mtunnel port\033[93m:\033[0m ")
wireguard_port = input("\033[93mEnter \033[92mUDP port\033[93m:\033[0m ")
password = input("\033[93mEnter \033[92mpassword\033[93m:\033[0m ")
print("\033[93mRaw mode options:\033[97m (1)\033[96m UDP\033[97m (2)\033[92m ICMP \033[97m(3)\033[93m FakeTCP,\033[97m default is UDP\033[0m")
raw_mode = input().strip() or "1"
raw_mode = {"1": "udp", "2": "icmp", "3": "faketcp"}.get(raw_mode, "udp")
udp2raw_command = f"{binary_path} -s -l0.0.0.0:{tunnel_port} -r 127.0.0.1:{wireguard_port} -k \"{password}\" --raw-mode {raw_mode} -a"
service_name = f"udp2raw_{port_num}"
create_service(service_name, udp2raw_command)
restart_udp2raw_daemon_server()
def setup_tinyvpn_client():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mInstalling TinyVPN Client...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
binary_path = get_binary_path("tinyvpn")
if not binary_path or not os.path.exists(binary_path):
download_file("tinyvpn", binary_path)
make_executable(binary_path)
server_public_ip = input("\033[93mEnter the \033[92mserver's public IP address\033[93m:\033[0m ")
subnet = input("\033[93mEnter subnet \033[97m(default 10.22.22.2)\033[93m:\033[0m ") or "10.22.22.2"
fec_enabled = input("\033[93mDo you want to \033[92menable FEC\033[93m? \033[93m?(\033[92myes\033[93m/\033[91mn\033[97m default yes)\033[93m:\033[0m ").strip().lower() or "yes"
fec_option = "-f20:10" if fec_enabled in ["yes", "y"] else "--disable-fec"
tinyvpnport = input("\033[93mEnter \033[92mTinyVPN port\033[93m:\033[0m ")
tun_name = input("\033[93mEnter \033[92mTUN name\033[97m (example, azumi)\033[93m:\033[0m ")
mode = input("\033[93mEnter \033[92mmode \033[97m(0 or 1, default 1)\033[93m:\033[0m ").strip() or "1"
timeout = input("\033[93mEnter \033[92mtimeout \033[97m(8 or 1, default 1)\033[93m:\033[0m ").strip() or "1"
tun_mtu = input("\033[93mEnter \033[92mTUN MTU \033[97m(default 1250)\033[93m:\033[0m ") or "1250"
password = input("\033[93mEnter \033[92mpassword\033[93m:\033[0m ")
display_subnet_in_box(subnet)
tinyvpn_command = f"{binary_path} -c -r {server_public_ip}:{tinyvpnport} {fec_option} -k \"{password}\" --tun {tun_name} --sub-net {subnet} --keep-reconnect --mode {mode} --timeout {timeout} --tun-mtu {tun_mtu}"
create_service("tinyvpn", tinyvpn_command)
setup_keepalive(subnet)
restart_tinyvpn_daemon()
def stop_delete_keepalive():
keepalive_script_path = "/usr/local/bin/keepalive.sh"
keepalive_service_path = "/etc/systemd/system/keepalive.service"
subprocess.run(["sudo", "systemctl", "stop", "keepalive.service"], check=True)
subprocess.run(["sudo", "systemctl", "disable", "keepalive.service"], check=True)
if os.path.exists(keepalive_script_path):
os.remove(keepalive_script_path)
else:
print(f"\033[91mNo keepalive script found at {keepalive_script_path}...\033[0m")
if os.path.exists(keepalive_service_path):
print(f"\033[93mDeleting keepalive service file at {keepalive_service_path}...\033[0m")
os.remove(keepalive_service_path)
else:
print(f"\033[91mNo keepalive service file found at {keepalive_service_path}...\033[0m")
subprocess.run(["sudo", "systemctl", "daemon-reload"], check=True)
subprocess.run(["sudo", "systemctl", "reset-failed"], check=True)
display_checkmark("\033[92mKeepalive script deleted.\033[0m")
#subnet + keepalive
def getopposite_subnet(subnet, is_server=True):
parts = subnet.split(".")
if parts[-1] == "1":
opposite_ip = "2" if is_server else "1"
elif parts[-1] == "2":
opposite_ip = "1" if is_server else "2"
else:
raise ValueError("The subnet should end with either .1 or .2 for this setup.")
opposite_subnet = parts[:-1] + [opposite_ip]
return ".".join(opposite_subnet)
def keepalive_script(subnet, is_server=True):
opposite_subnet = getopposite_subnet(subnet, is_server)
script_content = f"""#!/bin/bash
while true; do
ping -c 2 {opposite_subnet} > /dev/null
sleep 10
done
"""
script_path = "/usr/local/bin/keepalive.sh"
with open(script_path, "w") as script_file:
script_file.write(script_content)
os.chmod(script_path, 0o755)
print(f"Keepalive script created at {script_path}")
def keepalive_service():
service_content = """
[Unit]
Description=Keep-Alive Service for TinyVPN
[Service]
ExecStart=/usr/local/bin/keepalive.sh
Restart=always
User=root
[Install]
WantedBy=multi-user.target
"""
service_path = "/etc/systemd/system/keepalive.service"
with open(service_path, "w") as service_file:
service_file.write(service_content)
subprocess.run(["systemctl", "daemon-reload"], check=True)
print(f"Keep-Alive service created at {service_path}")
subprocess.run(["systemctl", "enable", "keepalive.service"], check=True)
subprocess.run(["systemctl", "start", "keepalive.service"], check=True)
display_checkmark("Keep-Alive service is now running")
def setup_keepalive(subnet, is_server=True):
keepalive_script(subnet, is_server)
keepalive_service()
#custom daemon for udp2raw
def restart_udp2raw_daemon():
print("\033[93m───────────────────────────────────────\033[0m")
print("\033[93mSetting up Custom Daemon for udp2raw...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
enable_timer = input("\033[93mDo you want to \033[92menable \033[93mthe \033[96mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m").strip().lower()
if enable_timer not in ["yes", "y"]:
print("\033[91mReset timer not enabled. Exiting...\033[0m")
return
while True:
print("\033[93m╭───────────────────────────────────────╮\033[0m")
print("\n\033[93mSelect the time unit for restart interval:\033[0m")
print("1) \033[93mHours\033[0m")
print("2) \033[92mMinutes\033[0m")
print("\033[93m╰───────────────────────────────────────╯\033[0m")
time_unit_choice = input("\033[93mEnter your choice (1 or 2): \033[0m").strip()
if time_unit_choice == "1":
time_unit = "hours"
time_multiplier = 3600
break
elif time_unit_choice == "2":
time_unit = "minutes"
time_multiplier = 60
break
else:
print("\033[91mInvalid choice. select 1 for hours or 2 for minutes.\033[0m")
interval = input(f"\033[93mEnter the number of {time_unit} for restart interval: \033[0m").strip()
if not interval.isdigit() or int(interval) <= 0:
print("\033[91mPlease enter a valid number.\033[0m")
return
interval = int(interval)
total_seconds = interval * time_multiplier
bash_script = f"""
#!/bin/bash
while true; do
sleep {total_seconds}
systemctl restart udp2raw
done
"""
bash_script_path = "/usr/local/bin/udp2raw_daemon.sh"
with open(bash_script_path, "w") as f:
f.write(bash_script)
os.chmod(bash_script_path, 0o755)
service_file = f"""
[Unit]
Description=udp2raw Custom Restart Daemon
After=network.target
[Service]
ExecStart={bash_script_path}
Restart=always
User=root
WorkingDirectory=/usr/local/bin
[Install]
WantedBy=multi-user.target
"""
service_file_path = "/etc/systemd/system/udp2raw_daemon.service"
with open(service_file_path, "w") as f:
f.write(service_file)
subprocess.run(["systemctl", "daemon-reload"])
subprocess.run(["systemctl", "enable", "udp2raw_daemon.service"])
subprocess.run(["systemctl", "start", "udp2raw_daemon.service"])
display_checkmark(f"\033[92mTinyVPN restart daemon set up successfully.\033[0m")
def restart_udp2raw_daemon_server():
print("\033[93m───────────────────────────────────────\033[0m")
print("\033[93mSetting up Custom Daemon for udp2raw...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
enable_timer = input("\033[93mDo you want to \033[92menable \033[93mthe \033[96mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m").strip().lower()
if enable_timer not in ["yes", "y"]:
print("\033[91mReset timer not enabled. Exiting...\033[0m")
return
num_ports = int(input("\033[93mHow many \033[92mports\033[93m do you have? \033[0m").strip())
while True:
print("\033[93m╭───────────────────────────────────────╮\033[0m")
print("\n\033[93mSelect the time unit for restart interval:\033[0m")
print("1) \033[93mHours\033[0m")
print("2) \033[92mMinutes\033[0m")
print("\033[93m╰───────────────────────────────────────╯\033[0m")
time_unit_choice = input("\033[93mEnter your choice (1 or 2): \033[0m").strip()
if time_unit_choice == "1":
time_unit = "hours"
time_multiplier = 3600
break
elif time_unit_choice == "2":
time_unit = "minutes"
time_multiplier = 60
break
else:
print("\033[91mInvalid choice. Select 1 for hours or 2 for minutes.\033[0m")
interval = input(f"\033[93mEnter the number of {time_unit} for restart interval: \033[0m").strip()
if not interval.isdigit() or int(interval) <= 0:
print("\033[91mPlease enter a valid number.\033[0m")
return
interval = int(interval)
total_seconds = interval * time_multiplier
restart_commands = []
for port_num in range(1, num_ports + 1):
restart_commands.append(f"systemctl restart udp2raw_{port_num}")
bash_script = f"""
#!/bin/bash
while true; do
sleep {total_seconds}
{"; ".join(restart_commands)}
done
"""
bash_script_path = "/usr/local/bin/udp2raw_daemon.sh"
with open(bash_script_path, "w") as f:
f.write(bash_script)
os.chmod(bash_script_path, 0o755)
service_file = f"""
[Unit]
Description=udp2raw Custom Restart Daemon
After=network.target
[Service]
ExecStart={bash_script_path}
Restart=always
User=root
WorkingDirectory=/usr/local/bin
[Install]
WantedBy=multi-user.target
"""
service_file_path = "/etc/systemd/system/udp2raw_daemon.service"
with open(service_file_path, "w") as f:
f.write(service_file)
subprocess.run(["systemctl", "daemon-reload"])
subprocess.run(["systemctl", "enable", "udp2raw_daemon.service"])
subprocess.run(["systemctl", "start", "udp2raw_daemon.service"])
print("\033[92mUDP2RAW restart daemon set up successfully.\033[0m")
def setup_udp2raw_client():
print("\033[93m───────────────────────────────────────\033[0m")
display_notification("\033[93mInstalling UDP2RAW Client...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
binary_path = get_binary_path("udp2raw")
if not binary_path or not os.path.exists(binary_path):
download_file("udp2raw", binary_path)
make_executable(binary_path)
wireguard_ovpn_port = input("\033[93mEnter\033[92m UDP port\033[93m:\033[0m ")
tunnel_port = input("\033[93mEnter\033[92m tunnel port\033[93m:\033[0m ")
server_private_ip = input("\033[93mEnter the \033[96mserver's private IP address\033[93m:\033[0m ")
password = input("\033[93mEnter \033[92mpassword\033[93m:\033[0m ")
print("\033[93mRaw mode options:\033[97m (1)\033[96m UDP\033[97m (2)\033[92m ICMP \033[97m(3)\033[93m FakeTCP,\033[97m default is UDP\033[0m")
raw_mode = input().strip() or "1"
raw_mode = {"1": "udp", "2": "icmp", "3": "faketcp"}.get(raw_mode, "udp")
udp2raw_command = f"{binary_path} -c -l0.0.0.0:{wireguard_ovpn_port} -r {server_private_ip}:{tunnel_port} -k \"{password}\" --raw-mode {raw_mode} -a"
create_service("udp2raw", udp2raw_command)
restart_udp2raw_daemon()
#custom daemon for speederv
def restart_speederv_daemon_server():
print("\033[93m───────────────────────────────────────\033[0m")
print("\033[93mSetting up Custom Daemon for speederv2...\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
enable_timer = input("\033[93mDo you want to \033[92menable \033[93mthe \033[96mreset timer\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m").strip().lower()
if enable_timer not in ["yes", "y"]:
print("\033[91mReset timer not enabled. Exiting...\033[0m")
return
num_ports = int(input("\033[93mHow many \033[92mClients\033[93m do you have? \033[0m").strip())
while True:
print("\033[93m╭───────────────────────────────────────╮\033[0m")
print("\n\033[93mSelect the time unit for restart interval:\033[0m")
print("1) \033[93mHours\033[0m")
print("2) \033[92mMinutes\033[0m")
print("\033[93m╰───────────────────────────────────────╯\033[0m")
time_unit_choice = input("\033[93mEnter your choice (1 or 2): \033[0m").strip()
if time_unit_choice == "1":
time_unit = "hours"
time_multiplier = 3600