/** * @param VulnerableElement $element * @return string */ public function renderVulnerabilityTree(VulnerableElement $element) { $vulnerabilities = []; $childrenVulns = ''; $conditions = []; if ($element->hasChildren()) { $childrenHtml = []; foreach ($element->getChildrenArray() as $child) { $childrenHtml[] = $this->renderVulnerabilityTree($child); } $childrenVulns = implode('', $childrenHtml); } if ($element instanceof ConditionalVulnerableElement) { /** @var ICondition $condition */ foreach ($element->getConditions()->getConditions() as $condition) { $conditions[$condition->getName()] = $condition->toArray(); } } /** @var Vulnerability $vuln */ foreach ($element->getVulnerabilitySet()->getVulnerabilities() as $vuln) { $vulnerabilities[$vuln->getName()] = $vuln->asArray(); } sort($vulnerabilities); $vulnNames = VulnerabilityFactory::instance()->getAllVulnerabilityNames(); $computedVulnerabilities = []; /** @var Vulnerability $vuln */ foreach ($vulnNames as $vulnName) { $computedVulnerabilities[] = $element->getComputedVulnerability($vulnName)->asArray(); } $view = $this->pixie->view('admin/context/vuln_element'); $view->vulnerabilities = $vulnerabilities; $view->computedVulnerabilities = $computedVulnerabilities; $view->childrenVulns = $childrenVulns; $view->conditionList = $conditions; return $view->render(); }
/** * @param VulnerableElement $element * @return string */ public function vulnerabilityTreeAsArray(VulnerableElement $element) { $result = []; $vulnerabilities = []; $children = []; $conditions = []; if ($element->hasChildren()) { $childrenArr = []; foreach ($element->getChildrenArray() as $child) { $childrenArr[] = $this->vulnerabilityTreeAsArray($child); } $children = $childrenArr; } if ($element instanceof ConditionalVulnerableElement) { /** @var ICondition $condition */ foreach ($element->getConditions()->getConditions() as $condition) { $conditions[$condition->getName()] = $condition->toArray(); } } /** @var Vulnerability $vuln */ foreach ($element->getVulnerabilitySet()->getVulnerabilities() as $vuln) { $vulnerabilities[$vuln->getName()] = $vuln->asArray(); unset($vulnerabilities[$vuln->getName()]['name']); } ksort($vulnerabilities); if ($element->getName()) { $result['name'] = $element->getName(); } if (count($conditions)) { $result['conditions'] = $conditions; } if (count($vulnerabilities)) { $result['vuln_list'] = $vulnerabilities; } if (count($children)) { $result['children'] = $children; } return $result; }