From 6a53ec1bb19ab981ca059a9b68d3c3bb19938ebf Mon Sep 17 00:00:00 2001 From: Matthew Saunders Brown Date: Mon, 19 Jun 2023 10:42:50 -0700 Subject: [PATCH] new vhost-user-mod.sh script --- bin/vhost-user-mod.sh | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 bin/vhost-user-mod.sh diff --git a/bin/vhost-user-mod.sh b/bin/vhost-user-mod.sh new file mode 100755 index 0000000..bb11102 --- /dev/null +++ b/bin/vhost-user-mod.sh @@ -0,0 +1,71 @@ +#!/bin/bash +# +# vmail-stack +# https://git.stack-source.com/msb/vhost-stack +# Copyright (c) 2023 Matthew Saunders Brown +# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) + +# load include file +source $(dirname $0)/vhost.sh + +help() +{ + thisfilename=$(basename -- "$0") + echo "$thisfilename" + echo "Modify an existing user." + echo "" + echo "usage: $thisfilename -u [-p ] [-x ] [-w <0|1>] [-h]" + echo "" + echo " -h Print this help." + echo " -u System username to modify." + echo " -p Updated password for username." + echo " -x Updated PHP-FPM pm.max_children value." + echo " -w <0|1> Write user info to /home/username/.passwd (only applies when updating password)." + echo " 0 = no, 1 = yes. Default is 1, which can be overridden in main config." + exit +} + +vhost:getoptions "$@" + +# check for username +if [ -z "$username" ]; then + echo "username not set" + exit 1 +fi + +# verify user exists +if /bin/grep -q "^$username:" /etc/passwd; then + + # check for and change password + if [[ -n "$password" ]]; then + chpasswd <<<"$username:$password" + if [[ $write == 1 ]]; then + vhost::set-opensslpass + encryptedpass=`echo -n "$password" | openssl aes-256-cbc -a -salt -pass pass:$opensslpass -pbkdf2` + userid=(`stat -c '%u' /home/$username`) + userpasswdinfo="$username:$encryptedpass:$userid:$userid::/home/$username:/bin/bash" + if [[ -f "/home/$username/.passwd" ]]; then + chmod 640 /home/$username/.passwd + else + install -o $username -g $username -m 640 /dev/null /home/$username/.passwd + fi + echo "$userpasswdinfo" > /home/$username/.passwd + fi + fi + + # check for and change php workers + if [[ -n "$fpmmax" ]]; then + vhost::set-phpVersion + if [[ -f /etc/php/$phpVersion/fpm/pool.d/$username.conf ]]; then + sed -i "s|pm.max_children.*|pm.max_children = $fpmmax|g" /etc/php/8.1/fpm/pool.d/vr15com.conf + else + echo "ERROR: PHP config for $username does not exist." + exit 1 + fi + fi + +else + echo "ERROR: User $username does not exist." + exit 1 +fi +