コード例 #1
0
 /**
  * 
  * @param int $uploadTreeId
  * @param Request $request
  * @return int $jobQueueId
  */
 private function getJobQueueId($uploadTreeId, Request $request)
 {
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId);
     $uploadId = intval($uploadEntry['upload_fk']);
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     if ($uploadId <= 0 || !$this->uploadDao->isAccessible($uploadId, $groupId)) {
         throw new Exception('permission denied');
     }
     $bulkScope = $request->get('bulkScope');
     switch ($bulkScope) {
         case 'u':
             $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
             $topBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTable);
             $uploadTreeId = $topBounds->getItemId();
             break;
         case 'f':
             if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) {
                 $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId;
             }
             break;
         default:
             throw new InvalidArgumentException('bad scope request');
     }
     $refText = $request->get('refText');
     $actions = $request->get('bulkAction');
     $licenseRemovals = array();
     foreach ($actions as $licenseAction) {
         $licenseRemovals[$licenseAction['licenseId']] = $licenseAction['action'] == 'remove';
     }
     $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseRemovals, $refText);
     if ($bulkId <= 0) {
         throw new Exception('cannot insert bulk reference');
     }
     $upload = $this->uploadDao->getUpload($uploadId);
     $uploadName = $upload->getFilename();
     $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId);
     /** @var DeciderJobAgentPlugin $deciderPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId));
     $conflictStrategyId = intval($request->get('forceDecision'));
     $errorMsg = '';
     $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId);
     if (!empty($errorMsg)) {
         throw new Exception(str_replace('<br>', "\n", $errorMsg));
     }
     return $jqId;
 }
コード例 #2
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $upload = intval($request->get("upload"));
     $groupId = Auth::getGroupId();
     if (!$this->uploadDao->isAccessible($upload, $groupId)) {
         return $this->flushContent(_("Permission Denied"));
     }
     $item = intval($request->get("item"));
     $vars['baseuri'] = Traceback_uri();
     $vars['uploadId'] = $upload;
     $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload);
     if ($request->get('show') == 'quick') {
         $item = $this->uploadDao->getFatItemId($item, $upload, $this->uploadtree_tablename);
     }
     $vars['itemId'] = $item;
     $vars['micromenu'] = Dir2Browse($this->Name, $item, NULL, $showBox = 0, "Browse", -1, '', '', $this->uploadtree_tablename);
     $vars['licenseArray'] = $this->licenseDao->getLicenseArray();
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
     $left = $itemTreeBounds->getLeft();
     if (empty($left)) {
         return $this->flushContent(_("Job unpack/adj2nest hasn't completed."));
     }
     $histVars = $this->showUploadHist($itemTreeBounds);
     if (is_a($histVars, 'Symfony\\Component\\HttpFoundation\\RedirectResponse')) {
         return $histVars;
     }
     $vars = array_merge($vars, $histVars);
     $vars['content'] = js_url();
     return $this->render("browse.html.twig", $this->mergeWithDefault($vars));
 }
コード例 #3
0
 /**
  * @param int $userId
  * @param int
  * @param int $lastItem
  * @return array
  */
 protected function updateLastItem($userId, $groupId, $lastItem)
 {
     $type = GetParm("clearingTypes", PARM_INTEGER);
     $global = GetParm("globalDecision", PARM_STRING) === "on";
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($lastItem);
     $itemBounds = $this->uploadDao->getItemTreeBounds($lastItem, $uploadTreeTableName);
     $this->clearingDecisionEventProcessor->makeDecisionFromLastEvents($itemBounds, $userId, $groupId, $type, $global);
 }
コード例 #4
0
 public function getCleared($uploadId, $groupId = null)
 {
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $ungrupedStatements = $this->getStatements($uploadId, $uploadTreeTableName, $groupId);
     $this->changeTreeIdsToPaths($ungrupedStatements, $uploadTreeTableName, $uploadId);
     $statements = $this->groupStatements($ungrupedStatements);
     return array("statements" => array_values($statements));
 }
