update copyright year
[GitHub/Stricted/Domain-Control-Panel.git] / lib / page / SecListPage.class.php
1 <?php
2 namespace dns\page;
3 use dns\system\DNS;
4 use dns\system\User;
5 use dns\util\DNSSECUtil;
6
7 /**
8 * @author Jan Altensen (Stricted)
9 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
10 * @copyright 2014-2016 Jan Altensen (Stricted)
11 */
12 class SecListPage extends AbstractPage {
13 public $activeMenuItem = 'index';
14
15 public function prepare() {
16 if (!isset($_GET['id']) || empty($_GET['id']) || !ENABLE_DNSSEC) {
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\'re not authorized to view this page.', 403);
23 }
24
25 $sql = "SELECT * FROM dns_soa WHERE id = ?";
26 $res = DNS::getDB()->query($sql, array($_GET['id']));
27 $soa = DNS::getDB()->fetch_array($res);
28
29 $records = array();
30 $ds = array();
31
32 $sql = "SELECT * FROM dns_sec WHERE zone = ?";
33 $res = DNS::getDB()->query($sql, array($_GET['id']));
34 while ($row = DNS::getDB()->fetch_array($res)) {
35 if ($row['type'] == 'KSK') {
36 preg_match("/".$soa['origin']." IN DNSKEY 257 3 ([0-9]+) ([\s\S]+)/i", $row['public'], $match);
37 preg_match("/; This is a key-signing key, keyid ([0-9]+), for ".$soa['origin']."/i", $row['public'], $match2);
38 if (!empty($match) && !empty($match2)) {
39 if ($match[1] == $row['algo']) {
40 $ds = DNSSECUtil::calculateDS($soa['origin'], $match[1], $match[2]);
41 $ds['algo'] = $match[1];
42 $ds['keyid'] = $match2[1];
43 }
44 }
45 }
46 $records[] = $row;
47 }
48
49 DNS::getTPL()->assign(array("records" => $records, "soa" => $soa, 'ds' => $ds));
50 }
51 }