Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

add_record.php 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 request to add new records to existing zone
  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. Get permissions
  34. */
  35. if (verify_permission('zone_content_view_others')) {
  36. $perm_view = "all";
  37. } elseif (verify_permission('zone_content_view_own')) {
  38. $perm_view = "own";
  39. } else {
  40. $perm_view = "none";
  41. }
  42. if (verify_permission('zone_content_edit_others')) {
  43. $perm_content_edit = "all";
  44. } elseif (verify_permission('zone_content_edit_own')) {
  45. $perm_content_edit = "own";
  46. } else {
  47. $perm_content_edit = "none";
  48. }
  49. if (verify_permission('zone_meta_edit_others')) {
  50. $perm_meta_edit = "all";
  51. } elseif (verify_permission('zone_meta_edit_own')) {
  52. $perm_meta_edit = "own";
  53. } else {
  54. $perm_meta_edit = "none";
  55. }
  56. /*
  57. Check and make sure all post values have made it through
  58. if not set them.
  59. */
  60. $zone_id = "-1";
  61. if ((isset($_GET['id'])) && (v_num($_GET['id']))) {
  62. $zone_id = $_GET['id'];
  63. }
  64. $ttl = $dns_ttl;
  65. if ((isset($_POST['ttl'])) && (v_num($_POST['ttl']))) {
  66. $ttl = $_POST['ttl'];
  67. }
  68. $prio = "10";
  69. if ((isset($_POST['prio'])) && (v_num($_POST['prio']))) {
  70. $prio = $_POST['prio'];
  71. }
  72. if (isset($_POST['name'])) {
  73. $name = $_POST['name'];
  74. } else {
  75. $name = "";
  76. }
  77. if (isset($_POST['type'])) {
  78. $type = $_POST['type'];
  79. } else {
  80. $type = "";
  81. }
  82. if (isset($_POST['content'])) {
  83. $content = $_POST['content'];
  84. } else {
  85. $content = "";
  86. }
  87. if ($zone_id == "-1") {
  88. error(ERR_INV_INPUT);
  89. include_once("inc/footer.inc.php");
  90. exit;
  91. }
  92. /*
  93. Check and see if the user is the zone owner
  94. Check the sone type and get the zone name
  95. */
  96. $user_is_zone_owner = verify_user_is_owner_zoneid($zone_id);
  97. $zone_type = get_domain_type($zone_id);
  98. $zone_name = get_zone_name_from_id($zone_id);
  99. /*
  100. If the form as been submitted
  101. process it!
  102. */
  103. if (isset($_POST["commit"])) {
  104. if ($zone_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0") {
  105. error(ERR_PERM_ADD_RECORD);
  106. } else {
  107. // a PTR-record is added if an A or an AAAA-record are created
  108. // and checkbox is checked
  109. if ((isset($_POST["reverse"])) && $iface_add_reverse_record ) {
  110. if ($type === 'A') {
  111. $content_array = preg_split("/\./", $content);
  112. $content_rev = sprintf("%d.%d.%d.%d.in-addr.arpa", $content_array[3], $content_array[2], $content_array[1], $content_array[0]);
  113. $zone_rev_id = get_best_matching_zone_id_from_name($content_rev);
  114. } elseif ($type === 'AAAA') {
  115. $content_rev = convert_ipv6addr_to_ptrrec($content);
  116. $zone_rev_id = get_best_matching_zone_id_from_name($content_rev);
  117. }
  118. if (isset($zone_rev_id) && $zone_rev_id != -1) {
  119. $zone_name = get_zone_name_from_id($zone_id);
  120. $fqdn_name = sprintf("%s.%s", $name, $zone_name);
  121. if (add_record($zone_rev_id, $content_rev, 'PTR', $fqdn_name, $ttl, $prio)) {
  122. success(" <a href=\"edit.php?id=" . $zone_rev_id . "\"> " . _('The PTR-record was successfully added.') . "</a>");
  123. log_info(sprintf('client_ip:%s user:%s operation:add_record record_type:PTR record:%s content:%s ttl:%s priority:%s',
  124. $_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
  125. $content_rev, $fqdn_name, $ttl, $prio));
  126. }
  127. } elseif (isset($content_rev)) {
  128. error(sprintf(ERR_REVERS_ZONE_NOT_EXIST, $content_rev));
  129. }
  130. }
  131. if (add_record($zone_id, $name, $type, $content, $ttl, $prio)) {
  132. success(" <a href=\"edit.php?id=" . $zone_id . "\"> " . _('The record was successfully added.') . "</a>");
  133. log_info(sprintf('client_ip:%s user:%s operation:add_record record_type:%s record:%s.%s content:%s ttl:%s priority:%s',
  134. $_SERVER['REMOTE_ADDR'], $_SESSION["userlogin"],
  135. $type, $name, $zone_name, $content, $ttl, $prio));
  136. $name = $type = $content = $ttl = $prio = "";
  137. }
  138. }
  139. }
  140. /*
  141. Display form to add a record
  142. */
  143. echo " <h2>" . _('Add record to zone') . " <a href=\"edit.php?id=" . $zone_id . "\"> " . $zone_name . "</a></h2>\n";
  144. if ($zone_type == "SLAVE" || $perm_content_edit == "none" || $perm_content_edit == "own" && $user_is_zone_owner == "0") {
  145. error(ERR_PERM_ADD_RECORD);
  146. } else {
  147. echo " <form method=\"post\">\n";
  148. echo " <input type=\"hidden\" name=\"domain\" value=\"" . $zone_id . "\">\n";
  149. echo " <table border=\"0\" cellspacing=\"4\">\n";
  150. echo " <tr>\n";
  151. echo " <td class=\"n\">" . _('Name') . "</td>\n";
  152. echo " <td class=\"n\">&nbsp;</td>\n";
  153. echo " <td class=\"n\">" . _('Type') . "</td>\n";
  154. echo " <td class=\"n\">" . _('Content') . "</td>\n";
  155. echo " <td class=\"n\">" . _('Priority') . "</td>\n";
  156. echo " <td class=\"n\">" . _('TTL') . "</td>\n";
  157. echo " </tr>\n";
  158. echo " <tr>\n";
  159. echo " <td class=\"n\"><input type=\"text\" name=\"name\" class=\"input\" value=\"" . htmlspecialchars($name) . "\">." . $zone_name . "</td>\n";
  160. echo " <td class=\"n\">IN</td>\n";
  161. echo " <td class=\"n\">\n";
  162. echo " <select name=\"type\">\n";
  163. $found_selected_type = !(isset($type) && $type);
  164. foreach (get_record_types() as $record_type) {
  165. if (isset($type) && $type) {
  166. if ($type == $record_type) {
  167. $found_selected_type = true;
  168. $add = " SELECTED";
  169. } else {
  170. $add = "";
  171. }
  172. } else {
  173. if (preg_match('/i(p6|n-addr).arpa/i', $zone_name) && strtoupper($record_type) == 'PTR') {
  174. $add = " SELECTED";
  175. $rev = "";
  176. } elseif ((strtoupper($record_type) == 'A') && $iface_add_reverse_record) {
  177. $add = " SELECTED";
  178. $rev = "<input type=\"checkbox\" name=\"reverse\"><span class=\"normaltext\">" . _('Add also reverse record') . "</span>\n";
  179. } else {
  180. $add = "";
  181. }
  182. }
  183. echo " <option" . $add . " value=\"" . htmlspecialchars($record_type) . "\">" . $record_type . "</option>\n";
  184. }
  185. if (!$found_selected_type)
  186. echo " <option SELECTED value=\"" . htmlspecialchars($type) . "\"><i>" . htmlspecialchars($type) . "</i></option>\n";
  187. echo " </select>\n";
  188. echo " </td>\n";
  189. echo " <td class=\"n\"><input type=\"text\" name=\"content\" class=\"input\" value=\"" . htmlspecialchars($content) . "\"></td>\n";
  190. echo " <td class=\"n\"><input type=\"text\" name=\"prio\" class=\"sinput\" value=\"" . htmlspecialchars($prio) . "\"></td>\n";
  191. echo " <td class=\"n\"><input type=\"text\" name=\"ttl\" class=\"sinput\" value=\"" . htmlspecialchars($ttl) . "\"</td>\n";
  192. echo " </tr>\n";
  193. echo " </table>\n";
  194. echo " <br>\n";
  195. echo " <input type=\"submit\" name=\"commit\" value=\"" . _('Add record') . "\" class=\"button\">\n";
  196. if (isset($rev)) {
  197. echo " $rev";
  198. }
  199. echo " </form>\n";
  200. }
  201. include_once("inc/footer.inc.php");