function isPermited(Host &$host, VM &$vm) { if (is_null($this->matrix)) { throw new Exception("TestingWithoutMatrix", 1); } return isset($this->matrix[$host->getId()][$vm->getId()]) ? $this->matrix[$host->getId()][$vm->getId()] : false; }
/** * Find vulnerable packages for a specific host * Save vulnerable pkgId and corresponding cveDefId and osGroupId to PkgCveDef table * @throws Exception * @param Host $host * */ public function calculateVulnerablePkgsForSpecificHost(Host $host) { if ($host == null || $host->getId() == -1) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host object is not valid or Host.id is not set"); } Utils::log(LOG_DEBUG, "Searching for vulnerable packages for specific host ", __FILE__, __LINE__); // If not in Os Group $osGroup = $this->getPakiti()->getManager("OsGroupsManager")->getOsGroupByOsId($host->getOsId()); if ($osGroup == null) { throw new Exception("Host's OS is not a member of any OsGroup"); } //Get installed Pkgs on Host $installedPkgs = $this->getPakiti()->getManager("PkgsManager")->getInstalledPkgs($host); //For each vulnerable package get Cvedef foreach ($installedPkgs as $installedPkg) { $confirmedVulnerabilities = array(); $potentialVulnerabilities = $this->getPakiti()->getDao("Vulnerability")->getVulnerabilitiesByPkgNameOsGroupIdArch($installedPkg->getName(), $osGroup->getId(), $installedPkg->getArch()); if (!empty($potentialVulnerabilities)) { foreach ($potentialVulnerabilities as $potentialVulnerability) { switch ($potentialVulnerability->getOperator()) { //TODO: Add more operator cases case "<": if ($this->vercmp($host->getType(), $installedPkg->getVersion(), $installedPkg->getRelease(), $potentialVulnerability->getVersion(), $potentialVulnerability->getRelease()) < 0) { array_push($confirmedVulnerabilities, $potentialVulnerability); } } } //For each confirmed Vulnerability get CveDefs if (!empty($confirmedVulnerabilities)) { $cveDefs = array(); foreach ($confirmedVulnerabilities as $confirmedVulnerability) { # Assign the Cvedef to the Package $this->getPakiti()->getManager("CveDefsManager")->assignPkgToCveDef($installedPkg->getId(), $this->getPakiti()->getDao("CveDef")->getCveDefForVulnerability($confirmedVulnerability)->getId(), $osGroup->getId()); } } } } }
public function delete(Host &$host) { if ($host == null || $host->getId() == -1) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host object is not valid or Host.id is not set"); } $this->db->query("delete from Host where id=" . $host->getId()); Utils::log(LOG_DEBUG, "Host deleted", __FILE__, __LINE__); }
public function removeHostFromHostGroups(Host &$host) { if ($host == null || $host->getId() == -1) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host object is not valid or Host.id is not set"); } Utils::log(LOG_DEBUG, "Removing the host from all host groups [host=" . $host->getHostname() . "]", __FILE__, __LINE__); $this->getPakiti()->getDao("HostGroup")->removeHostFromHostGroups($host->getId()); }
public function getInstalledPkgsCount(Host &$host) { $sql = "select count(*) from InstalledPkg where hostId={$host->getId()}"; return $this->db->queryToSingleValue($sql); }
public function removeHostTags(Host &$host) { if ($host == null || $host->getId() == -1) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host object is not valid or Host.id is not set"); } Utils::log(LOG_DEBUG, "Removing all tags associated with the host [hostname='{$host->getHostname()}']", __FILE__, __LINE__); $this->getPakiti()->getDao("Tag")->deleteTagsByHostId($host->getId()); }
public function setLastReportId(Host &$host, Report &$report) { if ($host == null || $host->getId() == -1 || $report == null || $report->getId() == -1) { Utils::log(LOG_DEBUG, "Exception", __FILE__, __LINE__); throw new Exception("Host or Report pobject is not valid or Host.id or Report.id is not set"); } return $this->getPakiti()->getDao("Host")->setLastReportId($host->getId(), $report->getId()); }
/** * removePossibleHost * remove o host enviado como um dos possiveis hosts a ser alocado em * @param Host $host */ function removePossibleHost(&$host) { unset($this->possibleHost[$host->getId()]); }