1
0
mirror of https://github.com/myvesta/vesta.git synced 2025-03-12 04:35:23 -07:00
myvesta/bin/v-change-user-password

65 lines
1.8 KiB
Plaintext
Raw Permalink Normal View History

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
password=$2; HIDE=2
2013-01-19 23:07:26 +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
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'
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
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
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"
log_event "$OK" "$ARGUMENTS"
2013-01-19 23:07:26 +02:00
exit