if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['method'])) { $method = $_POST['method']; $valid = true; $problem = ''; $zone = ''; $content = array(); $temp = ''; switch ($method) { case "file": $zone = isset($_POST['fil_domain']) && isset($_FILES['fil']['tmp_name']) ? $zone = $_POST['fil_domain'] : ''; $content = $zone > '' ? file($_FILES['fil']['tmp_name']) : array(); $smarty->assign("method", "Upload from file"); break; case "list": $zone = isset($_POST['sel_domain']) && $_POST['sel'] != '- select file -' ? $_POST['sel_domain'] : ''; $content = $zone > '' ? file($conf->path . idnToHost($_POST['sel'])) : array(); $smarty->assign("method", "Select orphan file from list"); break; case "text": $zone = isset($_POST['txt_domain']) && isset($_POST['txt']) ? $_POST['txt_domain'] : ''; $content = $zone > '' ? explode("\n", $_POST['txt']) : array(); $smarty->assign("method", "Write zone manually or pasted from clipboard"); break; default: problem(); } if (count($content) < 4) { problem("nocontent"); } $gzone = $zone; $zone = hostToIdn($zone);
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; }
while ($rec = $res->fetchRow()) { switch ($rec['prefkey']) { case 'hostmaster': $key = 0; break; case 'prins': $key = 1; $rec['prefval'] = idnToHost($rec['prefval']); break; case 'secns': $key = 2; $rec['prefval'] = idnToHost($rec['prefval']); break; case 'master': $key = 3; $rec['prefval'] = idnToHost($rec['prefval']); break; default: $key = 4; } $options[$key] = $rec; } $smarty->assign("records", $recordarray); $smarty->assign("options", $options); $smarty->assign("pagetitle", "Options"); $smarty->assign("template", "optionsread.tpl"); $smarty->assign("help", help("optionsread")); $smarty->assign("menu_button", menu_buttons()); $smarty->display("main.tpl"); } else { access_denied();