Advertisement
nhneutrino

Untitled

Mar 7th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.36 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. echo "Candlekeep maildir creator by NH3CL"
  4. echo "Version: 1.1 - 2015.08.17"
  5.  
  6. users="/home/vmail/users"
  7.  
  8. echo -n "Give domain [ENTER]: "
  9. read domain
  10. echo -n "Give the username [ENTER]:"
  11. read user
  12. echo -n "Mailbox size (MB):"
  13. read mailboxsize
  14. echo
  15.  
  16. grep -i "$user@$domain" "$users"
  17.  
  18. if  [ $? == 0 ]; then
  19.   echo -e "\e[4;31mERROR:\e[0m Mailbox already exists, exit."
  20.   exit 1
  21. else
  22.  
  23. #If folder not exists, create
  24.     if [ ! -d "/home/vmail/$domain" ]; then
  25.  mkdir "/home/vmail/$domain"
  26.     fi
  27. #go to folder
  28. cd "/home/vmail/$domain"
  29.  
  30. #Creating mailbox
  31.  maildirmake.courier $user
  32. fi
  33.  
  34. #giving rights to system user
  35. chown -R vmail:vmail /home/vmail/$domain
  36.  
  37. #Write into the textfile. Full e-mail address
  38. echo -e "$user@$domain" >> $users
  39.  
  40. #Write into the database
  41. mysql -h localhost -umail_admin -p[password] <<EOF
  42. use mail;
  43. INSERT INTO domains(domain) VALUES('$domain');
  44. EOF
  45.  
  46. #Generating password (A-Z, a-z, 0-9)
  47. password=$(makepasswd --chars 8)
  48.  
  49. #Mailbox size convert to byte
  50. bytemailboxsize=$(($mailboxsize*1024*1024))
  51.  
  52. #Writeing mailbox details into database
  53. mysql -h localhost -umail_admin -p[password] <<EOF
  54. use mail;
  55. INSERT INTO users(email,password,quota) VALUES('$user@$domain',ENCRYPT('$password'),'$bytemailboxsize');
  56. EOF
  57.  
  58.  
  59. echo -e "Congratulation \e[32m$user@$domain\e[0m created. Password: \e[32m$password\e[0m Thanks!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement