add missing file from last commit
authorStricted <info@stricted.de>
Tue, 17 Feb 2015 06:05:35 +0000 (07:05 +0100)
committerStricted <info@stricted.de>
Tue, 17 Feb 2015 06:05:35 +0000 (07:05 +0100)
lib/page/DomainAddPage.class.php [new file with mode: 0644]

diff --git a/lib/page/DomainAddPage.class.php b/lib/page/DomainAddPage.class.php
new file mode 100644 (file)
index 0000000..5ada3b8
--- /dev/null
@@ -0,0 +1,73 @@
+<?php
+namespace dns\page;
+use dns\system\DNS;
+use dns\system\User;
+
+/**
+ * @author      Jan Altensen (Stricted)
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @copyright   2014-2015 Jan Altensen (Stricted)
+ */
+class DomainAddPage extends AbstractPage {
+       public $activeMenuItem = 'add';
+       
+       public function prepare() {
+               if (isset($_POST['origin']) && isset($_POST['submit'])) {
+                       if (!empty($_POST['origin'])) {
+                               $origin = $_REQUEST['origin'];
+                               if (substr($origin, -1) != ".") {
+                                       $origin = $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($_SESSION['userID'], $soaID));
+                                       
+                                       $sql = "SELECT * FROM dns_template WHERE userID = ?";
+                                       $res = DNS::getDB()->query($sql, array($_SESSION['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);
+                                               }
+                                       }
+                               }
+                               else {
+                                       DNS::getTPL()->assign(array("error" => 'origin'));
+                               }
+                       }
+                       else {
+                               DNS::getTPL()->assign(array("error" => 'origin'));
+                       }
+               }
+               else {
+                       DNS::getTPL()->assign(array("error" => ''));
+               }
+       }
+}