change write flag, defaults to enabled

This commit is contained in:
Matthew Saunders Brown 2023-05-04 17:15:27 -07:00
parent fa65c5dac2
commit 2592e4b8e3
4 changed files with 36 additions and 21 deletions

View File

@ -13,15 +13,15 @@ help()
thisfilename=$(basename -- "$0")
echo "Add virtualhost to this server, including shell user and MySQL database."
echo ""
echo "usage: $thisfilename -d <domain> [-u <username>] [-p <password>] [-x <fpmmax>] [-j <0|1>] [-w] [-h]"
echo "usage: $thisfilename -d <domain> [-u <username>] [-p <password>] [-x <fpmmax>] [-j <0|1>] [-w <0|1>] [-h]"
echo ""
echo " -h Print this help."
echo " -d <domain> Domain name of VirtualHost to remove."
echo " -u <username> Username to use for this virtualhost. Optional, defaults to first 8 alphanumeric characters of virtualhost."
echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -x <fpmmax> PHP-FPM pm.max_children. Optional, defaults to 4, recommended range 2-12 on Shared Server."
echo " -j <0|1> Whether or not to jail the user. 0 = no, 1 = yes. Default is 1, which can be overriden in main config."
echo " -w Write user & mysql info to files."
echo " -j <0|1> Whether or not to jail the user. 0 = no, 1 = yes. Default is 1, which can be overridden in main config."
echo " -w <0|1> Write user & mysql info to files. 0 = no, 1 = yes. Default is 1, which can be overridden in main config."
exit
}
@ -88,6 +88,11 @@ if [[ -z "$username" ]]; then
fi
fi
# check for and set write option
if [[ -z $write ]]; then
write=$WRITE_INFO
fi
if ! grep -q "^$username:" /etc/passwd; then
# check for and set password
if [[ -z "$password" ]]; then
@ -98,11 +103,7 @@ if ! grep -q "^$username:" /etc/passwd; then
fpmmax=$FPM_MAX
fi
# add user
if [[ -n $write ]]; then
/usr/local/bin/vhost-user-add.sh -u $username -p "$password" -x $fpmmax -w
else
/usr/local/bin/vhost-user-add.sh -u $username -p "$password" -x $fpmmax
fi
/usr/local/bin/vhost-user-add.sh -u $username -p "$password" -x $fpmmax -w $write
# check for and set jail option
if [[ -z $jail ]]; then
jail=$JAIL_USER
@ -120,8 +121,4 @@ fi
/usr/local/bin/vhost-add.sh -d $domain -u $username > /dev/null 2>&1
# add mysql database
if [[ -n $write ]]; then
/usr/local/bin/vhost-mysql-db-add.sh -d $domain -w > /dev/null 2>&1
else
/usr/local/bin/vhost-mysql-db-add.sh -d $domain > /dev/null 2>&1
fi
/usr/local/bin/vhost-mysql-db-add.sh -d $domain -w $write> /dev/null 2>&1

View File

@ -19,7 +19,8 @@ help()
echo " -d <domain> Domain name of VirtualHost to add db for."
echo " -u <username> Username for accessing the database. Optional, autogenerated if none specified."
echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -w Write db info to /srv/www/domain/.my.cnf and create include in /home/username/.my.cnf."
echo " -w <0|1> Write db info to /srv/www/domain/.my.cnf and create include in /home/username/.my.cnf."
echo " 0 = no, 1 = yes. Default is 1, which can be overridden in main config."
echo " -v Verbose - output newly created db info to console."
echo ""
echo " MySQL database names is based on virtualhost with . replaced by the word 'dot'"
@ -54,6 +55,11 @@ if [[ -d /var/lib/mysql/$database ]]; then
exit 1
fi
# check for and set write option
if [[ -z $write ]]; then
write=$WRITE_INFO
fi
# get & set username of virtualhost
vhost_username=$(stat -c '%U' /srv/www/$domain)
@ -73,7 +79,7 @@ mysql -e "GRANT ALL PRIVILEGES ON $database.* TO '$username'@'localhost';"
mysqladmin flush-privileges
# save mysql db info to file
if [[ -n $write ]]; then
if [[ $write == 1 ]]; then
touch /srv/www/$domain/.my.cnf
chown $vhost_username:$vhost_username /srv/www/$domain/.my.cnf
chmod 640 /srv/www/$domain/.my.cnf

View File

@ -13,14 +13,14 @@ help()
thisfilename=$(basename -- "$0")
echo "Add system user to server."
echo ""
echo "usage: $thisfilename -u <username> [-p <password> [-i <uid>] [-x <fpmmax>] [-w] [-h]"
echo "usage: $thisfilename -u <username> [-p <password> [-i <uid>] [-x <fpmmax>] [-w <0|1>] [-h]"
echo ""
echo " -h Print this help."
echo " -u <username> System username to add to server."
echo " -p <password> Password for username. Optional, random password generated if none specified."
echo " -i <uid> Numberic User ID to assign to user. Optional, next available uid set if none specified."
echo " -x <fpmmax> PHP-FPM pm.max_children. Optional, defaults to 4, recommended range 2-12 on Shared Server."
echo " -w Write user info to /home/username/.passwd."
echo " -w <0|1> Write user info to /home/username/.passwd. 0 = no, 1 = yes. Default is 1, which can be overridden in main config."
exit
}
@ -37,6 +37,11 @@ if [ -z "$password" ]; then
password=`/usr/bin/pwgen 12 1`
fi
# check for and set write option
if [[ -z $write ]]; then
write=$WRITE_INFO
fi
# get next UID if none specified
if [ -z "$uid" ]; then
uid=`awk -F: '{uid[$3]=1}END{for(x=1000; x<=65534; x++) {if(uid[x] != ""){}else{print x; exit;}}}' /etc/passwd`
@ -79,14 +84,16 @@ if [[ ! -f "/home/$username/.profile" ]]; then
install -o $username -g $username -m 640 /etc/skel/.profile /home/$username
fi
if [[ -n $write ]]; then
if [[ $write == 1 ]]; then
vhost::set-opensslpass
encryptedpass=`echo -n "$password" | openssl aes-256-cbc -a -salt -pass pass:$opensslpass -pbkdf2`
userpasswdinfo="$username:$encryptedpass:$uid:$uid::/home/$username:/bin/bash"
if [[ ! -f "/home/$username/.passwd" ]]; then
if [[ -f "/home/$username/.passwd" ]]; then
chmod 640 /home/$username/.passwd
else
install -o $username -g $username -m 640 /dev/null /home/$username/.passwd
echo "$userpasswdinfo" > /home/$username/.passwd
fi
echo "$userpasswdinfo" > /home/$username/.passwd
fi
# php-fpm pool

View File

@ -14,6 +14,7 @@ fi
FPM_MAX=4
JAIL_USER=1
WRITE_INFO=1
# functions
@ -102,7 +103,11 @@ function vhost:getoptions () {
verbose=true
;;
w ) # write - store data in file
write=true
write=${OPTARG}
if [[ $write != "0" ]] && [[ $write != "1" ]]; then
echo "ERROR: Invalid write setting: -j $write"
exit 1
fi
;;
x ) # php-fpm pm.max_children
fpmmax=${OPTARG}