<?php
namespace dns\page;
+use dns\system\helper\ITemplate;
+use dns\system\helper\TTemplate;
use dns\system\DNS;
/**
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-abstract class AbstractPage {
+abstract class AbstractPage implements ITemplate {
+ use TTemplate;
+
public $activeMenuItem = '';
public $template = "";
-
- public final function __construct() {
+
+ public function init() {
$this->prepare();
$this->show();
}
}
}
- DNS::getTPL()->assign(array("activeMenuItem" => $this->activeMenuItem));
- DNS::getTPL()->display($this->template);
+ $this->tpl->assign(array("activeMenuItem" => $this->activeMenuItem));
+ $this->tpl->display($this->template);
}
}
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
use dns\util\ParseZone;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class ActionPage extends AbstractPage {
+class ActionPage extends AbstractPage implements IDatabase {
+ use TDatabase;
+
public function prepare() {
if (!isset($_POST['action']) || empty($_POST['action']) || !isset($_POST['dataID'])) {
echo "failure";
}
$sql = "SELECT active, serial FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($dataID));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $soa = $this->db->fetch_array($res);
$active = ($soa['active'] ? 0 : 1);
$sql = "UPDATE dns_soa SET active = ?, serial = ? WHERE id = ?";
- DNS::getDB()->query($sql, array($active, $this->fixSerial($soa['serial']), $dataID));
+ $this->db->query($sql, array($active, $this->fixSerial($soa['serial']), $dataID));
echo "success";
exit;
}
$sql = "DELETE FROM dns_soa WHERE id = ?";
- DNS::getDB()->query($sql, array($dataID));
+ $this->db->query($sql, array($dataID));
echo "success";
exit;
}
else if ($action == "toggleRecord") {
$sql = "SELECT zone FROM dns_rr WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($dataID));
- $rr = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $rr = $this->db->fetch_array($res);
$soaID = $rr['zone'];
$soaIDs = User::getAccessibleDomains();
}
$sql = "SELECT active FROM dns_rr WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($dataID));
- $rr = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $rr = $this->db->fetch_array($res);
$active = ($rr['active'] ? 0 : 1);
$sql = "UPDATE dns_rr SET active = ? WHERE id = ?";
- DNS::getDB()->query($sql, array($active, $dataID));
+ $this->db->query($sql, array($active, $dataID));
$sql = "SELECT serial FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($soaID));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($soaID));
+ $soa = $this->db->fetch_array($res);
$sql = "UPDATE dns_soa SET serial = ? WHERE id = ?";
- DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soaID));
+ $this->db->query($sql, array($this->fixSerial($soa['serial']), $soaID));
echo "success";
exit;
}
else if ($action == "deleteRecord") {
$sql = "SELECT zone FROM dns_rr WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($dataID));
- $rr = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $rr = $this->db->fetch_array($res);
$soaID = $rr['zone'];
$soaIDs = User::getAccessibleDomains();
}
$sql = "DELETE FROM dns_rr WHERE id = ?";
- DNS::getDB()->query($sql, array($dataID));
+ $this->db->query($sql, array($dataID));
$sql = "SELECT serial FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($soaID));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($soaID));
+ $soa = $this->db->fetch_array($res);
$sql = "UPDATE dns_soa SET serial = ? WHERE id = ?";
- DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soaID));
+ $this->db->query($sql, array($this->fixSerial($soa['serial']), $soaID));
echo "success";
exit;
}
else if ($action == "toggleSec") {
$sql = "SELECT zone FROM dns_sec WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($dataID));
- $rr = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $rr = $this->db->fetch_array($res);
$soaID = $rr['zone'];
$soaIDs = User::getAccessibleDomains();
}
$sql = "SELECT active FROM dns_sec WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($dataID));
- $rr = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $rr = $this->db->fetch_array($res);
$active = ($rr['active'] ? 0 : 1);
$sql = "UPDATE dns_sec SET active = ? WHERE id = ?";
- DNS::getDB()->query($sql, array($active, $dataID));
+ $this->db->query($sql, array($active, $dataID));
$sql = "SELECT serial FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($soaID));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($soaID));
+ $soa = $this->db->fetch_array($res);
$sql = "UPDATE dns_soa SET serial = ? WHERE id = ?";
- DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soaID));
+ $this->db->query($sql, array($this->fixSerial($soa['serial']), $soaID));
echo "success";
exit;
}
else if ($action == "deleteSec") {
$sql = "SELECT zone FROM dns_sec WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($dataID));
- $rr = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $rr = $this->db->fetch_array($res);
$soaID = $rr['zone'];
$soaIDs = User::getAccessibleDomains();
}
$sql = "DELETE FROM dns_sec WHERE id = ?";
- DNS::getDB()->query($sql, array($dataID));
+ $this->db->query($sql, array($dataID));
$sql = "SELECT serial FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($soaID));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($soaID));
+ $soa = $this->db->fetch_array($res);
$sql = "UPDATE dns_soa SET serial = ? WHERE id = ?";
- DNS::getDB()->query($sql, array($this->fixSerial($soa['serial']), $soaID));
+ $this->db->query($sql, array($this->fixSerial($soa['serial']), $soaID));
echo "success";
exit;
else if ($action == "requestApiKey") {
if (User::isLoggedIn()) {
$sql = "SELECT * FROM dns_api WHERE userID = ?";
- $res = DNS::getDB()->query($sql, array(DNS::getSession()->userID));
- $row = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array(DNS::getSession()->userID));
+ $row = $this->db->fetch_array($res);
if (empty($row)) {
$apiKey = DNS::generateUUID();
$sql = "INSERT INTO dns_api (id, userID, apiKey) VALUES (NULL, ?, ?)";
- DNS::getDB()->query($sql, array(DNS::getSession()->userID, $apiKey));
+ $this->db->query($sql, array(DNS::getSession()->userID, $apiKey));
echo $apiKey;
exit;
}
$sql = 'SELECT * FROM dns_soa where id = ?';
- $res = DNS::getDB()->query($sql, array($dataID));
- $res = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $res = $this->db->fetch_array($res);
$soa = $res;
$parser = new ParseZone($_POST['zone'], $soa['origin']);
}
else if ($action == "export") {
$sql = 'SELECT * FROM dns_soa where id = ?';
- $res = DNS::getDB()->query($sql, array($dataID));
- $res = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($dataID));
+ $res = $this->db->fetch_array($res);
$soa = $res;
$soaIDs = User::getAccessibleDomains();
$out .= ";;\n";
$sql = 'SELECT * FROM dns_rr where zone = ?';
- $res = DNS::getDB()->query($sql, array($soa['id']));
- while ($record = DNS::getDB()->fetch_array($res)) {
+ $res = $this->db->query($sql, array($soa['id']));
+ while ($record = $this->db->fetch_array($res)) {
if (!$record['active']) {
$out .= ";; ";
}
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class ApiManagementPage extends AbstractPage {
+class ApiManagementPage extends AbstractPage implements IDatabase {
+ use TDatabase;
public $activeMenuItem = 'api';
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);
+ $res = $this->db->query($sql, array(DNS::getSession()->userID));
+ $row = $this->db->fetch_array($res);
$apiKey = "";
$apiKey = $row['apiKey'];
}
- DNS::getTPL()->assign(array("userID" => DNS::getSession()->userID,"apiKey" => $apiKey));
+ $this->tpl->assign(array("userID" => DNS::getSession()->userID,"apiKey" => $apiKey));
}
}
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
use Mso\IdnaConvert\IdnaConvert;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class DomainAddPage extends AbstractPage {
+class DomainAddPage extends AbstractPage implements IDatabase {
+ use TDatabase;
public $activeMenuItem = 'add';
public function prepare() {
$serial = date("Ymd")."01";
$sql = "SELECT * FROM dns_soa WHERE origin = ?";
- $res = DNS::getDB()->query($sql, array($origin));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($origin));
+ $soa = $this->db->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();
+ $this->db->query($sql, $soaData);
+ $soaID = $this->db->last_id();
$sql = "INSERT INTO dns_soa_to_user (id, userID, soaID) VALUES (null, ?, ?)";
- DNS::getDB()->query($sql, array(DNS::getSession()->userID, $soaID));
+ $this->db->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);
+ $res = $this->db->query($sql, array(DNS::getSession()->userID));
+ $tpl = $this->db->fetch_array($res);
$records = array();
if (!empty($tpl) && !empty($tpl['template'])) {
$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);
+ $this->db->query($sql, $rrData);
}
}
- DNS::getTPL()->assign(array("error" => '', 'success' => true));
+ $this->tpl->assign(array("error" => '', 'success' => true));
}
else {
- DNS::getTPL()->assign(array("error" => 'origin', 'origin' => $_POST['origin']));
+ $this->tpl->assign(array("error" => 'origin', 'origin' => $_POST['origin']));
}
}
else {
- DNS::getTPL()->assign(array("error" => 'origin'));
+ $this->tpl->assign(array("error" => 'origin'));
}
}
else {
- DNS::getTPL()->assign(array("error" => ''));
+ $this->tpl->assign(array("error" => ''));
}
}
}
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
use Mso\IdnaConvert\IdnaConvert;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class IndexPage extends AbstractPage {
+class IndexPage extends AbstractPage implements IDatabase {
+ use TDatabase;
+
public $activeMenuItem = 'index';
public function prepare() {
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)) {
+ $res = $this->db->query($sql, $soaIDs);
+ while ($row = $this->db->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);
+ $res2 = $this->db->query($sql2, array($row['id']));
+ $row2 = $this->db->fetch_array($res2);
$row['origin'] = $idna->decode($row['origin']);
$row['rrc'] = $row2['count'];
$domains[] = $row;
}
}
- DNS::getTPL()->assign(array(
+ $this->tpl->assign(array(
'domains' => $domains,
'pageNo' => $pageNo,
'pages' => $pages,
}
User::login(trim($_POST['username']), trim($_POST['password']), $remember);
- header("Location: index.php?index");
+ header("Location: index.php?index"); // TODO: use link builder
}
}
}
public function prepare() {
if (User::isLoggedIn()) {
User::logout();
- header("Location: ?page=index");
+ header("Location: ?page=index"); // TODO: use link builder
}
}
}
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
use Mso\IdnaConvert\IdnaConvert;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class RecordAddPage extends AbstractPage {
+class RecordAddPage extends AbstractPage implements IDatabase {
+ use TDatabase;
public $activeMenuItem = 'index';
public function prepare() {
$idna = new IdnaConvert();
$sql = "SELECT * FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($_GET['id']));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($_GET['id']));
+ $soa = $this->db->fetch_array($res);
$soa['origin'] = $idna->decode($soa['origin']);
- DNS::getTPL()->assign(array("soa" => $soa));
+ $this->tpl->assign(array("soa" => $soa));
$types = array('A', 'AAAA', 'CNAME', 'MX', 'PTR', 'SRV', 'TXT', 'TLSA', 'NS', 'DS');
$error = array();
}
$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);
+ $res = $this->db->query($sql, array($_GET['id'], $name, $type, $data));
+ $rr = $this->db->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));
+ $this->db->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));
+ $this->db->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));
+ $this->db->query($sql, array($this->fixSerial($soa['serial']), $soa['id']));
+ $this->tpl->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));
+ $this->tpl->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));
+ $this->tpl->assign(array('name' => $idna->decode($name), 'type' => $type, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl));
}
}
}
- DNS::getTPL()->assign(array("error" => $error));
+ $this->tpl->assign(array("error" => $error));
}
public function fixSerial ($old) {
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
use Mso\IdnaConvert\IdnaConvert;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class RecordEditPage extends AbstractPage {
+class RecordEditPage extends AbstractPage implements IDatabase {
+ use TDatabase;
public $activeMenuItem = 'index';
public function prepare() {
$idna = new IdnaConvert();
$sql = "SELECT * FROM dns_rr WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($_GET['id']));
- $rr = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($_GET['id']));
+ $rr = $this->db->fetch_array($res);
$soaIDs = User::getAccessibleDomains();
if (!in_array($rr['zone'], $soaIDs)) {
}
$sql = "SELECT * FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($rr['zone']));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($rr['zone']));
+ $soa = $this->db->fetch_array($res);
$soa['origin'] = $idna->decode($soa['origin']);
- DNS::getTPL()->assign(array("soa" => $soa, "rr" => $rr));
+ $this->tpl->assign(array("soa" => $soa, "rr" => $rr));
$types = array('A', 'AAAA', 'CNAME', 'MX', 'PTR', 'SRV', 'TXT', 'TLSA', 'NS', 'DS');
$error = array();
}
$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);
+ $res = $this->db->query($sql, array($rr['zone'], $name, $type, $data, $_GET['id']));
+ $rr = $this->db->fetch_array($res);
if (!empty($rr)) {
$error = array_merge($error, array('type', 'data'));
}
$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']));
+ $this->db->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']));
+ $this->db->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']));
+ $this->db->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);
+ $res = $this->db->query($sql, array($_GET['id']));
+ $rr = $this->db->fetch_array($res);
$weight = 0;
$port = 0;
$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));
+ $this->tpl->assign(array('name' => $name, 'type' => $type, 'weight' => $weight, 'port' => $port, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl));
+ $this->tpl->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));
+ $this->tpl->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));
+ $this->tpl->assign(array('name' => $idna->decode($name), 'type' => $type, 'data' => $idna->decode($data), 'aux' => $aux, 'ttl' => $ttl));
}
}
}
$data = $idna->decode($data);
}
- DNS::getTPL()->assign(array('name' => $name, 'type' => $type, 'weight' => $weight, 'port' => $port, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl));
+ $this->tpl->assign(array('name' => $name, 'type' => $type, 'weight' => $weight, 'port' => $port, 'data' => $data, 'aux' => $aux, 'ttl' => $ttl));
}
- DNS::getTPL()->assign(array("error" => $error));
+ $this->tpl->assign(array("error" => $error));
}
public function fixSerial ($old) {
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
use Mso\IdnaConvert\IdnaConvert;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class RecordListPage extends AbstractPage {
+class RecordListPage extends AbstractPage implements IDatabase {
+ use TDatabase;
public $activeMenuItem = 'index';
public function prepare() {
$idna = new IdnaConvert();
$sql = "SELECT count(*) as count FROM dns_rr WHERE zone = ?";
- $res = DNS::getDB()->query($sql, array($_GET['id']));
- $row = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($_GET['id']));
+ $row = $this->db->fetch_array($res);
$count = $row['count'];
$sortField = "type";
$pages = intval(ceil($count / $itemsPerPage));
$sql = "SELECT * FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($_GET['id']));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($_GET['id']));
+ $soa = $this->db->fetch_array($res);
$soa['origin'] = $idna->decode($soa['origin']);
$records = array();
$sql = "SELECT * FROM dns_rr WHERE zone = ?".(!empty($sqlOrderBy) ? " ORDER BY ".$sqlOrderBy : '')." LIMIT " . $sqlLimit . " OFFSET " . $sqlOffset;
- $res = DNS::getDB()->query($sql, array($_GET['id']));
- while ($row = DNS::getDB()->fetch_array($res)) {
+ $res = $this->db->query($sql, array($_GET['id']));
+ while ($row = $this->db->fetch_array($res)) {
$row['name'] = $idna->decode($row['name']);
if ($row['type'] == "SRV") {
$data = explode(" ", $row['data']);
$records[] = $row;
}
- DNS::getTPL()->assign(array(
+ $this->tpl->assign(array(
'records' => $records,
'soa' => $soa,
'pageNo' => $pageNo,
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class SecAddPage extends AbstractPage {
+class SecAddPage extends AbstractPage implements IDatabase {
+ use TDatabase;
public function prepare() {
if (!isset($_GET['id']) || empty($_GET['id']) || !ENABLE_DNSSEC) {
}
$sql = "SELECT * FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($_GET['id']));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($_GET['id']));
+ $soa = $this->db->fetch_array($res);
- DNS::getTPL()->assign(array("soa" => $soa));
+ $this->tpl->assign(array("soa" => $soa));
}
}
<?php
namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
use dns\system\DNS;
use dns\system\User;
use dns\util\DNSSECUtil;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2014-2016 Jan Altensen (Stricted)
*/
-class SecListPage extends AbstractPage {
+class SecListPage extends AbstractPage implements IDatabase {
+ use TDatabase;
public $activeMenuItem = 'index';
public function prepare() {
}
$sql = "SELECT * FROM dns_soa WHERE id = ?";
- $res = DNS::getDB()->query($sql, array($_GET['id']));
- $soa = DNS::getDB()->fetch_array($res);
+ $res = $this->db->query($sql, array($_GET['id']));
+ $soa = $this->db->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)) {
+ $res = $this->db->query($sql, array($_GET['id']));
+ while ($row = $this->db->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);
$records[] = $row;
}
- DNS::getTPL()->assign(array("records" => $records, "soa" => $soa, 'ds' => $ds));
+ $this->tpl->assign(array("records" => $records, "soa" => $soa, 'ds' => $ds));
}
}
$requestHandler = RequestHandler::getInstance();
$requestHandler->setDB(self::getDB());
+ $requestHandler->setTPL(self::getTPL());
$requestHandler->setRoutes($module);
$requestHandler->handle();
}
use dns\system\cache\builder\ControllerCacheBuilder;
use dns\system\helper\IDatabase;
use dns\system\helper\TDatabase;
+use dns\system\helper\ITemplate;
+use dns\system\helper\TTemplate;
use dns\system\route\Request;
use dns\system\route\Segment;
use Zend\Router\Http\RouteMatch;
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @copyright 2013-2016 Jan Altensen (Stricted)
*/
-class RequestHandler extends SingletonFactory implements IDatabase {
+class RequestHandler extends SingletonFactory implements IDatabase, ITemplate {
use TDatabase;
+ use TTemplate;
protected $router = null;
protected $apiModule = false;
try {
$page = new $className();
+
if ($page instanceof IDatabase) {
$page->setDB($this->db);
}
+
+ if ($page instanceof ITemplate) {
+ $page->setTPL($this->tpl);
+ }
+
+ $page->init();
}
catch (\Exception $e) {
if ($e->getCode() == 404) {
--- /dev/null
+<?php
+namespace dns\system\helper;
+
+interface ITemplate {
+ public function setTPL ($tpl);
+}
namespace dns\system\helper;
trait TDatabase {
- private $db = null;
+ protected $db = null;
public function setDB ($database) {
$this->db = $database;
--- /dev/null
+<?php
+namespace dns\system\helper;
+
+trait TTemplate {
+ protected $tpl = null;
+
+ public function setTPL ($tpl) {
+ $this->tpl = $tpl;
+ }
+}