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.

154 lines
4.2 KiB

  1. <?php
  2. //
  3. // Postfix Admin
  4. // by Mischa Peters <mischa at high5 dot net>
  5. // Copyright (c) 2002 - 2005 High5!
  6. // Licensed under GPL for more info check GPL-LICENSE.TXT
  7. //
  8. // File: create-alias.php
  9. //
  10. // Template File: create-alias.tpl
  11. //
  12. // Template Variables:
  13. //
  14. // tMessage
  15. // tAddress
  16. // tGoto
  17. // tDomain
  18. //
  19. // Form POST \ GET Variables:
  20. //
  21. // fAddress
  22. // fGoto
  23. // fDomain
  24. //
  25. require ("./variables.inc.php");
  26. require ("./config.inc.php");
  27. require ("./functions.inc.php");
  28. include ("./languages/" . check_language () . ".lang");
  29. $SESSID_USERNAME = check_session ();
  30. if (!check_admin($SESSID_USERNAME))
  31. {
  32. $list_domains = list_domains_for_admin ($SESSID_USERNAME);
  33. }
  34. else
  35. {
  36. $list_domains = list_domains ();
  37. }
  38. if ($_SERVER['REQUEST_METHOD'] == "GET")
  39. {
  40. $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text'];
  41. if (isset ($_GET['domain'])) $tDomain = escape_string ($_GET['domain']);
  42. include ("./templates/header.tpl");
  43. include ("./templates/menu.tpl");
  44. include ("./templates/create-alias.tpl");
  45. include ("./templates/footer.tpl");
  46. }
  47. if ($_SERVER['REQUEST_METHOD'] == "POST")
  48. {
  49. $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text'];
  50. if (isset ($_POST['fAddress']) && isset ($_POST['fDomain'])) $fAddress = escape_string ($_POST['fAddress']) . "@" . escape_string ($_POST['fDomain']);
  51. $fAddress = strtolower ($fAddress);
  52. if (isset ($_POST['fGoto'])) $fGoto = escape_string ($_POST['fGoto']);
  53. $fGoto = strtolower ($fGoto);
  54. isset ($_POST['fActive']) ? $fActive = escape_string ($_POST['fActive']) : $fActive = "1";
  55. if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
  56. if (!preg_match ('/@/',$fGoto))
  57. {
  58. $fGoto = $fGoto . "@" . escape_string ($_POST['fDomain']);
  59. }
  60. if (!check_owner ($SESSID_USERNAME, $fDomain))
  61. {
  62. $error = 1;
  63. $tAddress = escape_string ($_POST['fAddress']);
  64. $tGoto = $fGoto;
  65. $tDomain = $fDomain;
  66. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1'];
  67. }
  68. if (!check_alias ($fDomain))
  69. {
  70. $error = 1;
  71. $tAddress = escape_string ($_POST['fAddress']);
  72. $tGoto = $fGoto;
  73. $tDomain = $fDomain;
  74. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error3'];
  75. }
  76. if (empty ($fAddress) or !check_email ($fAddress))
  77. {
  78. $error = 1;
  79. $tAddress = escape_string ($_POST['fAddress']);
  80. $tGoto = $fGoto;
  81. $tDomain = $fDomain;
  82. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error1'];
  83. }
  84. if (empty ($fGoto) or !check_email ($fGoto))
  85. {
  86. $error = 1;
  87. $tAddress = escape_string ($_POST['fAddress']);
  88. $tGoto = $fGoto;
  89. $tDomain = $fDomain;
  90. $pCreate_alias_goto_text = $PALANG['pCreate_alias_goto_text_error'];
  91. }
  92. if (escape_string ($_POST['fAddress']) == "*") $fAddress = "@" . escape_string ($_POST['fDomain']);
  93. $result = db_query ("SELECT * FROM $table_alias WHERE address='$fAddress'");
  94. if ($result['rows'] == 1)
  95. {
  96. $error = 1;
  97. $tAddress = escape_string ($_POST['fAddress']);
  98. $tGoto = $fGoto;
  99. $tDomain = $fDomain;
  100. $pCreate_alias_address_text = $PALANG['pCreate_alias_address_text_error2'];
  101. }
  102. if ($fActive == "on")
  103. {
  104. $fActive = 1;
  105. }
  106. else
  107. {
  108. $fActive = 0;
  109. }
  110. $sqlActive=$fActive;
  111. if ('pgsql'==$CONF['database_type'])
  112. {
  113. $sqlActive=($fActive) ? 'true' : 'false';
  114. }
  115. if ($error != 1)
  116. {
  117. if (preg_match ('/^\*@(.*)$/', $fGoto, $match)) $fGoto = "@" . $match[1];
  118. $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified,active) VALUES ('$fAddress','$fGoto','$fDomain',NOW(),NOW(),'$sqlActive')");
  119. if ($result['rows'] != 1)
  120. {
  121. $tDomain = $fDomain;
  122. $tMessage = $PALANG['pCreate_alias_result_error'] . "<br />($fAddress -> $fGoto)<br />\n";
  123. }
  124. else
  125. {
  126. db_log ($SESSID_USERNAME, $fDomain, "create alias", "$fAddress -> $fGoto");
  127. $tDomain = $fDomain;
  128. $tMessage = $PALANG['pCreate_alias_result_succes'] . "<br />($fAddress -> $fGoto)<br />\n";
  129. }
  130. }
  131. include ("./templates/header.tpl");
  132. include ("./templates/menu.tpl");
  133. include ("./templates/create-alias.tpl");
  134. include ("./templates/footer.tpl");
  135. }
  136. ?>