From 3dc675ba375c48cd2cc4460091a419e8c6f7d8b2 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Sun, 16 Oct 2022 00:45:45 -0500 Subject: [PATCH] Add client validity option - For IKEv2 mode, add a new variable VPN_CLIENT_VALIDITY for specifying the client certificate validity period (in months). Must be an integer between 1 and 120. Default value is 120. Users can define it as an environment variable when setting up IKEv2 in auto mode, or when adding a new IKEv2 client using "--addclient". --- extras/ikev2setup.sh | 44 ++++++++++++++++++++++++++++++++++---------- extras/quickstart.sh | 1 + vpnsetup.sh | 1 + vpnsetup_alpine.sh | 1 + vpnsetup_amzn.sh | 1 + vpnsetup_centos.sh | 1 + vpnsetup_ubuntu.sh | 1 + 7 files changed, 40 insertions(+), 10 deletions(-) diff --git a/extras/ikev2setup.sh b/extras/ikev2setup.sh index b596981..7d7d47c 100755 --- a/extras/ikev2setup.sh +++ b/extras/ikev2setup.sh @@ -157,7 +157,7 @@ confirm_or_abort() { show_header() { cat <<'EOF' -IKEv2 Script Copyright (c) 2020-2022 Lin Song 24 Sept 2022 +IKEv2 Script Copyright (c) 2020-2022 Lin Song 16 Oct 2022 EOF } @@ -278,6 +278,11 @@ check_custom_dns() { fi } +check_client_validity() { + ! { printf '%s' "$1" | LC_ALL=C grep -q '[^0-9]\+' || [ "$1" -lt "1" ] \ + || [ "$1" -gt "120" ] || [ "$1" != "$((10#$1))" ]; } +} + check_and_set_client_name() { if [ -n "$VPN_CLIENT_NAME" ]; then client_name="$VPN_CLIENT_NAME" @@ -289,6 +294,22 @@ check_and_set_client_name() { check_cert_exists "$client_name" && exiterr "Client '$client_name' already exists." } +check_and_set_client_validity() { + if [ -n "$VPN_CLIENT_VALIDITY" ]; then + client_validity="$VPN_CLIENT_VALIDITY" + if ! check_client_validity "$client_validity"; then +cat <