#!/bin/bash # # vmail-stack # https://git.stack-source.com/msb/vmail-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)/vmail.sh help() { thisfilename=$(basename -- "$0") echo "Modify an existing domain." echo "" echo "usage: $thisfilename -d [OPTIONS]" echo "" echo " -h Print this help." echo " -d Domain to be modified." echo " -l Mailbox limit - the maximum number of mailboxes under this domain." echo " -q Mailbox Quota Default in GB - default quota for new mailboxes under this domain." echo " -r Default mailbox sending rate limit per hour, multiplied by 10 for limit per day." echo " -s <0|1> Status. 1 for enabled, 0 for disabled. Default is in db structure and is normally set to 1." exit } vmail:getoptions "$@" # check for domain if [[ -n $domain ]]; then domain_id=`mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -s -r -N -e "SELECT id from vm_domains WHERE domain='$domain';"` if [ -z $domain_id ] ; then echo "ERROR: Email domain $domain does not exist." exit fi else echo "domain name is required" exit 1 fi # set update portion of command to empty string dbset="" # 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 # check for ratelimit update if [[ -n $ratelimit ]]; then # make ratelimit uppercase in case it is set to NULL ratelimit=`echo $ratelimit | tr [:lower:] [:upper:]` if [[ "$ratelimit" =~ ^[0-9]+$ ]] || [[ "$ratelimit" == "NULL" ]]; then if [ ! -z "$dbset" ]; then dbset="$dbset," fi dbset="$dbset mbox_ratelimit_default=$ratelimit" else echo "ERROR: ratelimit (-r) must numeric or NULL" exit 1 fi fi # check for limit update if [[ -n $limit ]]; then # make limit uppercase in case it is set to NULL limit=`echo $limit | tr [:lower:] [:upper:]` if [[ "$limit" =~ ^[0-9]+$ ]] || [[ "$limit" == "NULL" ]]; then if [ ! -z "$dbset" ]; then dbset="$dbset," fi dbset="$dbset mbox_limit=$limit" else echo "ERROR: limit (-l) must numeric or NULL" exit 1 fi fi # check for status update if [[ -n $status ]]; then if [ "$status" == 0 ] || [ "$status" == 1 ]; then if [ ! -z "$dbset" ]; then dbset="$dbset," fi dbset="$dbset status=\"$status\"" else echo "ERROR: status (-s) must be 1 or 0" exit 1 fi fi if [ -n "$dbset" ]; then # build query dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE -e 'UPDATE vm_domains SET $dbset WHERE id=\"$domain_id\";'" eval $dbcmd else echo "ERROR: No values passed for update." exit 1 fi