|
24 | 24 | # if ovpn filename is not custom.ovpn and the provider is pia then copy included ovpn and certs
|
25 | 25 | if [[ "${VPN_CONFIG}" != "/config/openvpn/custom.ovpn" && "${VPN_PROV}" == "pia" ]]; then
|
26 | 26 |
|
27 |
| - # remove previous certs and ovpn files, user may of switched to strong |
28 |
| - rm -f /config/openvpn/* |
29 |
| - |
30 | 27 | if [[ "${STRONG_CERTS}" == "yes" ]]; then
|
31 | 28 |
|
32 | 29 | echo "[info] VPN strong certs defined, copying to /config/openvpn/..."
|
33 | 30 |
|
34 |
| - # copy strong encrption ovpn and certs |
| 31 | + # copy strong encryption ovpn and certs |
35 | 32 | cp -f /home/nobody/certs/strong/*.crt /config/openvpn/
|
36 | 33 | cp -f /home/nobody/certs/strong/*.pem /config/openvpn/
|
37 | 34 | cp -f "/home/nobody/certs/strong/strong.ovpn" "/config/openvpn/openvpn.ovpn"
|
|
40 | 37 |
|
41 | 38 | echo "[info] VPN default certs defined, copying to /config/openvpn/..."
|
42 | 39 |
|
43 |
| - # copy default encrption ovpn and certs |
| 40 | + # copy default encryption ovpn and certs |
44 | 41 | cp -f /home/nobody/certs/default/*.crt /config/openvpn/
|
45 | 42 | cp -f /home/nobody/certs/default/*.pem /config/openvpn/
|
46 | 43 | cp -f "/home/nobody/certs/default/default.ovpn" "/config/openvpn/openvpn.ovpn"
|
|
68 | 65 | /usr/bin/dos2unix "${VPN_CONFIG}"
|
69 | 66 |
|
70 | 67 | if [[ "${VPN_PROV}" == "pia" ]]; then
|
71 |
| - |
| 68 | + |
72 | 69 | if [[ "${VPN_PROTOCOL}" == "udp" && "${VPN_PORT}" != "1198" && "${STRONG_CERTS}" != "yes" ]]; then
|
73 | 70 | echo "[warn] VPN provider remote port incorrect, overriding to 1198"
|
74 | 71 | VPN_PORT="1198"
|
|
77 | 74 | echo "[warn] VPN provider remote port incorrect, overriding to 1197"
|
78 | 75 | VPN_PORT="1197"
|
79 | 76 |
|
80 |
| - |
81 | 77 | elif [[ "${VPN_PROTOCOL}" == "tcp" && "${VPN_PORT}" != "502" && "${STRONG_CERTS}" != "yes" ]]; then
|
82 | 78 | echo "[warn] VPN provider remote port incorrect, overriding to 502"
|
83 | 79 | VPN_PORT="502"
|
84 | 80 |
|
85 |
| - |
86 | 81 | elif [[ "${VPN_PROTOCOL}" == "tcp" && "${VPN_PORT}" != "501" && "${STRONG_CERTS}" == "yes" ]]; then
|
87 | 82 | echo "[warn] VPN provider remote port incorrect, overriding to 501"
|
88 | 83 | VPN_PORT="501"
|
89 | 84 | fi
|
90 | 85 | fi
|
91 | 86 |
|
92 |
| - # if vpn provider not airvpn then write credentials to file (airvpn uses certs for authentication) |
93 |
| - if [[ "${VPN_PROV}" != "airvpn" ]]; then |
| 87 | + # if vpn username and password specified then write credentials to file (authentication maybe via keypair) |
| 88 | + if [[ ! -z "${VPN_USER}" && ! -z "${VPN_PASS}" ]]; then |
94 | 89 |
|
95 | 90 | # store credentials in separate file for authentication
|
96 | 91 | if ! $(grep -Fq "auth-user-pass credentials.conf" "${VPN_CONFIG}"); then
|
@@ -130,19 +125,17 @@ else
|
130 | 125 | sed -i '/reneg-sec.*/d' "${VPN_CONFIG}"
|
131 | 126 | fi
|
132 | 127 |
|
133 |
| - # disable proto from ovpn file if present, defined via env variable and passed to openvpn via command line argument |
134 |
| - if $(grep -Fq "proto" "${VPN_CONFIG}"); then |
135 |
| - sed -i -e 's~^proto\s~# Disabled, as we pass this value via env var\n;proto ~g' "${VPN_CONFIG}" |
| 128 | + # write env vars to ovpn file (used as phased approach to parse ovpn file) |
| 129 | + if [[ ! -z "${VPN_PROTOCOL}" ]]; then |
| 130 | + sed -i -r "s~^;?proto\s.*~proto ${VPN_PROTOCOL}~g" "${VPN_CONFIG}" |
136 | 131 | fi
|
137 | 132 |
|
138 |
| - # disable remote from ovpn file if present, defined via env variable and passed to openvpn via command line argument |
139 |
| - if $(grep -Fq "remote" "${VPN_CONFIG}"); then |
140 |
| - sed -i -e 's~^remote\s~# Disabled, as we pass this value via env var\n;remote ~g' "${VPN_CONFIG}" |
| 133 | + if [[ ! -z "${VPN_REMOTE}" && ! -z "${VPN_PORT}" ]]; then |
| 134 | + sed -i -r "s~^;?remote\s.*~remote ${VPN_REMOTE} ${VPN_PORT}~g" "${VPN_CONFIG}" |
141 | 135 | fi
|
142 | 136 |
|
143 |
| - # disable dev from ovpn file if present, defined via env variable and passed to openvpn via command line argument |
144 |
| - if $(grep -Fq "dev" "${VPN_CONFIG}"); then |
145 |
| - sed -i -e 's~^dev\s~# Disabled, as we pass this value via env var\n;dev ~g' "${VPN_CONFIG}" |
| 137 | + if [[ ! -z "${VPN_DEVICE_TYPE}" ]]; then |
| 138 | + sed -i -r "s~^;?dev\s.*~dev ${VPN_DEVICE_TYPE}~g" "${VPN_CONFIG}" |
146 | 139 | fi
|
147 | 140 |
|
148 | 141 | # create the tunnel device
|
|
0 commit comments