40 use Symfony\Component\HttpFoundation\File\UploadedFile;
115 $newUpload =
false, $apiVersion = ApiVersion::V1)
117 $parametersSent =
false;
120 if (array_key_exists(
"analysis", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"analysis"])) {
121 $analysis->setUsingArray($scanOptionsJSON[
"analysis"], $apiVersion);
122 $parametersSent =
true;
126 if (array_key_exists(
"decider", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"decider"])) {
127 $decider->setUsingArray($scanOptionsJSON[
"decider"], $apiVersion);
128 $parametersSent =
true;
132 if (array_key_exists(
"scancode", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"scancode"])) {
133 $scancode->setUsingArray($scanOptionsJSON[
"scancode"]);
134 $parametersSent =
true;
137 $reuser =
new Reuser(0,
'groupName',
false,
false);
139 if (array_key_exists(
"reuse", $scanOptionsJSON) && ! empty($scanOptionsJSON[
"reuse"])) {
140 $reuser->setUsingArray($scanOptionsJSON[
"reuse"], $apiVersion);
141 $parametersSent =
true;
143 }
catch (\UnexpectedValueException $e) {
147 if (! $parametersSent) {
151 $scanOptions =
new ScanOptions($analysis, $reuser, $decider, $scancode);
152 return $scanOptions->scheduleAgents($folderId, $uploadId, $newUpload);
172 $isPublic, $ignoreScm, $uploadType,
173 $applyGlobal =
false)
175 $symReq = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
176 $uploadedFile = $symReq->files->get($this->uploadFilePage::FILE_INPUT_NAME,
186 if (! empty($ignoreScm) && ($ignoreScm ==
"true")) {
192 if (empty($uploadedFile)) {
193 if (empty($uploadType)) {
194 return array(
false,
"Missing 'uploadType' header",
195 "Send file with parameter " . $this->uploadFilePage::FILE_INPUT_NAME .
196 " or define 'uploadType' header with appropriate body.",
200 return $this->
handleUpload($reqBody, $uploadType, $folderId,
201 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
204 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
220 $isPublic, $ignoreScm = 0, $applyGlobal = 0)
222 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
223 $symfonySession = $GLOBALS[
'container']->get(
'session');
224 $symfonySession->set(
225 $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
227 $symfonyRequest->request->set($this->uploadFilePage::FOLDER_PARAMETER_NAME,
229 $symfonyRequest->request->set(
230 $this->uploadFilePage::DESCRIPTION_INPUT_NAME,
232 $symfonyRequest->files->set($this->uploadFilePage::FILE_INPUT_NAME,
234 $symfonyRequest->setSession($symfonySession);
235 $symfonyRequest->request->set(
236 $this->uploadFilePage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
237 $symfonyRequest->request->set(
'public', $isPublic);
238 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
239 $symfonyRequest->request->set(
'scm', $ignoreScm);
241 return $this->uploadFilePage->handleRequest($symfonyRequest);
256 private function handleUpload($body, $uploadType, $folderId, $fileDescription,
257 $isPublic, $ignoreScm = 0, $applyGlobal = 0)
260 switch ($uploadType) {
271 $message =
"Invalid 'uploadType'";
272 $statusDescription =
"uploadType should be any of (" .
273 implode(
",", self::VALID_UPLOAD_TYPES) .
")";
275 $sanity = array(
false, $message, $statusDescription, $code);
277 if ($sanity !==
true) {
280 $uploadResponse =
false;
281 switch ($uploadType) {
284 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
288 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
292 $fileDescription, $isPublic, $ignoreScm, $applyGlobal);
295 return $uploadResponse;
311 $statusDescription =
"";
314 if (! array_key_exists(
"vcsType", $vcsData) ||
315 ! in_array($vcsData[
"vcsType"], self::VALID_VCS_TYPES)) {
316 $message =
"Missing vcsType";
317 $statusDescription =
"vcsType should be any of (" .
318 implode(
", ", self::VALID_VCS_TYPES) .
")";
322 if ($vcsData[
"vcsType"] ==
"git") {
328 if (! array_key_exists(
"vcsUrl", $vcsData)) {
329 $message =
"Missing vcsUrl";
330 $statusDescription =
"vcsUrl should be passed.";
334 if (! array_key_exists(
"vcsName", $vcsData)) {
335 $vcsData[
"vcsName"] =
"";
337 if (! array_key_exists(
"vcsUsername", $vcsData)) {
338 $vcsData[
"vcsUsername"] =
"";
340 if (! array_key_exists(
"vcsPassword", $vcsData)) {
341 $vcsData[
"vcsPassword"] =
"";
343 if (! array_key_exists(
"vcsBranch", $vcsData)) {
344 $vcsData[
"vcsBranch"] =
"";
346 $vcsData[
"vcsType"] = $vcsType;
348 return array(
false, $message, $statusDescription, $code);
366 $statusDescription =
"";
369 if (! array_key_exists(
"url", $urlData)) {
370 $message =
"Missing url";
371 $statusDescription =
"Missing upload url from request";
375 if (! array_key_exists(
"name", $urlData)) {
376 $urlData[
"name"] =
"";
378 if (! array_key_exists(
"accept", $urlData)) {
379 $urlData[
"accept"] =
"";
381 if (! array_key_exists(
"reject", $urlData)) {
382 $urlData[
"reject"] =
"";
384 if (! array_key_exists(
"maxRecursionDepth", $urlData)) {
385 $urlData[
"maxRecursionDepth"] =
"";
388 return array(
false, $message, $statusDescription, $code);
406 $statusDescription =
"";
409 if (! array_key_exists(
"path", $srvData)) {
410 $message =
"Missing path";
411 $statusDescription =
"Missing upload path from request";
415 if (! array_key_exists(
"name", $srvData)) {
416 $srvData[
"name"] =
"";
419 return array(
false, $message, $statusDescription, $code);
436 $isPublic, $ignoreScm, $applyGlobal)
438 $vcsType = $vcsData[
"vcsType"];
439 $vcsUrl = $vcsData[
"vcsUrl"];
440 $vcsName = $vcsData[
"vcsName"];
441 $vcsUsername = $vcsData[
"vcsUsername"];
442 $vcsPasswd = $vcsData[
"vcsPassword"];
443 $vcsBranch = $vcsData[
"vcsBranch"];
445 $symfonySession = $GLOBALS[
'container']->get(
'session');
446 $symfonySession->set($this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
449 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
450 $symfonyRequest->setSession($symfonySession);
452 $symfonyRequest->request->set($this->uploadVcsPage::FOLDER_PARAMETER_NAME,
454 $symfonyRequest->request->set($this->uploadVcsPage::DESCRIPTION_INPUT_NAME,
456 $symfonyRequest->request->set($this->uploadVcsPage::GETURL_PARAM, $vcsUrl);
457 $symfonyRequest->request->set(
458 $this->uploadVcsPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
459 $symfonyRequest->request->set(
'public', $isPublic);
460 $symfonyRequest->request->set(
'name', $vcsName);
461 $symfonyRequest->request->set(
'vcstype', $vcsType);
462 $symfonyRequest->request->set(
'username', $vcsUsername);
463 $symfonyRequest->request->set(
'passwd', $vcsPasswd);
464 $symfonyRequest->request->set(
'branch', $vcsBranch);
465 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
466 $symfonyRequest->request->set(
'scm', $ignoreScm);
468 return $this->uploadVcsPage->handleRequest($symfonyRequest);
482 $isPublic, $ignoreScm, $applyGlobal)
484 $url = $urlData[
"url"];
485 $name = $urlData[
"name"];
486 $accept = $urlData[
"accept"];
487 $reject = $urlData[
"reject"];
488 $maxRecursionDepth = $urlData[
"maxRecursionDepth"];
490 $symfonySession = $GLOBALS[
'container']->get(
'session');
491 $symfonySession->set($this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
494 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
495 $symfonyRequest->setSession($symfonySession);
497 $symfonyRequest->request->set($this->uploadUrlPage::FOLDER_PARAMETER_NAME,
499 $symfonyRequest->request->set($this->uploadUrlPage::DESCRIPTION_INPUT_NAME,
501 $symfonyRequest->request->set(
502 $this->uploadUrlPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
503 $symfonyRequest->request->set(
'public', $isPublic);
504 $symfonyRequest->request->set($this->uploadUrlPage::NAME_PARAM, $name);
505 $symfonyRequest->request->set($this->uploadUrlPage::ACCEPT_PARAM, $accept);
506 $symfonyRequest->request->set($this->uploadUrlPage::REJECT_PARAM, $reject);
507 $symfonyRequest->request->set($this->uploadUrlPage::GETURL_PARAM, $url);
508 $symfonyRequest->request->set($this->uploadUrlPage::LEVEL_PARAM,
510 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
511 $symfonyRequest->request->set(
'scm', $ignoreScm);
513 return $this->uploadUrlPage->handleRequest($symfonyRequest);
527 $isPublic, $ignoreScm, $applyGlobal)
529 $path = $srvData[
"path"];
530 $name = $srvData[
"name"];
532 $symfonySession = $GLOBALS[
'container']->get(
'session');
533 $symfonySession->set($this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
536 $symfonyRequest = new \Symfony\Component\HttpFoundation\Request();
537 $symfonyRequest->setSession($symfonySession);
539 $symfonyRequest->request->set($this->uploadSrvPage::FOLDER_PARAMETER_NAME,
541 $symfonyRequest->request->set($this->uploadSrvPage::DESCRIPTION_INPUT_NAME,
543 $symfonyRequest->request->set(
544 $this->uploadSrvPage::UPLOAD_FORM_BUILD_PARAMETER_NAME,
"restUpload");
545 $symfonyRequest->request->set(
'public', $isPublic);
546 $symfonyRequest->request->set($this->uploadSrvPage::SOURCE_FILES_FIELD,
548 $symfonyRequest->request->set($this->uploadSrvPage::NAME_PARAM, $name);
549 $symfonyRequest->request->set(
'globalDecisions', $applyGlobal);
550 $symfonyRequest->request->set(
'scm', $ignoreScm);
552 return $this->uploadSrvPage->handleRequest($symfonyRequest);
561 public function generateUploadSummary($uploadId, $groupId)
564 $restHelper = $container->get(
'helper.restHelper');
565 $uploadDao = $restHelper->getUploadDao();
566 $dbManager = $restHelper->getDbHelper()->getDbManager();
567 $copyrightDao = $container->get(
'dao.copyright');
568 $agentDao = $container->get(
'dao.agent');
570 $agentName =
"copyright";
571 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
574 array(UploadTreeProxy::OPT_SKIP_THESE =>
"noLicense",
575 UploadTreeProxy::OPT_GROUP_ID => $groupId),
576 $uploadTreeTableName,
577 'no_license_uploadtree' . $uploadId);
578 $clearingCount = $noLicenseUploadTreeView->count();
581 array(UploadTreeProxy::OPT_SKIP_THESE =>
"alreadyCleared",
582 UploadTreeProxy::OPT_GROUP_ID => $groupId),
583 $uploadTreeTableName,
584 'already_cleared_uploadtree' . $uploadId);
585 $filesToBeCleared = $nonClearedUploadTreeView->count();
587 $itemTreeBounds = $uploadDao->getParentItemBounds($uploadId,
588 $uploadTreeTableName);
590 $scanProx->createAgentStatus([$agentName]);
591 $agents = $scanProx->getLatestSuccessfulAgentIds();
593 if (array_key_exists($agentName, $agents) && ! empty($agents[$agentName])) {
594 $copyrightCount = count(
595 $copyrightDao->getAllEntriesReport($agentName, $uploadId,
596 $uploadTreeTableName,
null,
false,
null,
"C.agent_fk = " .
597 $agents[$agentName], $groupId));
600 $mainLicenses = $this->
getMainLicenses($dbManager, $uploadId, $groupId);
603 $uiLicense = $restHelper->getPlugin(
"license");
604 $hist = $uiLicense->getUploadHist($itemTreeBounds);
605 if (!is_array($hist) || !array_key_exists(
'uniqueLicenseCount', $hist)) {
607 $hist[
'uniqueLicenseCount'] = 0;
608 $hist[
'scannerLicenseCount'] = 0;
609 $hist[
'editedUniqueLicenseCount'] = 0;
610 $hist[
'editedLicenseCount'] = 0;
613 $summary =
new UploadSummary();
614 $summary->setUploadId($uploadId);
615 $summary->setUploadName($uploadDao->getUpload($uploadId)->getFilename());
616 $summary->setAssignee($uploadDao->getAssignee($uploadId, $groupId));
617 if ($mainLicenses !==
null) {
618 $summary->setMainLicense(implode(
",", $mainLicenses));
620 $summary->setUniqueLicenses($hist[
'uniqueLicenseCount']);
621 $summary->setTotalLicenses($hist[
'scannerLicenseCount']);
622 $summary->setUniqueConcludedLicenses($hist[
'editedUniqueLicenseCount']);
623 $summary->setTotalConcludedLicenses($hist[
'editedLicenseCount']);
624 $summary->setFilesToBeCleared($filesToBeCleared);
625 $summary->setFilesCleared($clearingCount);
626 $summary->setClearingStatus($uploadDao->getStatus($uploadId, $groupId));
627 $summary->setCopyrightCount($copyrightCount);
640 $sql =
"SELECT rf_shortname FROM license_ref lf JOIN upload_clearing_license ucl"
641 .
" ON lf.rf_pk=ucl.rf_fk WHERE upload_fk=$1 AND ucl.group_fk=$2";
642 $stmt = __METHOD__.
'.collectMainLicenses';
643 $rows = $dbManager->getRows($sql, array($uploadId, $groupId), $stmt);
648 foreach ($rows as $row) {
649 $mainLicenses[] = $row[
'rf_shortname'];
651 return $mainLicenses;
660 public function getUploadCopyrightList($uploadId)
663 $restHelper = $container->get(
'helper.restHelper');
664 $uploadDao = $restHelper->getUploadDao();
666 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
667 $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
672 $copyrightListObj = $restHelper->getPlugin(
'export-list');
673 $copyrightList = $copyrightListObj->getCopyrights($uploadId,
674 $parent->getItemId(), $uploadTreeTableName, -1,
'');
675 if (array_key_exists(
"warn", $copyrightList)) {
676 unset($copyrightList[
"warn"]);
679 $responseList = array();
680 foreach ($copyrightList as $copyFilepath) {
682 foreach ($responseList as $response) {
683 if ($copyFilepath[
'content'] == $response[
'copyright']) {
689 $copyrightContent = array();
690 foreach ($copyrightList as $copy) {
691 if (strcasecmp($copyFilepath[
'content'], $copy[
'content']) == 0) {
692 $copyrightContent[] = $copy[
'filePath'];
695 $responseRow = array();
696 $responseRow[
'copyright'] = $copyFilepath[
'content'];
697 $responseRow[
'filePath'] = $copyrightContent;
698 $responseList[] = $responseRow;
701 return $responseList;
715 if ($itemTreeBounds !==
null) {
716 $clearingList = $clearingDao->getFileClearings($itemTreeBounds, $groupId);
722 foreach ($clearingList as $clearingDecision) {
723 $clearingArray[] = $clearingDecision->getType();
726 if (empty($clearingArray) || $clearingArray[0] ===
null) {
727 return "NOASSERTION";
743 public function getUploadLicenseList($uploadId, $agents, $printContainers, $boolLicense, $boolCopyright, $page = 0, $limit = 50, $apiVersion=ApiVersion::V1)
746 $restHelper = $container->get(
'helper.restHelper');
747 $uploadDao = $restHelper->getUploadDao();
748 $agentDao = $container->get(
'dao.agent');
749 $uploadTreeTableName = $uploadDao->getUploadtreeTableName($uploadId);
750 $parent = $uploadDao->getParentItemBounds($uploadId, $uploadTreeTableName);
751 $groupId = $restHelper->getGroupId();
753 $scanProx->createAgentStatus($agents);
754 $agent_ids = $scanProx->getLatestSuccessfulAgentIds();
755 $clearingDao = $container->get(
"dao.clearing");
761 $licenseListObj = $restHelper->getPlugin(
'export-list');
762 $licenseList = $licenseListObj->createListOfLines($uploadTreeTableName,
763 $parent->getItemId(), $agent_ids, -1,
true,
'', !$printContainers);
764 if (array_key_exists(
"warn", $licenseList)) {
765 unset($licenseList[
"warn"]);
772 if ($boolCopyright) {
773 $copyrightListObj = $restHelper->getPlugin(
'export-list');
774 $copyrightList = $copyrightListObj->getCopyrights($uploadId,
775 $parent->getItemId(), $uploadTreeTableName, -1,
'');
776 if (array_key_exists(
"warn", $copyrightList)) {
777 unset($copyrightList[
"warn"]);
781 $responseList = array();
784 foreach ($licenseList as $license) {
785 $copyrightContent =
null;
786 if ($boolCopyright) {
787 $copyrightContent = [];
788 foreach ($copyrightList as $copy) {
789 if (($license[
'filePath'] == $copy[
'filePath']) !==
false ) {
790 $copyrightContent[] = $copy[
'content'];
793 if (count($copyrightContent)==0) {
794 $copyrightContent =
null;
798 $findings =
new Findings($license[
'agentFindings'],
799 $license[
'conclusions'], $copyrightContent);
800 $uploadTreeTableId = $license[
'uploadtree_pk'];
801 $uploadtree_tablename = $uploadDao->getUploadtreeTableName($uploadId);
802 if ($uploadTreeTableId!==
null) {
803 $itemTreeBounds = $uploadDao->getItemTreeBounds($uploadTreeTableId,$uploadtree_tablename);
805 $itemTreeBounds=
null;
808 $clearingDao, $groupId);
809 $responseRow =
new FileLicenses($license[
'filePath'], $findings,
811 $responseList[] = $responseRow->getArray($apiVersion);
813 } elseif (!$boolLicense && $boolCopyright) {
814 foreach ($copyrightList as $copyFilepath) {
815 $copyrightContent = array();
816 foreach ($copyrightList as $copy) {
817 if (($copyFilepath[
'filePath'] == $copy[
'filePath']) ===
true) {
818 $copyrightContent[] = $copy[
'content'];
821 $findings =
new Findings();
822 $findings->setCopyright($copyrightContent);
823 $responseRow =
new FileLicenses($copyFilepath[
'filePath'], $findings);
824 $responseList[] = $responseRow->getArray($apiVersion);
827 $offset = $page * $limit;
828 $paginatedResponseList = array_slice($responseList, $offset, $limit);
829 $paginatedResponseListSize =
sizeof($responseList);
830 return array($paginatedResponseList, $paginatedResponseListSize);
Handle new file uploads from Slim framework and move to FOSSology.
handleScheduleAnalysis($uploadId, $folderId, $scanOptionsJSON, $newUpload=false, $apiVersion=ApiVersion::V1)
sanitizeUrlData(&$urlData)
Check if the passed URL object is correct or not.
generateUrlUpload($urlData, $folderName, $fileDescription, $isPublic, $ignoreScm, $applyGlobal)
getMainLicenses($dbManager, $uploadId, $groupId)
createNewUpload($reqBody, $folderId, $fileDescription, $isPublic, $ignoreScm, $uploadType, $applyGlobal=false)
generateVcsUpload($vcsData, $folderId, $fileDescription, $isPublic, $ignoreScm, $applyGlobal)
fetchClearingStatus($itemTreeBounds, $clearingDao, $groupId)
sanitizeSrvData(&$srvData)
Check if the passed server upload object is correct or not.
generateSrvUpload($srvData, $folderName, $fileDescription, $isPublic, $ignoreScm, $applyGlobal)
createFileUpload($uploadedFile, $folderId, $fileDescription, $isPublic, $ignoreScm=0, $applyGlobal=0)
handleUpload($body, $uploadType, $folderId, $fileDescription, $isPublic, $ignoreScm=0, $applyGlobal=0)
sanitizeVcsData(&$vcsData)
Check if the passed VCS object is correct or not.
Model to hold analysis settings.
Model holding information about license findings and conclusions.
Info model to contain general error and return values.
Model to hold info required by Reuser agent.
Model to hold add settings for new scan.
Model class to hold Upload info.