/** * \brief test for MenuEndlessPage() */ function test_MenuEndlessPage() { print "test function MenuEndlessPage()\n"; $Page = 10; $Uri = "http://fossology.org/repo/"; $expected = "<a href='http:\\/\\/fossology.org\\/repo\\/&page=9'>\\[Prev\\]<\\/a>"; $result = MenuEndlessPage($Page, 1, $Uri); $this->assertRegExp("/<b>11<\\/b>/", $result); $this->assertRegExp("/{$expected}/", $result); }
/** * \brief print search results to stdout * \param $UploadtreeRecs Array of search results (uploadtree recs) * \param $Page page number being displayed. * \param $GETvars GET variables * \return HTML to display record results */ function HTMLResults($UploadtreeRecs, $Page, $GETvars) { $Outbuf = ""; $PageChoices = ""; $Count = count($UploadtreeRecs); if ($Count == 0) { $Outbuf .= _("No matching files.\n"); return $Outbuf; } if ($Page > 0 || $Count >= $this->MaxPerPage) { $Uri = Traceback_uri() . "?mod=" . $this->Name . $GETvars; $PageChoices = MenuEndlessPage($Page, $Count >= $this->MaxPerPage, $Uri) . "<P />\n"; $Outbuf .= $PageChoices; } else { $PageChoices = ""; } $Outbuf .= UploadtreeFileList($UploadtreeRecs, "browse", "view", $Page * $this->MaxPerPage + 1); /* put page menu at the bottom, too */ $Outbuf .= $PageChoices; return $Outbuf; }
/** * @brief Returns an upload job status in html * @param $JobData * @return Returns an upload job status in html **/ function Show($JobData, $Page) { global $PG_CONN; $OutBuf = ''; $NumJobs = count($JobData); if ($NumJobs == 0) { return _("There are no jobs to display"); } /* Next/Prev menu */ $Next = $NumJobs > $this->MaxUploadsPerPage; if ($NumJobs > $this->MaxUploadsPerPage) { $OutBuf .= MenuEndlessPage($Page, $Next); } /*****************************************************************/ /* Now display the summary */ /*****************************************************************/ $Job = -1; $Blocked = array(); $First = 1; $Upload = "-1"; $Uri = Traceback_uri() . "?mod=" . $this->Name; $UriFull = $Uri . Traceback_parm_keep(array("upload")); $uploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:white;'"; $jobStyle = "style='font:bold 8pt verdana, arial, helvetica; background:lavender; color:black;'"; $prevupload_pk = ""; $OutBuf .= "<table class='text' border=1 width='100%' name='jobtable'>\n"; $FirstJob = $Page * $this->MaxUploadsPerPage; $LastJob = $Page * $this->MaxUploadsPerPage + $this->MaxUploadsPerPage; $JobNumber = -1; /** if $single_browse is 1, represent alread has an upload browse link, if single_browse is 0, no upload browse link */ $single_browse = 0; foreach ($JobData as $job_pk => $Job) { /* Upload */ if (!empty($Job["upload"])) { $UploadName = GetArrayVal("upload_filename", $Job["upload"]); $UploadDesc = GetArrayVal("upload_desc", $Job["upload"]); $upload_pk = GetArrayVal("upload_pk", $Job["upload"]); /** the column pfile_fk of the record in the table(upload) is NULL when this record is inserted */ if (!empty($upload_pk) && $prevupload_pk != $upload_pk || empty($upload_pk) && 0 == $single_browse) { $prevupload_pk = $upload_pk; $JobNumber++; /* Only display the jobs for this page */ if ($JobNumber >= $LastJob) { break; } if ($JobNumber < $FirstJob) { continue; } /* blank line separator between pfiles */ $OutBuf .= "<tr><td colspan=7> <hr> </td></tr>"; $OutBuf .= "<tr>"; $OutBuf .= "<th {$uploadStyle}></th>"; $OutBuf .= "<th colspan=4 {$uploadStyle}>"; if (!empty($Job['uploadtree'])) { $uploadtree_pk = $Job['uploadtree']['uploadtree_pk']; $OutBuf .= "<a title='Click to browse' href='" . Traceback_uri() . "?mod=browse&upload=" . $Job['job']['job_upload_fk'] . "&item=" . $uploadtree_pk . "'>"; } else { $OutBuf .= "<a title='Click to browse' href='" . Traceback_uri() . "?mod=browse'>"; } /* get $UserName if all jobs are shown */ $UserName = ""; $allusers = GetParm("allusers", PARM_INTEGER); if ($allusers > 0) { $UploadRec = GetSingleRec("upload", "where upload_pk={$Job['job']['job_upload_fk']}"); if (!empty($UploadRec)) { $UserRec = GetSingleRec("users", "where user_pk={$UploadRec['user_fk']}"); $UserName = "******"; } else { $UserRec = GetSingleRec("users", "where user_pk={$Job['job']['job_user_fk']}"); $UserName = "******"; } } $OutBuf .= $UploadName . $UserName; if (!empty($UploadDesc)) { $OutBuf .= " (" . $UploadDesc . ")"; } $OutBuf .= "</a>"; $OutBuf .= "</th>"; $OutBuf .= "<th {$uploadStyle}></th>"; $OutBuf .= "</tr>"; $single_browse = 1; } else { if ($JobNumber < $FirstJob) { continue; } } } else { /* blank line separator between pfiles */ $NoUploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:black;'"; $OutBuf .= "<tr><td colspan=7> <hr> </td></tr>"; $OutBuf .= "<tr>"; $OutBuf .= "<th {$NoUploadStyle}></th>"; $OutBuf .= "<th colspan=4 {$NoUploadStyle}>"; $OutBuf .= $Job["job"]["job_name"]; $OutBuf .= "</th>"; $OutBuf .= "<th {$NoUploadStyle}></th>"; $OutBuf .= "</tr>"; } /* Job data */ $OutBuf .= "<tr>"; $OutBuf .= "<th {$jobStyle}>"; $OutBuf .= _("Job/Dependency"); $OutBuf .= "</th>"; $OutBuf .= "<th {$jobStyle}>"; $OutBuf .= _("Status"); $OutBuf .= "</th>"; $OutBuf .= "<th colspan=3 {$jobStyle}>"; $OutBuf .= $Job["job"]["job_name"]; $OutBuf .= "</th>"; $OutBuf .= "<th {$jobStyle}>"; $OutBuf .= "</th></tr>"; /* Job queue */ foreach ($Job['jobqueue'] as $jq_pk => $jobqueueRec) { $RowColor = $this->GetColor($jobqueueRec); $jobqueueStyle = $this->jobqueueStyle($RowColor); $OutBuf .= "<tr {$jobqueueStyle}>"; /* Job/Dependency */ $OutBuf .= "<td {$jobqueueStyle}>"; $OutBuf .= "<a href='{$UriFull}&show=job&job=" . $jq_pk . "'>"; $OutBuf .= $jq_pk; $OutBuf .= "</a>"; $count = 0; if (!empty($jobqueueRec["depends"])) { foreach ($jobqueueRec["depends"] as $depend_jq_pk) { $OutBuf .= $count++ == 0 ? " / " : ", "; $OutBuf .= "<a href='{$UriFull}&show=job&job=" . $depend_jq_pk . "'>"; $OutBuf .= $depend_jq_pk; $OutBuf .= "</a>"; } } $OutBuf .= "</td>"; /* status */ $Status = $jobqueueRec["jq_endtext"]; $OutBuf .= "<td style='text-align:center'>{$Status}</td>"; $isPaused = $Status == "Paused" ? true : false; /* agent name */ $OutBuf .= "<td>{$jobqueueRec['jq_type']}</td>"; /* items processed */ if ($jobqueueRec["jq_itemsprocessed"] > 0) { $items = number_format($jobqueueRec['jq_itemsprocessed']); $OutBuf .= "<td style='text-align:right'>{$items} items</td>"; } else { $OutBuf .= "<td></td>"; } /* dates */ $OutBuf .= "<td>"; $OutBuf .= substr($jobqueueRec['jq_starttime'], 0, 16); if (!empty($jobqueueRec["jq_endtime"])) { $OutBuf .= " - " . substr($jobqueueRec['jq_endtime'], 0, 16); $NumSecs = strtotime($jobqueueRec['jq_endtime']) - strtotime($jobqueueRec['jq_starttime']); } else { $NumSecs = time() - strtotime($jobqueueRec['jq_starttime']); } /* Don't display items/sec unless the job has started */ if ($jobqueueRec['jq_starttime']) { if ($NumSecs > 0) { $ItemsPerSec = round($jobqueueRec['jq_itemsprocessed'] / $NumSecs); if ($ItemsPerSec < 1) { $OutBuf .= sprintf(" : (%01.2f items/sec)", $jobqueueRec['jq_itemsprocessed'] / $NumSecs); } else { $OutBuf .= sprintf(" : (%d items/sec)", $ItemsPerSec); } } } $OutBuf .= "</td>"; /* actions, must be admin or own the upload */ if ($jobqueueRec['jq_end_bits'] == 0 && ($_SESSION["UserLevel"] == PLUGIN_DB_ADMIN || $_SESSION["UserId"] == $Job['job']['job_user_fk'])) { $OutBuf .= "<th {$jobStyle}>"; if ($isPaused) { $text = _("Unpause"); $OutBuf .= "<a href='{$UriFull}&action=restart&jobid={$jq_pk}' title='Un-Pause this job'>{$text}</a>"; } else { $text = _("Pause"); $OutBuf .= "<a href='{$UriFull}&action=pause&jobid={$jq_pk}' title='Pause this job'>{$text}</a>"; } $OutBuf .= " | "; $text = _("Cancel"); $OutBuf .= "<a href='{$UriFull}&action=cancel&jobid={$jq_pk}' title='Cancel this job'>{$text}</a>"; } else { $OutBuf .= "<th>"; } $OutBuf .= "</th></tr>"; } } $OutBuf .= "</table>\n"; if ($NumJobs > $this->MaxUploadsPerPage) { $OutBuf .= "<p>" . MenuEndlessPage($Page, $Next); } return $OutBuf; }
/** * @brief Returns an upload job status in html * @param $jobData * @return Returns an upload job status in html **/ protected function show($jobData, $page) { global $container; /** @var DbManager */ $dbManager = $container->get('db.manager'); $outBuf = ''; $pagination = ''; $numJobs = count($jobData); if ($numJobs == 0) { return array('showJobsData' => "There are no jobs to display"); } $uri = Traceback_uri() . "?mod=showjobs"; $uriFull = $uri . Traceback_parm_keep(array("upload")); $uriFullMenu = $uri . Traceback_parm_keep(array("allusers")); /* Next/Prev menu */ $next = $numJobs > $this->maxUploadsPerPage; if ($numJobs > $this->maxUploadsPerPage) { $pagination .= MenuEndlessPage($page, $next, $uriFullMenu); } /*****************************************************************/ /* Now display the summary */ /*****************************************************************/ $job = -1; $uploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:white;'"; $noUploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:black;'"; $jobStyle = "style='font:bold 8pt verdana, arial, helvetica; background:lavender; color:black;'"; $prevupload_pk = ""; $firstJob = $page * $this->maxUploadsPerPage; $lastJob = $page * $this->maxUploadsPerPage + $this->maxUploadsPerPage; $jobNumber = -1; /** if $single_browse is 1, represent alread has an upload browse link, if single_browse is 0, no upload browse link */ $single_browse = 0; foreach ($jobData as $job) { /* Upload */ if (!empty($job["upload"])) { $uploadName = GetArrayVal("upload_filename", $job["upload"]); $uploadDesc = GetArrayVal("upload_desc", $job["upload"]); $upload_pk = GetArrayVal("upload_pk", $job["upload"]); $jobId = GetArrayVal("job_pk", $job["job"]); /** the column pfile_fk of the record in the table(upload) is NULL when this record is inserted */ if (!empty($upload_pk) && $prevupload_pk != $upload_pk || empty($upload_pk) && 0 == $single_browse) { $prevupload_pk = $upload_pk; $jobNumber++; /* Only display the jobs for this page */ if ($jobNumber >= $lastJob) { break; } if ($jobNumber < $firstJob) { continue; } /* blank line separator between pfiles */ $outBuf .= "<tr><td colspan=8> <hr> </td></tr>"; $outBuf .= "<tr>"; $outBuf .= "<th {$uploadStyle}></th>"; $outBuf .= "<th colspan=6 {$uploadStyle}>"; if (!empty($job['uploadtree'])) { $uploadtree_pk = $job['uploadtree']['uploadtree_pk']; $outBuf .= "<a title='Click to browse' href='" . Traceback_uri() . "?mod=browse&upload=" . $job['job']['job_upload_fk'] . "&item=" . $uploadtree_pk . "'>"; } else { $outBuf .= "<a {$noUploadStyle}>"; } /* get $userName if all jobs are shown */ $userName = ""; $allusers = GetParm("allusers", PARM_INTEGER); if ($allusers > 0) { $statementName = __METHOD__ . "UploadRec"; $uploadRec = $dbManager->getSingleRow("select * from upload where upload_pk=\$1", array($job['job']['job_upload_fk']), $statementName); if (!empty($uploadRec['user_fk'])) { $statementName = __METHOD__ . "UserRec"; $userRec = $dbManager->getSingleRow("select * from users where user_pk=\$1", array($uploadRec['user_fk']), $statementName); $userName = "******"; } else { $statementName = __METHOD__ . "UserRec1"; $userRec = $dbManager->getSingleRow("select * from users where user_pk=\$1", array($job['job']['job_user_fk']), $statementName); $userName = "******"; } } $outBuf .= $uploadName . $userName; if (!empty($uploadDesc)) { $outBuf .= " (" . $uploadDesc . ")"; } $outBuf .= "</a>"; $outBuf .= "</th>"; $outBuf .= "<th {$uploadStyle}><a>" . $this->showJobsDao->getEstimatedTime($jobId) . "</a></th>"; $outBuf .= "</tr>"; $single_browse = 1; } else { if ($jobNumber < $firstJob) { continue; } } } else { /* Show Jobs that are not attached to an upload */ $jobNumber++; /* Only display the jobs for this page */ if ($jobNumber >= $lastJob) { break; } if ($jobNumber < $firstJob) { continue; } /* blank line separator between pfiles */ $outBuf .= "<tr><td colspan=8> <hr> </td></tr>"; $outBuf .= "<tr>"; $outBuf .= "<th {$noUploadStyle}></th>"; $outBuf .= "<th colspan=6 {$noUploadStyle}>"; $outBuf .= htmlentities($job["job"]["job_name"], ENT_QUOTES); $outBuf .= "</th>"; $outBuf .= "<th {$noUploadStyle}></th>"; $outBuf .= "</tr>"; } /* Job data */ $outBuf .= "<tr>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("Job/Dependency"); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("Status"); $outBuf .= "</th>"; $outBuf .= "<th colspan=3 {$jobStyle}>"; $outBuf .= htmlentities($job["job"]["job_name"], ENT_QUOTES); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("Average items/sec"); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("ETA"); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= "</th></tr>"; /* Job queue */ foreach ($job['jobqueue'] as $jq_pk => $jobqueueRec) { $varJobQueueRow = array('jqId' => $jq_pk, 'jobId' => $jobqueueRec['jq_job_fk'], 'class' => $this->getClass($jobqueueRec), 'uriFull' => $uriFull, 'depends' => $jobqueueRec['jdep_jq_depends_fk'] ? $jobqueueRec['depends'] : array(), 'status' => $jobqueueRec['jq_endtext'], 'agentName' => $jobqueueRec['jq_type'], 'itemsProcessed' => $jobqueueRec['jq_itemsprocessed'], 'startTime' => substr($jobqueueRec['jq_starttime'], 0, 16), 'endTime' => empty($jobqueueRec["jq_endtime"]) ? '' : substr($jobqueueRec['jq_endtime'], 0, 16), 'endText' => $jobqueueRec['jq_endtext']); if (!empty($jobqueueRec["jq_endtime"])) { $numSecs = strtotime($jobqueueRec['jq_endtime']) - strtotime($jobqueueRec['jq_starttime']); } else { $numSecs = time() - strtotime($jobqueueRec['jq_starttime']); } $itemsPerSec = null; if ($jobqueueRec['jq_starttime']) { $itemsPerSec = $this->showJobsDao->getNumItemsPerSec($jobqueueRec['jq_itemsprocessed'], $numSecs); $varJobQueueRow['itemsPerSec'] = $itemsPerSec; } if (empty($jobqueueRec['jq_endtime'])) { $varJobQueueRow['eta'] = $this->showJobsDao->getEstimatedTime($jobId, $jobqueueRec['jq_type'], $itemsPerSec, $job['job']['job_upload_fk']); } $varJobQueueRow['canDoActions'] = $_SESSION[Auth::USER_LEVEL] == PLUGIN_DB_ADMIN || Auth::getUserId() == $job['job']['job_user_fk']; $varJobQueueRow['isInProgress'] = $jobqueueRec['jq_end_bits'] == 0; $varJobQueueRow['isReady'] = $jobqueueRec['jq_end_bits'] == 1; switch ($jobqueueRec['jq_type']) { case 'readmeoss': $varJobQueueRow['download'] = "ReadMeOss"; break; case 'spdx2': $varJobQueueRow['download'] = "SPDX2 report"; break; case 'spdx2tv': $varJobQueueRow['download'] = "SPDX2 tag/value report"; break; case 'dep5': $varJobQueueRow['download'] = "DEP5 copyright file"; break; default: $varJobQueueRow['download'] = ""; } $outBuf .= $this->renderString('ui-showjobs-jobqueue-row.html.twig', $varJobQueueRow); } } if ($numJobs > $this->maxUploadsPerPage) { $pagination = "<p>" . MenuEndlessPage($page, $next, $uriFullMenu); } return array('showJobsData' => $outBuf, 'pagination' => $pagination); }
/** * \brief Show Sightings, List the directory locations where this pfile is found */ function ShowSightings($Upload, $Item) { global $PG_CONN; $V = ""; if (empty($Upload) || empty($Item)) { return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } $Max = 50; $Offset = $Page * $Max; /********************************** List the directory locations where this pfile is found **********************************/ $text = _("Sightings"); $V .= "<H2>{$text}</H2>\n"; $sql = "SELECT * FROM pfile,uploadtree\n WHERE pfile_pk=pfile_fk\n AND pfile_pk IN\n (SELECT pfile_fk FROM uploadtree WHERE uploadtree_pk = {$Item})\n LIMIT {$Max} OFFSET {$Offset}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $Count = pg_num_rows($result); if ($Page > 0 || $Count >= $Max) { $VM = "<P />\n" . MenuEndlessPage($Page, $Count >= $Max) . "<P />\n"; } else { $VM = ""; } if ($Count > 0) { $V .= _("This exact file appears in the following locations:\n"); $V .= $VM; $Offset++; $V .= Dir2FileList($result, "browse", "view", $Offset); $V .= $VM; } else { if ($Page > 0) { $V .= _("End of listing.\n"); } else { $V .= _("This file does not appear in any other known location.\n"); } } pg_free_result($result); return $V; }
/** * \brief Display the loaded menu and plugins. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; global $Plugins; $Time = time(); $Max = 50; switch ($this->OutputType) { case "XML": break; case "HTML": $UploadTreePk = GetParm("item", PARM_INTEGER); $Page = GetParm("page", PARM_INTEGER); $WantLic = GetParm("lic", PARM_RAW); $WantLic = str_replace("\\'", "'", $WantLic); if (empty($UploadTreePk) || empty($WantLic)) { return; } if (empty($Page)) { $Page = 0; } $Offset = $Page * $Max; /* Get License Name */ $text = _("The following files contain the license"); $V .= "{$text} '<b>"; $V .= htmlentities($WantLic); $V .= "</b>'.\n"; /* Load licenses */ $Lics = array(); $Offset = $Page * $Max; $Lics = LicenseSearch($UploadTreePk, $WantLic, $Offset, $Max); /* Save the license results */ $Count = count($Lics); /* Get the page menu */ if ($Count >= $Max || $Page > 0) { $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n"; $V .= $VM; } else { $VM = ""; } /* Offset is +1 to start numbering from 1 instead of zero */ $V .= Dir2FileList($Lics, "browse", "view-license", $Offset + 1, 1); if (!empty($VM)) { $V .= $VM . "\n"; } $V .= "<hr>\n"; $Time = time() - $Time; $text = _("Elaspsed time:"); $text1 = _("seconds"); $V .= "<small>{$text} {$Time} {$text1}</small>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print $V; return; }
/** * \brief Display the loaded menu and plugins. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $Plugins; global $PG_CONN; // make sure there is a db connection if (!$PG_CONN) { echo _("NO DB connection"); } $OutBuf = ""; $Time = microtime(true); $Max = 50; /* Input parameters */ $agent_pk = GetParm("agent", PARM_INTEGER); $uploadtree_pk = GetParm("item", PARM_INTEGER); $hash = GetParm("hash", PARM_RAW); $type = GetParm("type", PARM_RAW); $excl = GetParm("excl", PARM_RAW); $filter = GetParm("filter", PARM_RAW); if (empty($uploadtree_pk) || empty($hash) || empty($type) || empty($agent_pk)) { $text = _("is missing required parameters"); echo $this->Name . " {$text}."; return; } /* Check item1 and item2 upload permissions */ $Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}"); $UploadPerm = GetUploadPerm($Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } /* get all rows */ $rows = $this->GetRows($uploadtree_pk, $agent_pk, $upload_pk); /* Get uploadtree_tablename */ $uploadtree_tablename = GetUploadtreeTableName($upload_pk); /* slim down to all rows with this hash and type, and filter */ $NumInstances = 0; $rows = $this->GetRequestedRows($rows, $hash, $type, $excl, $NumInstances, $filter); //debugprint($rows, "rows"); switch ($this->OutputType) { case "XML": break; case "HTML": // micro menus $OutBuf .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); $RowCount = count($rows); if ($RowCount) { $Content = htmlentities($rows[0]['content']); $Offset = $Page < 0 ? 0 : $Page * $Max; $PkgsOnly = false; $text = _("files"); $text1 = _("unique"); $text3 = _("copyright"); $text4 = _("email"); $text5 = _("url"); switch ($type) { case "statement": $TypeStr = "{$text3}"; break; case "email": $TypeStr = "{$text4}"; break; case "url": $TypeStr = "{$text5}"; break; } $OutBuf .= "{$NumInstances} {$TypeStr} instances found in {$RowCount} {$text}"; $OutBuf .= ": <b>{$Content}</b>"; $text = _("Display excludes files with these extensions"); if (!empty($excl)) { $OutBuf .= "<br>{$text}: {$excl}"; } /* Get the page menu */ if ($RowCount >= $Max && $Page >= 0) { $PagingMenu = "<P />\n" . MenuEndlessPage($Page, intval(($RowCount + $Offset) / $Max)) . "<P />\n"; $OutBuf .= $PagingMenu; } else { $PagingMenu = ""; } /* Offset is +1 to start numbering from 1 instead of zero */ $RowNum = $Offset; $LinkLast = "copyrightview&agent={$agent_pk}"; $ShowBox = 1; $ShowMicro = NULL; // base url $ucontent = rawurlencode($Content); $baseURL = "?mod=" . $this->Name . "&agent={$agent_pk}&item={$uploadtree_pk}&hash={$hash}&type={$type}&page=-1"; // display rows foreach ($rows as $row) { // Allow user to exclude files with this extension $FileExt = GetFileExt($row['ufile_name']); if (empty($excl)) { $URL = $baseURL . "&excl={$FileExt}"; } else { $URL = $baseURL . "&excl={$excl}:{$FileExt}"; } $text = _("Exclude this file type"); $Header = "<a href={$URL}>{$text}.</a>"; $ok = true; if ($excl) { $ExclArray = explode(":", $excl); if (in_array($FileExt, $ExclArray)) { $ok = false; } } if ($ok) { $OutBuf .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLast, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); } } } else { $OutBuf .= _("No files found"); } if (!empty($PagingMenu)) { $OutBuf .= $PagingMenu . "\n"; } $OutBuf .= "<hr>\n"; $Time = microtime(true) - $Time; $text = _("Elapsed time"); $text1 = _("seconds"); $OutBuf .= sprintf("<small>{$text}: %.2f {$text1}</small>\n", $Time); break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $OutBuf; } print $OutBuf; return; }
/** * \brief Display the loaded menu and plugins. */ function Output() { $uploadtree_pk = GetParm("item", PARM_INTEGER); $rf_shortname = GetParm("lic", PARM_RAW); $tag_pk = GetParm("tag", PARM_INTEGER); $Excl = GetParm("excl", PARM_RAW); $Exclic = GetParm("exclic", PARM_RAW); if (empty($uploadtree_pk) || empty($rf_shortname)) { $text = _("is missing required parameters."); return $this->Name . " {$text}"; } $Max = 50; $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } // Get upload_pk and $uploadtree_tablename $UploadtreeRec = GetSingleRec("uploadtree", "where uploadtree_pk={$uploadtree_pk}"); global $container; /** @var UploadDao */ $uploadDao = $container->get('dao.upload'); $uploadtree_tablename = $uploadDao->getUploadtreeTableName($UploadtreeRec['upload_fk']); // micro menus $V = menu_to_1html(menu_find($this->Name, $MenuDepth), 0); /* Load licenses */ $Offset = $Page < 0 ? 0 : $Page * $Max; $order = ""; $PkgsOnly = false; // Count is uploadtree recs, not pfiles $agentId = GetParm('agentId', PARM_INTEGER); if (empty($agentId)) { $agentId = "any"; } $CountArray = $this->countFilesWithLicense($agentId, $rf_shortname, $uploadtree_pk, $tag_pk, $uploadtree_tablename); if (empty($CountArray)) { $V .= _("<b> No files found for license {$rf_shortname} !</b>\n"); } else { $Count = $CountArray['count']; $Unique = $CountArray['unique']; $text = _("files found"); $text2 = _("with license"); $V .= "{$Unique} {$text} {$text2} <b>{$rf_shortname}</b>"; if ($Count < $Max) { $Max = $Count; } $limit = $Page < 0 ? "ALL" : $Max; $order = " order by ufile_name asc"; /** should delete $filesresult yourself */ $filesresult = GetFilesWithLicense($agentId, $rf_shortname, $uploadtree_pk, $PkgsOnly, $Offset, $limit, $order, $tag_pk, $uploadtree_tablename); $NumFiles = pg_num_rows($filesresult); $file_result_temp = pg_fetch_all($filesresult); $sorted_file_result = array(); // the final file list will display $max_num = $NumFiles; /** sorting by ufile_name from DB, then reorder the duplicates indented */ for ($i = 0; $i < $max_num; $i++) { $row = $file_result_temp[$i]; if (empty($row)) { continue; } array_push($sorted_file_result, $row); for ($j = $i + 1; $j < $max_num; $j++) { $row_next = $file_result_temp[$j]; if (!empty($row_next) && $row['pfile_fk'] == $row_next['pfile_fk']) { array_push($sorted_file_result, $row_next); $file_result_temp[$j] = null; } } } $text = _("Display"); $text1 = _("excludes"); $text2 = _("files with these extensions"); if (!empty($Excl)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Excl}"; } $text2 = _("files with these licenses"); if (!empty($Exclic)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Exclic}"; } /* Get the page menu */ if ($Max > 0 && $Count >= $Max && $Page >= 0) { $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n"; $V .= $VM; } else { $VM = ""; } /* Offset is +1 to start numbering from 1 instead of zero */ $RowNum = $Offset; $LinkLast = "view-license"; $ShowBox = 1; $ShowMicro = NULL; // base url $ushortname = rawurlencode($rf_shortname); $baseURL = "?mod=" . $this->Name . "&item={$uploadtree_pk}&lic={$ushortname}&page=-1"; $V .= "<table>"; $text = _("File"); $V .= "<tr><th>{$text}</th><th> "; $LastPfilePk = -1; $ExclArray = explode(":", $Excl); $ExclicArray = explode(":", $Exclic); foreach ($sorted_file_result as $row) { $pfile_pk = $row['pfile_fk']; $licstring = GetFileLicenses_string($row['agent_pk'], $pfile_pk, $row['uploadtree_pk'], $uploadtree_tablename); $URLlicstring = urlencode($licstring); // Allow user to exclude files with this extension $FileExt = GetFileExt($row['ufile_name']); $URL = $baseURL; if (!empty($Excl)) { $URL .= "&excl={$Excl}:{$FileExt}"; } else { $URL .= "&excl={$FileExt}"; } if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic); } $text = _("Exclude this file type."); $Header = "<a href={$URL}>{$text}</a>"; /* Allow user to exclude files with this exact license list */ $URL = $baseURL; if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic) . ":" . $URLlicstring; } else { $URL .= "&exclic={$URLlicstring}"; } if (!empty($Excl)) { $URL .= "&excl={$Excl}"; } $text = _("Exclude files with license"); $Header .= "<br><a href={$URL}>{$text}: {$licstring}.</a>"; $excludeByType = $Excl && in_array($FileExt, $ExclArray); $excludeByLicense = $Exclic && in_array($licstring, $ExclicArray); if (!empty($licstring) && !$excludeByType && !$excludeByLicense) { $V .= "<tr><td>"; /* Tack on pfile to url - information only */ $LinkLastpfile = $LinkLast . "&pfile={$pfile_pk}"; if ($LastPfilePk == $pfile_pk) { $indent = "<div style='margin-left:2em;'>"; $outdent = "</div>"; } else { $indent = ""; $outdent = ""; } $V .= $indent; $V .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLastpfile, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); $V .= $outdent; $V .= "</td>"; $V .= "<td> </td>"; $V .= "<td>{$row['agent_name']}: {$licstring}</td></tr>"; $V .= "<tr><td colspan=3><hr></td></tr>"; } $LastPfilePk = $pfile_pk; } pg_free_result($filesresult); $V .= "</table>"; if (!empty($VM)) { $V .= $VM . "\n"; } } return $V; }
/** * \brief Show Sightings, List the directory locations where this pfile is found */ function ShowSightings($Upload, $Item) { $V = ""; if (empty($Upload) || empty($Item)) { return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } $Max = 50; $Offset = $Page * $Max; /********************************** List the directory locations where this pfile is found **********************************/ $text = _("Sightings"); $V .= "<H2>{$text}</H2>\n"; $sql = "SELECT * FROM pfile,uploadtree\n WHERE pfile_pk=pfile_fk\n AND pfile_pk IN\n (SELECT pfile_fk FROM uploadtree WHERE uploadtree_pk = \$1)\n LIMIT \$2 OFFSET \$3"; $this->dbManager->prepare(__METHOD__ . "getListOfFiles", $sql); $result = $this->dbManager->execute(__METHOD__ . "getListOfFiles", array($Item, $Max, $Offset)); $Count = pg_num_rows($result); if ($Page > 0 || $Count >= $Max) { $VM = "<P />\n" . MenuEndlessPage($Page, $Count >= $Max) . "<P />\n"; } else { $VM = ""; } if ($Count > 0) { $V .= _("This exact file appears in the following locations:\n"); $V .= $VM; $Offset++; $V .= Dir2FileList($result, "browse", "view", $Offset); $V .= $VM; } else { if ($Page > 0) { $V .= _("End of listing.\n"); } else { $V .= _("This file does not appear in any other known location.\n"); } } pg_free_result($result); return $V; }
/** * \brief Display the loaded menu and plugins. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $Plugins; $V = ""; $Time = time(); $Max = 50; /* Input parameters */ $nomosagent_pk = GetParm("napk", PARM_INTEGER); $uploadtree_pk = GetParm("item", PARM_INTEGER); $rf_shortname = GetParm("lic", PARM_RAW); $tag_pk = GetParm("tag", PARM_INTEGER); $Excl = GetParm("excl", PARM_RAW); $Exclic = GetParm("exclic", PARM_RAW); $rf_shortname = rawurldecode($rf_shortname); if (empty($uploadtree_pk) || empty($rf_shortname)) { $text = _("is missing required parameters."); echo $this->Name . " {$text}"; return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } // Get upload_pk and $uploadtree_tablename $UploadtreeRec = GetSingleRec("uploadtree", "where uploadtree_pk={$uploadtree_pk}"); $UploadRec = GetSingleRec("upload", "where upload_pk={$UploadtreeRec['upload_fk']}"); $uploadtree_tablename = $UploadRec['uploadtree_tablename']; switch ($this->OutputType) { case "XML": break; case "HTML": // micro menus $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); /* Load licenses */ $Offset = $Page < 0 ? 0 : $Page * $Max; $order = ""; $PkgsOnly = false; $CheckOnly = false; // Count is uploadtree recs, not pfiles $CountArray = CountFilesWithLicense($nomosagent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly, $CheckOnly, $tag_pk, $uploadtree_tablename); $Count = $CountArray['count']; $Unique = $CountArray['unique']; $text = _("files found"); $text1 = _("unique"); $text2 = _("with license"); $V .= "{$Count} {$text} ({$Unique} {$text1}) {$text2} <b>{$rf_shortname}</b>"; if ($Count < $Max) { $Max = $Count; } $limit = $Page < 0 ? "ALL" : $Max; $order = " order by ufile_name asc"; /** should delete $filesresult yourself */ $filesresult = GetFilesWithLicense($nomosagent_pk, $rf_shortname, $uploadtree_pk, $PkgsOnly, $Offset, $limit, $order, $tag_pk, $uploadtree_tablename); $NumFiles = pg_num_rows($filesresult); $file_result_temp = pg_fetch_all($filesresult); $sorted_file_result = array(); // the final file list will display $max_num = $NumFiles; /** sorting by ufile_name from DB, then reorder the duplicates indented */ for ($i = 0; $i < $max_num; $i++) { $row = $file_result_temp[$i]; if (empty($row)) { continue; } array_push($sorted_file_result, $row); for ($j = $i + 1; $j < $max_num; $j++) { $row_next = $file_result_temp[$j]; if (!empty($row_next) && $row['pfile_fk'] == $row_next['pfile_fk']) { array_push($sorted_file_result, $row_next); $file_result_temp[$j] = null; } } } $text = _("Display"); $text1 = _("excludes"); $text2 = _("files with these extensions"); if (!empty($Excl)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Excl}"; } $text2 = _("files with these licenses"); if (!empty($Exclic)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Exclic}"; } /* Get the page menu */ if ($Max > 0 && $Count >= $Max && $Page >= 0) { $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n"; $V .= $VM; } else { $VM = ""; } /* Offset is +1 to start numbering from 1 instead of zero */ $RowNum = $Offset; $LinkLast = "view-license&napk={$nomosagent_pk}"; $ShowBox = 1; $ShowMicro = NULL; // base url $ushortname = rawurlencode($rf_shortname); $baseURL = "?mod=" . $this->Name . "&napk={$nomosagent_pk}&item={$uploadtree_pk}&lic={$ushortname}&page=-1"; $V .= "<table>"; $text = _("File"); $V .= "<tr><th>{$text}</th><th> "; $LastPfilePk = -1; $ExclArray = explode(":", $Excl); $ExclicArray = explode(":", $Exclic); foreach ($sorted_file_result as $row) { $pfile_pk = $row['pfile_fk']; $licstring = GetFileLicenses_string($nomosagent_pk, $pfile_pk, $row['uploadtree_pk'], $uploadtree_tablename); $URLlicstring = urlencode($licstring); // Allow user to exclude files with this extension $FileExt = GetFileExt($row['ufile_name']); $URL = $baseURL; if (!empty($Excl)) { $URL .= "&excl={$Excl}:{$FileExt}"; } else { $URL .= "&excl={$FileExt}"; } if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic); } $text = _("Exclude this file type."); $Header = "<a href={$URL}>{$text}</a>"; /* Allow user to exclude files with this exact license list */ $URL = $baseURL; if (!empty($Exclic)) { $URL .= "&exclic=" . urlencode($Exclic) . ":" . $URLlicstring; } else { $URL .= "&exclic={$URLlicstring}"; } if (!empty($Excl)) { $URL .= "&excl={$Excl}"; } $text = _("Exclude files with license"); $Header .= "<br><a href={$URL}>{$text}: {$licstring}.</a>"; $ok = true; /* exclude by type */ if ($Excl) { if (in_array($FileExt, $ExclArray)) { $ok = false; } } /* exclude by license */ if ($Exclic) { if (in_array($licstring, $ExclicArray)) { $ok = false; } } if (empty($licstring)) { $ok = false; } if ($ok) { $V .= "<tr><td>"; /* Tack on pfile to url - information only */ $LinkLastpfile = $LinkLast . "&pfile={$pfile_pk}"; if ($LastPfilePk == $pfile_pk) { $indent = "<div style='margin-left:2em;'>"; $outdent = "</div>"; } else { $indent = ""; $outdent = ""; } $V .= $indent; $V .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLastpfile, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); $V .= $outdent; $V .= "</td>"; $V .= "<td> </td>"; // spaces to seperate licenses // show the entire license list as a single string with links to the files // in this container with that license. $V .= "<td>{$licstring}</td></tr>"; $V .= "<tr><td colspan=3><hr></td></tr>"; // separate files } $LastPfilePk = $pfile_pk; } pg_free_result($filesresult); $V .= "</table>"; if (!empty($VM)) { $V .= $VM . "\n"; } $V .= "<hr>\n"; $Time = time() - $Time; $text = _("Elapsed time"); $text1 = _("seconds"); $V .= "<small>{$text}: {$Time} {$text1}</small>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print $V; return; }
/** * \brief Display all the files for a bucket in this subtree. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $Plugins; global $PG_CONN; /* Input parameters */ $bucketagent_pk = GetParm("bapk", PARM_INTEGER); $uploadtree_pk = GetParm("item", PARM_INTEGER); $bucket_pk = GetParm("bpk", PARM_INTEGER); $bucketpool_pk = GetParm("bp", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $BinNoSrc = GetParm("bns", PARM_INTEGER); // 1 if requesting binary with no src $Excl = GetParm("excl", PARM_RAW); if (empty($uploadtree_pk) || empty($bucket_pk) || empty($bucketpool_pk)) { $text = _("is missing required parameters."); echo $this->Name . " {$text}"; return; } /* Check upload permission */ $Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}"); $UploadPerm = GetUploadPerm($Row['upload_fk']); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text} item 1<h2>"; return; } $Page = GetParm("page", PARM_INTEGER); if (empty($Page)) { $Page = 0; } $V = ""; $Time = time(); $Max = 200; // Create cache of bucket_pk => bucket_name // Since we are going to do a lot of lookups $sql = "select bucket_pk, bucket_name from bucket_def where bucketpool_fk={$bucketpool_pk}"; $result_name = pg_query($PG_CONN, $sql); DBCheckResult($result_name, $sql, __FILE__, __LINE__); $bucketNameCache = array(); while ($name_row = pg_fetch_assoc($result_name)) { $bucketNameCache[$name_row['bucket_pk']] = $name_row['bucket_name']; } pg_free_result($result_name); switch ($this->OutputType) { case "XML": break; case "HTML": // micro menus $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0); /* Get all the files under this uploadtree_pk with this bucket */ $V .= _("The following files are in bucket: '<b>"); $V .= $bucketNameCache[$bucket_pk]; $V .= "</b>'.\n"; $text = _("Display"); $text1 = _("excludes"); $text2 = _("files with these licenses"); if (!empty($Excl)) { $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Excl}"; } $Offset = $Page <= 0 ? 0 : $Page * $Max; $PkgsOnly = false; // Get bounds of subtree (lft, rgt) for this uploadtree_pk $sql = "SELECT lft,rgt,upload_fk FROM uploadtree\n WHERE uploadtree_pk = {$uploadtree_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; pg_free_result($result); /* Get uploadtree table */ $uploadtree_tablename = GetUploadtreeTableName($upload_pk); /* If $BinNoSrc, then only list binary packages in this subtree * that do not have Source packages. * Else list files in the asked for bucket. */ if ($BinNoSrc) { } else { $Offset = $Page < 0 ? 0 : $Page * $Max; $limit = $Page < 0 ? "ALL" : $Max; // Get all the uploadtree_pk's with this bucket (for this agent and bucketpool) // in this subtree. // It would be best to sort by pfile_pk, so that the duplicate pfiles are // correctly indented, but pfile_pk has no meaning to the user. So a compromise, // sorting by ufile_name is used. $sql = "select uploadtree.*, bucket_file.nomosagent_fk as nomosagent_fk\n from uploadtree, bucket_file, bucket_def\n where upload_fk={$upload_pk} and uploadtree.lft between {$lft} and {$rgt}\n and ((ufile_mode & (1<<28)) = 0)\n and ((ufile_mode & (1<<29))=0)\n and uploadtree.pfile_fk=bucket_file.pfile_fk\n and agent_fk={$bucketagent_pk}\n and bucket_fk={$bucket_pk}\n and bucketpool_fk={$bucketpool_pk}\n and bucket_pk=bucket_fk \n order by uploadtree.ufile_name\n limit {$limit} offset {$Offset}"; $fileresult = pg_query($PG_CONN, $sql); DBCheckResult($fileresult, $sql, __FILE__, __LINE__); $Count = pg_num_rows($fileresult); } $file_result_temp = pg_fetch_all($fileresult); $sourted_file_result = array(); // the final file list will display $max_num = $Count; /** sorting by ufile_name from DB, then reorder the duplicates indented */ for ($i = 0; $i < $max_num; $i++) { $row = $file_result_temp[$i]; if (empty($row)) { continue; } array_push($sourted_file_result, $row); for ($j = $i + 1; $j < $max_num; $j++) { $row_next = $file_result_temp[$j]; if (!empty($row_next) && $row['pfile_fk'] == $row_next['pfile_fk']) { array_push($sourted_file_result, $row_next); $file_result_temp[$j] = null; } } } if ($Count < 1.25 * $Max) { $Max = $Count; } if ($Max < 1) { $Max = 1; } // prevent div by zero in corner case of no files /* Get the page menu */ if ($Count >= $Max && $Page >= 0) { $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n"; $V .= $VM; } else { $VM = ""; } // base url $baseURL = "?mod=" . $this->Name . "&bapk={$bucketagent_pk}&item={$uploadtree_pk}&bpk={$bucket_pk}&bp={$bucketpool_pk}&napk={$nomosagent_pk}&page=-1"; // for each uploadtree rec ($fileresult), find all the licenses in it and it's children $ShowBox = 1; $ShowMicro = NULL; $RowNum = $Offset; $Header = ""; $LinkLast = "list_bucket_files&bapk={$bucketagent_pk}"; /* file display loop/table */ $V .= "<table>"; $text = _("File"); $V .= "<tr><th>{$text}</th><th> "; $ExclArray = explode(":", $Excl); $ItemNumb = 0; $PrevPfile_pk = 0; if ($Count > 0) { foreach ($sourted_file_result as $row) { // get all the licenses in this subtree (bucket uploadtree_pk) $pfile_pk = $row['pfile_fk']; $licstring = GetFileLicenses_string($nomosagent_pk, $row['pfile_fk'], $row['uploadtree_pk'], $uploadtree_tablename); if (empty($licstring)) { $licstring = '-'; } $URLlicstring = urlencode($licstring); /* Allow user to exclude files with this exact license list */ if (!empty($Excl)) { $URL = $baseURL . "&excl=" . urlencode($Excl) . ":" . $URLlicstring; } else { $URL = $baseURL . "&excl={$URLlicstring}"; } $text = _("Exclude files with license"); $Header = "<a href={$URL}>{$text}: {$licstring}.</a>"; $ok = true; if ($Excl) { if (in_array($licstring, $ExclArray)) { $ok = false; } } if ($ok) { $nomosagent_pk = $row['nomosagent_fk']; $LinkLast = "view-license&bapk={$bucketagent_pk}&napk={$nomosagent_pk}"; $V .= "<tr><td>"; if ($PrevPfile_pk == $pfile_pk) { $V .= "<div style='margin-left:2em;'>"; } else { $V .= "<div>"; } $V .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLast, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename); $V .= "</div>"; $V .= "</td>"; $V .= "<td> </td>"; // spaces to seperate licenses // show the entire license list as a single string with links to the files // in this container with that license. $V .= "<td>{$licstring}</td></tr>"; $V .= "<tr><td colspan=3><hr></td></tr>"; // separate files } $PrevPfile_pk = $pfile_pk; } } pg_free_result($fileresult); $V .= "</table>"; if (!empty($VM)) { $V .= $VM . "\n"; } $V .= "<hr>\n"; $Time = time() - $Time; $text = _("Elapsed time"); $text1 = _("seconds"); $V .= "<small>{$text}: {$Time} {$text1}</small>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print $V; return; }