forked from hiboyhiboy/opt-file
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3script_script.sh
6470 lines (6111 loc) · 263 KB
/
3script_script.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
#copyright by hiboy
[ -f /tmp/script.lock ] && exit 0
touch /tmp/script.lock
### 创建子程序脚本【https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/3script_script.sh】
cat > "/tmp/sh_wifi_dog.sh" <<-\EEF
#!/bin/sh
export PATH='/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
IPT=/bin/iptables
WD_DIR="/usr/bin"
SVC_PATH=$WD_DIR/wifidog
if [ ! -f "$SVC_PATH" ] ; then
WD_DIR="/opt/bin"
fi
#开关
wifidog_enable=`nvram get wifidog_enable`
wifidog_Daemon=`nvram get wifidog_Daemon`
#认证服务器
wifidog_Hostname=`nvram get wifidog_Hostname`
wifidog_HTTPPort=`nvram get wifidog_HTTPPort`
[ -z $wifidog_HTTPPort ] && wifidog_HTTPPort="80" && nvram set wifidog_HTTPPort=$wifidog_HTTPPort
wifidog_Path=`nvram get wifidog_Path`
[ -z $wifidog_Path ] && wifidog_Path="/" && nvram set wifidog_Path=$wifidog_Path
#高级设置
wifidog_id=`nvram get wifidog_id`
[ -z $wifidog_id ] && wifidog_id=$(/sbin/ifconfig br0 | sed -n '/HWaddr/ s/^.*HWaddr */HWADDR=/pg' | awk -F"=" '{print $2}' |sed -n 's/://pg'| awk -F" " '{print $1}') && nvram set wifidog_id=$wifidog_id
wifidog_lanif=`nvram get wifidog_lanif`
[ -z $wifidog_lanif ] && wifidog_lanif="br0" && nvram set wifidog_lanif=$wifidog_lanif
wifidog_wanif=`nvram get wifidog_wanif`
[ -z $wifidog_wanif ] && wifidog_wanif=$(nvram get wan0_ifname_t) && nvram set wifidog_wanif=$wifidog_wanif
wifidog_Port=`nvram get wifidog_Port`
[ -z $wifidog_Port ] && wifidog_Port="2060" && nvram set wifidog_Port=$wifidog_Port
wifidog_Interval=`nvram get wifidog_Interval`
[ -z $wifidog_Interval ] && wifidog_Interval="60" && nvram set wifidog_Interval=$wifidog_Interval
wifidog_Timeout=`nvram get wifidog_Timeout`
[ -z $wifidog_Timeout ] && wifidog_Timeout="5" && nvram set wifidog_Timeout=$wifidog_Timeout
wifidog_MaxConn=`nvram get wifidog_MaxConn`
[ -z $wifidog_MaxConn ] && wifidog_MaxConn="30" && nvram set wifidog_MaxConn=$wifidog_MaxConn
wifidog_MACList=`nvram get wifidog_MACList`
[ -z $wifidog_MACList ] && wifidog_MACList="00:00:DE:AD:BE:AF" && nvram set wifidog_MACList=$wifidog_MACList
start()
{
SVC_PATH=$WD_DIR/wifidog
if [ ! -f "$SVC_PATH" ] ; then
SVC_PATH="/opt/bin/wifidog"
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【Wifidog】" "自动安装 wifidog 程序"
# 找不到 wifidog,安装 opt
if [ ! -d "/opt/bin" ] ; then
upanPath=""
ss_opt_x=`nvram get ss_opt_x`
[ "$ss_opt_x" = "3" ] || [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}'| grep AiCard | sed -n '1p'`
[ -z $upanPath ] && [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
[ "$ss_opt_x" = "4" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
if [ ! -z $upanPath ] ; then
mkdir -p /media/$upanPath/opt
mount -o bind /media/$upanPath/opt /opt
ln -sf /media/$upanPath /tmp/AiDisk_00
else
mkdir -p /tmp/AiDisk_00/opt
mount -o bind /tmp/AiDisk_00/opt /opt
fi
mkdir -p /opt/bin
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【Wifidog】" "找不到 $SVC_PATH 下载程序"
wget --continue --no-check-certificate -O /opt/bin/wifidog "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/wifidog"
chmod 755 "/opt/bin/wifidog"
wget --continue --no-check-certificate -O /opt/bin/wdctl "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/wdctl"
chmod 755 "/opt/bin/wdctl"
else
logger -t "【Wifidog】" "找到 $SVC_PATH"
fi
SVC_PATH=/opt/bin/wifidog
fi
[ ! -s "$SVC_PATH" ] && { logger -t "【Wifidog】" "找不到 $SVC_PATH, 需要手动安装 $SVC_PATH"; }
{
rm -f /etc/storage/wifidog.conf
# 将数值赋给WiFiDog官方的配置参数
echo "
#WiFiDog 配置文件
#网关ID
GatewayID $wifidog_id
#内部网卡
GatewayInterface $wifidog_lanif
#外部网卡
ExternalInterface $wifidog_wanif
#认证服务器
AuthServer {
Hostname $wifidog_Hostname
HTTPPort $wifidog_HTTPPort
Path $wifidog_Path
}
#守护进程
Daemon $wifidog_Daemon
#检查DNS状态(Check DNS health by querying IPs of these hosts)
PopularServers $wifidog_Hostname
#运行状态
HtmlMessageFile /www/wifidog-msg.html
#监听端口
GatewayPort $wifidog_Port
#心跳间隔时间
CheckInterval $wifidog_Interval
#心跳间隔次数
ClientTimeout $wifidog_Timeout
#HTTP最大连接数
HTTPDMaxConn $wifidog_MaxConn
#信任的MAC地址,加入信任列表将不用登录可访问
TrustedMACList $wifidog_MACList
#全局防火墙设置
FirewallRuleSet global {
FirewallRule allow tcp port 443
}
#新验证用户
FirewallRuleSet validating-users {
FirewallRule allow to 0.0.0.0/0
}
#正常用户
FirewallRuleSet known-users {
FirewallRule allow to 0.0.0.0/0
}
#未知用户
FirewallRuleSet unknown-users {
FirewallRule allow udp port 53
FirewallRule allow tcp port 53
FirewallRule allow udp port 67
FirewallRule allow tcp port 67
}
#锁住用户
FirewallRuleSet locked-users {
FirewallRule block to 0.0.0.0/0
}
" >> /etc/storage/wifidog.conf
}
if [ "$wifidog_enable" = "1" ] ; then
$WD_DIR/wifidog -c /etc/storage/wifidog.conf &
fi
logger -t "【Wifidog】" "启动"
}
stop()
{
logger -t "【Wifidog】" "关闭"
echo "Stopping Wifidog ... "
if $WD_DIR/wdctl status 2> /dev/null
then
if $WD_DIR/wdctl stop
then
echo "OK"
else
echo "FAILED: wdctl stop exited with non 0 status"
fi
else
echo "FAILED: Wifidog was not running"
fi
}
status()
{
$WD_DIR/wdctl status
}
case "$1" in
start)
start
;;
restart)
stop
sleep 2
start
;;
reload)
stop
sleep 2
start
;;
stop)
stop
;;
status)
status
;;
debug|test-module)
### Test ipt_mark with iptables
test_ipt_mark () {
IPTABLES_OK=$($IPT -A FORWARD -m mark --mark 2 -j ACCEPT 2>&1 | grep "No chain.target.match")
if [ -z "$IPTABLES_OK" ] ; then
$IPT -D FORWARD -m mark --mark 2 -j ACCEPT 2>&1
echo 1
else
echo 0
fi
}
### Test ipt_mac with iptables
test_ipt_mac () {
IPTABLES_OK=$($IPT -A INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1 | grep "No chain.target.match")
if [ -z "$IPTABLES_OK" ] ; then
$IPT -D INPUT -m mac --mac-source 00:00:00:00:00:00 -j ACCEPT 2>&1
echo 1
else
echo 0
fi
}
### Test ipt_REDIRECT with iptables
test_ipt_REDIRECT () {
IPTABLES_OK=$($IPT -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 2060 2>&1 | grep "No chain.target.match")
if [ -z "$IPTABLES_OK" ] ; then
$IPT -t nat -D PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 2060 2>&1
echo 1
else
echo 0
fi
}
### Find a module on disk
module_exists () {
echo " Looking for a module on disk"
EXIST=$(find /lib/modules/`uname -r` -name $1.*o 2>/dev/null)
if [ -n "$EXIST" ] ; then
echo 1
else
echo 0
fi
}
### Test if a module is in memory
module_in_memory () {
MODULE=$(lsmod | grep $1 | awk '{print $1}')
if [ "$MODULE" = "$1" ] ; then
echo 1
else
echo 0
fi
}
echo "Testing for iptables modules"
echo " Testing ipt_mac"
TEST_IPT_MAC=$(test_ipt_mac)
if [ "$TEST_IPT_MAC" = "0" ] ; then
echo " iptables is not working with ipt_mac"
echo " Scanning disk for ipt_mac module"
TEST_IPT_MAC_MODULE_EXISTS=$(module_exists "ipt_mac")
if [ "$TEST_IPT_MAC_MODULE_EXISTS" = "0" ] ; then
echo " ipt_mac module is missing, please install it (kernel or module)"
exit
else
echo " ipt_mac module exists, trying to load"
insmod ipt_mac > /dev/null
TEST_IPT_MAC_MODULE_MEMORY=$(module_in_memory "ipt_mac")
if [ "$TEST_IPT_MAC_MODULE_MEMORY" = "0" ] ; then
echo " Error: ipt_mac not loaded"
exit
else
echo " ipt_mac loaded sucessfully"
fi
fi
else
echo " ipt_mac module is working"
fi
echo " Testing ipt_mark"
TEST_IPT_MARK=$(test_ipt_mark)
if [ "$TEST_IPT_MARK" = "0" ] ; then
echo " iptables is not working with ipt_mark"
echo " Scanning disk for ipt_mark module"
TEST_IPT_MARK_MODULE_EXISTS=$(module_exists "ipt_mark")
if [ "$TEST_IPT_MARK_MODULE_EXISTS" = "0" ] ; then
echo " iptables ipt_mark module missing, please install it (kernel or module)"
exit
else
echo " ipt_mark module exists, trying to load"
insmod ipt_mark
TEST_IPT_MARK_MODULE_MEMORY=$(module_in_memory "ipt_mark")
if [ "$TEST_IPT_MARK_MODULE_MEMORY" = "0" ] ; then
echo " Error: ipt_mark not loaded"
exit
else
echo " ipt_mark loaded sucessfully"
fi
fi
else
echo " ipt_mark module is working"
fi
##TODO: This will not test if required iptables userspace (iptables-mod-nat on Kamikaze) is installed
echo " Testing ipt_REDIRECT"
TEST_IPT_MAC=$(test_ipt_REDIRECT)
if [ "$TEST_IPT_MAC" = "0" ] ; then
echo " iptables is not working with ipt_REDIRECT"
echo " Scanning disk for ipt_REDIRECT module"
TEST_IPT_MAC_MODULE_EXISTS=$(module_exists "ipt_REDIRECT")
if [ "$TEST_IPT_MAC_MODULE_EXISTS" = "0" ] ; then
echo " ipt_REDIRECT module is missing, please install it (kernel or module)"
exit
else
echo " ipt_REDIRECT module exists, trying to load"
insmod ipt_REDIRECT > /dev/null
TEST_IPT_MAC_MODULE_MEMORY=$(module_in_memory "ipt_REDIRECT")
if [ "$TEST_IPT_MAC_MODULE_MEMORY" = "0" ] ; then
echo " Error: ipt_REDIRECT not loaded"
exit
else
echo " ipt_REDIRECT loaded sucessfully"
fi
fi
else
echo " ipt_REDIRECT module is working"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status|test-module}"
A_restart=`nvram get wifidog_status`
B_restart="$wifidog_enable$wifidog_Daemon$wifidog_Hostname$wifidog_HTTPPort$wifidog_Path$wifidog_id$wifidog_lanif$wifidog_wanif$wifidog_Port$wifidog_Interval$wifidog_Timeout$wifidog_MaxConn$wifidog_MACList"
B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
if [ "$A_restart" != "$B_restart" ] ; then
nvram set wifidog_status=$B_restart
needed_restart=1
else
needed_restart=0
fi
if [ "$wifidog_enable" = "0" ] && [ "$needed_restart" = "1" ] ; then
[ ! -z "`pidof wifidog`" ] && logger -t "【Wifidog】" "停止 wifidog"
$WD_DIR/wdctl stop
sleep 1
killall -9 wifidog wdctl
fi
if [ "$wifidog_enable" = "1" ] ; then
port=$(iptables -t nat -L PREROUTING | grep 'Outgoing' | wc -l)
if [ "$port" = 0 ] ; then
logger -t "【Wifidog】" "检测:找不到 wifidog 转发规则, 重新添加"
stop
$WD_DIR/wdctl stop
sleep 1
killall -9 wifidog wdctl
start
fi
fi
if [ "$wifidog_enable" = "1" ] && [ "$needed_restart" = "1" ] ; then
$WD_DIR/wdctl stop
sleep 1
killall -9 wifidog wdctl
start
restart_dhcpd
fi
exit 1
;;
esac
exit 0
EEF
chmod 777 "/tmp/sh_wifi_dog.sh"
cat > "/tmp/sh_tinyproxy.sh" <<-\EEF
#!/bin/sh
export PATH='/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
tinyproxy_port=`nvram get tinyproxy_port`
tinyproxy_enable=`nvram get tinyproxy_enable`
tinyproxy_path=`nvram get tinyproxy_path`
[ -z $tinyproxy_path ] && tinyproxy_path=`which tinyproxy` && nvram set tinyproxy_path=$tinyproxy_path
A_restart=`nvram get tinyproxy_status`
B_restart="$tinyproxy_enable$tinyproxy_path$tinyproxy_port$(cat /etc/storage/tinyproxy_script.sh | grep -v '^#' | grep -v "^$")"
B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
if [ "$A_restart" != "$B_restart" ] ; then
nvram set tinyproxy_status=$B_restart
needed_restart=1
else
needed_restart=0
fi
if [ "$tinyproxy_enable" = "0" ] && [ "$needed_restart" = "1" ] ; then
[ ! -z "`pidof tinyproxy`" ] && logger -t "【tinyproxy】" "停止 tinyproxy"
killall -9 tinyproxy tinyproxy_script.sh
fi
if [ "$tinyproxy_enable" = "1" ] && [ "$needed_restart" = "1" ] ; then
killall -9 tinyproxy tinyproxy_script.sh
SVC_PATH=$tinyproxy_path
if [ ! -f "$SVC_PATH" ] ; then
SVC_PATH="/opt/bin/tinyproxy"
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【tinyproxy】" "自动安装 tinyproxy 程序"
# 找不到 tinyproxy,安装 opt
if [ ! -d "/opt/bin" ] ; then
upanPath=""
ss_opt_x=`nvram get ss_opt_x`
[ "$ss_opt_x" = "3" ] || [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}'| grep AiCard | sed -n '1p'`
[ -z $upanPath ] && [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
[ "$ss_opt_x" = "4" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
if [ ! -z $upanPath ] ; then
mkdir -p /media/$upanPath/opt
mount -o bind /media/$upanPath/opt /opt
ln -sf /media/$upanPath /tmp/AiDisk_00
else
mkdir -p /tmp/AiDisk_00/opt
mount -o bind /tmp/AiDisk_00/opt /opt
fi
mkdir -p /opt/bin
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【tinyproxy】" "找不到 $SVC_PATH 下载程序"
wget --continue --no-check-certificate -O /opt/bin/tinyproxy "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/tinyproxy"
chmod 755 "/opt/bin/tinyproxy"
else
logger -t "【tinyproxy】" "找到 $SVC_PATH"
fi
tinyproxy_path=`which tinyproxy` && nvram set tinyproxy_path=$tinyproxy_path
SVC_PATH=$tinyproxy_path
fi
[ ! -s "$SVC_PATH" ] && { logger -t "【tinyproxy】" "找不到 $SVC_PATH ,需要手动安装 $SVC_PATH"; }
logger -t "【tinyproxy】" "运行 tinyproxy_script"
killall -9 tinyproxy tinyproxy_script.sh
$tinyproxy_path -c /etc/storage/tinyproxy_script.sh &
restart_dhcpd
sleep 3
[ ! -z "`pidof tinyproxy`" ] && logger -t "【tinyproxy】" "启动成功"
[ -z "`pidof tinyproxy`" ] && logger -t "【tinyproxy】" "启动失败, 注意检查端口是否有冲突,10秒后自动尝试重新启动" && sleep 10 && nvram set tinyproxy_status=00 && /tmp/sh_tinyproxy.sh &
fi
EEF
chmod 777 "/tmp/sh_tinyproxy.sh"
cat > "/tmp/sh_mproxy.sh" <<-\EEF
#!/bin/sh
export PATH='/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
mproxy_enable=`nvram get mproxy_enable`
mproxy_port=`nvram get mproxy_port`
A_restart=`nvram get mproxy_status`
B_restart="$mproxy_enable$mproxy_port$(cat /etc/storage/mproxy_script.sh | grep -v '^#' | grep -v "^$")"
B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
if [ "$A_restart" != "$B_restart" ] ; then
nvram set mproxy_status=$B_restart
needed_restart=1
else
needed_restart=0
fi
if [ "$mproxy_enable" = "0" ] && [ "$needed_restart" = "1" ] ; then
[ ! -z "`pidof mproxy`" ] && logger -t "【mproxy】" "停止 mproxy"
killall -9 mproxy mproxy_script.sh
fi
if [ "$mproxy_enable" = "1" ] && [ "$needed_restart" = "1" ] ; then
killall -9 mproxy mproxy_script.sh
SVC_PATH="/usr/sbin/mproxy"
if [ ! -f "$SVC_PATH" ] ; then
SVC_PATH="/opt/bin/mproxy"
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【mproxy】" "自动安装 mproxy 程序"
# 找不到 mproxy,安装 opt
if [ ! -d "/opt/bin" ] ; then
upanPath=""
ss_opt_x=`nvram get ss_opt_x`
[ "$ss_opt_x" = "3" ] || [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}'| grep AiCard | sed -n '1p'`
[ -z $upanPath ] && [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
[ "$ss_opt_x" = "4" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
if [ ! -z $upanPath ] ; then
mkdir -p /media/$upanPath/opt
mount -o bind /media/$upanPath/opt /opt
ln -sf /media/$upanPath /tmp/AiDisk_00
else
mkdir -p /tmp/AiDisk_00/opt
mount -o bind /tmp/AiDisk_00/opt /opt
fi
mkdir -p /opt/bin
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【mproxy】" "找不到 $SVC_PATH 下载程序"
wget --continue --no-check-certificate -O /opt/bin/mproxy "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/mproxy"
chmod 755 "/opt/bin/mproxy"
else
logger -t "【mproxy】" "找到 $SVC_PATH"
fi
fi
hash mproxy 2>/dev/null || { logger -t "【mproxy】" "找不到 $SVC_PATH ,需要手动安装 $SVC_PATH"; }
logger -t "【mproxy】" "运行 mproxy_script"
killall -9 mproxy mproxy_script.sh
/etc/storage/mproxy_script.sh &
restart_dhcpd
sleep 5
[ ! -z "`pidof mproxy`" ] && logger -t "【mproxy】" "启动成功"
[ -z "`pidof mproxy`" ] && logger -t "【mproxy】" "启动失败, 注意检查端口是否有冲突, 10秒后自动尝试重新启动" && sleep 10 && nvram set mproxy_status=00 && /tmp/sh_mproxy.sh &
fi
EEF
chmod 777 "/tmp/sh_mproxy.sh"
cat > "/tmp/sh_vpnproxy.sh" <<-\EEF
#!/bin/sh
export PATH='/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
vpnproxy_enable=`nvram get vpnproxy_enable`
vpnproxy_wan_port=`nvram get vpnproxy_wan_port`
[ -z $vpnproxy_wan_port ] && vpnproxy_wan_port="8888" && nvram set vpnproxy_wan_port=$vpnproxy_wan_port
vpnproxy_vpn_port=`nvram get vpnproxy_vpn_port`
[ -z $vpnproxy_vpn_port ] && vpnproxy_vpn_port="1194" && nvram set vpnproxy_vpn_port=$vpnproxy_vpn_port
A_restart=`nvram get vpnproxy_status`
B_restart="$vpnproxy_enable$vpnproxy_wan_port$vpnproxy_vpn_port"
B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
if [ "$A_restart" != "$B_restart" ] ; then
nvram set vpnproxy_status=$B_restart
needed_restart=1
else
needed_restart=0
fi
if [ "$vpnproxy_enable" = "0" ] && [ "$needed_restart" = "1" ] ; then
[ ! -z "`pidof nvpproxy`" ] && logger -t "【vpnproxy】" "停止 vpnproxy"
killall -9 nvpproxy
fi
if [ "$vpnproxy_enable" = "1" ] && [ "$needed_restart" = "1" ] ; then
killall -9 nvpproxy
SVC_PATH="/opt/bin/nvpproxy"
hash nvpproxy 2>/dev/null || m -rf /opt/bin/nvpproxy
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【vpnproxy】" "自动安装 vpnproxy 程序"
# 找不到 vpnproxy,安装 opt
if [ ! -d "/opt/bin" ] ; then
upanPath=""
ss_opt_x=`nvram get ss_opt_x`
[ "$ss_opt_x" = "3" ] || [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}'| grep AiCard | sed -n '1p'`
[ -z $upanPath ] && [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
[ "$ss_opt_x" = "4" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
if [ ! -z $upanPath ] ; then
mkdir -p /media/$upanPath/opt
mount -o bind /media/$upanPath/opt /opt
ln -sf /media/$upanPath /tmp/AiDisk_00
else
mkdir -p /tmp/AiDisk_00/opt
mount -o bind /tmp/AiDisk_00/opt /opt
fi
mkdir -p /opt/bin
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【vpnproxy】" "找不到 $SVC_PATH 下载程序"
rm -rf /opt/bin/nvpproxy.tar.gz
wget --continue --no-check-certificate -O /opt/bin/nvpproxy.tar.gz "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/nvpproxy.tar.gz"
tar -xzvf /opt/bin/nvpproxy.tar.gz -C /opt/bin/
if [ ! -s "/opt/bin/nvpproxy" ] ; then
logger -t "【vpnproxy】" "解压不正常:/opt/bin/nvpproxy"
logger -t "【vpnproxy】" "启动失败, 10秒后自动尝试重新启动" && sleep 10
nvram set vpnproxy_status=00 && /tmp/sh_vpnproxy.sh &
exit 1
fi
chmod 755 "/opt/bin/nvpproxy"
rm -rf /opt/bin/nvpproxy.tar.gz
else
logger -t "【vpnproxy】" "找到 $SVC_PATH"
fi
fi
hash nvpproxy 2>/dev/null || { logger -t "【vpnproxy】" "找不到 $SVC_PATH ,需要手动安装 $SVC_PATH"; }
logger -t "【vpnproxy】" "运行 $SVC_PATH"
killall -9 nvpproxy
start-stop-daemon -S -q -b -m -p /var/run/nvpproxy.pid -x $SVC_PATH -- -port=$vpnproxy_wan_port -proxy=127.0.0.1:$vpnproxy_vpn_port
restart_dhcpd
sleep 5
[ ! -z "`pidof nvpproxy`" ] && logger -t "【vpnproxy】" "启动成功"
[ -z "`pidof nvpproxy`" ] && logger -t "【vpnproxy】" "启动失败, 注意检查端口是否有冲突, 10秒后自动尝试重新启动" && sleep 5 && nvram set vpnproxy_status=00 && /tmp/sh_vpnproxy.sh &
fi
EEF
chmod 777 "/tmp/sh_vpnproxy.sh"
cat > "/tmp/sh_shellinabox.sh" <<-\EEF
#!/bin/sh
export PATH='/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
shellinabox_enable=`nvram get shellinabox_enable`
[ -z $shellinabox_enable ] && shellinabox_enable="0" && nvram set shellinabox_enable=$shellinabox_enable
shellinabox_port=`nvram get shellinabox_port`
[ -z $shellinabox_port ] && shellinabox_port="4200" && nvram set shellinabox_port=$shellinabox_port
shellinabox_css=`nvram get shellinabox_css`
[ -z $shellinabox_css ] && shellinabox_css="white-on-black" && nvram set shellinabox_css=$shellinabox_css
shellinabox_options=`nvram get shellinabox_options`
shellinabox_wan=`nvram get shellinabox_wan`
A_restart=`nvram get shellinabox_status`
B_restart="$shellinabox_enable$shellinabox_port$shellinabox_css$shellinabox_options$shellinabox_wan"
B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
if [ "$A_restart" != "$B_restart" ] ; then
nvram set shellinabox_status=$B_restart
needed_restart=1
else
needed_restart=0
fi
if [ -n "`pidof shellinaboxd`" ] && [ "$shellinabox_enable" = "1" ] && [ "$shellinabox_wan" = "1" ] ; then
port=$(iptables -t filter -L INPUT -v -n --line-numbers | grep dpt:$shellinabox_port | cut -d " " -f 1 | sort -nr | wc -l)
if [ "$port" = 0 ] ; then
logger -t "【shellinabox】" "检测:找不到 ss-server 端口:$shellinabox_port 规则, 重新添加"
iptables -t filter -I INPUT -p tcp --dport $shellinabox_port -j ACCEPT &
fi
fi
if [ "$shellinabox_enable" = "0" ] && [ "$needed_restart" = "1" ] ; then
[ ! -z "`pidof shellinaboxd`" ] && logger -t "【shellinabox】" "停止 shellinabox" && /opt/etc/init.d/S88shellinaboxd stop
killall -9 shellinaboxd
fi
if [ "$shellinabox_enable" = "1" ] && [ "$needed_restart" = "1" ] ; then
killall -9 shellinaboxd
SVC_PATH="/opt/sbin/shellinaboxd"
hash shellinaboxd 2>/dev/null || m -rf /opt/sbin/shellinaboxd
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【shellinabox】" "自动安装 shellinabox 程序"
# 找不到 shellinabox,安装 opt
rm -rf /opt/opti.txt
if [ ! -f "/opt/opti.txt" ] ; then
ssfile=`nvram get ssfile`
ssfile2=`nvram get ssfile2`
upanPath=""
ss_opt_x=`nvram get ss_opt_x`
[ "$ss_opt_x" = "3" ] || [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}'| grep AiCard | sed -n '1p'`
[ -z $upanPath ] && [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
[ "$ss_opt_x" = "4" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
if [ ! -z $upanPath ] ; then
mkdir -p /media/$upanPath/opt
mount -o bind /media/$upanPath/opt /opt
ln -sf /media/$upanPath /tmp/AiDisk_00
/tmp/sh_installs.sh $ssfile 1
else
mkdir -p /tmp/AiDisk_00/opt
mount -o bind /tmp/AiDisk_00/opt /opt
/tmp/sh_installs.sh $ssfile2 2
fi
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【shellinabox】" "找不到 $SVC_PATH"
else
logger -t "【shellinabox】" "找到 $SVC_PATH"
fi
fi
hash shellinaboxd 2>/dev/null || { logger -t "【shellinabox】" "找不到 $SVC_PATH ,需要安装 opt 环境 opkg install shellinabox"; }
logger -t "【shellinabox】" "运行 $SVC_PATH"
killall -9 shellinaboxd
/opt/etc/init.d/S88shellinaboxd restart
sleep 5
[ ! -z "`pidof shellinaboxd`" ] && logger -t "【shellinabox】" "启动成功"
[ -z "`pidof shellinaboxd`" ] && logger -t "【shellinabox】" "启动失败, 注意检查端口是否有冲突, 10秒后自动尝试重新启动" && sleep 10 && nvram set shellinabox_status=00 && /tmp/sh_shellinabox.sh &
fi
EEF
chmod 777 "/tmp/sh_shellinabox.sh"
cat > "/tmp/sh_theme.sh" <<-\EEF
#!/bin/sh
export PATH='/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
theme_enable=`nvram get theme_enable`
[ -z $theme_enable ] && theme_enable=0 && nvram set theme_enable=$theme_enable
A_restart=`nvram get theme_status`
B_restart="$theme_enable"
#B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
B_restart=`echo -n "$B_restart"`
if [ "$A_restart" != "$B_restart" ] ; then
nvram set theme_status=$B_restart
needed_restart=1
else
needed_restart=0
fi
if [ "$theme_enable" = "0" ] && [ "$needed_restart" = "1" ] ; then
logger -t "【主题界面】" "停止下载主题包"
fi
if [ "$theme_enable" != "0" ] && [ "$needed_restart" = "1" ] ; then
SVC_PATH="/opt/share/www/custom/common-theme/css/main.css"
#rm -f $SVC_PATH
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【主题界面】" "部署主题风格包"
if [ ! -d "/opt/share/www/custom" ] ; then
upanPath=""
ss_opt_x=`nvram get ss_opt_x`
[ "$ss_opt_x" = "3" ] || [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}'| grep AiCard | sed -n '1p'`
[ -z $upanPath ] && [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
[ "$ss_opt_x" = "4" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
if [ ! -z $upanPath ] ; then
mkdir -p /media/$upanPath/opt
mount -o bind /media/$upanPath/opt /opt
ln -sf /media/$upanPath /tmp/AiDisk_00
else
mkdir -p /tmp/AiDisk_00/opt
mount -o bind /tmp/AiDisk_00/opt /opt
fi
mkdir -p /opt/share/www/custom
fi
rm -f $SVC_PATH
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【主题界面】" "主题风格包下载 $theme_enable"
rm -f /opt/share/www/custom/theme.tgz
[ "$theme_enable" = "1" ] && wget --continue --no-check-certificate -O /opt/share/www/custom/theme.tgz "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/theme-big.tgz"
[ "$theme_enable" = "2" ] && wget --continue --no-check-certificate -O /opt/share/www/custom/theme.tgz "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/theme-lit.tgz"
tar -xzvf /opt/share/www/custom/theme.tgz -C /opt/share/www/custom
if [ ! -s "$SVC_PATH" ] ; then
logger -t "【主题界面】" "解压不正常:/opt/share/www/custom"
nvram set theme_status=00
exit 1
fi
rm -f /opt/share/www/custom/theme.tgz
fi
fi
fi
EEF
chmod 777 "/tmp/sh_theme.sh"
cat > "/tmp/sh_lnmp.sh" <<-\EEF
#!/bin/sh
export PATH='/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
lnmp_enable=`nvram get lnmp_enable`
[ -z $lnmp_enable ] && lnmp_enable=0 && nvram set lnmp_enable=$lnmp_enable
default_enable=`nvram get default_enable`
[ -z $default_enable ] && default_enable=0 && nvram set default_enable=$default_enable
default_port=`nvram get default_port`
[ -z $default_port ] && default_port=81 && nvram set default_port=$default_port
kodexplorer_enable=`nvram get kodexplorer_enable`
[ -z $kodexplorer_enable ] && kodexplorer_enable=0 && nvram set kodexplorer_enable=$kodexplorer_enable
kodexplorer_port=`nvram get kodexplorer_port`
[ -z $kodexplorer_port ] && kodexplorer_port=82 && nvram set kodexplorer_port=$kodexplorer_port
phpmyadmin_enable=`nvram get phpmyadmin_enable`
[ -z $phpmyadmin_enable ] && phpmyadmin_enable=0 && nvram set phpmyadmin_enable=$phpmyadmin_enable
phpmyadmin_port=`nvram get phpmyadmin_port`
[ -z $phpmyadmin_port ] && phpmyadmin_port=85 && nvram set phpmyadmin_port=$phpmyadmin_port
wifidog_server_enable=`nvram get wifidog_server_enable`
[ -z $wifidog_server_enable ] && wifidog_server_enable=0 && nvram set wifidog_server_enable=$wifidog_server_enable
wifidog_server_port=`nvram get wifidog_server_port`
[ -z $wifidog_server_port ] && wifidog_server_port=84 && nvram set wifidog_server_port=$wifidog_server_port
owncloud_enable=`nvram get owncloud_enable`
[ -z $owncloud_enable ] && owncloud_enable=0 && nvram set owncloud_enable=$owncloud_enable
owncloud_port=`nvram get owncloud_port`
[ -z $owncloud_port ] && owncloud_port=83 && nvram set owncloud_port=$owncloud_port
mysql_enable=`nvram get mysql_enable`
http_username=`nvram get http_username`
A_restart=`nvram get lnmp_status`
B_restart="$http_username$lnmp_enable$mysql_enable$default_enable$kodexplorer_enable$owncloud_enable$phpmyadmin_enable$wifidog_server_enable$default_port$kodexplorer_port$owncloud_port$phpmyadmin_port$wifidog_server_port"
B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
if [ "$A_restart" != "$B_restart" ] ; then
nvram set lnmp_status=$B_restart
needed_restart=1
else
needed_restart=0
fi
if [ "$lnmp_enable" = "0" ] && [ "$needed_restart" = "1" ] ; then
[ ! -z "`pidof nginx`" ] && logger -t "【LNMP】" "停止 nginx+php+mysql 环境"
/opt/etc/init.d/S70mysqld stop
/opt/etc/init.d/S79php-fpm stop
/opt/etc/init.d/S80nginx stop
killall spawn-fcgi nginx php-cgi mysqld
fi
if [ "$lnmp_enable" = "1" ] && [ "$needed_restart" = "1" ] ; then
/opt/etc/init.d/S70mysqld stop
/opt/etc/init.d/S79php-fpm stop
/opt/etc/init.d/S80nginx stop
killall spawn-fcgi nginx php-cgi mysqld
logger -t "【LNMP】" "/opt 已用数据空间`df -m|grep "% /opt" | awk ' {print $5F}'`/100%"
logger -t "【LNMP】" "/opt 已用节点空间`df -i|grep "% /opt" | awk ' {print $5F}'`/100%"
logger -t "【LNMP】" "以上两个数据如出现占用100%时,则opt空间或Inodes爆满,会影响LNMP运行,请重新正确格式化U盘。"
SVC_PATH="/opt/lnmp.txt"
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【LNMP】" "自动安装 nginx+php+mysql 环境"
# 找不到【LNMP】,安装 opt
if [ ! -d "/opt/bin" ] ; then
upanPath=""
ss_opt_x=`nvram get ss_opt_x`
[ "$ss_opt_x" = "3" ] || [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}'| grep AiCard | sed -n '1p'`
[ -z $upanPath ] && [ "$ss_opt_x" = "1" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
[ "$ss_opt_x" = "4" ] && upanPath=`ls -l /media/ | awk '/^d/ {print $NF}' | grep -v AiCard | sed -n '1p'`
if [ ! -z $upanPath ] ; then
mkdir -p /media/$upanPath/opt
mount -o bind /media/$upanPath/opt /opt
ln -sf /media/$upanPath /tmp/AiDisk_00
else
mkdir -p /tmp/AiDisk_00/opt
mount -o bind /tmp/AiDisk_00/opt /opt
fi
mkdir -p /opt/bin
fi
optava=`df -m|grep "% /opt" | awk ' {print $4F}'`
if [ $optava -le 300 ] || [ -z "$optava" ] ; then
logger -t "【LNMP】" "/opt剩余空间: $optava M,不足300M, 停止启用 LNMP, 请尝试重启"
lnmp_enable=0 && nvram set lnmp_enable=$lnmp_enable
nvram set lnmp_status=$optava
nvram commit
exit 1
fi
touch /opt/testchmod
chmod 644 /opt/testchmod
optava=`ls /opt -al | grep testchmod| grep 'rw-r--r--'`
if [ -z "$optava" ] ; then
logger -t "【LNMP】" "/opt 修改文件权限失败, 停止启用 LNMP"
logger -t "【LNMP】" "注意: U 盘格式不支持 FAT32, 请格式化 U 盘, 要用 EXT4 或 NTFS 格式。"
lnmp_enable=0 && nvram set lnmp_enable=$lnmp_enable
nvram commit
exit 1
fi
if [ ! -f "$SVC_PATH" ] ; then
logger -t "【LNMP】" "找不到 $SVC_PATH 下载 /opt/opt-lnmp.tgz,需时3分钟"
lnmpfile=`nvram get lnmpfile`
logger -t "【LNMP】" "下载地址:$lnmpfile"
rm -rf /opt/opt-lnmp.tgz
wget --continue --no-check-certificate -O /opt/opt-lnmp.tgz "$lnmpfile"
logger -t "【LNMP】" "下载 /opt/opt-lnmp.tgz 完成. 解压文档, 需时5分钟。。。"
tar -xzvf /opt/opt-lnmp.tgz -C /opt/
if [ ! -s "$SVC_PATH" ] ; then
logger -t "【LNMP】" "解压不正常:$SVC_PATH"
logger -t "【LNMP】" "启动失败, 10秒后自动尝试重新启动" && sleep 10
rm -f /opt/lnmp.txt
killall spawn-fcgi nginx php-cgi mysqld
nvram set lnmp_status=00
nvram commit
/tmp/sh_lnmp.sh &
exit 1
else
logger -t "【LNMP】" "解压完成."
fi
else
logger -t "【LNMP】" "找到 $SVC_PATH"
fi
fi
chmod -R 777 /opt/bin/
chmod -R 777 /opt/lib/
if [ -f "/opt/etc/init.d/S69pdcnlnmpinit" ] ; then
sed -e 's/.*nvram get lnmp_enable.*/lnmp_enable=`nvram get lnmp_enable` \&\& default_port=`nvram get default_port` /g' -i /opt/etc/init.d/S69pdcnlnmpinit
fi
logger -t "【LNMP】" "运行 nginx+php+mysql 环境"
if [ "$mysql_enable" = "4" ] || [ ! -d "/opt/mysql/test" ] ; then
logger -t "【LNMP】" "重置 /opt/mysql 数据"
killall mysqld
rm -rf /opt/mysql/*
sed -e "s/.*user.*/user = "$http_username"/g" -i /opt/etc/my.cnf
chmod 644 /opt/etc/my.cnf
mkdir -p /opt/mysql/
/opt/bin/mysql_install_db
/opt/bin/mysqld &
sleep 2
logger -t "【LNMP】" "重置 mysql 默认账号:root, 默认密码:admin, 请手动修改密码"
/opt/bin/mysqladmin -u root password admin
killall mysqld
mysql_enable=0 && nvram set mysql_enable=$mysql_enable
nvram commit
fi
if [ "$default_enable" = "4" ] ; then
logger -t "【LNMP】" "重置 默认主页 数据."
rm -rf /opt/www/default
logger -t "【LNMP】" "重置 默认主页 数据完成。"
default_enable=0 && nvram set default_enable=$default_enable
nvram commit
fi
if [ "$kodexplorer_enable" = "4" ] ; then
logger -t "【LNMP】" "重置 KodExplorer 芒果云 数据."
rm -rf /opt/www/kodexplorer
logger -t "【LNMP】" "重置 KodExplorer 芒果云 数据完成."
kodexplorer_enable=0 && nvram set kodexplorer_enable=$kodexplorer_enable
nvram commit
fi
if [ "$owncloud_enable" = "4" ] ; then
logger -t "【LNMP】" "重置 OwnCloud 私有云 数据."
rm -rf /opt/www/owncloud
logger -t "【LNMP】" "重置 OwnCloud 私有云 数据完成."
owncloud_enable=0 && nvram set owncloud_enable=$owncloud_enable
nvram commit
fi
if [ "$phpmyadmin_enable" = "4" ] ; then
logger -t "【LNMP】" "重置 phpMyAdmin 数据."
rm -rf /opt/www/phpmyadmin
logger -t "【LNMP】" "重置 phpMyAdmin 数据完成."
phpmyadmin_enable=0 && nvram set phpmyadmin_enable=$phpmyadmin_enable
nvram commit
fi
if [ "$wifidog_server_enable" = "4" ] ; then
logger -t "【LNMP】" "重置 wifidog_server 数据."
rm -rf /opt/www/wifidog_server
logger -t "【LNMP】" "重置 wifidog_server 数据完成."
wifidog_server_enable=0 && nvram set wifidog_server_enable=$wifidog_server_enable
nvram commit
fi
B_restart="$http_username$lnmp_enable$mysql_enable$default_enable$kodexplorer_enable$owncloud_enable$phpmyadmin_enable$wifidog_server_enable$default_port$kodexplorer_port$owncloud_port$phpmyadmin_port$wifidog_server_port"
B_restart=`echo -n "$B_restart" | md5sum | sed s/[[:space:]]//g | sed s/-//g`
nvram set lnmp_status=$B_restart
if [ "$lnmp_enable" = "1" ] ; then
if [ "$default_enable" = "1" ] || [ "$default_enable" = "2" ] ; then
if [ ! -d "/opt/www/default" ] ; then
mkdir -p /opt/www/default
cp -rf /opt/etc/nginx/xhost/default.conf /opt/etc/nginx/vhost/default.conf
if [ ! -f "/opt/www/default/tz.php" ] ; then
logger -t "【LNMP】" "找不到 tz.php, 下载程序文档, 需时1秒"
logger -t "【LNMP】" "下载地址:https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/tz.php"
wget --continue --no-check-certificate -O /opt/www/default/tz.php "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/tz.php"
fi
fi
if [ ! -d "/opt/www/default" ] ; then
logger -t "【LNMP】" "默认主页 停用, 因未找到 /opt/www/default"
fi
fi
if [ "$kodexplorer_enable" = "1" ] || [ "$kodexplorer_enable" = "2" ] ; then
if [ ! -d "/opt/www/kodexplorer/data" ] ; then
if [ ! -f "/opt/www/kodexplorer.tgz" ] ; then
logger -t "【LNMP】" "找不到 kodexplorer.tgz, 下载程序文档, 需时2分钟"
lnmpfile3=`nvram get lnmpfile3`
logger -t "【LNMP】" "下载地址:$lnmpfile3"
wget --continue --no-check-certificate -O /opt/www/kodexplorer.tgz "$lnmpfile3"
fi
logger -t "【LNMP】" "解压 kodexplorer 文档, 需时1分钟"
tar -xzvf /opt/www/kodexplorer.tgz -C /opt/www
fi
if [ ! -d "/opt/www/kodexplorer/data" ] ; then
logger -t "【LNMP】" "芒果云 停用, 因未找到 /opt/www/kodexplorer/data"
else
sed -e "s/.*upload_chunk_size.*/ \'upload_chunk_size\' => 1024*1024*1, \/\/上传分片大小;默认1M/g" -i /opt/www/kodexplorer/config/setting.php
chmod -R 777 /opt/www/kodexplorer/
fi
fi
if [ "$phpmyadmin_enable" = "1" ] || [ "$phpmyadmin_enable" = "2" ] ; then
if [ ! -d "/opt/www/phpmyadmin/libraries" ] ; then
if [ ! -f "/opt/www/phpmyadmin.tgz" ] ; then
logger -t "【LNMP】" "找不到 phpmyadmin.tgz, 下载程序文档, 需时2分钟"
lnmpfile4=`nvram get lnmpfile4`
logger -t "【LNMP】" "下载地址:$lnmpfile4"
wget --continue --no-check-certificate -O /opt/www/phpmyadmin.tgz "$lnmpfile4"
fi
logger -t "【LNMP】" "解压 phpmyadmin 文档, 需时1分钟"
tar -xzvf /opt/www/phpmyadmin.tgz -C /opt/www
fi
if [ ! -d "/opt/www/phpmyadmin/libraries" ] ; then
logger -t "【LNMP】" "phpmyadmin 停用, 因未找到 /opt/www/phpmyadmin/libraries"
else
chmod 644 /opt/www/phpmyadmin/config.inc.php
fi
fi
rm -rf /opt/etc/nginx/vhost/wifidog_server.conf
if [ "$wifidog_server_enable" = "1" ] || [ "$wifidog_server_enable" = "2" ] ; then
if [ ! -d "/opt/www/wifidog_server/auth" ] ; then
if [ ! -f "/opt/www/wifidog_server.tgz" ] ; then
logger -t "【LNMP】" "找不到 wifidog_server.tgz, 下载程序文档"
lnmpfile6=`nvram get lnmpfile6`
logger -t "【LNMP】" "下载地址:$lnmpfile6"
wget --continue --no-check-certificate -O /opt/www/wifidog_server.tgz "$lnmpfile6"
fi
logger -t "【LNMP】" "解压 wifidog_server 文档"
tar -xzvf /opt/www/wifidog_server.tgz -C /opt/www
fi
if [ ! -d "/opt/www/wifidog_server/auth" ] ; then
logger -t "【LNMP】" "wifidog_server 停用, 因未找到 /opt/www/wifidog_server/auth"
else
chmod -R 777 /opt/www/wifidog_server/
[ ! -f "/opt/etc/nginx/xhost/wifidog_server.conf" ] && wget --continue --no-check-certificate -O /opt/etc/nginx/xhost/wifidog_server.conf "https://code.aliyun.com/hiboyhiboy/padavan-opt/raw/master/wifidog_server.conf"
cp -rf /opt/etc/nginx/xhost/wifidog_server.conf /opt/etc/nginx/vhost/wifidog_server.conf
logger -t "【LNMP】" "wifidog_server 路径:/opt/www/wifidog_server 端口:$wifidog_server_port"
sed -e "s/.*访问端口4.*/ listen "$wifidog_server_port"; "' # 访问端口4/g' -i /opt/etc/nginx/vhost/wifidog_server.conf
sed -e "s/.*output_buffering.*/output_buffering = On/g" -i /opt/etc/php.ini
sed -e "s/.*session\.auto_start.*/session\.auto_start = 1/g" -i /opt/etc/php.ini
logger -t "【LNMP】" "wifidog_server:`nvram get lan_ipaddr`:"$wifidog_server_port
fi
fi
if [ "$owncloud_enable" = "1" ] || [ "$owncloud_enable" = "2" ] ; then
if [ ! -d "/opt/www/owncloud/config" ] ; then
if [ ! -f "/opt/www/owncloud-8.0.14.tar.bz2" ] ; then
logger -t "【LNMP】" "找不到 owncloud-8.0.14.tar.bz2, 下载程序文档, 需时3分钟"
lnmpfile5=`nvram get lnmpfile5`
logger -t "【LNMP】" "下载地址:$lnmpfile5"