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.

add_zone_master.php 7.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. <?php
  2. /* Poweradmin, a friendly web-based admin tool for PowerDNS.
  3. * See <http://www.poweradmin.org> for more details.
  4. *
  5. * Copyright 2007-2010 Rejo Zenger <rejo@zenger.nl>
  6. * Copyright 2010-2017 Poweradmin Development Team
  7. * <http://www.poweradmin.org/credits.html>
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * Script that handles requests to add new master zones
  24. *
  25. * @package Poweradmin
  26. * @copyright 2007-2010 Rejo Zenger <rejo@zenger.nl>
  27. * @copyright 2010-2017 Poweradmin Development Team
  28. * @license http://opensource.org/licenses/GPL-3.0 GPL
  29. */
  30. require_once("inc/toolkit.inc.php");
  31. include_once("inc/header.inc.php");
  32. echo " <script type=\"text/javascript\" src=\"inc/helper.js\"></script>";
  33. global $pdnssec_use;
  34. global $dns_third_level_check;
  35. $owner = "-1";
  36. if ((isset($_POST['owner'])) && (v_num($_POST['owner']))) {
  37. $owner = $_POST['owner'];
  38. }
  39. $dom_type = "NATIVE";
  40. if (isset($_POST["dom_type"]) && (in_array($_POST['dom_type'], $server_types))) {
  41. $dom_type = $_POST["dom_type"];
  42. }
  43. if (isset($_POST['domain'])) {
  44. $temp = array();
  45. foreach ($_POST['domain'] as $domain) {
  46. if ($domain != "") {
  47. $temp[] = trim($domain);
  48. }
  49. }
  50. $domains = $temp;
  51. } else {
  52. $domains = array();
  53. }
  54. if (isset($_POST['zone_template'])) {
  55. $zone_template = $_POST['zone_template'];
  56. } else {
  57. $zone_template = "none";
  58. }
  59. $enable_dnssec = false;
  60. if (isset($_POST['dnssec']) && $_POST['dnssec'] == '1') {
  61. $enable_dnssec = true;
  62. }
  63. /*
  64. Check user permissions
  65. */
  66. (do_hook('verify_permission' , 'zone_master_add' )) ? $zone_master_add = "1" : $zone_master_add = "0";
  67. (do_hook('verify_permission' , 'user_view_others' )) ? $perm_view_others = "1" : $perm_view_others = "0";
  68. if (isset($_POST['submit']) && $zone_master_add == "1") {
  69. $error = false;
  70. foreach ($domains as $domain) {
  71. if (!is_valid_hostname_fqdn($domain, 0)) {
  72. error($domain . ' failed - ' . ERR_DNS_HOSTNAME);
  73. } elseif ($dns_third_level_check && get_domain_level($domain) > 2 && domain_exists(get_second_level_domain($domain))) {
  74. error($domain . ' failed - ' . ERR_DOMAIN_EXISTS);
  75. $error = true;
  76. } elseif (domain_exists($domain) || record_name_exists($domain)) {
  77. error($domain . ' failed - ' . ERR_DOMAIN_EXISTS);
  78. // TODO: repopulate domain name(s) to the form if there was an error occured
  79. $error = true;
  80. } elseif (add_domain($domain, $owner, $dom_type, '', $zone_template)) {
  81. $domain_id = get_zone_id_from_name($domain);
  82. success("<a href=\"edit.php?id=" . $domain_id . "\">" . $domain . " - " . SUC_ZONE_ADD . '</a>');
  83. log_info(sprintf('client_ip:%s user:%s operation:add_zone zone:%s zone_type:%s zone_template:%s',
  84. $_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
  85. $domain,$dom_type,$zone_template));
  86. if ($pdnssec_use) {
  87. if ($enable_dnssec) {
  88. dnssec_secure_zone($domain);
  89. }
  90. dnssec_rectify_zone($domain_id);
  91. }
  92. }
  93. }
  94. if (false === $error) {
  95. unset($domains, $owner, $dom_type, $zone_template);
  96. }
  97. }
  98. if ($zone_master_add != "1") {
  99. error(ERR_PERM_ADD_ZONE_MASTER);
  100. } else {
  101. echo " <h2>" . _('Add master zone') . "</h2>\n";
  102. $available_zone_types = array("MASTER", "NATIVE");
  103. $users = do_hook('show_users');
  104. $zone_templates = get_list_zone_templ($_SESSION['userid']);
  105. echo " <form method=\"post\" action=\"add_zone_master.php\">\n";
  106. echo " <table>\n";
  107. echo " <tr>\n";
  108. echo " <td class=\"n\">" . _('Zone name') . ":</td>\n";
  109. echo " <td class=\"n\">\n";
  110. echo " <ul id=\"domain_names\" style=\"list-style-type:none; padding:0 \">\n";
  111. echo " <li><input type=\"text\" class=\"input\" name=\"domain[]\" value=\"\" id=\"domain_1\"></li>\n";
  112. echo " </ol>\n";
  113. echo " </td>\n";
  114. echo " <td class=\"n\">\n";
  115. echo " <input class=\"button\" type=\"button\" value=\"Add another domain\" onclick=\"addField('domain_names','domain_',0);\" />\n";
  116. echo " </td>\n";
  117. echo " </tr>\n";
  118. echo " <tr>\n";
  119. echo " <td class=\"n\">" . _('Owner') . ":</td>\n";
  120. echo " <td class=\"n\">\n";
  121. echo " <select name=\"owner\">\n";
  122. /*
  123. Display list of users to assign zone to if creating
  124. user has the proper permission to do so.
  125. */
  126. foreach ($users as $user) {
  127. if ($user['id'] === $_SESSION['userid']) {
  128. echo " <option value=\"" . $user['id'] . "\" selected>" . $user['fullname'] . "</option>\n";
  129. } elseif ($perm_view_others == "1") {
  130. echo " <option value=\"" . $user['id'] . "\">" . $user['fullname'] . "</option>\n";
  131. }
  132. }
  133. echo " </select>\n";
  134. echo " </td>\n";
  135. echo " <td class=\"n\">&nbsp;</td>\n";
  136. echo " </tr>\n";
  137. echo " <tr>\n";
  138. echo " <td class=\"n\">" . _('Type') . ":</td>\n";
  139. echo " <td class=\"n\">\n";
  140. echo " <select name=\"dom_type\">\n";
  141. foreach ($available_zone_types as $type) {
  142. echo " <option value=\"" . $type . "\">" . strtolower($type) . "</option>\n";
  143. }
  144. echo " </select>\n";
  145. echo " </td>\n";
  146. echo " <td>&nbsp;</td>\n";
  147. echo " </tr>\n";
  148. echo " <tr>\n";
  149. echo " <td class=\"n\">" . _('Template') . ":</td>\n";
  150. echo " <td class=\"n\">\n";
  151. echo " <select name=\"zone_template\">\n";
  152. echo " <option value=\"none\">none</option>\n";
  153. foreach ($zone_templates as $zone_template) {
  154. echo " <option value=\"" . $zone_template['id'] . "\">" . $zone_template['name'] . "</option>\n";
  155. }
  156. echo " </select>\n";
  157. echo " </td>\n";
  158. echo " <td>&nbsp;</td>\n";
  159. echo " </tr>\n";
  160. echo " <tr>\n";
  161. echo " <td class=\"n\">" . _('DNSSEC') . ":</td>\n";
  162. echo " <td class=\"n\"><input type=\"checkbox\" class=\"input\" name=\"dnssec\" value=\"1\"></td>\n";
  163. echo " </tr>\n";
  164. echo " <tr>\n";
  165. echo " <td class=\"n\">&nbsp;</td>\n";
  166. echo " <td class=\"n\">\n";
  167. echo " <input type=\"submit\" class=\"button\" name=\"submit\" value=\"" . _('Add zone') . "\" onclick=\"checkDomainFilled();return false;\">\n";
  168. echo " </td>\n";
  169. echo " <td class=\"n\">&nbsp;</td>\n";
  170. echo " </tr>\n";
  171. echo " </table>\n";
  172. echo " </form>\n";
  173. }
  174. include_once("inc/footer.inc.php");