|
|
@@ -1,6 +1,6 @@
|
|
|
#!/bin/bash
|
|
|
# info: check user password
|
|
|
-# options: USER PASSWORD [IP]
|
|
|
+# options: USER PASSWORD [IP] [RETURN_HASH]
|
|
|
#
|
|
|
# example: v-check-user-password admin qwerty1234
|
|
|
#
|
|
|
@@ -14,6 +14,7 @@
|
|
|
user=$1
|
|
|
password=$2; HIDE=2
|
|
|
ip=${3-127.0.0.1}
|
|
|
+return_hash=$4
|
|
|
|
|
|
# Includes
|
|
|
# shellcheck source=/etc/hestiacp/hestia.conf
|
|
|
@@ -31,11 +32,11 @@ date=$(echo "$time_n_date" |cut -f 2 -d \ )
|
|
|
# Verifications #
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
-check_args '2' "$#" 'USER PASSWORD'
|
|
|
+check_args '2' "$#" 'USER PASSWORD RETURN_HASH'
|
|
|
is_format_valid 'user'
|
|
|
|
|
|
# Checking user
|
|
|
-if [ ! -d "$HESTIA/data/users/$user" ] && [ "$user" != 'root' ]; then
|
|
|
+if [ ! -d "$HESTIA/data/users/$user" ]; then
|
|
|
echo "Error: password missmatch"
|
|
|
echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
|
|
|
exit 9
|
|
|
@@ -63,8 +64,7 @@ then
|
|
|
salt=$(echo "$shadow" |cut -f 3 -d \$)
|
|
|
method=$(echo "$shadow" |cut -f 2 -d \$)
|
|
|
if [ "$method" = "y" ]; then
|
|
|
- echo "Unsuported hash method";
|
|
|
- exit 1;
|
|
|
+ method="yescrypt"
|
|
|
elif [ "$method" -eq '1' ]; then
|
|
|
method='md5'
|
|
|
elif [ "$method" -eq '6' ]; then
|
|
|
@@ -85,13 +85,22 @@ if [ -z "$salt" ]; then
|
|
|
exit 9
|
|
|
fi
|
|
|
|
|
|
-# Generating hash
|
|
|
-set -o noglob
|
|
|
-hash=$($BIN/v-generate-password-hash "$method" "$salt" <<< "$password")
|
|
|
-if [[ -z "$hash" ]]; then
|
|
|
- echo "Error: password missmatch"
|
|
|
- echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
|
|
|
- exit 9
|
|
|
+if [ "$method" = "yescrypt" ]; then
|
|
|
+ hash=$(mkpasswd "$password" "$shadow")
|
|
|
+ if [ $? -ne 0 ]; then
|
|
|
+ echo "Error: password missmatch"
|
|
|
+ echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
|
|
|
+ exit 9
|
|
|
+ fi
|
|
|
+else
|
|
|
+ # Generating hash
|
|
|
+ set -o noglob
|
|
|
+ hash=$($BIN/v-generate-password-hash "$method" "$salt" <<< "$password")
|
|
|
+ if [[ -z "$hash" ]]; then
|
|
|
+ echo "Error: password missmatch"
|
|
|
+ echo "$date $time $user $ip failed to login" >> $HESTIA/log/auth.log
|
|
|
+ exit 9
|
|
|
+ fi
|
|
|
fi
|
|
|
|
|
|
# Checking hash
|
|
|
@@ -106,6 +115,9 @@ fi
|
|
|
# Hestia #
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
+if [ -n "$return_hash" ]; then
|
|
|
+ echo $hash;
|
|
|
+fi
|
|
|
# Logging
|
|
|
echo "$date $time $user $ip successfully logged in" >> $HESTIA/log/auth.log
|
|
|
|