alias del works
This commit is contained in:
parent
198afdfd63
commit
bd12a4ee26
|
@ -42,10 +42,6 @@ while getopts "achs" opt; do
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
|
|
||||||
dbcmdopts="-e"
|
|
||||||
dbquery="SELECT vm_aliases.alias, vm_mboxes.mbox, vm_domains.domain FROM vm_aliases, vm_mboxes, vm_domains WHERE vm_aliases.mbox_id = vm_mboxes.id AND vm_mboxes.domain_id = vm_domains.id"
|
|
||||||
|
|
||||||
# check for and set alias search term(s)
|
# check for and set alias search term(s)
|
||||||
if [ -n "$1" ]; then
|
if [ -n "$1" ]; then
|
||||||
if [ $1 == "-h" ]; then
|
if [ $1 == "-h" ]; then
|
||||||
|
@ -57,38 +53,35 @@ if [ -n "$1" ]; then
|
||||||
alias=${searchterm%@*}
|
alias=${searchterm%@*}
|
||||||
domain=${searchterm##*@}
|
domain=${searchterm##*@}
|
||||||
if ! vmail::validate_domain $domain; then
|
if ! vmail::validate_domain $domain; then
|
||||||
echo "ERROR: $searchterm is not a valid email address."
|
echo "ERROR: $domain is not a valid domain name."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif vmail::validate_domain $searchterm; then
|
|
||||||
domain=$searchterm
|
|
||||||
else
|
else
|
||||||
echo "ERROR: $searchterm is not a valid search term."
|
echo "ERROR: $searchterm is not a valid email alias."
|
||||||
help
|
help
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# build query
|
# build query
|
||||||
if [ -n "$domain" ]; then
|
dbcmd="mysql --defaults-extra-file=$MYSQL_CONNECTION_INFO_FILE"
|
||||||
# add specific domain
|
dbcmdopts="-s -r -N -e"
|
||||||
dbquery="$dbquery AND vm_domains.domain='$domain'"
|
|
||||||
if [ -n "$localpart" ]; then
|
# get aliases id which also works to confirm alias exists
|
||||||
# search for specific alias or mbox
|
dbquery="SELECT vm_aliases.id FROM vm_aliases, vm_mboxes, vm_domains WHERE vm_aliases.alias='$alias' AND vm_aliases.mbox_id=vm_mboxes.id AND vm_mboxes.domain_id=vm_domains.id AND vm_domains.domain='$domain'"
|
||||||
if [ -n "$aliassearch" ]; then
|
vm_aliases_id=`$dbcmd $dbcmdopts "$dbquery"`
|
||||||
# search for specific alias address
|
|
||||||
dbquery="$dbquery AND vm_aliases.alias='$localpart'"
|
if [ -z "$vm_aliases_id" ]; then
|
||||||
else
|
echo "ERROR: Alias $searchterm does not exist."
|
||||||
# search for all aliases for specific email address
|
exit 1
|
||||||
dbquery="$dbquery AND vm_mboxes.mbox='$localpart'"
|
elif [ "$vm_aliases_id" -gt '0' ]; then
|
||||||
fi
|
dbquery="DELETE FROM vm_aliases WHERE vm_aliases.id='$vm_aliases_id'"
|
||||||
fi
|
eval $dbcmd $dbcmdopts "\"$dbquery\""
|
||||||
|
echo "SUCCESS: Alias $searchterm removed from system."
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
echo "ERROR: System error querying vmail database"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# set order by
|
|
||||||
dbquery="$dbquery ORDER BY vm_domains.domain, vm_mboxes.mbox, vm_aliases.alias;";
|
|
||||||
|
|
||||||
# execute mysql query
|
|
||||||
eval $dbcmd $dbcmdopts "\"$dbquery\"" $cvs
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user