forked from poweradmin/poweradmin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
177 lines (157 loc) · 8.36 KB
/
search.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/* Poweradmin, a friendly web-based admin tool for PowerDNS.
* See <http://www.poweradmin.org> for more details.
*
* Copyright 2007-2010 Rejo Zenger <[email protected]>
* Copyright 2010-2014 Poweradmin Development Team
* <http://www.poweradmin.org/credits.html>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* Script that handles search requests
*
* @package Poweradmin
* @copyright 2007-2010 Rejo Zenger <[email protected]>
* @copyright 2010-2014 Poweradmin Development Team
* @license http://opensource.org/licenses/GPL-3.0 GPL
*/
require_once 'inc/toolkit.inc.php';
require_once 'inc/header.inc.php';
if (!do_hook('verify_permission', 'search')) {
error(ERR_PERM_SEARCH);
require_once 'inc/footer.inc.php';
die();
}
$parameters['query'] = isset($_POST['query']) && !empty($_POST['query']) ? $_POST['query'] : '';
$parameters['zones'] = !isset($_POST['do_search']) && !isset($_POST['zones']) || isset($_POST['zones']) && $_POST['zones'] == true ? true : false;
$parameters['records'] = !isset($_POST['do_search']) && !isset($_POST['records']) || isset($_POST['records']) && $_POST['records'] == true ? true : false;
$parameters['wildcard'] = !isset($_POST['do_search']) && !isset($_POST['wildcard']) || isset($_POST['wildcard']) && $_POST['wildcard'] == true ? true : false;
$parameters['reverse'] = !isset($_POST['do_search']) && !isset($_POST['reverse']) || isset($_POST['reverse']) && $_POST['reverse'] == true ? true : false;
?>
<h2><?php echo _('Search zones and records'); ?></h2>
<form name="search_form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<table>
<tr>
<td>
<input type="text" class="input" name="query" value="<?php echo $parameters['query']; ?>">
<input type="submit" class="button" name="do_search" value="<?php echo _('Search'); ?>">
<input type="checkbox" class="input" name="zones" value="true"<?php echo $parameters['zones'] ? ' checked="checked"' : ''; ?>><?php echo _('Zones'); ?>
<input type="checkbox" class="input" name="records" value="true"<?php echo $parameters['records'] ? ' checked="checked"' : ''; ?>><?php echo _('Records'); ?> |
<input type="checkbox" class="input" name="wildcard" value="true"<?php echo $parameters['wildcard'] ? ' checked="checked"' : ''; ?>><?php echo _('Wildcard'); ?>
<input type="checkbox" class="input" name="reverse" value="true"<?php echo $parameters['reverse'] ? ' checked="checked"' : ''; ?>><?php echo _('Reverse'); ?>
<input type="hidden" name="zone_sort_by" value="<?php echo ZONE_SORT_BY; ?>">
<input type="hidden" name="record_sort_by" value="<?php echo RECORD_SORT_BY; ?>">
</td>
</tr>
<tr>
<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>
</tr>
</table>
</form>
<?php
if (isset($_POST['query'])) {
if (do_hook('verify_permission', 'zone_content_view_others')) {
$permissions['view'] = "all";
} elseif (do_hook('verify_permission', 'zone_content_view_own')) {
$permissions['view'] = "own";
} else {
$permissions['view'] = "none";
}
if (do_hook('verify_permission', 'zone_content_edit_others')) {
$permissions['edit'] = "all";
} elseif (do_hook('verify_permission', 'zone_content_edit_own')) {
$permissions['edit'] = "own";
} else {
$permissions['edit'] = "none";
}
$searchResult = search_zone_and_record(
$parameters,
$permissions['view'],
ZONE_SORT_BY,
RECORD_SORT_BY
);
if (is_array($searchResult['zones'])):
?>
<h3><?php echo _('Zones found'); ?></h3>
<table>
<tr>
<th></th>
<th><a href="javascript:zone_sort_by('name');"><?php echo _('Name'); ?></a></th>
<th><a href="javascript:zone_sort_by('type');"><?php echo _('Type'); ?></a></th>
<th><a href="javascript:zone_sort_by('count_records');"><?php echo _('Records'); ?></a></th>
<th><a href="javascript:zone_sort_by('fullname');"><?php echo _('Owner'); ?></a></th>
</tr>
<?php foreach ($searchResult['zones'] as $zone): ?>
<tr>
<td>
<?php if ($permissions['edit'] == 'all' || $permissions['edit'] == 'own' && do_hook('verify_user_is_owner_zoneid', $zone['id'])): ?>
<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>
<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>
<?php endif; ?>
</td>
<td><?php echo $zone['name']; ?></td>
<td><?php echo $zone['type']; ?></td>
<td><?php echo $zone['count_records']; ?></td>
<td><?php echo $zone['fullname']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php
endif;
if (is_array($searchResult['records'])):
?>
<h3><?php echo _('Records found'); ?></h3>
<table>
<tr>
<th></th>
<th><a href="javascript:record_sort_by('name');"><?php echo _('Name'); ?></a></th>
<th><a href="javascript:record_sort_by('type');"><?php echo _('Type'); ?></a></th>
<th><a href="javascript:record_sort_by('prio');"><?php echo _('Priority'); ?></a></th>
<th><a href="javascript:record_sort_by('content');"><?php echo _('Content'); ?></a></th>
<th><a href="javascript:record_sort_by('ttl');"><?php echo _('TTL'); ?></a></th>
</tr>
<?php foreach ($searchResult['records'] as $record): ?>
<tr>
<td>
<?php if ($permissions['edit'] == 'all' || $permissions['edit'] == 'own' && do_hook('verify_user_is_owner_zoneid', $record['domain_id'])): ?>
<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>
<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>
<?php endif; ?>
</td>
<td><?php echo $record['name']; ?></td>
<td><?php echo $record['type']; ?></td>
<td><?php echo $record['prio']; ?></td>
<td><?php echo $record['content']; ?></td>
<td><?php echo $record['ttl']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<script type="text/javascript">
function zone_sort_by(sortbytype)
{
document.search_form.zone_sort_by.value = sortbytype;
document.getElementsByName("do_search")[0].click();
}
function record_sort_by(sortbytype)
{
document.search_form.record_sort_by.value = sortbytype;
document.getElementsByName("do_search")[0].click();
}
</script>
<?php
endif;
}
require_once 'inc/footer.inc.php';
?>