2013-01-19 23:07:26 +02:00
|
|
|
#!/bin/bash
|
|
|
|
# info: change user password
|
|
|
|
# options: USER PASSWORD
|
|
|
|
#
|
|
|
|
# The function changes user's password and updates RKEY value.
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Variable&Function #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
2015-11-06 17:38:58 +02:00
|
|
|
# Argument definition
|
2013-01-19 23:07:26 +02:00
|
|
|
user=$1
|
2015-10-21 15:57:54 +03:00
|
|
|
password=$2; HIDE=2
|
2013-01-19 23:07:26 +02:00
|
|
|
|
2020-04-11 02:16:24 +02:00
|
|
|
# Importing system enviroment as we run this script
|
|
|
|
# mostly by cron wich not read it by itself
|
|
|
|
source /etc/profile
|
|
|
|
|
2013-01-19 23:07:26 +02:00
|
|
|
# Includes
|
|
|
|
source $VESTA/func/main.sh
|
2013-10-09 00:50:08 +03:00
|
|
|
source $VESTA/conf/vesta.conf
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Verifications #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
2020-03-24 20:40:47 +01:00
|
|
|
if [ "$user" = "root" ]; then
|
|
|
|
check_result $E_FORBIDEN "Changing root password is forbiden"
|
|
|
|
fi
|
2013-01-19 23:07:26 +02:00
|
|
|
check_args '2' "$#" 'USER PASSWORD'
|
2016-06-09 16:31:56 +03:00
|
|
|
is_format_valid 'user'
|
2013-01-19 23:07:26 +02:00
|
|
|
is_object_valid 'user' 'USER' "$user"
|
|
|
|
is_object_unsuspended 'user' 'USER' "$user"
|
2015-03-29 12:39:42 +03:00
|
|
|
is_password_valid
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Action #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
|
|
# Changing user password
|
2013-06-23 17:27:07 +03:00
|
|
|
echo "$user:$password" | /usr/sbin/chpasswd
|
2013-01-19 23:07:26 +02:00
|
|
|
md5=$(awk -v user=$user -F : 'user == $1 {print $2}' /etc/shadow)
|
|
|
|
|
2018-03-29 16:35:31 +03:00
|
|
|
if [ "$user" = 'admin' ] && [ -e "$VESTA/web/reset.admin" ]; then
|
|
|
|
rm -f $VESTA/web/reset.admin
|
|
|
|
fi
|
|
|
|
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
# Vesta #
|
|
|
|
#----------------------------------------------------------#
|
|
|
|
|
|
|
|
# Changing RKEY value
|
2016-06-24 16:31:43 +03:00
|
|
|
update_user_value "$user" '$RKEY' "$(generate_password)"
|
2013-01-19 23:07:26 +02:00
|
|
|
update_user_value "$user" '$MD5' "$md5"
|
|
|
|
|
|
|
|
# Logging
|
|
|
|
log_history "changed password"
|
2016-06-09 16:31:56 +03:00
|
|
|
log_event "$OK" "$ARGUMENTS"
|
2013-01-19 23:07:26 +02:00
|
|
|
|
|
|
|
exit
|