$total = isset($_POST['total']) && $_POST['total'] > 0 ? $_POST['total'] : 0; for ($x = 0; $x < $total; $x++) { if (isset($_POST['delete'][$x])) { $zone->eraseRecord(intval($_POST['host_id'][$x])); } else { $nrec = array(); foreach (array('host', 'ttl', 'type', 'pri', 'destination') as $key) { $pkey = $key == 'ttl' ? 'rttl' : $key; $nrec[$key] = isset($_POST[$pkey][$x]) ? $_POST[$pkey][$x] : ''; $nrec[$key] = $key == 'ttl' && $nrec[$key] == '' ? 0 : $nrec[$key]; $nrec[$key] = $key == 'pri' && $nrec[$key] == '' ? 10 : $nrec[$key]; $nrec[$key] = $key == 'host' && $nrec[$key] == '' ? '@' : $nrec[$key]; $nrec[$key] = $key == 'destination' && $nrec[$key] == '' ? '@' : $nrec[$key]; } if ($nrec['host'] != $nrec['destination']) { $urec = new masterRecord(intval($_POST['host_id'][$x])); $urec->loadRecord(); $urec->setRecord($nrec); $xrec = $urec->getRecordRaw(); $urec->saveRecord(); } } } $zone->clearZone(); $zone->loadZone(); $nrec = array(); foreach (array('host', 'ttl', 'type', 'pri', 'destination') as $key) { $nrec[$key] = isset($_POST['new' . $key]) && $_POST['new' . $key] > '' ? $_POST['new' . $key] : NULL; } if ($nrec['host'] != $nrec['destination']) { $nrec['pri'] = $nrec['type'] == 'MX' ? 10 : 0;
public function parseZone($rows, $zonename, $owner = 1) { if (!is_array($rows)) { ob_start(); var_dump($rows); $this->err .= "Zone can be parsed from an array only" . "\n" . ob_get_clean(); error_log($this->err); return false; } else { $this->clearZone(); $this->head['name'] = idnToHost($zonename); $soafound = false; $soabegins = false; $soadata = ''; $recrow = ''; foreach ($rows as $row) { $row = preg_replace(COMMENT_PATTERN, ' ', trim($row)); $row = $row == " " ? '' : $row; if ($soafound === false) { if (preg_match(ORIGIN_PATTERN, $row, $match)) { $zone = strtolower($match[1]); if ($zone != $expectedname) { $this->clearZone(); $this->err .= "Given zone not matches with the expected (" . $zone . "<=>" . $expectedzone . ")"; error_log($this->err); return false; } } if (preg_match(SOA_BEGINS_PATTERN, $row, $match)) { $soabegins = true; } if ($soabegins) { $soadata .= $row; } if (preg_match(FULL_SOA_PATTERN, $soadata, $match)) { $prins = $match[3]; if (preg_match(TIMES_PATTERN, $match[5], $match2)) { $soafound = true; $serial = $match2[1]; $refresh = $this->bind_time_format($match2[2]); $retry = $this->bind_time_format($match2[3]); $expire = $this->bind_time_format($match2[4]); $ttl = $this->bind_time_format($match2[5]); if ($this->setZoneHead(array('serial' => intval($serial), 'refresh' => intval($refresh), 'retry' => intval($retry), 'expire' => intval($expire), 'ttl' => intval($ttl), 'owner' => intval($owner), 'pri_dns' => strval($prins), 'sec_dns' => '##EMPTY##')) && $this->saveZoneHead()) { $soafound = true; } else { $this->err .= "Head cannot be set" . "\n" . $soadata; $this->clearZone(); return false; } } else { $this->err .= "SOA record cannot be parsed" . "\n" . $soadata; error_log($this->err); return false; } } } else { if ($recrow != '') { $rowpart = trim($row); $recrow .= $rowpart; $end = strpos($recrow, ')'); if ($end > 0) { $recrow = substr($recrow, 0, $end); $recd = new masterRecord(array('zone' => $this->head['id'])); if ($recd->setRecord($recrow)) { $parsed = $recd->getRecordRaw(); if ($this->head['sec_dns'] == '##EMPTY##' && $parsed['type'] == 'NS' && $parsed['destination'] != $self->head['pri_dns'] && ($parsed['host'] == '@' || $parsed['host'] == '')) { $self->head['sec_dns'] == $parsed['destination']; } $this->records[] = $recd; $recrow = ''; } else { $this->err .= $recd->getErr(); return false; } } } elseif ($row > '') { $end = strpos($row, '('); if ($end > 0) { $row = preg_replace('/\\(/', '', $row); $recrow = $row; } $end = strpos($recrow, ')'); if ($end > 0) { $recrow = substr($recrow, 0, $end); $recd = new masterRecord(array('zone' => $this->head['id'])); if ($recd->setRecord($recrow, $this->head['name'])) { $this->records[] = $recd; $recrow = ''; } else { $this->err .= $recd->getErr(); return false; } } elseif ($recrow == '') { $recd = new masterRecord(array('zone' => $this->head['id'])); if ($recd->setRecord($row, $this->head['name'])) { $this->records[] = $recd; } else { $this->err .= $recd->getErr(); return false; } } } } } $recs = array(); foreach ($this->records as $each) { $rhd = $each->getRecordRaw(); if ($rhd['type'] == 'NS') { if ($rhd['host'] == '@' && $rhd['destination'] == $this->head['pri_dns'] . '.') { continue; } elseif ($rhd['host'] == '@') { $this->head['sec_dns'] = $this->head['sec_dns'] == '##EMPTY##' ? preg_replace('/\\.$/', '', $rhd['destination']) : $this->head['sec_dns']; continue; } } $recs[] = $each; } $this->records = $recs; $this->saveZone(); } return true; }