コード例 #1
0
 public function prepare()
 {
     if (!isset($_GET['id']) || empty($_GET['id']) || !ENABLE_DNSSEC) {
         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);
     }
     $sql = "SELECT * FROM dns_soa WHERE id = ?";
     $res = DNS::getDB()->query($sql, array($_GET['id']));
     $soa = DNS::getDB()->fetch_array($res);
     $records = array();
     $ds = array();
     $sql = "SELECT * FROM dns_sec WHERE zone = ?";
     $res = DNS::getDB()->query($sql, array($_GET['id']));
     while ($row = DNS::getDB()->fetch_array($res)) {
         if ($row['type'] == 'KSK') {
             preg_match("/" . $soa['origin'] . " IN DNSKEY 257 3 ([0-9]+) ([\\s\\S]+)/i", $row['public'], $match);
             preg_match("/; This is a key-signing key, keyid ([0-9]+), for " . $soa['origin'] . "/i", $row['public'], $match2);
             if (!empty($match) && !empty($match2)) {
                 if ($match[1] == $row['algo']) {
                     $ds = DNSSECUtil::calculateDS($soa['origin'], $match[1], $match[2]);
                     $ds['algo'] = $match[1];
                     $ds['keyid'] = $match2[1];
                 }
             }
         }
         $records[] = $row;
     }
     DNS::getTPL()->assign(array("records" => $records, "soa" => $soa, 'ds' => $ds));
 }
コード例 #2
0
 /**
  * init RequestHandler
  */
 public function __construct($module = '')
 {
     $this->pattern = '~/?(?:(?P<controller>[A-Za-z0-9\\-]+)(?:/(?P<id>\\d+)(?:-(?P<title>[^/]+))?)?)?~x';
     $controllers = ControllerCacheBuilder::getInstance()->getData(array('module' => $module));
     if (DNS::getSession()->username !== null) {
         DNS::getTPL()->assign(array("username" => DNS::getSession()->username));
     } else {
         DNS::getTPL()->assign(array("username" => ''));
     }
     $className = "";
     if (!empty($_SERVER['QUERY_STRING'])) {
         $this->matches($_SERVER['QUERY_STRING']);
         $this->registerRouteData();
     } else {
         $className = '\\dns' . (empty($module) ? '' : '\\' . $module) . '\\page\\IndexPage';
     }
     if (isset($this->routeData['controller']) && !empty($this->routeData['controller'])) {
         $controller = strtolower($this->routeData['controller']);
         if (isset($controllers[$controller]) && !empty($controllers[$controller])) {
             $className = $controllers[$controller];
         } else {
             @header('HTTP/1.0 404 Not Found');
             DNS::getTPL()->assign(array("activeMenuItem" => '', "error" => 'The link you are trying to reach is no longer available or invalid.'));
             DNS::getTPL()->display('error.tpl');
             exit;
         }
     }
     if (!User::isLoggedIn() && $className != '\\dns\\page\\LoginPage' && $className != '\\dns\\page\\ApiPage') {
         DNS::getTPL()->display('login.tpl');
         exit;
     }
     // handle offline mode
     if (defined('OFFLINE') && OFFLINE) {
         $admin = User::isAdmin();
         $available = false;
         if (defined($className . '::AVAILABLE_DURING_OFFLINE_MODE') && constant($className . '::AVAILABLE_DURING_OFFLINE_MODE')) {
             $available = true;
         }
         if (!$admin && !$available) {
             @header('HTTP/1.1 503 Service Unavailable');
             DNS::getTPL()->display('offline.tpl');
             exit;
         }
     }
     try {
         new $className();
     } catch (\Exception $e) {
         if ($e->getCode() == 404) {
             @header('HTTP/1.0 404 Not Found');
         } else {
             if ($e->getCode() == 403) {
                 @header('HTTP/1.0 403 Forbidden');
             }
         }
         /* show error page */
         DNS::getTPL()->assign(array("activeMenuItem" => '', "error" => $e->getMessage()));
         DNS::getTPL()->display('error.tpl');
         exit;
     }
 }
コード例 #3
0
 public function prepare()
 {
     $sql = "SELECT * FROM dns_api WHERE userID = ?";
     $res = DNS::getDB()->query($sql, array(DNS::getSession()->userID));
     $row = DNS::getDB()->fetch_array($res);
     $apiKey = "";
     if (isset($row['apiKey'])) {
         $apiKey = $row['apiKey'];
     }
     DNS::getTPL()->assign(array("userID" => DNS::getSession()->userID, "apiKey" => $apiKey));
 }