コード例 #5
0
 private function getJobQueueId($uploadTreeId)
 {
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId);
     $uploadId = intval($uploadEntry['upload_fk']);
     if ($uploadId <= 0) {
         throw new Exception('permission denied');
     }
     $bulkScope = filter_input(INPUT_POST, 'bulkScope');
     switch ($bulkScope) {
         case 'u':
             $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
             $row = $this->dbManager->getSingleRow("SELECT uploadtree_pk FROM {$uploadTreeTable} WHERE upload_fk = \$1 ORDER BY uploadtree_pk LIMIT 1", array($uploadId), __METHOD__ . "adam" . $uploadTreeTable);
             $uploadTreeId = $row['uploadtree_pk'];
             break;
         case 'f':
             if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) {
                 $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId;
             }
             break;
         default:
             throw new InvalidArgumentException('bad scope request');
     }
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     $refText = filter_input(INPUT_POST, 'refText');
     $action = filter_input(INPUT_POST, 'bulkAction');
     $licenseId = GetParm('licenseId', PARM_INTEGER);
     $removing = $action === 'remove';
     $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseId, $removing, $refText);
     if ($bulkId <= 0) {
         throw new Exception('cannot insert bulk reference');
     }
     $upload = $this->uploadDao->getUpload($uploadId);
     $uploadName = $upload->getFilename();
     $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId);
     /** @var DeciderJobAgentPlugin $deciderPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId));
     $conflictStrategyId = intval(filter_input(INPUT_POST, 'forceDecision'));
     $errorMsg = '';
     $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId);
     if (!empty($errorMsg)) {
         throw new Exception(str_replace('<br>', "\n", $errorMsg));
     }
     return $jqId;
 }
コード例 #6
0
ファイル: spdx2.php プロジェクト: rlintu/fossology
 /**
  * @param string[][][] &$filesWithLicenses
  * @param int $uploadId
  * @return string
  */
 protected function addCopyrightResults(&$filesWithLicenses, $uploadId)
 {
     /* @var $copyrightDao CopyrightDao */
     $copyrightDao = $this->container->get('dao.copyright');
     $uploadtreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
     $allEntries = $copyrightDao->getAllEntries('copyright', $uploadId, $uploadtreeTable, $type = 'statement');
     foreach ($allEntries as $finding) {
         $filesWithLicenses[$finding['uploadtree_pk']]['copyrights'][] = \convertToUTF8($finding['content'], false);
     }
 }
コード例 #7
0
 public function testRun()
 {
     $this->setUpTables();
     $this->setUpRepo();
     $output = $this->runCopyright($uploadId = 1);
     $this->rmRepo();
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $matches = $this->copyrightDao->getAllEntries("copyright", $uploadId, $uploadTreeTableName);
     $this->assertGreaterThan($expected = 5, count($matches), $output);
 }
コード例 #8
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $uploadId = intval($request->get('upload'));
     if (empty($uploadId)) {
         return;
     }
     $uploadTreeId = intval($request->get('item'));
     if (empty($uploadTreeId)) {
         return;
     }
     $onlyTried = !$request->get('all');
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     /** @var ItemTreeBounds */
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($uploadTreeId, $uploadTreeTableName);
     /** @var Session */
     $session = $this->getObject('session');
     $groupId = $session->get(Auth::GROUP_ID);
     $bulkHistory = $this->clearingDao->getBulkHistory($itemTreeBounds, $groupId, $onlyTried);
     return $this->render("bulk-history.html.twig", $this->mergeWithDefault(array('bulkHistory' => $bulkHistory)));
 }
コード例 #9
0
ファイル: spdx2.php プロジェクト: DanielDobre/fossology
 protected function addCopyrightResults(&$filesWithLicenses, $uploadId)
 {
     /* @var $copyrightDao CopyrightDao */
     $copyrightDao = $this->container->get('dao.copyright');
     $uploadtreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
     $allEntries = $copyrightDao->getAllEntries('copyright', $uploadId, $uploadtreeTable, $type = 'skipcontent');
     //, $onlyCleared=true, DecisionTypes::IDENTIFIED, 'textfinding!=\'\'');
     foreach ($allEntries as $finding) {
         $filesWithLicenses[$finding['uploadtree_pk']]['copyrights'][] = \convertToUTF8($finding['content']);
     }
 }
