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.

152 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-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 ($_SERVER['REQUEST_METHOD'] == "GET")
  35. {
  36. if (isset ($_GET['address'])) $fAddress = escape_string ($_GET['address']);
  37. if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  38. if (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin'))
  39. {
  40. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress' AND domain='$fDomain'");
  41. if ($result['rows'] == 1)
  42. {
  43. $row = db_array ($result['result']);
  44. $tGoto = $row['goto'];
  45. /* Has a mailbox as well? Remove the address from $tGoto in order to edit just the real aliases */
  46. $result = db_query ("SELECT * FROM $table_mailbox WHERE username='$fAddress' AND domain='$fDomain'");
  47. if ($result['rows'] == 1)
  48. {
  49. $tGoto = preg_replace ('/\s*,*\s*' . $fAddress . '\s*,*\s*/', '', $tGoto);
  50. }
  51. }
  52. }
  53. else
  54. {
  55. $tMessage = $PALANG['pEdit_alias_address_error'];
  56. }
  57. }
  58. if ($_SERVER['REQUEST_METHOD'] == "POST")
  59. {
  60. $pEdit_alias_goto = $PALANG['pEdit_alias_goto'];
  61. if (isset ($_GET['address'])) $fAddress = escape_string ($_GET['address']);
  62. $fAddress = strtolower ($fAddress);
  63. if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  64. if (isset ($_POST['fGoto'])) $fGoto = escape_string ($_POST['fGoto']);
  65. $fGoto = strtolower ($fGoto);
  66. if (! (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')) )
  67. {
  68. $error = 1;
  69. $tGoto = $_POST['fGoto'];
  70. $tMessage = $PALANG['pEdit_alias_domain_error'] . "$fDomain</span>";
  71. }
  72. elseif (!check_alias_owner ($SESSID_USERNAME, $fAddress))
  73. {
  74. $error = 1;
  75. $tGoto = $fGoto;
  76. $tMessage = $PALANG['pEdit_alias_result_error'];
  77. }
  78. $goto = preg_replace ('/\\\r\\\n/', ',', $fGoto);
  79. $goto = preg_replace ('/\r\n/', ',', $goto);
  80. $goto = preg_replace ('/[\s]+/i', '', $goto);
  81. $goto = preg_replace ('/,*$|^,*/', '', $goto);
  82. $goto = preg_replace ('/,,*/', ',', $goto);
  83. if (empty ($goto))
  84. {
  85. $error = 1;
  86. $tGoto = $_POST['fGoto'];
  87. $tMessage = $PALANG['pEdit_alias_goto_text_error1'];
  88. }
  89. if ($error != 1)
  90. {
  91. $array = preg_split ('/,/', $goto);
  92. }
  93. else
  94. {
  95. $array = array();
  96. }
  97. for ($i = 0; $i < sizeof ($array); $i++) {
  98. if (in_array ("$array[$i]", $CONF['default_aliases'])) continue;
  99. if (empty ($array[$i])) continue; # TODO: should never happen - remove after 2.2 release
  100. if (!check_email ($array[$i]))
  101. {
  102. $error = 1;
  103. $tGoto = $goto;
  104. $tMessage = $PALANG['pEdit_alias_goto_text_error2'] . "$array[$i]</span>";
  105. }
  106. }
  107. $result = db_query ("SELECT * FROM $table_mailbox WHERE username='$fAddress' AND domain='$fDomain'");
  108. /* The alias has a real mailbox as well, prepend $goto with it */
  109. if ($result['rows'] == 1)
  110. {
  111. $goto = "$fAddress,$goto";
  112. }
  113. if ($error != 1)
  114. {
  115. $result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fAddress' AND domain='$fDomain'");
  116. if ($result['rows'] != 1)
  117. {
  118. $tMessage = $PALANG['pEdit_alias_result_error'];
  119. }
  120. else
  121. {
  122. db_log ($SESSID_USERNAME, $fDomain, 'edit_alias', "$fAddress -> $goto");
  123. header ("Location: list-virtual.php?domain=$fDomain");
  124. exit;
  125. }
  126. }
  127. }
  128. $fAddress = htmlentities($fAddress, ENT_QUOTES);
  129. $fDomain = htmlentities($fDomain, ENT_QUOTES);
  130. include ("templates/header.php");
  131. include ("templates/menu.php");
  132. include ("templates/edit-alias.php");
  133. include ("templates/footer.php");
  134. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  135. ?>