forked from testiknn/opt-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mtd_storage.sh
2498 lines (2217 loc) · 83 KB
/
mtd_storage.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
Builds="/etc/storage/Builds-2018-10-28"
result=0
mtd_part_name="Storage"
mtd_part_dev="/dev/mtdblock5"
mtd_part_size=200000
dir_storage="/etc/storage"
slk="/tmp/.storage_locked"
tmp="/tmp/storage.tar"
tbz="${tmp}.bz2"
hsh="/tmp/hashes/storage_md5"
config_qos="/etc/storage/qos.conf"
config_tinyproxy="/etc/storage/tinyproxy_script.sh"
config_mproxy="/etc/storage/mproxy_script.sh"
script0_script="/etc/storage/script0_script.sh"
script_script="/etc/storage/script_script.sh"
script1_script="/etc/storage/script1_script.sh"
script2_script="/etc/storage/script2_script.sh"
script3_script="/etc/storage/script3_script.sh"
adbyby_rules_script="/etc/storage/adbyby_rules_script.sh"
adm_rules_script="/etc/storage/adm_rules_script.sh"
koolproxy_rules_script="/etc/storage/koolproxy_rules_script.sh"
koolproxy_rules_list="/etc/storage/koolproxy_rules_list.sh"
shadowsocks_config_script="/etc/storage/shadowsocks_config_script.sh"
shadowsocks_ss_spec_lan="/etc/storage/shadowsocks_ss_spec_lan.sh"
shadowsocks_ss_spec_wan="/etc/storage/shadowsocks_ss_spec_wan.sh"
ad_config_script="/etc/storage/ad_config_script.sh"
FastDick_script="/etc/storage/FastDick_script.sh"
crontabs_script="/etc/storage/crontabs_script.sh"
jbls_script="/etc/storage/jbls_script.sh"
vlmcsdini_script="/etc/storage/vlmcsdini_script.sh"
DNSPOD_script="/etc/storage/DNSPOD_script.sh"
cloudxns_script="/etc/storage/cloudxns_script.sh"
aliddns_script="/etc/storage/aliddns_script.sh"
ddns_script="/etc/storage/ddns_script.sh"
ngrok_script="/etc/storage/ngrok_script.sh"
frp_script="/etc/storage/frp_script.sh"
kcptun_script="/etc/storage/kcptun_script.sh"
serverchan_script="/etc/storage/serverchan_script.sh"
SSRconfig_script="/etc/storage/SSRconfig_script.sh"
ap_script="/etc/storage/ap_script.sh"
script_start="$dir_storage/start_script.sh"
script_started="$dir_storage/started_script.sh"
script_shutd="$dir_storage/shutdown_script.sh"
script_postf="$dir_storage/post_iptables_script.sh"
script_postw="$dir_storage/post_wan_script.sh"
script_inets="$dir_storage/inet_state_script.sh"
script_vpnsc="$dir_storage/vpns_client_script.sh"
script_vpncs="$dir_storage/vpnc_server_script.sh"
script_ezbtn="$dir_storage/ez_buttons_script.sh"
func_get_mtd()
{
local mtd_part mtd_char mtd_idx mtd_hex
mtd_part=`cat /proc/mtd | grep \"$mtd_part_name\"`
mtd_char=`echo $mtd_part | cut -d':' -f1`
mtd_hex=`echo $mtd_part | cut -d' ' -f2`
mtd_idx=`echo $mtd_char | cut -c4-5`
if [ -n "$mtd_idx" ] && [ $mtd_idx -ge 4 ] ; then
mtd_part_dev="/dev/mtdblock${mtd_idx}"
mtd_part_size=`echo $((0x$mtd_hex))`
else
logger -t "Storage" "Cannot find MTD partition: $mtd_part_name"
exit 1
fi
}
func_mdir()
{
[ ! -d "$dir_storage" ] && mkdir -p -m 755 $dir_storage
}
func_stop_apps()
{
killall -q rstats
[ $? -eq 0 ] && sleep 1
}
func_start_apps()
{
/sbin/rstats
}
func_load()
{
local fsz
bzcat $mtd_part_dev > $tmp 2>/dev/null
fsz=`stat -c %s $tmp 2>/dev/null`
if [ -n "$fsz" ] && [ $fsz -gt 0 ] ; then
md5sum $tmp > $hsh
tar xf $tmp -C $dir_storage 2>/dev/null
else
result=1
rm -f $hsh
logger -t "Storage load" "Invalid storage data in MTD partition: $mtd_part_dev"
fi
rm -f $tmp
rm -f $slk
}
func_tarb()
{
rm -f $tmp
cd $dir_storage
find * -print0 | xargs -0 touch -c -h -t 201001010000.00
find * ! -type d -print0 | sort -z | xargs -0 tar -cf $tmp 2>/dev/null
cd - >>/dev/null
if [ ! -f "$tmp" ] ; then
logger -t "Storage" "Cannot create tarball file: $tmp"
exit 1
fi
}
func_save()
{
local fsz
echo "Save storage files to MTD partition \"$mtd_part_dev\""
rm -f $tbz
md5sum -c -s $hsh 2>/dev/null
if [ $? -eq 0 ] ; then
echo "Storage hash is not changed, skip write to MTD partition. Exit."
rm -f $tmp
return 0
fi
md5sum $tmp > $hsh
bzip2 -9 $tmp 2>/dev/null
fsz=`stat -c %s $tbz 2>/dev/null`
if [ -n "$fsz" ] && [ $fsz -ge 16 ] && [ $fsz -le $mtd_part_size ] ; then
mtd_write write $tbz $mtd_part_name
if [ $? -eq 0 ] ; then
echo "Done."
else
result=1
echo "Error! MTD write FAILED"
logger -t "Storage save" "Error write to MTD partition: $mtd_part_dev"
fi
else
result=1
echo "Error! Invalid storage final data size: $fsz"
logger -t "Storage save" "Invalid storage final data size: $fsz"
[ $fsz -gt $mtd_part_size ] && logger -t "Storage save" "Storage using data size: $fsz > flash partition size: $mtd_part_size"
fi
rm -f $tmp
rm -f $tbz
}
func_backup()
{
rm -f $tbz
bzip2 -9 $tmp 2>/dev/null
if [ $? -ne 0 ] ; then
result=1
logger -t "Storage backup" "Cannot create BZ2 file!"
fi
rm -f $tmp
}
func_restore()
{
local fsz tmp_storage
[ ! -f "$tbz" ] && exit 1
fsz=`stat -c %s $tbz 2>/dev/null`
if [ -z "$fsz" ] || [ $fsz -lt 16 ] || [ $fsz -gt $mtd_part_size ] ; then
result=1
rm -f $tbz
logger -t "Storage restore" "Invalid BZ2 file size: $fsz"
return 1
fi
tmp_storage="/tmp/storage"
rm -rf $tmp_storage
mkdir -p -m 755 $tmp_storage
tar xjf $tbz -C $tmp_storage 2>/dev/null
if [ $? -ne 0 ] ; then
result=1
rm -f $tbz
rm -rf $tmp_storage
logger -t "Storage restore" "Unable to extract BZ2 file: $tbz"
return 1
fi
if [ ! -f "$tmp_storage/start_script.sh" ] ; then
result=1
rm -f $tbz
rm -rf $tmp_storage
logger -t "Storage restore" "Invalid content of BZ2 file: $tbz"
return 1
fi
func_stop_apps
rm -f $slk
rm -f $tbz
rm -rf $dir_storage
mkdir -p -m 755 $dir_storage
cp -rf $tmp_storage /etc
rm -rf $tmp_storage
func_start_apps
}
func_erase()
{
mtd_write erase $mtd_part_name
if [ $? -eq 0 ] ; then
rm -f $hsh
rm -rf $dir_storage
mkdir -p -m 755 $dir_storage
touch "$slk"
else
result=1
fi
}
func_reset()
{
rm -f $slk
rm -rf $dir_storage
mkdir -p -m 755 $dir_storage
}
func_resetsh()
{
rm -f $slk
rm -f /etc/storage/Builds-*
if [ -z "$(grep /etc/storage/script_script.sh /etc/storage/started_script.sh)" ] ; then
logger -t "【mtd_storage.sh】" "由于【/etc/storage/started_script.sh】缺少关键启动命令:【/etc/storage/script_script.sh】,重置全部脚本!"
#删除UI配置文件
rm -f $jbls_script $vlmcsdini_script $config_tinyproxy $config_mproxy $shadowsocks_ss_spec_lan $shadowsocks_ss_spec_wan $kcptun_script $SSRconfig_script
rm -f $ngrok_script $frp_script $ddns_script $ad_config_script $adbyby_rules_script $adm_rules_script $koolproxy_rules_list $koolproxy_rules_script
rm -f /etc/storage/v2ray_config_script.sh /etc/storage/cow_config_script.sh /etc/storage/meow_config_script.sh /etc/storage/meow_direct_script.sh
rm -f $koolproxy_rules_list $vlmcsdini_script
#删除UI脚本文件
rm -f /etc/storage/v2ray_script.sh /etc/storage/cow_script.sh /etc/storage/meow_script.sh /etc/storage/softether_script.sh
#删除内部脚本文件
rm -f $script0_script $script_script $script1_script $script2_script $script3_script $crontabs_script $DNSPOD_script $cloudxns_script $aliddns_script
rm -f $serverchan_script $script_start $script_started $script_postf $script_postw $script_inets $script_vpnsc $script_vpncs $script_ezbtn
fi
rm -f /opt/bin/ss-redir /opt/bin/ssr-redir /opt/bin/ss-local /opt/bin/ssr-local /opt/bin/obfs-local
rm -f /opt/bin/ss0-redir /opt/bin/ssr0-redir /opt/bin/ss0-local /opt/bin/ssr0-local
rm -f $script_script
mkdir -p -m 755 $dir_storage
rm -f /etc/storage/china_ip_list.txt /etc/storage/basedomain.txt
[ ! -f /etc/storage/china_ip_list.txt ] && tar -xzvf /etc_ro/china_ip_list.tgz -C /tmp && ln -sf /tmp/china_ip_list.txt /etc/storage/china_ip_list.txt
[ ! -f /etc/storage/basedomain.txt ] && tar -xzvf /etc_ro/basedomain.tgz -C /tmp && ln -sf /tmp/basedomain.txt /etc/storage/basedomain.txt
# 解压覆盖脚本
tar -xzvf /etc_ro/script.tgz -C /etc/storage/
tar -xzvf /etc_ro/www_sh.tgz -C /etc/storage/
# 重置菜单
sleep 1
#eval /etc/storage/www_sh/menu_title.sh re
touch /tmp/menu_title_re
}
func_fill()
{
mkdir -p -m 777 "/etc/storage/lib"
mkdir -p -m 777 "/etc/storage/bin"
mkdir -p -m 777 "/etc/storage/tinyproxy"
dir_httpssl="$dir_storage/https"
dir_dnsmasq="$dir_storage/dnsmasq"
dir_ovpnsvr="$dir_storage/openvpn/server"
dir_ovpncli="$dir_storage/openvpn/client"
dir_sswan="$dir_storage/strongswan"
dir_sswan_crt="$dir_sswan/ipsec.d"
dir_inadyn="$dir_storage/inadyn"
dir_crond="$dir_storage/cron/crontabs"
dir_wlan="$dir_storage/wlan"
{
[ ! -s /etc/storage/china_ip_list.txt ] && [ -s /etc_ro/china_ip_list.tgz ] && { tar -xzvf /etc_ro/china_ip_list.tgz -C /tmp ; ln -sf /tmp/china_ip_list.txt /etc/storage/china_ip_list.txt ; }
[ ! -s /etc/storage/basedomain.txt ] && [ -s /etc_ro/basedomain.tgz ] && { tar -xzvf /etc_ro/basedomain.tgz -C /tmp ; ln -sf /tmp/basedomain.txt /etc/storage/basedomain.txt ; }
[ ! -s /etc/storage/qos.conf ] && [ -s /etc_ro/qos.conf ] && cp -f /etc_ro/qos.conf /etc/storage
ln -sf /etc/storage/PhMain.ini /etc/PhMain.ini &
ln -sf /etc/storage/init.status /etc/init.status &
[ ! -s /etc/storage/script/init.sh ] && [ -s /etc_ro/script.tgz ] && tar -xzvf /etc_ro/script.tgz -C /etc/storage/
[ -s /etc/storage/script/init.sh ] && chmod 777 /etc/storage/script -R
[ ! -s /etc/storage/www_sh/menu_title.sh ] && [ -s /etc_ro/www_sh.tgz ] && tar -xzvf /etc_ro/www_sh.tgz -C /etc/storage/
[ -s /etc/storage/www_sh/menu_title.sh ] && chmod 777 /etc/storage/www_sh -R
#[ ! -s /etc/storage/bin/daydayup ] && [ -s /etc_ro/daydayup ] && ln -sf /etc_ro/daydayup /etc/storage/bin/daydayup
} &
user_hosts="$dir_dnsmasq/hosts"
user_dnsmasq_conf="$dir_dnsmasq/dnsmasq.conf"
user_dnsmasq_serv="$dir_dnsmasq/dnsmasq.servers"
user_ovpnsvr_conf="$dir_ovpnsvr/server.conf"
user_ovpncli_conf="$dir_ovpncli/client.conf"
user_inadyn_conf="$dir_inadyn/inadyn.conf"
user_sswan_conf="$dir_sswan/strongswan.conf"
user_sswan_ipsec_conf="$dir_sswan/ipsec.conf"
user_sswan_secrets="$dir_sswan/ipsec.secrets"
# create crond dir
[ ! -d "$dir_crond" ] && mkdir -p -m 730 "$dir_crond"
# create https dir
[ ! -d "$dir_httpssl" ] && mkdir -p -m 700 "$dir_httpssl"
# create start script
if [ ! -f "$script_start" ] ; then
reset_ss.sh -a
fi
# create started script
if [ ! -f "$script_started" ] ; then
cat > "$script_started" <<-\EEE
#!/bin/sh
### Custom user script
### Called after router started and network is ready
### Example - load ipset modules
modprobe ip_set
modprobe ip_set_hash_ip
modprobe ip_set_hash_net
modprobe ip_set_bitmap_ip
modprobe ip_set_list_set
modprobe xt_set
/etc/storage/www_sh/menu_title.sh &
#confdir=`grep "/tmp/ss/dnsmasq.d" /etc/storage/dnsmasq/dnsmasq.conf | sed 's/.*\=//g'`
#if [ -z "$confdir" ] ; then
confdir="/tmp/ss/dnsmasq.d"
#fi
[ ! -d "$confdir" ] && mkdir -p $confdir
# SMB资源挂载(局域网共享映射,无USB也能挂载储存空间)
# 说明:【192.168.123.66】为共享服务器的IP,【nas】为共享文件夹名称
# 说明:username=、password=填账号密码,删除代码前面的#启用功能。
#sleep 10
#modprobe des_generic
#modprobe cifs CIFSMaxBufSize=64512
#mkdir -p /media/cifs
#mount -t cifs //192.168.123.66/nas /media/cifs -o username=user,password=pass,dynperm,nounix,noserverino,file_mode=0777,dir_mode=0777
sleep 5
stop_ftpsamba
sleep 3
#mdev -s
# 挂载SD卡
for mmc_mount in `/usr/bin/find /dev -name 'mmcblk[0-9]*' | awk '{print $1}'`
do
[ ! -z "$(df -m | grep $mmc_mount )" ] && continue
mmc_mount=$(basename $mmc_mount | awk '{print $1}')
echo $mmc_mount
device_name=`echo ${mmc_mount:6:1}`
partno=`echo ${mmc_mount:8:1}`
[ -z "$partno" ] && partno=1
/sbin/automount.sh $mmc_mount AiCard_$device_name$partno
done
# 挂载存储设备
for sd_mount in `/usr/bin/find /dev -name 'sd[a-z]*' | awk '{print $1}'`
do
[ ! -z "$(df -m | grep $sd_mount )" ] && continue
sd_mount=$(basename $sd_mount | awk '{print $1}')
echo $sd_mount
device_name=`echo ${sd_mount:2:1}`
partno=`echo ${sd_mount:3:1}`
[ -z "$partno" ] && partno=1
/sbin/automount.sh $sd_mount AiDisk_$device_name$partno
done
sleep 3
run_ftpsamba
sleep 3
### 运行脚本1
/etc/storage/script_script.sh
/etc/storage/ez_buttons_script.sh 3 &
logger -t "【运行路由器启动后】" "脚本完成"
# Office手动激活CMD命令:
# cd C:\Program Files\Microsoft Office\Office15
# cscript ospp.vbs /sethst:192.168.123.1
# cscript ospp.vbs /act
# cscript ospp.vbs /dstatus
# windows手动激活CMD命令:
# slmgr.vbs /upk
# slmgr.vbs /skms 192.168.123.1
# slmgr.vbs /ipk XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
# slmgr.vbs /ato
# slmgr.vbs /xpr
# key查看
# cat /etc/storage/key
#启动流量监控脚本
mkdir -p /tmp/bwmon
/usr/sbin/bwmon &
# 固件将加入使用情况统计 (感谢bigandy提供)
# 统计系统原因:
# 由于低容量固件(8M)的运行以及开启OPT后,部分程序需要实时从外部网络获取,
# 导致引起不少软件下载服务器或网盘等服务提供者的流量超标。
# 为了固件可以更加稳定运行,我们准备建立自己的软件下载服务器,但在建立下载服务器前,
# 我们希望了解一下固件被使用的情况,因此会加入一些与用户个人隐私无关的数据采集。
# 将会采集的数据内容仅包括如下内容:
# PN: 固件名称,由每次固件编译时候产生一个固定值。
# VER:固件版本,由每次固件编译时候产生一个固定值。
# UUID: 由系统自动生成的Linux UUID,一次性产生,随时可以删除重新产生随机数。
# 重置路由后会清除此ID,然后由系统随机重新生成。
# 生成方式 nvram set pdcn_uuid=`cat /proc/sys/kernel/random/uuid`,生成后保存在 nvram 里面,
# 直到路由被重置或者手动删除此id。如果不希望发送此数值,可以删除对应的数据提交脚本中的相应内容。
# OPT:OPT状态,用于得知是否需要下载或者更新 OPT 内容,以统计OPT下载服务所需要的带宽。
# 0:为没有,1,外置存储, 2, 内存虚拟盘
# 提交方式:
# wget 带参数。
# 以上便是所有将会提交到统计服务器的数据内容,如果觉得我们还会提交其他数据,
# 欢迎检查提交数据的脚本源码以及对提交行为进行抓包检查。
# 采集频度:
# 每次路由重新上电开机,也就是重启或者冷启动。
# 原因:路由中第三方程序以及OPT的载入在每次重启后向服务器请求下载,有了这个统计数据,
# 我们才能计算需要一台多少带宽的服务器提供第三方软件下载功能。
# 抵制方式:
# 如果你非常抗拒这种数据的采集行为,可以用以下方法关闭:
# 首次刷入或者重置后,不要联网,进入自定义脚本中,删除对应的采集语句。
# 但我们希望你不要抵制这个采集行为,毕竟需要提供的数据比任何一款软件自动升级的提交内容都要少。
# 这也是作为将来固件检测自动升级的一个标准动作,今后的下载服务器也会通过获取这些数据提供下载服务。
ss_opt_x=`nvram get ss_opt_x`
upanPath=""
[ "$ss_opt_x" = "3" ] && upanPath="`df -m | grep /dev/mmcb | grep -E "$(echo $(/usr/bin/find /dev/ -name 'mmcb*') | sed -e 's@/dev/ /dev/@/dev/@g' | sed -e 's@ @|@g')" | grep "/media" | awk '{print $NF}' | sort -u | awk 'NR==1' `"
[ "$ss_opt_x" = "4" ] && upanPath="`df -m | grep /dev/sd | grep -E "$(echo $(/usr/bin/find /dev/ -name 'sd*') | sed -e 's@/dev/ /dev/@/dev/@g' | sed -e 's@ @|@g')" | grep "/media" | awk '{print $NF}' | sort -u | awk 'NR==1' `"
[ -z "$upanPath" ] && [ "$ss_opt_x" = "1" ] && upanPath="`df -m | grep /dev/mmcb | grep -E "$(echo $(/usr/bin/find /dev/ -name 'mmcb*') | sed -e 's@/dev/ /dev/@/dev/@g' | sed -e 's@ @|@g')" | grep "/media" | awk '{print $NF}' | sort -u | awk 'NR==1' `"
[ -z "$upanPath" ] && [ "$ss_opt_x" = "1" ] && upanPath="`df -m | grep /dev/sd | grep -E "$(echo $(/usr/bin/find /dev/ -name 'sd*') | sed -e 's@/dev/ /dev/@/dev/@g' | sed -e 's@ @|@g')" | grep "/media" | awk '{print $NF}' | sort -u | awk 'NR==1' `"
echo "$upanPath"
if [ ! -z "$upanPath" ] ; then
#已挂载储存设备
opt_value="1"
else
#未挂载储存设备
opt_value="0"
[ -s /opt/bin/curl ] && opt_value="2"
fi
echo $opt_value
PN=`grep Web_Title= /www/EN.dict | sed 's/Web_Title=//g'| sed 's/ 无线路由器//g'`
VER=`nvram get firmver_sub`
pdcn_uuid=`nvram get pdcn_uuid`
[ -z $pdcn_uuid ] && pdcn_uuid=`cat /proc/sys/kernel/random/uuid` && nvram set pdcn_uuid=$pdcn_uuid
pdcn_uuid_enable=`nvram get pdcn_uuid_enable`
[ -z "$pdcn_uuid_enable" ] && pdcn_uuid_enable=1 && nvram set pdcn_uuid_enable=1
# 提交统计
if [ "$pdcn_uuid_enable" = "1" ] ; then
wget --no-check-certificate -O /dev/null http://pdcn.cn2k.net:8080/create?pn=$PN\&ver=$VER\&ID=$pdcn_uuid\&opt=$opt_value &
fi
EEE
chmod 755 "$script_started"
fi
# create shutdown script
if [ ! -f "$script_shutd" ] ; then
cat > "$script_shutd" <<-\EEE
#!/bin/sh
### Custom user script
### Called before router shutdown
### $1 - action (0: reboot, 1: halt, 2: power-off)
EEE
chmod 755 "$script_shutd"
fi
# create post-iptables script
if [ ! -f "$script_postf" ] ; then
cat > "$script_postf" <<-\EEE
#!/bin/sh
#copyright by Emong's Qos update hiboy
/etc/storage/crontabs_script.sh &
export PATH='/etc/storage/bin:/tmp/script:/etc/storage/script:/opt/usr/sbin:/opt/usr/bin:/opt/sbin:/opt/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin'
export LD_LIBRARY_PATH=/lib:/opt/lib
# qos 功能 0关闭;1启动
qoss=0
# 当在线终端≤2台时取消限速.(路由端1+电脑端1=2台)
qosb=2
# 默认为20M
DOWN=2560
UP=256
[ "$qoss" = "1" ] && logger -t "【QOS】" "最大下载 $DOWN KB/S,最大上传 $UP KB/S"
# IP限速设置
# 未设置的IP带宽减半,如启用adbyby,因7620的CPU瓶颈,宽带峰值50M
# 注意参数之间有空格
# 可选项:删除前面的#可生效
# [KB/S]IP地址 最大下载 下载保证 最大上传 上传保证
cat > "/tmp/qos_ip_limit_DOMAIN.txt" <<-\EOF
#192.168.123.115 2560 100 200 20
192.168.123.2-192.168.123.244 2560 100 100 15
EOF
# 连接数限制
#如果开启该功能后,打开下载软件可能会导致QQ等聊天软件掉线.(因为连接数量会被占光)
# IP地址 TCP连接数 UDP连接数
cat > "/tmp/qos_connlmt_DOMAIN.txt" <<-\EOF
#192.168.123.10 100 100
192.168.123.20-192.168.123.25 100 100
EOF
# 端口优先
# 请勿添加下载应用的端口80、8080等等.由于没有被流量控制和处理优先级,下载应用会占用大量资源导致网络卡
# 协议 端口
cat > "/tmp/qos_port_first_DOMAIN.txt" <<-\EOF
UDP 53
TCP 22
TCP 23
#TCP 443
TCP 1723
#TCP 3389
TCP 3724,1119,1120
TCP 28012,10008,13006,2349,7101:7103
UDP 2349,12000:12175
EOF
load_var() {
WAN_IF="imq1"
LAN_IF="imq0"
WAN_IFT=$(nvram get wan0_ifname_t)
IPM="iptables -t mangle"
lan_ip="`nvram get lan_ipaddr`/24"
}
load_modules(){
[ ! -f /tmp/qos-emong-modules ] && {
modprobe act_connmark #缺,补621-sched_act_connmark.patch@597
for module in imq ipt_IMQ ipt_web xt_length xt_hashlimit cls_fw sch_htb sch_sfq sch_red xt_length xt_IMQ ipt_ipp2p xt_dscp xt_DSCP cls_u32 sch_hfsc sch_prio ipt_multiport ipt_CONNMARK ipt_length ipt_hashlimit xt_connlimit xt_connbytes ipt_connlimit em_u32 sch_ingress act_mirred
do
modprobe $module
done
modprobe imq numdevs=1
echo >/tmp/qos-emong-modules
}
}
qos_stop() {
tc qdisc del dev $WAN_IF root
tc qdisc del dev $LAN_IF root
$IPM -F
$IPM -X UP
$IPM -X DOWN
$IPM -X IP_DOWN
$IPM -X IP_UP
}
qos_start(){
ip link set imq0 up
ip link set imq1 up
tc qdisc add dev $WAN_IF root handle 1: htb
tc qdisc add dev $LAN_IF root handle 1: htb
tc class add dev $WAN_IF parent 1: classid 1:2 htb rate $((UP))kbps
tc class add dev $LAN_IF parent 1: classid 1:2 htb rate $((DOWN))kbps
tc class add dev $WAN_IF parent 1: classid 1:1 htb rate $((UP*95/100))kbps
tc class add dev $WAN_IF parent 1:1 classid 1:11 htb rate $((UP*5/10))kbps prio 1
tc class add dev $WAN_IF parent 1:1 classid 1:12 htb rate $((UP*5/10))kbps ceil $((UP*9/10))kbps prio 2
tc class add dev $WAN_IF parent 1:12 classid 1:121 htb rate $((UP*4/10))kbps ceil $((UP*8/10))kbps prio 1
tc class add dev $WAN_IF parent 1:12 classid 1:122 htb rate $((UP*1/10))kbps ceil $((UP*4/10))kbps prio 2
tc class add dev $WAN_IF parent 1:12 classid 1:123 htb rate $((UP*4/10))kbps ceil $((UP*6/10))kbps prio 3
tc qdisc add dev $WAN_IF parent 1:11 handle 11: sfq perturb 10
tc qdisc add dev $WAN_IF parent 1:121 handle 121: sfq perturb 10
tc qdisc add dev $WAN_IF parent 1:122 handle 122: sfq perturb 10
tc qdisc add dev $WAN_IF parent 1:123 handle 123: sfq perturb 10
tc filter add dev $WAN_IF parent 1: handle 0x10/0xfff0 fw classid 1:11
tc filter add dev $WAN_IF parent 1: handle 0x20/0xfff0 fw classid 1:121
tc filter add dev $WAN_IF parent 1: handle 0x30/0xfff0 fw classid 1:122
tc filter add dev $WAN_IF parent 1: handle 0x40/0xfff0 fw classid 1:123
tc class add dev $LAN_IF parent 1: classid 1:1 htb rate $((DOWN*95/100))kbps
tc class add dev $LAN_IF parent 1:1 classid 1:11 htb rate $((DOWN*5/10))kbps prio 1
tc class add dev $LAN_IF parent 1:1 classid 1:12 htb rate $((DOWN*5/10))kbps ceil $((DOWN*9/10))kbps prio 2
tc class add dev $LAN_IF parent 1:12 classid 1:121 htb rate $((DOWN*4/10))kbps ceil $((DOWN*8/10))kbps prio 1
tc class add dev $LAN_IF parent 1:12 classid 1:122 htb rate $((DOWN*1/10))kbps ceil $((DOWN*4/10))kbps prio 10
tc class add dev $LAN_IF parent 1:12 classid 1:123 htb rate $((DOWN*4/10))kbps ceil $((DOWN*6/10))kbps prio 3
tc qdisc add dev $LAN_IF parent 1:11 handle 11: sfq perturb 10
tc qdisc add dev $LAN_IF parent 1:121 handle 121: sfq perturb 10
tc qdisc add dev $LAN_IF parent 1:122 handle 122: sfq perturb 10
tc qdisc add dev $LAN_IF parent 1:123 handle 123: sfq perturb 10
tc filter add dev $LAN_IF parent 1: handle 0x10/0xfff0 fw classid 1:11
tc filter add dev $LAN_IF parent 1: handle 0x20/0xfff0 fw classid 1:121
tc filter add dev $LAN_IF parent 1: handle 0x30/0xfff0 fw classid 1:122
tc filter add dev $LAN_IF parent 1: handle 0x40/0xfff0 fw classid 1:123
$IPM -N UP
$IPM -N DOWN
$IPM -N IP_UP
$IPM -N IP_DOWN
$IPM -I POSTROUTING -o br0 -j DOWN
$IPM -I PREROUTING -i br0 -j UP
$IPM -A DOWN -j IMQ --todev 0
$IPM -A UP -j IMQ --todev 1
#$IPM -I DOWN -s $lan_ip -j RETURN
$IPM -I DOWN -p tcp -m multiport --dports 22,53,445,139 -j RETURN
$IPM -I DOWN -p icmp -j RETURN
#$IPM -A DOWN -m length --length :100 -j RETURN
$IPM -A DOWN -j MARK --set-mark=0x41
$IPM -A DOWN -m length --length 1024:1500 -j MARK --set-mark=0x31
$IPM -A DOWN -p tcp -m multiport --dports 21,80,443,3389,8118 -j MARK --set-mark=0x21
$IPM -A DOWN -m length --length :768 -j MARK --set-mark=0x11
$IPM -A DOWN -j IP_DOWN
#$IPM -I UP -d $lan_ip -j RETURN
$IPM -I UP -p tcp -m multiport --sports 22,53,445,139 -j RETURN
$IPM -I UP -p icmp -j RETURN
#$IPM -A UP -m length --length :80 -j RETURN
$IPM -A UP -j MARK --set-mark=0x41
$IPM -A UP -m length --length 1024:1500 -j MARK --set-mark=0x31
$IPM -A UP -p tcp -m multiport --sports 21,80,443,3389,8118 -j MARK --set-mark=0x21
$IPM -A UP -m length --length :512 -j MARK --set-mark=0x11
$IPM -A UP -j IP_UP
}
connlmt() {
$IPM -A FORWARD -p tcp -d $1 -m connlimit --connlimit-above $2 -j DROP
$IPM -A FORWARD -p udp -d $1 -m connlimit --connlimit-above $3 -j DROP
}
ip_limit() {
conns=$6
[ $((conns)) -lt "6" ] && logger -t "【QOS】" "限速设置[KB/S]IP:$1, 最大下载:$2, 下载保证:$3, 最大上传:$4, 上传保证:$5"
[ $((conns)) -ge "6" ] && logger -t "【QOS】" "连接数限制IP:$1 TCP:$2, UDP:$3"
n=$(echo $1|cut -d '-' -f1|cut -d '.' -f4)
m=$(echo $1|cut -d '-' -f2|cut -d '.' -f4)
NET=$(echo $1|cut -d '.' -f1-3)
while [ $n -le $m ]
do
ip=$n
if [ $((conns)) -lt "6" ] ; then
[ ${#ip} -lt 3 ] && ip=0$ip
[ ${#ip} -lt 3 ] && ip=0$ip
var=1
tc class add dev $WAN_IF parent 1:2 classid 1:$var$ip htb rate $5kbps ceil $4kbps
tc qdisc add dev $WAN_IF parent 1:$var$ip handle $var$ip sfq perturb 10
tc filter add dev $WAN_IF parent 1: handle 0x$var$ip fw flowid 1:$var$ip
tc class add dev $LAN_IF parent 1:2 classid 1:$var$ip htb rate $3kbps ceil $2kbps
tc qdisc add dev $LAN_IF parent 1:$var$ip handle $var$ip sfq perturb 10
tc filter add dev $LAN_IF parent 1: handle 0x$var$ip fw flowid 1:$var$ip
$IPM -A IP_DOWN -d $NET.$n -j MARK --set-mark 0x$var$ip
$IPM -A IP_UP -s $NET.$n -j MARK --set-mark 0x$var$ip
else
connlmt $NET.$n $2 $3
fi
n=$((n+1))
done
}
port_first() {
logger -t "【QOS】" "端口优先:$1, $2"
$IPM -I DOWN -p $1 -m multiport --dports $2 -j RETURN
$IPM -I UP -p $1 -m multiport --sports $2 -j RETURN
}
if [ "$qoss" = "1" ] && [ -f "/lib/modules/$(uname -r)/kernel/net/netfilter/xt_IMQ.ko" ] ; then
if [ $(cat /tmp/qos_state) -eq 1 ] ; then
logger -t "【QOS】" "正在运行"
exit
else
echo 1 >/tmp/qos_state
fi
logger -t "【QOS】" "启动 QOS 成功"
echo 1 >/tmp/qoss_state
load_var
load_modules
qos_stop
qos_start
while read line
do
c_line=`echo $line |grep -v "#"`
if [ ! -z "$c_line" ] ; then
ip_limit $line
fi
done < /tmp/qos_ip_limit_DOMAIN.txt
while read line
do
c_line=`echo $line |grep -v "#"`
if [ ! -z "$c_line" ] ; then
line="$line 4 5 6"
ip_limit $line
fi
done < /tmp/qos_connlmt_DOMAIN.txt
while read line
do
c_line=`echo $line |grep -v "#"`
if [ ! -z "$c_line" ] ; then
port_first $line
fi
done < /tmp/qos_port_first_DOMAIN.txt
if [ ! -f /tmp/qos_scheduler.lock ] ; then
/tmp/qos_scheduler.sh $qosb &
fi
echo 0 >/tmp/qos_state
else
logger -t "【QOS】" "QOS 没有开启或闪存不足缺模块"
echo 0 >/tmp/qoss_state
ip link set imq0 down
ip link set imq1 down
fi
logger -t "【防火墙规则】" "脚本完成"
EEE
chmod 755 "$script_postf"
fi
if [ ! -f "$ap_script" ] || [ ! -s "$ap_script" ] ; then
cat > "$ap_script" <<-\EEE
#!/bin/sh
#/etc/storage/ap_script.sh
#copyright by hiboy
# AP中继连接守护功能。【0】 Internet互联网断线后自动搜寻;【1】 当中继信号断开时启动自动搜寻。
apauto=0
# AP连接成功条件,【0】 连上AP即可,不检查是否联网;【1】 连上AP并连上Internet互联网。
apauto2=0
# 【0】 联网断线后自动搜寻,大于【10】时则每隔【N】秒搜寻(无线网络会瞬断一下),直到连上最优先信号。
aptime="0"
# 如搜寻的AP不联网则列入黑名单/tmp/apblack.txt 功能 【0】关闭;【1】启动
# 控制台输入【echo "" > /tmp/apblack.txt】可以清空黑名单
apblack=0
# 自定义分隔符号,默认为【@】,注意:下面配置一同修改
fenge='@'
# 【自动切换中继信号】功能 填写配置参数启动
cat >/tmp/ap2g5g.txt <<-\EOF
# 中继AP配置填写说明:
# 各参数用【@】分割开,如果有多个信号可回车换行继续填写即可(从第一行的参数开始搜寻)【第一行的是最优先信号】
# 搜寻时无线网络会瞬断一下
# 参数说明:
# ①2.4Ghz或5Ghz:"2"=【2.4Ghz】"5"=【5Ghz】
# ②无线AP工作模式:"0"=【AP(桥接被禁用)】"1"=【WDS桥接(AP被禁用)】"2"=【WDS中继(网桥 + AP)】"3"=【AP-Client(AP被禁用)】"4"=【AP-Client + AP】
# ③无线AP-Client角色: "0"=【LAN bridge】"1"=【WAN (Wireless ISP)】
# ④中继AP 的 SSID:"ASUS"
# ⑤中继AP 密码:"1234567890"
# ⑥中继AP 的 MAC地址:"20:76:90:20:B0:F0"【可以不填,不限大小写】
# 下面是信号填写例子:(删除前面的#可生效)
#2@4@1@ASUS@1234567890
#2@4@1@ASUS_中文@1234567890@34:bd:f9:1f:d2:b1
#2@4@1@ASUS3@1234567890@34:bd:f9:1f:d2:b0
EOF
cat /tmp/ap2g5g.txt | grep -v '^#' | grep -v "^$" > /tmp/ap2g5g
killall sh_apauto.sh
if [ -s /tmp/ap2g5g ] ; then
cat >/tmp/sh_apauto.sh <<-\EOF
#!/bin/sh
logger -t "【AP 中继】" "连接守护启动"
while true; do
if [ ! -f /tmp/apc.lock ] ; then
if [[ $(cat /tmp/apauto.lock) == 1 ]] ; then
#【1】 当中继信号断开时启动自动搜寻
a2=`iwconfig apcli0 | awk -F'"' '/ESSID/ {print $2}'`
a5=`iwconfig apclii0 | awk -F'"' '/ESSID/ {print $2}'`
[ "$a2" = "" -a "$a5" = "" ] && ap=1 || ap=0
if [ "$ap" = "1" ] ; then
logger -t "【AP 中继】" "连接中断,启动自动搜寻"
/etc/storage/inet_state_script.sh 0 t &
fi
fi
if [[ $(cat /tmp/apauto.lock) == 0 ]] ; then
#【2】 Internet互联网断线后自动搜寻
ping_text=`ping -4 114.114.114.114 -c 1 -w 2 -q`
ping_time=`echo $ping_text | awk -F '/' '{print $4}'| awk -F '.' '{print $1}'`
ping_loss=`echo $ping_text | awk -F ', ' '{print $3}' | awk '{print $1}'`
if [ ! -z "$ping_time" ] ; then
echo "ping:$ping_time ms 丢包率:$ping_loss"
else
echo "ping:失效"
fi
if [ ! -z "$ping_time" ] ; then
echo "online"
else
echo "Internet互联网断线后自动搜寻"
/etc/storage/inet_state_script.sh 0 t &
fi
fi
fi
sleep 69
done
EOF
chmod 777 "/tmp/sh_apauto.sh"
echo $apauto > /tmp/apauto.lock
[ "$1" = "crontabs" ] && /tmp/sh_apauto.sh &
else
echo "" > /tmp/apauto.lock
fi
EEE
chmod 755 "$ap_script"
fi
# create inet-state script
if [ ! -f "$script_inets" ] || [ ! -s "$script_inets" ] ; then
cat > "$script_inets" <<-\EEE
#!/bin/sh
#/etc/storage/inet_state_script.sh
### Custom user script
### Called on Internet status changed
### $1 - Internet status (0/1)
### $2 - elapsed time (s) from previous state
#copyright by hiboy
logger -t "【网络检测】" "互联网状态:$1, 经过时间:$2s."
# 【自动切换中继信号】功能 需要到【无线网络 - 无线桥接】页面配置
. /etc/storage/ap_script.sh
baidu='http://gb.corp.163.com/gb/images/spacer.gif'
aptimes=$1
if [ $((aptimes)) -gt "9" ] ; then
logger -t "【连接 AP】" "$1秒后, 自动搜寻 ap"
sleep $1
else
logger -t "【连接 AP】" "10秒后, 自动搜寻 ap"
sleep 10
fi
cat /tmp/ap2g5g.txt | grep -v '^#' | grep -v "^$" > /tmp/ap2g5g
if [ ! -f /tmp/apc.lock ] && [ "$1" != "1" ] && [ -s /tmp/ap2g5g ] ; then
touch /tmp/apc.lock
a2=`iwconfig apcli0 | awk -F'"' '/ESSID/ {print $2}'`
a5=`iwconfig apclii0 | awk -F'"' '/ESSID/ {print $2}'`
[ "$a2" = "" -a "$a5" = "" ] && ap=1 || ap=0
if [ "$ap" = "1" ] || [ "$2" = "t" ] && [ -f /tmp/apc.lock ] ; then
#搜寻开始/tmp/ap2g5g
while read line
do
c_line=`echo $line | grep -v '^#' | grep -v "^$"`
if [ ! -z "$c_line" ] ; then
apc=$line
radio=$(echo $apc | cut -d $fenge -f1)
# ApCli 2.4Ghz
if [ "$radio" = "2" ] ; then
rtwlt_mode_x=`nvram get rt_mode_x`
else
rtwlt_mode_x=`nvram get wl_mode_x`
fi
# [ "$rtwlt_mode_x" = "3" ] || [ "$rtwlt_mode_x" = "4" ] &&
rtwlt_mode_x=$(echo $apc | cut -d $fenge -f2)
rtwlt_sta_wisp=$(echo $apc | cut -d $fenge -f3)
rtwlt_sta_ssid=$(echo $apc | cut -d $fenge -f4)
rtwlt_sta_wpa_psk=$(echo $apc | cut -d $fenge -f5)
rtwlt_sta_bssid=$(echo $apc | cut -d $fenge -f6 | tr 'A-Z' 'a-z')
if [ "$radio" = "2" ] ; then
ap=`iwconfig | grep 'apcli0' | grep ESSID:"$rtwlt_sta_ssid" | wc -l`
if [ "$ap" = "0" ] ; then
ap=`iwconfig |sed -n '/apcli0/,/Rate/{/apcli0/n;/Rate/b;p}' | grep $rtwlt_sta_bssid | tr 'A-Z' 'a-z' | wc -l`
fi
else
ap=`iwconfig | grep 'apclii0' | grep ESSID:"$rtwlt_sta_ssid" | wc -l`
if [ "$ap" = "0" ] ; then
ap=`iwconfig |sed -n '/apclii0/,/Rate/{/apclii0/n;/Rate/b;p}' | grep $rtwlt_sta_bssid | tr 'A-Z' 'a-z' | wc -l`
fi
fi
if [ "$ap" = "1" ] ; then
logger -t "【连接 AP】" "当前是 $rtwlt_sta_ssid, 停止搜寻"
rm -f /tmp/apc.lock
if [ $((aptime)) -ge "9" ] ; then
/etc/storage/inet_state_script.sh $aptime "t" &
sleep 2
logger -t "【连接 AP】" "直到连上最优先信号 $(echo $(grep -v '^#' /tmp/ap2g5g | grep -v "^$" | head -1) | cut -d $fenge -f4)"
fi
exit
else
logger -t "【连接 AP】" "自动搜寻 $rtwlt_sta_ssid"
fi
if [ "$radio" = "2" ] ; then
# ApCli 2.4Ghz
iwpriv apcli0 set SiteSurvey=1
if [ ! -z "$rtwlt_sta_bssid" ] ; then
logger -t "【连接 AP】" "自动搜寻 $rtwlt_sta_ssid:$rtwlt_sta_bssid"
site_survey=$(iwpriv apcli0 get_site_survey | sed -n "/$rtwlt_sta_bssid/p" | tr 'A-Z' 'a-z')
else
site_survey=$(iwpriv apcli0 get_site_survey | sed -n "/$rtwlt_sta_ssid/p" | tr 'A-Z' 'a-z')
fi
else
iwpriv apclii0 set SiteSurvey=1
if [ ! -z "$rtwlt_sta_bssid" ] ; then
logger -t "【连接 AP】" "自动搜寻 $rtwlt_sta_ssid:$rtwlt_sta_bssid"
site_survey=$(iwpriv apclii0 get_site_survey | sed -n "/$rtwlt_sta_bssid/p" | tr 'A-Z' 'a-z')
else
site_survey=$(iwpriv apclii0 get_site_survey | sed -n "/$rtwlt_sta_ssid/p" | tr 'A-Z' 'a-z')
fi
fi
if [ -z "$site_survey" ] ; then
logger -t "【连接 AP】" "没找到 $rtwlt_sta_ssid, 如果含中文请填写正确的MAC地址"
ap3=1
fi
if [ ! -z "$site_survey" ] ; then
Ch=${site_survey:0:4}
SSID=${site_survey:4:33}
BSSID=${site_survey:37:20}
Security=${site_survey:57:23}
Signal=${site_survey:80:9}
WMode=${site_survey:89:7}
ap3=0
fi
if [ "$apblack" = "1" ] ; then
apblacktxt=$(grep "【SSID:$rtwlt_sta_bssid" /tmp/apblack.txt)
if [ ! -z $apblacktxt ] ; then
logger -t "【连接 AP】" "当前是黑名单 $rtwlt_sta_ssid, 跳过黑名单继续搜寻"
ap3=1
else
apblacktxt=$(grep "【SSID:$rtwlt_sta_ssid" /tmp/apblack.txt)
if [ ! -z $apblacktxt ] ; then
logger -t "【连接 AP】" "当前是黑名单 $rtwlt_sta_ssid, 跳过黑名单继续搜寻"
ap3=1
fi
fi
fi
if [ "$ap3" != "1" ] ; then
if [ "$radio" = "2" ] ; then
nvram set rt_channel=$Ch
iwpriv apcli0 set Channel=$Ch
else
nvram set wl_channel=$Ch
iwpriv apclii0 set Channel=$Ch
fi
if [[ $(expr $Security : ".*none*") -gt "1" ]] ; then
rtwlt_sta_auth_mode="open"
rtwlt_sta_wpa_mode="0"
fi
if [[ $(expr $Security : ".*1psk*") -gt "1" ]] ; then
rtwlt_sta_auth_mode="psk"
rtwlt_sta_wpa_mode="1"
fi
if [[ $(expr $Security : ".*2psk*") -gt "1" ]] ; then
rtwlt_sta_auth_mode="psk"
rtwlt_sta_wpa_mode="2"
fi
if [[ $(expr $Security : ".*wpapsk*") -gt "1" ]] ; then
rtwlt_sta_auth_mode="psk"
rtwlt_sta_wpa_mode="1"
fi
if [[ $(expr $Security : ".*tkip*") -gt "1" ]] ; then
rtwlt_sta_crypto="tkip"
fi
if [[ $(expr $Security : ".*aes*") -gt "1" ]] ; then
rtwlt_sta_crypto="aes"
fi
if [ "$radio" = "2" ] ; then
nvram set rt_mode_x=$rtwlt_mode_x
nvram set rt_sta_wisp=$rtwlt_sta_wisp