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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 search requests
  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. require_once 'inc/header.inc.php';
  32. if (!do_hook('verify_permission', 'search')) {
  33. error(ERR_PERM_SEARCH);
  34. require_once 'inc/footer.inc.php';
  35. die();
  36. }
  37. $parameters['query'] = isset($_POST['query']) && !empty($_POST['query']) ? $_POST['query'] : '';
  38. $parameters['zones'] = !isset($_POST['do_search']) && !isset($_POST['zones']) || isset($_POST['zones']) && $_POST['zones'] == true ? true : false;
  39. $parameters['records'] = !isset($_POST['do_search']) && !isset($_POST['records']) || isset($_POST['records']) && $_POST['records'] == true ? true : false;
  40. $parameters['wildcard'] = !isset($_POST['do_search']) && !isset($_POST['wildcard']) || isset($_POST['wildcard']) && $_POST['wildcard'] == true ? true : false;
  41. $parameters['reverse'] = !isset($_POST['do_search']) && !isset($_POST['reverse']) || isset($_POST['reverse']) && $_POST['reverse'] == true ? true : false;
  42. ?>
  43. <h2><?php echo _('Search zones and records'); ?></h2>
  44. <form name="search_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
  45. <table>
  46. <tr>
  47. <td>
  48. <input type="text" class="input" name="query" value="<?php echo $parameters['query']; ?>">
  49. <input type="submit" class="button" name="do_search" value="<?php echo _('Search'); ?>">
  50. <input type="checkbox" class="input" name="zones" value="true"<?php echo $parameters['zones'] ? ' checked="checked"' : ''; ?>><?php echo _('Zones'); ?>
  51. <input type="checkbox" class="input" name="records" value="true"<?php echo $parameters['records'] ? ' checked="checked"' : ''; ?>><?php echo _('Records'); ?> |
  52. <input type="checkbox" class="input" name="wildcard" value="true"<?php echo $parameters['wildcard'] ? ' checked="checked"' : ''; ?>><?php echo _('Wildcard'); ?>
  53. <input type="checkbox" class="input" name="reverse" value="true"<?php echo $parameters['reverse'] ? ' checked="checked"' : ''; ?>><?php echo _('Reverse'); ?>
  54. <input type="hidden" name="zone_sort_by" value="<?php echo ZONE_SORT_BY; ?>">
  55. <input type="hidden" name="record_sort_by" value="<?php echo RECORD_SORT_BY; ?>">
  56. </td>
  57. </tr>
  58. <tr>
  59. <td><?php echo _('Enter a hostname or IP address. SQL LIKE syntax supported: an underscore (_) in pattern matches any single character, a percent sign (%) matches any string of zero or more characters.'); ?></td>
  60. </tr>
  61. </table>
  62. </form>
  63. <?php
  64. if (isset($_POST['query'])) {
  65. if (do_hook('verify_permission', 'zone_content_view_others')) {
  66. $permissions['view'] = "all";
  67. } elseif (do_hook('verify_permission', 'zone_content_view_own')) {
  68. $permissions['view'] = "own";
  69. } else {
  70. $permissions['view'] = "none";
  71. }
  72. if (do_hook('verify_permission', 'zone_content_edit_others')) {
  73. $permissions['edit'] = "all";
  74. } elseif (do_hook('verify_permission', 'zone_content_edit_own')) {
  75. $permissions['edit'] = "own";
  76. } else {
  77. $permissions['edit'] = "none";
  78. }
  79. $searchResult = search_zone_and_record(
  80. $parameters,
  81. $permissions['view'],
  82. ZONE_SORT_BY,
  83. RECORD_SORT_BY
  84. );
  85. if (is_array($searchResult['zones'])):
  86. ?>
  87. <h3><?php echo _('Zones found'); ?></h3>
  88. <table>
  89. <tr>
  90. <th></th>
  91. <th><a href="javascript:zone_sort_by('name');"><?php echo _('Name'); ?></a></th>
  92. <th><a href="javascript:zone_sort_by('type');"><?php echo _('Type'); ?></a></th>
  93. <th><a href="javascript:zone_sort_by('count_records');"><?php echo _('Records'); ?></a></th>
  94. <th><a href="javascript:zone_sort_by('fullname');"><?php echo _('Owner'); ?></a></th>
  95. </tr>
  96. <?php foreach ($searchResult['zones'] as $zone): ?>
  97. <tr>
  98. <td>
  99. <?php if ($permissions['edit'] == 'all' || $permissions['edit'] == 'own' && do_hook('verify_user_is_owner_zoneid', $zone['id'])): ?>
  100. <a href="<?php echo 'edit.php?name=' . $zone['name'] . '&id=' . $zone['id']; ?>"><img src="images/edit.gif" alt="[ <?php echo _('Edit zone'); ?> ]" title="<?php echo _('Edit zone'); ?>"></a>
  101. <a href="<?php echo 'delete_domain.php?name=' . $zone['name'] . '&id=' . $zone['id']; ?>"><img src="images/delete.gif" alt="[ <?php echo _('Delete zone'); ?> ]" title="<?php echo _('Delete zone'); ?>"></a>
  102. <?php endif; ?>
  103. </td>
  104. <td><?php echo $zone['name']; ?></td>
  105. <td><?php echo $zone['type']; ?></td>
  106. <td><?php echo $zone['count_records']; ?></td>
  107. <td><?php echo $zone['fullname']; ?></td>
  108. </tr>
  109. <?php endforeach; ?>
  110. </table>
  111. <?php
  112. endif;
  113. if (is_array($searchResult['records'])):
  114. ?>
  115. <h3><?php echo _('Records found'); ?></h3>
  116. <table>
  117. <tr>
  118. <th></th>
  119. <th><a href="javascript:record_sort_by('name');"><?php echo _('Name'); ?></a></th>
  120. <th><a href="javascript:record_sort_by('type');"><?php echo _('Type'); ?></a></th>
  121. <th><a href="javascript:record_sort_by('prio');"><?php echo _('Priority'); ?></a></th>
  122. <th><a href="javascript:record_sort_by('content');"><?php echo _('Content'); ?></a></th>
  123. <th><a href="javascript:record_sort_by('ttl');"><?php echo _('TTL'); ?></a></th>
  124. </tr>
  125. <?php foreach ($searchResult['records'] as $record): ?>
  126. <tr>
  127. <td>
  128. <?php if ($permissions['edit'] == 'all' || $permissions['edit'] == 'own' && do_hook('verify_user_is_owner_zoneid', $record['domain_id'])): ?>
  129. <a href="<?php echo 'edit_record.php?domain=' . $record['domain_id'] . '&id=' . $record['id']; ?>"><img src="images/edit.gif" alt="[ <?php echo _('Edit zone'); ?> ]" title="<?php echo _('Edit zone'); ?>"></a>
  130. <a href="<?php echo 'delete_record.php?domain=' . $record['domain_id'] . '&id=' . $record['id']; ?>"><img src="images/delete.gif" alt="[ <?php echo _('Delete zone'); ?> ]" title="<?php echo _('Delete zone'); ?>"></a>
  131. <?php endif; ?>
  132. </td>
  133. <td><?php echo $record['name']; ?></td>
  134. <td><?php echo $record['type']; ?></td>
  135. <td><?php echo $record['prio']; ?></td>
  136. <td><?php echo $record['content']; ?></td>
  137. <td><?php echo $record['ttl']; ?></td>
  138. </tr>
  139. <?php endforeach; ?>
  140. </table>
  141. <script type="text/javascript">
  142. function zone_sort_by(sortbytype)
  143. {
  144. document.search_form.zone_sort_by.value = sortbytype;
  145. document.getElementsByName("do_search")[0].click();
  146. }
  147. function record_sort_by(sortbytype)
  148. {
  149. document.search_form.record_sort_by.value = sortbytype;
  150. document.getElementsByName("do_search")[0].click();
  151. }
  152. </script>
  153. <?php
  154. endif;
  155. }
  156. require_once 'inc/footer.inc.php';
  157. ?>