diff --git a/includes/class/Zone.php b/includes/class/Zone.php index 9fb77b7..642f9dd 100644 --- a/includes/class/Zone.php +++ b/includes/class/Zone.php @@ -126,17 +126,15 @@ class Zone { } } - public function addrrset($name, $type, $content, $disbled, $ttl = 3600) { + public function addrrset($name, $type, $content, $disabled = FALSE, $ttl = 3600) { if ($this->getrrset($name, $type) !== FALSE) { throw new Exception("This rrset already exists."); } - $rrset = new RRSet($name, $type, $content, $ttl); + $rrset = new RRSet($name, $type, $content, $disabled, $ttl); array_push($this->rrsets, $rrset); } public function addrecord($name, $type, $content, $disabled = FALSE, $ttl = 3600) { - $found = FALSE; - $rrset = $this->getrrset($name, $type); if ($rrset) { @@ -227,7 +225,7 @@ class Zone { } class RRSet { - public function __construct($name = '', $type = '', $content = '', $ttl = 3600) { + public function __construct($name = '', $type = '', $content = '', $disabled = FALSE, $ttl = 3600) { $this->name = $name; $this->type = $type; $this->ttl = $ttl; @@ -236,7 +234,7 @@ class RRSet { $this->comments = Array(); if (isset($content) and $content != '') { - $this->addRecord($content); + $this->addRecord($content, $disabled); } } diff --git a/zones.php b/zones.php index 4648965..1bb66c8 100644 --- a/zones.php +++ b/zones.php @@ -21,7 +21,7 @@ function is_ascii($string) { } function _valid_label($name) { - return is_ascii($name) && ( bool ) preg_match("/^([-.a-z0-9_\/\*]+)?$/i", $name ); + return is_ascii($name) && ( bool ) preg_match("/^([-.a-z0-9_\/\*]+)?.$/i", $name ); } function decode_record_id($id) { @@ -161,6 +161,7 @@ case "listslaves": array_push($return, $zone->export()); } } + usort($return, "zone_compare"); jtable_respond($return); break; @@ -172,7 +173,6 @@ case "listrecords": foreach ($records as &$record) { $record['id'] = json_encode($record); } - unset($record); usort($records, "record_compare"); jtable_respond($records); break; @@ -297,7 +297,36 @@ case "update": case "createrecord": $zone = new Zone(); $zone->parse($api->loadzone($_GET['zoneid'])); - $record = $zone->addrecord($_POST['name'], $_POST['type'], $_POST['content'], $_POST['disabled'], $_POST['ttl']); + + $name = isset($_POST['name']) ? $_POST['name'] : ''; + $type = $_POST['type']; + $content = $_POST['content']; + + if ('' == $name) { + $name = $zone->name; + } elseif (string_ends_with($name, '.')) { + # "absolute" name, shouldn't append zone[name] - but check. + $name = substr($name, 0, -1); + if (!string_ends_with($name, $zone->name)) { + jtable_respond(null, 'error', "Name $name not in zone ".$zone->name); + } + } else if (!string_ends_with($name, $zone->name)) { + $name = $name . '.' . $zone->name; + } + + + if (!_valid_label($name)) { + jtable_respond(null, 'error', "Please only use [a-z0-9_/.-]"); + } + if (!$type) { + jtable_respond(null, 'error', "Require a type"); + } + if (!is_ascii($content)) { + jtable_respond(null, 'error', "Please only use ASCII-characters in your fields"); + } + + + $record = $zone->addrecord($name, $type, $content, $_POST['disabled'], $_POST['ttl']); $api->savezone($zone->export()); jtable_respond($record, 'single');