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.

159 lines
4.3 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. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress'");
  107. if ($result['rows'] == 1) {
  108. $error = 1;
  109. $tAddress = escape_string ($_POST['fAddress']);
  110. $tGoto = $fGoto;
  111. $tDomain = $fDomain;
  112. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error2'];
  113. }
  114. if ($fActive == "on") {
  115. $sqlActive = db_get_boolean(True);
  116. }
  117. else {
  118. $sqlActive = db_get_boolean(False);
  119. }
  120. if ($error != 1) {
  121. if (preg_match('/^\*@(.*)$/', $fGoto, $match)) {
  122. $fGoto = "@" . $match[1];
  123. }
  124. $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified,active) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW(),'$sqlActive')");
  125. if ($result['rows'] != 1) {
  126. $tDomain = $fDomain;
  127. $tMessage = $PALANG['pCreate_alias_result_error'] . "<br />($fAddress -> $fGoto)<br />\n";
  128. }
  129. else {
  130. db_log ($SESSID_USERNAME, $fDomain, 'create_alias', "$fAddress -> $fGoto");
  131. $tDomain = $fDomain;
  132. $tMessage = $PALANG['pCreate_alias_result_success'] . "<br />($fAddress -> $fGoto)<br />\n";
  133. }
  134. }
  135. }
  136. include ("templates/header.php");
  137. include ("templates/menu.php");
  138. include ("templates/create-alias.php");
  139. include ("templates/footer.php");
  140. ?>