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
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. * Users can use this to set forwards etc for their mailbox.
  17. *
  18. * Template File: users_edit-alias.tpl
  19. *
  20. * Template Variables:
  21. *
  22. * tMessage
  23. * tGotoArray
  24. * tStoreAndForward
  25. *
  26. * Form POST \ GET Variables:
  27. *
  28. * fAddress
  29. * fGoto
  30. */
  31. require_once('../common.php');
  32. $smarty->assign ('smarty_template', 'users_edit-alias');
  33. authentication_require_role('user');
  34. $USERID_USERNAME = authentication_get_username();
  35. $tmp = preg_split ('/@/', $USERID_USERNAME);
  36. $USERID_DOMAIN = $tmp[1];
  37. $vacation_domain = $CONF['vacation_domain'];
  38. $vacation_goto = preg_replace('/@/', '#', $USERID_USERNAME) . '@' . $vacation_domain;
  39. $ah = new AliasHandler($USERID_USERNAME);
  40. $smarty->assign ('USERID_USERNAME', $USERID_USERNAME);
  41. if ( ! $ah->get() ) die("Can't get alias details. Invalid alias?"); # this can only happen if a admin deleted the user since the user logged in
  42. $tGotoArray = $ah->result();
  43. $tStoreAndForward = $ah->hasStoreAndForward();
  44. $vacation_domain = $CONF['vacation_domain'];
  45. if ($_SERVER['REQUEST_METHOD'] == "GET")
  46. {
  47. ($tStoreAndForward) ? $smarty->assign ('forward_and_store', ' checked="checked"') : $smarty->assign ('forward_only', ' checked="checked"');
  48. $smarty->assign ('tGotoArray', $tGotoArray);
  49. $smarty->display ('index.tpl');
  50. }
  51. if ($_SERVER['REQUEST_METHOD'] == "POST")
  52. {
  53. // user clicked on cancel button
  54. if(isset($_POST['fCancel'])) {
  55. header("Location: main.php");
  56. exit(0);
  57. }
  58. $pEdit_alias_goto = $PALANG['pEdit_alias_goto'];
  59. if (isset($_POST['fGoto'])) $fGoto = trim($_POST['fGoto']);
  60. if (isset($_POST['fForward_and_store'])) $fForward_and_store = $_POST['fForward_and_store'];
  61. $goto = strtolower ($fGoto);
  62. $goto = preg_replace ('/\\\r\\\n/', ',', $goto);
  63. $goto = preg_replace ('/\r\n/', ',', $goto);
  64. $goto = preg_replace ('/,[\s]+/i', ',', $goto);
  65. $goto = preg_replace ('/[\s]+,/i', ',', $goto);
  66. $goto = preg_replace ('/\,*$/', '', $goto);
  67. $goto = explode(",",$goto);
  68. $error = 0;
  69. $goto = array_merge(array_unique($goto));
  70. $good_goto = array();
  71. if($fForward_and_store != 'YES' && sizeof($goto) == 1 && $goto[0] == '') {
  72. $tMessage = $PALANG['pEdit_alias_goto_text_error1'];
  73. $error += 1;
  74. }
  75. if($error === 0) {
  76. foreach($goto as $address) {
  77. if ($address != "") { # $goto[] may contain a "" element
  78. # TODO - from https://sourceforge.net/tracker/?func=detail&aid=3027375&group_id=191583&atid=937964
  79. # The not-so-good news is that some internals of edit-alias aren't too nice
  80. # - for example, $goto[] can contain an element with empty string. I added a
  81. # check for that in the 2.3 branch, but we should use a better solution
  82. # (avoid empty elements in $goto) in trunk ;-)
  83. if(!check_email($address)) {
  84. $error += 1;
  85. if (!empty($tMessage)) $tMessage .= "<br />";
  86. $tMessage .= $PALANG['pEdit_alias_goto_text_error2'] . " $address</font>";
  87. }
  88. else {
  89. $good_goto[] = $address;
  90. }
  91. }
  92. }
  93. }
  94. if ($error == 0) {
  95. $flags = 'remote_only';
  96. if($fForward_and_store == "YES" ) {
  97. $flags = 'forward_and_store';
  98. }
  99. $updated = $ah->update($good_goto, $flags);
  100. if($updated) {
  101. header ("Location: main.php");
  102. exit;
  103. }
  104. if (!empty($tMessage)) $tMessage .= "<br />";
  105. $tMessage .= $PALANG['pEdit_alias_result_error'];
  106. }
  107. else {
  108. $tGotoArray = $goto;
  109. }
  110. $smarty->assign ('tMessage', $tMessage, false);
  111. $smarty->assign ('tGotoArray', $tGotoArray);
  112. if ($fForward_and_store == "YES") {
  113. $smarty->assign ('forward_and_store', ' checked="checked"');
  114. } else {
  115. $smarty->assign ('forward_only', ' checked="checked"');
  116. }
  117. $smarty->display ('index.tpl');
  118. }
  119. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  120. ?>