Changes to domain admin scripts, and added new scripts

This commit is contained in:
Daulton Tetreault 2020-05-18 13:34:08 -05:00
parent 2a2cd7aed6
commit b3d3459cf3
7 changed files with 82 additions and 4 deletions

View file

@ -17,8 +17,8 @@ There are scripts so far to do the following administrative functions:
| | 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 |
| | disable-mail-forwarding.sh | Re-activate a user account |
| | disable-user.sh | De-activate a user account |
| | enable-user.sh | Re-enables a disabled user account |
| | list-active-accounts.sh | List active user accounts |
| | list-inactive-accounts.sh | List inactive user accounts |
| | list-all-but-regular-accounts.sh | Lists all from the forwardings table that are not just regular accounts |

View file

@ -36,3 +36,11 @@ if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 2 ]; th
fi
printf "INSERT INTO domain_admins (username, domain, active) VALUES ('${username}', '${domain}', 1); \n"
printf "UPDATE mailbox SET isadmin = '1' WHERE username = '${username}';\n"
if [ "$domain" = "all" ] || [ "$domain" = "ALL" ]; then
printf "UPDATE mailbox SET isglobaladmin = '1' WHERE username = '${username}';\n"
else
printf "UPDATE mailbox SET isglobaladmin = '0' WHERE username = '${username}';\n"
fi

33
Scripts/disable-user.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/sh
#
# Author: Daulton
# Website: daulton.ca
# Purpose: Disables a user account in iRedmail.
# License: 2-clause BSD license
#
# Example usage: sh disable-user.sh jeff@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 disable-user.sh jeff@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 -U vmailadmin -d vmail
# sql> \i /path/to/output.sql;
# Read input
username="$1"
if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then
printf "Purpose: Disables a user account in iRedmail. \n"
printf "Usage: sh disable-user.sh jeff@example.com \n"
exit 0
fi
printf "UPDATE mailbox SET active = '0' WHERE username = '${username}';\n"

33
Scripts/enable-user.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/sh
#
# Author: Daulton
# Website: daulton.ca
# Purpose: Re-enables a disabled user account in iRedmail.
# License: 2-clause BSD license
#
# Example usage: sh enable-user.sh jeff@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 enable-user.sh jeff@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 -U vmailadmin -d vmail
# sql> \i /path/to/output.sql;
# Read input
username="$1"
if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; then
printf "Purpose: Re-enables a disabled user account in iRedmail. \n"
printf "Usage: sh enable-user.sh jeff@example.com \n"
exit 0
fi
printf "UPDATE mailbox SET active = '1' WHERE username = '${username}';\n"

View file

@ -31,3 +31,5 @@ if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -ne 1 ]; th
fi
printf "DELETE from domain_admins WHERE username = '${username}'; \n"
printf "UPDATE mailbox SET isadmin = '0' WHERE username = '${username}';\n"
printf "UPDATE mailbox SET isglobaladmin = '0' WHERE username = '${username}';\n"

View file

@ -10,7 +10,7 @@
# This will print SQL commands on the console directly, you can redirect the
# output to a file for further use like this:
#
# sh sh remove-user.sh jeff@example.com > output.sql
# sh remove-user.sh jeff@example.com > output.sql
#
# Import output.sql into SQL database like below:
#
@ -18,7 +18,7 @@
# mysql> USE vmail;
# mysql> SOURCE /path/to/output.sql;
#
# psql -d vmail
# psql -U vmailadmin -d vmail
# sql> \i /path/to/output.sql;
# Read input

View file

@ -31,3 +31,5 @@ if [ "$1" == "-h" ] || [ "$1" == "--h" ] || [ "$1" == "/h" ] || [ $# -lt 1 ] ||
fi
printf "UPDATE domain_admins SET active = '0' WHERE username = '$username';\n"
printf "UPDATE mailbox SET isadmin = '0' WHERE username = '${username}';\n"
printf "UPDATE mailbox SET isglobaladmin = '0' WHERE username = '${username}';\n"