outsource record-generation and zone-generation to classes for better handling
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
47
lib/classes/dns/class.DnsEntry.php
Normal file
47
lib/classes/dns/class.DnsEntry.php
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2016 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2016-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
*/
|
||||
class DnsEntry
|
||||
{
|
||||
|
||||
public $record;
|
||||
|
||||
public $ttl;
|
||||
|
||||
public $class = 'IN';
|
||||
|
||||
public $type;
|
||||
|
||||
public $priority;
|
||||
|
||||
public $content;
|
||||
|
||||
public function __construct($record = '', $type = 'A', $content = null, $prio = 0, $ttl = 18000, $class = 'IN')
|
||||
{
|
||||
$this->record = $record;
|
||||
$this->type = $type;
|
||||
$this->content = $content;
|
||||
$this->priority = $prio;
|
||||
$this->ttl = $ttl;
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$result = $this->record . "\t" . $this->ttl . "\t" . $this->class . "\t" . $this->type . "\t" . (($this->prio >= 0 && ($this->type == 'MX' || $this->type == 'SRV')) ? $this->prio . "\t" : "") . $this->content . PHP_EOL;
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
44
lib/classes/dns/class.DnsZone.php
Normal file
44
lib/classes/dns/class.DnsZone.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of the Froxlor project.
|
||||
* Copyright (c) 2016 the Froxlor Team (see authors).
|
||||
*
|
||||
* For the full copyright and license information, please view the COPYING
|
||||
* file that was distributed with this source code. You can also view the
|
||||
* COPYING file online at http://files.froxlor.org/misc/COPYING.txt
|
||||
*
|
||||
* @copyright (c) the authors
|
||||
* @author Froxlor team <team@froxlor.org> (2016-)
|
||||
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
|
||||
* @package Classes
|
||||
*
|
||||
*/
|
||||
class DnsZone
|
||||
{
|
||||
|
||||
public $ttl;
|
||||
|
||||
public $origin;
|
||||
|
||||
public $records;
|
||||
|
||||
public function __construct($ttl = 18000, $origin = '', $records = null)
|
||||
{
|
||||
$this->ttl = $ttl;
|
||||
$this->origin = $origin;
|
||||
$this->records = $records;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
$_zonefile = "\$TTL " . $this->ttl . PHP_EOL;
|
||||
$_zonefile .= "\$ORIGIN " . $this->origin . "." . PHP_EOL;
|
||||
if (! empty($this->records)) {
|
||||
foreach ($this->records as $record) {
|
||||
$_zonefile .= (string) $record;
|
||||
}
|
||||
}
|
||||
return $_zonefile;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user