add more DI stuff
authorStricted <info@stricted.net>
Thu, 21 Jul 2016 08:22:19 +0000 (10:22 +0200)
committerStricted <info@stricted.net>
Thu, 21 Jul 2016 08:22:19 +0000 (10:22 +0200)
17 files changed:
lib/page/AbstractPage.class.php
lib/page/ActionPage.class.php
lib/page/ApiManagementPage.class.php
lib/page/DomainAddPage.class.php
lib/page/IndexPage.class.php
lib/page/LoginPage.class.php
lib/page/LogoutPage.class.php
lib/page/RecordAddPage.class.php
lib/page/RecordEditPage.class.php
lib/page/RecordListPage.class.php
lib/page/SecAddPage.class.php
lib/page/SecListPage.class.php
lib/system/DNS.class.php
lib/system/RequestHandler.class.php
lib/system/helper/ITemplate.class.php [new file with mode: 0644]
lib/system/helper/TDatabase.class.php
lib/system/helper/TTemplate.class.php [new file with mode: 0644]

index c79661b6b9dff1572a0fd1fc3a70aff25e371310..e58f0e595248865c485972223369045c984704e2 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace dns\page;
+use dns\system\helper\ITemplate;
+use dns\system\helper\TTemplate;
 use dns\system\DNS;
 
 /**
@@ -7,11 +9,13 @@ 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();
        }
@@ -30,7 +34,7 @@ abstract class AbstractPage {
                        }
                }
                
-               DNS::getTPL()->assign(array("activeMenuItem" => $this->activeMenuItem));
-               DNS::getTPL()->display($this->template);
+               $this->tpl->assign(array("activeMenuItem" => $this->activeMenuItem));
+               $this->tpl->display($this->template);
        }
 }
index e006ee9a7fc866ebb4b07e7fe675e6345dddd7c5..a6e4eefc2034f603b129963e46b44f6eea3d9547 100644 (file)
@@ -1,5 +1,7 @@
 <?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;
@@ -9,7 +11,9 @@ 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";
@@ -31,13 +35,13 @@ class ActionPage extends AbstractPage {
                        }
                        
                        $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;
@@ -55,15 +59,15 @@ class ActionPage extends AbstractPage {
                        }
                        
                        $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();
@@ -73,28 +77,28 @@ class ActionPage extends AbstractPage {
                        }
                        
                        $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();
@@ -104,22 +108,22 @@ class ActionPage extends AbstractPage {
                        }
                        
                        $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();
@@ -129,28 +133,28 @@ class ActionPage extends AbstractPage {
                        }
                        
                        $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();
@@ -160,14 +164,14 @@ class ActionPage extends AbstractPage {
                        }
                        
                        $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;
@@ -175,14 +179,14 @@ class ActionPage extends AbstractPage {
                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;
@@ -210,8 +214,8 @@ class ActionPage extends AbstractPage {
                                        }
                                        
                                        $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']);
@@ -243,8 +247,8 @@ class ActionPage extends AbstractPage {
                }
                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();
@@ -288,8 +292,8 @@ class ActionPage extends AbstractPage {
                        $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 .= ";; ";
                                }
index 325ca0a618800bca680a369b5a0b67621063d68b..5f3c8f773c8f26f7ca1f671cb0b7d2d20cd19d0c 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
 use dns\system\DNS;
 use dns\system\User;
 
@@ -8,13 +10,14 @@ 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 = "";
                
@@ -22,6 +25,6 @@ class ApiManagementPage extends AbstractPage {
                        $apiKey = $row['apiKey'];
                }
                
-               DNS::getTPL()->assign(array("userID" => DNS::getSession()->userID,"apiKey" => $apiKey));
+               $this->tpl->assign(array("userID" => DNS::getSession()->userID,"apiKey" => $apiKey));
        }
 }
index b3700f1f21eb17b1e5dc6adecdcdda9c106ff2d7..2feea017b2aacafeea496a901af7cf2a321700fa 100644 (file)
@@ -1,5 +1,7 @@
 <?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;
@@ -9,7 +11,8 @@ 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() {
@@ -29,22 +32,22 @@ class DomainAddPage extends AbstractPage {
                                $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'])) {
@@ -61,21 +64,21 @@ class DomainAddPage extends AbstractPage {
                                                        
                                                        $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" => ''));
                }
        }
 }
index 9021f5e03fb4cae7ad209016a4ee492dab5b2f19..277fb39f63b336009c6f58f47260c940e508e235 100644 (file)
@@ -1,5 +1,7 @@
 <?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;
@@ -9,7 +11,9 @@ 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() {
@@ -52,18 +56,18 @@ class IndexPage extends AbstractPage {
                
                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,
index 260a2f4ec0e4945e8e6ca1579a69ffa5e4f94955..cbdc8142104d58d9b9d40fefe1442bb6b01f7b2c 100644 (file)
@@ -20,7 +20,7 @@ class LoginPage extends AbstractPage {
                                }
                                
                                User::login(trim($_POST['username']), trim($_POST['password']), $remember);
-                               header("Location: index.php?index");
+                               header("Location: index.php?index"); // TODO: use link builder
                        }
                }
        }
index 366639537f864a2825273dc79e26fdf9002150dd..81d980098ed4ec2892e56e88f57d2359240a5a95 100644 (file)
@@ -12,7 +12,7 @@ class LogoutPage extends AbstractPage {
        public function prepare() {
                if (User::isLoggedIn()) {
                        User::logout();
-                       header("Location: ?page=index");
+                       header("Location: ?page=index"); // TODO: use link builder
                }
        }
 }
index e8c997c3eb901b0a70c5bdbdfc792437f95fcf33..4270ef1dfc7bdb6a2ff49d0b8f3ca86f1cdd37e8 100644 (file)
@@ -1,5 +1,7 @@
 <?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;
@@ -9,7 +11,8 @@ 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() {
@@ -24,12 +27,12 @@ class RecordAddPage extends AbstractPage {
                $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();
@@ -113,8 +116,8 @@ class RecordAddPage extends AbstractPage {
                        }
                        
                        $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'));
                        }
@@ -122,27 +125,27 @@ class RecordAddPage extends AbstractPage {
                        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) {
index c22bd4236a663161ad43055687a8b51c36533b80..a31e645ccca5832c955e7518796df8d6e6b03368 100644 (file)
@@ -1,5 +1,7 @@
 <?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;
@@ -9,7 +11,8 @@ 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() {
@@ -19,8 +22,8 @@ class RecordEditPage extends AbstractPage {
                $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)) {
@@ -28,12 +31,12 @@ class RecordEditPage extends AbstractPage {
                }
                                
                $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();
@@ -117,8 +120,8 @@ class RecordEditPage extends AbstractPage {
                        }
                        
                        $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'));
                        }
@@ -127,18 +130,18 @@ class RecordEditPage extends AbstractPage {
                                
                                $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;
@@ -162,15 +165,15 @@ class RecordEditPage extends AbstractPage {
                                        $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));
                                }
                        }
                }
@@ -197,10 +200,10 @@ class RecordEditPage extends AbstractPage {
                                $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) {
index 490c60ceab1d12ddce768af8224b83326907eece..e0da8e0c1c46cdd2b0c5886bfe193dae8043f388 100644 (file)
@@ -1,5 +1,7 @@
 <?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;
@@ -9,7 +11,8 @@ 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() {
@@ -25,8 +28,8 @@ class RecordListPage extends AbstractPage {
                $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";
@@ -63,16 +66,16 @@ class RecordListPage extends AbstractPage {
                $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']);
@@ -95,7 +98,7 @@ class RecordListPage extends AbstractPage {
                        $records[] = $row;
                }
                
-               DNS::getTPL()->assign(array(
+               $this->tpl->assign(array(
                        'records' => $records,
                        'soa' => $soa,
                        'pageNo' => $pageNo,
index b695a3c1a2a0a9527a80c379dfba86bfa8cbed1d..2928aea6a0b14810aa1e0c03b8850560650c1983 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 namespace dns\page;
+use dns\system\helper\IDatabase;
+use dns\system\helper\TDatabase;
 use dns\system\DNS;
 use dns\system\User;
 
@@ -8,7 +10,8 @@ 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) {
@@ -21,9 +24,9 @@ class SecAddPage extends AbstractPage {
                }
                
                $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));
        }
 }
index 8b716413eaed9f399ca95229664ce65f46b608c5..45c60530fccea2fa6d847283bfbe69b5135b3f21 100644 (file)
@@ -1,5 +1,7 @@
 <?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;
@@ -9,7 +11,8 @@ 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() {
@@ -23,15 +26,15 @@ class SecListPage extends AbstractPage {
                }
                
                $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);
@@ -46,6 +49,6 @@ class SecListPage extends AbstractPage {
                        $records[] = $row;
                }
                
-               DNS::getTPL()->assign(array("records" => $records, "soa" => $soa, 'ds' => $ds));
+               $this->tpl->assign(array("records" => $records, "soa" => $soa, 'ds' => $ds));
        }
 }
index 5b26c32dea52e446ade9ed5a818e9cc3c61402bf..a342d4f899ed06f4ae7e78ac2cffcf0bb8f1c0c6 100644 (file)
@@ -70,6 +70,7 @@ class DNS {
                
                $requestHandler = RequestHandler::getInstance();
                $requestHandler->setDB(self::getDB());
+               $requestHandler->setTPL(self::getTPL());
                $requestHandler->setRoutes($module);
                $requestHandler->handle();
        }
index 0e889e38cb1c686f6baf940fa01daab3e48e2fa4..a8f2f7f10bd229f8b56f9b0444d73aa863eafbf1 100644 (file)
@@ -3,6 +3,8 @@ namespace dns\system;
 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;
@@ -13,8 +15,9 @@ use Zend\Router\SimpleRouteStack;
  * @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;
@@ -114,9 +117,16 @@ class RequestHandler extends SingletonFactory implements IDatabase {
                        
                        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) {
diff --git a/lib/system/helper/ITemplate.class.php b/lib/system/helper/ITemplate.class.php
new file mode 100644 (file)
index 0000000..0197240
--- /dev/null
@@ -0,0 +1,6 @@
+<?php
+namespace dns\system\helper;
+
+interface ITemplate {
+       public function setTPL ($tpl);
+}
index 408e6d743bde4b0096947adb8ae5e0f95ef581c9..99c005e50658ee60d0a84ff256c537d62954b34c 100644 (file)
@@ -2,7 +2,7 @@
 namespace dns\system\helper;
 
 trait TDatabase {
-       private $db = null;
+       protected $db = null;
        
        public function setDB ($database) {
                $this->db = $database;
diff --git a/lib/system/helper/TTemplate.class.php b/lib/system/helper/TTemplate.class.php
new file mode 100644 (file)
index 0000000..0b2581b
--- /dev/null
@@ -0,0 +1,10 @@
+<?php
+namespace dns\system\helper;
+
+trait TTemplate {
+       protected $tpl = null;
+       
+       public function setTPL ($tpl) {
+               $this->tpl = $tpl;
+       }
+}