-
Notifications
You must be signed in to change notification settings - Fork 84
/
oep.py
6279 lines (5131 loc) · 264 KB
/
oep.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
import sys
import re
import os
import shutil
import time
import colorama
from colorama import Fore, Style
import subprocess
from time import sleep
import readline
import netifaces
import netifaces as ni
import io
import ipaddress
import threading
import itertools
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
def eoip_status():
os.system("clear")
print("\033[92m ^ ^\033[0m")
print("\033[92m(\033[91mO,O\033[92m)\033[0m")
print("\033[92m( ) \033[93mEoIP Status Menu\033[0m")
print('\033[92m "-"\033[93m══════════════════════════\033[0m')
print("\033[93m╭───────────────────────────────────────╮\033[0m")
print("\033[93mYou are viewing the status of your EoIP tunnels:\033[0m")
eoip_interfaces = {
"eoipkh1": "eoip kharej config 1",
"eoipkh2": "eoip kharej config 2",
"eoipkh3": "eoip kharej config 3",
"eoipkh4": "eoip kharej config 4",
"eoipkh5": "eoip kharej config 5",
"eoipir1": "eoip iran config 1",
"eoipir2": "eoip iran config 2",
"eoipir3": "eoip iran config 3",
"eoipir4": "eoip iran config 4",
"eoipir5": "eoip iran config 5",
}
active_int = []
for interface, label in eoip_interfaces.items():
status = interface_check(interface)
if status == "online":
active_int.append(interface)
if not active_int:
print(" No Interfaces available.")
else:
for interface in active_int:
if interface.startswith("eoipkh"):
index = interface[-1]
service_file = f"/etc/systemd/system/eoip_kharej_{index}.service"
additional_file = f"/etc/systemd/system/eoip_additional_kharej_{index}.service"
print(f" \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m {interface} ({eoip_interfaces[interface]})\033[0m")
print(" \033[93mTunnel Method: \033[97mEoIP\033[0m")
if os.path.exists(service_file):
remote_ip = remote_extraction(service_file)
if remote_ip:
print(f" \033[93mRemote IP: \033[97m{remote_ip}\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
elif os.path.exists(additional_file):
remote_ip = remote_extraction(additional_file)
if remote_ip:
print(f" \033[93mRemote IP (Additional): \033[97m{remote_ip}\033[0m")
elif interface.startswith("eoipir"):
index = interface[-1]
service_file = f"/etc/systemd/system/eoip_iran_{index}.service"
additional_file = f"/etc/systemd/system/additional_irancmd_{index}.service"
print(f" \033[93mStatus: \033[92mOnline\033[97m | \033[93mInterface name:\033[96m {interface} ({eoip_interfaces[interface]})\033[0m")
print(" \033[93mTunnel Method: \033[97mEoIP\033[0m")
if os.path.exists(service_file):
remote_ip = remote_extraction(service_file)
if remote_ip:
print(f" \033[93mRemote IP: \033[97m{remote_ip}\033[0m")
print("\033[93m───────────────────────────────────────\033[0m")
elif os.path.exists(additional_file):
remote_ip = remote_extraction(additional_file)
if remote_ip:
print(f" \033[93mRemote IP (Additional): \033[97m{remote_ip}\033[0m")
secret_key = ipsec_secret()
if secret_key != "Not found":
print(" \033[93mIPsec Secret Key:\033[96m", secret_key, "\033[0m")
print("0. \033[94mback to the previous menu\033[0m")
print("\033[93m╰───────────────────────────────────────╯\033[0m")
while True:
choice = input("\033[38;5;205mEnter your choice Please: \033[0m")
if choice == "0":
os.system("clear")
eoip_menu()
break
else:
print("Invalid choice.")
def interface_check(interface):
output = subprocess.run(
["ip", "a", "show", interface], capture_output=True, text=True
)
if output.returncode == 0:
if re.search(r"state (UP|UNKNOWN)", output.stdout):
return "online"
return "offline"
def remote_extraction(service_file):
try:
with open(service_file, "r") as file:
for line in file:
if "ExecStart" in line:
match = re.search(r"remote\s+((?:[0-9]{1,3}\.){3}[0-9]{1,3}|(?:[a-fA-F0-9:]+))", line)
if match:
return match.group(1)
except FileNotFoundError:
pass
return None
def ipsec_secret():
try:
with open("/etc/ipsec.secrets", "r") as file:
lines = file.readlines()
for line in lines:
if "PSK" in line:
secret_key = line.split('"')[1]
return secret_key.strip()
except FileNotFoundError:
pass
return "Not found"
def spinnerboy():
for c in itertools.cycle(['|', '/', '-', '\\']):
if stop_spinner:
break
sys.stdout.write(f'\r{c} Loading... ')
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\rDone! \n')
def runcommand(cmd, desc=""):
global stop_spinner
stop_spinner = False
spinner_thread = threading.Thread(target=spinnerboy)
spinner_thread.start()
try:
print(f"{desc}...")
process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
output = process.stdout.readline()
if process.poll() is not None and output == b"":
break
if output:
sys.stdout.write(output.decode())
sys.stdout.flush()
process.communicate()
if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, cmd)
except subprocess.CalledProcessError as e:
stop_spinner = True
spinner_thread.join()
print(f"\033[91merror: {desc}: {e}\033[0m")
raise e
stop_spinner = True
spinner_thread.join()
time.sleep(0.5)
def dependencies():
commands = [
("sudo apt install -y make", "Installing make"),
("sudo apt install -y git", "Installing git")
]
for cmd, desc in commands:
try:
runcommand(cmd, desc)
except subprocess.CalledProcessError:
return
def clone_eoip():
target_dir = "/usr/local/bin/eoip"
if not os.path.exists(target_dir):
os.makedirs(target_dir, exist_ok=True)
print(f"\033[93mCreated eoip\033[0m")
if os.path.exists(os.path.join(target_dir, ".git")):
print("\033[93meoip already exists.\033[0m")
else:
try:
runcommand(f"git clone https://github.com/miyugundam/eoip.git {target_dir}", "Cloning eoip repo")
except subprocess.CalledProcessError:
print("\033[91mclone failed..\033[0m")
return
try:
os.chdir(target_dir)
runcommand("make", "Building eoip")
runcommand("sudo make install", "Installing eoip")
os.chdir("..")
except subprocess.CalledProcessError:
print("\033[91mbuild was unsuccessful.\033[0m")
return
def create_serviceeoip(service_name, service_exec):
service_content = f"""[Unit]
Description={service_name}
After=network.target
[Service]
ExecStart=/usr/local/bin/eoip/{service_exec}
Restart=on-failure
[Install]
WantedBy=multi-user.target
"""
service_file_path = f"/etc/systemd/system/{service_name}.service"
with open(service_file_path, 'w') as service_file:
service_file.write(service_content)
subprocess.run(f"sudo systemctl daemon-reload", shell=True, check=True)
subprocess.run(f"sudo systemctl enable {service_name}.service", shell=True, check=True)
subprocess.run(f"sudo systemctl restart {service_name}.service", shell=True, check=True)
def create_serviceeoip_additional(service_name, service_exec):
service_content = f"""[Unit]
Description={service_name}
After=network.target
[Service]
ExecStart={service_exec}
Restart=on-failure
[Install]
WantedBy=multi-user.target
"""
service_file_path = f"/etc/systemd/system/{service_name}.service"
with open(service_file_path, 'w') as service_file:
service_file.write(service_content)
subprocess.run(f"sudo systemctl daemon-reload", shell=True, check=True)
subprocess.run(f"sudo systemctl enable {service_name}.service", shell=True, check=True)
subprocess.run(f"sudo systemctl restart {service_name}.service", shell=True, check=True)
def cmd(command):
subprocess.run(command, shell=True, check=True)
def animate(message):
for char in message:
print(char, end="", flush=True)
time.sleep(0.05)
print()
def anime():
animation = [
"[= ]",
"[== ]",
"[=== ]",
"[==== ]",
"[===== ]",
"[======]",
"[===== ]",
"[==== ]",
"[=== ]",
"[== ]",
"[= ]",
]
for i in range(20):
time.sleep(0.1)
sys.stdout.write(f"\r{animation[i % len(animation)]}")
sys.stdout.flush()
sys.stdout.write("\r")
sys.stdout.flush()
def hide(command):
process = subprocess.Popen(
command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.PIPE
)
while process.poll() is None:
anime()
_, stderr = process.communicate()
if process.returncode != 0:
print(f"\033[91merror: {stderr.decode()}\033[0m")
def service_exists(service_name):
result = subprocess.run(
["systemctl", "list-units", "--full", "--all", service_name],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
return service_name in result.stdout.decode()
def set_mtu(private_ip):
print("\033[93m────────────────────────────────────────\033[0m")
set_mtu = input(f"\033[93mDo you want to set the \033[92mMTU size\033[93m for \033[96m{private_ip}\033[93m? (\033[92myes\033[93m/\033[91mno\033[93m): \033[0m").lower()
if set_mtu in ["yes", "y"]:
mtu = input(f"\033[93mEnter the \033[92mMTU size\033[93m for \033[96m{private_ip}\033[93m: \033[0m")
return mtu
return None
def additional_commands(server_num, private_ip, dev, ipv4=True):
subnet = "24" if ipv4 else "64"
script_dir = "/usr/local/bin/cmd/"
script_path = f"{script_dir}eoip_additional_commands_{server_num}.sh"
os.makedirs(script_dir, exist_ok=True)
additional_commands_script = f"""#!/bin/bash
ip addr add {private_ip}/{subnet} dev {dev}
ip link set {dev} up
"""
with open(script_path, 'w') as script_file:
script_file.write(additional_commands_script)
os.chmod(script_path, 0o755)
return private_ip, subnet, script_path
def nextip(ip, ipv4=True):
ip_obj = ipaddress.ip_address(ip)
next_ip = ip_obj + 1
return str(next_ip)
def oppositeip(ip, ipv4=True):
try:
if ipv4:
octets = ip.split(".")
if octets[-1] == '1':
octets[-1] = '2'
elif octets[-1] == '2':
octets[-1] = '1'
return ".".join(octets)
else:
ip_obj = ipaddress.IPv6Address(ip)
if ip_obj.packed[-1] == 1:
return str(ip_obj + 1)
elif ip_obj.packed[-1] == 2:
return str(ip_obj - 1)
else:
raise ValueError(f"Unsupported IPv6 address: {ip}")
except ipaddress.AddressValueError:
raise ValueError(f"IP address format is weird: {ip}")
def config_client_eoip1(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipir1"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
def config_client_eoip2(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipir2"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
def config_client_eoip3(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipir3"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
def config_client_eoip4(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipir4"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
def config_client_eoip5(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipir5"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
#kharej eoip
def config_client_eoip_kh1(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipkh1"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
def config_client_eoip_kh2(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipkh2"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
def config_client_eoip_kh3(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")
animate("\033[93mInstalling IPSEC..\033[0m")
hide("sudo apt install strongswan -y")
animate("\033[92mIPSEC Installation is completed!\033[0m")
if service_exists("strongswan-starter.service"):
cmd("sudo systemctl disable strongswan-starter")
cmd("sudo systemctl stop strongswan-starter")
if service_exists("strongswan.service"):
cmd("sudo systemctl disable strongswan")
cmd("sudo systemctl stop strongswan")
cmd("sudo rm -f /etc/ipsec1.conf /etc/ipsec.secrets")
ipsec_conf = """config setup
charondebug=all
uniqueids=no
##azumiisinyourarea
"""
dev_name = f"eoipkh3"
private_ip, subnet, _ = additional_commands(1, private_ip, dev=dev_name, ipv4=ipv4)
opposite_ip = oppositeip(private_ip, ipv4=ipv4)
ipsec_conf += f"""conn eoip_{dev_name}
left=%defaultroute
leftsubnet={private_ip}/{subnet}
leftid={private_ip}
right={opposite_ip}
rightsubnet={opposite_ip}/{subnet}
ike=aes256gcm16-sha512-ecp384!
esp=aes256gcm16-sha512-ecp384!
keyexchange=ikev2
auto=start
authby=secret
keyingtries=%forever
dpdaction=restart
dpddelay=30s
dpdtimeout=120s
rekeymargin=3m
rekeyfuzz=100%
reauth=no
"""
with open("/etc/ipsec.secrets", "a") as f:
f.write(f'{opposite_ip} {private_ip} : PSK "{psk}"\n')
with open("/etc/ipsec1.conf", "w") as f:
f.write(ipsec_conf)
service_content = """[Unit]
Description=strongazumi IPsec IKEv1/IKEv2 daemon using ipsec.conf
After=network-online.target
[Service]
ExecStart=/usr/sbin/ipsec start --nofork --conf /etc/ipsec1.conf
ExecReload=/usr/sbin/ipsec reload
Restart=always
RestartSec=5
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
"""
with open("/etc/systemd/system/strong-azumi1.service", "w") as f:
f.write(service_content)
cmd("sudo systemctl daemon-reload")
cmd("sudo systemctl enable strong-azumi1")
cmd("sudo systemctl restart strong-azumi1")
def config_client_eoip_kh4(psk, private_ip, ipv4=True):
print("\033[93m─────────────────────────────────────────────────────────\033[0m")