vhost-stack/bin/vhost-user-get.sh

86 lines
2.2 KiB
Bash
Raw Permalink Normal View History

2023-03-30 14:59:01 -07:00
#!/bin/bash
#
# vhost-stack
# https://git.stack-source.com/msb/vhost-stack
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# 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 "Get System Users with info."
echo ""
echo "usage: $thisfilename [-u <username>] [-c] [-h]"
echo ""
echo " -h Print this help."
echo " -u <username> Only return info about specified username, otherwise all usernames are returned."
echo " -v Verbose - include unencrypted passwords, if available."
2023-03-30 14:59:01 -07:00
echo " -c CVS - Output in cvs format, instead of tabbed table."
}
vhost:getoptions "$@"
vhost::set-phpVersion
2023-03-30 14:59:01 -07:00
# create newline var
NL=$'\n'
# check for username (optional)
if [[ ! -z $username ]]; then
if [[ -d "/home/$username" ]]; then
usernames=$username
else
echo "ERROR: $username not found"
exit 1
fi
else
usernames=(`ls /home/`)
fi
if [[ -n $verbose ]]; then
output="uid username passwd jailed fpmmax"
else
output="uid username jailed fpmmax"
fi
2023-03-30 14:59:01 -07:00
for username in "${usernames[@]}"
do
userid=(`stat -c '%u' /home/$username`)
if [[ -n $verbose ]]; then
if [[ -f /home/$username/.passwd ]]; then
password=(`awk -F : '{ print $2 }' /home/$username/.passwd`)
if [[ -f /root/.vhost.ini ]]; then
vhost::set-opensslpass
password=`echo "$password" | openssl aes-256-cbc -d -a -pass pass:$opensslpass -pbkdf2`
fi
else
password="(unknown)"
2023-03-30 14:59:01 -07:00
fi
fi
shell=(`grep $username /etc/passwd|awk -F : '{ print $6 }'`)
if [[ $shell = "/usr/jails/$username/./home/$username" ]]; then
jailed="Yes"
else
jailed="No"
fi
fpmmax=0
if [[ -f "/etc/php/$phpVersion/fpm/pool.d/$username.conf" ]]; then
2024-05-16 11:15:17 -07:00
fpmmax=$(grep pm.max_children /etc/php/$phpVersion/fpm/pool.d/$username.conf | awk -F '=' '{ print $2 }' | tr -d ' ')
fi
if [[ -n $verbose ]]; then
output="$output${NL}$userid $username $password $jailed $fpmmax"
2023-04-24 14:04:12 -07:00
else
output="$output${NL}$userid $username $jailed $fpmmax"
2023-04-24 14:04:12 -07:00
fi
2023-03-30 14:59:01 -07:00
done
if [[ $cvs ]]; then
echo "$output" | tr " " ","
else
echo "$output" | column -t
fi