Make OpenVPN username case insensitive

This commit is contained in:
Johan 2025-03-21 14:16:43 +01:00
parent e6f33e3015
commit f35d41bc3a
2 changed files with 7 additions and 7 deletions

View File

@ -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

View File

@ -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