<?php
namespace dns\page;
-use dns\system\ParseZone;
+use dns\util\ParseZone;
use dns\system\DNS;
use dns\system\User;
$action = trim($_POST['action']);
$dataID = intval(trim($_POST['dataID']));
if ($action == "toggleDomain") {
+ if (User::isReseller() === false) {
+ echo "failure";
+ exit;
+ }
+
$soaIDs = User::getAccessibleDomains();
if (!in_array($dataID, $soaIDs)) {
echo "failure";
exit;
}
else if ($action == "deleteDomain") {
+ if (User::isReseller() === false) {
+ echo "failure";
+ exit;
+ }
+
$soaIDs = User::getAccessibleDomains();
if (!in_array($dataID, $soaIDs)) {
echo "failure";
$row = DNS::getDB()->fetch_array($res);
if (empty($row)) {
- $apiKey = sha1(uniqid(sha1(uniqid().time().uniqid())));
+ $apiKey = DNS::generateRandomID();
$sql = "INSERT INTO dns_api (id, userID, apiKey) VALUES (NULL, ?, ?)";
DNS::getDB()->query($sql, array($_SESSION['userID'], $apiKey));
if (isset($_POST['zone']) && !empty($_POST['zone'])) {
if ($dataID == 0) {
if (isset($_POST['origin']) && !empty($_POST['origin'])) {
+ /*
+ if (User::isReseller() === false) {
+ echo "failure";
+ exit;
+ }
+ */
// new zone
}
}
public $activeMenuItem = 'add';
public function prepare() {
+ if (User::isReseller() === false) {
+ throw new \Exeption('Forbidden', 403);
+ }
if (isset($_POST['origin']) && isset($_POST['submit'])) {
if (!empty($_POST['origin'])) {
$origin = $_POST['origin'];
DNS::getTPL()->assign(array("user" => $user));
}
+ else {
+ throw new \Exeption('Forbidden', 403);
+ }
}
}
*/
/* assign language variables */
- self::getTPL()->assign(array("language" => $this->language));
+ self::getTPL()->assign(array(
+ "language" => $this->language,
+ "isReseller" => User::isReseller(),
+ "isAdmin" => User::isAdmin()
+ ));
}
/**
return self::$tplObj;
}
+ /**
+ * Creates a random hash.
+ *
+ * @return string
+ */
+ public static function generateRandomID() {
+ return sha1(microtime() . uniqid(mt_rand(), true));
+ }
+
/**
* build options from database
*
+++ /dev/null
-<?php
-namespace dns\system;
-
-/**
- * @author Jan Altensen (Stricted)
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @copyright 2015 Jan Altensen (Stricted)
- */
-class ParseZone {
- /**
- * domain name
- *
- * var string
- */
- private $origin = '';
-
- /**
- * lines of zone file
- *
- * var array
- */
- private $lines = array();
-
- /**
- * global ttl
- *
- * var integer
- */
- private $ttl = 0;
-
- /**
- * parsed soa record
- *
- * var array
- */
- private $soa = array();
-
- /**
- * parsed resource records
- *
- * var array
- */
- private $records = array();
-
- /**
- * init this class
- *
- * param string $file
- * param string $origin
- */
- public function __construct ($file, $origin = "") {
- if (!empty($origin)) $this->origin = $origin;
- // unify all lines
- $file = preg_replace_callback('/(\([^()]*\))/', function ($matches) {
- $a = explode("\n", $matches[0]);
- $b = array();
- foreach ($a as $line) {
-
- // unify whitespaces
- $line = preg_replace('/\s+/', ' ', $line);
-
- // strip comments
- $line = preg_replace('/(\s+)?(;|#)([\s\S]+)?/i', '', $line);
- $b[] = $line;
- }
- $line = implode("", $b);
-
- return str_replace(array("( ", "(", " )", ")"), "", $line);
- }, $file);
-
- $this->lines = explode("\n", $file);
-
- /*
- * limit lines to 200, if more is needed we can change it
- */
- if (count($this->lines) > 200) {
- throw new \Exception('zone file to big for parsing');
- }
- }
-
- /**
- * parse zone file
- */
- public function parse () {
- foreach ($this->lines as $line) {
- // unify whitespaces
- $line = preg_replace('/\s+/', ' ', $line);
-
- // strip comments
- $line = preg_replace('/(\s+)?(;|#)([\s\S]+)?/i', '', $line);
-
- /* ignore these lines */
- if (empty($line)) continue;
- if (strpos($line, "RRSIG") !== false) continue;
- if (strpos($line, "NSEC") !== false) continue;
- if (strpos($line, "DNSKEY") !== false) continue;
- if (strpos($line, "SPF") !== false) continue;
-
- $this->parseORIGIN($line);
- $this->parseTTL($line);
-
- if (strpos($line, "SOA") !== false) {
- $this->parseSOA($line);
- continue;
- }
-
- // parse all other records
- $this->parseRR($line);
- }
- }
-
- /**
- * parse ORIGIN
- *
- * param string $line
- */
- public function parseORIGIN ($line) {
- if (preg_match('/\$ORIGIN ([*-a-z0-9.]+)/i', $line, $match)) {
- $origin = $match[1];
- if (empty($this->origin)) {
- $this->origin = $origin;
- }
- else {
- if ($this->origin != $origin) {
- throw new \Exception('parse error');
- }
- }
- }
- }
-
- /**
- * parse TTL
- *
- * param string $line
- */
- public function parseTTL ($line) {
- if (preg_match('/\$TTL ([0-9]+)([a-z]+)?/i', $line, $match)) {
- if (isset($match[2])) {
- $this->ttl = $this->formatTime($match[1], $match[2]);
- }
- else {
- $this->ttl = $match[1];
- }
- }
- }
-
- /**
- * parse RR
- *
- * param string $line
- */
- public function parseRR ($line) {
- if(preg_match("/([*-a-z0-9.]+)? ([0-9]+)?(?: )?(IN)?(?: )?([a-z]+) ([\s\S]+)/i", $line, $matches)) {
- $record=array();
- // parse domain name
- if (!empty($this->origin) && $matches[1] == "@") {
- $record['name'] = $this->origin;
- }
- else {
- if (empty($matches[1])) {
- $record['name'] = $this->origin;
- }
- else {
- $record['name'] = $matches[1];
- }
- }
-
- // parse ttl
- if (empty($matches[2])) {
- $record['ttl'] = $this->ttl;
- }
- else {
- $record['ttl'] = $matches[2];
- }
-
- // parse type
- $record['type'] = $matches[4];
- if ($matches[4] == 'MX' || $matches[4] == 'SRV' || $matches[4] == 'DS') {
- $exp = explode(' ', $matches[5], 2);
- $record['aux'] = $exp[0];
- $record['data'] = $exp[1];
- }
- else {
- $record['aux'] = 0;
- $record['data'] = $matches[5];
- }
-
- // parse data
- if (strpos($record['data'], "@") !== false && !empty($this->origin)) {
- $record['data'] = str_replace("@", $this->origin, $record['data']);
- }
-
- $this->records[] = $record;
- }
- }
-
- /**
- * parse SOA
- *
- * param string $line
- */
- public function parseSOA ($line) {
- if (preg_match("/([@a-z0-9.-]+) ([0-9]+)?([a-z]+)?(?: )?(IN)?(?: )?(?:[a-z]+) ([-a-z0-9.]+) ([@-a-z0-9.]+) ([0-9a-]+) ([0-9]+)([a-z]+)? ([0-9]+)([a-z]+)? ([0-9]+)([a-z]+)? ([0-9]+)([a-z]+)?/i", $line, $matches)) {
- // set domain name
- if ($matches[1] == "@") {
- if (empty($this->origin)) {
- throw new \Exception('parse error');
- }
- }
- else {
- if (empty($this->origin)) {
- if (empty($matches[1])) {
- throw new \Exception('parse error');
- }
- else {
- $this->origin = $matches[1];
- }
- }
- else {
- if ($this->origin != $matches[1]) {
- throw new \Exception('parse error');
- }
- }
- }
-
- $this->soa['origin'] = $this->origin;
- $this->soa['ns'] = $matches[5];
-
- // replace @ with .
- if (strpos($matches[6], "@") !== false) {
- $this->soa['mbox'] = str_replace("@", ".", $matches[6]);
- }
- else {
- $this->soa['mbox'] = $matches[6];
- }
-
- $this->soa['serial'] = $matches[7];
-
- // parse refresh
- if (isset($matches[9]) && !empty($matches[9])) {
- $this->soa['refresh'] = $this->formatTime($matches[8], $matches[9]);
- }
- else {
- $this->soa['refresh'] = $matches[8];
- }
-
- // parse retry
- if (isset($matches[11]) && !empty($matches[11])) {
- $this->soa['retry'] = $this->formatTime($matches[10], $matches[11]);
- }
- else {
- $this->soa['retry'] = $matches[10];
- }
-
- // parse expire
- if (isset($matches[13]) && !empty($matches[13])) {
- $this->soa['expire'] = $this->formatTime($matches[12], $matches[13]);
- }
- else {
- $this->soa['expire'] = $matches[12];
- }
-
- // parse minimum and ttl
- if (isset($matches[3]) && !empty($matches[3]) && $matches[3] != "IN" && $matches[3] != "SO") {
- $this->soa['minimum'] = $this->formatTime($matches[2], $matches[3]);
- $this->soa['ttl'] = $this->formatTime($matches[2], $matches[3]);
- }
- else {
- if (!empty($matches[2])) {
- $this->soa['minimum'] = $matches[2];
- $this->soa['ttl'] = $matches[2];
- }
- else {
- $this->soa['minimum'] = $this->ttl;
- $this->soa['ttl'] = $this->ttl;
- }
- }
- }
- }
-
- /**
- * returns the parsed zone file
- *
- * @return array
- */
- public function getParsedData () {
- return array('soa' => $this->soa, 'rr' => $this->records);
- }
-
- /**
- * format ttl to seconds
- *
- * @param integer $time
- * @param string $modifier
- * @return integer
- */
- public function formatTime ($time, $modifier = '') {
- if (!empty($modifier)) {
- switch($modifier) {
- case "y":
- case "Y":
- $multiplier=86400*365;
- break;
- case 'w':
- case 'W':
- $multiplier=86400*7;
- break;
- case "d":
- case "D":
- $multiplier=86400;
- break;
- case "h":
- case "H":
- $multiplier=3600;
- break;
- case "m":
- case "M":
- $multiplier=60;
- break;
- case "s":
- case "S":
- default:
- $multiplier=1;
- break;
- }
-
- return $time * $multiplier;
- }
- else {
- return $time;
- }
- }
-}
--- /dev/null
+<?php
+namespace dns\util;
+
+/**
+ * @author Jan Altensen (Stricted)
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @copyright 2015 Jan Altensen (Stricted)
+ */
+class ParseZone {
+ /**
+ * domain name
+ *
+ * var string
+ */
+ private $origin = '';
+
+ /**
+ * lines of zone file
+ *
+ * var array
+ */
+ private $lines = array();
+
+ /**
+ * global ttl
+ *
+ * var integer
+ */
+ private $ttl = 0;
+
+ /**
+ * parsed soa record
+ *
+ * var array
+ */
+ private $soa = array();
+
+ /**
+ * parsed resource records
+ *
+ * var array
+ */
+ private $records = array();
+
+ /**
+ * init this class
+ *
+ * param string $file
+ * param string $origin
+ */
+ public function __construct ($file, $origin = "") {
+ if (!empty($origin)) $this->origin = $origin;
+ // unify all lines
+ $file = preg_replace_callback('/(\([^()]*\))/', function ($matches) {
+ $a = explode("\n", $matches[0]);
+ $b = array();
+ foreach ($a as $line) {
+
+ // unify whitespaces
+ $line = preg_replace('/\s+/', ' ', $line);
+
+ // strip comments
+ $line = preg_replace('/(\s+)?(;|#)([\s\S]+)?/i', '', $line);
+ $b[] = $line;
+ }
+ $line = implode("", $b);
+
+ return str_replace(array("( ", "(", " )", ")"), "", $line);
+ }, $file);
+
+ $this->lines = explode("\n", $file);
+
+ /*
+ * limit lines to 200, if more is needed we can change it
+ */
+ if (count($this->lines) > 200) {
+ throw new \Exception('zone file to big for parsing');
+ }
+ }
+
+ /**
+ * parse zone file
+ */
+ public function parse () {
+ foreach ($this->lines as $line) {
+ // unify whitespaces
+ $line = preg_replace('/\s+/', ' ', $line);
+
+ // strip comments
+ $line = preg_replace('/(\s+)?(;|#)([\s\S]+)?/i', '', $line);
+
+ /* ignore these lines */
+ if (empty($line)) continue;
+ if (strpos($line, "RRSIG") !== false) continue;
+ if (strpos($line, "NSEC") !== false) continue;
+ if (strpos($line, "DNSKEY") !== false) continue;
+ if (strpos($line, "SPF") !== false) continue;
+
+ $this->parseORIGIN($line);
+ $this->parseTTL($line);
+
+ if (strpos($line, "SOA") !== false) {
+ $this->parseSOA($line);
+ continue;
+ }
+
+ // parse all other records
+ $this->parseRR($line);
+ }
+ }
+
+ /**
+ * parse ORIGIN
+ *
+ * param string $line
+ */
+ public function parseORIGIN ($line) {
+ if (preg_match('/\$ORIGIN ([*-a-z0-9.]+)/i', $line, $match)) {
+ $origin = $match[1];
+ if (empty($this->origin)) {
+ $this->origin = $origin;
+ }
+ else {
+ if ($this->origin != $origin) {
+ throw new \Exception('parse error');
+ }
+ }
+ }
+ }
+
+ /**
+ * parse TTL
+ *
+ * param string $line
+ */
+ public function parseTTL ($line) {
+ if (preg_match('/\$TTL ([0-9]+)([a-z]+)?/i', $line, $match)) {
+ if (isset($match[2])) {
+ $this->ttl = $this->formatTime($match[1], $match[2]);
+ }
+ else {
+ $this->ttl = $match[1];
+ }
+ }
+ }
+
+ /**
+ * parse RR
+ *
+ * param string $line
+ */
+ public function parseRR ($line) {
+ if(preg_match("/([*-a-z0-9.]+)? ([0-9]+)?(?: )?(IN)?(?: )?([a-z]+) ([\s\S]+)/i", $line, $matches)) {
+ $record=array();
+ // parse domain name
+ if (!empty($this->origin) && $matches[1] == "@") {
+ $record['name'] = $this->origin;
+ }
+ else {
+ if (empty($matches[1])) {
+ $record['name'] = $this->origin;
+ }
+ else {
+ $record['name'] = $matches[1];
+ }
+ }
+
+ // parse ttl
+ if (empty($matches[2])) {
+ $record['ttl'] = $this->ttl;
+ }
+ else {
+ $record['ttl'] = $matches[2];
+ }
+
+ // parse type
+ $record['type'] = $matches[4];
+ if ($matches[4] == 'MX' || $matches[4] == 'SRV' || $matches[4] == 'DS') {
+ $exp = explode(' ', $matches[5], 2);
+ $record['aux'] = $exp[0];
+ $record['data'] = $exp[1];
+ }
+ else {
+ $record['aux'] = 0;
+ $record['data'] = $matches[5];
+ }
+
+ // parse data
+ if (strpos($record['data'], "@") !== false && !empty($this->origin)) {
+ $record['data'] = str_replace("@", $this->origin, $record['data']);
+ }
+
+ $this->records[] = $record;
+ }
+ }
+
+ /**
+ * parse SOA
+ *
+ * param string $line
+ */
+ public function parseSOA ($line) {
+ if (preg_match("/([@a-z0-9.-]+) ([0-9]+)?([a-z]+)?(?: )?(IN)?(?: )?(?:[a-z]+) ([-a-z0-9.]+) ([@-a-z0-9.]+) ([0-9a-]+) ([0-9]+)([a-z]+)? ([0-9]+)([a-z]+)? ([0-9]+)([a-z]+)? ([0-9]+)([a-z]+)?/i", $line, $matches)) {
+ // set domain name
+ if ($matches[1] == "@") {
+ if (empty($this->origin)) {
+ throw new \Exception('parse error');
+ }
+ }
+ else {
+ if (empty($this->origin)) {
+ if (empty($matches[1])) {
+ throw new \Exception('parse error');
+ }
+ else {
+ $this->origin = $matches[1];
+ }
+ }
+ else {
+ if ($this->origin != $matches[1]) {
+ throw new \Exception('parse error');
+ }
+ }
+ }
+
+ $this->soa['origin'] = $this->origin;
+ $this->soa['ns'] = $matches[5];
+
+ // replace @ with .
+ if (strpos($matches[6], "@") !== false) {
+ $this->soa['mbox'] = str_replace("@", ".", $matches[6]);
+ }
+ else {
+ $this->soa['mbox'] = $matches[6];
+ }
+
+ $this->soa['serial'] = $matches[7];
+
+ // parse refresh
+ if (isset($matches[9]) && !empty($matches[9])) {
+ $this->soa['refresh'] = $this->formatTime($matches[8], $matches[9]);
+ }
+ else {
+ $this->soa['refresh'] = $matches[8];
+ }
+
+ // parse retry
+ if (isset($matches[11]) && !empty($matches[11])) {
+ $this->soa['retry'] = $this->formatTime($matches[10], $matches[11]);
+ }
+ else {
+ $this->soa['retry'] = $matches[10];
+ }
+
+ // parse expire
+ if (isset($matches[13]) && !empty($matches[13])) {
+ $this->soa['expire'] = $this->formatTime($matches[12], $matches[13]);
+ }
+ else {
+ $this->soa['expire'] = $matches[12];
+ }
+
+ // parse minimum and ttl
+ if (isset($matches[3]) && !empty($matches[3]) && $matches[3] != "IN" && $matches[3] != "SO") {
+ $this->soa['minimum'] = $this->formatTime($matches[2], $matches[3]);
+ $this->soa['ttl'] = $this->formatTime($matches[2], $matches[3]);
+ }
+ else {
+ if (!empty($matches[2])) {
+ $this->soa['minimum'] = $matches[2];
+ $this->soa['ttl'] = $matches[2];
+ }
+ else {
+ $this->soa['minimum'] = $this->ttl;
+ $this->soa['ttl'] = $this->ttl;
+ }
+ }
+ }
+ }
+
+ /**
+ * returns the parsed zone file
+ *
+ * @return array
+ */
+ public function getParsedData () {
+ return array('soa' => $this->soa, 'rr' => $this->records);
+ }
+
+ /**
+ * format ttl to seconds
+ *
+ * @param integer $time
+ * @param string $modifier
+ * @return integer
+ */
+ public function formatTime ($time, $modifier = '') {
+ if (!empty($modifier)) {
+ switch($modifier) {
+ case "y":
+ case "Y":
+ $multiplier=86400*365;
+ break;
+ case 'w':
+ case 'W':
+ $multiplier=86400*7;
+ break;
+ case "d":
+ case "D":
+ $multiplier=86400;
+ break;
+ case "h":
+ case "H":
+ $multiplier=3600;
+ break;
+ case "m":
+ case "M":
+ $multiplier=60;
+ break;
+ case "s":
+ case "S":
+ default:
+ $multiplier=1;
+ break;
+ }
+
+ return $time * $multiplier;
+ }
+ else {
+ return $time;
+ }
+ }
+}
<a href="#"><i class="fa fa-home"></i> Domains<span class="fa arrow"></span></a>
<ul class="{if $activeMenuItem == 'index' || $activeMenuItem == 'add' || $activeMenuItem == 'update'}nav nav-second-level collapse in{else}nav nav-second-level{/if}">
<li><a {if $activeMenuItem == 'index'}class="active" {/if}href="index.php?page=DomainList"><i class="fa fa-list"></i> Auflisten</a></li>
- <li><a {if $activeMenuItem == 'add'}class="active" {/if}href="index.php?page=DomainAdd"><i class="fa fa-plus"></i> Hinzufügen</a></li>
+ {if $isReseller === true}<li><a {if $activeMenuItem == 'add'}class="active" {/if}href="index.php?page=DomainAdd"><i class="fa fa-plus"></i> Hinzufügen</a></li>{/if}
</ul>
</li>
<li{if $activeMenuItem == 'settings' || $activeMenuItem == 'api'} class="active"{/if}>
</ol>
</div>
</div>
+{if $isReseller === true}
<div class="row">
<div class="col-lg-12">
<div class="page-header pull-right">
</div>
</div>
</div>
+{/if}
{hascontent}
<div class="row">
<div class="col-lg-12">
<td>{$domain['serial']}</td>
<td>{$domain['rrc']}</td>
<td>
- <span class="fa fa-remove ttips pointer deleteDomain" delete-id="{$domain['id']}" delete-confirm="{lang}domain.delete.message{/lang}" title="{lang}button.delete{/lang}"></span>
- <span class="fa fa{if $domain['active']}-check{/if}-square-o ttips pointer toggleDomain" toggle-id="{$domain['id']}" title="{if $domain['active']}{lang}button.disable{/lang}{else}{lang}button.enable{/lang}{/if}" data-disable-message="{lang}button.disable{/lang}" data-enable-message="{lang}button.enable{/lang}"></span>
+ {if $isReseller === true}
+ <span class="fa fa-remove ttips pointer deleteDomain" delete-id="{$domain['id']}" delete-confirm="{lang}domain.delete.message{/lang}" title="{lang}button.delete{/lang}"></span>
+ <span class="fa fa{if $domain['active']}-check{/if}-square-o ttips pointer toggleDomain" toggle-id="{$domain['id']}" title="{if $domain['active']}{lang}button.disable{/lang}{else}{lang}button.enable{/lang}{/if}" data-disable-message="{lang}button.disable{/lang}" data-enable-message="{lang}button.enable{/lang}"></span>
+ {/if}
<a href="index.php?page=SecList&id={$domain['id']}" class="ttips" title="Edit DNSSEC"><span class="fa fa-key"></span></a>
</td>
</tr>