-
Notifications
You must be signed in to change notification settings - Fork 0
/
domaintable.inc.php
387 lines (332 loc) · 14.1 KB
/
domaintable.inc.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
<?php
include_once("logging.inc.php");
function showdomains ($count, $page, $adminlist, $search, $user) {
global $DB, $row_classes, $content_footer;
$searchstr = "%".$search."%";
/* do the database queries */
if ($adminlist==1) {
if (strlen($search) > 0) { # admin doing a search
$domains = $DB->prepare("SELECT domains.id AS domain_id, domains.type AS type, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id WHERE domains.name LIKE ? ".
"GROUP BY domainname, domain_id ORDER BY domainname");
$dbreturn = $DB->execute($domains, array($searchstr));
$domsall = $DB->prepare("SELECT domains.id AS domain_id, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id WHERE domains.name LIKE ? ".
"GROUP BY domainname, domain_id");
$dbreturnall = $DB->execute($domsall, array($searchstr));
} else { # no search
$domains = $DB->prepare("SELECT domains.id AS domain_id, domains.type AS type, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id ".
"GROUP BY domainname, domain_id ORDER BY domainname");
$dbreturn = $DB->execute($domains, NULL);
$domsall = $DB->prepare("SELECT domains.id AS domain_id, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id ".
"GROUP BY domainname, domain_id");
$dbreturnall = $DB->execute($domsall, NULL);
}
} else {
if (strlen($search) > 0) { # non admin doing a search
$domains = $DB->prepare("SELECT domains.id AS domain_id, domains.type AS type, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id WHERE zones.owner=? AND domains.name LIKE ? ".
"GROUP BY domainname, domain_id ORDER BY domainname");
$dbreturn = $DB->execute($domains, array((int) $user, $searchstr));
$domsall = $DB->prepare("SELECT domains.id AS domain_id, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id WHERE zones.owner=? AND domains.name LIKE ? ".
"GROUP BY domainname, domain_id");
$dbreturnall = $DB->execute($domsall, array((int) $user, $searchstr));
} else { # no search
$domains = $DB->prepare("SELECT domains.id AS domain_id, domains.type AS type, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id WHERE zones.owner=? ".
"GROUP BY domainname, domain_id ORDER BY domainname");
$dbreturn = $DB->execute($domains, array((int) $user));
$domsall = $DB->prepare("SELECT domains.id AS domain_id, min(zones.owner) ".
"AS owner, domains.name AS domainname FROM domains LEFT JOIN zones ON domains.id=zones.domain_id LEFT JOIN records ON records.domain_id=domains.id WHERE zones.owner=? ".
"GROUP BY domainname, domain_id");
$dbreturnall = $DB->execute($domsall, array((int) $user));
}
}
if (PEAR::isError($dbreturn)) {
writelog($_SESSION['username'], $_SESSION['userid'], 5, $dbreturn->getMessage());
header('Location: error.php?error=dberror');
}
if (PEAR::isError($dbreturnall)) {
writelog($_SESSION['username'], $_SESSION['userid'], 5, $dbreturnall->getMessage());
header('Location: error.php?error=dberror');
}
$total = $dbreturnall->numRows();
$num_pages = ceil($dbreturnall->numRows() / $count);
if ($page > $num_pages) { $page = $num_pages; }
if (!$dbreturn->numRows() >= 1) {
if (strlen($search) > 0) {
echo "No domains matched your search query.";
} else {
echo "No domains available.";
}
} else {
$thisfile = $_SERVER['PHP_SELF'];
/*
if ($page > 1) {
$content_footer["left"] = "<a href=\"". $thisfile ."?page=". ($page-1) ."&search=". htmlentities($search) ."\">« Previous Page</a>";
}
$content_footer["middle"] = "Page $page of $num_pages";
if ($page < $num_pages) {
$content_footer["right"] = "<a href=\"". $thisfile ."?page=". ($page+1) ."&search=". htmlentities($search) ."\">Next Page »</a>";
}
*/
?>
<div class="section">
<?php
if (strlen($search) > 0) { ?>
<h1>Search results: (<?php print $total; ?>)</h1>
<?php } else {
if ($adminlist==1) { ?>
<h1>Total domains in system: (<?php print $total; ?>)</h1>
<?php } else { ?>
<h1>Domains for user: <?php print htmlentities($_SESSION['username']); ?>, Total: (<?php print $total; ?>)</h1>
<?php }
} ?>
[ <a href="addhost.php?domain=<?php print htmlentities($domainid); ?>">Add host</a> ]<br>
<?php
/*
<div class="controls">
<?php show_numberset($thisfile, $page, $search, 0); ?>
</div>
*/
?>
<table class="display compact" id="domains-table">
<thead>
<tr class="header">
<td>Domain name</td>
<td>Type</td>
<td>Owner(s)</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<?php
while ($row = $dbreturn->fetchRow(DB_FETCHMODE_OBJECT)) {
if (DB::isError($row)) {
header('Location: error.php?error=dberror');
}
#if (($adminlist == 1) || (isowner($row->id))) { # only if we own the domain or are admin
?>
<tr class="<?php print $row_classes[$count++ % 2]; ?>">
<td><a href="editdomain.php?id=<?php print $row->domain_id; ?>"><?php print htmlentities($row->domainname); ?></a></td>
<td><?php print $row->type; ?></td>
<td>
<select name="owners"size="1">
<?php print domainowners($row->domain_id); ?>
</select>
</td>
<td>[ <a href="domain-delete.php?id=<?php print $row->domain_id; ?>" onClick="return confirmAction('Delete domain: <?php print htmlentities($row->domainname); ?>?')">Delete</a> | <a href="editdomain.php?id=<?php print $row->domain_id; ?>">Edit</a> ]</td>
</tr>
<?php
# }
}
?> </tbody>
</table>
</div>
<script>
$(document).ready(function() {
$('#domains-table').DataTable({
"order": [ 0, 'asc' ],
"columns": [
{
"orderable": true,
"searchable": true
},
{
"orderable": true,
"searchable": false
},
{
"orderable": true,
"searchable": false
},
{
"orderable": false,
"searchable": false
}
]
});
});
</script>
<?php
}
}
function domainowners ($domainid) {
global $DB;
$query = $DB->prepare("SELECT owner FROM zones WHERE domain_id = ?;");
$dbreturn = $DB->execute($query, array((int) $domainid));
if ($dbreturn->numRows() < 1) {
print "<option value=\"10\">System</option>";
return;
}
while ($row = $dbreturn->fetchRow(DB_FETCHMODE_OBJECT)) {
if (DB::isError($row)) {
header('Location: error.php?error=dberror');
}
print "<option value=\"10\">". htmlentities(id2user($row->owner)) ."</option>";
}
}
function showdomain ($domainid, $count, $page, $adminlist, $search) {
global $DB, $row_classes, $content_footer;
$user = $_SESSION["userid"];
if (!(is_owner($domainid, $user)) && !(isadmin())) {
redirect("error.php?error=perm");
}
$dname = domain_id2name($domainid);
$searchstr = "%".$search."%";
/* order nicely */
/* select name, type, content, CASE type WHEN 'SOA' THEN 1 WHEN 'NS' THEN 2 WHEN 'MX' THEN 3 WHEN 'TXT' THEN 4 WHEN 'A' THEN 5 WHEN 'AAAA' THEN 5 ELSE 6 END AS ordering FROM records WHERE domain_id=20 ORDER BY ordering limit 50; */
/* do the database queries */
if (strlen($search) > 0) { # doing a search
$domainq = $DB->prepare("SELECT *, CASE type WHEN 'SOA' THEN 1 WHEN 'NS' THEN 2 WHEN 'MX' THEN 3 WHEN 'TXT' THEN 4 WHEN 'A' THEN 5 WHEN 'AAAA' THEN 5 ELSE 6 END AS ordering FROM records WHERE domain_id=? AND content LIKE ? OR name LIKE ? ORDER BY ordering");
$dbreturn = $DB->execute($domainq, array((int) $domainid, $searchstr, $searchstr));
$domsall = $DB->prepare("SELECT *, CASE type WHEN 'SOA' THEN 1 WHEN 'NS' THEN 2 WHEN 'MX' THEN 3 WHEN 'TXT' THEN 4 WHEN 'A' THEN 5 WHEN 'AAAA' THEN 5 ELSE 6 END AS ordering FROM records WHERE domain_id=? AND content LIKE ? OR name LIKE ? ORDER BY ordering");
$dbreturnall = $DB->execute($domsall, array((int) $domainid, $searchstr, $searchstr));
} else { # no search
$domainq = $DB->prepare("SELECT *, CASE type WHEN 'SOA' THEN 1 WHEN 'NS' THEN 2 WHEN 'MX' THEN 3 WHEN 'TXT' THEN 4 WHEN 'A' THEN 5 WHEN 'AAAA' THEN 5 ELSE 6 END AS ordering FROM records WHERE domain_id=? ORDER BY ordering");
$dbreturn = $DB->execute($domainq, array((int) $domainid));
$domsall = $DB->prepare("SELECT *, CASE type WHEN 'SOA' THEN 1 WHEN 'NS' THEN 2 WHEN 'MX' THEN 3 WHEN 'TXT' THEN 4 WHEN 'A' THEN 5 WHEN 'AAAA' THEN 5 ELSE 6 END AS ordering FROM records WHERE domain_id=? ORDER BY ordering");
$dbreturnall = $DB->execute($domsall, array((int) $domainid));
}
if (PEAR::isError($dbreturn)) {
print $dbreturn->getMessage();
header('Location: error.php?error=dberror');
}
if (PEAR::isError($dbreturnall)) {
writelog($_SESSION['username'], $_SESSION['userid'], 5, $dbreturnall->getMessage());
print $dbreturnall->getMessage();
// header('Location: error.php?error=dberror');
}
$total = $dbreturnall->numRows();
$num_pages = ceil($dbreturnall->numRows() / $count);
if ($page > $num_pages) { $page = $num_pages; }
if (!$dbreturn->numRows() >= 1) {
if (strlen($search) > 0) {
echo "No records matched your search query.";
} else {
echo "No records available.";
}
} else {
$thisfile = $_SERVER['PHP_SELF'];
if ($page > 1) {
$content_footer["left"] = "<a href=\"". $thisfile ."?page=". ($page-1) ."&id=". $domainid ."&search=". htmlentities($search) ."\">« Previous Page</a>";
}
$content_footer["middle"] = "Page $page of $num_pages";
if ($page < $num_pages) {
$content_footer["right"] = "<a href=\"". $thisfile ."?page=". ($page+1) ."&id=". $domainid ."&search=". htmlentities($search) ."\">Next Page »</a>";
}
?>
<div class="section">
<?php
if (strlen($search) > 0) { ?>
<h1>Search results: (<?php print $total; ?>)</h1>
<?php } else {
if ($adminlist==1) { ?>
<h1>Total domains in system: (<?php print $total; ?>)</h1>
<?php } else { ?>
<h1>Records for domain <?php print htmlentities($dname); ?> Total (<?php print $total; ?>)</h1>
<?php }
} ?>
<div class="controls">
<table class="controls">
<tr class="controls">
<td class="left">
<form action="domainproperties.php" method="get">
<input type="hidden" name="id" value="<?php print htmlentities($domainid); ?>">
<input type="submit" name="set" value="Properties" title="properties">
</form>
</td>
<td class="right">[ <a href="addhost.php?domain=<?php print htmlentities($domainid); ?>">Add host</a> ]</td>
</tr>
</table>
</div>
<table class="display compact" id="domain-records">
<thead>
<tr class="header">
<td>Record name</td>
<td>Type</td>
<td>Content</td>
<td>TTL</td>
<td>Priority</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<?php
while ($row = $dbreturn->fetchRow(DB_FETCHMODE_OBJECT)) {
if (DB::isError($row)) {
header('Location: error.php?error=dberror');
}
#if (($adminlist == 1) || (isowner($row->id))) { # only if we own the domain or are admin
?>
<tr class="<?php print $row_classes[$count++ % 2]; ?>">
<td><a href="editrecord.php?type=0&id=<?php print $row->id; ?>"><?php print htmlentities($row->name); ?></a></td>
<td><?php print $row->type; ?></td>
<td><?php print $row->content; ?></td>
<td><?php print $row->ttl; ?></td>
<td><?php print $row->prio; ?></td>
<td>[<a href="record-delete.php?type=0&id=<?php print $row->id; ?>" onClick="return confirmAction('Delete this record?')">Delete</a>]</td>
</tr>
<?php
}
?>
</tbody>
</table>
<script>
$(document).ready(function() {
$('#domain-records').DataTable({
"order": [[ 1, 'asc' ], [ 0, 'asc' ]],
"columns": [
{
"orderable": true,
"searchable": true
},
{
"orderable": true,
"searchable": true,
"render": function ( data, type, row, meta ) {
//Do not alter printing etc
if (type !== 'sort') {
return data;
}
//Else sorting initiated
switch(data) {
case "SOA":
return 0;
case "NS":
return 1;
case "MX":
return 2;
default:
return 3;
}
}
},
{
"orderable": false,
"searchable": false
},
{
"orderable": false,
"searchable": false
},
{
"orderable": false,
"searchable": false
},
{
"orderable": false,
"searchable": false
}
]
});
});
</script>
</div>
<?php
}
}
?>