diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.md b/README.md old mode 100644 new mode 100755 index c593d7a..c95e13b --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -Administrative scripts for iRedMail, useful if you do not use iRedAdmin. +Administrative scripts for iRedMail, useful if you do not use iRedAdmin, or you do not have iRedAdmin Pro. Read the examples and usage in each script to understand the parameters to use. Each script will generate SQL for you to use. These scripts are for a iRedMail installation with an SQL back end, specifically PostgreSQL. @@ -8,7 +8,10 @@ There are scripts so far to do the following administrative functions: | ------------- | ----------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | | User accounts | | | | | create-new-user.sh | Creates a new user, with an optional feature of created users being a part of default aliases | -| | create-new-user-bulk.sh | Creates new users from a CSV file, with an optional feature of created users being a part of default aliases | | +| | create-new-user-bulk.sh | Creates new users from a CSV file, with an optional feature of created users being a part of default aliases | +| | add-domain-admin.sh | Makes an existing user a domain admin | +| | revoke-domain-admin.sh | Revokes a users domain administrator permission | +| | remove-domain-admin.sh | Remove a users entry entirely from the domain_admins table | | | remove-user.sh | Delete a user | | | update-account-password.sh | Update a users password | | | disable-mail-forwarding.sh | De-activate a user account | @@ -22,7 +25,8 @@ There are scripts so far to do the following administrative functions: | | disable-pop3-for-user.sh | Disables pop3 for a user account, prevents usage of this protocol | | | disable-pop3-for-domain.sh | Disables pop3 for all accounts on a given domain | | | disable-imap-for-user.sh | Disables IMAP for a user account, prevents usage of this protocol | -| | increase-mailbox-quota.sh | Increases the mail box quota size for a given user | +| | increase-mailbox-quota.sh | Increases the mail box quota size for a given user | +| | increase-all-mailbox-quota.sh | Increases the mail box quota size for all users regardless of domain, or for a specific domain | | Aliases | | | | | create-alias.sh | Create an alias | | | add-user-to-alias.sh | Add a user to an alias. Multiple users can be added to the same alias, use the script as many times as necessary. | @@ -34,14 +38,17 @@ There are scripts so far to do the following administrative functions: | Forwarding | | | | | list-forwarding.sh | List any configured forwards | | | remove-forwarding.sh | Deletes mail forwarding from a given address to another entered address | +| | remove-whole-forward.sh | Removes the whole forwarding address and all forwards associated to it | | | add-mail-forward.sh | Forward mail from one user account to another | | | is-forward-to.sh | List if any addresses are set to forward to a given address | | | is-forward-from.sh | List if any addresses are set to forward fromm a given address | | | disable-mail-forwarding.sh | Disables mail forwarding from a given address to another entered address, but do not delete the configured forward | | Domain | | | | | add-domain.sh | Creates a new domain in the database, after which you can begin creating user accounts in the new domain | +| | update-domain.sh | Change domain name of an existing domain and associated mail accounts | | | remove-domain.sh | Removes a domain from the database | -| | update-domain-quota.sh | Updates the domain wide mailbox quota | +| | update-domain-quota.sh | Updates the domain wide mailbox quota | +| | update-all-domain-quota.sh | Updates all existing domains with a new default mailbox quota | | | enable-domain.sh | Enables a domain in the database, must exist already | | | disable-domain.sh | Disables a domain in the database | | Misc | | | diff --git a/Scripts/add-domain-admin.sh b/Scripts/add-domain-admin.sh new file mode 100755 index 0000000..1fde6d0 --- /dev/null +++ b/Scripts/add-domain-admin.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Makes an existing user a domain admin in iRedMail. +# License: 2-clause BSD license +# +# Note: Replace ALL with a specific domain name if you want the user to be restricted to administer only +# a specific domain. +# +# sh new-domain-admin.sh user@example.com ALL +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh new-domain.sh example.com > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -d vmail +# sql> \i /path/to/output.sql; + +# Read input +username="$1" +domain="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then + printf "Purpose: Makes an existing user a domain admin in iRedMail. \n" + printf "Note: Replace ALL with a specific domain name if you want the user to be restricted to administer only a specific domain. \n" + printf "Usage: sh new-domain-admin.sh user@example.com ALL \n" + exit 0 +fi + +printf "INSERT INTO domain_admins (username, domain, active) VALUES ('${username}', '${domain}', 1); \n" diff --git a/Scripts/add-domain.sh b/Scripts/add-domain.sh old mode 100644 new mode 100755 index 5ad9142..2c0678c --- a/Scripts/add-domain.sh +++ b/Scripts/add-domain.sh @@ -26,7 +26,7 @@ # Read input domain="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Adds a new domain in iRedMail. \n" printf "Usage: sh new-domain.sh example.com \n" exit 0 diff --git a/Scripts/add-mail-forward.sh b/Scripts/add-mail-forward.sh old mode 100644 new mode 100755 index d46dc98..0fef85b --- a/Scripts/add-mail-forward.sh +++ b/Scripts/add-mail-forward.sh @@ -27,7 +27,7 @@ address="$1" forwardToEmail="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Creates a mail forwarding setup to direct email sent to user@example.com otherUser@example.com in iRedmail. \n" printf "Usage: sh add-mail-forward.sh user@example.com otherUser@example.com \n" exit 0 diff --git a/Scripts/add-user-to-alias.sh b/Scripts/add-user-to-alias.sh old mode 100644 new mode 100755 index 03c17a2..2a30ea2 --- a/Scripts/add-user-to-alias.sh +++ b/Scripts/add-user-to-alias.sh @@ -27,7 +27,7 @@ aliasAccount="$1" sendToEmail="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Add a user to an alias in iRedmail. \n" printf "Usage: sh add-user-to-alias.sh alias@mydomain.com jeff@gmail.com \n" exit 0 @@ -36,4 +36,4 @@ fi aliasAccountDomain=$(echo $aliasAccount | cut -f 2 -d '@') sendToEmailDomain=$(echo $sendToEmail | cut -f 2 -d '@') -printf "INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_list, active) VALUES ('${aliasAccount}', '${sendToEmail}', '${aliasAccountDomain}', '${sendToEmailDomain}', 1, 1); \n" +printf "INSERT INTO forwardings (address, forwarding, domain, dest_domain, is_list, active) VALUES ('${aliasAccount}', '${sendToEmail}', '${aliasAccountDomain}', '${sendToEmailDomain}', 0, 1); \n" diff --git a/Scripts/change-domain.sh b/Scripts/change-domain.sh new file mode 100755 index 0000000..848470d --- /dev/null +++ b/Scripts/change-domain.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Changes an existing domain to a different one in iRedMail. +# License: 2-clause BSD license +# Note: Once the new domain is added to iRedMail in the database, you can they use create-new-user.sh or create-new-user-bulk.sh scripts to add user accounts. +# The usage of this script is only necessary when adding NEW domains to iRedMail as during installation time your initial domain will be added. +# +# sh change-domain.sh old-domain.com new-domain.com +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh change-domain.sh old-domain.com new-domain.com > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -d vmail +# sql> \i /path/to/output.sql; + +# Read input +oldDomain="$1" +oldDomain="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 || [ $# -gt 2 ]; then + printf "Purpose: Changes an existing domain to a different one in iRedMail. \n" + printf "Usage: sh change-domain.sh old-domain.com new-domain.com \n" + exit 0 +fi + +printf "INSERT INTO domain VALUES domain = '$domain' AND active ='1';\n" diff --git a/Scripts/create-alias-policy.sh b/Scripts/create-alias-policy.sh old mode 100644 new mode 100755 index 10c4ee8..ff58204 --- a/Scripts/create-alias-policy.sh +++ b/Scripts/create-alias-policy.sh @@ -35,7 +35,7 @@ dlName="$1" policy="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Creates or updates an access policy for an alias to restrict which senders are allowed to send email to this mail alias, in iRedMail. \n" printf "Available access policies: \n" printf "public no restrictions \n" diff --git a/Scripts/create-alias.sh b/Scripts/create-alias.sh old mode 100644 new mode 100755 index 14abc74..6440d09 --- a/Scripts/create-alias.sh +++ b/Scripts/create-alias.sh @@ -25,7 +25,7 @@ dlName="$1" domainName="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Creates an alias in iRedmail, email sent to an alias goes to all addresses added onto the alias. \n" printf "Usage: sh create-alias.sh alias@mydomain.com mydomain.com \n" exit 0 diff --git a/Scripts/create-new-user-bulk.sh b/Scripts/create-new-user-bulk.sh old mode 100644 new mode 100755 diff --git a/Scripts/create-new-user.sh b/Scripts/create-new-user.sh old mode 100644 new mode 100755 diff --git a/Scripts/disable-domain.sh b/Scripts/disable-domain.sh old mode 100644 new mode 100755 index 62dd6aa..c5c105a --- a/Scripts/disable-domain.sh +++ b/Scripts/disable-domain.sh @@ -24,7 +24,7 @@ # Read input domain="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Disables a domain in iRedMail. \n" printf "Usage: sh disable-domain.sh example.com \n" exit 0 diff --git a/Scripts/disable-imap-for-user.sh b/Scripts/disable-imap-for-user.sh old mode 100644 new mode 100755 index 50ebfd4..97991b8 --- a/Scripts/disable-imap-for-user.sh +++ b/Scripts/disable-imap-for-user.sh @@ -24,7 +24,7 @@ # Read input username="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Disables enableimap,enableimapsecured,enableimaptls in the mailbox table for a given user to be 0 (disabled) in iRedmail so to disable IMAP. \n" printf "Usage: sh disable-imap-for-user.sh jeff@example.com \n" exit 0 diff --git a/Scripts/disable-mail-forwarding.sh b/Scripts/disable-mail-forwarding.sh old mode 100644 new mode 100755 index 223fd89..9467f2a --- a/Scripts/disable-mail-forwarding.sh +++ b/Scripts/disable-mail-forwarding.sh @@ -25,7 +25,7 @@ fromUser="$1" toUser="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Disable mail forwarding or from an alias, from a user account to another mail account in iRedmail. \n" printf "Usage: sh disable-mail-forwarding.sh fromUser@example.com toUser@example.com \n" exit 0 diff --git a/Scripts/disable-pop3-for-domain.sh b/Scripts/disable-pop3-for-domain.sh old mode 100644 new mode 100755 index 8a8ff45..7e98064 --- a/Scripts/disable-pop3-for-domain.sh +++ b/Scripts/disable-pop3-for-domain.sh @@ -28,7 +28,7 @@ # Read input domain="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Disables enablepop3,enablepop3secured,enablepop3tls in the mailbox table for a given domain to be 0 (disabled) in iRedmail so to disable pop3. \n" printf "Usage: sh disable-pop3-for-domain.sh example.com \n" exit 0 diff --git a/Scripts/disable-pop3-for-user.sh b/Scripts/disable-pop3-for-user.sh old mode 100644 new mode 100755 index d80bd1b..b067da5 --- a/Scripts/disable-pop3-for-user.sh +++ b/Scripts/disable-pop3-for-user.sh @@ -24,7 +24,7 @@ # Read input username="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Disables enablepop3,enablepop3secured,enablepop3tls in the mailbox table for a given user to be 0 (disabled) in iRedmail so to disable pop3. \n" printf "Usage: sh disable-pop3-for-user.sh jeff@example.com \n" exit 0 diff --git a/Scripts/enable-domain.sh b/Scripts/enable-domain.sh old mode 100644 new mode 100755 index 7a7507d..3f76b58 --- a/Scripts/enable-domain.sh +++ b/Scripts/enable-domain.sh @@ -24,7 +24,7 @@ # Read input domain="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Re-enables a disabled domain in iRedMail. \n" printf "Usage: sh enable-domain.sh example.com \n" exit 0 diff --git a/Scripts/enable-imap-for-user.sh b/Scripts/enable-imap-for-user.sh old mode 100644 new mode 100755 index 9c7fe3a..f05af67 --- a/Scripts/enable-imap-for-user.sh +++ b/Scripts/enable-imap-for-user.sh @@ -24,7 +24,7 @@ # Read input username="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Enables enableimap,enableimapsecured,enableimaptls in the mailbox table for a given user to be 1 (enabled) in iRedmail so to enable IMAP. \n" printf "Usage: sh enable-imap-for-user.sh jeff@example.com \n" exit 0 diff --git a/Scripts/enable-mail-forwarding.sh b/Scripts/enable-mail-forwarding.sh old mode 100644 new mode 100755 index 6762d84..ca4d3cb --- a/Scripts/enable-mail-forwarding.sh +++ b/Scripts/enable-mail-forwarding.sh @@ -25,7 +25,7 @@ fromUser="$1" toUser="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Re-enable mail forwarding or from an alias, from a user account to another mail account in iRedmail. \n" printf "Usage: sh enable-mail-forwarding.sh fromUser@example.com toUser@example.com \n" exit 0 diff --git a/Scripts/enable-pop3-for-domain.sh b/Scripts/enable-pop3-for-domain.sh old mode 100644 new mode 100755 index 6302203..b8ced1c --- a/Scripts/enable-pop3-for-domain.sh +++ b/Scripts/enable-pop3-for-domain.sh @@ -28,7 +28,7 @@ # Read input domain="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Enables enablepop3,enablepop3secured,enablepop3tls in the mailbox table for a given domain to be 1 (enabled) in iRedmail so to enable pop3. \n" printf "Usage: sh enable-pop3-for-domain.sh example.com \n" exit 0 diff --git a/Scripts/enable-pop3-for-user.sh b/Scripts/enable-pop3-for-user.sh old mode 100644 new mode 100755 index 2dd5c0f..cdeea56 --- a/Scripts/enable-pop3-for-user.sh +++ b/Scripts/enable-pop3-for-user.sh @@ -24,7 +24,7 @@ # Read input username="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Enables enablepop3,enablepop3secured,enablepop3tls in the mailbox table for a given user to be 1 (enabled) in iRedmail so to disable pop3. \n" printf "Usage: sh enable-pop3-for-user.sh jeff@example.com \n" exit 0 diff --git a/Scripts/generate_password_hash.py b/Scripts/generate_password_hash.py old mode 100644 new mode 100755 diff --git a/Scripts/increase-all-mailbox-quota.sh b/Scripts/increase-all-mailbox-quota.sh new file mode 100755 index 0000000..b3e4374 --- /dev/null +++ b/Scripts/increase-all-mailbox-quota.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Increases the mail box quota size for all users regardless of domain, or for a specific domain, in iRedmail. +# License: 2-clause BSD license +# +# Note: Enter the size as mb. The default quota is 1024 mb. Replace the domain name with an asterisk (*) to update all current users with the new mailbox quota size. +# +# Example usage: sh increase-all-mailbox-quota.sh example.com 2048 +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh increase-all-mailbox-quota.sh example.com 2048 > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -d vmail +# sql> \i /path/to/output.sql; + +# Read input +domain="$1" +quota="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then + printf "Purpose: Increases the mail box quota size for all users regardless of domain, or for a specific domain, in iRedmail. \n" + printf "Note: Replace the domain name with a quoted asterisk (*) to update all current users with the new mailbox quota size." + printf "Usage: sh increase-all-mailbox-quota.sh example.com 2048 OR sh increase-all-mailbox-quota.sh \"*\" 2048 \n" + exit 0 +fi + +if [ "$domain" != "*" ]; then + printf "UPDATE mailbox SET quota = '${quota}' WHERE domain = '${domain}'; \n" +else + printf "UPDATE mailbox SET quota = '${quota}'; \n" +fi diff --git a/Scripts/increase-mailbox-quota.sh b/Scripts/increase-mailbox-quota.sh old mode 100644 new mode 100755 index 82e7a94..d2851e7 --- a/Scripts/increase-mailbox-quota.sh +++ b/Scripts/increase-mailbox-quota.sh @@ -27,7 +27,7 @@ address="$1" quota="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Updates the allowed mailbox size (quota) for a user in iRedmail. \n" printf "Usage: sh increase-mailbox-quota.sh jeff@example.com 2048 \n" exit 0 diff --git a/Scripts/is-address-an-alias.sh b/Scripts/is-address-an-alias.sh old mode 100644 new mode 100755 index ddafdfb..8e0899b --- a/Scripts/is-address-an-alias.sh +++ b/Scripts/is-address-an-alias.sh @@ -25,7 +25,7 @@ # Read input address="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Determine if a given email address is an alias in iRedmail. \n" printf "Usage: sh is-address-an-alias.sh jeff@example.com \n" exit 0 diff --git a/Scripts/is-forward-from.sh b/Scripts/is-forward-from.sh old mode 100644 new mode 100755 index aae9b0e..857a55b --- a/Scripts/is-forward-from.sh +++ b/Scripts/is-forward-from.sh @@ -24,7 +24,7 @@ # Read input address="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Determine if a given email address has forwards set from itself to other email addreses in iRedmail. \n" printf "Usage: sh is-forward-from.sh jeff@example.com \n" exit 0 diff --git a/Scripts/is-forward-to.sh b/Scripts/is-forward-to.sh old mode 100644 new mode 100755 index d2c58ca..248edbc --- a/Scripts/is-forward-to.sh +++ b/Scripts/is-forward-to.sh @@ -25,7 +25,7 @@ # Read input address="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Determine if a given email address has forwards set from itself to other email addreses in iRedmail. \n" printf "Usage: sh is-forward-to.sh jeff@example.com \n" exit 0 diff --git a/Scripts/list-active-accounts.sh b/Scripts/list-active-accounts.sh old mode 100644 new mode 100755 index 85f70a0..58ae813 --- a/Scripts/list-active-accounts.sh +++ b/Scripts/list-active-accounts.sh @@ -21,7 +21,7 @@ # psql -d vmail # sql> \i /path/to/output.sql; -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -gt 0 ]; then printf "Purpose: Lists active email accounts in iRedmail. \n" printf "Usage: sh list-active-accounts.sh \n" exit 0 diff --git a/Scripts/list-all-accounts.sh b/Scripts/list-all-accounts.sh old mode 100644 new mode 100755 index 724ad48..0e6eca8 --- a/Scripts/list-all-accounts.sh +++ b/Scripts/list-all-accounts.sh @@ -21,7 +21,7 @@ # psql -d vmail # sql> \i /path/to/output.sql; -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -gt 0 ]; then printf "Purpose: Lists all email accounts in iRedmail from the mailbox table, does not include aliases. \n" printf "Usage: sh list-all-accounts.sh \n" exit 0 diff --git a/Scripts/list-all-but-regular-accounts.sh b/Scripts/list-all-but-regular-accounts.sh old mode 100644 new mode 100755 index 03ebd1a..5493381 --- a/Scripts/list-all-but-regular-accounts.sh +++ b/Scripts/list-all-but-regular-accounts.sh @@ -21,7 +21,7 @@ # psql -d vmail # sql> \i /path/to/output.sql; -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -gt 0 ]; then printf "Purpose: Lists all from the forwardings table that are not just regular accounts in iRedmail. \n" printf "Usage: sh list-all-but-regular-accounts.sh \n" exit 0 diff --git a/Scripts/list-forwarding.sh b/Scripts/list-forwarding.sh old mode 100644 new mode 100755 index 5c14e31..b13db97 --- a/Scripts/list-forwarding.sh +++ b/Scripts/list-forwarding.sh @@ -21,7 +21,7 @@ # psql -d vmail # sql> \i /path/to/output.sql; -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -gt 0 ]; then printf "Purpose: Lists all active email forwarding configurations in iRedmail. \n" printf "Usage: sh list-forwarding-active.sh \n" exit 0 diff --git a/Scripts/list-inactive-accounts.sh b/Scripts/list-inactive-accounts.sh old mode 100644 new mode 100755 index b7527ba..3907abc --- a/Scripts/list-inactive-accounts.sh +++ b/Scripts/list-inactive-accounts.sh @@ -21,7 +21,7 @@ # psql -d vmail # sql> \i /path/to/output.sql; -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -gt 0 ]; then printf "Purpose: Lists inactive email accounts in iRedmail. \n" printf "Usage: sh list-inactive-accounts.sh \n" exit 0 diff --git a/Scripts/list-largest-to-smallest-mailbox.sh b/Scripts/list-largest-to-smallest-mailbox.sh old mode 100644 new mode 100755 index da8513a..455f350 --- a/Scripts/list-largest-to-smallest-mailbox.sh +++ b/Scripts/list-largest-to-smallest-mailbox.sh @@ -21,7 +21,7 @@ # psql -d vmail # sql> \i /path/to/output.sql; -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -gt 0 ]; then printf "Purpose: Lists mailboxes in vmail db in used_quota from largest to smallest in iRedmail. \n" printf "Usage: sh list-largest-to-smallest-mailbox.sh \n" exit 0 diff --git a/Scripts/list-top-10-mailbox.sh b/Scripts/list-top-10-mailbox.sh old mode 100644 new mode 100755 index 6a98e26..b5263ce --- a/Scripts/list-top-10-mailbox.sh +++ b/Scripts/list-top-10-mailbox.sh @@ -21,7 +21,7 @@ # psql -d vmail # sql> \i /path/to/output.sql; -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -gt 0 ]; then printf "Purpose: Lists top 10 mailboxes in vmail db in used_quota from largest to smallest in iRedmail. \n" printf "Usage: sh list-top-10-mailbox.sh \n" exit 0 diff --git a/Scripts/remove-alias.sh b/Scripts/remove-alias.sh old mode 100644 new mode 100755 index de1092d..b8c1b34 --- a/Scripts/remove-alias.sh +++ b/Scripts/remove-alias.sh @@ -24,7 +24,7 @@ # Read input aliasName="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Creates an alias address which can be used to send email to multiple users at once when they are added 'onto' the alias in iRedmail. \n" printf "Usage: \n" exit 0 diff --git a/Scripts/remove-domain-admin.sh b/Scripts/remove-domain-admin.sh new file mode 100755 index 0000000..7c87667 --- /dev/null +++ b/Scripts/remove-domain-admin.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Remove a users entry entirely from the domain_admins table in iRedMail. +# License: 2-clause BSD license +# +# sh remove-domain-admin.sh user@example.com +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh remove-domain-admin.sh user@example.com > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -d vmail +# sql> \i /path/to/output.sql; + +# Read input +username="$1" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then + printf "Purpose: Remove a users entry entirely from the domain_admins table in iRedMail. \n" + printf "Usage: sh remove-domain-admin.sh user@example.com \n" + exit 0 +fi + +printf "DELETE from domain_admins WHERE username = '${username}'; \n" diff --git a/Scripts/remove-domain.sh b/Scripts/remove-domain.sh old mode 100644 new mode 100755 index f014519..b617011 --- a/Scripts/remove-domain.sh +++ b/Scripts/remove-domain.sh @@ -25,7 +25,7 @@ # Read input domain="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Remove a domain from iRedMail. This does not remove associates mail accounts or mailboxes. \n" printf "Usage: sh remove-domain.sh example.com \n" exit 0 diff --git a/Scripts/remove-forwarding.sh b/Scripts/remove-forwarding.sh old mode 100644 new mode 100755 index c6a510f..a3ef250 --- a/Scripts/remove-forwarding.sh +++ b/Scripts/remove-forwarding.sh @@ -25,7 +25,7 @@ address="$1" destinationAddress="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Remove mail forwarding for a user or remove a user from an alias in iRedmail. \n" printf "Usage: sh remove-forwarding.sh alias@mydomain.com jeff@gmail.com \n" exit 0 diff --git a/Scripts/remove-user.sh b/Scripts/remove-user.sh old mode 100644 new mode 100755 index a20ede5..9ee59df --- a/Scripts/remove-user.sh +++ b/Scripts/remove-user.sh @@ -24,7 +24,7 @@ # Read input address="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Removes a user account from the database in iRedmail, this does not delete the mailbox stored on the filesystem. \n" printf "Usage: sh remove-user.sh jeff@example.com \n" exit 0 diff --git a/Scripts/remove-whole-forward.sh b/Scripts/remove-whole-forward.sh new file mode 100755 index 0000000..07cc83d --- /dev/null +++ b/Scripts/remove-whole-forward.sh @@ -0,0 +1,34 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Removes the whole forwarding address and all forwards associated to it in iRedMail. +# License: 2-clause BSD license +# +# Example usage: sh remove-whole-forward.sh contact@mydomain.com +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh remove-whole-forward.sh contact@mydomain.com > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -d vmail +# sql> \i /path/to/output.sql; + +# Read input +address="$1" +destinationAddress="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then + printf "Purpose: Removes the whole forwarding address and all forwards associated to it in iRedMail. \n" + printf "Usage: sh remove-whole-forward.sh contact@mydomain.com \n" + exit 0 +fi + +printf "DELETE FROM forwardings WHERE address = '${address}'; \n" diff --git a/Scripts/revoke-domain-admin.sh b/Scripts/revoke-domain-admin.sh new file mode 100755 index 0000000..3f8c80e --- /dev/null +++ b/Scripts/revoke-domain-admin.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Revokes a users domain administrator permission in iRedMail. +# License: 2-clause BSD license +# +# sh revoke-domain-admin.sh user@example.com +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh revoke-domain-admin.sh user@example.com > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -d vmail +# sql> \i /path/to/output.sql; + +# Read input +username="$1" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 1 ] || [ $# -gt 1 ]; then + printf "Purpose: Revokes a users domain administrator permission in iRedMail. \n" + printf "Usage: sh revoke-domain-admin.sh user@example.com \n" + exit 0 +fi + +printf "UPDATE domain_admins SET active = '0' WHERE username = '$username';\n" diff --git a/Scripts/set-account-active.sh b/Scripts/set-account-active.sh old mode 100644 new mode 100755 index 0ea2b7a..9376e12 --- a/Scripts/set-account-active.sh +++ b/Scripts/set-account-active.sh @@ -24,7 +24,7 @@ # Read input address="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Re-activate a user account iRedmail. \n" printf "Usage: sh set-account-active.sh jeff@example.com \n" exit 0 diff --git a/Scripts/set-account-inactive.sh b/Scripts/set-account-inactive.sh old mode 100644 new mode 100755 index 0f0952d..cb9755b --- a/Scripts/set-account-inactive.sh +++ b/Scripts/set-account-inactive.sh @@ -24,7 +24,7 @@ # Read input address="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Deactivate a user account iRedmail. \n" printf "Usage: sh set-account-inactive.sh jeff@example.com \n" exit 0 diff --git a/Scripts/set-alias-active.sh b/Scripts/set-alias-active.sh old mode 100644 new mode 100755 index 352874b..7e40116 --- a/Scripts/set-alias-active.sh +++ b/Scripts/set-alias-active.sh @@ -24,7 +24,7 @@ # Read input aliasName="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Re-activates, or turns back on, an alias in iRedmail. \n" printf "Usage: sh set-alias-active.sh alias@mydomain.com \n" exit 0 diff --git a/Scripts/set-alias-inactive.sh b/Scripts/set-alias-inactive.sh old mode 100644 new mode 100755 index d12301c..c537f57 --- a/Scripts/set-alias-inactive.sh +++ b/Scripts/set-alias-inactive.sh @@ -24,7 +24,7 @@ # Read input aliasName="$1" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -eq 0 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then printf "Purpose: Updates an alias to become inactive in iRedmail. \n" printf "Usage: sh set-alias-inactive.sh alias@mydomain.com \n" exit 0 diff --git a/Scripts/update-account-password.sh b/Scripts/update-account-password.sh old mode 100644 new mode 100755 index baeb68e..1cdd42a --- a/Scripts/update-account-password.sh +++ b/Scripts/update-account-password.sh @@ -32,7 +32,7 @@ address="$1" password="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Updates the password for a user account in iRedmail. \n" printf "Note: You can also use this script to change hashing algorithms. If you made an account with SHA512 but actually wanted bcrypt you can change that by updating the password." printf "Instructions: diff --git a/Scripts/update-all-domain-quota.sh b/Scripts/update-all-domain-quota.sh new file mode 100755 index 0000000..aeda2c6 --- /dev/null +++ b/Scripts/update-all-domain-quota.sh @@ -0,0 +1,35 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Updates the default quota for mailbox size for all domains, setting applies to all newly created mailboxes, in iRedmail. +# License: 2-clause BSD license +# +# Note: 2048 is the new domain quota for NEWLY created mailboxes. +# sh update-all-quota.sh example.com 2048 +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh update-all-domain-quota.sh 2048 > output.sql +# +# Import output.sql into SQL database like below: +# +# mysql -uroot -p +# mysql> USE vmail; +# mysql> SOURCE /path/to/output.sql; +# +# psql -d vmail +# sql> \i /path/to/output.sql; + +# Read input +domain="$1" +quota="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then + printf "Purpose: Updates the default quota for mailbox size for all domains, setting applies to all newly created mailboxes, in iRedmail. \n" + printf "Usage: sh update-all-domain-quota.sh 2048 \n" + exit 0 +fi + +printf "UPDATE domain SET settings = 'default_user_quota:$quota;';\n" diff --git a/Scripts/update-domain-quota.sh b/Scripts/update-domain-quota.sh old mode 100644 new mode 100755 index b05e5db..f9dbcb1 --- a/Scripts/update-domain-quota.sh +++ b/Scripts/update-domain-quota.sh @@ -26,7 +26,7 @@ domain="$1" quota="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Updates the default quota for mailbox size for a domain in iRedmail. \n" printf "Usage: sh update-domain-quota.sh example.com 2048 \n" exit 0 diff --git a/Scripts/update-domain.sh b/Scripts/update-domain.sh new file mode 100755 index 0000000..ceedb15 --- /dev/null +++ b/Scripts/update-domain.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# +# Author: Daulton +# Website: daulton.ca +# Purpose: Change domain name of an existing domain and associated mail accounts in iRedmail. +# License: 2-clause BSD license +# +# WARNING: This changes ONLY the SQL side, the mail directory needs to be renamed as well as any existing maildir to reflect the new domain. +# +# sh update-domain.sh old-domain.com new-domain.com +# +# This will print SQL commands on the console directly, you can redirect the +# output to a file for further use like this: +# +# sh update-domain.sh old-domain.com new-domain.com > 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 +current="$1" +new="$2" + +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then + printf "Purpose: Change domain name of an existing domain and associated mail accounts in iRedmail. \n" + printf "WARNING: This changes ONLY the SQL side, the mail directory needs to be renamed as well as any existing maildir to reflect the new domain. \n" + printf "Usage: sh update-domain.sh old-domain.com new-domain.com \n" + exit 0 +fi + +# alias table +printf "UPDATE alias SET domain = '$new' WHERE domain = '$current';\n" +printf "UPDATE alias SET username = replace(username, '$current', '$new') WHERE address LIKE '$current'';\n" + +# deleted_mailboxes table +printf "UPDATE deleted_mailboxes SET maildir = regexp_replace(maildir, '\m$current\M', '$new', 'gi') WHERE domain LIKE '$current';\n" +printf "UPDATE deleted_mailboxes SET username = regexp_replace(username, '\m$current\M', '$new', 'gi') WHERE domain LIKE '$current';\n" +printf "UPDATE deleted_mailboxes SET domain = '$new' WHERE domain = '$current';\n" + +# domain table +printf "UPDATE domain SET domain = '$new' WHERE domain = '$current';\n" + +# domain_admins table +printf "UPDATE domain_admins SET username = regexp_replace(username, '\m$current\M', '$new', 'gi') WHERE username LIKE '%$current';\n" + +# forwardings table +printf "UPDATE forwardings SET address = regexp_replace(address, '\m$current\M', '$new', 'gi') WHERE domain LIKE '$current';\n" +printf "UPDATE forwardings SET forwarding = regexp_replace(forwarding, '\m$current\M', '$new', 'gi') WHERE dest_domain LIKE '$current';\n" +printf "UPDATE forwardings SET domain = '$new' WHERE domain = '$current';\n" +printf "UPDATE forwardings SET dest_domain = '$new' WHERE dest_domain = '$current';\n" + +# mailbox table +printf "UPDATE mailbox SET maildir = regexp_replace(maildir, '\m$current\M', '$new', 'gi') WHERE domain LIKE '$current';\n" +printf "UPDATE mailbox SET username = regexp_replace(username, '\m$current\M', '$new', 'gi') WHERE domain LIKE '$current';\n" +printf "UPDATE mailbox SET domain = '$new' WHERE domain = '$current';\n" + +# used_quota table +printf "UPDATE used_quota SET username = regexp_replace(username, '\m$current\M', '$new', 'gi') WHERE domain LIKE '$current';\n" +printf "UPDATE used_quota SET domain = '$new' WHERE domain = '$current';\n" + diff --git a/Scripts/update-storagebasedirectory.sh b/Scripts/update-storagebasedirectory.sh old mode 100644 new mode 100755 index 90a03f7..1eee6d4 --- a/Scripts/update-storagebasedirectory.sh +++ b/Scripts/update-storagebasedirectory.sh @@ -28,7 +28,7 @@ current="$1" new="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Updates the storagebasedirectory in iRedmail, this by default is /var/vmail. \n" printf "Usage: sh update-storagebasedirectory.sh /var/vmail /var/someNewLocation \n" exit 0 diff --git a/Scripts/update-storagenode.sh b/Scripts/update-storagenode.sh old mode 100644 new mode 100755 index 98f8526..4b5272d --- a/Scripts/update-storagenode.sh +++ b/Scripts/update-storagenode.sh @@ -28,7 +28,7 @@ current="$1" new="$2" -if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 2 ]; then +if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; then printf "Purpose: Updates the storagenode in iRedmail, this by default is vmail1. \n" printf "Usage: sh update-storagenode.sh vmail1 vmail2 \n" exit 0