/** * Add */ public function executeAdd() { if ($this->isGET()) { return $this->renderJson(array("success" => false, "info" => "POST only.")); } else { $name = $this->getRequestParameter('name'); $domain = new Domain(); $domain->setName($name); $domain->setType($this->template->getType()); $domain->save(); foreach ($this->template->getTemplateRecords() as $tr) { $record = new Record(); $record->setDomainId($domain->getId()); $record->setName(str_replace("%DOMAIN%", $name, $tr->getName())); $record->setType($tr->getType()); if ($tr->getType() == 'SOA') { $content = str_replace("%DOMAIN%", $name, $tr->getContent()); $content = str_replace("%SERIAL%", date("Ymd") . "01", $content); } else { $content = $tr->getContent(); } $record->setContent($content); $record->setTtl($tr->getTtl()); $record->setPrio($tr->getPrio()); $record->save(); } return $this->renderJson(array("success" => true, "info" => "Domain added.")); } }
public function getHostFromReport(Host &$host, &$pkgs) { Utils::log(LOG_DEBUG, "Getting the host from the report", __FILE__, __LINE__); if ($host == null) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host object is not valid or Host.id is not set"); } # Get the osId $host->setOsName($this->guessOs($host, $pkgs)); $osDao = $this->getPakiti()->getDao("Os"); $osId = $osDao->getIdByName($host->getOsName()); if ($osId == -1) { # Os is missing, so store it $os = new Os(); $os->setName($host->getOsName()); $osDao->create($os); $osId = $os->getId(); } else { $os = $osDao->getById($osId); } $host->setOsId($osId); $host->setOs($os); # Get the archId $archDao = $this->getPakiti()->getDao("Arch"); $archId = $archDao->getIdByName($host->getArchName()); if ($archId == -1) { # Arch is missing, so store it $arch = new Arch(); $arch->setName($host->getArchName()); $archDao->create($arch); $archId = $arch->getId(); } else { $arch = $archDao->getById($archId); } $host->setArchId($archId); $host->setArch($arch); # Get the domainId # Guess the domain name from the reporterHostname $domainName = $this->guessDomain($host->getHostname()); $domainDao = $this->getPakiti()->getDao("Domain"); $domainId = $domainDao->getIdByName($domainName); if ($domainId == -1) { # Domain is missing, so store it $domain = new Domain(); $domain->setName($domainName); $domainDao->create($domain); $domainId = $domain->getId(); } else { $domain = $domainDao->getById($domainId); } $host->setDomainId($domainId); $host->setDomain($domain); # Try to find the host in the DB $host->setId($this->getHostId($host)); if ($host->getId() != -1) { # Update entries $this->getPakiti()->getDao("Host")->update($host); return $host; } else { return $this->storeHostFromReport($host); } }
function domain_insert($post, $db) { $new_domain = new Domain(); $new_domain->setName($post['dname']); $new_domain->setServerName($post['sname']); $new_domain->setServerIP($post['sip']); $new_domain->setServerPort($post['sport']); $new_domain->setServerAdmin($post['sadmin']); $new_domain->setAlias($post['salias']); $new_domain->setOther($post['other']); $new_domain->setModSecConf($post['mod_sec_conf']); $new_domain->setActive($post['validity']); $new_domain->setFilled(true); $db->addDomain($new_domain); }
public function getAllDomains($where = '') { $count_str = "SELECT D.*,C.ConfName from domain D\n LEFT JOIN modsec_conf C ON (C.ConfID=D.ConfID)\n {$where}"; $result = $this->dbh->query($count_str); if (PEAR::isError($result)) { echo $result->getMessage() . ' - ' . $result->getUserinfo(); exit; } $array = $result->fetchAll(); $result->free(); $domains_a = array(); foreach ($array as $el) { $domain = new Domain(); $domain->setID($el[0]); $domain->setName($el[1]); $domain->setServerName($el[2]); $domain->setServerIP($el[3]); $domain->setServerPort($el[4]); $domain->setServerAdmin($el[5]); $domain->setAlias($el[6]); $domain->setOther(stripslashes($el[7])); $domain->setModSecConf($el[8]); $domain->setActive($el[9]); $domain->setModSecConfName($el[12]); $domain->setFilled(true); $domains_a[] = $domain; } return $domains_a; }