コード例 #10
0
 /**
  * @param $itemId - uploadtree id
  * @param $uploadId - upload id
  */
 public function getCopyrightList($itemId, $uploadId)
 {
     if (empty($itemId)) {
         $itemId = $this->uploadDao->getUploadParent($uploadId);
     }
     if (!$this->selectAgentId($uploadId)) {
         echo 'no valid copyright agent found';
         return;
     }
     $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($uploadId);
     $toprow = $this->uploadDao->getItemTreeBounds($itemId, $uploadtree_tablename);
     $extraWhere = 'agent_fk=' . $this->agentId . ' AND lft>' . $toprow->getLeft() . ' AND rgt<' . $toprow->getRight();
     $allCopyrightEntries = $this->copyrightDao->getAllEntries('copyright', $uploadId, $uploadtree_tablename, empty($this->type) || $this->type == 'all' ? null : $this->type, false, null, $extraWhere);
     $modeMask = empty($this->includeContainer) ? 3 << 28 : 1 << 28;
     $sql = "SELECT uploadtree_pk, ufile_name, lft, rgt FROM {$uploadtree_tablename} \n              WHERE upload_fk=\$1 AND lft>\$2 AND rgt<\$3 AND (ufile_mode & \$4) = 0\n              ORDER BY uploadtree_pk";
     $this->dbManager->prepare($outerStmt = __METHOD__ . '.loopThroughAllRecordsInTree', $sql);
     $outerresult = $this->dbManager->execute($outerStmt, array($toprow->getUploadId(), $toprow->getLeft(), $toprow->getRight(), $modeMask));
     while ($row = $this->dbManager->fetchArray($outerresult)) {
         $this->printRow($row, $uploadtree_tablename, $allCopyrightEntries);
         //$this->uploadDao->getParentItemBounds($uploadId)->getItemId());
     }
     $this->dbManager->freeResult($outerresult);
 }
コード例 #11
0
 /**
  * @brief Display the loaded menu and plugins.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $itemId = $_POST['uploadTreeId'];
     if (empty($itemId)) {
         return $this->errorJson("bad item id");
     }
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     $decisionMark = @$_POST['decisionMark'];
     if (!empty($decisionMark)) {
         $itemTableName = $this->uploadDao->getUploadtreeTableName($itemId);
         /** @var ItemTreeBounds */
         $itemTreeBounds = $this->uploadDao->getItemTreeBounds($itemId, $itemTableName);
         $errMsg = $this->clearingDao->markDirectoryAsIrrelevant($itemTreeBounds, $groupId, $userId);
         if (empty($errMsg)) {
             return new JsonResponse(array('result' => 'success'));
         }
         return $this->errorJson($errMsg, $errMsg);
     }
     return $this->doEdit($userId, $groupId, $itemId);
 }
コード例 #12
0
 /**
  * \brief Display the loaded menu and plugins.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $action = GetParm("action", PARM_STRING);
     $id = GetParm("id", PARM_STRING);
     $upload = GetParm("upload", PARM_INTEGER);
     if (($action == "update" || $action == "delete") && !isset($id)) {
         $text = _("Wrong request");
         echo "<h2>{$text}</h2>";
         return;
     } else {
         if (isset($id)) {
             list($upload, $item, $hash, $type) = explode(",", $id);
         }
     }
     /* check upload permissions */
     $UploadPerm = GetUploadPerm($upload);
     if ($UploadPerm < Auth::PERM_READ) {
         $text = _("Permission Denied");
         echo "<h2>{$text}</h2>";
         return;
     }
     $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload);
     switch ($action) {
         case "getData":
             return $this->doGetData($upload);
         case "update":
             return $this->doUpdate($item, $hash, $type);
         case "delete":
             return $this->doDelete($item, $hash, $type);
         case "undo":
             return $this->doUndo($item, $hash, $type);
     }
 }
