forked from Xentrk/x3mRouting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x3mRouting_Menu.sh
1829 lines (1592 loc) · 69.7 KB
/
x3mRouting_Menu.sh
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
#!/bin/sh
####################################################################################################
# Script: x3mRouting_Menu.sh
# Author: Xentrk
# Last Updated Date: 22-May-2021
#
# Description:
# Install, Update or Remove the x3mRouting repository
#
# Acknowledgement:
# This project would never have been made possible if not for @Martineau on snbfourms.com
# providing his Selective Routing knowledge and expertise. I am extemely GRATEFUL!
#
# Code for update code functions inspired by https://github.com/Adamm00 - credit to @Adamm
# and https://github.com/jackyaz/spdMerlin - credit to Jack Yaz
####################################################################################################
# shellcheck disable=SC2028
# shellcheck disable=SC2010 # need to us ls with a grep
export PATH=/sbin:/bin:/usr/sbin:/usr/bin$PATH
VERSION="2.4.5"
GIT_REPO="x3mRouting"
BRANCH="master"
# Change branch to master after merge
GITHUB_DIR="https://raw.githubusercontent.com/Xentrk/$GIT_REPO/$BRANCH"
LOCAL_REPO=/jffs/scripts/x3mRouting
ADDONS=/jffs/addons/x3mRouting
NAT_START=/jffs/scripts/nat-start
FW_START=/jffs/scripts/firewall-start
# Uncomment the line below for debugging
#set -x
COLOR_RED='\033[0;31m'
COLOR_WHITE='\033[0m'
COLOR_GREEN='\e[0;32m'
Welcome_Message() {
clear
printf '\n_______________________________________________________________________\n'
printf '| |\n'
printf '| Welcome to the %bx3mRouting%b Installation Menu |\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '| Version %s by Xentrk |\n' "$VERSION"
printf '| ____ _ _ |\n'
printf '| |__ | | | | | |\n'
printf '| __ __ _| |_ _ _ | |_ ___ | | __ ____ ____ _ _ _ |\n'
printf '| \ \/ / |_ | %b %b \ __|/ _ \| |/ / / _// \| %b %b \ |\n' "\`" "\`" "\`" "\`"
printf '| / / __| | | | | |_ | __/| < ( (_ | [] || | | | |\n'
printf '| /_/\_\|___ |_|_|_|\___|\___||_|\_\[] \___\\\____/|_|_|_| |\n'
printf '|_____________________________________________________________________|\n'
printf '| |\n'
printf '| Requirements: jffs partition and USB drive with entware installed |\n'
printf '| |\n'
printf '| See the project repository at |\n'
printf '| %bhttps://github.com/Xentrk/x3mRouting%b |\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '| for helpful tips. |\n'
printf '|_____________________________________________________________________|\n\n'
Main_Menu
}
Main_Menu() {
while true; do
printf '%b[1]%b Install LAN Client Routing\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[2]%b Install OpenVPN Client GUI, OpenVPN Event & x3mRouting.sh Script\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[3]%b Install OpenVPN Event & x3mRouting.sh Script\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[4]%b Install x3mRouting Utility Scripts\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[5]%b Check for updates to existing x3mRouting installation\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[6]%b Remove x3mRouting Repository\n' "$COLOR_GREEN" "$COLOR_WHITE"
localmd5="$(md5sum "$ADDONS/x3mRouting_Menu.sh" | awk '{print $1}')"
remotemd5="$(curl -fsL --retry 3 "${GITHUB_DIR}/x3mRouting_Menu.sh" | md5sum | awk '{print $1}')"
[ "$localmd5" != "$remotemd5" ] && printf '%b[7]%b Update x3mRouting Menu\n' "$COLOR_GREEN" "$COLOR_WHITE"
# Look for presence of old files to determine if candidate for update
if [ -d "$LOCAL_REPO" ]; then
if [ "$(ls "$LOCAL_REPO" | grep -c "load_")" -ge 1 ] || [ "$(ls "$LOCAL_REPO" | grep -c "route_all_vpnserver.sh")" -ge 1 ] || [ "$(ls "$LOCAL_REPO" | grep -c "route_ipset_vpnserver.sh")" -ge 1 ] || [ "$(ls "/jffs/configs" | grep -c ".nvram")" -ge 1 ]; then
printf '%b[u]%b Update x3mRouting to Version 2.0.0\n' "$COLOR_RED" "$COLOR_WHITE"
fi
fi
# End Check for old files
printf '\n%b%s%b%s\n' "$COLOR_GREEN" "[n del]" "$COLOR_WHITE" " Uninstall Option Number"
printf '%b[e]%b Exit x3mMenu\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '\n%b%s%b%s' "$COLOR_GREEN" "Option " "$COLOR_WHITE" "==> "
read -r "MENU1"
case "$MENU1" in
1)
Check_Firmware_Version
mkdir -p "$LOCAL_REPO"
echo
Install_x3mRouting_LAN_Clients
Install_x3mRouting_OpenVPN_Event
printf '\n%s%b%s%b%s\n\n' "Creating " "$COLOR_GREEN" "$LOCAL_REPO//x3mRouting_client_rules" "$COLOR_WHITE" " file"
sh "$LOCAL_REPO/x3mRouting_client_config.sh"
Firewall_Start_Update
Install_Done "x3mRouting for LAN Clients"
return 1
;;
"1 force")
mkdir -p "$LOCAL_REPO"
echo
Install_x3mRouting_LAN_Clients
Install_x3mRouting_OpenVPN_Event
printf '\n%s%b%s%b%s\n\n' "Creating " "$COLOR_GREEN" "$LOCAL_REPO//x3mRouting_client_rules" "$COLOR_WHITE" " file"
sh "$LOCAL_REPO/x3mRouting_client_config.sh"
Firewall_Start_Update
Install_Done "x3mRouting for LAN Clients"
return 1
;;
"1 del")
Confirm_Removal_OPT1
return 1
;;
2)
Check_Firmware_Version
mkdir -p "$LOCAL_REPO"
printf '\n'
Install_x3mRouting_GUI
Install_x3mRouting_OpenVPN_Event
Install_x3mRouting_Shell_Scripts
Firewall_Start_Update
Install_Done "GUI, OpenVPN Event and Shell Scripts"
return 1
;;
"2 force")
mkdir -p "$LOCAL_REPO"
printf '\n'
Install_x3mRouting_GUI
Install_x3mRouting_OpenVPN_Event
Install_x3mRouting_Shell_Scripts
Firewall_Start_Update
Install_Done "GUI, OpenVPN Event and Shell Scripts"
return 1
;;
"2 del")
Confirm_Removal_OPT2
return 1
;;
3)
mkdir -p "$LOCAL_REPO"
Install_x3mRouting_OpenVPN_Event
Install_x3mRouting_Shell_Scripts
Install_Done "OpenVPN Event and Shell Scripts"
return 1
;;
"3 force")
mkdir -p "$LOCAL_REPO"
Install_x3mRouting_OpenVPN_Event
Install_x3mRouting_Shell_Scripts
Install_Done "OpenVPN Event and Shell Scripts"
return 1
;;
"3 del")
Confirm_Removal_OPT3
return 1
;;
4)
mkdir -p "$LOCAL_REPO"
for FILE in getdomainnames.sh autoscan.sh; do
Download_File "$LOCAL_REPO" "$FILE"
done
echo
printf '%s%b%s%b%s%b%s%b%s\n\n' "Installation of " "$COLOR_GREEN" "getdomainnames.sh" "$COLOR_WHITE" " and " "$COLOR_GREEN" "autoscan.sh" "$COLOR_WHITE" " completed"
Install_ASN_Lookup_Tool
echo "Press enter to continue"
read -r
Welcome_Message
;;
"4 del")
Confirm_Removal_OPT4
return 1
;;
5)
Confirm_Update
Welcome_Message
return 1
;;
6)
Validate_Removal
return 1
;;
7)
Update_Installer
return 1
;;
u)
Pre_Install_OpenVPN_Event_x3mRouting
Update_NewVersion
Migrate_Util_Files
Update_Repo_Files
Update_Addons_Files
Welcome_Message
return 1
;;
e)
Exit_Message
;;
o)
Install_x3mRouting_OpenVPN_Event
return 1
;;
*)
printf '\n%bInvalid Option%b %s%b Please enter a valid option\n\n' "$COLOR_RED" "$COLOR_GREEN" "$MENU1" "$COLOR_WHITE"
;;
esac
done
}
Install_Done() {
echo
printf '%s%b%s%b%s\n\n' "Installation of " "$COLOR_GREEN" "$1" "$COLOR_WHITE" " completed"
echo "Press enter to continue"
read -r
Welcome_Message
}
Install_ASN_Lookup_Tool() {
Chk_Entware 30
if [ "$READY" -eq 1 ]; then
echo "You must first install Entware before proceeding"
printf 'Exiting %s\n' "$(basename "$0")"
exit 1
fi
for ENTWARE_PACKAGE in bash bind-host mtr whois; do
echo "Checking if $ENTWARE_PACKAGE is installed..."
Chk_Entware $ENTWARE_PACKAGE 30
if [ "$READY" -eq 1 ]; then
echo "Unable to install entware package $ENTWARE_PACKAGE"
printf 'Exiting %s\n' "$(basename "$0")"
exit 1
fi
done
echo "Downloading ASN Lookup Utility..."
mkdir -p /jffs/addons/x3mRouting
[ -s /opt/bin/asn ] && rm /opt/bin/asn
/usr/sbin/curl -s --retry 3 https://raw.githubusercontent.com/Xentrk/asn/master/asn -o /jffs/addons/x3mRouting/asn
chmod 755 /jffs/addons/x3mRouting/asn && ln -s "/jffs/addons/x3mRouting/asn" "/opt/bin/asn"
printf '%s%b%s%b%s\n\n' "Installation of the " "$COLOR_GREEN" "ASN Lookup Tool" "$COLOR_WHITE" " completed"
}
Check_Firmware_Version() {
buildno=$(nvram get buildno | sed 's/\.//')
buildmajor=$(nvram get buildno | awk '{ string=substr($0, 1, 3); print string;}')
if [ "$buildmajor" -ge 386 ]; then
return
fi
if [ "$buildno" -lt 38419 ]; then
echo "Invalid firmware version detected - $(nvram get buildno). This option of x3mRouting requires version 384.19 and above."
echo "You can force update x3mRouting by typing the word 'force' below."
echo "You must perform a 384.19+ firwmare update immediately after updating x3mRouting."
printf '\n%s%b%s%b' "Press enter to continue or the word 'force' to override" "$COLOR_GREEN" " ==> " "$COLOR_WHITE"
while true; do
read -r "USER_OPT"
case "$USER_OPT" in
force)
return
;;
*)
Welcome_Message
;;
esac
done
fi
}
Download_OpenVPN_Screen() {
FILE="Advanced_OpenVPNClient_Content.asp"
buildno=$(nvram get buildno | sed 's/\.//')
buildmajor=$(nvram get buildno | awk '{ string=substr($0, 1, 3); print string;}')
if [ "$buildmajor" -ge 386 ]; then
Download_File "$ADDONS" "$FILE"
else
echo "Invalid firmware version detected - $(nvram get buildno). This version of the Advanced OpenVPN Client Content screen requires version 386.1 and above."
echo "Downloading 384.xx compatible version of $FILE"
STATUS="$(curl --retry 3 -sL -w '%{http_code}' "https://raw.githubusercontent.com/Xentrk/x3mRouting/x3mRouting-384.19/Advanced_OpenVPNClient_Content.asp" -o "$ADDONS/$FILE")"
if [ "$STATUS" -eq "200" ]; then
printf '\n%b%s%b downloaded successfully\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE"
else
printf '\n%b%s%b download failed with curl error %s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" "$STATUS"
exit 1
fi
fi
}
Remove_OPT1() {
# Remove LOCAL_REPO files
for FILE in x3mRouting_client_nvram.sh x3mRouting_client_config.sh x3mRouting_client_rules; do
[ -s "$LOCAL_REPO/$FILE" ] && rm -f "$LOCAL_REPO/$FILE" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$LOCAL_REPO/$FILE" "$COLOR_WHITE" " completed" || printf '\n%b%s%b%s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " not found."
done
# only remove files if GUI is not being used.
if [ ! -s "$ADDONS/Advanced_OpenVPNClient_Content.asp" ]; then
Remove_firewall_start_Entries
for FILE in x3mRouting_firewall_start.sh x3mvpnrouting.sh updown-dns.sh; do
if [ -s "$ADDONS/$FILE" ]; then
rm -f "$ADDONS/$FILE" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$ADDONS/$FILE" "$COLOR_WHITE" " completed" || printf '\n%b%s%b%s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " not found."
fi
done
fi
for VPN_ID in 1 2 3 4 5; do
if [ -s "$ADDONS/ovpnc${VPN_ID}.nvram" ] && [ -s "$ADDONS/client${VPN_ID}_dns.sh" ]; then
rm -rf "$ADDONS/ovpnc${VPN_ID}.nvram"
rm -rf "$ADDONS/client${VPN_ID}_dns.sh"
service restart_vpnclient"$VPN_ID" && echo "Retarting VPN Client $VPN_ID to remove x3mRouting LAN Client Routing and DNS Rules"
fi
# Removing nvram files that don't use Accept DNS Configuration = Exclusive
[ -s "$ADDONS/ovpnc${VPN_ID}.nvram" ] && rm -rf "$ADDONS/ovpnc${VPN_ID}.nvram" && service restart_vpnclient"$VPN_ID" && echo "Retarting VPN Client $VPN_ID to remove x3mRouting LAN Client Routing Rules"
# shouldn't have this condition, but ..
[ -s "$ADDONS/client${VPN_ID}_dns.sh" ] && rm -rf "$ADDONS/client${VPN_ID}_dns.sh" && service restart_vpnclient"$VPN_ID" && echo "Retarting VPN Client $VPN_ID to remove x3mRouting LAN Client DNS Rules"
# check up/down openvpn-event files for entries
UP_ENTRY="sh $ADDONS/updown-dns.sh $VPN_ID up"
DOWN_ENTRY="sh $ADDONS/updown-dns.sh $VPN_ID down"
VPNC_UP_FILE="$REPO_DIR/vpnclient${VPN_ID}-route-up"
VPNC_DOWN_FILE="$REPO_DIR/vpnclient${VPN_ID}-route-pre-down"
if [ -s "$VPNC_UP_FILE" ]; then
if [ "$(grep -c "$UP_ENTRY" "$VPNC_UP_FILE")" -eq 1 ]; then
sed -i "\\~$ADDONS/updown-dns.sh~d" "$VPNC_UP_FILE"
Check_For_Shebang "$VPNC_UP_FILE"
fi
fi
if [ -s "$VPNC_DOWN_FILE" ]; then
if [ "$(grep -c "$DOWN_ENTRY" "$VPNC_DOWN_FILE")" -eq 1 ]; then # only add if entry does not exist
sed -i "\\~$ADDONS/updown-dns.sh~d" "$VPNC_DOWN_FILE" # add 'ipset=' domains entry to dnsmasq.conf.add
Check_For_Shebang "$VPNC_DOWN_FILE"
fi
fi
done
printf "\nPress enter to continue"
read -r
Welcome_Message
}
Confirm_Removal_OPT1() {
while true; do
printf '\nAre you sure you want to uninstall LAN Client Routing files?\n\n'
printf '%b[1]%b --> Yes \n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[2]%b --> Cancel\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '\n%b[1-2]%b: ' "$COLOR_GREEN" "$COLOR_WHITE"
read -r "MENU_VALIDATE_REMOVAL"
case "$MENU_VALIDATE_REMOVAL" in
1)
Remove_OPT1
break
;;
2)
Welcome_Message
break
;;
*)
printf '%bInvalid Option%b %s%b Please enter a valid option\n' "$COLOR_RED" "$COLOR_GREEN" "$MENU_VALIDATE_REMOVAL" "$COLOR_WHITE"
;;
esac
done
}
Remove_OPT2() {
# Remove the jq package
Remove_jq_Package
# Remove entries from /jffs/scripts/init-start
Remove_init_start_Entries
# Remove entries from /jffs/scripts/nat-start
Remove_nat_start_Entries
# Only remove entries from /jffs/scripts/firewall-start if option 1 not installed
[ ! -s "$LOCAL_REPO/x3mRouting_client_config.sh" ] && Remove_firewall_start_Entries
Remove_Prerouting_Rules
Remove_Postrouting_Rules
# Remove vpnclientX-route-up files
for VPNID in 1 2 3 4 5; do
UP_FILE=/jffs/scripts/x3mRouting/vpnclient${VPNID}-route-up
[ -s "$UP_FILE" ] && rm -rf "$UP_FILE"
done
# Remove vpnclientX-route-pre-down files
for VPNID in 1 2 3 4 5; do
DOWN_FILE=/jffs/scripts/x3mRouting/vpnclient${VPNID}-route-pre-down
[ -s "$DOWN_FILE" ] && rm -rf "$DOWN_FILE"
done
# Remove x3mRouting.sh file
FILE=x3mRouting.sh
[ -s "$LOCAL_REPO/$FILE" ] && rm -f "$LOCAL_REPO/$FILE" && rm -rf "/opt/bin/x3mRouting" 2>/dev/null && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$LOCAL_REPO/$FILE" "$COLOR_WHITE" " completed"
# Remove mount_files_gui.sh file
[ -s "$ADDONS/mount_files_gui.sh" ] && rm -f "$ADDONS/mount_files_gui.sh" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$ADDONS/mount_files_gui.sh" "$COLOR_WHITE" " completed"
# Remove Advanced_OpenVPNClient_Content.asp file
[ -s "$ADDONS/Advanced_OpenVPNClient_Content.asp" ] && [ "$(df | grep -c "/www/Advanced_OpenVPNClient_Content.asp")" -eq 1 ] && umount /www/Advanced_OpenVPNClient_Content.asp && rm -f "$ADDONS/Advanced_OpenVPNClient_Content.asp" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$ADDONS/Advanced_OpenVPNClient_Content.asp" "$COLOR_WHITE" " completed"
# Only remove files if LAN Client Routing is not being used
if [ ! -s "$LOCAL_REPO/x3mRouting_client_nvram.sh" ] && [ ! -s "$LOCAL_REPO/x3mRouting_client_config.sh" ]; then
for FILE in x3mRouting_firewall_start.sh x3mvpnrouting.sh openvpn-event; do
if [ -s "$ADDONS/$FILE" ]; then
rm -f "$ADDONS/$FILE" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$ADDONS/$FILE" "$COLOR_WHITE" " completed"
fi
done
fi
printf "\nPress enter to continue"
read -r
Welcome_Message
}
Confirm_Removal_OPT2() {
while true; do
printf '\nAre you sure you want to uninstall Option 2 files?\n\n'
printf '%b[1]%b --> Yes \n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[2]%b --> Cancel\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '\n%b[1-2]%b: ' "$COLOR_GREEN" "$COLOR_WHITE"
read -r "MENU_VALIDATE_REMOVAL"
case "$MENU_VALIDATE_REMOVAL" in
1)
Remove_OPT2
break
;;
2)
Welcome_Message
break
;;
*)
printf '%bInvalid Option%b %s%b Please enter a valid option\n' "$COLOR_RED" "$COLOR_GREEN" "$MENU_VALIDATE_REMOVAL" "$COLOR_WHITE"
;;
esac
done
}
Remove_OPT3() {
echo "Starting removal of option 3 files and associated file entries..."
# Remove the jq package
Remove_jq_Package
# Remove entries from /jffs/scripts/init-start
Remove_init_start_Entries
# Remove entries from /jffs/scripts/nat-start
Remove_nat_start_Entries
Remove_Prerouting_Rules
Remove_Postrouting_Rules
# Remove vpnclientX-route-up files
for VPNID in 1 2 3 4 5; do
UP_FILE=/jffs/scripts/x3mRouting/vpnclient${VPNID}-route-up
[ -s "$UP_FILE" ] && rm -rf "$UP_FILE"
done
# Remove vpnclientX-route-pre-down files
for VPNID in 1 2 3 4 5; do
DOWN_FILE=/jffs/scripts/x3mRouting/vpnclient${VPNID}-route-pre-down
[ -s "$DOWN_FILE" ] && rm -rf "$DOWN_FILE"
done
# Remove x3mRouting.sh and openvpn-event files
for FILE in x3mRouting.sh openvpn-event; do
[ -s "$LOCAL_REPO/$FILE" ] && rm -f "$LOCAL_REPO/$FILE" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$LOCAL_REPO/$FILE" "$COLOR_WHITE" " completed"
[ "$FILE" = "x3mRouting.sh" ] && rm -rf "/opt/bin/x3mRouting" 2>/dev/null
done
printf "\nPress enter to continue"
read -r
Welcome_Message
}
Confirm_Removal_OPT3() {
while true; do
printf '\nAre you sure you want to uninstall Option 3 files?\n\n'
printf '%b[1]%b --> Yes \n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[2]%b --> Cancel\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '\n%b[1-2]%b: ' "$COLOR_GREEN" "$COLOR_WHITE"
read -r "MENU_VALIDATE_REMOVAL"
case "$MENU_VALIDATE_REMOVAL" in
1)
Remove_OPT3
break
;;
2)
Welcome_Message
break
;;
*)
printf '%bInvalid Option%b %s%b Please enter a valid option\n' "$COLOR_RED" "$COLOR_GREEN" "$MENU_VALIDATE_REMOVAL" "$COLOR_WHITE"
;;
esac
done
}
Remove_OPT4() {
for FILE in getdomainnames.sh autoscan.sh; do
[ -s "$LOCAL_REPO/$FILE" ] && rm -f "$LOCAL_REPO/$FILE" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$LOCAL_REPO/$FILE" "$COLOR_WHITE" " completed"
done
# ASN Lookup Utility
[ -s "$ADDONS/asn" ] && rm -f /opt/bin/asn && rm -f "$ADDONS/asn" && printf '\n%s%b%s%b%s\n' "Removal of " "$COLOR_GREEN" "$ADDONS/asn" "$COLOR_WHITE" " completed"
printf "\nPress enter to continue"
read -r
Welcome_Message
}
Confirm_Removal_OPT4() {
while true; do
printf '\n%s%b%s%b%s%b%s%b%s\n\n' "Are you sure you want to uninstall" "$COLOR_GREEN" " getdomainnames.sh" "$COLOR_WHITE" " and " "$COLOR_GREEN" "autoscan.sh" "$COLOR_WHITE" " files?"
printf '%b[1]%b --> Yes \n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[2]%b --> Cancel\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '\n%b[1-2]%b: ' "$COLOR_GREEN" "$COLOR_WHITE"
read -r "MENU_VALIDATE_REMOVAL"
case "$MENU_VALIDATE_REMOVAL" in
1)
Remove_OPT4
break
;;
2)
Welcome_Message
break
;;
*)
printf '%bInvalid Option%b %s%b Please enter a valid option\n' "$COLOR_RED" "$COLOR_GREEN" "$MENU_VALIDATE_REMOVAL" "$COLOR_WHITE"
;;
esac
done
}
Validate_Removal() {
while true; do
printf '\nAre you sure you want to uninstall the %bx3mRouting%b repository\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf 'and all changes made by the installer?\n\n'
printf '%b[1]%b --> Yes\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[2]%b --> Cancel\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '\n%b[1-2]%b: ' "$COLOR_GREEN" "$COLOR_WHITE"
read -r "MENU_VALIDATE_REMOVAL"
case "$MENU_VALIDATE_REMOVAL" in
1)
Remove_Existing_Installation
break
;;
2)
Welcome_Message
break
;;
*)
printf '%bInvalid Option%b %s%b Please enter a valid option\n' "$COLOR_RED" "$COLOR_GREEN" "$MENU_VALIDATE_REMOVAL" "$COLOR_WHITE"
;;
esac
done
}
Confirm_Update() {
while true; do
printf '\n\nThis option will check your current installation and update any files that have changed\n'
printf 'since you last installed the repository. Updating is highly recommended to get the most recent.\n'
printf 'files. Chosing this option will not update missing files. Select the install option from the\n'
printf 'menu to reinstall missing files\n\n'
printf 'Would you like to check and download any files that have been updated?\n\n'
printf '%b[1]%b --> Yes\n' "$COLOR_GREEN" "$COLOR_WHITE"
printf '%b[2]%b --> No\n' "$COLOR_GREEN" "$COLOR_WHITE"
echo
printf '[1-2]: '
read -r "CONFIRM_UPDATE_OPTION"
case "$CONFIRM_UPDATE_OPTION" in
1)
echo
# install x3mRouting_firewall_start.sh if option 1 or 2 installed.
if [ -s "$ADDONS/Advanced_OpenVPNClient_Content.asp" ] || [ -s "$REPO_DIR/x3mRouting_client_config.sh" ]; then
if [ ! -f "$ADDONS/x3mRouting_firewall_start.sh" ]; then
Download_File "$ADDONS" "x3mRouting_firewall_start.sh"
Firewall_Start_Update
fi
else # remove for opt 3 users if installed in earlier versions of 394.19 test branch
Remove_firewall_start_Entries
fi
Update_Repo_Files
Update_Addons_Files
break
;;
2)
Welcome_Message
break
;;
*)
echo "[*] $CONFIRM_UPDATE_OPTION Isn't An Option!"
;;
esac
done
}
Remove_Mounts () {
[ "$(df | grep -c "/www/Advanced_OpenVPNClient_Content.asp")" -eq 1 ] && umount /www/Advanced_OpenVPNClient_Content.asp
}
Migrate_Util_Files () {
for VPN_ID in 1 2 3 4 5; do
[ -s "/jffs/configs/ovpnc${VPN_ID}.nvram" ] && mv "/jffs/configs/ovpnc${VPN_ID}.nvram" "$ADDONS/ovpnc${VPN_ID}.nvram"
done
[ -s "/jffs/configs/x3mRouting_client_config" ] && mv "/jffs/configs/x3mRouting_client_config" "$ADDONS/x3mRouting_client_config"
for FILE in vpnrouting.sh Advanced_OpenVPNClient_Content.asp mount_files_lan.sh mount_files_gui.sh; do
if [ -s "$LOCAL_REPO/$FILE" ]; then
case "$FILE" in
vpnrouting.sh) [ "$(df | grep -c "/usr/sbin/vpnrouting.sh")" -eq 1 ] && umount /usr/sbin/vpnrouting.sh && rm "$LOCAL_REPO/$FILE" && Download_File "$ADDONS" x3mvpnrouting ;;
Advanced_OpenVPNClient_Content.asp) [ "$(df | grep -c "/www/Advanced_OpenVPNClient_Content.asp")" -eq 1 ] && umount /www/Advanced_OpenVPNClient_Content.asp && [ -s "$LOCAL_REPO/$FILE" ] && mv "$LOCAL_REPO/$FILE" "$ADDONS/$FILE" ;;
mount_files_gui.sh) [ -s "$LOCAL_REPO/$FILE" ] && mv "$LOCAL_REPO/$FILE" "$ADDONS/$FILE" && sed 's/scripts/addons/' "$ADDONS/$FILE" > "/tmp/$FILE" && mv "/tmp/$FILE" "$ADDONS/$FILE" && chmod 755 "$ADDONS/$FILE" ;;
mount_files_lan.sh) [ -s "$LOCAL_REPO/$FILE" ] && rm "$LOCAL_REPO/$FILE" ;;
esac
fi
done
if [ -s "/jffs/scripts/init-start" ]; then
FILE=mount_files_gui.sh
if grep -q "$LOCAL_REPO/$FILE" "/jffs/scripts/init-start"; then
OLD_ENTRY="$LOCAL_REPO/$FILE"
NEW_ENTRY="$ADDONS/$FILE"
sed -i "s|$OLD_ENTRY|$NEW_ENTRY|" "/jffs/scripts/init-start"
fi
fi
if [ -s "/jffs/scripts/init-start" ]; then
FILE=mount_files_lan.sh
if grep -q "$LOCAL_REPO/$FILE" "/jffs/scripts/init-start"; then
sed -i "\\~mount_files_lan~d" "/jffs/scripts/init-start"
Check_For_Shebang "/jffs/scripts/init-start"
fi
fi
# Remount Files
[ -s "$ADDONS/mount_files_gui.sh" ] && sh "$ADDONS/mount_files_gui.sh"
}
### Code for update code functions inspired by https://github.com/Adamm00 - credit to @Adamm
### and https://github.com/jackyaz/spdMerlin - credit to Jack Yaz
Update_Addons_Files() {
# updown-client.sh removal for 384.19 Beta 1+, install updown-dns.sh if LAN Client Routing option installed
if [ -s "$ADDONS/updown-client.sh" ]; then
[ "$(df | grep -c "/usr/sbin/updown-client.sh")" -eq 1 ] && umount /usr/sbin/updown-client.sh
rm -rf "$ADDONS/updown-client.sh"
if [ -s "$LOCAL_REPO/x3mRouting_client_nvram.sh" ] || [ -s "$LOCAL_REPO/x3mRouting_client_config.sh" ]; then
# only download if LAN Clients option installed
Download_File "$ADDONS" updown-dns.sh
fi
fi
# vpnrouting.sh removal for x3mRouting Version 2.3.0
if [ -s "$ADDONS/vpnrouting.sh" ]; then
[ "$(df | grep -c "/usr/sbin/vpnrouting.sh")" -eq 1 ] && umount /usr/sbin/vpnrouting.sh
rm -rf "$ADDONS/vpnrouting.sh"
Download_File "$ADDONS" x3mvpnrouting.sh
fi
[ -s "$ADDONS/mount_files_lan.sh" ] && rm "$ADDONS/mount_files_lan.sh"
# Need to check init-start
if [ -s "/jffs/scripts/init-start" ]; then # file exists
PARM="mount_files_lan.sh"
if grep -q "$PARM" "/jffs/scripts/init-start"; then # see if line exists
sed -i "\\~$PARM~d" "/jffs/scripts/init-start"
printf '%b%s%b%s%b%s%b\n' "$COLOR_GREEN" "$PARM" "$COLOR_WHITE" " entry removed from " "$COLOR_GREEN" "/jffs/scripts/init-start" "$COLOR_WHITE"
Check_For_Shebang /jffs/scripts/init-start
fi
fi
# Check if ASN Lookup Utility installed
FILE=asn
if [ -s "$ADDONS/$FILE" ]; then
localver=$(grep "VERSION=" "$ADDONS/$FILE" | grep -m1 -oE '[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
serverver=$(/usr/sbin/curl -fsL --retry 3 "https://raw.githubusercontent.com/Xentrk/asn/master/asn" | grep "VERSION=" | grep -m1 -oE '[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
if [ "$localver" != "$serverver" ]; then
printf 'New version of %b%s%b available - updating to %s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" "$serverver"
Install_ASN_Lookup_Tool
else
printf 'No new version of %b%s%b to update - latest is %s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" "$serverver"
fi
localmd5="$(md5sum "$ADDONS/$FILE" | awk '{print $1}')"
remotemd5="$(curl -fsL --retry 3 "https://raw.githubusercontent.com/Xentrk/asn/master/asn" | md5sum | awk '{print $1}')"
if [ "$localmd5" != "$remotemd5" ]; then
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " does not match - downloading"
Install_ASN_Lookup_Tool
else
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " matches GitHub repo file."
fi
fi
# may need to repair firewall_start
if [ -s "$ADDONS/x3mRouting_firewall_start.sh" ]; then
Firewall_Start_Update
fi
# Check if version update
for FILE in mount_files_gui.sh updown-dns.sh x3mvpnrouting.sh x3mRouting_firewall_start.sh; do
if [ -s "$ADDONS/$FILE" ]; then
localver=$(grep "VERSION=" "$ADDONS/$FILE" | grep -m1 -oE '[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
serverver=$(/usr/sbin/curl -fsL --retry 3 "$GITHUB_DIR/$FILE" | grep "VERSION=" | grep -m1 -oE '[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
if [ "$localver" != "$serverver" ]; then
printf 'New version of %b%s%b available - updating to %s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" "$serverver"
Download_File "$ADDONS" "$FILE"
else
printf 'No new version of %b%s%b to update - latest is %s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" "$serverver"
fi
fi
done
Remove_Mounts
# Check if md5sum difference
# Don't check for updates to Advanced_OpenVPNClient_Content.asp here as it requires checks for firmware version 386.1 and above
for FILE in mount_files_gui.sh updown-dns.sh x3mvpnrouting.sh x3mRouting_firewall_start.sh; do
if [ -s "$ADDONS/$FILE" ]; then
localmd5="$(md5sum "$ADDONS/$FILE" | awk '{print $1}')"
remotemd5="$(curl -fsL --retry 3 "$GITHUB_DIR/$FILE" | md5sum | awk '{print $1}')"
if [ "$localmd5" != "$remotemd5" ]; then
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " does not match - downloading"
Download_File "$ADDONS" "$FILE"
else
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " matches GitHub repo file."
fi
fi
done
# Check if md5sum difference for Advanced_OpenVPNClient_Content.asp
# Advanced_OpenVPNClient_Content.asp requires checks for firmware version 386.1 and above
FILE=Advanced_OpenVPNClient_Content.asp
if [ -s "$ADDONS/$FILE" ]; then
localmd5="$(md5sum "$ADDONS/$FILE" | awk '{print $1}')"
remotemd5="$(curl -fsL --retry 3 "$GITHUB_DIR/$FILE" | md5sum | awk '{print $1}')"
if [ "$localmd5" != "$remotemd5" ]; then
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " does not match - downloading"
Download_OpenVPN_Screen
else
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " matches GitHub repo file."
fi
fi
# check up/down openvpn-event files for entries updown-dns.sh entries and remove if exist
printf '\n%s\n' "Examining contents of VPN Client Up/Down files for deprecated 'updown-dns.sh' entries."
for VPN_ID in 1 2 3 4 5; do
VPNC_UP_FILE="$LOCAL_REPO/vpnclient${VPN_ID}-route-up"
VPNC_DOWN_FILE="$LOCAL_REPO/vpnclient${VPN_ID}-route-pre-down"
if [ -s "$VPNC_UP_FILE" ]; then
if grep -q "updown-dns.sh" "$VPNC_UP_FILE"; then
sed -i "\\~updown-dns.sh~d" "$VPNC_UP_FILE"
Check_For_Shebang "$VPNC_UP_FILE"
fi
fi
if [ -s "$VPNC_DOWN_FILE" ]; then
if grep -q "updown-dns.sh" "$VPNC_DOWN_FILE"; then # only add if entry does not exist
sed -i "\\~updown-dns.sh~d" "$VPNC_DOWN_FILE" # add 'ipset=' domains entry to dnsmasq.conf.add
Check_For_Shebang "$VPNC_DOWN_FILE"
fi
fi
done
# Remount GUI if exist
[ -s "$ADDONS/mount_files_gui.sh" ] && sh "$ADDONS/mount_files_gui.sh"
echo
echo "Update of x3mRouting completed"
echo
echo "Press enter to continue"
read -r
}
Update_Repo_Files() {
if [ -d "$LOCAL_REPO" ]; then
# OPT1 option now requires openvpn-event
if [ -s "$LOCAL_REPO/x3mRouting_client_nvram.sh" ] && [ ! -f "$LOCAL_REPO/openvpn-event" ]; then
Download_File "$LOCAL_REPO" openvpn-event
fi
for FILE in x3mRouting.sh x3mRouting_client_nvram.sh x3mRouting_client_config.sh openvpn-event getdomainnames.sh autoscan.sh; do
if [ -s "$LOCAL_REPO/$FILE" ]; then
localver=$(grep "VERSION=" "$LOCAL_REPO/$FILE" | grep -m1 -oE '[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
serverver=$(/usr/sbin/curl -fsL --retry 3 "$GITHUB_DIR/$FILE" | grep "VERSION=" | grep -m1 -oE '[0-9]{1,2}([.][0-9]{1,2})([.][0-9]{1,2})')
if [ "$localver" != "$serverver" ]; then
printf 'New version of %b%s%b available - updating to %s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" "$serverver"
Download_File "$LOCAL_REPO" "$FILE"
else
printf 'No new version of %b%s%b to update - latest is %s\n' "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" "$serverver"
fi
localmd5="$(md5sum "$LOCAL_REPO/$FILE" | awk '{print $1}')"
remotemd5="$(curl -fsL --retry 3 "$GITHUB_DIR/$FILE" | md5sum | awk '{print $1}')"
if [ "$localmd5" != "$remotemd5" ]; then
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " does not match - downloading"
Download_File "$LOCAL_REPO" "$FILE"
else
printf '%s%b%s%b%s\n' "MD5 hash of " "$COLOR_GREEN" "$FILE" "$COLOR_WHITE" " matches GitHub repo file."
fi
fi
done
else
printf '\n%s%b%s%b%s\n' "Project Repository directory " "$COLOR_GREEN" "$DIR" "$COLOR_WHITE" " not found"
echo "Select one of the the install options from the main menu to install the respository"
echo
echo "Press enter to continue"
read -r
return
fi
# Update /jffs/scripts/openvpn-event to updated version 2.4.5 x3mRouting script entry
[ -s /jffs/scripts/openvpn-event ] && Update_jffs_Scripts_Openvpn_Event
}
Pre_Install_OpenVPN_Event_x3mRouting () {
# checking for existance of any "load" scripts. Their presence indicates x3mRouting.sh & openvpn need to be first installed
# before removing the "load" scripts
if [ "$(ls "$LOCAL_REPO" | grep -c "load_")" -ge "1" ]; then
Download_File "$LOCAL_REPO" "x3mRouting.sh" && rm -rf "/opt/bin/x3mRouting" 2>/dev/null && ln -s "$LOCAL_REPO/x3mRouting.sh" "/opt/bin/x3mRouting"
Download_File "$LOCAL_REPO" "openvpn-event"
fi
}
Update_NewVersion() {
# This script will clean-up old files and create a conversion file
CONV_FILE=/jffs/scripts/x3mRouting/x3mRouting_Conversion.sh
# START: Functions
Conversion_Msg() {
{
echo "# Source File====> $FILE"
echo "# Original Entry=> $LINE"
echo "$LINE4"
echo
} >> "$CONV_FILE"
}
Warning_Msg() {
{
echo "# If the source VPN Client you want to bypass is '1', then no changes are required."
echo "# Otherwise, edit the '1' to be a valid VPN Client number '1-5'"
}>> "$CONV_FILE"
}
Process_File() {
FILE=$1
if [ "$(grep -c "load_" "$FILE")" -gt 0 ]; then
grep "load_" "$FILE" | while read -r LINE; do
# Skip comment lines
LINETYPE=$(echo "$LINE" | awk '{ string=substr($0, 1, 1); print string;}')
if [ "$LINETYPE" = "#" ]; then
continue
fi
# AMAZON
if [ "$(echo "$LINE" | grep -c load_AMAZON_ipset_iface.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_AMAZON_ipset_iface.sh/x3mRouting.sh/' | sed 's/ 1/ ALL 1/' | sed 's/ 2/ ALL 2/' | sed 's/ 3/ ALL 3/' | sed 's/ 4/ ALL 4/'| sed 's/ 5/ ALL 5/' | sed 's/ 0/ 1 0/')
AWS_REGION=$(echo "$LINE2" | awk '{ print substr( $0, length($0) - 1, length($0) ) }')
[ "$AWS_REGION" = "AL" ] && AWS_REGION=GLOBAL
LINE3=$(echo "$LINE2" | awk '{print $1, $2, $3, $4, $5}')
LINE4="$LINE3 aws_region=$AWS_REGION"
if [ "$(echo "$LINE4" | grep -c "1 0")" -ge 1 ]; then
Warning_Msg
fi
Conversion_Msg
continue
fi
if [ "$(echo "$LINE" | grep -c load_AMAZON_ipset.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_AMAZON_ipset.sh/x3mRouting.sh/')
IPSET=$(echo "$LINE2" | awk '{print $3}' )
AWS_REGION=$(echo "$LINE2" | awk '{ print substr( $0, length($0) - 1, length($0) ) }')
LINE3=$(echo "$LINE2" | awk '{print $1, $2}')
LINE4="$LINE3 ipset_name=$IPSET aws_region=$AWS_REGION"
Conversion_Msg
continue
fi
# ASN
if [ "$(echo "$LINE" | grep -c load_ASN_ipset_iface.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_ASN_ipset_iface.sh/x3mRouting.sh/' | sed 's/ 1/ ALL 1/' | sed 's/ 2/ ALL 2/' | sed 's/ 3/ ALL 3/' | sed 's/ 4/ ALL 4/'| sed 's/ 5/ ALL 5/' | sed 's/ 0/ 1 0/')
ASNUM=$(echo "$LINE2" | sed -ne 's/^.*AS//p')
ASN="AS${ASNUM}"
LINE3=$(echo "$LINE2" | awk '{print $1, $2, $3, $4, $5}')
LINE4="$LINE3 asnum=$ASN"
if [ "$(echo "$LINE4" | grep -c "1 0")" -ge 1 ]; then
Warning_Msg
fi
Conversion_Msg
continue
fi
if [ "$(echo "$LINE" | grep -c load_ASN_ipset.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_ASN_ipset.sh/x3mRouting.sh/')
IPSET=$(echo "$LINE2" | awk '{print $3}')
ASNUM=$(echo "$LINE2" | sed -ne 's/^.*AS//p')
ASN="AS${ASNUM}"
LINE3=$(echo "$LINE2" | awk '{print $1, $2}')
LINE4="$LINE3 ipset_name=$IPSET asnum=$ASN"
Conversion_Msg
continue
fi
# DNSMASQ
if [ "$(echo "$LINE" | grep -c load_DNSMASQ_ipset_iface.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_DNSMASQ_ipset_iface.sh/x3mRouting.sh/' | sed 's/ 1/ ALL 1/' | sed 's/ 2/ ALL 2/' | sed 's/ 3/ ALL 3/' | sed 's/ 4/ ALL 4/'| sed 's/ 5/ ALL 5/' | sed 's/ 0/ 1 0/')
IPSET=$(echo "$LINE2" | awk '{print $5}' )
DNSMASQ=$(echo "$LINE2" | awk '{print $6}' )
LINE3=$(echo "$LINE2" | awk '{print $1, $2, $3, $4, $5}')
LINE4="$LINE3 dnsmasq=$DNSMASQ"
if [ "$(echo "$LINE4" | grep -c "1 0")" -ge 1 ]; then
Warning_Msg
fi
Conversion_Msg
continue
fi
if [ "$(echo "$LINE" | grep -c load_DNSMASQ_ipset.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_DNSMASQ_ipset.sh/x3mRouting.sh/')
IPSET=$(echo "$LINE2" | awk '{print $3}' )
DNSMASQ=$(echo "$LINE2" | awk '{print $4}' )
LINE3=$(echo "$LINE2" | awk '{print $1, $2}')
LINE4="$LINE3 ipset_name=$IPSET dnsmasq=$DNSMASQ"
Conversion_Msg
continue
fi
# MANUAL
if [ "$(echo "$LINE" | grep -c load_MANUAL_ipset_iface.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_MANUAL_ipset_iface.sh/x3mRouting.sh/' | sed 's/ 1/ ALL 1/' | sed 's/ 2/ ALL 2/' | sed 's/ 3/ ALL 3/' | sed 's/ 4/ ALL 4/'| sed 's/ 5/ ALL 5/' | sed 's/ 0/ 1 0/')
LINE3=$(echo "$LINE2" | awk '{print $1, $2, $3, $4, $5}')
LINE4="$LINE3"
if [ "$(echo "$LINE4" | grep -c "1 0")" -ge 1 ]; then
Warning_Msg
fi
Conversion_Msg
continue
fi
if [ "$(echo "$LINE" | grep -c load_MANUAL_ipset.sh)" -ge 1 ]; then
LINE2=$(echo "$LINE" | sed 's/load_MANUAL_ipset.sh/x3mRouting.sh/')
IPSET=$(echo "$LINE2" | awk '{print $3}')
LINE3=$(echo "$LINE2" | awk '{print $1, $2}')
LINE4="$LINE3 ipset_name=$IPSET"
Conversion_Msg
continue
fi
done
fi
}
Check_For_Shebang() {
CLIENTX_FILE=$1
SHEBANG_COUNT=0
EMPTY_LINE_COUNT=0
NOT_EMPTY_LINE_COUNT=0
COMMENT_LINE_COUNT=0
if [ -f "$CLIENTX_FILE" ]; then # file exists
while read -r LINE || [ -n "$LINE" ]; do
if [ "$LINE" = "#!/bin/sh" ]; then
SHEBANG_COUNT=$((SHEBANG_COUNT + 1))
continue
fi
linetype=$(echo "$LINE" | awk '{ string=substr($0, 1, 1); print string; }')
if [ "$linetype" = "#" ]; then
COMMENT_LINE_COUNT=$((COMMENT_LINE_COUNT + 1))
continue
fi
if [ -z "$LINE" ]; then
EMPTY_LINE_COUNT=$((EMPTY_LINE_COUNT + 1))
continue
fi