PostfixAdmin - web based virtual user administration interface for Postfix mail servers https://postfixadmin.github.io/postfixadmin/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
5.1 KiB

  1. <?php
  2. //
  3. // File: create-mailbox.php
  4. //
  5. // Template File: create-mailbox.tpl
  6. //
  7. // Template Variables:
  8. //
  9. // tMessage
  10. // tUsername
  11. // tName
  12. // tQuota
  13. // tDomain
  14. //
  15. // Form POST \ GET Variables:
  16. //
  17. // fUsername
  18. // fPassword
  19. // fPassword2
  20. // fName
  21. // fQuota
  22. // fDomain
  23. // fActive
  24. // fMail
  25. //
  26. require ("../variables.inc.php");
  27. require ("../config.inc.php");
  28. require ("../functions.inc.php");
  29. include ("../languages/" . $CONF['language'] . ".lang");
  30. $list_domains = list_domains ();
  31. if ($_SERVER['REQUEST_METHOD'] == "GET")
  32. {
  33. $tQuota = $CONF['maxquota'];
  34. $pCreate_mailbox_password_text = $PALANG['pCreate_mailbox_password_text'];
  35. $pCreate_mailbox_name_text = $PALANG['pCreate_mailbox_name_text'];
  36. $pCreate_mailbox_quota_text = $PALANG['pCreate_mailbox_quota_text'];
  37. include ("../templates/header.tpl");
  38. include ("../templates/admin_menu.tpl");
  39. include ("../templates/create-mailbox.tpl");
  40. include ("../templates/footer.tpl");
  41. }
  42. if ($_SERVER['REQUEST_METHOD'] == "POST")
  43. {
  44. $pCreate_mailbox_password_text = $PALANG['pCreate_mailbox_password_text'];
  45. $pCreate_mailbox_name_text = $PALANG['pCreate_mailbox_name_text'];
  46. $pCreate_mailbox_quota_text = $PALANG['pCreate_mailbox_quota_text'];
  47. $fUsername = $_POST['fUsername'] . "@" . $_POST['fDomain'];
  48. $fPassword = $_POST['fPassword'];
  49. $fPassword2 = $_POST['fPassword2'];
  50. $fName = $_POST['fName'];
  51. $fDomain = $_POST['fDomain'];
  52. if (isset ( $_POST['fQuota'])) $fQuota = $_POST['fQuota'];
  53. if (isset ( $_POST['fActive'])) $fActive = $_POST['fActive'];
  54. if (isset ( $_POST['fMail'])) $fMail = $_POST['fMail'];
  55. if (!check_mailbox ($fDomain))
  56. {
  57. $error = 1;
  58. $tUsername = $_POST['fUsername'];
  59. $tName = $fName;
  60. $tQuota = $fQuota;
  61. $tDomain = $fDomain;
  62. $pCreate_mailbox_username_text = $PALANG['pCreate_mailbox_username_text_error3'];
  63. }
  64. if (empty ($fUsername) or !check_email ($fUsername))
  65. {
  66. $error = 1;
  67. $tUsername = $_POST['fUsername'];
  68. $tName = $fName;
  69. $tQuota = $fQuota;
  70. $tDomain = $fDomain;
  71. $pCreate_mailbox_username_text = $PALANG['pCreate_mailbox_username_text_error1'];
  72. }
  73. if (empty ($fPassword) or ($fPassword != $fPassword2))
  74. {
  75. $error = 1;
  76. $tUsername = $_POST['fUsername'];
  77. $tName = $fName;
  78. $tQuota = $fQuota;
  79. $tDomain = $fDomain;
  80. $pCreate_mailbox_password_text = $PALANG['pCreate_mailbox_password_text_error'];
  81. }
  82. if (!check_quota ($fQuota, $fDomain))
  83. {
  84. $error = 1;
  85. $tUsername = $_POST['fUsername'];
  86. $tName = $fName;
  87. $tQuota = $fQuota;
  88. $tDomain = $fDomain;
  89. $pCreate_mailbox_quota_text = $PALANG['pCreate_mailbox_quota_text_error'];
  90. }
  91. $result = db_query ("SELECT * FROM alias WHERE address='$fUsername'");
  92. if ($result['rows'] == 1)
  93. {
  94. $error = 1;
  95. $tUsername = $_POST['fUsername'];
  96. $tName = $fName;
  97. $tQuota = $fQuota;
  98. $tDomain = $fDomain;
  99. $pCreate_mailbox_username_text = $PALANG['pCreate_mailbox_username_text_error2'];
  100. }
  101. if ($error != 1)
  102. {
  103. $password = pacrypt ($fPassword);
  104. if ($CONF['domain_path'] == "YES")
  105. {
  106. if ($CONF['domain_in_mailbox'] == "YES")
  107. {
  108. $maildir = $fDomain . "/" . $fUsername . "/";
  109. }
  110. else
  111. {
  112. $maildir = $fDomain . "/" . $_POST['fUsername'] . "/";
  113. }
  114. }
  115. else
  116. {
  117. $maildir = $fUsername . "/";
  118. }
  119. if (!empty ($fQuota)) $quota = $fQuota . "000000";
  120. if ($fActive == "on") $fActive = 1;
  121. $result = db_query ("INSERT INTO alias (address,goto,domain,created,modified,active) VALUES ('$fUsername','$fUsername','$fDomain',NOW(),NOW(),'$fActive')");
  122. if ($result['rows'] != 1)
  123. {
  124. $tDomain = $fDomain;
  125. $tMessage = $PALANG['pAlias_result_error'] . "<br />($fUsername -> $fUsername)</br />";
  126. }
  127. $result = db_query ("INSERT INTO mailbox (username,password,name,maildir,quota,domain,created,modified,active) VALUES ('$fUsername','$password','$fName','$maildir','$quota','$fDomain',NOW(),NOW(),'$fActive')");
  128. if ($result['rows'] != 1)
  129. {
  130. $tDomain = $fDomain;
  131. $tMessage .= $PALANG['pCreate_mailbox_result_error'] . "<br />($fUsername)<br />";
  132. }
  133. else
  134. {
  135. db_log ("site admin", $fDomain, "create mailbox", "$fUsername");
  136. $tDomain = $fDomain;
  137. $tMessage = $PALANG['pCreate_mailbox_result_succes'] . "<br />($fUsername)</br />";
  138. $tQuota = $CONF['maxquota'];
  139. if ($fMail == "on") {
  140. if (!mail ($fUsername, $PALANG['pSendmail_subject_text'], $PALANG['pSendmail_body_text'], "From:" . "Site Admin"))
  141. {
  142. $tMessage .= "<br />" . $PALANG['pSendmail_result_error'] . "<br />";
  143. }
  144. else
  145. {
  146. $tMessage .= "<br />" . $PALANG['pSendmail_result_succes'] . "<br />";
  147. }
  148. }
  149. }
  150. }
  151. include ("../templates/header.tpl");
  152. include ("../templates/admin_menu.tpl");
  153. include ("../templates/create-mailbox.tpl");
  154. include ("../templates/footer.tpl");
  155. }
  156. ?>