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.

206 lines
6.1 KiB

reverting most changes from SVN r572 aka https://sourceforge.net/tracker/index.php?func=detail&aid=2567466&group_id=191583&atid=937966 because - it undermines the $CONF[*alias_control*] settings more or less - mailbox aliases with non-default targets are always shown in the "Aliases" section - see comment from 2009-05-04 on https://sourceforge.net/tracker/?func=detail&aid=1902476&group_id=191583&atid=937964 - it introduced some "funny" bugs - a nice example is http://sourceforge.net/tracker/?func=detail&aid=2786284&group_id=191583&atid=937964 Files / sections affected by the revert: - list-virtual.php: all numbers (alias count etc.) correct? (the changes in this file are the largest ones) - functions.inc.php: SQL queries in get_domain_properties() - delete.php: the only change since r572 affected code that was inserted in r572 (and is now deleted again) - nothing should break here - create-alias.php: had no changes since r572 - therefore nothing should break here Exceptions (not reverted): - edit-alias: this change looks useful (hide mailbox alias target from admins if they don't have permissions to change it). The actual code has changed in the meantime, but the functionality stays. Additionally, reverting this would be very hard or throw useful later changes away. BUT: shouldn't the page completely forbid to edit a mailbox alias if the admin doesn't have permissions for it? - functions.inc.php: comment for pacrypt() ;-) - linebreaks in long SQL queries Please check if everything is still working as expected (especially the domain list and the virtual list) - I did only some quick tests. git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@652 a1433add-5e2c-0410-b055-b7f2511e0802
17 years ago
reverting most changes from SVN r572 aka https://sourceforge.net/tracker/index.php?func=detail&aid=2567466&group_id=191583&atid=937966 because - it undermines the $CONF[*alias_control*] settings more or less - mailbox aliases with non-default targets are always shown in the "Aliases" section - see comment from 2009-05-04 on https://sourceforge.net/tracker/?func=detail&aid=1902476&group_id=191583&atid=937964 - it introduced some "funny" bugs - a nice example is http://sourceforge.net/tracker/?func=detail&aid=2786284&group_id=191583&atid=937964 Files / sections affected by the revert: - list-virtual.php: all numbers (alias count etc.) correct? (the changes in this file are the largest ones) - functions.inc.php: SQL queries in get_domain_properties() - delete.php: the only change since r572 affected code that was inserted in r572 (and is now deleted again) - nothing should break here - create-alias.php: had no changes since r572 - therefore nothing should break here Exceptions (not reverted): - edit-alias: this change looks useful (hide mailbox alias target from admins if they don't have permissions to change it). The actual code has changed in the meantime, but the functionality stays. Additionally, reverting this would be very hard or throw useful later changes away. BUT: shouldn't the page completely forbid to edit a mailbox alias if the admin doesn't have permissions for it? - functions.inc.php: comment for pacrypt() ;-) - linebreaks in long SQL queries Please check if everything is still working as expected (especially the domain list and the virtual list) - I did only some quick tests. git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@652 a1433add-5e2c-0410-b055-b7f2511e0802
17 years ago
reverting most changes from SVN r572 aka https://sourceforge.net/tracker/index.php?func=detail&aid=2567466&group_id=191583&atid=937966 because - it undermines the $CONF[*alias_control*] settings more or less - mailbox aliases with non-default targets are always shown in the "Aliases" section - see comment from 2009-05-04 on https://sourceforge.net/tracker/?func=detail&aid=1902476&group_id=191583&atid=937964 - it introduced some "funny" bugs - a nice example is http://sourceforge.net/tracker/?func=detail&aid=2786284&group_id=191583&atid=937964 Files / sections affected by the revert: - list-virtual.php: all numbers (alias count etc.) correct? (the changes in this file are the largest ones) - functions.inc.php: SQL queries in get_domain_properties() - delete.php: the only change since r572 affected code that was inserted in r572 (and is now deleted again) - nothing should break here - create-alias.php: had no changes since r572 - therefore nothing should break here Exceptions (not reverted): - edit-alias: this change looks useful (hide mailbox alias target from admins if they don't have permissions to change it). The actual code has changed in the meantime, but the functionality stays. Additionally, reverting this would be very hard or throw useful later changes away. BUT: shouldn't the page completely forbid to edit a mailbox alias if the admin doesn't have permissions for it? - functions.inc.php: comment for pacrypt() ;-) - linebreaks in long SQL queries Please check if everything is still working as expected (especially the domain list and the virtual list) - I did only some quick tests. git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@652 a1433add-5e2c-0410-b055-b7f2511e0802
17 years ago
  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the GPL license that is bundled with
  8. * this package in the file LICENSE.TXT.
  9. *
  10. * Further details on the project are available at :
  11. * http://www.postfixadmin.com or http://postfixadmin.sf.net
  12. *
  13. * File: create-alias.php
  14. * Template File: create-alias.tpl
  15. * Responsible for allowing for the creation of mail aliases.
  16. *
  17. * @version $Id$
  18. * @license GNU GPL v2 or later.
  19. *
  20. * Template Variables:
  21. *
  22. * tMessage
  23. * tAddress
  24. * tGoto
  25. * tDomain
  26. *
  27. * Form POST \ GET Variables:
  28. *
  29. * fAddress
  30. * fGoto
  31. * fDomain
  32. *
  33. */
  34. require_once('common.php');
  35. authentication_require_role('admin');
  36. $username = authentication_get_username();
  37. $SESSID_USERNAME = $username;
  38. if(authentication_has_role('global-admin')) {
  39. $list_domains = list_domains ();
  40. }
  41. else {
  42. $list_domains = list_domains_for_admin ($username);
  43. }
  44. $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text'];
  45. if ($_SERVER['REQUEST_METHOD'] == "GET")
  46. {
  47. if (isset ($_GET['domain'])) {
  48. $tDomain = escape_string ($_GET['domain']);
  49. }
  50. }
  51. if ($_SERVER['REQUEST_METHOD'] == "POST")
  52. {
  53. if (isset ($_POST['fAddress']) && isset ($_POST['fDomain'])) {
  54. $fAddress = escape_string($_POST['fAddress']) . "@" . escape_string ($_POST['fDomain']);
  55. $fAddress = strtolower ($fAddress);
  56. }
  57. if (isset ($_POST['fGoto'])) {
  58. $fGoto = escape_string ($_POST['fGoto']);
  59. $fGoto = strtolower ($fGoto);
  60. }
  61. if(isset($_POST['fActive'])) {
  62. $fActive = escape_string ($_POST['fActive']);
  63. }
  64. else {
  65. $fActive = "1";
  66. }
  67. if(isset($_POST['fDomain'])) {
  68. $fDomain = escape_string ($_POST['fDomain']);
  69. }
  70. # TODO: Doesn't work with multiple aliases - fix or discard...
  71. # if(!preg_match ('/@/',$fGoto)) {
  72. # $fGoto = $fGoto . "@" . escape_string ($_POST['fDomain']);
  73. # }
  74. if(!(authentication_has_role('global-admin') ||
  75. check_owner ($SESSID_USERNAME, $fDomain) ))
  76. {
  77. $error = 1;
  78. $tAddress = escape_string ($_POST['fAddress']);
  79. $tGoto = $fGoto;
  80. $tDomain = $fDomain;
  81. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1'];
  82. }
  83. if(!check_alias($fDomain)) {
  84. $error = 1;
  85. $tAddress = escape_string ($_POST['fAddress']);
  86. $tGoto = $fGoto;
  87. $tDomain = $fDomain;
  88. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error3'];
  89. }
  90. if(empty ($fAddress) || !check_email ($fAddress)) {
  91. $error = 1;
  92. $tAddress = escape_string ($_POST['fAddress']);
  93. $tGoto = $fGoto;
  94. $tDomain = $fDomain;
  95. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1'];
  96. }
  97. // Begin check alias email
  98. $goto = preg_replace ('/\\\r\\\n/', ',', $fGoto);
  99. $goto = preg_replace ('/\r\n/', ',', $goto);
  100. $goto = preg_replace ('/,[\s]+/i', ',', $goto);
  101. $goto = preg_replace ('/[\s]+,/i', ',', $goto);
  102. $goto = preg_replace ('/,*$|^,*/', '', $goto);
  103. $goto = preg_replace ('/,,*/', ',', $goto);
  104. if (empty ($goto) && !authentication_has_role('global-admin')) {
  105. $error = 1;
  106. $tGoto = $_POST['fGoto'];
  107. $tMessage = $PALANG['pEdit_alias_goto_text_error1'];
  108. }
  109. $new_aliases = array();
  110. if ($error != 1) {
  111. $new_aliases = explode(',', $goto);
  112. }
  113. $new_aliases = array_unique($new_aliases);
  114. foreach($new_aliases as $address) {
  115. if (in_array($address, $CONF['default_aliases'])) continue;
  116. if (empty($address)) continue; # TODO: should never happen - remove after 2.2 release
  117. if (!check_email($address)) {
  118. $error = 1;
  119. $tGoto = $goto;
  120. if (!empty($tMessage)) $tMessage .= "<br />";
  121. $tMessage .= $PALANG['pEdit_alias_goto_text_error2'] . "$address</span>";
  122. }
  123. }
  124. $goto = implode(',', $new_aliases);
  125. $fGoto = escape_string($goto);
  126. // End check alias mail
  127. if (empty($fGoto)) {
  128. $error = 1;
  129. $tAddress = escape_string ($_POST['fAddress']);
  130. $tGoto = $fGoto;
  131. $tDomain = $fDomain;
  132. $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text_error'];
  133. }
  134. if (escape_string($_POST['fAddress']) == "*") {
  135. $fAddress = "@" . escape_string ($_POST['fDomain']);
  136. }
  137. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress'");
  138. if ($result['rows'] == 1)
  139. {
  140. $error = 1;
  141. $tAddress = escape_string ($_POST['fAddress']);
  142. $tGoto = $fGoto;
  143. $tDomain = $fDomain;
  144. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error2'];
  145. }
  146. if ($fActive == "on") {
  147. $sqlActive = db_get_boolean(True);
  148. }
  149. else {
  150. $sqlActive = db_get_boolean(False);
  151. }
  152. if ($error != 1) {
  153. if (preg_match('/^\*@(.*)$/', $fGoto, $match)) {
  154. $fGoto = "@" . $match[1];
  155. }
  156. $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified,active) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW(),'$sqlActive')");
  157. if ($result['rows'] != 1) {
  158. $tDomain = $fDomain;
  159. $tMessage = $PALANG['pCreate_alias_result_error'] . "<br />($fAddress -> $fGoto)<br />\n";
  160. }
  161. else {
  162. db_log ($fDomain, 'create_alias', "$fAddress -> $fGoto");
  163. $tDomain = $fDomain;
  164. $tMessage = $PALANG['pCreate_alias_result_success'] . "<br />($fAddress -> $fGoto)<br />\n";
  165. }
  166. } else { # on error
  167. $tAddress = htmlentities($_POST['fAddress']);
  168. $tGoto = htmlentities($_POST['fGoto']);
  169. $tDomain = htmlentities($_POST['fDomain']);
  170. }
  171. }
  172. $smarty->assign ('tAddress', $tAddress);
  173. $smarty->assign ('select_options', select_options ($list_domains, array ($tDomain)), false);
  174. $smarty->assign ('pCreate_alias_address_text', $pCreate_alias_address_text, false);
  175. $smarty->assign ('tGoto', $tGoto, false);
  176. $smarty->assign ('pCreate_alias_goto_text', $pCreate_alias_goto_text);
  177. $smarty->assign ('tMessage', $tMessage, false);
  178. $smarty->assign ('smarty_template', 'create-alias');
  179. $smarty->display ('index.tpl');
  180. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  181. ?>