/** * @param int $uploadTreeId * @param string $tableName * @param int $agentId * @param array $typeToHighlightTypeMap * @throws \Exception * @return Highlight[] */ public function getHighlights($uploadTreeId, $tableName = "copyright", $agentId = 0, $typeToHighlightTypeMap = array('statement' => Highlight::COPYRIGHT, 'email' => Highlight::EMAIL, 'url' => Highlight::URL, 'author' => Highlight::AUTHOR)) { $pFileId = 0; $row = $this->uploadDao->getUploadEntry($uploadTreeId); if (!empty($row['pfile_fk'])) { $pFileId = $row['pfile_fk']; } else { $text = _("Could not locate the corresponding pfile."); print $text; } $statementName = __METHOD__ . $tableName; $sql = "SELECT * FROM {$tableName} WHERE copy_startbyte IS NOT NULL AND pfile_fk=\$1"; $params = array($pFileId); if ($agentId != 0) { $statementName .= '.agentId'; $sql .= ' AND agent_fk=$2'; $params[] = $agentId; } $this->dbManager->prepare($statementName, $sql); $result = $this->dbManager->execute($statementName, $params); $highlights = array(); while ($row = $this->dbManager->fetchArray($result)) { $type = $row['type']; $content = $row['content']; $htmlElement = null; $highlightType = array_key_exists($type, $typeToHighlightTypeMap) ? $typeToHighlightTypeMap[$type] : Highlight::UNDEFINED; $highlights[] = new Highlight($row['copy_startbyte'], $row['copy_endbyte'], $highlightType, -1, -1, $content, $htmlElement); } $this->dbManager->freeResult($result); return $highlights; }
/** * * @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; }
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; }
function OutputOpen() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $uploadId = GetParm("upload", PARM_INTEGER); if (empty($uploadId)) { return; } $uploadTreeId = GetParm("item", PARM_INTEGER); if (empty($uploadTreeId)) { $parent = $this->uploadDao->getUploadParent($uploadId); if (!isset($parent)) { $this->invalidParm = true; return; } $item = $this->uploadDao->getNextItem($uploadId, $parent); if ($item === UploadDao::NOT_FOUND) { $this->invalidParm = true; return; } $uploadTreeId = $item->getId(); return new RedirectResponse(Traceback_uri() . '?mod=' . $this->Name . Traceback_parm_keep(array("upload", "show")) . "&item={$uploadTreeId}"); } $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId); $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId, $uploadTreeTableName); if (Isdir($uploadEntry['ufile_mode']) || Iscontainer($uploadEntry['ufile_mode'])) { $parent = $this->uploadDao->getUploadParent($uploadId); if (!isset($parent)) { $this->invalidParm = true; return; } $item = $this->uploadDao->getNextItem($uploadId, $parent); if ($item === UploadDao::NOT_FOUND) { $this->invalidParm = true; return; } $uploadTreeId = $item->getId(); return new RedirectResponse(Traceback_uri() . '?mod=' . $this->Name . Traceback_parm_keep(array("upload", "show")) . "&item={$uploadTreeId}"); } return parent::OutputOpen(); }
/** * \brief Display the tag info data associated with the file. */ function ShowTagInfo($Upload, $Item) { $VT = ""; $text = _("Tag Info"); $VT .= "<H2>{$text}</H2>\n"; $groupId = Auth::getGroupId(); $row = $this->uploadDao->getUploadEntry($Item); if (empty($row)) { $text = _("Invalid URL, nonexistant item"); return "<h2>{$text} {$Item}</h2>"; } $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; if (empty($lft)) { $text = _("Upload data is unavailable. It needs to be unpacked."); return "<h2>{$text} uploadtree_pk: {$Item}</h2>"; } global $PG_CONN; $sql = "SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_file,tag WHERE tag_pk = tag_fk) T ON uploadtree.pfile_fk = T.pfile_fk WHERE uploadtree.upload_fk = {$upload_pk} AND uploadtree.lft >= {$lft} AND uploadtree.rgt <= {$rgt} UNION SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_uploadtree,tag WHERE tag_pk = tag_fk) T ON uploadtree.uploadtree_pk = T.uploadtree_fk WHERE uploadtree.upload_fk = {$upload_pk} AND uploadtree.lft >= {$lft} AND uploadtree.rgt <= {$rgt} ORDER BY ufile_name"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) > 0) { $VT .= "<table border=1>\n"; $text = _("FileName"); $text2 = _("Tag"); $VT .= "<tr><th>{$text}</th><th>{$text2}</th><th></th></tr>\n"; while ($row = pg_fetch_assoc($result)) { $VT .= "<tr><td align='center'>" . $row['ufile_name'] . "</td><td align='center'>" . $row['tag'] . "</td>"; if ($this->uploadDao->isAccessible($upload_pk, $groupId)) { $VT .= "<td align='center'><a href='" . Traceback_uri() . "?mod=tag&action=edit&upload={$Upload}&item=" . $row['uploadtree_pk'] . "&tag_file_pk=" . $row['tag_file_pk'] . "'>View</a></td></tr>\n"; } else { $VT .= "<td align='center'></td></tr>\n"; } } $VT .= "</table><p>\n"; } pg_free_result($result); return $VT; }
/** * \brief Display the tag info data associated with the file. */ function ShowTagInfo($Upload, $Item) { $VT = ""; $text = _("Tag Info"); $VT .= "<H2>{$text}</H2>\n"; $groupId = Auth::getGroupId(); $row = $this->uploadDao->getUploadEntry($Item); if (empty($row)) { $text = _("Invalid URL, nonexistant item"); return "<h2>{$text} {$Item}</h2>"; } $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; if (empty($lft)) { $text = _("Upload data is unavailable. It needs to be unpacked."); return "<h2>{$text} uploadtree_pk: {$Item}</h2>"; } $sql = "SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_file,tag WHERE tag_pk = tag_fk) T\n ON uploadtree.pfile_fk = T.pfile_fk WHERE uploadtree.upload_fk = \$1\n AND uploadtree.lft >= \$2 AND uploadtree.rgt <= \$3 UNION SELECT * FROM uploadtree INNER JOIN\n (SELECT * FROM tag_uploadtree,tag WHERE tag_pk = tag_fk) T ON uploadtree.uploadtree_pk = T.uploadtree_fk\n WHERE uploadtree.upload_fk = \$1 AND uploadtree.lft >= \$2 AND uploadtree.rgt <= \$3 ORDER BY ufile_name"; $this->dbManager->prepare(__METHOD__, $sql); $result = $this->dbManager->execute(__METHOD__, array($upload_pk, $lft, $rgt)); if (pg_num_rows($result) > 0) { $VT .= "<table border=1>\n"; $text = _("FileName"); $text2 = _("Tag"); $VT .= "<tr><th>{$text}</th><th>{$text2}</th><th></th></tr>\n"; while ($row = pg_fetch_assoc($result)) { $VT .= "<tr><td align='center'>" . $row['ufile_name'] . "</td><td align='center'>" . $row['tag'] . "</td>"; if ($this->uploadDao->isAccessible($upload_pk, $groupId)) { $VT .= "<td align='center'><a href='" . Traceback_uri() . "?mod=tag&action=edit&upload={$Upload}&item=" . $row['uploadtree_pk'] . "&tag_file_pk=" . $row['tag_file_pk'] . "'>View</a></td></tr>\n"; } else { $VT .= "<td align='center'></td></tr>\n"; } } $VT .= "</table><p>\n"; } $this->dbManager->freeResult($result); return $VT; }
/** * \brief Given a filename, return all uploadtree. * \param $Item uploadtree_pk of tree to search, if empty, do global search * \param $Filename filename or pattern to search for, false if unused * \param $tag tag (or tag pattern mytag%) to search for, false if unused * \param $Page display page number * \param $SizeMin Minimum file size, -1 if unused * \param $SizeMax Maximum file size, -1 if unused * \param $searchtype "containers" or "allfiles" * \return array of uploadtree recs. Each record contains uploadtree_pk, parent, * upload_fk, pfile_fk, ufile_mode, and ufile_name */ function GetResults($Item, $Filename, $tag, $Page, $SizeMin, $SizeMax, $searchtype, $License, $Copyright) { global $PG_CONN; $UploadtreeRecs = array(); // uploadtree record array to return $NeedTagfileTable = true; $NeedTaguploadtreeTable = true; if ($Item) { /* Find lft and rgt bounds for this $Uploadtree_pk */ $row = $this->uploadDao->getUploadEntry($Item); if (empty($row)) { $text = _("Invalid URL, nonexistant item"); return "<h2>{$text} {$Item}</h2>"; } $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; /* Check upload permission */ if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) { return $UploadtreeRecs; } } /* Start the result select stmt */ $SQL = "SELECT DISTINCT uploadtree_pk, parent, upload_fk, uploadtree.pfile_fk, ufile_mode, ufile_name FROM uploadtree"; if (!empty($License)) { $SQL .= ", ( SELECT license_ref.rf_shortname, license_file.rf_fk, license_file.pfile_fk\n FROM license_file JOIN license_ref ON license_file.rf_fk = license_ref.rf_pk) AS pfile_ref"; } if (!empty($Copyright)) { $SQL .= ",copyright"; } /* Figure out the tag_pk's of interest */ if (!empty($tag)) { $sql = "select tag_pk from tag where tag ilike '{$tag}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { /* tag doesn't match anything, so no results are possible */ pg_free_result($result); return $UploadtreeRecs; } /* Make a list of the tag_pk's that satisfy the criteria */ $tag_pk_array = pg_fetch_all($result); pg_free_result($result); /* add the tables needed for the tag query */ $sql = "select tag_file_pk from tag_file limit 1"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { /* tag_file didn't have data, don't add the tag_file table for tag query */ $NeedTagfileTable = false; } else { $SQL .= ", tag_file"; } pg_free_result($result); /* add the tables needed for the tag query */ $sql = "select tag_uploadtree_pk from tag_uploadtree limit 1"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) < 1) { /* tag_uploadtree didn't have data, don't add the tag_uploadtree table for tag query */ $NeedTaguploadtreeTable = false; } else { $SQL .= ", tag_uploadtree"; } pg_free_result($result); if (!$NeedTagfileTable && !$NeedTaguploadtreeTable) { $SQL .= ", tag_file, tag_uploadtree"; } } /* do we need the pfile table? Yes, if any of these are a search critieria. */ if (!empty($SizeMin) or !empty($SizeMax)) { $SQL .= ", pfile where pfile_pk=uploadtree.pfile_fk "; $NeedAnd = true; } else { $SQL .= " where "; $NeedAnd = false; } /* add the tag conditions */ if (!empty($tag)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= "("; $NeedOr = false; foreach ($tag_pk_array as $tagRec) { if ($NeedOr) { $SQL .= " OR"; } $SQL .= "("; $tag_pk = $tagRec['tag_pk']; if ($NeedTagfileTable && $NeedTaguploadtreeTable) { $SQL .= "(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk={$tag_pk}) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk={$tag_pk}) "; } else { if ($NeedTaguploadtreeTable) { $SQL .= "uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk={$tag_pk}"; } else { if ($NeedTagfileTable) { $SQL .= "uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk={$tag_pk}"; } else { $SQL .= "(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk={$tag_pk}) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk={$tag_pk}) "; } } } $SQL .= ")"; $NeedOr = 1; } $NeedAnd = 1; $SQL .= ")"; } if ($Filename) { $Filename = str_replace("'", "''", $Filename); // protect DB if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " ufile_name ilike '{$Filename}'"; $NeedAnd = 1; } if (!empty($SizeMin)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " pfile.pfile_size >= {$SizeMin}"; $NeedAnd = 1; } if (!empty($SizeMax)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " pfile.pfile_size <= {$SizeMax}"; $NeedAnd = 1; } if ($Item) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " upload_fk = {$upload_pk} AND lft >= {$lft} AND rgt <= {$rgt}"; $NeedAnd = 1; } /* search only containers */ $dir_ufile_mode = 536888320; if ($searchtype == 'containers') { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)"; $NeedAnd = 1; } if ($searchtype == 'directory') { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0) AND (ufile_mode != {$dir_ufile_mode}) and pfile_fk != 0"; $NeedAnd = 1; } /** license and copyright */ if (!empty($License)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " uploadtree.pfile_fk=pfile_ref.pfile_fk and pfile_ref.rf_shortname ilike '{$License}'"; $NeedAnd = 1; } if (!empty($Copyright)) { if ($NeedAnd) { $SQL .= " AND"; } $SQL .= " uploadtree.pfile_fk=copyright.pfile_fk and copyright.content ilike '%{$Copyright}%'"; } $Offset = $Page * $this->MaxPerPage; $SQL .= " ORDER BY ufile_name, uploadtree.pfile_fk"; $SQL .= " LIMIT {$this->MaxPerPage} OFFSET {$Offset};"; $result = pg_query($PG_CONN, $SQL); DBCheckResult($result, $SQL, __FILE__, __LINE__); if (pg_num_rows($result)) { while ($row = pg_fetch_assoc($result)) { if (!$this->uploadDao->isAccessible($row['upload_fk'], Auth::getGroupId())) { continue; } $UploadtreeRecs[] = $row; } } pg_free_result($result); return $UploadtreeRecs; }
/** * @param $Uploadtree_pk * @return bool */ protected function isADirectory($Uploadtree_pk) { $row = $this->uploadDao->getUploadEntry($Uploadtree_pk, $this->uploadtree_tablename); $isADirectory = IsDir($row['ufile_mode']); return $isADirectory; }
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)); }
/** * \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>'; } }