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_templ_record.php 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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-2014 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 records to zone templates
  24. *
  25. * @package Poweradmin
  26. * @copyright 2007-2010 Rejo Zenger <rejo@zenger.nl>
  27. * @copyright 2010-2014 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. /*
  33. Check and make sure all post values have made it through
  34. if not set them.
  35. */
  36. $zone_templ_id = "-1";
  37. if ((isset($_GET['id'])) && (v_num($_GET['id']))) {
  38. $zone_templ_id = $_GET['id'];
  39. }
  40. $ttl = $dns_ttl;
  41. if ((isset($_POST['ttl'])) && (v_num($_POST['ttl']))) {
  42. $ttl = $_POST['ttl'];
  43. }
  44. $prio = "";
  45. if ((isset($_POST['prio'])) && (v_num($_POST['prio']))) {
  46. $prio = $_POST['prio'];
  47. }
  48. if (isset($_POST['name'])) {
  49. $name = $_POST['name'];
  50. } else {
  51. $name = "";
  52. }
  53. if (isset($_POST['type'])) {
  54. $type = $_POST['type'];
  55. } else {
  56. $type = "";
  57. }
  58. if (isset($_POST['content'])) {
  59. $content = $_POST['content'];
  60. } else {
  61. $content = "";
  62. }
  63. if ($zone_templ_id == "-1") {
  64. error(ERR_INV_INPUT);
  65. include_once("inc/footer.inc.php");
  66. exit;
  67. }
  68. $templ_details = get_zone_templ_details($zone_templ_id);
  69. $owner = get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
  70. /*
  71. If the form as been submitted
  72. process it!
  73. */
  74. if (isset($_POST["commit"])) {
  75. if (!(verify_permission('zone_master_add')) || !$owner) {
  76. error(ERR_PERM_ADD_RECORD);
  77. } else {
  78. if (add_zone_templ_record($zone_templ_id, $name, $type, $content, $ttl, $prio)) {
  79. success(_('The record was successfully added.'));
  80. $name = $type = $content = $ttl = $prio = "";
  81. }
  82. }
  83. }
  84. /*
  85. Display form to add a record
  86. */
  87. echo " <h2>" . _('Add record to zone template') . " \"" . $templ_details['name'] . "\"</h2>\n";
  88. if (!(verify_permission('zone_master_add')) || !$owner) {
  89. error(ERR_PERM_ADD_RECORD);
  90. } else {
  91. echo " <form method=\"post\">\n";
  92. echo " <input type=\"hidden\" name=\"domain\" value=\"" . $zone_templ_id . "\">\n";
  93. echo " <table border=\"0\" cellspacing=\"4\">\n";
  94. echo " <tr>\n";
  95. echo " <td class=\"n\">" . _('Name') . "</td>\n";
  96. echo " <td class=\"n\">&nbsp;</td>\n";
  97. echo " <td class=\"n\">" . _('Type') . "</td>\n";
  98. echo " <td class=\"n\">" . _('Content') . "</td>\n";
  99. echo " <td class=\"n\">" . _('Priority') . "</td>\n";
  100. echo " <td class=\"n\">" . _('TTL') . "</td>\n";
  101. echo " </tr>\n";
  102. echo " <tr>\n";
  103. echo " <td class=\"n\"><input type=\"text\" name=\"name\" class=\"input\" value=\"" . $name . "\"></td>\n";
  104. echo " <td class=\"n\">IN</td>\n";
  105. echo " <td class=\"n\">\n";
  106. echo " <select name=\"type\">\n";
  107. $found_selected_type = !(isset($type) && $type);
  108. foreach (get_record_types() as $record_type) {
  109. if (isset($type) && $type) {
  110. if ($type == $record_type) {
  111. $add = " SELECTED";
  112. $found_selected_type = true;
  113. } else {
  114. $add = "";
  115. }
  116. } else {
  117. // TODO: from where comes $zone_name value and why this check exists here?
  118. if (isset($zone_name) && preg_match('/i(p6|n-addr).arpa/i', $zone_name) && strtoupper($record_type) == 'PTR') {
  119. $add = " SELECTED";
  120. } elseif (strtoupper($record_type) == 'A') {
  121. $add = " SELECTED";
  122. } else {
  123. $add = "";
  124. }
  125. }
  126. echo " <option" . $add . " value=\"" . $record_type . "\">" . $record_type . "</option>\n";
  127. }
  128. if (!$found_selected_type)
  129. echo " <option SELECTED value=\"" . htmlspecialchars($type) . "\"><i>" . htmlspecialchars($type) . "</i></option>\n";
  130. echo " </select>\n";
  131. echo " </td>\n";
  132. echo " <td class=\"n\"><input type=\"text\" name=\"content\" class=\"input\" value=\"" . $content . "\"></td>\n";
  133. echo " <td class=\"n\"><input type=\"text\" name=\"prio\" class=\"sinput\" value=\"" . $prio . "\"></td>\n";
  134. echo " <td class=\"n\"><input type=\"text\" name=\"ttl\" class=\"sinput\" value=\"" . $ttl . "\"</td>\n";
  135. echo " </tr>\n";
  136. echo " <tr>\n";
  137. echo " <td colspan=\"6\"><br><b>Hint:</b></td>\n";
  138. echo " </tr>\n";
  139. echo " <tr>\n";
  140. echo " <td colspan=\"6\">" . _('The following placeholders can be used in template records') . "</td>\n";
  141. echo " </tr>\n";
  142. echo " <tr>\n";
  143. echo " <td colspan=\"6\"><br>&nbsp;&nbsp;&nbsp;&nbsp; * [ZONE] - " . _('substituted with current zone name') . "<br>";
  144. echo "&nbsp;&nbsp;&nbsp;&nbsp; * [SERIAL] - " . _('substituted with current date and 2 numbers') . " (YYYYMMDD + 00)</td>\n";
  145. echo " </tr>\n";
  146. echo " </table>\n";
  147. echo " <br>\n";
  148. echo " <input type=\"submit\" name=\"commit\" value=\"" . _('Add record') . "\" class=\"button\">\n";
  149. echo " </form>\n";
  150. }
  151. include_once("inc/footer.inc.php");