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.

167 lines
5.2 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-alias.php
  16. * Used to update an alias.
  17. *
  18. * Template File: edit-alias.php
  19. *
  20. * Template Variables:
  21. *
  22. * tMessage
  23. * tGoto
  24. *
  25. * Form POST \ GET Variables:
  26. *
  27. * fAddress
  28. * fDomain
  29. * fGoto
  30. */
  31. require_once('common.php');
  32. authentication_require_role('admin');
  33. $SESSID_USERNAME = authentication_get_username();
  34. if($CONF['alias_control_admin'] == 'NO' && !authentication_has_role('global-admin')) {
  35. die("Check config.inc.php - domain administrators do not have the ability to edit user's aliases (alias_control_admin)");
  36. }
  37. if ($_SERVER['REQUEST_METHOD'] == "GET")
  38. {
  39. if (isset ($_GET['address'])) $fAddress = escape_string ($_GET['address']);
  40. if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  41. if (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin'))
  42. {
  43. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress' AND domain='$fDomain'");
  44. if ($result['rows'] == 1)
  45. {
  46. $row = db_array ($result['result']);
  47. $tGoto = $row['goto'];
  48. //. if we are not a global admin, and special_alias_control is NO, hide the alias that's the mailbox name.
  49. if($CONF['special_alias_control'] == 'NO' && !authentication_has_role('global-admin')) {
  50. /* Has a mailbox as well? Remove the address from $tGoto in order to edit just the real aliases */
  51. $result = db_query ("SELECT * FROM $table_mailbox WHERE username='$fAddress' AND domain='$fDomain'");
  52. if ($result['rows'] == 1)
  53. {
  54. $tGoto = preg_replace ('/\s*,*\s*' . $fAddress . '\s*,*\s*/', '', $tGoto);
  55. }
  56. }
  57. }
  58. }
  59. else
  60. {
  61. $tMessage = $PALANG['pEdit_alias_address_error'];
  62. }
  63. }
  64. if ($_SERVER['REQUEST_METHOD'] == "POST")
  65. {
  66. $pEdit_alias_goto = $PALANG['pEdit_alias_goto'];
  67. if (isset ($_GET['address'])) $fAddress = escape_string ($_GET['address']);
  68. $fAddress = strtolower ($fAddress);
  69. if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  70. if (isset ($_POST['fGoto'])) $fGoto = escape_string ($_POST['fGoto']);
  71. $fGoto = strtolower ($fGoto);
  72. if (! (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')) )
  73. {
  74. $error = 1;
  75. $tGoto = $_POST['fGoto'];
  76. $tMessage = $PALANG['pEdit_alias_domain_error'] . "$fDomain</span>";
  77. }
  78. elseif (!check_alias_owner ($SESSID_USERNAME, $fAddress))
  79. {
  80. $error = 1;
  81. $tGoto = $fGoto;
  82. $tMessage = $PALANG['pEdit_alias_result_error'];
  83. }
  84. $goto = preg_replace ('/\\\r\\\n/', ',', $fGoto);
  85. $goto = preg_replace ('/\r\n/', ',', $goto);
  86. $goto = preg_replace ('/[\s]+/i', '', $goto);
  87. $goto = preg_replace ('/,*$|^,*/', '', $goto);
  88. $goto = preg_replace ('/,,*/', ',', $goto);
  89. if (empty ($goto) && !authentication_has_role('global-admin'))
  90. {
  91. $error = 1;
  92. $tGoto = $_POST['fGoto'];
  93. $tMessage = $PALANG['pEdit_alias_goto_text_error1'];
  94. }
  95. if ($error != 1)
  96. {
  97. $array = preg_split ('/,/', $goto);
  98. }
  99. else
  100. {
  101. $array = array();
  102. }
  103. for ($i = 0; $i < sizeof ($array); $i++) {
  104. if (in_array ("$array[$i]", $CONF['default_aliases'])) continue;
  105. if (empty ($array[$i])) continue; # TODO: should never happen - remove after 2.2 release
  106. if (!check_email ($array[$i]))
  107. {
  108. $error = 1;
  109. $tGoto = $goto;
  110. $tMessage = $PALANG['pEdit_alias_goto_text_error2'] . "$array[$i]</span>";
  111. }
  112. }
  113. $result = db_query ("SELECT * FROM $table_mailbox WHERE username='$fAddress' AND domain='$fDomain'");
  114. /* The alias has a real mailbox as well, prepend $goto with it */
  115. if ($result['rows'] == 1)
  116. {
  117. // ensure mailbox alias exists... if they're a domain admin, and they're not allowed to...
  118. if($CONF['alias_control_admin'] == 'NO' && !authentication_has_role('global-admin')) {
  119. $array[] = $fAddress;
  120. }
  121. }
  122. // duplicates suck, mmkay..
  123. $array = array_unique($array);
  124. $goto = implode(',', $array);
  125. if ($error != 1)
  126. {
  127. $goto = escape_string($goto);
  128. $result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fAddress' AND domain='$fDomain'");
  129. if ($result['rows'] != 1)
  130. {
  131. $tMessage = $PALANG['pEdit_alias_result_error'];
  132. }
  133. else
  134. {
  135. db_log ($SESSID_USERNAME, $fDomain, 'edit_alias', "$fAddress -> $goto");
  136. header ("Location: list-virtual.php?domain=$fDomain");
  137. exit;
  138. }
  139. }
  140. }
  141. $fAddress = htmlentities($fAddress, ENT_QUOTES);
  142. $fDomain = htmlentities($fDomain, ENT_QUOTES);
  143. include ("templates/header.php");
  144. include ("templates/menu.php");
  145. include ("templates/edit-alias.php");
  146. include ("templates/footer.php");
  147. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  148. ?>