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.

129 lines
4.0 KiB

  1. <?php
  2. /**
  3. * Postfix Admin
  4. *
  5. * LICENSE
  6. * This source file is subject to the GPL license that is bundled with
  7. * this package in the file LICENSE.TXT.
  8. *
  9. * Further details on the project are available at :
  10. * http://www.postfixadmin.com or http://postfixadmin.sf.net
  11. *
  12. * @version $Id$
  13. * @license GNU GPL v2 or later.
  14. *
  15. * File: create-domain.php
  16. * Allows administrators to create new domains.
  17. * Template File: admin_create-domain.php
  18. *
  19. * Template Variables:
  20. *
  21. * tMessage
  22. * tDomain
  23. * tDescription
  24. * tAliases
  25. * tMailboxes
  26. * tMaxquota
  27. * tDefaultaliases
  28. *
  29. * Form POST \ GET Variables:
  30. *
  31. * fDomain
  32. * fDescription
  33. * fAliases
  34. * fMailboxes
  35. * fMaxquota
  36. * fDefaultaliases
  37. */
  38. require_once('common.php');
  39. authentication_require_role('global-admin');
  40. if ($_SERVER['REQUEST_METHOD'] == "GET")
  41. {
  42. $tAliases = $CONF['aliases'];
  43. $tMailboxes = $CONF['mailboxes'];
  44. $tMaxquota = $CONF['maxquota'];
  45. $tTransport = $CONF['transport_default'];
  46. }
  47. if ($_SERVER['REQUEST_METHOD'] == "POST")
  48. {
  49. if (isset ($_POST['fDomain'])) $fDomain = escape_string ($_POST['fDomain']);
  50. $form_fields = array('fDescription' => '', 'fAliases' => '0', 'fMailboxes' => '0',
  51. 'fMaxquota' => '0', 'fTransport' => 'virtual', 'fDefaultaliases' => '0',
  52. 'fBackupmx' => '0');
  53. foreach($form_fields as $key => $default) {
  54. if(isset($_POST[$key]) && (!empty($_POST[$key]))) {
  55. $$key = escape_string($_POST[$key]);
  56. }
  57. else {
  58. $$key = $default;
  59. }
  60. }
  61. if (empty ($fDomain) or domain_exist ($fDomain) or !check_domain ($fDomain))
  62. {
  63. $error = 1;
  64. $tDomain = escape_string ($_POST['fDomain']);
  65. $tDescription = escape_string ($_POST['fDescription']);
  66. $tAliases = escape_string ($_POST['fAliases']);
  67. $tMailboxes = escape_string ($_POST['fMailboxes']);
  68. if (isset ($_POST['fMaxquota'])) $tMaxquota = escape_string ($_POST['fMaxquota']);
  69. if (isset ($_POST['fTransport'])) $tTransport = escape_string ($_POST['fTransport']);
  70. if (isset ($_POST['fDefaultaliases'])) $tDefaultaliases = escape_string ($_POST['fDefaultaliases']);
  71. if (isset ($_POST['fBackupmx'])) $tBackupmx = escape_string ($_POST['fBackupmx']);
  72. if (domain_exist ($fDomain)) $pAdminCreate_domain_domain_text = $PALANG['pAdminCreate_domain_domain_text_error'];
  73. if (empty ($fDomain) or !check_domain ($fDomain)) $pAdminCreate_domain_domain_text = $PALANG['pAdminCreate_domain_domain_text_error2'];
  74. }
  75. if ($error != 1)
  76. {
  77. $tAliases = $CONF['aliases'];
  78. $tMailboxes = $CONF['mailboxes'];
  79. $tMaxquota = $CONF['maxquota'];
  80. if ($fBackupmx == "on")
  81. {
  82. $fAliases = -1;
  83. $fMailboxes = -1;
  84. $fMaxquota = -1;
  85. $fBackupmx = 1;
  86. $sqlBackupmx = db_get_boolean(true);
  87. }
  88. else
  89. {
  90. $fBackupmx = 0;
  91. $sqlBackupmx = db_get_boolean(false);
  92. }
  93. $sql_query = "INSERT INTO $table_domain (domain,description,aliases,mailboxes,maxquota,transport,backupmx,created,modified) VALUES ('$fDomain','$fDescription',$fAliases,$fMailboxes,$fMaxquota,'$fTransport',$sqlBackupmx,NOW(),NOW())";
  94. $result = db_query($sql_query);
  95. if ($result['rows'] != 1)
  96. {
  97. $tMessage = $PALANG['pAdminCreate_domain_result_error'] . "<br />($fDomain)<br />";
  98. }
  99. else
  100. {
  101. if ($fDefaultaliases == "on")
  102. {
  103. foreach ($CONF['default_aliases'] as $address=>$goto)
  104. {
  105. $address = $address . "@" . $fDomain;
  106. $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified) VALUES ('$address','$goto','$fDomain',NOW(),NOW())");
  107. }
  108. }
  109. $tMessage = $PALANG['pAdminCreate_domain_result_success'] . "<br />($fDomain)</br />";
  110. }
  111. }
  112. }
  113. include ("templates/header.php");
  114. include ("templates/menu.php");
  115. include ("templates/admin_create-domain.php");
  116. include ("templates/footer.php");
  117. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  118. ?>