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_record.php 8.9KB

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