From cac5ad19a1d701a35b2dd6cf9a86b8938f3f9666 Mon Sep 17 00:00:00 2001 From: Daulton Tetreault Date: Sun, 1 Aug 2021 08:48:12 -0500 Subject: [PATCH] Added requested script for Alias Domains #5, as well as corresponding deletion script. --- README.md | 2 ++ Scripts/add-alias-domain.sh | 37 ++++++++++++++++++++++++++++++++++ Scripts/remove-alias-domain.sh | 35 ++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+) create mode 100755 Scripts/add-alias-domain.sh create mode 100755 Scripts/remove-alias-domain.sh diff --git a/README.md b/README.md index 34b691b..2f16cec 100755 --- a/README.md +++ b/README.md @@ -38,6 +38,8 @@ There are scripts so far to do the following administrative functions: | | set-alias-active.sh | Set an alias as active | | | set-alias-inactive.sh | Set an alias as inactive | | | is-address-an-alias.sh | Check if a given email address is an alias | +| | add-alias-domain.sh | Add an alias domain | +| | remove-alias-domain.sh | Remove an alias domain | | Forwarding | | | | | list-forwarding.sh | List any configured forwards | | | remove-forwarding.sh | Deletes mail forwarding from a given address to another entered address | diff --git a/Scripts/add-alias-domain.sh b/Scripts/add-alias-domain.sh new file mode 100755 index 0000000..c74b3a0 --- /dev/null +++ b/Scripts/add-alias-domain.sh @@ -0,0 +1,37 @@ +#!/bin/bash +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Add an alias domain in iRedMail. +# License: 2-clause BSD license +# +# Let's say you have a mail domain example.com hosted on your iRedMail server, if you add domain name domain.ltd as an alias domain of example.com, all emails sent to username@domain.ltd will be delivered to user username@example.com's mailbox. +# +# bash add-alias-domain.sh example.com domain.ltd +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# bash add-alias-domain.sh example.com domain.ltd > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -U vmailadmin -d vmail +# sql> \i /path/to/output.sql; + +# Read input +domain="$1" +domainAlias="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then + printf "Purpose: Add an alias domain in iRedMail. \n" + printf "Note: Let's say you have a mail domain example.com hosted on your iRedMail server, if you add domain name domain.ltd as an alias domain of example.com, all emails sent to username@domain.ltd will be delivered to user username@example.com's mailbox. \n" + printf "Usage: bash add-alias-domain.sh example.com domain.ltd \n" + exit 0 +fi + +printf "INSERT INTO alias_domain (alias_domain, target_domain) VALUES ('${domainAlias}', '${domain}'); \n" diff --git a/Scripts/remove-alias-domain.sh b/Scripts/remove-alias-domain.sh new file mode 100755 index 0000000..9762260 --- /dev/null +++ b/Scripts/remove-alias-domain.sh @@ -0,0 +1,35 @@ +#!/bin/bash +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Remove an alias domain in iRedMail. +# License: 2-clause BSD license +# +# bash remove-alias-domain.sh example.com domain.ltd +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# bash remove-alias-domain.sh example.com domain.ltd > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -U vmailadmin -d vmail +# sql> \i /path/to/output.sql; + +# Read input +domain="$1" +domainAlias="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then + printf "Purpose: Remove an alias domain in iRedMail. \n" + printf "Note: In the below example command the domain name domain.ltd is an alias domain of example.com. Adjust your command accordingly. \n" + printf "Usage: bash remove-alias-domain.sh example.com domain.ltd \n" + exit 0 +fi + +printf "DELETE FROM alias_domain WHERE alias_domain = '$domainAlias' AND target_domain = '$domain'; \n"