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.

183 lines
5.1 KiB

  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at :
  10. * http://www.postfixadmin.com or http://postfixadmin.sf.net
  11. *
  12. * @version $Id$
  13. * @license GNU GPL v2 or later.
  14. *
  15. * File: edit-mailbox.php
  16. * Used to update an existing mailboxes settings.
  17. * Template File: edit-mailbox.php
  18. *
  19. * Template Variables:
  20. *
  21. * tMessage
  22. * tName
  23. * tQuota
  24. *
  25. * Form POST \ GET Variables:
  26. *
  27. * fUsername
  28. * fDomain
  29. * fPassword
  30. * fPassword2
  31. * fName
  32. * fQuota
  33. * fActive
  34. */
  35. require_once('common.php');
  36. authentication_require_role('admin');
  37. $SESSID_USERNAME = authentication_get_username();
  38. $fUsername = 'x';
  39. $fDomain = 'y';
  40. $error = 0;
  41. if (isset ($_GET['username'])) $fUsername = escape_string ($_GET['username']);
  42. $fUsername = strtolower ($fUsername);
  43. if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  44. $pEdit_mailbox_name_text = $PALANG['pEdit_mailbox_name_text'];
  45. $pEdit_mailbox_quota_text = $PALANG['pEdit_mailbox_quota_text'];
  46. if (!(check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')) )
  47. {
  48. $error = 1;
  49. $tName = $fName;
  50. $tQuota = $fQuota;
  51. $tActive = $fActive;
  52. $tMessage = $PALANG['pEdit_mailbox_domain_error'] . "$fDomain</span>";
  53. }
  54. $result = db_query("SELECT * FROM $table_mailbox WHERE username = '$fUsername' AND domain = '$fDomain'");
  55. if($result['rows'] != 1) {
  56. die("Invalid username chosen; user does not exist in mailbox table");
  57. }
  58. $user_details = db_array($result['result']);
  59. if ($_SERVER['REQUEST_METHOD'] == "GET")
  60. {
  61. if (check_owner($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin'))
  62. {
  63. $tName = $user_details['name'];
  64. $tQuota = divide_quota($user_details['quota']);
  65. $tActive = $user_details['active'];
  66. if ('pgsql'==$CONF['database_type']) {
  67. $tActive = ('t'==$user_details['active']) ? 1 : 0;
  68. }
  69. $result = db_query ("SELECT * FROM $table_domain WHERE domain='$fDomain'");
  70. if ($result['rows'] == 1)
  71. {
  72. $row = db_array ($result['result']);
  73. $tMaxquota = $row['maxquota'];
  74. }
  75. }
  76. }
  77. if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['cancel'])) {
  78. header("Location: list-virtual.php?domain=$fDomain");
  79. exit(0);
  80. }
  81. if ($_SERVER['REQUEST_METHOD'] == "POST")
  82. {
  83. if (isset ($_POST['fPassword'])) $fPassword = escape_string ($_POST['fPassword']);
  84. if (isset ($_POST['fPassword2'])) $fPassword2 = escape_string ($_POST['fPassword2']);
  85. if (isset ($_POST['fName'])) $fName = escape_string ($_POST['fName']);
  86. if (isset ($_POST['fQuota'])) $fQuota = intval ($_POST['fQuota']);
  87. if (isset ($_POST['fActive'])) $fActive = escape_string ($_POST['fActive']);
  88. if($fPassword != $user_details['password'] || $fPassword2 != $user_details['password']){
  89. $min_length = $CONF['min_password_length'];
  90. if($fPassword == $fPassword2) {
  91. if ($fPassword != "") {
  92. if($min_length > 0 && strlen($fPassword) < $min_length) {
  93. flash_error(sprintf($PALANG['pPasswordTooShort'], $CONF['min_password_length']));
  94. $error = 1;
  95. }
  96. $formvars['password'] = pacrypt($fPassword);
  97. }
  98. }
  99. else {
  100. flash_error($PALANG['pEdit_mailbox_password_text_error']);
  101. $error = 1;
  102. }
  103. }
  104. if ($CONF['quota'] == "YES")
  105. {
  106. if (!check_quota ($fQuota, $fDomain))
  107. {
  108. $error = 1;
  109. $tName = $fName;
  110. $tQuota = $fQuota;
  111. $tActive = $fActive;
  112. $pEdit_mailbox_quota_text = $PALANG['pEdit_mailbox_quota_text_error'];
  113. }
  114. }
  115. if ($error != 1)
  116. {
  117. if (!empty ($fQuota))
  118. {
  119. $quota = multiply_quota ($fQuota);
  120. }
  121. else
  122. {
  123. $quota = 0;
  124. }
  125. if ($fActive == "on")
  126. {
  127. $sqlActive = db_get_boolean(True);
  128. $fActive = 1;
  129. }
  130. else
  131. {
  132. $sqlActive = db_get_boolean(False);
  133. $fActive = 0;
  134. }
  135. $formvars['name'] = $fName;
  136. $formvars['quota'] =$quota;
  137. $formvars['active']=$sqlActive;
  138. if(preg_match('/^(.*)@/', $fUsername, $matches)) {
  139. $formvars['local_part'] = $matches[1];
  140. }
  141. $result = db_update('mailbox', "username='$fUsername' AND domain='$fDomain'", $formvars, array('modified'));
  142. $maildir = $user_details['maildir'];
  143. if ($result != 1 || !mailbox_postedit($fUsername,$fDomain,$maildir, $quota)) {
  144. $tMessage = $PALANG['pEdit_mailbox_result_error'];
  145. }
  146. else {
  147. db_log ($SESSID_USERNAME, $fDomain, 'edit_mailbox', $fUsername);
  148. header ("Location: list-virtual.php?domain=$fDomain");
  149. exit(0);
  150. }
  151. }
  152. else
  153. {
  154. # error detected. Put the values the user entered in the form again.
  155. $tName = $fName;
  156. $tQuota = $fQuota;
  157. $tActive = $fActive;
  158. }
  159. }
  160. include ("templates/header.php");
  161. include ("templates/menu.php");
  162. include ("templates/edit-mailbox.php");
  163. include ("templates/footer.php");
  164. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  165. ?>