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.

125 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.tpl
  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. foreach(array('fDescription' => '', 'fAliases' => '0', 'fMailboxes' => '0',
  51. 'fMaxquota' => '0', 'fTransport' => 'virtual',
  52. 'fDefaultaliases' => '0', 'fBackupmx' => '0') as $key => $default) {
  53. if(isset($_POST[$key]) && !empty($POST[$key])) {
  54. $$key = escape_string($_POST[$key]);
  55. }
  56. $$key = $default;
  57. }
  58. if (empty ($fDomain) or domain_exist ($fDomain) or !check_domain ($fDomain))
  59. {
  60. $error = 1;
  61. $tDomain = escape_string ($_POST['fDomain']);
  62. $tDescription = escape_string ($_POST['fDescription']);
  63. $tAliases = escape_string ($_POST['fAliases']);
  64. $tMailboxes = escape_string ($_POST['fMailboxes']);
  65. if (isset ($_POST['fMaxquota'])) $tMaxquota = escape_string ($_POST['fMaxquota']);
  66. if (isset ($_POST['fTransport'])) $tTransport = escape_string ($_POST['fTransport']);
  67. if (isset ($_POST['fDefaultaliases'])) $tDefaultaliases = escape_string ($_POST['fDefaultaliases']);
  68. if (isset ($_POST['fBackupmx'])) $tBackupmx = escape_string ($_POST['fBackupmx']);
  69. if (domain_exist ($fDomain)) $pAdminCreate_domain_domain_text = $PALANG['pAdminCreate_domain_domain_text_error'];
  70. if (empty ($fDomain) or !check_domain ($fDomain)) $pAdminCreate_domain_domain_text = $PALANG['pAdminCreate_domain_domain_text_error2'];
  71. }
  72. if ($error != 1)
  73. {
  74. $tAliases = $CONF['aliases'];
  75. $tMailboxes = $CONF['mailboxes'];
  76. $tMaxquota = $CONF['maxquota'];
  77. if ($fBackupmx == "on")
  78. {
  79. $fAliases = -1;
  80. $fMailboxes = -1;
  81. $fMaxquota = -1;
  82. $fBackupmx = 1;
  83. $sqlBackupmx = ('pgsql'==$CONF['database_type']) ? 'true' : 1;
  84. }
  85. else
  86. {
  87. $fBackupmx = 0;
  88. $sqlBackupmx = ('pgsql'==$CONF['database_type']) ? 'false' : 0;
  89. }
  90. $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())";
  91. $result = db_query($sql_query);
  92. if ($result['rows'] != 1)
  93. {
  94. $tMessage = $PALANG['pAdminCreate_domain_result_error'] . "<br />($fDomain)<br />";
  95. }
  96. else
  97. {
  98. if ($fDefaultaliases == "on")
  99. {
  100. foreach ($CONF['default_aliases'] as $address=>$goto)
  101. {
  102. $address = $address . "@" . $fDomain;
  103. $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified) VALUES ('$address','$goto','$fDomain',NOW(),NOW())");
  104. }
  105. }
  106. $tMessage = $PALANG['pAdminCreate_domain_result_success'] . "<br />($fDomain)</br />";
  107. }
  108. }
  109. }
  110. include ("templates/header.tpl");
  111. include ("templates/menu.tpl");
  112. include ("templates/admin_create-domain.tpl");
  113. include ("templates/footer.tpl");
  114. /* vim: set expandtab softtabstop=3 tabstop=3 shiftwidth=3: */
  115. ?>