summaryrefslogtreecommitdiff
path: root/public/fs/etc/openvpn/hostvpn-conf.sh
diff options
context:
space:
mode:
authorroot@culturestrings <root@culturestrings>2020-09-01 18:44:10 +0000
committerroot@culturestrings <root@culturestrings>2020-09-01 19:17:13 +0000
commitc2ee4ced281a9fbfd36e5e930f935a0c240812b2 (patch)
tree88c0e5f4dc1436400a3930726e770cab68a97290 /public/fs/etc/openvpn/hostvpn-conf.sh
parentc63e1b6d9bc66dc579e888a393fd5072f2c743a8 (diff)
downloadculturestrings-c2ee4ced281a9fbfd36e5e930f935a0c240812b2.tar.bz2
culturestrings-c2ee4ced281a9fbfd36e5e930f935a0c240812b2.tar.xz
openvpn: support two distinct (masquerading and non-masquerading) vpn's.
Diffstat (limited to 'public/fs/etc/openvpn/hostvpn-conf.sh')
-rwxr-xr-xpublic/fs/etc/openvpn/hostvpn-conf.sh59
1 files changed, 47 insertions, 12 deletions
diff --git a/public/fs/etc/openvpn/hostvpn-conf.sh b/public/fs/etc/openvpn/hostvpn-conf.sh
index 24cb390..72f828c 100755
--- a/public/fs/etc/openvpn/hostvpn-conf.sh
+++ b/public/fs/etc/openvpn/hostvpn-conf.sh
@@ -3,6 +3,7 @@
set -eu
sitezone="$1"
+vpn_type="$2"
cfg_script="$0"
cfg_srcdir=$(cd -- "${cfg_script%/*}/" ; pwd -P)
@@ -10,17 +11,51 @@ cfg_srcdir=$(cd -- "${cfg_script%/*}/" ; pwd -P)
source /root/config/private/config/server.ports
source /root/config/private/config/hostinfo/${sitezone}
-if [ ${vpn_route_all} = 'yes' ]; then
- vpn_route_all_subst='s/^@vpn_route_all@ //g'
+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
- vpn_route_all_subst='/^@vpn_route_all@ /d'
+ printf '%s\n' 'usage: ./hostvpn-conf.sh sitezone {primary|secondary}'
+ exit 2
fi
-
-sed -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 "${vpn_route_all_subst}" \
- "${cfg_srcdir}/hostvpn.conf.in"