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.

177 lines
4.9 KiB

  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.php
  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. if(!preg_match ('/@/',$fGoto)) {
  71. $fGoto = $fGoto . "@" . escape_string ($_POST['fDomain']);
  72. }
  73. if(!(authentication_has_role('global-admin') ||
  74. check_owner ($SESSID_USERNAME, $fDomain) ))
  75. {
  76. $error = 1;
  77. $tAddress = escape_string ($_POST['fAddress']);
  78. $tGoto = $fGoto;
  79. $tDomain = $fDomain;
  80. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1'];
  81. }
  82. if(!check_alias($fDomain)) {
  83. $error = 1;
  84. $tAddress = escape_string ($_POST['fAddress']);
  85. $tGoto = $fGoto;
  86. $tDomain = $fDomain;
  87. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error3'];
  88. }
  89. if(empty ($fAddress) || !check_email ($fAddress)) {
  90. $error = 1;
  91. $tAddress = escape_string ($_POST['fAddress']);
  92. $tGoto = $fGoto;
  93. $tDomain = $fDomain;
  94. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1'];
  95. }
  96. if (empty($fGoto) || !check_email ($fGoto)) {
  97. $error = 1;
  98. $tAddress = escape_string ($_POST['fAddress']);
  99. $tGoto = $fGoto;
  100. $tDomain = $fDomain;
  101. $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text_error'];
  102. }
  103. if (escape_string($_POST['fAddress']) == "*") {
  104. $fAddress = "@" . escape_string ($_POST['fDomain']);
  105. }
  106. $append_alias = false;
  107. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress'");
  108. if ($result['rows'] == 1)
  109. {
  110. $append_alias = true;
  111. $tAddress = escape_string ($_POST['fAddress']);
  112. $tGoto = $fGoto;
  113. $tDomain = $fDomain;
  114. }
  115. if ($fActive == "on") {
  116. $sqlActive = db_get_boolean(True);
  117. }
  118. else {
  119. $sqlActive = db_get_boolean(False);
  120. }
  121. $success = false;
  122. /* Alias (or mailbox) already present, let's add the destination to that row */
  123. if ($append_alias) {
  124. if (preg_match('/^\*@(.*)$/', $fGoto, $match)) {
  125. $fGoto = "@" . $match[1];
  126. }
  127. $array = db_array ($result['result']);
  128. $values ['goto'] = $array['goto'] . ',' . $fGoto;
  129. $result = db_update ($table_alias, "address = '$fAddress'", $values, array ('modified'));
  130. $success = ($result == 1);
  131. } elseif ($error != 1) {
  132. if (preg_match('/^\*@(.*)$/', $fGoto, $match)) {
  133. $fGoto = "@" . $match[1];
  134. }
  135. $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified,active) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW(),'$sqlActive')");
  136. $success = ($result['rows'] == 1);
  137. }
  138. if (! $success) {
  139. $tDomain = $fDomain;
  140. $tMessage = $PALANG['pCreate_alias_result_error'] . "<br />($fAddress -> $fGoto)<br />\n";
  141. }
  142. else {
  143. db_log ($SESSID_USERNAME, $fDomain, 'create_alias', "$fAddress -> $fGoto");
  144. $tDomain = $fDomain;
  145. $tMessage = $PALANG['pCreate_alias_result_success'] . "<br />($fAddress -> $fGoto)<br />\n";
  146. }
  147. }
  148. include ("templates/header.php");
  149. include ("templates/menu.php");
  150. include ("templates/create-alias.php");
  151. include ("templates/footer.php");
  152. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  153. ?>