bin/vmail-domains-mod.sh
This commit is contained in:
parent
677ac2aa79
commit
5b2f1749ac
|
@ -10,91 +10,115 @@ source $(dirname $0)/vmail.sh
|
||||||
help()
|
help()
|
||||||
{
|
{
|
||||||
thisfilename=$(basename -- "$0")
|
thisfilename=$(basename -- "$0")
|
||||||
echo "$thisfilename"
|
echo "Modify an existing domain."
|
||||||
echo "Get domain data from vmail database."
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "usage: $thisfilename [domain] [OPTIONS]"
|
echo "usage: $thisfilename domain [OPTIONS]"
|
||||||
echo ""
|
echo ""
|
||||||
echo " -e Exact match instead of wildcard search."
|
|
||||||
echo " -c Output in cvs format."
|
|
||||||
echo " -h Print this help."
|
echo " -h Print this help."
|
||||||
echo " -s Be more silent - use tabs instead of tables for output, do not display column headers."
|
echo " -l LIMIT Mailbox limit - the maximum number of mailboxes under this domain."
|
||||||
echo ""
|
echo " -q QUOTA Mailbox Quota Default - default quota for new mailboxes under this domain."
|
||||||
echo " Domain can either be a FQDN or a search term."
|
echo " -s STATUS 1 for enabled, 0 for disabled. Default is in db structure and is normally set to 1."
|
||||||
echo " e.g. to search for all .org domains enter .org as the domain."
|
|
||||||
echo " Use the -e option to disable wildcard search and require exact match of FQDN."
|
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
|
|
||||||
# set & check $domain here
|
# check for and verify domain
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
if [ $1 == "-h" ]; then
|
||||||
|
help
|
||||||
|
else
|
||||||
|
domain=$1
|
||||||
|
shift
|
||||||
|
if vmail::validate_domain $domain; then
|
||||||
|
domain_id=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT id from vm_domains WHERE vm_domains.domain='$domain';"`
|
||||||
|
if [ -z $domain_id ] ; then
|
||||||
|
echo "ERROR: Email domain $domain does not exist."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "ERROR: $domain is not a valid domain name."
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
help
|
||||||
|
fi
|
||||||
|
|
||||||
# set any options that were passed
|
# set any options that were passed
|
||||||
while getopts ":s:l:q:" opt; do
|
while getopts "hl:q:s:" opt; do
|
||||||
case "${opt}" in
|
case "${opt}" in
|
||||||
s )
|
h )
|
||||||
status=${OPTARG}
|
help
|
||||||
;;
|
exit;;
|
||||||
l )
|
l )
|
||||||
limit=${OPTARG}
|
limit=${OPTARG}
|
||||||
;;
|
|
||||||
q )
|
|
||||||
quota=${OPTARG}
|
|
||||||
;;
|
|
||||||
\? )
|
|
||||||
echo "Invalid option: $OPTARG" 1>&2
|
|
||||||
;;
|
|
||||||
: )
|
|
||||||
echo "Invalid option: $OPTARG requires an argument" 1>&2
|
|
||||||
;;
|
;;
|
||||||
|
q )
|
||||||
|
quota=${OPTARG}
|
||||||
|
;;
|
||||||
|
s )
|
||||||
|
status=${OPTARG}
|
||||||
|
;;
|
||||||
|
\? )
|
||||||
|
echo "Invalid option: $OPTARG" 1>&2
|
||||||
|
;;
|
||||||
|
: )
|
||||||
|
echo "Invalid option: $OPTARG requires an argument" 1>&2
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# check if vmail domain dir exits
|
# set update portion of command to empty string
|
||||||
if [ -d /var/vmail/$domain ]; then
|
dbset=""
|
||||||
echo "ERROR: Directory /var/vmail/$domain already exists."
|
|
||||||
exit 1
|
# check for quota update
|
||||||
|
if [ -n "$quota" ]; then
|
||||||
|
# make quota uppercase in case it is set to NULL
|
||||||
|
quota=`echo $quota | tr [:lower:] [:upper:]`
|
||||||
|
if [[ "$quota" =~ ^[0-9]+$ ]] || [[ "$quota" == "NULL" ]]; then
|
||||||
|
dbset=" mbox_quota_default=\"$quota\""
|
||||||
|
else
|
||||||
|
echo "ERROR: quota (-q) must numeric or NULL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# check if domain exists in vmail database
|
# check for limit update
|
||||||
rowcount=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT COUNT(*) from vm_domains WHERE domain='$domain';"`
|
if [ ! -z "$limit" ]; then
|
||||||
if [ "$rowcount" -eq '0' ] ; then
|
# make limit uppercase in case it is set to NULL
|
||||||
# looks good, build SQL
|
limit=`echo $limit | tr [:lower:] [:upper:]`
|
||||||
cmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e \"INSERT INTO vm_domains SET domain='$domain'\""
|
if [[ "$limit" =~ ^[0-9]+$ ]] || [[ "$limit" == "NULL" ]]; then
|
||||||
if [ ! -z "$status" ] ; then
|
if [ ! -z "$dbset" ]; then
|
||||||
if [ "$status" == 0 ] || [ "$status" == 1 ]; then
|
dbset="$dbset,"
|
||||||
cmd="$cmd, status='$status'"
|
|
||||||
else
|
|
||||||
echo "ERROR: status (-s) must be 1 or 0"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
dbset="$dbset mbox_limit=\"$limit\""
|
||||||
|
else
|
||||||
|
echo "ERROR: limit (-l) must numeric or NULL"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [ ! -z "$limit" ] ; then
|
fi
|
||||||
if [[ "$limit" == "NULL" ]]; then
|
|
||||||
cmd="$cmd, mbox_limit=NULL"
|
# check for status update
|
||||||
elif [[ "$limit" =~ ^[0-9]+$ ]]; then
|
if [ ! -z "$status" ]; then
|
||||||
cmd="$cmd, mbox_limit='$limit'"
|
if [ "$status" == 0 ] || [ "$status" == 1 ]; then
|
||||||
else
|
if [ ! -z "$dbset" ]; then
|
||||||
echo "ERROR: limit (-l) must numeric or NULL"
|
dbset="$dbset,"
|
||||||
exit 1
|
fi
|
||||||
fi
|
dbset="$dbset status=\"$status\""
|
||||||
fi
|
else
|
||||||
if [ ! -z "$quota" ] ; then
|
echo "ERROR: status (-s) must be 1 or 0"
|
||||||
if [[ "$quota" == "NULL" ]]; then
|
exit
|
||||||
cmd="$cmd, mbox_quota_default=NULL"
|
fi
|
||||||
elif [[ "$quota" =~ ^[0-9]+$ ]]; then
|
fi
|
||||||
cmd="$cmd, mbox_quota_default='$quota'"
|
|
||||||
else
|
if [ -n "$dbset" ]; then
|
||||||
echo "ERROR: quota (-q) must numeric or NULL"
|
|
||||||
exit 1
|
# build query
|
||||||
fi
|
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e 'UPDATE vm_domains SET $dbset WHERE domain.id=\"$domain_id\";'"
|
||||||
fi
|
# eval $dbcmd
|
||||||
cmd="$cmd;"
|
echo $dbcmd
|
||||||
# add domain to vmail database
|
|
||||||
echo $cmd
|
else
|
||||||
elif [ "$rowcount" -eq '1' ] ; then
|
|
||||||
echo "ERROR: $domain already exists in vmail database."
|
echo "ERROR: No values passed for update."
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
echo "ERROR: System error querying vmail database"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue
Block a user