-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmtd_storage.sh
executable file
·792 lines (655 loc) · 17.5 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
#!/bin/sh
result=0
mtd_part_name="Storage"
mtd_part_dev="/dev/mtdblock5"
mtd_part_size=65536
dir_storage="/etc/storage"
slk="/tmp/.storage_locked"
tmp="/tmp/storage.tar"
tbz="${tmp}.bz2"
hsh="/tmp/hashes/storage_md5"
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" "无法找到 MTD 分区: $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" "MTD 分区中的存储数据无效: $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" "无法创建 tarball 文件: $tmp"
exit 1
fi
}
func_save()
{
local fsz
logger -t "Storage save" "将存储文件保存到 MTD 分区 \"$mtd_part_dev\""
echo "将存储文件保存到 MTD 分区 \"$mtd_part_dev\""
rm -f $tbz
md5sum -c -s $hsh 2>/dev/null
if [ $? -eq 0 ] ; then
echo "存储哈希未更改,跳过写入 MTD 分区。退出。"
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 "完成."
logger -t "Storage save" "完成."
else
result=1
echo "错误!MTD 写入失败。"
logger -t "Storage save" "错误!MTD 写入失败。: $mtd_part_dev"
fi
else
result=1
echo "错误!无效的存储最终数据大小: $fsz"
logger -t "Storage save" "无效的存储最终数据大小: $fsz"
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" "无法创建 BZ2 文件!"
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" "无效的 BZ2 文件大小: $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" "无法解压 BZ2 文件: $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" "BZ2 文件内容无效: $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_fill()
{
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"
dir_chnroute="$dir_storage/chinadns"
#dir_gfwlist="$dir_storage/gfwlist"
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"
script_gipv6="$dir_storage/getipv6.sh"
script_ipv6="$dir_storage/ipv6.sh"
user_hosts="$dir_dnsmasq/hosts"
user_dnsmasq_conf="$dir_dnsmasq/dnsmasq.conf"
user_dhcp_conf="$dir_dnsmasq/dhcp.conf"
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"
chnroute_file="/etc_ro/chnroute.bz2"
#gfwlist_conf_file="/etc_ro/gfwlist.bz2"
# 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 chnroute.txt
if [ ! -d "$dir_chnroute" ] ; then
if [ -f "$chnroute_file" ]; then
mkdir -p "$dir_chnroute" && tar jxf "$chnroute_file" -C "$dir_chnroute"
fi
fi
# create gfwlist
#if [ ! -d "$dir_gfwlist" ] ; then
# if [ -f "$gfwlist_conf_file" ]; then
# mkdir -p "$dir_gfwlist" && tar jxf "$gfwlist_conf_file" -C "$dir_gfwlist"
# fi
#fi
# create start script
if [ ! -f "$script_start" ] ; then
reset_ss.sh -a
fi
# create started script
if [ ! -f "$script_started" ] ; then
cat > "$script_started" <<'EOF'
#!/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
echo 4096 131072 6291456 > /proc/sys/net/ipv4/tcp_rmem
echo 4194304 >/proc/sys/net/core/rmem_max
echo 212992 > /proc/sys/net/core/rmem_default
#drop caches
sync && echo 3 > /proc/sys/vm/drop_caches
# Roaming assistant for mt76xx WiFi
#iwpriv ra0 set KickStaRssiLow=-85
#iwpriv ra0 set AssocReqRssiThres=-80
#iwpriv rai0 set KickStaRssiLow=-85
#iwpriv rai0 set AssocReqRssiThres=-80
# Mount SATA disk
#mdev -s
#wing <HOST:443> <PASS>
#wing 192.168.1.9:1080
#ipset add gfwlist 8.8.4.4
#**************github下载加速******************
#建议自建加速,项目:https://github.com/hunshcn/gh-proxy
#设置github加速下载镜像代理地址,失效请自行更换(按下方格式填写,每行一个,末尾加/)
nvram set github_proxy="https://github.moeyy.xyz/
https://gh.llkk.cc/
https://mirror.ghproxy.com/
https://ghproxy.net/
"
#*************github下载加速******************
#**************替换背景图片******************
#上传图片命名为wood.jpg到/etc/storage/bg/目录里
#路径必须为:/etc/storage/bg/wood.jpg 去掉下方代码前面的# 表示启用更换背景
#mount --bind /etc/storage/bg /www/bootstrap/img/bg
#**************替换背景图片*******************
EOF
chmod 755 "$script_started"
fi
# create shutdown script
if [ ! -f "$script_shutd" ] ; then
cat > "$script_shutd" <<EOF
#!/bin/sh
### Custom user script
### Called before router shutdown
### \$1 - action (0: reboot, 1: halt, 2: power-off)
EOF
chmod 755 "$script_shutd"
fi
# create post-iptables script
if [ ! -f "$script_postf" ] ; then
cat > "$script_postf" <<EOF
#!/bin/sh
### Custom user script
### Called after internal iptables reconfig (firewall update)
#wing resume
#自动配置 POSTROUTING 的 MSS钳制,防止网络堵塞和数据丢失
iptables -t mangle -A POSTROUTING ! -o br0 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
ip6tables -t mangle -A POSTROUTING ! -o br0 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
# 手动指定MSS
#iptables -t mangle -A POSTROUTING ! -o br0 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1452
#ip6tables -t mangle -A POSTROUTING ! -o br0 -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1432
### ipv6防火墙全关规则 以下把#去掉则关闭ip6防火墙
#ip6tables -F
#ip6tables -X
#ip6tables -P INPUT ACCEPT
#ip6tables -P OUTPUT ACCEPT
#ip6tables -P FORWARD ACCEPT
### ipv6防火墙单独规则 开放3389远程桌面 其它端口按下方规则添加 以下把#去掉则生效
#ip6tables -I FORWARD -p tcp --dport 3389 -j ACCEPT
#ip6tables -I FORWARD -p tcp --dport 8829 -j ACCEPT
EOF
chmod 755 "$script_postf"
fi
# create gipv6 script
if [ ! -f "$script_gipv6" ] ; then
cat > "$script_gipv6" <<EOF
#!/bin/sh
### Custom user script
### getipv6
#wing resume
hostipv6=\`ip -6 neighbor show | grep -i \$1 | sed -n 's/.dev* \([0-9a-f:]\+\).*/\2/p' | grep -v fe80:: |tail -n 1\`
echo \${hostipv6}
EOF
chmod 755 "$script_gipv6"
fi
# create ipv6 script
if [ ! -f "$script_ipv6" ] ; then
cat > "$script_ipv6" <<EOF
#!/bin/sh
### Custom user script
### showipv6
#wing resume
cat /tmp/static_ip.inf | grep -v "^$" | awk -F "," ' { sh "/etc/storage/getipv6.sh " \$2 |getline result;if ( \$6 == 0 ) print \$1,result ","\$2","\$3","\$4","\$5","\$6} ' > /tmp/static_ipv6.inf
EOF
chmod 755 "$script_ipv6"
fi
# create post-wan script
if [ ! -f "$script_postw" ] ; then
cat > "$script_postw" <<EOF
#!/bin/sh
#mtk_gpio -d 6 0
### Called after internal WAN up/down action
### \$1 - WAN action (up/down)
### \$2 - WAN interface name (e.g. eth3 or ppp0)
### \$3 - WAN IPv4 address
EOF
chmod 755 "$script_postw"
fi
# create inet-state script
if [ ! -f "$script_inets" ] ; then
cat > "$script_inets" <<EOF
#!/bin/sh
### Custom user script
### Called on Internet status changed
### \$1 - Internet status (0/1)
### \$2 - elapsed time (s) from previous state
logger -t "di" "Internet state: \$1, elapsed time: \$2s."
EOF
chmod 755 "$script_inets"
fi
# create vpn server action script
if [ ! -f "$script_vpnsc" ] ; then
cat > "$script_vpnsc" <<EOF
#!/bin/sh
### Custom user script
### Called after remote peer connected/disconnected to internal VPN server
### \$1 - peer action (up/down)
### \$2 - peer interface name (e.g. ppp10)
### \$3 - peer local IP address
### \$4 - peer remote IP address
### \$5 - peer name
peer_if="\$2"
peer_ip="\$4"
peer_name="\$5"
### example: add static route to private LAN subnet behind a remote peer
func_ipup()
{
# if [ "\$peer_name" == "dmitry" ] ; then
# route add -net 192.168.5.0 netmask 255.255.255.0 dev \$peer_if
# elif [ "\$peer_name" == "victoria" ] ; then
# route add -net 192.168.8.0 netmask 255.255.255.0 dev \$peer_if
# fi
return 0
}
func_ipdown()
{
# if [ "\$peer_name" == "dmitry" ] ; then
# route del -net 192.168.5.0 netmask 255.255.255.0 dev \$peer_if
# elif [ "\$peer_name" == "victoria" ] ; then
# route del -net 192.168.8.0 netmask 255.255.255.0 dev \$peer_if
# fi
return 0
}
case "\$1" in
up)
func_ipup
;;
down)
func_ipdown
;;
esac
EOF
chmod 755 "$script_vpnsc"
fi
# create vpn client action script
if [ ! -f "$script_vpncs" ] ; then
cat > "$script_vpncs" <<EOF
#!/bin/sh
### Custom user script
### Called after internal VPN client connected/disconnected to remote VPN server
### \$1 - action (up/down)
### \$IFNAME - tunnel interface name (e.g. ppp5 or tun0)
### \$IPLOCAL - tunnel local IP address
### \$IPREMOTE - tunnel remote IP address
### \$DNS1 - peer DNS1
### \$DNS2 - peer DNS2
# private LAN subnet behind a remote server (example)
peer_lan="192.168.9.0"
peer_msk="255.255.255.0"
### example: add static route to private LAN subnet behind a remote server
func_ipup()
{
# route add -net \$peer_lan netmask \$peer_msk gw \$IPREMOTE dev \$IFNAME
return 0
}
func_ipdown()
{
# route del -net \$peer_lan netmask \$peer_msk gw \$IPREMOTE dev \$IFNAME
return 0
}
logger -t vpnc-script "\$IFNAME \$1"
case "\$1" in
up)
func_ipup
;;
down)
func_ipdown
;;
esac
EOF
chmod 755 "$script_vpncs"
fi
# create Ez-Buttons script
if [ ! -f "$script_ezbtn" ] ; then
cat > "$script_ezbtn" <<EOF
#!/bin/sh
### Custom user script
### Called on WPS or FN button pressed
### \$1 - button param
[ -x /opt/bin/on_wps.sh ] && /opt/bin/on_wps.sh \$1 &
EOF
chmod 755 "$script_ezbtn"
fi
# create user dnsmasq.conf
[ ! -d "$dir_dnsmasq" ] && mkdir -p -m 755 "$dir_dnsmasq"
for i in dnsmasq.conf hosts ; do
[ -f "$dir_storage/$i" ] && mv -n "$dir_storage/$i" "$dir_dnsmasq"
done
if [ ! -f "$user_dnsmasq_conf" ] ; then
cat > "$user_dnsmasq_conf" <<EOF
# Custom user conf file for dnsmasq
# Please add needed params only!
### Web Proxy Automatic Discovery (WPAD)
dhcp-option=252,"\n"
### Set the limit on DHCP leases, the default is 150
#dhcp-lease-max=150
### Add local-only domains, queries are answered from hosts or DHCP only
#local=/router/localdomain/
### Examples:
### Enable built-in TFTP server
#enable-tftp
### Set the root directory for files available via TFTP.
#tftp-root=/opt/srv/tftp
### Make the TFTP server more secure
#tftp-secure
### Set the boot filename for netboot/PXE
#dhcp-boot=pxelinux.0
### Log for all queries
#log-queries
### Keep DHCP host name valid at any times
#dhcp-to-host
EOF
if [ -f /usr/bin/vlmcsd ]; then
cat >> "$user_dnsmasq_conf" <<EOF
### vlmcsd related
srv-host=_vlmcs._tcp,my.router,1688,0,100
EOF
fi
if [ -f /usr/bin/wing ]; then
cat >> "$user_dnsmasq_conf" <<EOF
# Custom domains to gfwlist
#gfwlist=mit.edu
#gfwlist=openwrt.org,lede-project.org
#gfwlist=github.com,github.io,githubusercontent.com
EOF
fi
if [ -d $dir_gfwlist ]; then
cat >> "$user_dnsmasq_conf" <<EOF
### gfwlist related (resolve by port 5353)
#min-cache-ttl=3600
#conf-dir=/etc/storage/gfwlist
EOF
fi
chmod 644 "$user_dnsmasq_conf"
fi
# create user dns servers
if [ ! -f "$user_dhcp_conf" ] ; then
cat > "$user_dhcp_conf" <<EOF
#6C:96:CF:E0:95:55,192.168.1.10,iMac
EOF
chmod 644 "$user_dhcp_conf"
fi
# create user inadyn.conf"
[ ! -d "$dir_inadyn" ] && mkdir -p -m 755 "$dir_inadyn"
if [ ! -f "$user_inadyn_conf" ] ; then
cat > "$user_inadyn_conf" <<EOF
# Custom user conf file for inadyn DDNS client
# Please add only new custom system!
### Example for twoDNS.de:
#system custom@http_srv_basic_auth
# ssl
# checkip-url checkip.two-dns.de /
# server-name update.twodns.de
# server-url /update\?hostname=
# username account
# password secret
# alias example.dd-dns.de
EOF
chmod 644 "$user_inadyn_conf"
fi
# create user hosts
if [ ! -f "$user_hosts" ] ; then
cat > "$user_hosts" <<EOF
# Custom user hosts file
# Example:
# 192.168.1.100 Boo
EOF
chmod 644 "$user_hosts"
fi
# create user AP confs
[ ! -d "$dir_wlan" ] && mkdir -p -m 755 "$dir_wlan"
if [ ! -f "$dir_wlan/AP.dat" ] ; then
cat > "$dir_wlan/AP.dat" <<EOF
# Custom user AP conf file
EOF
chmod 644 "$dir_wlan/AP.dat"
fi
if [ ! -f "$dir_wlan/AP_5G.dat" ] ; then
cat > "$dir_wlan/AP_5G.dat" <<EOF
# Custom user AP conf file
EOF
chmod 644 "$dir_wlan/AP_5G.dat"
fi
# create openvpn files
if [ -x /usr/sbin/openvpn ] ; then
[ ! -d "$dir_ovpncli" ] && mkdir -p -m 700 "$dir_ovpncli"
[ ! -d "$dir_ovpnsvr" ] && mkdir -p -m 700 "$dir_ovpnsvr"
dir_ovpn="$dir_storage/openvpn"
for i in ca.crt dh1024.pem server.crt server.key server.conf ta.key ; do
[ -f "$dir_ovpn/$i" ] && mv -n "$dir_ovpn/$i" "$dir_ovpnsvr"
done
if [ ! -f "$user_ovpnsvr_conf" ] ; then
cat > "$user_ovpnsvr_conf" <<EOF
# Custom user conf file for OpenVPN server
# Please add needed params only!
### Max clients limit
max-clients 10
### Internally route client-to-client traffic
client-to-client
### Allow clients with duplicate "Common Name"
;duplicate-cn
### Legacy LZO adaptive compression
;comp-lzo adaptive
;push "comp-lzo adaptive"
### Keepalive and timeout
keepalive 10 60
### Process priority level (0..19)
nice 3
### Syslog verbose level
verb 0
mute 10
EOF
chmod 644 "$user_ovpnsvr_conf"
fi
if [ ! -f "$user_ovpncli_conf" ] ; then
cat > "$user_ovpncli_conf" <<EOF
# Custom user conf file for OpenVPN client
# Please add needed params only!
### If your server certificates with the nsCertType field set to "server"
remote-cert-tls server
### Process priority level (0..19)
nice 0
### Syslog verbose level
verb 0
mute 10
EOF
chmod 644 "$user_ovpncli_conf"
fi
fi
# create strongswan files
if [ -x /usr/sbin/ipsec ] ; then
[ ! -d "$dir_sswan" ] && mkdir -p -m 700 "$dir_sswan"
[ ! -d "$dir_sswan_crt" ] && mkdir -p -m 700 "$dir_sswan_crt"
[ ! -d "$dir_sswan_crt/cacerts" ] && mkdir -p -m 700 "$dir_sswan_crt/cacerts"
[ ! -d "$dir_sswan_crt/certs" ] && mkdir -p -m 700 "$dir_sswan_crt/certs"
[ ! -d "$dir_sswan_crt/private" ] && mkdir -p -m 700 "$dir_sswan_crt/private"
if [ ! -f "$user_sswan_conf" ] ; then
cat > "$user_sswan_conf" <<EOF
### strongswan.conf - user strongswan configuration file
EOF
chmod 644 "$user_sswan_conf"
fi
if [ ! -f "$user_sswan_ipsec_conf" ] ; then
cat > "$user_sswan_ipsec_conf" <<EOF
### ipsec.conf - user strongswan IPsec configuration file
EOF
chmod 644 "$user_sswan_ipsec_conf"
fi
if [ ! -f "$user_sswan_secrets" ] ; then
cat > "$user_sswan_secrets" <<EOF
### ipsec.secrets - user strongswan IPsec secrets file
EOF
chmod 644 "$user_sswan_secrets"
fi
fi
}
case "$1" in
load)
func_get_mtd
func_mdir
func_load
;;
save)
[ -f "$slk" ] && exit 1
func_get_mtd
func_mdir
func_tarb
func_save
;;
backup)
func_mdir
func_tarb
func_backup
;;
restore)
func_get_mtd
func_restore
;;
erase)
func_get_mtd
func_erase
;;
reset)
func_stop_apps
func_reset
func_fill
func_start_apps
;;
fill)
func_mdir
func_fill
;;
*)
echo "Usage: $0 {load|save|backup|restore|erase|reset|fill}"
exit 1
;;
esac
exit $result