Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //         $start = intval($input->getOption('start'));
     //         $stop  = intval($input->getOption('stop'));
     //     	sleep(10);
     //     	throw new SynKnotException("chybka");
     //     	var_dump("executing reload");
     //nasype DNS (pri) zóny do temp adresáře
     $dnsCommand = $this->getApplication()->find('synknot:dns');
     $dnsCommand->run($input, $output);
     //nasype PTR zóny do tmp adresáře
     $ptrCommand = $this->getApplication()->find('synknot:ptr');
     $ptrCommand->run($input, $output);
     $fileBuilder = new FileBuilder($this->config);
     //přesun nových záznamů
     //temp do používaného adresáře
     $fileBuilder->moveDirectory($this->config['path-pri-tmp'], $this->config['path-pri']);
     //přesun seznamu zónových souborů
     $fileBuilder->moveFile($this->config['path-zones-tmp'], $this->config['path-zones']);
     //pro PTR to platí taky
     $fileBuilder->moveDirectory($this->config['path-ptr-tmp'], $this->config['path-ptr']);
     $fileBuilder->moveFile($this->config['path-zones-ptr-tmp'], $this->config['path-zones-ptr']);
     //reload
     $dnsSynchronizer = new DNSSynchronizer($this->config);
     $dnsSynchronizer->reloadService();
     $output->writeln('Reloading service.');
     //TODO
     //$this->getContainer()->get('logger')->info("Reload complete");
     //         $this->logger->info()
 }
Example #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     //         $start = intval($input->getOption('start'));
     //         $stop  = intval($input->getOption('stop'));
     $dnsCommand = $this->getApplication()->find('synknot:dns');
     $dnsCommand->run($input, $output);
     $ptrCommand = $this->getApplication()->find('synknot:ptr');
     $ptrCommand->run($input, $output);
     $fileBuilder = new FileBuilder($this->config);
     if (is_dir($this->config['path-timers'])) {
         $fileBuilder->clearDirectory($this->config['path-timers'], array('*.mdb'));
     }
     //přesun nových záznamů
     $fileBuilder->clearDirectory($this->config['path-pri-backup']);
     $fileBuilder->moveDirectory($this->config['path-pri'], $this->config['path-pri-backup']);
     $fileBuilder->moveDirectory($this->config['path-pri-tmp'], $this->config['path-pri']);
     //přesun seznamu zónových souborů
     $fileBuilder->moveFile($this->config['path-zones'], $this->config['path-zones-backup']);
     $fileBuilder->moveFile($this->config['path-zones-tmp'], $this->config['path-zones']);
     $fileBuilder = new FileBuilder($this->config);
     //přesun nových záznamů
     $fileBuilder->clearDirectory($this->config['path-ptr-backup']);
     $fileBuilder->moveDirectory($this->config['path-ptr'], $this->config['path-ptr-backup']);
     $fileBuilder->moveDirectory($this->config['path-ptr-tmp'], $this->config['path-ptr']);
     //přesun seznamu zónových souborů
     $fileBuilder->moveFile($this->config['path-zones-ptr'], $this->config['path-zones-ptr-backup']);
     $fileBuilder->moveFile($this->config['path-zones-ptr-tmp'], $this->config['path-zones-ptr']);
     //restart
     $dnsSynchronizer = new DNSSynchronizer($this->config);
     $dnsSynchronizer->restartService();
     $output->writeln('Restarting service.');
 }
