Linux EOL in v-log-failed-login and v-change-user-rkey

This commit is contained in:
myvesta 2022-04-25 22:16:34 +02:00 committed by GitHub
commit 74e9dd4abf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 91 additions and 0 deletions

60
bin/v-change-user-rkey Normal file
View file

@ -0,0 +1,60 @@
#!/bin/bash
# info: change user rkey
# options: USER
#
# The function changes user's RKEY value.
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
# Includes
source $VESTA/func/main.sh
source $VESTA/conf/vesta.conf
#----------------------------------------------------------#
# Verifications #
#----------------------------------------------------------#
if [ "$user" = "root" ]; then
check_result $E_FORBIDEN "Changing root password is forbiden"
fi
check_args '1' "$#" 'USER'
is_format_valid 'user'
is_object_valid 'user' 'USER' "$user"
is_object_unsuspended 'user' 'USER' "$user"
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
hash=$(generate_password)
d=$(date +%s)
# Changing RKEY value
update_user_value "$user" '$RKEY' "$hash"
#check if RKEYEXP exists
if [ -z "$(grep RKEYEXP $USER_DATA/user.conf)" ]; then
sed -i "s/^RKEY/RKEYEXP='$d'\nRKEY/g" $USER_DATA/user.conf
else
update_user_value "$user" '$RKEYEXP' "$d"
fi
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
# Logging
log_history "changed rkey"
log_event "$OK" "$ARGUMENTS"
exit

31
bin/v-log-failed-login Normal file
View file

@ -0,0 +1,31 @@
#!/bin/bash
# info: log failed login attempt
# options: USER [IP]
#
# The function log failed login attempt
#----------------------------------------------------------#
# Variable&Function #
#----------------------------------------------------------#
# Argument definition
user=$1
ip=${2-127.0.0.1}
time_n_date=$(date +'%T %F')
time=$(echo "$time_n_date" |cut -f 1 -d \ )
date=$(echo "$time_n_date" |cut -f 2 -d \ )
#----------------------------------------------------------#
# Action #
#----------------------------------------------------------#
echo "$date $time $user $ip failed to login" >> $VESTA/log/auth.log
#----------------------------------------------------------#
# Vesta #
#----------------------------------------------------------#
exit 0