expaned username creation options

This commit is contained in:
Matthew Saunders Brown 2021-10-02 15:31:35 -07:00
parent 6606865372
commit 90a9d0b23c

View File

@ -15,7 +15,7 @@ help()
echo "usage: $thisfilename virtualhost [OPTIONS]" echo "usage: $thisfilename virtualhost [OPTIONS]"
echo "" echo ""
echo " -h Print this help." echo " -h Print this help."
echo " -u USERNAME Username to use for this virtualhost. Optional, defaults to first 8 characters of virtualhost." 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 " -p PASSWORD Password for username. Optional, random password generated if none specified."
echo " -j Whether or not to jail the user. Optional, default is to not jail user." echo " -j Whether or not to jail the user. Optional, default is to not jail user."
exit exit
@ -27,6 +27,7 @@ if [ -n "$1" ]; then
help help
elif vhost::validate_domain $1; then elif vhost::validate_domain $1; then
virtualhost="${1,,}" virtualhost="${1,,}"
shift
else else
echo "ERROR: Invalid virtualhost: $1" echo "ERROR: Invalid virtualhost: $1"
exit 1 exit 1
@ -75,6 +76,45 @@ fi
if [ ! -n "$username" ]; then if [ ! -n "$username" ]; then
username=`echo $virtualhost | sed 's|\.||'` username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:8}` username=`echo ${username:0:8}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:7}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:6}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:5}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:9}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:10}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:11}`
if grep -q "^$username:" /etc/passwd; then
# username already exists, try another
username=`echo $virtualhost | sed 's|\.||'`
username=`echo ${username:0:12}`
if grep -q "^$username:" /etc/passwd; then
echo "trouble setting unique username, specify '-u USERNAME' to use an existing username"
exit 1
fi
fi
fi
fi
fi
fi
fi
fi
fi fi
if ! grep -q "^$username:" /etc/passwd; then if ! grep -q "^$username:" /etc/passwd; then