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.

138 lines
3.6 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. }
  46. }
  47. else
  48. {
  49. $tMessage = $PALANG['pEdit_alias_address_error'];
  50. }
  51. }
  52. if ($_SERVER['REQUEST_METHOD'] == "POST")
  53. {
  54. $pEdit_alias_goto = $PALANG['pEdit_alias_goto'];
  55. if (isset ($_GET['address'])) $fAddress = escape_string ($_GET['address']);
  56. $fAddress = strtolower ($fAddress);
  57. if (isset ($_GET['domain'])) $fDomain = escape_string ($_GET['domain']);
  58. if (isset ($_POST['fGoto'])) $fGoto = escape_string ($_POST['fGoto']);
  59. $fGoto = strtolower ($fGoto);
  60. if (! (check_owner ($SESSID_USERNAME, $fDomain) || authentication_has_role('global-admin')) )
  61. {
  62. $error = 1;
  63. $tGoto = $_POST['fGoto'];
  64. $tMessage = $PALANG['pEdit_alias_domain_error'] . "$fDomain</span>";
  65. }
  66. elseif (!check_alias_owner ($SESSID_USERNAME, $fAddress))
  67. {
  68. $error = 1;
  69. $tGoto = $fGoto;
  70. $tMessage = $PALANG['pEdit_alias_result_error'];
  71. }
  72. $goto = preg_replace ('/\\\r\\\n/', ',', $fGoto);
  73. $goto = preg_replace ('/\r\n/', ',', $goto);
  74. $goto = preg_replace ('/[\s]+/i', '', $goto);
  75. $goto = preg_replace ('/,*$|^,*/', '', $goto);
  76. $goto = preg_replace ('/,,*/', ',', $goto);
  77. if (empty ($goto))
  78. {
  79. $error = 1;
  80. $tGoto = $_POST['fGoto'];
  81. $tMessage = $PALANG['pEdit_alias_goto_text_error1'];
  82. }
  83. if ($error != 1)
  84. {
  85. $array = preg_split ('/,/', $goto);
  86. }
  87. else
  88. {
  89. $array = array();
  90. }
  91. for ($i = 0; $i < sizeof ($array); $i++) {
  92. if (in_array ("$array[$i]", $CONF['default_aliases'])) continue;
  93. if (empty ($array[$i])) continue; # TODO: should never happen - remove after 2.2 release
  94. if (!check_email ($array[$i]))
  95. {
  96. $error = 1;
  97. $tGoto = $goto;
  98. $tMessage = $PALANG['pEdit_alias_goto_text_error2'] . "$array[$i]</span>";
  99. }
  100. }
  101. if ($error != 1)
  102. {
  103. $result = db_query ("UPDATE $table_alias SET goto='$goto',modified=NOW() WHERE address='$fAddress' AND domain='$fDomain'");
  104. if ($result['rows'] != 1)
  105. {
  106. $tMessage = $PALANG['pEdit_alias_result_error'];
  107. }
  108. else
  109. {
  110. db_log ($SESSID_USERNAME, $fDomain, 'edit_alias', "$fAddress -> $goto");
  111. header ("Location: list-virtual.php?domain=$fDomain");
  112. exit;
  113. }
  114. }
  115. }
  116. $fAddress = htmlentities($fAddress, ENT_QUOTES);
  117. $fDomain = htmlentities($fDomain, ENT_QUOTES);
  118. include ("templates/header.php");
  119. include ("templates/menu.php");
  120. include ("templates/edit-alias.php");
  121. include ("templates/footer.php");
  122. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  123. ?>