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.

147 lines
4.6 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-domain.php
  14. * Template File: create-alias-domain.tpl
  15. * Responsible for allowing for the creation of alias domains.
  16. *
  17. * @version $Id$
  18. * @license GNU GPL v2 or later.
  19. *
  20. * Template Variables:
  21. *
  22. * tMessage
  23. *
  24. * Form POST \ GET Variables:
  25. *
  26. * fAliasDomain
  27. * fTargetDomain
  28. * fActive
  29. *
  30. */
  31. require_once('common.php');
  32. authentication_require_role('admin');
  33. if (!boolconf('alias_domain')) {
  34. header("Location: " . $CONF['postfix_admin_url'] . "/main.php");
  35. exit;
  36. }
  37. $fAliasDomain = '';
  38. $fTargetDomain= '';
  39. $username = authentication_get_username();
  40. $SESSID_USERNAME = $username;
  41. if(authentication_has_role('global-admin')) {
  42. $list_domains = list_domains ();
  43. }
  44. else {
  45. $list_domains = list_domains_for_admin ($username);
  46. }
  47. # read alias_domain table to see which domains in $list_domains
  48. # are still available as an alias- or target-domain
  49. $list_aliases = Array();
  50. $result = db_query ("SELECT alias_domain, target_domain FROM $table_alias_domain");
  51. if ($result['rows'] > 0) {
  52. while ($row = db_array ($result['result']))
  53. {
  54. $list_aliases[ $row['alias_domain'] ] = $row['target_domain'];
  55. }
  56. }
  57. # filter available alias domains
  58. $alias_domains = array();
  59. foreach ($list_domains as $dom) {
  60. if (isset($list_aliases[$dom]) || in_array($dom,$list_aliases)) continue;
  61. $alias_domains[] = $dom;
  62. }
  63. if (count($alias_domains) == 0) {
  64. $error = 1;
  65. $tMessage = $PALANG['pCreate_alias_domain_error4'];
  66. }
  67. # filter available target domains
  68. foreach ($list_domains as $dom) {
  69. if (isset($list_aliases[$dom])) continue;
  70. $target_domains[] = $dom;
  71. }
  72. if (isset ($_REQUEST['alias_domain'])) {
  73. $fAliasDomain = escape_string ($_REQUEST['alias_domain']);
  74. $fAliasDomain = strtolower ($fAliasDomain);
  75. }
  76. if (isset ($_REQUEST['target_domain'])) {
  77. $fTargetDomain = escape_string ($_REQUEST['target_domain']);
  78. $fTargetDomain = strtolower ($fTargetDomain);
  79. }
  80. //*** ?????
  81. if (isset ($_REQUEST['active'])) {
  82. $fActive = (bool)$_REQUEST['active'];
  83. } else {
  84. $fActive = false;
  85. }
  86. if (!isset ($_REQUEST['submit']))
  87. $fActive = true;
  88. if ($_SERVER['REQUEST_METHOD'] == "POST")
  89. {
  90. if(!authentication_has_role ('global-admin') &&
  91. !(check_owner ($SESSID_USERNAME, $fAliasDomain) &&
  92. check_owner ($SESSID_USERNAME, $fTargetDomain)))
  93. {
  94. $error = 1;
  95. $tMessage = $PALANG['pCreate_alias_domain_error1'];
  96. }
  97. if (isset($list_aliases[$fAliasDomain]) || // alias_domain is unique (primary key, a domain can't be an alias for multiple others)
  98. in_array($fAliasDomain,$list_aliases) || // an alias_domain can't be a target_domain for a third domain.
  99. isset($list_aliases[$fTargetDomain]) || // same as above, other way around
  100. ($fAliasDomain == $fTargetDomain) || // i really don't have to
  101. empty($fAliasDomain) || empty($fTargetDomain)) // explain this, do i?
  102. {
  103. $error = 1;
  104. $tMessage = $PALANG['pCreate_alias_domain_error2'];
  105. }
  106. $sqlActive = db_get_boolean($fActive);
  107. if ($error != 1) {
  108. $result = db_query ("INSERT INTO $table_alias_domain (alias_domain,target_domain,created,modified,active) VALUES ('$fAliasDomain','$fTargetDomain',NOW(),NOW(),'$sqlActive')");
  109. if ($result['rows'] != 1) {
  110. $error = 1;
  111. $tMessage = $PALANG['pCreate_alias_domain_error3'];
  112. }
  113. else {
  114. db_log ($fAliasDomain, 'create_alias_domain', "$fAliasDomain -> $fTargetDomain");
  115. flash_info($PALANG['pCreate_alias_domain_success']);
  116. # we would have to update the list of domains available for aliasing. Doing a redirect is easier.
  117. header("Location: " . $CONF['postfix_admin_url'] . "/create-alias-domain.php");
  118. exit;
  119. }
  120. }
  121. $tMessage .= "<br />($fAliasDomain -> $fTargetDomain)<br />\n";
  122. }
  123. $smarty->assign ('alias_domains', (count($alias_domains) > 0));
  124. $smarty->assign ('select_options_alias', select_options ($alias_domains, array ($fAliasDomain)), false);
  125. $smarty->assign ('select_options_target', select_options ($target_domains, array ($fTargetDomain)), false);
  126. if ($fActive) $smarty->assign ('fActive', ' checked="checked"');
  127. if ($error == 1) $tMessage = '<span class="error_msg">'.$tMessage.'</span>';
  128. $smarty->assign ('tMessage', $tMessage, false);
  129. $smarty->assign ('smarty_template', 'create-alias-domain');
  130. $smarty->display ('index.tpl');
  131. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  132. ?>