コード例 #13
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $upload = intval($request->get("upload"));
     $groupId = Auth::getGroupId();
     if (!$this->uploadDao->isAccessible($upload, $groupId)) {
         throw new \Exception("Permission Denied");
     }
     $item = intval($request->get("item"));
     $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload);
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
     $left = $itemTreeBounds->getLeft();
     if (empty($left)) {
         throw new \Exception("Job unpack/adj2nest hasn't completed.");
     }
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->agentDao, $upload);
     $scanJobProxy->createAgentStatus($scannerAgents);
     $selectedAgentId = intval($request->get('agentId'));
     $tag_pk = intval($request->get('tag'));
     $UniqueTagArray = array();
     $this->licenseProjector = new LicenseMap($this->getObject('db.manager'), $groupId, LicenseMap::CONCLUSION, true);
     $vars = $this->createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy);
     return new JsonResponse(array('sEcho' => intval($request->get('sEcho')), 'aaData' => $vars['fileData'], 'iTotalRecords' => intval($request->get('totalRecords')), 'iTotalDisplayRecords' => $vars['iTotalDisplayRecords']));
 }
コード例 #14
0
ファイル: ui-browse.php プロジェクト: DanielDobre/fossology
 /**
  * @param int $uploadTreeId
  * @param int $Folder
  * @param int $Upload
  * @return string
  */
 function outputItemHtml($uploadTreeId, $Folder, $Upload)
 {
     global $container;
     $dbManager = $container->get('db.manager');
     $show = 'quick';
     $html = '';
     $uploadtree_tablename = "";
     if (!empty($uploadTreeId)) {
         $sql = "SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = \$1";
         $row = $dbManager->getSingleRow($sql, array($uploadTreeId));
         $Upload = $row['upload_fk'];
         if (!$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
             $this->vars['message'] = _("Permission Denied");
             return $this->render('include/base.html.twig');
         }
         if (!Iscontainer($row['ufile_mode'])) {
             global $Plugins;
             $View =& $Plugins[plugin_find_id("view")];
             if (!empty($View)) {
                 $this->vars['content'] = $View->ShowView(NULL, "browse");
                 return $this->render('include/base.html.twig');
             }
         }
         $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($row['upload_fk']);
         $html .= Dir2Browse($this->Name, $uploadTreeId, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename) . "\n";
     } else {
         if (!empty($Upload)) {
             $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
             $html .= Dir2BrowseUpload($this->Name, $Upload, NULL, 1, "Browse", $uploadtree_tablename) . "\n";
         }
     }
     if (empty($Upload)) {
         $this->vars['show'] = $show;
         $this->ShowFolder($Folder);
         return $html;
     }
     if (empty($uploadTreeId)) {
         try {
             $uploadTreeId = $this->uploadDao->getUploadParent($Upload);
         } catch (Exception $e) {
             $this->vars['message'] = $e->getMessage();
             return $this->render('include/base.html.twig');
         }
     }
     $html .= $this->ShowItem($Upload, $uploadTreeId, $show, $Folder, $uploadtree_tablename);
     $this->vars['content'] = $html;
     return $this->render('include/base.html.twig');
 }
コード例 #15
0
ファイル: showjobs.php プロジェクト: DanielDobre/fossology
 /**
  * @brief Returns geeky scan details about the jobqueue item
  * @param $job_pk
  * @return Return job and jobqueue record data in an html table.
  **/
 function showJobDB($job_pk)
 {
     global $container;
     /** @var DbManager */
     $dbManager = $container->get('db.manager');
     $statementName = __METHOD__ . "ShowJobDBforjob";
     $dbManager->prepare($statementName, "SELECT *, jq_endtime-jq_starttime as elapsed FROM jobqueue LEFT JOIN job ON job.job_pk = jobqueue.jq_job_fk WHERE jobqueue.jq_pk = \$1");
     $result = $dbManager->execute($statementName, array($job_pk));
     $row = $dbManager->fetchArray($result);
     $dbManager->freeResult($result);
     if (!empty($row["job_upload_fk"])) {
         /* get the upload filename */
         $statementName = __METHOD__ . "upload_filenameforShowJobDB";
         $dbManager->prepare($statementName, "select upload_filename, upload_desc from upload where upload_pk =\$1");
         $uploadresult = $dbManager->execute($statementName, array($row['job_upload_fk']));
         $uploadRow = $dbManager->fetchArray($uploadresult);
         if (empty($uploadRow)) {
             /* upload has been deleted so try to get the job name from the original upload job record */
             $jobName = $this->showJobsDao->getJobName($row["job_upload_fk"]);
             $upload_filename = "Deleted " . $jobName;
             $upload_desc = '';
         } else {
             $upload_filename = $uploadRow['upload_filename'];
             $upload_desc = $uploadRow['upload_desc'];
         }
         $dbManager->freeResult($uploadresult);
         if (empty($row['jq_pk'])) {
             return _("Job history record is no longer available");
         }
         $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($row['job_upload_fk']);
         /* Find the uploadtree_pk for this upload so that it can be used in the browse link */
         $statementName = __METHOD__ . "uploadtreeRec";
         $uploadtreeRec = $dbManager->getSingleRow("select * from {$uploadtree_tablename} where parent is NULL and upload_fk=\$1", array($row['job_upload_fk']), $statementName);
         $uploadtree_pk = $uploadtreeRec['uploadtree_pk'];
     }
     /* upload file name link to browse */
     if (!empty($row['job_upload_fk'])) {
         $uploadTreeName = "";
         $uploadTreeName = "<a title='Click to browse this upload' href='" . Traceback_uri() . "?mod=browse&upload=" . $row['job_upload_fk'] . "&item=" . $uploadtree_pk . "'>" . $upload_filename . "</a>";
         return $uploadTreeName;
     }
 }