コード例 #4
0
 public function prepare()
 {
     if (User::isReseller() === false) {
         throw new \Exeption('Forbidden', 403);
     }
     if (isset($_POST['origin']) && isset($_POST['submit'])) {
         if (!empty($_POST['origin'])) {
             $idna = new idna_convert();
             $origin = $_POST['origin'];
             if (substr($origin, -1) != ".") {
                 $origin = $origin . ".";
             }
             $origin = $idna->encode($origin);
             $serial = date("Ymd") . "01";
             $sql = "SELECT * FROM dns_soa WHERE origin = ?";
             $res = DNS::getDB()->query($sql, array($origin));
             $soa = DNS::getDB()->fetch_array($res);
             if (empty($soa)) {
                 $soaData = array($origin, DNS_SOA_NS, DNS_SOA_MBOX, $serial, DNS_SOA_REFRESH, DNS_SOA_RETRY, DNS_SOA_EXPIRE, DNS_SOA_MINIMUM_TTL, DNS_SOA_TTL, 1);
                 $sql = "INSERT INTO dns_soa (id, origin, ns, mbox, serial, refresh, retry, expire, minimum, ttl, active) VALUES (null, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
                 DNS::getDB()->query($sql, $soaData);
                 $soaID = DNS::getDB()->last_id();
                 $sql = "INSERT INTO dns_soa_to_user (id, userID, soaID) VALUES (null, ?, ?)";
                 DNS::getDB()->query($sql, array(DNS::getSession()->userID, $soaID));
                 $sql = "SELECT * FROM dns_template WHERE userID = ?";
                 $res = DNS::getDB()->query($sql, array(DNS::getSession()->userID));
                 $tpl = DNS::getDB()->fetch_array($res);
                 $records = array();
                 if (!empty($tpl) && !empty($tpl['template'])) {
                     $records = explode("\n", $tpl['template']);
                 } else {
                     $records = explode("\n", DNS_DEFAULT_RECORDS);
                 }
                 if (!empty($records)) {
                     foreach ($records as $record) {
                         $record = str_replace("{domain}", $origin, $record);
                         $record = explode(":", $record, 3);
                         $rrData = array($soaID, $record[0], $record[1], $record[2], $record[1] == "MX" ? 10 : 0, DNS_SOA_MINIMUM_TTL);
                         $sql = 'INSERT INTO dns_rr (id, zone, name, type, data, aux, ttl) VALUES (NULL, ?, ?, ?, ?, ?, ?)';
                         DNS::getDB()->query($sql, $rrData);
                     }
                 }
                 DNS::getTPL()->assign(array("error" => '', 'success' => true));
             } else {
                 DNS::getTPL()->assign(array("error" => 'origin', 'origin' => $_POST['origin']));
             }
         } else {
             DNS::getTPL()->assign(array("error" => 'origin'));
         }
     } else {
         DNS::getTPL()->assign(array("error" => ''));
     }
 }
コード例 #5
0
 public final function show()
 {
     if (empty($this->template) || $this->template == "") {
         $classParts = explode('\\', get_class($this));
         $className = str_replace('Page', '', array_pop($classParts));
         $this->template = lcfirst($className) . ".tpl";
     } else {
         if (substr($this->template, -4) != ".tpl") {
             $this->template = $this->template . ".tpl";
         }
     }
     DNS::getTPL()->assign(array("activeMenuItem" => $this->activeMenuItem));
     DNS::getTPL()->display($this->template);
 }
コード例 #6
0
 public function prepare()
 {
     if (!isset($_GET['id']) || empty($_GET['id']) || !ENABLE_DNSSEC) {
         throw new \Exception('The link you are trying to reach is no longer available or invalid.', 404);
     }
     print_r($_REQUEST);
     $soaIDs = User::getAccessibleDomains();
     if (!in_array($_GET['id'], $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($_GET['id']));
     $soa = DNS::getDB()->fetch_array($res);
     DNS::getTPL()->assign(array("soa" => $soa));
 }
コード例 #7
0
 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));
 }
コード例 #8
0
 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));
 }