From f35d41bc3ad08adf8ee019c1d3d0ffbfd53c98a8 Mon Sep 17 00:00:00 2001 From: Johan Date: Fri, 21 Mar 2025 14:16:43 +0100 Subject: [PATCH] Make OpenVPN username case insensitive --- BashScripts/add-openvpn-client.sh | 6 +++--- BashScripts/install-openvpn-server.sh | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BashScripts/add-openvpn-client.sh b/BashScripts/add-openvpn-client.sh index 7ba24a0..5093c89 100644 --- a/BashScripts/add-openvpn-client.sh +++ b/BashScripts/add-openvpn-client.sh @@ -21,15 +21,15 @@ if [ -f "/etc/openvpn/easy-rsa/pki/issued/$CLIENT_NAME.crt" ]; then exit 1 fi if grep -q "^auth-user-pass-verify" "/etc/openvpn/myserver.conf"; then - read -e -p "Enter username: " -i "$CLIENT_USERNAME" CLIENT_USERNAME - if grep -q "^$CLIENT_USERNAME" "/etc/openvpn/credentials"; then + read -e -p "Enter username: " -i "$CLIENT_NAME" CLIENT_USERNAME + if grep -i -q "^$CLIENT_USERNAME" "/etc/openvpn/credentials"; then echo "Username $CLIENT_USERNAME already exists" exit 1 fi read -e -p "Enter password: " -i "$CLIENT_PASSWORD" CLIENT_PASSWORD CLIENT_PASSWORD_HASH=$(echo -n "$CLIENT_PASSWORD" | sha256sum | awk '{print $1}') echo "$CLIENT_USERNAME:$CLIENT_PASSWORD_HASH:$CLIENT_NAME" >> "/etc/openvpn/credentials" - EXTRA_CONFIG = "auth-user-pass" + EXTRA_CONFIG="auth-user-pass" fi read -e -p "Use static IP for this client? VPN subnet is $VPN_SUBNET (Leave empty for dynamic): " -i "" CLIENT_IP if [ ! -z "${CLIENT_IP}" ]; then diff --git a/BashScripts/install-openvpn-server.sh b/BashScripts/install-openvpn-server.sh index 36d8a89..8827c55 100644 --- a/BashScripts/install-openvpn-server.sh +++ b/BashScripts/install-openvpn-server.sh @@ -144,15 +144,15 @@ if [ -f "/etc/openvpn/easy-rsa/pki/issued/$CLIENT_NAME.crt" ]; then exit 1 fi if grep -q "^auth-user-pass-verify" "/etc/openvpn/myserver.conf"; then - read -e -p "Enter username: " -i "$CLIENT_USERNAME" CLIENT_USERNAME - if grep -q "^$CLIENT_USERNAME" "/etc/openvpn/credentials"; then + read -e -p "Enter username: " -i "$CLIENT_NAME" CLIENT_USERNAME + if grep -i -q "^$CLIENT_USERNAME" "/etc/openvpn/credentials"; then echo "Username $CLIENT_USERNAME already exists" exit 1 fi read -e -p "Enter password: " -i "$CLIENT_PASSWORD" CLIENT_PASSWORD CLIENT_PASSWORD_HASH=$(echo -n "$CLIENT_PASSWORD" | sha256sum | awk '{print $1}') echo "$CLIENT_USERNAME:$CLIENT_PASSWORD_HASH:$CLIENT_NAME" >> "/etc/openvpn/credentials" - EXTRA_CONFIG = "auth-user-pass" + EXTRA_CONFIG="auth-user-pass" fi read -e -p "Use static IP for this client? VPN subnet is $VPN_SUBNET (Leave empty for dynamic): " -i "" CLIENT_IP if [ ! -z "${CLIENT_IP}" ]; then @@ -217,7 +217,7 @@ readarray -t lines < $1 username=${lines[0]} password=${lines[1]} password_hash=$(echo -n "$password" | sha256sum | awk '{print $1}') -if grep -q "^$username:$password_hash:" "/etc/openvpn/credentials"; then +if grep -i -q "^$username:$password_hash:" "/etc/openvpn/credentials"; then exit 0 # Authentication success else exit 1 # Authentication failed