From 6706658bb3ad7caac1139eaedd40c55be6234051 Mon Sep 17 00:00:00 2001 From: Stricted Date: Wed, 6 May 2015 02:27:21 +0200 Subject: [PATCH] fix line endings --- .travis.yml | 28 +- lib/page/IndexPage.class.php | 150 +++++------ lib/page/RecordAddPage.class.php | 316 +++++++++++----------- lib/page/RecordEditPage.class.php | 432 +++++++++++++++--------------- lib/util/DNSSECUtil.class.php | 324 +++++++++++----------- 5 files changed, 625 insertions(+), 625 deletions(-) diff --git a/.travis.yml b/.travis.yml index 17b26cb..fc4768d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,14 @@ -language: php -php: - - 5.3 - - 5.4 - - 5.5 - - 5.6 -before_install: - - pear install pear/PHP_CodeSniffer - - phpenv rehash -before_script: - - git clone --branch=master --depth=1 --quiet git://github.com/WoltLab/WCF.git WCF -script: - - find . -type f -name '*.php' |xargs -I file php -l file > /dev/null - - phpcs -p --extensions=php --standard="`pwd`/WCF/CodeSniff/WCF" --ignore="lib/api/" . \ No newline at end of file +language: php +php: + - 5.3 + - 5.4 + - 5.5 + - 5.6 +before_install: + - pear install pear/PHP_CodeSniffer + - phpenv rehash +before_script: + - git clone --branch=master --depth=1 --quiet git://github.com/WoltLab/WCF.git WCF +script: + - find . -type f -name '*.php' |xargs -I file php -l file > /dev/null + - phpcs -p --extensions=php --standard="`pwd`/WCF/CodeSniff/WCF" --ignore="lib/api/" --ignore="WCF/" . \ No newline at end of file diff --git a/lib/page/IndexPage.class.php b/lib/page/IndexPage.class.php index 5621a94..6a79914 100644 --- a/lib/page/IndexPage.class.php +++ b/lib/page/IndexPage.class.php @@ -1,75 +1,75 @@ - - * @copyright 2014-2015 Jan Altensen (Stricted) - */ -class IndexPage extends AbstractPage { - public $activeMenuItem = 'index'; - - public function prepare() { - $domains = array(); - $soaIDs = User::getAccessibleDomains(); - $idna = new idna_convert(); - - $sortField = "id"; - $sortOrder = "ASC"; - $sqlOrderBy = ""; - $validSortFields = array('id', 'origin', 'serial'); - - if (isset($_GET['sortField'])) { - if (in_array($_GET['sortField'], $validSortFields)) { - $sortField = $_GET['sortField']; - } - } - - if (isset($_GET['sortOrder'])) { - if ($_GET['sortOrder'] == "ASC" || $_GET['sortOrder'] == "DESC") { - $sortOrder = $_GET['sortOrder']; - } - } - - if (!empty($sortField) && !empty($sortField)) { - $sqlOrderBy = $sortField." ".$sortOrder; - } - - $pageNo = 1; - if (isset($_GET['pageNo']) && !empty($_GET['pageNo'])) { - $pageNo = intval($_GET['pageNo']); - } - - $itemsPerPage = 20; - $pages = 0; - - $sqlLimit = $itemsPerPage; - $sqlOffset = ($pageNo - 1) * $itemsPerPage; - $pages = intval(ceil(count($soaIDs) / $itemsPerPage)); - - if (count($soaIDs) > 0) { - $sql = "SELECT * FROM dns_soa WHERE id IN (".str_repeat('?, ', count($soaIDs) - 1). "?)".(!empty($sqlOrderBy) ? " ORDER BY ".$sqlOrderBy : '')." LIMIT " . $sqlLimit . " OFFSET " . $sqlOffset; - $res = DNS::getDB()->query($sql, $soaIDs); - while ($row = DNS::getDB()->fetch_array($res)) { - $sql2 = "SELECT count(*) as count FROM dns_rr WHERE zone = ?"; - $res2 = DNS::getDB()->query($sql2, array($row['id'])); - $row2 = DNS::getDB()->fetch_array($res2); - $row['origin'] = $idna->decode($row['origin']); - $row['rrc'] = $row2['count']; - $domains[] = $row; - } - } - - DNS::getTPL()->assign(array( - 'domains' => $domains, - 'pageNo' => $pageNo, - 'pages' => $pages, - 'count' => count($soaIDs), - 'sortField' => $sortField, - 'sortOrder' => $sortOrder - )); - } -} + + * @copyright 2014-2015 Jan Altensen (Stricted) + */ +class IndexPage extends AbstractPage { + public $activeMenuItem = 'index'; + + public function prepare() { + $domains = array(); + $soaIDs = User::getAccessibleDomains(); + $idna = new idna_convert(); + + $sortField = "id"; + $sortOrder = "ASC"; + $sqlOrderBy = ""; + $validSortFields = array('id', 'origin', 'serial'); + + if (isset($_GET['sortField'])) { + if (in_array($_GET['sortField'], $validSortFields)) { + $sortField = $_GET['sortField']; + } + } + + if (isset($_GET['sortOrder'])) { + if ($_GET['sortOrder'] == "ASC" || $_GET['sortOrder'] == "DESC") { + $sortOrder = $_GET['sortOrder']; + } + } + + if (!empty($sortField) && !empty($sortField)) { + $sqlOrderBy = $sortField." ".$sortOrder; + } + + $pageNo = 1; + if (isset($_GET['pageNo']) && !empty($_GET['pageNo'])) { + $pageNo = intval($_GET['pageNo']); + } + + $itemsPerPage = 20; + $pages = 0; + + $sqlLimit = $itemsPerPage; + $sqlOffset = ($pageNo - 1) * $itemsPerPage; + $pages = intval(ceil(count($soaIDs) / $itemsPerPage)); + + if (count($soaIDs) > 0) { + $sql = "SELECT * FROM dns_soa WHERE id IN (".str_repeat('?, ', count($soaIDs) - 1). "?)".(!empty($sqlOrderBy) ? " ORDER BY ".$sqlOrderBy : '')." LIMIT " . $sqlLimit . " OFFSET " . $sqlOffset; + $res = DNS::getDB()->query($sql, $soaIDs); + while ($row = DNS::getDB()->fetch_array($res)) { + $sql2 = "SELECT count(*) as count FROM dns_rr WHERE zone = ?"; + $res2 = DNS::getDB()->query($sql2, array($row['id'])); + $row2 = DNS::getDB()->fetch_array($res2); + $row['origin'] = $idna->decode($row['origin']); + $row['rrc'] = $row2['count']; + $domains[] = $row; + } + } + + DNS::getTPL()->assign(array( + 'domains' => $domains, + 'pageNo' => $pageNo, + 'pages' => $pages, + 'count' => count($soaIDs), + 'sortField' => $sortField, + 'sortOrder' => $sortOrder + )); + } +} diff --git a/lib/page/RecordAddPage.class.php b/lib/page/RecordAddPage.class.php index 06e1a4f..6c31ea6 100644 --- a/lib/page/RecordAddPage.class.php +++ b/lib/page/RecordAddPage.class.php @@ -1,158 +1,158 @@ - - * @copyright 2014-2015 Jan Altensen (Stricted) - */ -class RecordAddPage extends AbstractPage { - public $activeMenuItem = 'index'; - - public function prepare() { - if (!isset($_GET['id']) || empty($_GET['id'])) { - throw new \Exception('The link you are trying to reach is no longer available or invalid.', 404); - } - - $soaIDs = User::getAccessibleDomains(); - if (!in_array($_GET['id'], $soaIDs)) { - throw new \Exception('Access denied. You’re not authorized to view this page.', 403); - } - $idna = new idna_convert(); - - $sql = "SELECT * FROM dns_soa WHERE id = ?"; - $res = DNS::getDB()->query($sql, array($_GET['id'])); - $soa = DNS::getDB()->fetch_array($res); - - $soa['origin'] = $idna->decode($soa['origin']); - - DNS::getTPL()->assign(array("soa" => $soa)); - - $types = array('A', 'AAAA', 'CNAME', 'MX', 'PTR', 'SRV', 'TXT', 'TLSA', 'NS', 'DS'); - $error = array(); - if (isset($_POST['submit']) && !empty($_POST['submit'])) { - if (isset($_POST['name']) && isset($_POST['ttl']) && !empty($_POST['ttl']) && isset($_POST['type']) && !empty($_POST['type']) && isset($_POST['data']) && !empty($_POST['data'])) { - $type = trim($_POST['type']); - - if (!empty($_POST['name'])) { - $name = $idna->encode(trim($_POST['name'])); - } - else { - $name = $idna->encode(trim($soa['origin'])); - } - - if (in_array($type, $types)) { - $aux = 0; - if (($type == "MX" || $type == "TLSA" || $type == "SRV" || $type == "DS") && isset($_POST['aux']) && !empty($_POST['aux'])) { - $aux = trim($_POST['aux']); - } - - $data = trim($_POST['data']); - if ($type == "SRV" || $type == "DS") { - if (isset($_POST['weight']) && !empty($_POST['weight']) && isset($_POST['port']) && !empty($_POST['port'])) { - if ($type == "SRV") { - $data = $idna->encode($data); - } - $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; - } - else { - $error = array_merge($error, array('weight', 'port', 'data')); - } - } - - $ttl = $_POST['ttl']; - if ($ttl < DNS_SOA_MINIMUM_TTL) { - $ttl = DNS_SOA_MINIMUM_TTL; - } - - if ($type == "TLSA") { - if ($aux != 3) { - // fallback - $aux = 3; - } - - if (isset($_POST['weight']) && isset($_POST['port'])) { - if (!is_numeric($_POST['weight'])) { - $error = array_merge($error, array('weight')); - } - else if (!is_numeric($_POST['port'])) { - $error = array_merge($error, array('weight')); - } - else if (strlen($_POST['data']) != 64) { - $error = array_merge($error, array('data')); - } - else { - $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; - } - } - else { - $error = array_merge($error, array('weight', 'port', 'data')); - } - } - - if ($type == "A") { - if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { - $error = array_merge($error, array('data')); - } - } - else if ($type == "AAAA") { - if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { - $error = array_merge($error, array('data')); - } - } - } - else { - $error = array_merge($error, array('type')); - } - } - else { - $error = array_merge($error, array('name', 'ttl', 'data')); - } - - $sql = 'SELECT * FROM dns_rr WHERE zone = ? AND name = ? AND type = ? AND data = ?'; - $res = DNS::getDB()->query($sql, array($_GET['id'], $name, $type, $data)); - $rr = DNS::getDB()->fetch_array($res); - if (!empty($rr)) { - $error = array_merge($error, array('type', 'data')); - } - - if (empty($error)) { - $sql = 'INSERT INTO dns_rr (id, zone, name, type, data, aux, ttl) VALUES (NULL, ?, ?, ?, ?, ?, ?)'; - if ($type == "SRV" || $type == "DS" || $type == "TLSA") { - DNS::getDB()->query($sql, array($_GET['id'], $name, $type, $data, $aux, $ttl)); - } - else { - DNS::getDB()->query($sql, array($_GET['id'], $name, $type, $idna->encode($data), $aux, $ttl)); - } - - $sql = "UPDATE dns_soa SET serial = ? WHERE id = ?"; - DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soa['id'])); - DNS::getTPL()->assign(array('success' => true)); - } - else { - if ($type == "SRV" || $type == "DS" || $type == "TLSA") { - DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'weight' => $_POST['weight'], 'port' => $_POST['port'], 'data' => $_POST['data'], 'aux' => $aux, 'ttl' => $ttl)); - } - else { - DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl)); - } - } - } - - DNS::getTPL()->assign(array("error" => $error)); - } - - public function fixSerial ($old) { - if (substr($old, 0, -2) == date("Ymd")) { - $new = $old + 1; - } - else { - $new = date("Ymd")."01"; - } - - return $new; - } -} + + * @copyright 2014-2015 Jan Altensen (Stricted) + */ +class RecordAddPage extends AbstractPage { + public $activeMenuItem = 'index'; + + public function prepare() { + if (!isset($_GET['id']) || empty($_GET['id'])) { + throw new \Exception('The link you are trying to reach is no longer available or invalid.', 404); + } + + $soaIDs = User::getAccessibleDomains(); + if (!in_array($_GET['id'], $soaIDs)) { + throw new \Exception('Access denied. You’re not authorized to view this page.', 403); + } + $idna = new idna_convert(); + + $sql = "SELECT * FROM dns_soa WHERE id = ?"; + $res = DNS::getDB()->query($sql, array($_GET['id'])); + $soa = DNS::getDB()->fetch_array($res); + + $soa['origin'] = $idna->decode($soa['origin']); + + DNS::getTPL()->assign(array("soa" => $soa)); + + $types = array('A', 'AAAA', 'CNAME', 'MX', 'PTR', 'SRV', 'TXT', 'TLSA', 'NS', 'DS'); + $error = array(); + if (isset($_POST['submit']) && !empty($_POST['submit'])) { + if (isset($_POST['name']) && isset($_POST['ttl']) && !empty($_POST['ttl']) && isset($_POST['type']) && !empty($_POST['type']) && isset($_POST['data']) && !empty($_POST['data'])) { + $type = trim($_POST['type']); + + if (!empty($_POST['name'])) { + $name = $idna->encode(trim($_POST['name'])); + } + else { + $name = $idna->encode(trim($soa['origin'])); + } + + if (in_array($type, $types)) { + $aux = 0; + if (($type == "MX" || $type == "TLSA" || $type == "SRV" || $type == "DS") && isset($_POST['aux']) && !empty($_POST['aux'])) { + $aux = trim($_POST['aux']); + } + + $data = trim($_POST['data']); + if ($type == "SRV" || $type == "DS") { + if (isset($_POST['weight']) && !empty($_POST['weight']) && isset($_POST['port']) && !empty($_POST['port'])) { + if ($type == "SRV") { + $data = $idna->encode($data); + } + $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; + } + else { + $error = array_merge($error, array('weight', 'port', 'data')); + } + } + + $ttl = $_POST['ttl']; + if ($ttl < DNS_SOA_MINIMUM_TTL) { + $ttl = DNS_SOA_MINIMUM_TTL; + } + + if ($type == "TLSA") { + if ($aux != 3) { + // fallback + $aux = 3; + } + + if (isset($_POST['weight']) && isset($_POST['port'])) { + if (!is_numeric($_POST['weight'])) { + $error = array_merge($error, array('weight')); + } + else if (!is_numeric($_POST['port'])) { + $error = array_merge($error, array('weight')); + } + else if (strlen($_POST['data']) != 64) { + $error = array_merge($error, array('data')); + } + else { + $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; + } + } + else { + $error = array_merge($error, array('weight', 'port', 'data')); + } + } + + if ($type == "A") { + if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { + $error = array_merge($error, array('data')); + } + } + else if ($type == "AAAA") { + if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { + $error = array_merge($error, array('data')); + } + } + } + else { + $error = array_merge($error, array('type')); + } + } + else { + $error = array_merge($error, array('name', 'ttl', 'data')); + } + + $sql = 'SELECT * FROM dns_rr WHERE zone = ? AND name = ? AND type = ? AND data = ?'; + $res = DNS::getDB()->query($sql, array($_GET['id'], $name, $type, $data)); + $rr = DNS::getDB()->fetch_array($res); + if (!empty($rr)) { + $error = array_merge($error, array('type', 'data')); + } + + if (empty($error)) { + $sql = 'INSERT INTO dns_rr (id, zone, name, type, data, aux, ttl) VALUES (NULL, ?, ?, ?, ?, ?, ?)'; + if ($type == "SRV" || $type == "DS" || $type == "TLSA") { + DNS::getDB()->query($sql, array($_GET['id'], $name, $type, $data, $aux, $ttl)); + } + else { + DNS::getDB()->query($sql, array($_GET['id'], $name, $type, $idna->encode($data), $aux, $ttl)); + } + + $sql = "UPDATE dns_soa SET serial = ? WHERE id = ?"; + DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soa['id'])); + DNS::getTPL()->assign(array('success' => true)); + } + else { + if ($type == "SRV" || $type == "DS" || $type == "TLSA") { + DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'weight' => $_POST['weight'], 'port' => $_POST['port'], 'data' => $_POST['data'], 'aux' => $aux, 'ttl' => $ttl)); + } + else { + DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl)); + } + } + } + + DNS::getTPL()->assign(array("error" => $error)); + } + + public function fixSerial ($old) { + if (substr($old, 0, -2) == date("Ymd")) { + $new = $old + 1; + } + else { + $new = date("Ymd")."01"; + } + + return $new; + } +} diff --git a/lib/page/RecordEditPage.class.php b/lib/page/RecordEditPage.class.php index 23d077f..2d62717 100644 --- a/lib/page/RecordEditPage.class.php +++ b/lib/page/RecordEditPage.class.php @@ -1,216 +1,216 @@ - - * @copyright 2014-2015 Jan Altensen (Stricted) - */ -class RecordEditPage extends AbstractPage { - public $activeMenuItem = 'index'; - - public function prepare() { - if (!isset($_GET['id']) || empty($_GET['id'])) { - throw new \Exception('The link you are trying to reach is no longer available or invalid.', 404); - } - $idna = new idna_convert(); - - $sql = "SELECT * FROM dns_rr WHERE id = ?"; - $res = DNS::getDB()->query($sql, array($_GET['id'])); - $rr = DNS::getDB()->fetch_array($res); - - $soaIDs = User::getAccessibleDomains(); - if (!in_array($rr['zone'], $soaIDs)) { - throw new \Exception('Access denied. You’re not authorized to view this page.', 403); - } - - $sql = "SELECT * FROM dns_soa WHERE id = ?"; - $res = DNS::getDB()->query($sql, array($rr['zone'])); - $soa = DNS::getDB()->fetch_array($res); - - $soa['origin'] = $idna->decode($soa['origin']); - - DNS::getTPL()->assign(array("soa" => $soa, "rr" => $rr)); - - $types = array('A', 'AAAA', 'CNAME', 'MX', 'PTR', 'SRV', 'TXT', 'TLSA', 'NS', 'DS'); - $error = array(); - if (isset($_POST['submit']) && !empty($_POST['submit'])) { - if (isset($_POST['name']) && isset($_POST['ttl']) && !empty($_POST['ttl']) && isset($_POST['type']) && !empty($_POST['type']) && isset($_POST['data']) && !empty($_POST['data'])) { - $type = trim($_POST['type']); - - if (!empty($_POST['name'])) { - $name = $idna->encode(trim($_POST['name'])); - } - else { - $name = $idna->encode(trim($soa['origin'])); - } - - if (in_array($type, $types)) { - $aux = 0; - if (($type == "MX" || $type == "TLSA" || $type == "SRV" || $type == "DS") && isset($_POST['aux']) && !empty($_POST['aux'])) { - $aux = trim($_POST['aux']); - } - - $data = trim($_POST['data']); - if ($type == "SRV" || $type == "DS") { - if (isset($_POST['weight']) && !empty($_POST['weight']) && isset($_POST['port']) && !empty($_POST['port'])) { - if ($type == "SRV") { - $data = $idna->encode($data); - } - $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; - } - else { - $error = array_merge($error, array('weight', 'port', 'data')); - } - } - - $ttl = $_POST['ttl']; - if ($ttl < DNS_SOA_MINIMUM_TTL) { - $ttl = DNS_SOA_MINIMUM_TTL; - } - - if ($type == "TLSA") { - if ($aux != 3) { - // fallback - $aux = 3; - } - - if (isset($_POST['weight']) && isset($_POST['port'])) { - if (!is_numeric($_POST['weight'])) { - $error = array_merge($error, array('weight')); - } - else if (!is_numeric($_POST['port'])) { - $error = array_merge($error, array('weight')); - } - else if (strlen($_POST['data']) != 64) { - $error = array_merge($error, array('data')); - } - else { - $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; - } - } - else { - $error = array_merge($error, array('weight', 'port', 'data')); - } - } - - if ($type == "A") { - if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { - $error = array_merge($error, array('data')); - } - } - else if ($type == "AAAA") { - if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { - $error = array_merge($error, array('data')); - } - } - } - else { - $error = array_merge($error, array('type')); - } - } - else { - $error = array_merge($error, array('name', 'ttl', 'data')); - } - - $sql = 'SELECT * FROM dns_rr WHERE zone = ? AND name = ? AND type = ? AND data = ? AND id != ?'; - $res = DNS::getDB()->query($sql, array($rr['zone'], $name, $type, $data, $_GET['id'])); - $rr = DNS::getDB()->fetch_array($res); - if (!empty($rr)) { - $error = array_merge($error, array('type', 'data')); - } - - if (empty($error)) { - - $sql = 'UPDATE dns_rr SET name = ?, type = ?, aux = ?, data = ?, ttl = ? WHERE id = ?'; - if ($type == "SRV" || $type == "DS" || $type == "TLSA") { - DNS::getDB()->query($sql, array($name, $type, $aux, $data, $ttl, $_GET['id'])); - } - else { - DNS::getDB()->query($sql, array($name, $type, $aux, $idna->encode($data), $ttl, $_GET['id'])); - } - - $sql = "UPDATE dns_soa SET serial = ? WHERE id = ?"; - DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soa['id'])); - - $sql = "SELECT * FROM dns_rr WHERE id = ?"; - $res = DNS::getDB()->query($sql, array($_GET['id'])); - $rr = DNS::getDB()->fetch_array($res); - - $weight = 0; - $port = 0; - $data = $rr['data']; - $type = $rr['type']; - $name = $idna->decode($rr['name']); - $aux = $rr['aux']; - $ttl = $rr['ttl']; - if ($type == "SRV" || $type == "DS" || $type == "TLSA") { - $datae = explode(" ", $data); - $weight = $datae[0]; - $port = $datae[1]; - if ($type == "SRV") { - $data = $idna->decode($datae[2]); - } - else { - $data = $datae[2]; - } - } - else { - $data = $idna->decode($data); - } - - DNS::getTPL()->assign(array('name' => $name, 'type' => $type, 'weight' => $weight, 'port' => $port, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl)); - DNS::getTPL()->assign(array('success' => true)); - } - else { - if ($type == "SRV" || $type == "DS" || $type == "TLSA") { - DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'weight' => $_POST['weight'], 'port' => $_POST['port'], 'data' => $_POST['data'], 'aux' => $aux, 'ttl' => $ttl)); - } - else { - DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'data' => $idna->decode($data), 'aux' => $aux, 'ttl' => $ttl)); - } - } - } - else { - $weight = 0; - $port = 0; - $data = $rr['data']; - $type = $rr['type']; - $name = $idna->decode($rr['name']); - $aux = $rr['aux']; - $ttl = $rr['ttl']; - if ($type == "SRV" || $type == "DS" || $type == "TLSA") { - $datae = explode(" ", $data); - $weight = $datae[0]; - $port = $datae[1]; - if ($type == "SRV") { - $data = $idna->decode($datae[2]); - } - else { - $data = $datae[2]; - } - } - else { - $data = $idna->decode($data); - } - - DNS::getTPL()->assign(array('name' => $name, 'type' => $type, 'weight' => $weight, 'port' => $port, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl)); - } - - DNS::getTPL()->assign(array("error" => $error)); - } - - public function fixSerial ($old) { - if (substr($old, 0, -2) == date("Ymd")) { - $new = $old + 1; - } - else { - $new = date("Ymd")."01"; - } - - return $new; - } -} + + * @copyright 2014-2015 Jan Altensen (Stricted) + */ +class RecordEditPage extends AbstractPage { + public $activeMenuItem = 'index'; + + public function prepare() { + if (!isset($_GET['id']) || empty($_GET['id'])) { + throw new \Exception('The link you are trying to reach is no longer available or invalid.', 404); + } + $idna = new idna_convert(); + + $sql = "SELECT * FROM dns_rr WHERE id = ?"; + $res = DNS::getDB()->query($sql, array($_GET['id'])); + $rr = DNS::getDB()->fetch_array($res); + + $soaIDs = User::getAccessibleDomains(); + if (!in_array($rr['zone'], $soaIDs)) { + throw new \Exception('Access denied. You’re not authorized to view this page.', 403); + } + + $sql = "SELECT * FROM dns_soa WHERE id = ?"; + $res = DNS::getDB()->query($sql, array($rr['zone'])); + $soa = DNS::getDB()->fetch_array($res); + + $soa['origin'] = $idna->decode($soa['origin']); + + DNS::getTPL()->assign(array("soa" => $soa, "rr" => $rr)); + + $types = array('A', 'AAAA', 'CNAME', 'MX', 'PTR', 'SRV', 'TXT', 'TLSA', 'NS', 'DS'); + $error = array(); + if (isset($_POST['submit']) && !empty($_POST['submit'])) { + if (isset($_POST['name']) && isset($_POST['ttl']) && !empty($_POST['ttl']) && isset($_POST['type']) && !empty($_POST['type']) && isset($_POST['data']) && !empty($_POST['data'])) { + $type = trim($_POST['type']); + + if (!empty($_POST['name'])) { + $name = $idna->encode(trim($_POST['name'])); + } + else { + $name = $idna->encode(trim($soa['origin'])); + } + + if (in_array($type, $types)) { + $aux = 0; + if (($type == "MX" || $type == "TLSA" || $type == "SRV" || $type == "DS") && isset($_POST['aux']) && !empty($_POST['aux'])) { + $aux = trim($_POST['aux']); + } + + $data = trim($_POST['data']); + if ($type == "SRV" || $type == "DS") { + if (isset($_POST['weight']) && !empty($_POST['weight']) && isset($_POST['port']) && !empty($_POST['port'])) { + if ($type == "SRV") { + $data = $idna->encode($data); + } + $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; + } + else { + $error = array_merge($error, array('weight', 'port', 'data')); + } + } + + $ttl = $_POST['ttl']; + if ($ttl < DNS_SOA_MINIMUM_TTL) { + $ttl = DNS_SOA_MINIMUM_TTL; + } + + if ($type == "TLSA") { + if ($aux != 3) { + // fallback + $aux = 3; + } + + if (isset($_POST['weight']) && isset($_POST['port'])) { + if (!is_numeric($_POST['weight'])) { + $error = array_merge($error, array('weight')); + } + else if (!is_numeric($_POST['port'])) { + $error = array_merge($error, array('weight')); + } + else if (strlen($_POST['data']) != 64) { + $error = array_merge($error, array('data')); + } + else { + $data = trim($_POST['weight']).' '.trim($_POST['port']).' '.$data; + } + } + else { + $error = array_merge($error, array('weight', 'port', 'data')); + } + } + + if ($type == "A") { + if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) === false) { + $error = array_merge($error, array('data')); + } + } + else if ($type == "AAAA") { + if (filter_var($data, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) { + $error = array_merge($error, array('data')); + } + } + } + else { + $error = array_merge($error, array('type')); + } + } + else { + $error = array_merge($error, array('name', 'ttl', 'data')); + } + + $sql = 'SELECT * FROM dns_rr WHERE zone = ? AND name = ? AND type = ? AND data = ? AND id != ?'; + $res = DNS::getDB()->query($sql, array($rr['zone'], $name, $type, $data, $_GET['id'])); + $rr = DNS::getDB()->fetch_array($res); + if (!empty($rr)) { + $error = array_merge($error, array('type', 'data')); + } + + if (empty($error)) { + + $sql = 'UPDATE dns_rr SET name = ?, type = ?, aux = ?, data = ?, ttl = ? WHERE id = ?'; + if ($type == "SRV" || $type == "DS" || $type == "TLSA") { + DNS::getDB()->query($sql, array($name, $type, $aux, $data, $ttl, $_GET['id'])); + } + else { + DNS::getDB()->query($sql, array($name, $type, $aux, $idna->encode($data), $ttl, $_GET['id'])); + } + + $sql = "UPDATE dns_soa SET serial = ? WHERE id = ?"; + DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soa['id'])); + + $sql = "SELECT * FROM dns_rr WHERE id = ?"; + $res = DNS::getDB()->query($sql, array($_GET['id'])); + $rr = DNS::getDB()->fetch_array($res); + + $weight = 0; + $port = 0; + $data = $rr['data']; + $type = $rr['type']; + $name = $idna->decode($rr['name']); + $aux = $rr['aux']; + $ttl = $rr['ttl']; + if ($type == "SRV" || $type == "DS" || $type == "TLSA") { + $datae = explode(" ", $data); + $weight = $datae[0]; + $port = $datae[1]; + if ($type == "SRV") { + $data = $idna->decode($datae[2]); + } + else { + $data = $datae[2]; + } + } + else { + $data = $idna->decode($data); + } + + DNS::getTPL()->assign(array('name' => $name, 'type' => $type, 'weight' => $weight, 'port' => $port, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl)); + DNS::getTPL()->assign(array('success' => true)); + } + else { + if ($type == "SRV" || $type == "DS" || $type == "TLSA") { + DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'weight' => $_POST['weight'], 'port' => $_POST['port'], 'data' => $_POST['data'], 'aux' => $aux, 'ttl' => $ttl)); + } + else { + DNS::getTPL()->assign(array('name' => $idna->decode($name), 'type' => $type, 'data' => $idna->decode($data), 'aux' => $aux, 'ttl' => $ttl)); + } + } + } + else { + $weight = 0; + $port = 0; + $data = $rr['data']; + $type = $rr['type']; + $name = $idna->decode($rr['name']); + $aux = $rr['aux']; + $ttl = $rr['ttl']; + if ($type == "SRV" || $type == "DS" || $type == "TLSA") { + $datae = explode(" ", $data); + $weight = $datae[0]; + $port = $datae[1]; + if ($type == "SRV") { + $data = $idna->decode($datae[2]); + } + else { + $data = $datae[2]; + } + } + else { + $data = $idna->decode($data); + } + + DNS::getTPL()->assign(array('name' => $name, 'type' => $type, 'weight' => $weight, 'port' => $port, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl)); + } + + DNS::getTPL()->assign(array("error" => $error)); + } + + public function fixSerial ($old) { + if (substr($old, 0, -2) == date("Ymd")) { + $new = $old + 1; + } + else { + $new = date("Ymd")."01"; + } + + return $new; + } +} diff --git a/lib/util/DNSSECUtil.class.php b/lib/util/DNSSECUtil.class.php index 50ac4fe..135ebfe 100644 --- a/lib/util/DNSSECUtil.class.php +++ b/lib/util/DNSSECUtil.class.php @@ -1,162 +1,162 @@ - - * @copyright 2015 Jan Altensen (Stricted) - */ -class DNSSECUtil { - // see: http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml - public static $availableAlgorithm = array(3, 5, 6, 7, 8, 10, 12, 13, 14); - - /** - * calculate the DS record for parent zone - * - * @param string $owner - * @param string $algorithm - * @param string $publicKey - * @return array - */ - public static function calculateDS ($owner, $algorithm, $publicKey) { - $owner = self::convertOwner($owner); - $flags = '0101'; - $protocol = '03'; - $algorithm = '0'.dechex($algorithm); - $publicKey = bin2hex(base64_decode($publicKey)); - - $string = hex2bin($owner.$flags.$protocol.$algorithm.$publicKey); - - $sha1 = strtoupper(sha1($string)); - $sha256 = strtoupper(hash('sha256', $string)); - - return array('sha1' => $sha1, 'sha256' => $sha256); - } - - /** - * convert the domain name to HEX - * - * @param string $owner - * @return string - */ - public static function convertOwner ($owner) { - if (substr($owner, -1) == '.') { - $owner = substr($owner, 0, -1); - } - - $return = ''; - - $parts = explode(".", $owner); - foreach ($parts as $part) { - $len = dechex(strlen($part)); - $return .= str_repeat('0', 2 - strlen($len)).$len; - $part = str_split($part); - $count = count($part); - for ($i = 0; $i < $count; $i++) { - $byte = strtoupper(dechex(ord($part[$i]))); - $byte = str_repeat('0', 2 - strlen($byte)).$byte; - $return .= $byte; - } - } - - $return .= '00'; - - return $return; - } - - /** - * validate DNSSEC public key - * - * @param string $content - * @return boolean - */ - public static function validatePublicKey ($content) { - // unify newlines - $content = preg_replace("/(\r\n)|(\r)/", "\n", $content); - - $pattern = "; This is a (key|zone)-signing key, keyid (?P[0-9]+), for (?P[\s\S]+)\.\n"; - $pattern .= "; Created: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; - $pattern .= "; Publish: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; - $pattern .= "; Activate: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; - $pattern .= "([\s\S]+). IN DNSKEY 25(6|7) 3 (?P[0-9]+) (?P[\s\S]+)(\n)?"; - preg_match('/'.$pattern.'/i', $content, $matches); - if (!empty($matches)) { - if (!in_array($matches['algorithm'], self::$availableAlgorithm)) { - return false; - } - - $data = explode(' ', $matches['key']); - foreach ($data as $d) { - if (base64_encode(base64_decode($d, true)) !== $d) { - return false; - } - } - } - else { - return false; - } - - return true; - } - - /** - * validate DNSSEC private key - * - * @param string $content - * @return boolean - */ - public static function validatePrivateKey ($content) { - // unify newlines - $content = preg_replace("/(\r\n)|(\r)/", "\n", $content); - - $pattern = "Private-key-format: v([0-9a-z.]+)\n"; - $pattern .= "Algorithm: (?P[0-9]+) \(([0-9a-z\-]+)\)\n"; - $pattern .= "Modulus: (?P[\s\S]+)\n"; - $pattern .= "PublicExponent: (?P[\s\S]+)\n"; - $pattern .= "PrivateExponent: (?P[\s\S]+)\n"; - $pattern .= "Prime1: (?P[\s\S]+)\n"; - $pattern .= "Prime2: (?P[\s\S]+)\n"; - $pattern .= "Exponent1: (?P[\s\S]+)\n"; - $pattern .= "Exponent2: (?P[\s\S]+)\n"; - $pattern .= "Coefficient: (?P[\s\S]+)\n"; - $pattern .= "Created: (?P[0-9]+)\n"; - $pattern .= "Publish: (?P[0-9]+)\n"; - $pattern .= "Activate: (?P[0-9]+)(\n)?"; - - preg_match('/'.$pattern.'/i', $content, $matches); - if (!empty($matches)) { - if (!in_array($matches['algorithm'], self::$availableAlgorithm)) { - return false; - } - else if (base64_encode(base64_decode($matches['modulus'], true)) !== $matches['modulus']) { - return false; - } - else if (base64_encode(base64_decode($matches['publicexponent'], true)) !== $matches['publicexponent']) { - return false; - } - else if (base64_encode(base64_decode($matches['privatexponent'], true)) !== $matches['privatexponent']) { - return false; - } - else if (base64_encode(base64_decode($matches['prime1'], true)) !== $matches['prime1']) { - return false; - } - else if (base64_encode(base64_decode($matches['prime2'], true)) !== $matches['prime2']) { - return false; - } - else if (base64_encode(base64_decode($matches['exponent1'], true)) !== $matches['exponent1']) { - return false; - } - else if (base64_encode(base64_decode($matches['exponent2'], true)) !== $matches['exponent2']) { - return false; - } - else if (base64_encode(base64_decode($matches['coefficient'], true)) !== $matches['coefficient']) { - return false; - } - } - else { - return false; - } - - return true; - } -} + + * @copyright 2015 Jan Altensen (Stricted) + */ +class DNSSECUtil { + // see: http://www.iana.org/assignments/dns-sec-alg-numbers/dns-sec-alg-numbers.xhtml + public static $availableAlgorithm = array(3, 5, 6, 7, 8, 10, 12, 13, 14); + + /** + * calculate the DS record for parent zone + * + * @param string $owner + * @param string $algorithm + * @param string $publicKey + * @return array + */ + public static function calculateDS ($owner, $algorithm, $publicKey) { + $owner = self::convertOwner($owner); + $flags = '0101'; + $protocol = '03'; + $algorithm = '0'.dechex($algorithm); + $publicKey = bin2hex(base64_decode($publicKey)); + + $string = hex2bin($owner.$flags.$protocol.$algorithm.$publicKey); + + $sha1 = strtoupper(sha1($string)); + $sha256 = strtoupper(hash('sha256', $string)); + + return array('sha1' => $sha1, 'sha256' => $sha256); + } + + /** + * convert the domain name to HEX + * + * @param string $owner + * @return string + */ + public static function convertOwner ($owner) { + if (substr($owner, -1) == '.') { + $owner = substr($owner, 0, -1); + } + + $return = ''; + + $parts = explode(".", $owner); + foreach ($parts as $part) { + $len = dechex(strlen($part)); + $return .= str_repeat('0', 2 - strlen($len)).$len; + $part = str_split($part); + $count = count($part); + for ($i = 0; $i < $count; $i++) { + $byte = strtoupper(dechex(ord($part[$i]))); + $byte = str_repeat('0', 2 - strlen($byte)).$byte; + $return .= $byte; + } + } + + $return .= '00'; + + return $return; + } + + /** + * validate DNSSEC public key + * + * @param string $content + * @return boolean + */ + public static function validatePublicKey ($content) { + // unify newlines + $content = preg_replace("/(\r\n)|(\r)/", "\n", $content); + + $pattern = "; This is a (key|zone)-signing key, keyid (?P[0-9]+), for (?P[\s\S]+)\.\n"; + $pattern .= "; Created: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; + $pattern .= "; Publish: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; + $pattern .= "; Activate: (?P[0-9]+) \(([a-z0-9: ]+)\)\n"; + $pattern .= "([\s\S]+). IN DNSKEY 25(6|7) 3 (?P[0-9]+) (?P[\s\S]+)(\n)?"; + preg_match('/'.$pattern.'/i', $content, $matches); + if (!empty($matches)) { + if (!in_array($matches['algorithm'], self::$availableAlgorithm)) { + return false; + } + + $data = explode(' ', $matches['key']); + foreach ($data as $d) { + if (base64_encode(base64_decode($d, true)) !== $d) { + return false; + } + } + } + else { + return false; + } + + return true; + } + + /** + * validate DNSSEC private key + * + * @param string $content + * @return boolean + */ + public static function validatePrivateKey ($content) { + // unify newlines + $content = preg_replace("/(\r\n)|(\r)/", "\n", $content); + + $pattern = "Private-key-format: v([0-9a-z.]+)\n"; + $pattern .= "Algorithm: (?P[0-9]+) \(([0-9a-z\-]+)\)\n"; + $pattern .= "Modulus: (?P[\s\S]+)\n"; + $pattern .= "PublicExponent: (?P[\s\S]+)\n"; + $pattern .= "PrivateExponent: (?P[\s\S]+)\n"; + $pattern .= "Prime1: (?P[\s\S]+)\n"; + $pattern .= "Prime2: (?P[\s\S]+)\n"; + $pattern .= "Exponent1: (?P[\s\S]+)\n"; + $pattern .= "Exponent2: (?P[\s\S]+)\n"; + $pattern .= "Coefficient: (?P[\s\S]+)\n"; + $pattern .= "Created: (?P[0-9]+)\n"; + $pattern .= "Publish: (?P[0-9]+)\n"; + $pattern .= "Activate: (?P[0-9]+)(\n)?"; + + preg_match('/'.$pattern.'/i', $content, $matches); + if (!empty($matches)) { + if (!in_array($matches['algorithm'], self::$availableAlgorithm)) { + return false; + } + else if (base64_encode(base64_decode($matches['modulus'], true)) !== $matches['modulus']) { + return false; + } + else if (base64_encode(base64_decode($matches['publicexponent'], true)) !== $matches['publicexponent']) { + return false; + } + else if (base64_encode(base64_decode($matches['privatexponent'], true)) !== $matches['privatexponent']) { + return false; + } + else if (base64_encode(base64_decode($matches['prime1'], true)) !== $matches['prime1']) { + return false; + } + else if (base64_encode(base64_decode($matches['prime2'], true)) !== $matches['prime2']) { + return false; + } + else if (base64_encode(base64_decode($matches['exponent1'], true)) !== $matches['exponent1']) { + return false; + } + else if (base64_encode(base64_decode($matches['exponent2'], true)) !== $matches['exponent2']) { + return false; + } + else if (base64_encode(base64_decode($matches['coefficient'], true)) !== $matches['coefficient']) { + return false; + } + } + else { + return false; + } + + return true; + } +} -- 2.20.1