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.

151 lines
4.7 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. $form_fields = array(
  41. 'fDomain' => array('type' => 'str', 'default' => null),
  42. 'fDescription' => array('type' => 'str', 'default' =>''),
  43. 'fAliases' => array('type' => 'int', 'default' => $CONF['aliases']),
  44. 'fMailboxes' => array('type' => 'int', 'default' => $CONF['mailboxes']),
  45. 'fMaxquota' => array('type' => 'int', 'default' => $CONF['maxquota']),
  46. 'fTransport' => array('type' => 'str', 'default' => $CONF['transport_default'], 'options' => $CONF['transport_options']),
  47. 'fDefaultaliases' => array('type' => 'str', 'default' => 'off', 'options' => array('on', 'off')),
  48. 'fBackupmx' => array('type' => 'str', 'default' => 'off', 'options' => array('on', 'off'))
  49. );
  50. foreach($form_fields as $key => $default) {
  51. if(isset($_POST[$key]) && (strlen($_POST[$key]) > 0)) {
  52. $$key = escape_string($_POST[$key]);
  53. }
  54. else {
  55. $$key = $default['default'];
  56. }
  57. if($default['type'] == 'int') {
  58. $$key = intval($$key);
  59. }
  60. if($default['type'] == 'str') {
  61. $$key = strip_tags($$key); /* should we even bother? */
  62. }
  63. if(isset($default['options'])) {
  64. if(!in_array($$key, $default['options'])) {
  65. die("Invalid parameter given for $key");
  66. }
  67. }
  68. }
  69. if ($_SERVER['REQUEST_METHOD'] == "GET")
  70. {
  71. /* default values as set above */
  72. $tTransport = $fTransport;
  73. $tAliases = $fAliases;
  74. $tMaxquota = $fMaxquota;
  75. $tMailboxes = $fMailboxes;
  76. $tDefaultAliases = $fDefaultaliases;
  77. $tBackupmx = $fBackupmx;
  78. }
  79. if ($_SERVER['REQUEST_METHOD'] == "POST")
  80. {
  81. $tBackupmx = "";
  82. if ($fDomain == null or domain_exist($fDomain) or !check_domain($fDomain))
  83. {
  84. $error = 1;
  85. $tDomain = $fDomain;
  86. $tDescription = $fDescription;
  87. $tAliases = $fAliases;
  88. $tMailboxes = $fMailboxes;
  89. if (isset ($_POST['fMaxquota'])) $tMaxquota = $fMaxquota;
  90. if (isset ($_POST['fTransport'])) $tTransport = $fTransport;
  91. if (isset ($_POST['fDefaultaliases'])) $tDefaultaliases = $fDefaultaliases;
  92. if (isset ($_POST['fBackupmx'])) $tBackupmx = $fBackupmx;
  93. $pAdminCreate_domain_domain_text = $PALANG['pAdminCreate_domain_domain_text_error2'];
  94. if (domain_exist ($fDomain)) $pAdminCreate_domain_domain_text = $PALANG['pAdminCreate_domain_domain_text_error'];
  95. }
  96. if ($error != 1)
  97. {
  98. $tAliases = $CONF['aliases'];
  99. $tMailboxes = $CONF['mailboxes'];
  100. $tMaxquota = $CONF['maxquota'];
  101. if ($fBackupmx == "on")
  102. {
  103. $fBackupmx = 1;
  104. $sqlBackupmx = db_get_boolean(true);
  105. }
  106. else
  107. {
  108. $fBackupmx = 0;
  109. $sqlBackupmx = db_get_boolean(false);
  110. }
  111. $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())";
  112. $result = db_query($sql_query);
  113. if ($result['rows'] != 1)
  114. {
  115. $tMessage = $PALANG['pAdminCreate_domain_result_error'] . "<br />($fDomain)<br />";
  116. }
  117. else
  118. {
  119. if ($fDefaultaliases == "on")
  120. {
  121. foreach ($CONF['default_aliases'] as $address=>$goto)
  122. {
  123. $address = $address . "@" . $fDomain;
  124. $result = db_query ("INSERT INTO $table_alias (address,goto,domain,created,modified) VALUES ('$address','$goto','$fDomain',NOW(),NOW())");
  125. }
  126. }
  127. $tMessage = $PALANG['pAdminCreate_domain_result_success'] . "<br />($fDomain)</br />";
  128. }
  129. if (!domain_postcreation($fDomain))
  130. {
  131. $tMessage = $PALANG['pAdminCreate_domain_error'];
  132. }
  133. }
  134. }
  135. include ("templates/header.php");
  136. include ("templates/menu.php");
  137. include ("templates/admin_create-domain.php");
  138. include ("templates/footer.php");
  139. /* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */
  140. ?>