コード例 #16
0
 /**
  * \brief This function returns the scheduler status.
  */
 function Output()
 {
     global $SysConf;
     global $PG_CONN;
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     if (empty($uploadtree_pk)) {
         return;
     }
     $upload_pk = GetParm("upload", PARM_INTEGER);
     if (empty($upload_pk)) {
         return;
     }
     if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
         $text = _("Permission Denied");
         return "<h2>{$text}</h2>";
     }
     $dltext = GetParm("output", PARM_STRING) == 'dltext';
     /* get last nomos agent_pk that has data for this upload */
     $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1);
     $agent_pk = $AgentRec[0]["agent_fk"];
     if ($AgentRec === false) {
         return _("No data available");
     }
     /* how many lines of data do you want to display */
     $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
     /* get the top of tree */
     $toprow = $this->uploadDao->getUploadEntry($uploadtree_pk);
     /* loop through all the records in this tree */
     $sql = "select uploadtree_pk, ufile_name, lft, rgt from uploadtree\n              where upload_fk='{$toprow['upload_fk']}' \n                    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n                    and (ufile_mode & (3<<28)) = 0 limit {$NomostListNum}";
     $outerresult = pg_query($PG_CONN, $sql);
     DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
     /* Select each uploadtree row in this tree, write out text:
      * filepath : license list
      * e.g. Pound-2.4.tgz/Pound-2.4/svc.c: GPL_v3+, Indemnity
      */
     $uploadtreeTablename = $this->uploadDao->getUploadtreeTableName($toprow['upload_fk']);
     $lines = array();
     while ($row = pg_fetch_assoc($outerresult)) {
         $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtreeTablename);
         $filepath = "";
         foreach ($filepatharray as $uploadtreeRow) {
             if (!empty($filepath)) {
                 $filepath .= "/";
             }
             $filepath .= $uploadtreeRow['ufile_name'];
         }
         $lines[] = $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtreeTablename);
     }
     $RealNumber = pg_num_rows($outerresult);
     pg_free_result($outerresult);
     if ($RealNumber == $NomostListNum) {
         $V .= _("<br><b>Warning: Only the last {$NomostListNum} lines are displayed.  To see the whole list, run fo_nomos_license_list from the command line.</b><br>");
     }
     if ($dltext) {
         $request = $this->getRequest();
         $itemId = intval($request->get('item'));
         $path = Dir2Path($itemId, $uploadtreeTablename);
         $fileName = $path[count($path) - 1]['ufile_name'] . ".txt";
         $headers = array("Content-Type" => "text", "Content-Disposition" => "attachment; filename=\"{$fileName}\"");
         $response = new Response(implode("\n", $lines), Response::HTTP_OK, $headers);
         return $response;
     } else {
         return $V . '<pre>' . implode("\n", $lines) . '</pre>';
     }
 }
