Ejemplo n.º 1
0
 /**
  * @param string[][][] &$filesWithLicenses
  * @param ItemTreeBounds $itemTreeBounds
  */
 protected function addScannerResults(&$filesWithLicenses, ItemTreeBounds $itemTreeBounds)
 {
     $uploadId = $itemTreeBounds->getUploadId();
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->container->get('dao.agent'), $uploadId);
     $scanJobProxy->createAgentStatus($scannerAgents);
     $scannerIds = $scanJobProxy->getLatestSuccessfulAgentIds();
     if (empty($scannerIds)) {
         return;
     }
     $selectedScanners = '{' . implode(',', $scannerIds) . '}';
     $tableName = $itemTreeBounds->getUploadTreeTableName();
     $stmt = __METHOD__ . '.scanner_findings';
     $sql = "SELECT DISTINCT uploadtree_pk,rf_fk FROM {$tableName} ut, license_file\n      WHERE ut.pfile_fk=license_file.pfile_fk AND rf_fk IS NOT NULL AND agent_fk=any(\$1)";
     $param = array($selectedScanners);
     if ($tableName == 'uploadtree_a') {
         $param[] = $uploadId;
         $sql .= " AND upload_fk=\$" . count($param);
         $stmt .= $tableName;
     }
     $sql .= " GROUP BY uploadtree_pk,rf_fk";
     $this->dbManager->prepare($stmt, $sql);
     $res = $this->dbManager->execute($stmt, $param);
     while ($row = $this->dbManager->fetchArray($res)) {
         $reportedLicenseId = $this->licenseMap->getProjectedId($row['rf_fk']);
         $shortName = $this->licenseMap->getProjectedShortname($reportedLicenseId);
         if ($shortName != 'No_license_found' && $shortName != 'Void') {
             $filesWithLicenses[$row['uploadtree_pk']]['scanner'][] = $shortName;
             $this->includedLicenseIds[$reportedLicenseId] = true;
         }
     }
     $this->dbManager->freeResult($res);
     return "licenseInfoInFile determined by Scanners {$selectedScanners}";
 }
 /**
  * @param ItemTreeBounds $itemTreeBounds
  * @param int $groupId
  * @param int[] $additionalEventIds additional event ids to include, indexed by licenseId
  * @param null|LicenseMap $licenseMap if given then license are considered as equal iff mapped to same
  * @return bool
  */
 public function hasUnhandledScannerDetectedLicenses(ItemTreeBounds $itemTreeBounds, $groupId, $additionalEventIds = array(), $licenseMap = null)
 {
     if (!empty($licenseMap) && !$licenseMap instanceof LicenseMap) {
         throw new Exception('invalid license map');
     }
     $userEvents = $this->clearingDao->getRelevantClearingEvents($itemTreeBounds, $groupId);
     $usageId = empty($licenseMap) ? LicenseMap::TRIVIAL : $licenseMap->getUsage();
     $scannerDetectedEvents = $this->agentLicenseEventProcessor->getScannerEvents($itemTreeBounds, $usageId);
     $eventLicenceIds = array();
     foreach (array_keys($userEvents) as $licenseId) {
         $eventLicenceIds[empty($licenseMap) ? $licenseId : $licenseMap->getProjectedId($licenseId)] = $licenseId;
     }
     foreach (array_keys($additionalEventIds) as $licenseId) {
         $eventLicenceIds[empty($licenseMap) ? $licenseId : $licenseMap->getProjectedId($licenseId)] = $licenseId;
     }
     foreach (array_keys($scannerDetectedEvents) as $licenseId) {
         if (!array_key_exists(empty($licenseMap) ? $licenseId : $licenseMap->getProjectedId($licenseId), $eventLicenceIds)) {
             return true;
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 protected function remapByProjectedId($matches)
 {
     $remapped = array();
     foreach ($matches as $licenseId => $licenseMatches) {
         $projectedId = $this->licenseMap->getProjectedId($licenseId);
         foreach ($licenseMatches as $agent => $agentMatches) {
             $haveId = array_key_exists($projectedId, $remapped);
             $haveAgent = $haveId && array_key_exists($agent, $remapped[$projectedId]);
             if ($haveAgent) {
                 $remapped[$projectedId][$agent] = array_merge($remapped[$projectedId][$agent], $agentMatches);
             } else {
                 $remapped[$projectedId][$agent] = $agentMatches;
             }
         }
     }
     return $remapped;
 }
Ejemplo n.º 4
0
 protected function getStatements($uploadId, $uploadTreeTableName, $groupId = null)
 {
     $itemTreeBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
     $clearingDecisions = $this->clearingDao->getFileClearingsFolder($itemTreeBounds, $groupId);
     $dbManager = $GLOBALS['container']->get('db.manager');
     $licenseMap = new LicenseMap($dbManager, $groupId, LicenseMap::REPORT);
     $mainLicIds = $this->clearingDao->getMainLicenseIds($uploadId, $groupId);
     $ungroupedStatements = array();
     foreach ($clearingDecisions as $clearingDecision) {
         if ($clearingDecision->getType() == DecisionTypes::IRRELEVANT) {
             continue;
         }
         /** @var ClearingDecision $clearingDecision */
         foreach ($clearingDecision->getClearingLicenses() as $clearingLicense) {
             if ($clearingLicense->isRemoved()) {
                 continue;
             }
             if ($this->onlyComments && !($comment = $clearingLicense->getComment())) {
                 continue;
             }
             $originLicenseId = $clearingLicense->getLicenseId();
             $licenseId = $licenseMap->getProjectedId($originLicenseId);
             if (!$this->onlyComments && in_array($licenseId, $mainLicIds)) {
                 continue;
             }
             if ($this->onlyComments) {
                 $text = $comment;
             } else {
                 $reportInfo = $clearingLicense->getReportInfo();
                 $text = $reportInfo ?: $this->getCachedLicenseText($licenseId, $groupId);
             }
             $ungroupedStatements[] = array('content' => $licenseMap->getProjectedShortname($originLicenseId, $clearingLicense->getShortName()), 'uploadtree_pk' => $clearingDecision->getUploadTreeId(), 'text' => $text);
         }
     }
     return $ungroupedStatements;
 }
Ejemplo n.º 5
0
 /**
  * \brief Update the database
  *
  * \return An update status string
  */
 function Updatedb()
 {
     $rfId = intval($_POST['rf_pk']);
     $shortname = trim($_POST['rf_shortname']);
     $fullname = trim($_POST['rf_fullname']);
     $url = $_POST['rf_url'];
     $notes = $_POST['rf_notes'];
     $text = trim($_POST['rf_text']);
     $parent = $_POST['rf_parent'];
     $report = $_POST['rf_report'];
     $riskLvl = intval($_POST['risk_level']);
     if (empty($shortname)) {
         $text = _("ERROR: The license shortname is empty.");
         return "<b>{$text}</b><p>";
     }
     if ($this->isShortnameBlocked($rfId, $shortname, $text)) {
         $text = _("ERROR: The shortname or license text already exist in the license list.  License not added.");
         return "<b>{$text}</b><p>";
     }
     $md5term = empty($text) || stristr($text, "License by Nomos") ? 'null' : 'md5($10)';
     $sql = "UPDATE license_ref SET\n        rf_active=\$2, marydone=\$3,  rf_shortname=\$4, rf_fullname=\$5,\n        rf_url=\$6,  rf_notes=\$7,  rf_text_updatable=\$8,   rf_detector_type=\$9,  rf_text=\$10,\n        rf_md5={$md5term},\n        rf_risk=\$11\n          WHERE rf_pk=\$1";
     $params = array($rfId, $_POST['rf_active'], $_POST['marydone'], $shortname, $fullname, $url, $notes, $_POST['rf_text_updatable'], $_POST['rf_detector_type'], $text, $riskLvl);
     $this->dbManager->prepare($stmt = __METHOD__ . ".{$md5term}", $sql);
     $this->dbManager->freeResult($this->dbManager->execute($stmt, $params));
     $parentMap = new LicenseMap($this->dbManager, 0, LicenseMap::CONCLUSION);
     $parentLicenses = $parentMap->getTopLevelLicenseRefs();
     if (array_key_exists($parent, $parentLicenses) && $parent != $parentMap->getProjectedId($rfId)) {
         $stmtDel = __METHOD__ . '.deleteFromMap';
         $this->dbManager->prepare($stmtDel, 'DELETE FROM license_map WHERE rf_fk=$1 AND usage=$2');
         $this->dbManager->execute($stmtDel, array($rfId, LicenseMap::CONCLUSION));
         $this->dbManager->insertTableRow('license_map', array('rf_fk' => $rfId, 'rf_parent' => $parent, 'usage' => LicenseMap::CONCLUSION));
     }
     $reportMap = new LicenseMap($this->dbManager, 0, LicenseMap::REPORT);
     $reportLicenses = $parentMap->getTopLevelLicenseRefs();
     if (array_key_exists($report, $reportLicenses) && $report != $reportMap->getProjectedId($rfId)) {
         $stmtDel = __METHOD__ . '.deleteFromMap';
         $this->dbManager->prepare($stmtDel, 'DELETE FROM license_map WHERE rf_fk=$1 AND usage=$2');
         $this->dbManager->execute($stmtDel, array($rfId, LicenseMap::REPORT));
         $this->dbManager->insertTableRow('license_map', array('rf_fk' => $rfId, 'rf_parent' => $report, 'usage' => LicenseMap::REPORT));
     }
     $ob = "License {$_POST['rf_shortname']} updated.<p>";
     return $ob;
 }
Ejemplo n.º 6
0
 function testProjectedIdOfMappedIdIsIdItselfIfTrivialMap()
 {
     $licenseMap = new LicenseMap($this->dbManager, $this->groupId, LicenseMap::TRIVIAL);
     assertThat($licenseMap->getProjectedId(2), is(2));
 }
Ejemplo n.º 7
0
 /**
  * @param array $child
  * @param int $uploadId
  * @param int $selectedAgentId
  * @param array $pfileLicenses
  * @param int $groupId
  * @param ClearingDecision[][] $editedMappedLicenses
  * @param string $uri
  * @param null|ClearingView $ModLicView
  * @param array $UniqueTagArray
  * @param boolean $isFlat
  * @param int[] $latestSuccessfulAgentIds
  * @return array
  */
 private function createFileDataRow($child, $uploadId, $selectedAgentId, $pfileLicenses, $groupId, $editedMappedLicenses, $uri, $ModLicView, &$UniqueTagArray, $isFlat, $latestSuccessfulAgentIds)
 {
     $fileId = $child['pfile_fk'];
     $childUploadTreeId = $child['uploadtree_pk'];
     $linkUri = '';
     if (!empty($fileId) && !empty($ModLicView)) {
         $linkUri = Traceback_uri();
         $linkUri .= "?mod=view-license&upload={$uploadId}&item={$childUploadTreeId}";
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
     }
     /* Determine link for containers */
     $isContainer = Iscontainer($child['ufile_mode']);
     if ($isContainer && !$isFlat) {
         $fatChild = $this->uploadDao->getFatItemArray($child['uploadtree_pk'], $uploadId, $this->uploadtree_tablename);
         $uploadtree_pk = $fatChild['item_id'];
         $linkUri = "{$uri}&item=" . $uploadtree_pk;
         if ($selectedAgentId) {
             $linkUri .= "&agentId={$selectedAgentId}";
         }
         $child['ufile_name'] = $fatChild['ufile_name'];
         if (!Iscontainer($fatChild['ufile_mode'])) {
             $isContainer = false;
         }
     } else {
         if ($isContainer) {
             $uploadtree_pk = Isartifact($child['ufile_mode']) ? DirGetNonArtifact($childUploadTreeId, $this->uploadtree_tablename) : $childUploadTreeId;
             $linkUri = "{$uri}&item=" . $uploadtree_pk;
             if ($selectedAgentId) {
                 $linkUri .= "&agentId={$selectedAgentId}";
             }
         }
     }
     /* Populate the output ($VF) - file list */
     /* id of each element is its uploadtree_pk */
     $fileName = $child['ufile_name'];
     if ($isContainer) {
         $fileName = "<a href='{$linkUri}'><span style='color: darkblue'> <b>{$fileName}</b> </span></a>";
     } else {
         if (!empty($linkUri)) {
             $fileName = "<a href='{$linkUri}'>{$fileName}</a>";
         }
     }
     /* show licenses under file name */
     $childItemTreeBounds = new ItemTreeBounds($childUploadTreeId, $this->uploadtree_tablename, $child['upload_fk'], $child['lft'], $child['rgt']);
     if ($isContainer) {
         $agentFilter = $selectedAgentId ? array($selectedAgentId) : $latestSuccessfulAgentIds;
         $licenseEntries = $this->licenseDao->getLicenseShortnamesContained($childItemTreeBounds, $agentFilter, array());
         $editedLicenses = $this->clearingDao->getClearedLicenses($childItemTreeBounds, $groupId);
     } else {
         $licenseEntries = array();
         if (array_key_exists($fileId, $pfileLicenses)) {
             foreach ($pfileLicenses[$fileId] as $shortName => $rfInfo) {
                 $agentEntries = array();
                 foreach ($rfInfo as $agent => $match) {
                     $agentName = $this->agentNames[$agent];
                     $agentEntry = "<a href='?mod=view-license&upload={$child['upload_fk']}&item={$childUploadTreeId}&format=text&agentId={$match['agent_id']}&licenseId={$match['license_id']}#highlight'>" . $agentName . "</a>";
                     if ($match['match_percentage'] > 0) {
                         $agentEntry .= ": {$match['match_percentage']}%";
                     }
                     $agentEntries[] = $agentEntry;
                 }
                 $licenseEntries[] = $shortName . " [" . implode("][", $agentEntries) . "]";
             }
         }
         /* @var $decision ClearingDecision */
         if (false !== ($decision = $this->clearingFilter->getDecisionOf($editedMappedLicenses, $childUploadTreeId, $fileId))) {
             $editedLicenses = $decision->getPositiveLicenses();
         } else {
             $editedLicenses = array();
         }
     }
     $concludedLicenses = array();
     /** @var LicenseRef $licenseRef */
     foreach ($editedLicenses as $licenseRef) {
         $projectedId = $this->licenseProjector->getProjectedId($licenseRef->getId());
         $projectedName = $this->licenseProjector->getProjectedShortname($licenseRef->getId(), $licenseRef->getShortName());
         $concludedLicenses[$projectedId] = $projectedName;
     }
     $editedLicenseList = implode(', ', $concludedLicenses);
     $licenseList = implode(', ', $licenseEntries);
     $fileListLinks = FileListLinks($uploadId, $childUploadTreeId, 0, $fileId, true, $UniqueTagArray, $this->uploadtree_tablename, !$isFlat);
     $getTextEditUser = _("Edit");
     $fileListLinks .= "[<a href='#' onclick='openUserModal({$childUploadTreeId})' >{$getTextEditUser}</a>]";
     if ($isContainer) {
         $getTextEditBulk = _("Bulk");
         $fileListLinks .= "[<a href='#' onclick='openBulkModal({$childUploadTreeId})' >{$getTextEditBulk}</a>]";
     }
     $filesThatShouldStillBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesThatShouldStillBeCleared) ? $this->filesThatShouldStillBeCleared[$childItemTreeBounds->getItemId()] : 0;
     $filesToBeCleared = array_key_exists($childItemTreeBounds->getItemId(), $this->filesToBeCleared) ? $this->filesToBeCleared[$childItemTreeBounds->getItemId()] : 0;
     $filesCleared = $filesToBeCleared - $filesThatShouldStillBeCleared;
     $img = $filesCleared == $filesToBeCleared ? 'green' : 'red';
     return array($fileName, $licenseList, $editedLicenseList, $img, "{$filesCleared}/{$filesToBeCleared}", $fileListLinks);
 }