summaryrefslogtreecommitdiff
path: root/public/fs/etc/openvpn/hostvpn-conf.sh
blob: 72f828c5c4e33286d6f615322ec6606d39ab1f85 (plain)
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
#!/bin/sh

set -eu

sitezone="$1"
vpn_type="$2"

cfg_script="$0"
cfg_srcdir=$(cd -- "${cfg_script%/*}/" ; pwd -P)

source /root/config/private/config/server.ports
source /root/config/private/config/hostinfo/${sitezone}

if [ ${vpn_type} = 'primary' ]; then
	vpn_tunnel=tun0
	ipv6_subnet=8000

	if [ ${vpn_route_all} = 'yes' ]; then
		vpn_route_all_subst='s/^@vpn_route_all@ //g'
	else
		vpn_route_all_subst='/^@vpn_route_all@ /d'
	fi

	sed -e 's/@vpn_tunnel@/'${vpn_tunnel}'/g' \
		-e 's/@vpn_type@/'${vpn_type}'/g'  \
		-e 's/@vpn_port@/'${vpn_port}'/g'   \
		-e 's/@hostname@/'${hostname}'/g'    \
		-e 's/@vpn_net4@/'${vpn_net4}'/g'     \
		-e 's/@vpn_ipv4@/'${vpn_ipv4}'/g'      \
		-e 's/@host_ipv4@/'${host_ipv4}'/g'     \
		-e 's/@host_ipv6@/'${host_ipv6}'/g'      \
		-e 's/@ipv6_subnet@/'${ipv6_subnet}'/g'   \
		-e "${vpn_route_all_subst}"                \
		"${cfg_srcdir}/hostvpn.conf.in"

elif [ ${vpn_type} = 'secondary' ]; then
	vpn_tunnel=tun1
	ipv6_subnet=c000

	if [ ${avpn_route_all} = 'yes' ]; then
		vpn_route_all_subst='s/^@vpn_route_all@ //g'
	else
		vpn_route_all_subst='/^@vpn_route_all@ /d'
	fi

	sed -e 's/@vpn_tunnel@/'${vpn_tunnel}'/g' \
		-e 's/@vpn_type@/'${vpn_type}'/g'  \
		-e 's/@vpn_port@/'${avpn_port}'/g'  \
		-e 's/@hostname@/'${hostname}'/g'    \
		-e 's/@vpn_net4@/'${avpn_net4}'/g'    \
		-e 's/@vpn_ipv4@/'${avpn_ipv4}'/g'     \
		-e 's/@host_ipv4@/'${host_ipv4}'/g'     \
		-e 's/@host_ipv6@/'${host_ipv6}'/g'      \
		-e 's/@ipv6_subnet@/'${ipv6_subnet}'/g'   \
		-e "${vpn_route_all_subst}"                \
		"${cfg_srcdir}/hostvpn.conf.in"

else
	printf '%s\n' 'usage: ./hostvpn-conf.sh sitezone {primary|secondary}'
	exit 2
fi