/** * @see \Src\RouterBoard\IRouterBoardBackup::backupOneRouterBoard() */ public function backupOneRouterBoard(InputParser $input) { if (!($inputArray = $input->getAddr())) { throw new Exception("Input array is empty!"); } foreach ($inputArray as $ipAddr) { if ($this->dbconnect->checkExistIP($ipAddr['addr'])) { $data = $this->dbconnect->getOneIP($ipAddr['addr']); $this->goBackup($data[0]['addr'], $data[0]['port'], $data[0]['identity']); continue; } $this->logger->log('IP addresses: ' . $ipAddr['addr'] . ' does not exist in the database! Add this IP address first.', $this->logger->setError()); } $this->sendMail(); }
/** * @see \Src\RouterBoard\IRouterBoard::updateIP() */ public function updateIP(InputParser $input) { if (!($inputArray = $input->getAddr())) { throw new Exception("Input array is empty!"); } if (count($inputArray) != 2) { $this->logger->log("The delete is not possible. Enter only two IP addresses: -i ip -i ip", $this->logger->setError()); return; } $dbconnect = new $this->config['database']['data-adapter']($this->config, $this->logger); $ip0 = $dbconnect->checkExistIP($inputArray[0]['addr']); $ip1 = $dbconnect->checkExistIP($inputArray[1]['addr']); if ($ip0 && $ip1) { $this->logger->log("Both IP addresses already exist in database!", $this->logger->setError()); return; } if (!$ip0 && !$ip1) { $this->logger->log("Neither of the two IP address exist in the database!", $this->logger->setError()); return; } $ssh = new SSHConnector($this->config, $this->logger); if ($ip0) { if ($identity = $ssh->createBackupAccount($inputArray[1]['addr'], $inputArray[1]['port'])) { if ($dbconnect->updateIP($inputArray[0]['addr'], $inputArray[1]['addr'], $inputArray[1]['port'], $identity)) { $this->logger->log("The update has been successful."); } else { $this->logger->log("The update IP '" . $inputArray[0]['addr'] . "' database error.", $this->logger->setError()); } } return; } if ($identity = $ssh->createBackupAccount($inputArray[0]['addr'], $inputArray[0]['port'])) { if ($dbconnect->updateIP($inputArray[1]['addr'], $inputArray[0]['addr'], $inputArray[0]['port'], $identity)) { $this->logger->log("The update has been successful."); } else { $this->logger->log("The update IP '" . $inputArray[1]['addr'] . "' database error.", $this->logger->setError()); } } }
/** * @see \Src\RouterBoard\IRouterBoardBackup::backupOneRouterBoard() */ public function backupOneRouterBoard(InputParser $input) { if (!($inputArray = $input->getAddr())) { throw new Exception("Input array is empty!"); } foreach ($inputArray as $ipAddr) { if ($this->dbconnect->checkExistIP($ipAddr['addr'])) { $data = $this->dbconnect->getOneIP($ipAddr['addr']); if (is_null($data[0]['port'])) { $data[0]['port'] = $this->config['routerboard']['ssh-port']; } if ($this->ssh->getBackupFile($data[0]['addr'], $data[0]['port'], $this->rootdir, $this->folder, $data[0]['identity'])) { // push both to the repository $this->doGitLabPush($data[0]['addr'], $data[0]['identity'], 'backup', 'base64'); $this->doGitLabPush($data[0]['addr'], $data[0]['identity'], 'rsc', 'text'); $this->logger->log("Backup of the router " . $data[0]['addr'] . " has been sucessfully."); $this->dbconnect->updateBackupTime($data[0]['addr']); continue; } } $this->logger->log('IP addresses: ' . $ipAddr['addr'] . ' does not exist in the database! Add this IP address first.', $this->logger->setError()); } $this->sendMail(); }
public function testInputParserError() { $input = array(0 => '10.17.254.300', 1 => '10.10.10.300', 2 => '192.168.1.1:90750'); $inputParser = new InputParser(self::$config, new OutputLogger(new NullOutput()), $input); $this->assertFalse($inputParser->getAddr()); }