diff --git a/bin/vhost-user-get.sh b/bin/vhost-user-get.sh new file mode 100755 index 0000000..e51d51f --- /dev/null +++ b/bin/vhost-user-get.sh @@ -0,0 +1,68 @@ +#!/bin/bash +# +# vhost-stack +# https://git.stack-source.com/msb/vhost-stack +# Copyright (c) 2022 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 "Get System Users with info." + echo "" + echo "usage: $thisfilename [-u ] [-c] [-h]" + echo "" + echo " -h Print this help." + echo " -u Only return info about specified username, otherwise all usernames are returned." + echo " -c CVS - Output in cvs format, instead of tabbed table." +} + +vhost:getoptions "$@" + +# 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 + +output="username uid jailed passwd" + +for username in "${usernames[@]}" +do + userid=(`stat -c '%u' /home/$username`) + 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= + fi + shell=(`grep $username /etc/passwd|awk -F : '{ print $6 }'`) + if [[ $shell = "/usr/jails/$username/./home/$username" ]]; then + jailed="Yes" + else + jailed="No" + fi + output="$output${NL}$username $userid $jailed $password" +done + +if [[ $cvs ]]; then + echo "$output" | tr " " "," +else + echo "$output" | column -t +fi +