Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

edit_zone_templ.php 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  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 zone templates editing
  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. $zone_templ_id = "-1";
  33. if (isset($_GET['id']) && v_num($_GET['id'])) {
  34. $zone_templ_id = $_GET['id'];
  35. }
  36. if ($zone_templ_id == "-1") {
  37. error(ERR_INV_INPUT);
  38. include_once("inc/footer.inc.php");
  39. exit;
  40. }
  41. /*
  42. Check permissions
  43. */
  44. $owner = get_zone_templ_is_owner($zone_templ_id, $_SESSION['userid']);
  45. if (isset($_POST['commit']) && $owner) {
  46. success(SUC_ZONE_TEMPL_UPD);
  47. foreach ($_POST['record'] as $record) {
  48. edit_zone_templ_record($record);
  49. }
  50. }
  51. if (isset($_POST['edit']) && $owner) {
  52. edit_zone_templ($_POST, $zone_templ_id);
  53. }
  54. if (isset($_POST['save_as'])) {
  55. if (zone_templ_name_exists($_POST['templ_name'])) {
  56. error(ERR_ZONE_TEMPL_EXIST);
  57. } elseif ($_POST['templ_name'] == '') {
  58. error(ERR_ZONE_TEMPL_IS_EMPTY);
  59. } else {
  60. success(SUC_ZONE_TEMPL_ADD);
  61. $templ_details = get_zone_templ_details($zone_templ_id);
  62. add_zone_templ_save_as($_POST['templ_name'], $_POST['templ_descr'], $_SESSION['userid'], $_POST['record']);
  63. }
  64. }
  65. if (isset($_POST['update_zones'])) {
  66. $zones = get_list_zone_use_templ($zone_templ_id, $_SESSION['userid']);
  67. success(SUC_ZONES_UPD);
  68. foreach ($zones as $zone) {
  69. update_zone_records($zone['id'], $zone_templ_id);
  70. }
  71. }
  72. if (!(verify_permission('zone_master_add')) || !$owner) {
  73. error(ERR_PERM_EDIT_ZONE_TEMPL);
  74. } else {
  75. if (zone_templ_id_exists($zone_templ_id) == "0") {
  76. error(ERR_ZONE_TEMPL_NOT_EXIST);
  77. } else {
  78. $record_count = count_zone_templ_records($zone_templ_id);
  79. $templ_details = get_zone_templ_details($zone_templ_id);
  80. echo " <h2>" . _('Edit zone template') . " \"" . $templ_details['name'] . "\"</h2>\n";
  81. echo " <div class=\"showmax\">\n";
  82. show_pages($record_count, $iface_rowamount, $zone_templ_id);
  83. echo " </div>\n";
  84. $records = get_zone_templ_records($zone_templ_id, ROWSTART, $iface_rowamount, RECORD_SORT_BY);
  85. if ($records == "-1") {
  86. echo " <p>" . _("This template zone does not have any records yet.") . "</p>\n";
  87. } else {
  88. echo " <form method=\"post\" action=\"\">\n";
  89. echo " <table>\n";
  90. echo " <tr>\n";
  91. echo " <th>&nbsp;</th>\n";
  92. echo " <th><a href=\"edit_zone_templ.php?id=" . $zone_templ_id . "&amp;record_sort_by=name\">" . _('Name') . "</a></th>\n";
  93. echo " <th><a href=\"edit_zone_templ.php?id=" . $zone_templ_id . "&amp;record_sort_by=type\">" . _('Type') . "</a></th>\n";
  94. echo " <th><a href=\"edit_zone_templ.php?id=" . $zone_templ_id . "&amp;record_sort_by=content\">" . _('Content') . "</a></th>\n";
  95. echo " <th><a href=\"edit_zone_templ.php?id=" . $zone_templ_id . "&amp;record_sort_by=prio\">" . _('Priority') . "</a></th>\n";
  96. echo " <th><a href=\"edit_zone_templ.php?id=" . $zone_templ_id . "&amp;record_sort_by=ttl\">" . _('TTL') . "</a></th>\n";
  97. echo " </tr>\n";
  98. foreach ($records as $r) {
  99. echo " <tr>\n";
  100. echo " <td class=\"n\">\n";
  101. echo " <input type=\"hidden\" name=\"record[" . $r['id'] . "][rid]\" value=\"" . $r['id'] . "\">\n";
  102. echo " <a href=\"edit_zone_templ_record.php?id=" . $r['id'] . "&amp;zone_templ_id=" . $zone_templ_id . "\">
  103. <img src=\"images/edit.gif\" alt=\"[ " . _('Edit record') . " ]\"></a>\n";
  104. echo " <a href=\"delete_zone_templ_record.php?id=" . $r['id'] . "&amp;zone_templ_id=" . $zone_templ_id . "\">
  105. <img src=\"images/delete.gif\" ALT=\"[ " . _('Delete record') . " ]\" BORDER=\"0\"></a>\n";
  106. echo " </td>\n";
  107. echo " <td class=\"u\"><input class=\"wide\" name=\"record[" . $r['id'] . "][name]\" value=\"" . $r['name'] . "\"></td>\n";
  108. echo " <td class=\"u\">\n";
  109. echo " <select name=\"record[" . $r['id'] . "][type]\">\n";
  110. $found_selected_type = false;
  111. foreach (get_record_types() as $type_available) {
  112. if ($type_available == $r['type']) {
  113. $add = " SELECTED";
  114. $found_selected_type = true;
  115. } else {
  116. $add = "";
  117. }
  118. echo " <option" . $add . " value=\"" . $type_available . "\" >" . $type_available . "</option>\n";
  119. }
  120. if (!$found_selected_type) {
  121. echo " <option SELECTED value=\"" . htmlspecialchars($r['type']) . "\"><i>" . $r['type'] . "</i></option>\n";
  122. }
  123. /*
  124. Sanitize content due to SPF record quoting in PowerDNS
  125. */
  126. if ($r['type'] == "SRV" || $r['type'] == "SPF") {
  127. $clean_content = trim($r['content'], "\x22\x27");
  128. } else {
  129. $clean_content = $r['content'];
  130. }
  131. echo " </select>\n";
  132. echo " </td>\n";
  133. echo " <td class=\"u\"><input class=\"wide\" name=\"record[" . $r['id'] . "][content]\" value='" . $clean_content . "'></td>\n";
  134. if ($r['type'] == "MX" || $r['type'] == "SRV") {
  135. echo " <td class=\"u\"><input name=\"record[" . $r['id'] . "][prio]\" value=\"" . $r['prio'] . "\"></td>\n";
  136. } else {
  137. echo " <td class=\"n\">&nbsp;</td>\n";
  138. }
  139. echo " <td class=\"u\"><input name=\"record[" . $r['id'] . "][ttl]\" value=\"" . $r['ttl'] . "\"></td>\n";
  140. echo " </tr>\n";
  141. }
  142. echo " <tr>\n";
  143. echo " <td colspan=\"6\"><br><b>Hint:</b></td>\n";
  144. echo " </tr>\n";
  145. echo " <tr>\n";
  146. echo " <td colspan=\"6\">" . _('The following placeholders can be used in template records') . "</td>\n";
  147. echo " </tr>\n";
  148. echo " <tr>\n";
  149. echo " <td colspan=\"6\"><br>&nbsp;&nbsp;&nbsp;&nbsp; * [ZONE] - " . _('substituted with current zone name') . "<br>";
  150. echo "&nbsp;&nbsp;&nbsp;&nbsp; * [SERIAL] - " . _('substituted with current date and 2 numbers') . " (YYYYMMDD + 00)</td>\n";
  151. echo " </tr>\n";
  152. echo " <tr>\n";
  153. echo " <td colspan=\"6\"><br>Save as new template:</td>\n";
  154. echo " </tr>\n";
  155. echo " <tr>\n";
  156. echo " <th>" . _('Template Name') . "</th>\n";
  157. echo " <td><input class=\"wide\" type=\"text\" name=\"templ_name\" value=\"\"></td>\n";
  158. echo " </tr>\n";
  159. echo " <tr>\n";
  160. echo " <th>" . _('Template Description') . "</th>\n";
  161. echo " <td><input class=\"wide\" type=\"text\" name=\"templ_descr\" value=\"\"></td>\n";
  162. echo " </tr>\n";
  163. echo " </table>\n";
  164. echo " <input type=\"submit\" class=\"button\" name=\"commit\" value=\"" . _('Commit changes') . "\">\n";
  165. echo " <input type=\"reset\" class=\"button\" name=\"reset\" value=\"" . _('Reset changes') . "\">\n";
  166. echo " <input type=\"submit\" class=\"button\" name=\"save_as\" value=\"" . _('Save as template') . "\">\n";
  167. echo " <input type=\"submit\" class=\"button\" name=\"update_zones\" value=\"" . _('Update zones') . "\">\n";
  168. echo " </form>";
  169. }
  170. echo " <form method=\"post\" action=\"\">\n";
  171. echo " <table>\n";
  172. echo " <tr>\n";
  173. echo " <th>" . _('Name') . "</th>\n";
  174. echo " <td><input class=\"wide\" type=\"text\" name=\"templ_name\" value=\"" . $templ_details['name'] . "\"></td>\n";
  175. echo " </tr>\n";
  176. echo " <tr>\n";
  177. echo " <th>" . _('Description') . "</th>\n";
  178. echo " <td><input class=\"wide\" type=\"text\" name=\"templ_descr\" value=\"" . $templ_details['descr'] . "\"></td>\n";
  179. echo " </tr>\n";
  180. echo " </table>\n";
  181. echo " <input type=\"submit\" class=\"button\" name=\"edit\" value=\"" . _('Commit changes') . "\">\n";
  182. echo " </form>\n";
  183. echo " <input type=\"button\" class=\"button\" OnClick=\"location.href='add_zone_templ_record.php?id=" . $zone_templ_id . "'\" value=\"" . _('Add record') . "\">&nbsp;&nbsp\n";
  184. echo " <input type=\"button\" class=\"button\" OnClick=\"location.href='delete_zone_templ.php?id=" . $zone_templ_id . "'\" value=\"" . _('Delete zone template') . "\">\n";
  185. }
  186. }
  187. include_once("inc/footer.inc.php");