Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

edit-alias.php 4.3KB

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