Example #3
0
 public function createPTRRecords(IAdapter $dataAdapter)
 {
     $data = $dataAdapter->getData();
     $ptrBuilder = new PTRBuilder($this->config);
     //temp
     // rozdělení do ptr groups
     // 		$ptrBuilders = array();
     // 		foreach ($data as $row){
     // 			$ptrGroup = $ptrBuilder->getPTRGroup($row["ip"]);
     // 			if(!isset($ptrBuilders[$ptrGroup])){
     // 				$ptrBuilder = new PTRBuilder($this->config);
     // 				$ptrBuilders[$ptrGroup] = $ptrBuilder;
     // 			}else{
     // 				$ptrBuilder = $ptrBuilders[$ptrGroup];
     // 			}
     // 			if(!empty($row['ptr'])){
     // 				$ptrBuilder->addRecord($row["ip"], $row["ptr"]);
     // 			}
     // 		}
     foreach ($data as $row) {
         $ptrBuilder->addRecord($row["ip"], $row["ptr"]);
     }
     $fileBuilder = new FileBuilder($this->config);
     // 		$ptrGroupList = array();
     // vytváření PTR souborů pro každou group
     $this->getLogger()->log("Creating PTR zones");
     foreach ($ptrBuilder->getRecords() as $key => $ptrGroup) {
         //uložit do souboru
         // 			$path = sprintf('%1$s%2$s.zone', $this->config['path-pri-tmp'], $domainName);
         switch ($this->config['server-status']) {
             case "master":
                 //obsah zónového souboru
                 $path = $this->config['path-ptr-tmp'] . $key . ".zone";
                 $pathOld = $this->config['path-ptr'] . $key . ".zone";
                 $serial = date("Ymd") . "01";
                 $ptrZone = $ptrBuilder->build($key, $serial);
                 //starý zónový soubor
                 if (file_exists($pathOld)) {
                     $this->getLogger()->log("Found old PTR zone " . $pathOld);
                     $ptrZoneOld = file_get_contents($pathOld);
                     try {
                         //sériové číslo v původním souboru
                         $oldSerial = $this->getSerial($ptrZoneOld);
                         $ptrZoneCheck = $this->switchSerial($ptrZoneOld, $serial);
                         //stará zóna je jiná, než tahle, tak se navýší serial
                         if ($ptrZoneCheck != $ptrZone) {
                             $maxSerial = max($serial, intval($oldSerial + 1));
                             $ptrZone = $this->switchSerial($ptrZone, $maxSerial);
                             $this->getLogger()->log("Different PTR zone > new serial " . $maxSerial);
                         } else {
                             //zóny jsou stejné
                             //if($serial < $oldSerial){
                             //kdyby náhodou byl serial menší, tak musí zůstat ten již upravovaný
                             $ptrZone = $this->switchSerial($ptrZone, $oldSerial);
                             $this->getLogger()->log("Same PTR zone > old serial " . $oldSerial);
                             //}else{
                             //$this->getLogger()->log("PTR serial should be the same");
                             //}
                         }
                         //TODO tests:
                         /*
                          * - jestli se vytvoří zónový soubor na fresh instalaci
                          * - jestli se přepíše a zvětší serial u již hotového zónového souboru, když jsou data jiná
                          * - jestli se nepřepíše serial, když jsou data stejná, ale den větší
                          * - když jsou soubory rozlišné, tak se má vygenerovat nový serial, který je minimálně dnes
                          */
                     } catch (Exception $e) {
                         $this->getLogger()->log($e->getMessage());
                         throw $e;
                     }
                 }
                 $fileBuilder->saveContent($ptrZone, $path);
                 $this->getLogger()->log("Saving PTR zone " . $path);
                 break;
             case "slave":
                 $ptrZone = $ptrBuilder->build($key);
                 //tím se dostane do zonelist
                 //záznam o zónovém souboru do seznamu
                 break;
         }
         // 			$ptrGroupList[] = sprintf("%s{\n\tfile \"%s\";\n}", $key, $this->config['path-ptr'] . $key . ".zone");
     }
     //vytvoření seznamu všech PTR groups
     // 		$ptrBuilder->saveContent($this->config['path-zones-ptr-tmp'], implode(PHP_EOL . PHP_EOL, $ptrGroupList));
     //přesun nových záznamů
     // 		$fileBuilder->clearDirectory($this->config['path-ptr-backup']);
     // 		$fileBuilder->moveDirectory($this->config['path-ptr'], $this->config['path-ptr-backup']);
     // 		$fileBuilder->moveDirectory($this->config['path-ptr-tmp'], $this->config['path-ptr']);
     //přesun seznamu zónových souborů
     $fileBuilder->saveContent($ptrBuilder->getZoneList(), $this->config['path-zones-ptr-tmp']);
     // 		$fileBuilder->moveFile($this->config['path-zones-ptr'], $this->config['path-zones-ptr-backup']);
     // 		$fileBuilder->moveFile($this->config['path-zones-ptr-tmp'], $this->config['path-zones-ptr']);
 }