This commit is contained in:
Julien Vaubourg
2015-09-28 16:53:22 +02:00
parent 67d17653fb
commit e001f16c2d
8 changed files with 233 additions and 143 deletions

View File

@@ -1,8 +1,8 @@
# [WARN] Edit this raw configuration ONLY IF YOU KNOW what
# you do!
# [WARN] Continue to use the placeholders <TPL:*> and keep
# update their value on the web admin (they are not
# only used for this file).
# [WARN] Edit this raw configuration ONLY IF YOU KNOW
# what you do!
# [WARN] Continue to use the placeholders <TPL:*> and
# keep update their value on the web admin (they
# are not only used for this file).
remote <TPL:SERVER_NAME>
proto <TPL:PROTO>

View File

@@ -52,6 +52,11 @@ is_serverip6route_set() {
fi
}
is_dns_set() {
[ -e /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient ]\
&& grep -q ${ynh_dns0} /etc/resolv.conf
}
is_openvpn_running() {
systemctl is-active openvpn@client.service &> /dev/null
}
@@ -59,7 +64,7 @@ is_openvpn_running() {
is_running() {
((has_nativeip6 && is_serverip6route_set "${new_server_ip6}") || ! has_nativeip6)\
&& ((! has_hotspot_app && has_ip6delegatedprefix && is_ip6addr_set) || has_hotspot_app || ! has_ip6delegatedprefix)\
&& is_openvpn_running
&& is_dns_set && is_openvpn_running
}
## Setters
@@ -76,6 +81,15 @@ set_serverip6route() {
ip route add "${server_ip6}/128" via "${ip6_gw}" dev "${wired_device}"
}
set_dns() {
cat << EOF > /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
echo nameserver ${ynh_dns0} > /etc/resolv.conf
echo nameserver ${ynh_dns1} >> /etc/resolv.conf
EOF
bash /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
}
start_openvpn() {
ip6_gw=${1}
server_ip6=${2}
@@ -129,6 +143,10 @@ unset_serverip6route() {
ip route delete "${server_ip6}/128" via "${ip6_gw}" dev "${wired_device}"
}
unset_dns() {
rm -f /etc/dhcp/dhclient-exit-hooks.d/ynh-vpnclient
}
stop_openvpn() {
systemctl stop openvpn.service
}
@@ -187,6 +205,8 @@ if [ "$1" != restart ]; then
ynh_server_proto=$(ynh_setting_get vpnclient server_proto)
ynh_ip6_addr=$(ynh_setting_get vpnclient ip6_addr)
ynh_login_user=$(ynh_setting_get vpnclient login_user)
ynh_dns0=$(ynh_setting_get vpnclient dns0)
ynh_dns1=$(ynh_setting_get vpnclient dns1)
old_ip6_gw=$(ynh_setting_get vpnclient ip6_gw)
old_wired_device=$(ynh_setting_get vpnclient wired_device)
@@ -255,6 +275,12 @@ case "${1}" in
set_ip6addr
fi
# Set host DNS resolvers
if ! is_dns_set; then
echo "Set host DNS resolvers"
set_dns
fi
# Update dynamic settings
ynh_setting_set vpnclient server_ip6 "${new_server_ip6}"
ynh_setting_set vpnclient ip6_gw "${new_ip6_gw}"
@@ -280,6 +306,11 @@ case "${1}" in
unset_serverip6route "${old_server_ip6}" "${old_ip6_gw}" "${old_wired_device}"
fi
if is_dns_set; then
echo "Unset forced host DNS resolvers"
unset_dns
fi
if is_openvpn_running; then
echo "Stop openvpn"
stop_openvpn
@@ -347,6 +378,13 @@ case "${1}" in
echo "[INFO] No IPv6 server route to set"
fi
if is_dns_set; then
echo "[OK] Host DNS correctly set"
else
echo "[ERR] No host DNS set"
exitcode=1
fi
if is_openvpn_running; then
echo "[OK] Openvpn is running"
else