-
Notifications
You must be signed in to change notification settings - Fork 3
/
movistar.sh
executable file
·1097 lines (974 loc) · 25.3 KB
/
movistar.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
# Includes
. /etc/openwrt_release
. /lib/functions/uci-defaults.sh
# Config
version="r20"
debug="/tmp/movistar.log"
debug_persistent="/etc/movistar.log"
# Vars
switch_ifname_lan="eth0.1"
switch_ifname_iptv="eth0.2"
switch_ifname_voip="eth0.3"
switch_ifname_wan="eth0.6"
switch_wan_eth1=0
router=""
router_detected=0
switch_name="switch0"
switch_port_cpu=-1
switch_port_wan=-1
switch_port_lan=""
voip_enabled=0
iptv_enabled=0
lan_ipaddr="192.168.1.1"
lan_netmask="255.255.255.0"
lan_cidr=24
iptv_ipaddr=""
iptv_netmask=""
iptv_gateway=""
iptv_has_alias=0
tvlan_ipaddr=""
tvlan_netmask=""
tvlan_cidr=0
dhcptv_enabled=0
udpxy_config=0
udpxy_port=4022
udpxy_wan=0
# Common Functions
log() {
echo -e $@ >> $debug;
}
print() {
echo -e $@;
log $@;
}
error() {
echo -e "Error: $@" 1>&2;
log "Error: $@";
}
space() {
print "---"
}
ip_check() {
echo $1 | awk -F"\." ' $0 ~ /^([0-9]{1,3}\.){3}[0-9]{1,3}$/ && $1 <=255 && $2 <= 255 && $3 <= 255 && $4 <= 255 '
}
read_check_ip() {
local ip=""
local valid=""
# Get valid IP
while [ ${#valid} -eq 0 ]
do
read ip
valid=$(ip_check "$ip")
done
# Return IP
log $ip;
echo $ip
}
port_check() {
echo $1 | awk ' $0 ~ /^([0-9]{1,5})$/ && $1 >=1 && $1 <=65535 '
}
read_check_port() {
local port=""
local valid=""
# Get valid port
while [ ${#valid} -eq 0 ]
do
read port
valid=$(port_check "$port")
done
# Return port
log $port;
echo $port
}
read_check_yesno() {
local answer=""
local valid=0
# Get valid answer
while [ $valid -eq 0 ]
do
read answer
if [ ${#answer} -gt 0 ]; then
if [ $answer = "y" ] || [ $answer = "n" ]; then
valid=1
fi
fi
done
# Return answer
log $answer;
if [ $answer = "y" ]; then
echo 1
else
echo 0
fi
}
service_disable() {
# Check if service is installed
if [ -f /etc/init.d/$1 ]; then
/etc/init.d/$1 stop >> $debug 2>&1
/etc/init.d/$1 disable >> $debug 2>&1
print "$1 disabled"
fi
}
service_enable() {
# Check if service is installed
if [ -f /etc/init.d/$1 ]; then
/etc/init.d/$1 enable >> $debug 2>&1
/etc/init.d/$1 stop >> $debug 2>&1
/etc/init.d/$1 start >> $debug 2>&1
print "$1 enabled"
fi
}
netmask_cidr() {
nbits=0
IFS=.
for dec in $1 ; do
case $dec in
255) let nbits+=8;;
254) let nbits+=7;;
252) let nbits+=6;;
248) let nbits+=5;;
240) let nbits+=4;;
224) let nbits+=3;;
192) let nbits+=2;;
128) let nbits+=1;;
0);;
*) error "$dec is not recognised"; exit 1
esac
done
echo "$nbits"
}
# Funs
switch_detect() {
local switch_port_min=0
local switch_port_max=0
local switch_port_list=""
local switch_port_num=0
local switch_exists=0
# Check if switch exists
( (swconfig dev $switch_name help) >> $debug 2>&1 ) && switch_exists=1
if [ $switch_exists -eq 0 ]; then
error "switch couldn't be detected"
exit 1;
fi
# Detect special switch configurations
switch_list=$(swconfig list)
log $switch_list
case $switch_list in
*"ag71xx-mdio"* |\
*"rtl8366"*)
if [ -d "/sys/class/net/eth1" ]; then
switch_wan_eth1=1
fi
;;
esac
# Detect switch ports
switch_help=$(swconfig dev $switch_name help)
switch_port_cpu=$(echo $switch_help | sed "s/cpu @ /&\n/;s/.*\n//;s/), vlans/\n&/;s/\n.*//")
switch_port_num=$(echo $switch_help | sed "s/, ports: /&\n/;s/.*\n//;s/ (cpu @ /\n&/;s/\n.*//")
# Obtain port list
switch_port_max=$(($switch_port_num - 1))
for i in $(seq $switch_port_min 1 $switch_port_max)
do
if [ ${#switch_port_list} -eq 0 ]; then
switch_port_list="$i"
else
switch_port_list="$switch_port_list $i"
fi
done
# Print switch info
print "Switch Info"
print "\tSwitch Ports: $switch_port_num [$switch_port_list]"
print "\tSwitch CPU Port: $switch_port_cpu"
if [ $switch_wan_eth1 -eq 0 ]; then
print "\tSwitch WAN Port: Unknown"
else
print "\tSwitch WAN Interface: eth1"
fi
print "\tSwitch LAN Ports: Unknown"
space
# Ask for wan port number
if [ $switch_wan_eth1 -eq 1 ]; then
print "Your WAN interface has been detected as eth1."
print "Is this correct? (y/n)"
switch_wan_eth1=$(read_check_yesno)
if [ $switch_wan_eth1 -eq 1 ]; then
switch_ifname_iptv="eth1.2"
switch_ifname_voip="eth1.3"
switch_ifname_wan="eth1.6"
fi
fi
# Print wan port info
if [ $switch_wan_eth1 -eq 0 ]; then
print "Please specify WAN port number"
# Get valid wan port
local switch_port_wan_valid=0
while [ $switch_port_wan_valid -eq 0 ]
do
read switch_port_wan
# Check wan port
if [ $switch_port_wan -lt $switch_port_min ] || [ $switch_port_wan -gt $switch_port_max ]; then
error "Invalid WAN port: valid range [$switch_port_list]"
elif [ $switch_port_wan -eq $switch_port_cpu ]; then
error "Invalid WAN port: matches CPU port"
else
switch_port_wan_valid=1
fi
done
fi
log $switch_port_wan
# Obtain lan ports
for i in $(seq $switch_port_min 1 $switch_port_max)
do
if [ $i -eq $switch_port_cpu ] || [ $i -eq $switch_port_wan ]; then
continue
else
if [ ${#switch_port_lan} -eq 0 ]; then
switch_port_lan="$i"
else
switch_port_lan="$switch_port_lan $i"
fi
fi
done
space
# Print switch info
print "Switch Info"
print "\tSwitch Ports: $switch_port_num [$switch_port_list]"
print "\tSwitch CPU Port: $switch_port_cpu"
if [ $switch_wan_eth1 -eq 0 ]; then
print "\tSwitch WAN Port: $switch_port_wan"
else
print "\tSwitch WAN Interface: eth1"
fi
print "\tSwitch LAN Ports: $switch_port_lan"
}
router_detect() {
if [ -f "/tmp/sysinfo/board_name" ]; then
router=$(cat /tmp/sysinfo/board_name)
else
case $DISTRIB_TARGET in
"bcm53xx"*)
router=$(cat /proc/device-tree/compatible | tr '\0' '\t' | cut -f 1)
;;
"brcm63xx"*)
router=$(awk 'BEGIN{FS="[ \t:/]+"} /system type/ {print $4}' /proc/cpuinfo)
case $router in
"96369R-1231N")
router="wap-5813n"
;;
esac
;;
esac
fi
local router_name=""
case $router in
"archer-c5")
router_name="TP-Link Archer C5"
;;
"archer-c7")
router_name="TP-Link Archer C7"
;;
"armada-385-linksys-caiman")
router_name="Linksys WRT1200AC"
;;
"armada-385-linksys-cobra")
router_name="Linksys WRT1900AC v2"
;;
"armada-xp-linksys-mamba")
router_name="Linksys WRT1900AC"
;;
"asus,rt-ac87u")
router_name="ASUS RT-AC87U"
;;
"mynet-n750")
router_name="Western Digital My Net N750"
;;
"rb-951ui-2hnd")
router_name="Mikrotik RouterBoard RB951Ui-2HnD"
;;
"tl-wdr4300")
router_name="TP-Link WDR3500/3600/4300/4310"
;;
"tl-wdr4900-v2")
router_name="TP-Link WDR4900 v2"
;;
"tl-wr841n-v1")
router_name="TP-Link WR841ND"
;;
"tl-wr941nd")
router_name="TP-Link WR941ND"
;;
"tl-wr1043nd")
router_name="TP-Link WR1043ND"
;;
"tl-wr1043nd-v2")
router_name="TP-Link WR1043ND v2"
;;
"wap-5813n")
router_name="Comtrend WAP-5813n"
;;
"wrt160nl")
router_name="TP-Link WRT160NL"
;;
*)
print "Router not supported."
print "You need to set the switch config manually."
switch_detect
;;
esac
if [ ${#router_name} -gt 0 ]; then
router_detected=1
print "Router identified: $router_name ($router)"
fi
}
enabled_configs_print() {
# Print configuration mode
local configs_enabled="WAN"
if [ $voip_enabled -eq 1 ]; then
configs_enabled="$configs_enabled + VOIP"
fi
if [ $iptv_enabled -eq 1 ]; then
configs_enabled="$configs_enabled + IPTV"
fi
print $configs_enabled
}
lan_ask() {
# Ask for lan ip/netmask
print "Customize LAN Network? (def 192.168.1.1/24) (y/n)"
local lan_custom=$(read_check_yesno)
if [ $lan_custom -eq 1 ]; then
print "LAN IP Address (e.g 192.168.1.1)"
lan_ipaddr=$(read_check_ip)
print "LAN Netmask (e.g 255.255.255.0)"
lan_netmask=$(read_check_ip)
lan_cidr=$(netmask_cidr $lan_netmask)
fi
}
mode_ask() {
# Ask for VOIP
print "Enable VOIP? (y/n)"
voip_enabled=$(read_check_yesno)
# Ask for IPTV
print "Enable IPTV? (y/n)"
iptv_enabled=$(read_check_yesno)
# Print configs enabled
enabled_configs_print
space
# Ask for IPTV configuration
if [ $iptv_enabled -eq 1 ]; then
print "IPTV IP Address (e.g 172.26.0.2/10.128.0.2)"
# Get valid ip
local iptv_ipaddr_valid=0
while [ $iptv_ipaddr_valid -eq 0 ]
do
iptv_ipaddr=$(read_check_ip)
# Check ip
case $iptv_ipaddr in
"10."*)
iptv_ipaddr_valid=1
iptv_has_alias=0
;;
"172."*)
iptv_ipaddr_valid=1
iptv_has_alias=1
;;
*)
error "Unsupported IPTV IP address"
;;
esac
done
print "IPTV Netmask (e.g. 255.255.240.0/255.128.0.0)"
iptv_netmask=$(read_check_ip)
print "IPTV Gateway (e.g. 172.26.208.1/10.128.0.1)"
iptv_gateway=$(read_check_ip)
if [ $iptv_has_alias -eq 1 ]; then
print "TV-LAN Alias (e.g. 10.0.0.1)"
tvlan_ipaddr=$(read_check_ip)
print "TV-LAN Netmask (e.g. 255.255.255.248)"
tvlan_netmask=$(read_check_ip)
tvlan_cidr=$(netmask_cidr $tvlan_netmask)
else
local linux_version=$(uname -r)
if [ -f /lib/modules/${linux_version}/nf_nat_rtsp.ko ] && [ -f /lib/modules/${linux_version}/nf_conntrack_rtsp.ko ]; then
print "nf_conntrack_rtsp module detected"
else
print "Please install nf_conntrack_rtsp module IPTV decoders (VOD)"
fi
print "Enable DHCP for IPTV decoders? (y/n)"
dhcptv_enabled=$(read_check_yesno)
fi
if [ -f /etc/config/udpxy ]; then
print "Configure udpxy? (y/n)"
udpxy_config=$(read_check_yesno)
if [ $udpxy_config -eq 1 ]; then
print "Enter udpxy port (def $udpxy_port)"
udpxy_port=$(read_check_port)
print "Allow access to udpxy from WAN? (y/n)"
udpxy_wan=$(read_check_yesno)
fi
fi
fi
}
log_persistent() {
# Ask for Log persistance
print "Make log persistent? (y/n)"
log_persistent=$(read_check_yesno)
if [ $log_persistent -eq 1 ]; then
cp $debug $debug_persistent
print "Log copied from $debug to $debug_persistent"
fi
}
set_bird4() {
# General
cat << EOF > $1
log syslog all;
router id ${lan_ipaddr};
protocol kernel {
persist;
scan time 20;
import all;
export all;
}
protocol device {
scan time 10;
}
protocol static {
export none;
}
EOF
# VOIP RIPv2
if [ $voip_enabled -eq 1 ]; then
cat << EOF >> $1
filter voip_filter {
if net ~ 10.0.0.0/8 then accept;
else reject;
}
protocol rip voip {
import all;
export filter voip_filter;
interface "${switch_ifname_voip}";
}
EOF
fi
# IPTV RIPv2
if [ $iptv_enabled -eq 1 ]; then
cat << EOF >> $1
filter iptv_filter {
if net ~ 172.16.0.0/12 then accept;
else reject;
}
protocol rip iptv {
import all;
export filter iptv_filter;
interface "${switch_ifname_iptv}";
}
EOF
fi
}
mode_network_cfg() {
local ula_prefix="$(uci -q get network.globals.ula_prefix)"
# Erase network config
rm -f /etc/config/network >> $debug 2>&1
touch /etc/config/network >> $debug 2>&1
print "Network config erased"
# Loopback
ucidef_set_interface_loopback >> $debug 2>&1
# ULA
if [ -z $ula_prefix ] || [ "$ula_prefix" == "auto" ]; then
local r1=$(dd if=/dev/urandom bs=1 count=1 2> /dev/null | hexdump -e '1/1 "%02x"')
local r2=$(dd if=/dev/urandom bs=2 count=1 2> /dev/null | hexdump -e '2/1 "%02x"')
local r3=$(dd if=/dev/urandom bs=2 count=1 2> /dev/null | hexdump -e '2/1 "%02x"')
ula_prefix="fd${r1}:${r2}:${r3}::/48"
fi
uci set network.globals.ula_prefix="$ula_prefix" >> $debug 2>&1
# Switch config
local soft_vlans=0
local wan_mac=""
if [ $router_detected -eq 1 ]; then
case $router in
"armada-385-linksys-caiman" |\
"armada-385-linksys-cobra" |\
"armada-xp-linksys-mamba" |\
"wap-5813n")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 5t" >> $debug 2>&1
if [ $iptv_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "2" "4t 5t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "3" "4t 5t" >> $debug 2>&1
fi
ucidef_add_switch_vlan "switch0" "6" "4t 5t" >> $debug 2>&1
;;
"archer-c5" |\
"archer-c7" |\
"tl-wdr4900-v2")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "2 3 4 5 6t" >> $debug 2>&1
if [ $iptv_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "2" "1t 6t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "3" "1t 6t" >> $debug 2>&1
fi
ucidef_add_switch_vlan "switch0" "6" "1t 6t" >> $debug 2>&1
;;
"asus,rt-ac87u")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
switch_ifname_lan="eth1.1"
ucidef_add_switch_vlan "switch0" "1" "1 2 3 5 7t" >> $debug 2>&1
if [ $iptv_enabled -eq 1 ]; then
switch_ifname_iptv="eth1.2"
ucidef_add_switch_vlan "switch0" "2" "0t 7t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
switch_ifname_voip="eth1.3"
ucidef_add_switch_vlan "switch0" "3" "0t 7t" >> $debug 2>&1
fi
switch_ifname_wan="eth1.6"
ucidef_add_switch_vlan "switch0" "6" "0t 7t" >> $debug 2>&1
;;
"mynet-n750")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "0t 1 2 3 4" >> $debug 2>&1
if [ $iptv_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "2" "0t 5t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "3" "0t 5t" >> $debug 2>&1
fi
ucidef_add_switch_vlan "switch0" "6" "0t 5t" >> $debug 2>&1
wan_mac=$(mtd_get_mac_ascii devdata "wanmac")
;;
"rb-951ui-2hnd")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4" >> $debug 2>&1
switch_ifname_lan="eth1"
;;
"tl-wdr4300")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "0t 2 3 4 5" >> $debug 2>&1
if [ $iptv_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "2" "0t 1t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "3" "0t 1t" >> $debug 2>&1
fi
ucidef_add_switch_vlan "switch0" "6" "0t 1t" >> $debug 2>&1
;;
"tl-wr1043nd")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 5t" >> $debug 2>&1
if [ $iptv_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "2" "0t 5t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "3" "0t 5t" >> $debug 2>&1
fi
ucidef_add_switch_vlan "switch0" "6" "0t 5t" >> $debug 2>&1
;;
"tl-wr1043nd-v2")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "1 2 3 4 6t" >> $debug 2>&1
if [ $iptv_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "2" "5t 6t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "3" "5t 6t" >> $debug 2>&1
fi
ucidef_add_switch_vlan "switch0" "6" "5t 6t" >> $debug 2>&1
;;
"tl-wr841n-v1" |\
"tl-wr941nd")
switch_ifname_lan="lan1 lan2 lan3 lan4"
soft_vlans=1
;;
"wrt160nl")
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "0 1 2 3 4t" >> $debug 2>&1
switch_ifname_iptv="eth1.2"
switch_ifname_voip="eth1.3"
switch_ifname_wan="eth1.6"
;;
esac
else
ucidef_add_switch "switch0" "1" "1" >> $debug 2>&1
ucidef_add_switch_vlan "switch0" "1" "$switch_port_lan ${switch_port_cpu}t" >> $debug 2>&1
if [ $switch_wan_eth1 -eq 0 ]; then
if [ $iptv_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "2" "${switch_port_wan}t ${switch_port_cpu}t" >> $debug 2>&1
fi
if [ $voip_enabled -eq 1 ]; then
ucidef_add_switch_vlan "switch0" "3" "${switch_port_wan}t ${switch_port_cpu}t" >> $debug 2>&1
fi
ucidef_add_switch_vlan "switch0" "6" "${switch_port_wan}t ${switch_port_cpu}t" >> $debug 2>&1
fi
fi
# Software VLANs
if [ $soft_vlans -eq 1 ]; then
local switch_vconfig=""
local switch_ifconfig=""
if [ $iptv_enabled -eq 1 ]; then
switch_ifname_iptv="wan.2"
switch_vconfig="vconfig add wan 2\n"
switch_ifconfig="ifconfig wan.2 up\n"
fi
if [ $voip_enabled -eq 1 ]; then
switch_ifname_voip="wan.3"
switch_vconfig="${switch_vconfig}vconfig add wan 3\n"
switch_ifconfig="${switch_ifconfig}ifconfig wan.3 up\n"
fi
switch_ifname_wan="wan.6"
switch_vconfig="${switch_vconfig}vconfig add wan 6\n"
switch_ifconfig="${switch_ifconfig}ifconfig wan.6 up\n"
cat << EOF > /etc/rc.local
${switch_vconfig}
${switch_ifconfig}
exit 0
EOF
fi
# LAN
uci batch >> $debug 2>&1 << EOF
set network.lan="interface"
set network.lan.ifname="${switch_ifname_lan}"
set network.lan.type="bridge"
set network.lan.proto="static"
set network.lan.ip6assign="60"
EOF
if [ $iptv_enabled -eq 1 ]; then
uci set network.lan.igmp_snooping="1" >> $debug 2>&1
fi
if [ $iptv_enabled -eq 1 ] && [ $iptv_has_alias -eq 1 ]; then
uci batch >> $debug 2>&1 << EOF
add_list network.lan.ipaddr="${tvlan_ipaddr}/${tvlan_cidr}"
add_list network.lan.ipaddr="${lan_ipaddr}/${lan_cidr}"
EOF
else
uci batch >> $debug 2>&1 << EOF
set network.lan.ipaddr="${lan_ipaddr}"
set network.lan.netmask="${lan_netmask}"
EOF
fi
# IPTV
if [ $iptv_enabled -eq 1 ]; then
uci batch >> $debug 2>&1 << EOF
set network.iptv="interface"
set network.iptv.ifname="${switch_ifname_iptv}"
set network.iptv.proto="static"
set network.iptv.ipaddr="${iptv_ipaddr}"
set network.iptv.netmask="${iptv_netmask}"
set network.iptv.gateway="${iptv_gateway}"
set network.iptv.defaultroute="0"
set network.iptv.peerdns="0"
EOF
# IPTV route
uci batch >> $debug 2>&1 << EOF
add network route
set network.@route[-1].interface="iptv"
set network.@route[-1].target="172.16.0.0"
set network.@route[-1].netmask="255.240.0.0"
set network.@route[-1].gateway="${iptv_gateway}"
EOF
fi
# VOIP
if [ $voip_enabled -eq 1 ]; then
uci batch >> $debug 2>&1 << EOF
set network.voip="interface"
set network.voip.ifname="${switch_ifname_voip}"
set network.voip.proto="dhcp"
set network.voip.defaultroute="0"
set network.voip.peerdns="0"
EOF
fi
# WAN
uci batch >> $debug 2>&1 << EOF
set network.wan="interface"
set network.wan.ifname="${switch_ifname_wan}"
set network.wan.proto="pppoe"
set network.wan.username="adslppp@telefonicanetpa"
set network.wan.password="adslppp"
set network.wan.ipv6="1"
set network.wan.mtu="1492"
set network.wan6="interface"
set network.wan6.ifname="wan"
set network.wan6.proto="dhcpv6"
EOF
# WAN MAC address
if [ -n $wan_mac ]; then
ucidef_set_interface_macaddr "wan" "$wan_mac"
fi
# Load network config
print "Network config loaded"
# Save network config
uci commit network >> $debug 2>&1
print "Network config applied"
}
mode_firewall_cfg() {
# Firewall default config
local firewall_forwarding=0
while [ $firewall_forwarding -eq 0 ]
do
uci delete firewall.@forwarding[0] >> $debug 2>&1
firewall_forwarding=$?
done
local firewall_zone=0
while [ $firewall_zone -eq 0 ]
do
uci delete firewall.@zone[0] >> $debug 2>&1
firewall_zone=$?
done
# WAN Firewall
uci batch >> $debug 2>&1 << EOF
add firewall zone
set firewall.@zone[-1].name="lan"
set firewall.@zone[-1].input="ACCEPT"
set firewall.@zone[-1].output="ACCEPT"
set firewall.@zone[-1].forward="ACCEPT"
set firewall.@zone[-1].network="lan"
add firewall zone
set firewall.@zone[-1].name="wan"
set firewall.@zone[-1].input="REJECT"
set firewall.@zone[-1].output="ACCEPT"
set firewall.@zone[-1].forward="REJECT"
set firewall.@zone[-1].masq="1"
set firewall.@zone[-1].mtu_fix="1"
add_list firewall.@zone[-1].network="wan"
add_list firewall.@zone[-1].network="wan6"
add firewall forwarding
set firewall.@forwarding[-1].src="lan"
set firewall.@forwarding[-1].dest="wan"
EOF
# IPTV Firewall
if [ $iptv_enabled -eq 1 ]; then
uci batch >> $debug 2>&1 << EOF
add firewall zone
set firewall.@zone[-1].name="iptv"
set firewall.@zone[-1].input="ACCEPT"
set firewall.@zone[-1].output="ACCEPT"
set firewall.@zone[-1].forward="REJECT"
set firewall.@zone[-1].network="iptv"
set firewall.@zone[-1].mtu_fix="1"
EOF
if [ $iptv_has_alias -eq 0 ]; then
uci set firewall.@zone[-1].masq="1" >> $debug 2>&1
fi
uci batch >> $debug 2>&1 << EOF
add firewall forwarding
set firewall.@forwarding[-1].src="lan"
set firewall.@forwarding[-1].dest="iptv"
add firewall forwarding
set firewall.@forwarding[-1].src="iptv"
set firewall.@forwarding[-1].dest="lan"
EOF
fi
# VOIP Firewall
if [ $voip_enabled -eq 1 ]; then
uci batch >> $debug 2>&1 << EOF
add firewall zone
set firewall.@zone[-1].name="voip"
set firewall.@zone[-1].input="ACCEPT"
set firewall.@zone[-1].output="ACCEPT"
set firewall.@zone[-1].forward="REJECT"
set firewall.@zone[-1].network="voip"
set firewall.@zone[-1].masq="1"
set firewall.@zone[-1].mtu_fix="1"
add firewall forwarding
set firewall.@forwarding[-1].src="lan"
set firewall.@forwarding[-1].dest="voip"
EOF
fi
# udpxy acces from WAN
if [ $udpxy_wan -eq 1 ]; then
uci batch >> $debug 2>&1 << EOF
set firewall.udpxy=rule
set firewall.udpxy.target="ACCEPT"
set firewall.udpxy.src="wan"
set firewall.udpxy.proto="tcp udp"
set firewall.udpxy.dest_port="${udpxy_port}"
set firewall.udpxy.name="udpxy"
EOF
fi
# Save firewall config
uci commit firewall >> $debug 2>&1
cat /etc/config/firewall >> $debug 2>&1
print "Firewall config saved"
}
mode_misc_cfg() {
# bird4
if [ $voip_enabled -eq 1 ] || [ $iptv_enabled -eq 1 ]; then
# Set bird4 config
if [ -f /etc/bird4.conf ]; then
set_bird4 "/etc/bird4.conf"
fi
if [ -f /etc/bird.conf ]; then
set_bird4 "/etc/bird.conf"
fi
print "bird4 config applied"
# Enable bird4
service_enable "bird4"
else
# Disable bird4
service_disable "bird4"
fi
# Multicast
if [ $iptv_enabled -eq 1 ]; then
# Use mcproxy over igmpproxy
if [ -f /usr/sbin/mcproxy ]; then
# Set mcproxy config
if [ -f /etc/config/mcproxy ]; then
rm -f /etc/config/mcproxy
touch /etc/config/mcproxy
uci batch >> $debug 2>&1 << EOF
set mcproxy.mcproxy="mcproxy"
set mcproxy.mcproxy.respawn="1"
set mcproxy.mcproxy.protocol="IGMPv2"
set mcproxy.iptv="instance"
set mcproxy.iptv.name="iptv"
add_list mcproxy.iptv.upstream="${switch_ifname_iptv}"
add_list mcproxy.iptv.downstream="br-lan"
commit mcproxy
EOF
else
# Legacy mcproxy config
cat << EOF > /etc/mcproxy.conf
protocol IGMPv2;
pinstance iptv: "${switch_ifname_iptv}" ==> "br-lan";
EOF
fi
print "mcproxy config applied"
# Enable mcproxy
service_enable "mcproxy"
elif [ -f /etc/config/omcproxy ]; then
# Set omcproxy config
rm -f /etc/config/omcproxy
touch /etc/config/omcproxy
uci batch >> $debug 2>&1 << EOF
set omcproxy.iptv="proxy"
set omcproxy.iptv.scope="global"
set omcproxy.iptv.uplink="iptv"
add_list omcproxy.iptv.downlink="lan"
commit omcproxy
EOF
print "omcproxy config applied"
# Enable omcproxy
service_enable "omcproxy"
elif [ -f /etc/config/igmpproxy ]; then
# Set igmpproxy config
rm -f /etc/config/igmpproxy
touch /etc/config/igmpproxy
uci batch >> $debug 2>&1 << EOF
add igmpproxy igmpproxy
set igmpproxy.@igmpproxy[-1].quickleave="1"
add igmpproxy phyint
set igmpproxy.@phyint[-1].network="iptv"
set igmpproxy.@phyint[-1].direction="upstream"
add_list igmpproxy.@phyint[-1].altnet="172.16.0.0/12"
add_list igmpproxy.@phyint[-1].altnet="${lan_ipaddr}/${lan_cidr}"
add igmpproxy phyint
set igmpproxy.@phyint[-1].network="lan"
set igmpproxy.@phyint[-1].direction="downstream"
commit igmpproxy
EOF
print "igmpproxy config applied"
# Enable igmpproxy
service_enable "igmpproxy"
else
# mcproxy/omcproxy/igmpproxy not detected
error "No multicast proxy detected"
fi
else
# Disable mcproxy
service_disable "mcproxy"
# Disable igmpproxy
service_disable "igmpproxy"
fi
# DNS rebind protection
if [ $iptv_enabled -eq 1 ]; then
uci batch >> $debug 2>&1 << EOF
set dhcp.@dnsmasq[0].rebind_protection="0"
commit dhcp
EOF
print "DNS rebind protection disabled"
else
uci batch >> $debug 2>&1 << EOF
set dhcp.@dnsmasq[0].rebind_protection="1"
commit dhcp
EOF
print "DNS rebind protection enabled"
fi
# updxy