myvesta/bin/v-change-user-rkey

61 lines
1.5 KiB
Bash

#!/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