Improve VPN setup
- vpnsetup.sh now automatically sets up IKEv2 as part of the IPsec VPN setup, same as quickstart.sh.
This commit is contained in:
parent
6850aa7f3b
commit
74b72b331a
38
vpnsetup.sh
38
vpnsetup.sh
@ -43,6 +43,11 @@ check_ip() {
|
||||
printf '%s' "$1" | tr -d '\n' | grep -Eq "$IP_REGEX"
|
||||
}
|
||||
|
||||
check_dns_name() {
|
||||
FQDN_REGEX='^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$'
|
||||
printf '%s' "$1" | tr -d '\n' | grep -Eq "$FQDN_REGEX"
|
||||
}
|
||||
|
||||
check_root() {
|
||||
if [ "$(id -u)" != 0 ]; then
|
||||
exiterr "Script must be run as root. Try 'sudo sh $0'"
|
||||
@ -177,6 +182,22 @@ check_dns() {
|
||||
fi
|
||||
}
|
||||
|
||||
check_server_dns() {
|
||||
if [ -n "$VPN_DNS_NAME" ] && ! check_dns_name "$VPN_DNS_NAME"; then
|
||||
exiterr "Invalid DNS name. 'VPN_DNS_NAME' must be a fully qualified domain name (FQDN)."
|
||||
fi
|
||||
}
|
||||
|
||||
check_client_name() {
|
||||
if [ -n "$VPN_CLIENT_NAME" ]; then
|
||||
name_len="$(printf '%s' "$VPN_CLIENT_NAME" | wc -m)"
|
||||
if [ "$name_len" -gt "64" ] || printf '%s' "$VPN_CLIENT_NAME" | LC_ALL=C grep -q '[^A-Za-z0-9_-]\+' \
|
||||
|| case $VPN_CLIENT_NAME in -*) true;; *) false;; esac; then
|
||||
exiterr "Invalid client name. Use one word only, no special characters except '-' and '_'."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_iptables() {
|
||||
if [ "$os_type" = "ubuntu" ] || [ "$os_type" = "debian" ] || [ "$os_type" = "raspbian" ]; then
|
||||
if [ -x /sbin/iptables ] && ! iptables -nL INPUT >/dev/null 2>&1; then
|
||||
@ -245,12 +266,23 @@ run_setup() {
|
||||
if tmpdir=$(mktemp --tmpdir -d vpn.XXXXX 2>/dev/null); then
|
||||
if ( set -x; wget -t 3 -T 30 -q -O "$tmpdir/vpn.sh" "$setup_url" \
|
||||
|| curl -fsL "$setup_url" -o "$tmpdir/vpn.sh" 2>/dev/null ); then
|
||||
VPN_IPSEC_PSK="$VPN_IPSEC_PSK" VPN_USER="$VPN_USER" VPN_PASSWORD="$VPN_PASSWORD" \
|
||||
if VPN_IPSEC_PSK="$VPN_IPSEC_PSK" VPN_USER="$VPN_USER" VPN_PASSWORD="$VPN_PASSWORD" \
|
||||
VPN_PUBLIC_IP="$VPN_PUBLIC_IP" VPN_L2TP_NET="$VPN_L2TP_NET" \
|
||||
VPN_L2TP_LOCAL="$VPN_L2TP_LOCAL" VPN_L2TP_POOL="$VPN_L2TP_POOL" \
|
||||
VPN_XAUTH_NET="$VPN_XAUTH_NET" VPN_XAUTH_POOL="$VPN_XAUTH_POOL" \
|
||||
VPN_DNS_SRV1="$VPN_DNS_SRV1" VPN_DNS_SRV2="$VPN_DNS_SRV2" \
|
||||
/bin/bash "$tmpdir/vpn.sh" || status=1
|
||||
/bin/bash "$tmpdir/vpn.sh"; then
|
||||
if [ -s /opt/src/ikev2.sh ] && [ ! -f /etc/ipsec.d/ikev2.conf ]; then
|
||||
sleep 1
|
||||
VPN_DNS_NAME="$VPN_DNS_NAME" VPN_PUBLIC_IP="$VPN_PUBLIC_IP" \
|
||||
VPN_CLIENT_NAME="$VPN_CLIENT_NAME" VPN_XAUTH_POOL="$VPN_XAUTH_POOL" \
|
||||
VPN_DNS_SRV1="$VPN_DNS_SRV1" VPN_DNS_SRV2="$VPN_DNS_SRV2" \
|
||||
VPN_PROTECT_CONFIG="$VPN_PROTECT_CONFIG" \
|
||||
/bin/bash /opt/src/ikev2.sh --auto || status=1
|
||||
fi
|
||||
else
|
||||
status=1
|
||||
fi
|
||||
else
|
||||
status=1
|
||||
echo "Error: Could not download VPN setup script." >&2
|
||||
@ -270,6 +302,8 @@ vpnsetup() {
|
||||
check_iface
|
||||
check_creds
|
||||
check_dns
|
||||
check_server_dns
|
||||
check_client_name
|
||||
check_iptables
|
||||
install_pkgs
|
||||
get_setup_url
|
||||
|
Loading…
Reference in New Issue
Block a user