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.

165 lines
4.3 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.tpl
  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. $result = db_query("SELECT * FROM $table_mailbox WHERE username = '$fUsername' AND domain = '$fDomain'");
  47. if($result['rows'] != 1) {
  48. die("Invalid username chosen; user does not exist in mailbox table");
  49. }
  50. if (!(check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')) )
  51. {
  52. $error = 1;
  53. $tName = $fName;
  54. $tQuota = $fQuota;
  55. $tActive = $fActive;
  56. $tMessage = $PALANG['pEdit_mailbox_domain_error'] . "$fDomain</span>";
  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")
  78. {
  79. if (isset ($_POST['fPassword'])) $fPassword = escape_string ($_POST['fPassword']);
  80. if (isset ($_POST['fPassword2'])) $fPassword2 = escape_string ($_POST['fPassword2']);
  81. if (isset ($_POST['fName'])) $fName = escape_string ($_POST['fName']);
  82. if (isset ($_POST['fQuota'])) $fQuota = intval ($_POST['fQuota']);
  83. if (isset ($_POST['fActive'])) $fActive = escape_string ($_POST['fActive']);
  84. if($fPassword != $user_details['password']){
  85. if($fPassword == $fPassword2) {
  86. if ($fPassword != "") {
  87. $formvars['password'] = pacrypt($fPassword);
  88. }
  89. }
  90. else {
  91. flash_error($PALANG['pEdit_mailbox_password_text_error']);
  92. $error = 1;
  93. }
  94. }
  95. if ($CONF['quota'] == "YES")
  96. {
  97. if (!check_quota ($fQuota, $fDomain))
  98. {
  99. $error = 1;
  100. $tName = $fName;
  101. $tQuota = $fQuota;
  102. $tActive = $fActive;
  103. $pEdit_mailbox_quota_text = $PALANG['pEdit_mailbox_quota_text_error'];
  104. }
  105. }
  106. if ($error != 1)
  107. {
  108. if (!empty ($fQuota))
  109. {
  110. $quota = multiply_quota ($fQuota);
  111. }
  112. else
  113. {
  114. $quota = 0;
  115. }
  116. if ($fActive == "on")
  117. {
  118. $sqlActive = db_get_boolean(True);
  119. $fActive = 1;
  120. }
  121. else
  122. {
  123. $sqlActive = db_get_boolean(False);
  124. $fActive = 0;
  125. }
  126. $formvars['name'] = $fName;
  127. $formvars['quota'] =$quota;
  128. $formvars['active']=$sqlActive;
  129. $result = db_update ('mailbox', "username='$fUsername' AND domain='$fDomain'", $formvars, array('modified'));
  130. if ($result != 1) {
  131. $tMessage = $PALANG['pEdit_mailbox_result_error'];
  132. }
  133. else {
  134. db_log ($SESSID_USERNAME, $fDomain, 'edit_mailbox', $fUsername);
  135. header ("Location: list-virtual.php?domain=$fDomain");
  136. exit;
  137. }
  138. }
  139. }
  140. include ("$incpath/templates/header.tpl");
  141. include ("$incpath/templates/menu.tpl");
  142. include ("$incpath/templates/edit-mailbox.tpl");
  143. include ("$incpath/templates/footer.tpl");
  144. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  145. ?>