mirror of
https://github.com/tuxis-ie/nsedit.git
synced 2025-05-07 22:42:21 +03:00
* Implement getrrset() and use it where we can
* addrecord() should just add the record, even if the rrset does not yet exist * Make addrecord() return the created record * Implement getrecord()
This commit is contained in:
parent
be9683ef83
commit
e2034c5861
1 changed files with 42 additions and 20 deletions
|
@ -113,26 +113,22 @@ class Zone {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleterrset($name, $type) {
|
public function deleterrset($name, $type) {
|
||||||
foreach ($this->rrsets as $rrset) {
|
$rrset = $this->getrrset($name, $type);
|
||||||
if ($rrset->name == $name and $rrset->type == $type) {
|
if ($rrset) {
|
||||||
$rrset->delete();
|
$rrset->delete();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setrrsetttl($name, $type, $ttl) {
|
public function setrrsetttl($name, $type, $ttl) {
|
||||||
foreach ($this->rrsets as $rrset) {
|
$rrset = $this->getrrset($name, $type);
|
||||||
if ($rrset->name == $name and $rrset->type == $type) {
|
if ($rrset) {
|
||||||
$rrset->setttl($ttl);
|
$rrset->setttl($ttl);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addrrset($name, $type, $content, $ttl = 3600) {
|
public function addrrset($name, $type, $content, $disbled, $ttl = 3600) {
|
||||||
foreach ($this->rrsets as $rrset) {
|
if ($this->getrrset($name, $type) !== FALSE) {
|
||||||
if ($rrset->name == $name and $rrset->type == $type) {
|
throw new Exception("This rrset already exists.");
|
||||||
throw new Exception("This rrset already exists.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
$rrset = new RRSet($name, $type, $content, $ttl);
|
$rrset = new RRSet($name, $type, $content, $ttl);
|
||||||
array_push($this->rrsets, $rrset);
|
array_push($this->rrsets, $rrset);
|
||||||
|
@ -141,16 +137,40 @@ class Zone {
|
||||||
public function addrecord($name, $type, $content, $disabled = false, $ttl = 3600) {
|
public function addrecord($name, $type, $content, $disabled = false, $ttl = 3600) {
|
||||||
$found = FALSE;
|
$found = FALSE;
|
||||||
|
|
||||||
foreach ($this->rrsets as $rrset) {
|
$rrset = $this->getrrset($name, $type);
|
||||||
if ($rrset->name == $name and $rrset->type == $type) {
|
|
||||||
$rrset->addRecord($content, $disabled);
|
if ($rrset) {
|
||||||
$found = TRUE;
|
$rrset->addRecord($content, $disabled);
|
||||||
|
} else {
|
||||||
|
$this->addrrset($name, $type, $content, $disabled, $ttl);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->getrecord($name, $type, $content);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getrecord($name, $type, $content) {
|
||||||
|
$rrset = $this->getrrset($name, $type);
|
||||||
|
foreach ($rrset->export_records() as $record) {
|
||||||
|
if ($record['content'] == $content) {
|
||||||
|
$record['name'] = $rrset->name;
|
||||||
|
$record['ttl'] = $rrset->ttl;
|
||||||
|
$record['type'] = $rrset->type;
|
||||||
|
$id = json_encode($record);
|
||||||
|
$record['id'] = $id;
|
||||||
|
return $record;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$found) {
|
}
|
||||||
throw new Exception("RRset does not exist for this record");
|
|
||||||
|
public function getrrset($name, $type) {
|
||||||
|
foreach ($this->rrsets as $rrset) {
|
||||||
|
if ($rrset->name == $name and $rrset->type = $type) {
|
||||||
|
return $rrset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rrsets2records() {
|
public function rrsets2records() {
|
||||||
|
@ -161,6 +181,8 @@ class Zone {
|
||||||
$record['name'] = $rrset->name;
|
$record['name'] = $rrset->name;
|
||||||
$record['ttl'] = $rrset->ttl;
|
$record['ttl'] = $rrset->ttl;
|
||||||
$record['type'] = $rrset->type;
|
$record['type'] = $rrset->type;
|
||||||
|
$id = json_encode($record);
|
||||||
|
$record['id'] = $id;
|
||||||
array_push($ret, $record);
|
array_push($ret, $record);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue