import from private repository
[GitHub/Stricted/Domain-Control-Panel.git] / lib / page / RecordListPage.class.php
1 <?php
2 namespace dns\page;
3 use dns\system\DNS;
4 use dns\system\User;
5 use dns\api\idna\idna_convert;
6
7 /**
8 * @author Jan Altensen (Stricted)
9 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
10 * @copyright 2014-2015 Jan Altensen (Stricted)
11 */
12 class RecordListPage extends AbstractPage {
13 public $activeMenuItem = 'index';
14
15 public function prepare() {
16 if (!isset($_GET['id']) || empty($_GET['id'])) {
17 throw new \Exception('The link you are trying to reach is no longer available or invalid.', 404);
18 }
19
20 $soaIDs = User::getAccessibleDomains();
21 if (!in_array($_GET['id'], $soaIDs)) {
22 throw new \Exception('Access denied. You\92re not authorized to view this page.', 403);
23 }
24
25 $idna = new idna_convert();
26
27 $sql = "SELECT * FROM dns_soa WHERE id = ?";
28 $res = DNS::getDB()->query($sql, array($_GET['id']));
29 $soa = DNS::getDB()->fetch_array($res);
30
31 $soa['origin'] = $idna->decode($soa['origin']);
32
33 $records = array();
34
35 $sql = "SELECT * FROM dns_rr WHERE zone = ?";
36 $res = DNS::getDB()->query($sql, array($_GET['id']));
37 while ($row = DNS::getDB()->fetch_array($res)) {
38 $row['name'] = $idna->decode($row['name']);
39 if ($row['type'] == "SRV") {
40 $data = explode(" ", $row['data']);
41 $weight = $data[0];
42 $port = $data[1];
43 $data = $idna->encode($data[2]);
44
45 $data = $weight.' '.$port.' '.$data;
46
47 $row['data'] = $idna->decode($data);
48 }
49 else {
50 if ($row['type'] == "TLSA" || $row['type'] == "DS") {
51 $row['data'] = $$row['data'];
52 }
53 else {
54 $row['data'] = $idna->decode($row['data']);
55 }
56 }
57 $records[] = $row;
58 }
59
60 DNS::getTPL()->assign(array("records" => $records, "soa" => $soa));
61 }
62 }