コード例 #17
0
ファイル: ui-view.php プロジェクト: rlintu/fossology
 /**
  * \brief Generate the view contents in HTML
  *
  * @param resource $inputFile
  * @param string $BackMod
  * @param int $ShowMenu
  * @param int $ShowHeader
  * @param null $ShowText
  * @param bool $ViewOnly
  * @param bool $DispView
  * @param Highlight[] $highlightEntries
  * @param bool $insertBacklink
  *
  * \note This function is intended to be called from other plugins.
  */
 function getView($inputFile = NULL, $BackMod = "browse", $ShowHeader = 1, $ShowText = NULL, $highlightEntries = array(), $insertBacklink = false, $getPageMenuInline = false)
 {
     if ($this->State != PLUGIN_STATE_READY) {
         $output = "Invalid plugin state: " . $this->State;
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $Upload = GetParm("upload", PARM_INTEGER);
     if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
         $output = "Access denied";
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $Item = GetParm("item", PARM_INTEGER);
     $Page = GetParm("page", PARM_INTEGER);
     $licenseId = GetParm("licenseId", PARM_INTEGER);
     if (!$inputFile && empty($Item)) {
         $output = "invalid input file";
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
     if ($ShowHeader) {
         $Uri = Traceback_uri() . "?mod=browse" . Traceback_parm_keep(array('item', 'show', 'folder', 'upload'));
         /* No item */
         $header = Dir2Browse($BackMod, $Item, NULL, $showBox = 0, "View", -1, '', '', $uploadtree_tablename);
         $this->vars['micromenu'] = $header;
     }
     /* Display file contents */
     $output = "";
     $openedFin = False;
     $Format = $this->microMenu->getFormatParameter($Item);
     if (empty($inputFile)) {
         $inputFile = @fopen(RepPathItem($Item), "rb");
         if ($inputFile) {
             $openedFin = true;
         }
         if (empty($inputFile)) {
             $output = $this->outputWhenFileNotInRepo($Upload, $Item);
             return $getPageMenuInline ? array("Error", $output) : $output;
         }
     }
     rewind($inputFile);
     $Uri = preg_replace('/&page=[0-9]*/', '', Traceback());
     $blockSize = $Format == 'hex' ? $this->blockSizeHex : $this->blockSizeText;
     if (!isset($Page) && !empty($licenseId)) {
         $startPos = -1;
         foreach ($highlightEntries as $highlightEntry) {
             if ($highlightEntry->getLicenseId() == $licenseId && ($startPos == -1 || $startPos > $highlightEntry->getStart())) {
                 $startPos = $highlightEntry->getStart();
             }
         }
         if ($startPos != -1) {
             $Page = floor($startPos / $blockSize);
         }
     }
     if (!empty($ShowText)) {
         echo $ShowText, "<hr>";
     }
     $PageMenu = $this->GetFileJumpMenu($inputFile, $Page, $blockSize, $Uri);
     $PageSize = $blockSize * $Page;
     if (!empty($PageMenu) and !$getPageMenuInline) {
         $output .= "<center>{$PageMenu}</center><br>\n";
     }
     $startAt = $PageSize;
     $endAt = $PageSize + $blockSize;
     $relevantHighlightEntries = array();
     foreach ($highlightEntries as $highlightEntry) {
         if ($highlightEntry->getStart() < $endAt && $highlightEntry->getEnd() >= $startAt) {
             $relevantHighlightEntries[] = $highlightEntry;
         }
     }
     $this->highlightProcessor->sortHighlights($relevantHighlightEntries);
     $splitPositions = $this->highlightProcessor->calculateSplitPositions($relevantHighlightEntries);
     if ($Format == 'hex') {
         $output .= $this->getHex($inputFile, $PageSize, $this->blockSizeHex, $splitPositions);
     } else {
         $output .= $this->getText($inputFile, $PageSize, $Format == 'text' ? 0 : 1, $this->blockSizeText, $splitPositions, $insertBacklink);
     }
     if (!empty($PageMenu) and !$getPageMenuInline) {
         $output .= "<P /><center>{$PageMenu}</center><br>\n";
     }
     if ($openedFin) {
         fclose($inputFile);
     }
     return $getPageMenuInline ? array($PageMenu, $output) : $output;
 }
コード例 #18
0
ファイル: Xpview.php プロジェクト: DanielDobre/fossology
 protected function handle(Request $request)
 {
     $vars = array();
     $uploadId = intval($request->get('upload'));
     $uploadTreeId = intval($request->get('item'));
     if (empty($uploadTreeId) || empty($uploadId)) {
         $text = _("Empty Input");
         $vars['message'] = "<h2>{$text}</h2>";
         return $this->responseBad($vars);
     }
     if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
         $text = _("Permission Denied");
         $vars['message'] = "<h2>{$text}</h2>";
         return $this->responseBad();
     }
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId, $uploadTreeTableName);
     if (Isdir($uploadEntry['ufile_mode']) || Iscontainer($uploadEntry['ufile_mode'])) {
         $parent = $this->uploadDao->getUploadParent($uploadEntry['upload_fk']);
         if (!isset($parent)) {
             return $this->responseBad();
         }
         $uploadTree = $this->uploadDao->getNextItem($uploadEntry['upload_fk'], $parent);
         if ($uploadTree === UploadDao::NOT_FOUND) {
             return $this->responseBad();
         }
         $uploadTreeId = $uploadTree->getId();
         return new RedirectResponse(Traceback_uri() . '?mod=' . $this->getName() . Traceback_parm_keep(array('show', 'upload')) . "&item={$uploadTreeId}");
     }
     if (empty($uploadTreeId)) {
         return $this->responseBad('No item selected.');
     }
     $copyrightDecisionMap = $this->decisionTypes->getMap();
     $vars['micromenu'] = Dir2Browse($this->modBack, $uploadTreeId, NULL, $showBox = 0, "View", -1, '', '', $uploadTreeTableName);
     $lastItem = GetParm("lastItem", PARM_INTEGER);
     $changed = GetParm("changedSomething", PARM_STRING);
     $userId = Auth::getUserId();
     if (!empty($lastItem) && $changed == "true") {
         $lastUploadEntry = $this->uploadDao->getUploadEntry($lastItem, $uploadTreeTableName);
         $clearingType = $_POST['clearingTypes'];
         $description = $_POST['description'];
         $textFinding = $_POST['textFinding'];
         $comment = $_POST['comment'];
         $this->copyrightDao->saveDecision($this->decisionTableName, $lastUploadEntry['pfile_fk'], $userId, $clearingType, $description, $textFinding, $comment);
     }
     $scanJobProxy = new ScanJobProxy($this->agentDao, $uploadId);
     $scanJobProxy->createAgentStatus(array($this->agentName));
     $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     $highlights = array();
     if (array_key_exists($this->agentName, $selectedScanners)) {
         $latestXpAgentId = $selectedScanners[$this->agentName];
         $highlights = $this->copyrightDao->getHighlights($uploadTreeId, $this->tableName, $latestXpAgentId, $this->typeToHighlightTypeMap);
     }
     if (count($highlights) < 1) {
         $vars['message'] = _("No ") . $this->tableName . _(" data is available for this file.");
     }
     /* @var $view ui_view */
     $view = plugin_find("view");
     $theView = $view->getView(null, null, $showHeader = 0, "", $highlights, false, true);
     list($pageMenu, $textView) = $theView;
     list($description, $textFinding, $comment, $decisionType) = $this->copyrightDao->getDecision($this->decisionTableName, $uploadEntry['pfile_fk']);
     $vars['description'] = $description;
     $vars['textFinding'] = $textFinding;
     $vars['comment'] = $comment;
     $vars['itemId'] = $uploadTreeId;
     $vars['uploadId'] = $uploadId;
     $vars['pageMenu'] = $pageMenu;
     $vars['textView'] = $textView;
     $vars['legendBox'] = $this->legendBox();
     $vars['uri'] = Traceback_uri() . "?mod=" . $this->Name;
     $vars['optionName'] = $this->optionName;
     $vars['formName'] = "CopyRightForm";
     $vars['ajaxAction'] = $this->ajaxAction;
     $vars['skipOption'] = $this->skipOption;
     $vars['selectedClearingType'] = $decisionType;
     $vars['clearingTypes'] = $copyrightDecisionMap;
     $vars['xptext'] = $this->xptext;
     $agentId = intval($request->get("agent"));
     $vars = array_merge($vars, $this->additionalVars($uploadId, $uploadTreeId, $agentId));
     return $this->render('ui-cp-view.html.twig', $this->mergeWithDefault($vars));
 }