Repository navigation
Expand file tree
/
Copy pathhandle-connection
More file actions
executable file
·61 lines (54 loc) · 1.75 KB
/
Copy pathhandle-connection
File metadata and controls
executable file
·61 lines (54 loc) · 1.75 KB
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
source /etc/openvpn/conf.env
# Send output to stdout to avoid flooding the logs
/usr/bin/psql $REPORT_DB_URI -c "UPDATE units SET vpn_connected_since = NOW() WHERE uuid = '$common_name';" > /dev/null
# Dynamically assign VPN IP address
tmp_config=$1
if [ -z "$tmp_config" ]; then
exit 0
fi
vpn_address=$(/usr/bin/psql "$REPORT_DB_URI" -t -A -c "SELECT vpn_address FROM units WHERE uuid = '$common_name';")
if [ -n "$vpn_address" ]; then
echo "ifconfig-push $vpn_address $OVPN_NETMASK" >> $tmp_config
else
vpn_address=$ifconfig_pool_remote_ip
fi
# Add route to traefik
# using tmp to make the load atomic, moving the file at the end of the script
cat <<EOF > /etc/openvpn/proxy/$common_name.yaml.tmp
http:
# Add the router
routers:
router$common_name:
entryPoints:
- web
# must outrank the catch-all serving the controller UI
priority: 100
# addslash must come before stripprefix
middlewares:
- m$common_name-addslash
- m$common_name-stripprefix
service: service-$common_name
rule: PathPrefix(\`/$common_name\`)
# Add the service
services:
service-$common_name:
loadBalancer:
servers:
- url: https://$vpn_address:9090/
passHostHeader: true
# Add middleware
middlewares:
# without the trailing slash the unit's relative asset URLs resolve against the origin root
# and hit the controller's bundle
m$common_name-addslash:
redirectRegex:
regex: "^https?://[^/]+/$common_name(\\\\?.*)?\$"
replacement: "/$common_name/\${1}"
permanent: false
m$common_name-stripprefix:
stripPrefix:
prefixes:
- "/$common_name"
EOF
mv /etc/openvpn/proxy/$common_name.yaml.tmp /etc/openvpn/proxy/$common_name.yaml