31 $this->Name =
"view_info";
32 $this->Title = _(
"View File Information");
33 $this->Dependency = array(
"browse");
36 parent::__construct();
37 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
38 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
39 $this->userDao = $GLOBALS[
'container']->get(
'dao.user');
47 $tooltipText = _(
"View file information");
48 menu_insert(
"Browse-Pfile::Info", 5, $this->Name, $tooltipText);
51 $URI = $this->Name . $Parm;
61 menu_insert(
"View-Meta::{$menuText}", $menuPosition);
65 $tooltipText = _(
"View information about this file");
68 menu_insert(
"View::{$menuText}", $menuPosition, $URI, $tooltipText);
71 menu_insert(
"View-Meta::{$menuText}", $menuPosition, $URI, $tooltipText);
73 menu_insert(
"Browse::Info", -3, $URI, $tooltipText);
80 function ShowView($Upload, $Item, $ShowMenu = 0)
83 if (empty($Upload) || empty($Item)) {
91 $vars[
'repoLocPage'] = $Page;
99 $sql =
"SELECT * FROM uploadtree
100 INNER JOIN pfile ON uploadtree_pk = $1
101 AND pfile_fk = pfile_pk
106 __METHOD__ .
"GetFileDescribingRow"
108 $bytes = $row[
'pfile_size'];
110 $bytes = number_format($bytes, 0,
"",
",") .
' B';
111 if ($bytesH == $bytes) {
114 $bytesH =
'(' . $bytesH .
')';
116 $vars[
'sizeInBytes'] = $bytes;
117 $vars[
'sizeInMB'] = $bytesH;
118 $vars[
'fileSha1'] = $row[
'pfile_sha1'];
119 $vars[
'fileMd5'] = $row[
'pfile_md5'];
120 $vars[
'fileSha256'] = $row[
'pfile_sha256'];
121 $vars[
'fileSize'] = $row[
'pfile_size'];
122 $vars[
'filePfileId'] = $row[
'pfile_fk'];
133 if (empty($Upload) || empty($Item)) {
142 $offset = $page * $MAX;
146 $sql =
"SELECT * FROM pfile,uploadtree
147 WHERE pfile_pk=pfile_fk
149 (SELECT pfile_fk FROM uploadtree WHERE uploadtree_pk = $1)
151 $this->
dbManager->prepare(__METHOD__ .
"getListOfFiles", $sql);
152 $result = $this->
dbManager->execute(__METHOD__ .
"getListOfFiles", array($Item,$MAX,$offset));
153 $count = pg_num_rows($result);
154 if (($page > 0) || ($count >= $MAX)) {
155 $vMenu =
"<p>\n" .
MenuEndlessPage($page, ($count >= $MAX)) .
"</p>\n";
160 $v .= _(
"This exact file appears in the following locations:\n");
165 } elseif ($page > 0) {
166 $v .= _(
"End of listing.\n");
168 $v .= _(
"This file does not appear in any other known location.\n");
170 pg_free_result($result);
173 $vars[
'sightingsContent'] = $v;
184 $groupId = Auth::getGroupId();
186 if (empty($Item) || empty($Upload)) {
191 $sql =
"SELECT * FROM uploadtree where uploadtree_pk = $1";
192 $this->
dbManager->prepare(__METHOD__ .
"DisplayMimetype", $sql);
193 $result = $this->
dbManager->execute(__METHOD__ .
"DisplayMimetype", array($Item));
194 if (pg_num_rows($result)) {
195 $vars[
'fileInfo'] = 1;
196 $row = pg_fetch_assoc($result);
198 if (! empty($row[
'mimetype_pk'])) {
199 $vars[
'displayMimeTypeName'] = $row[
'mimetype_name'];
203 $vars[
'fileInfo'] = 0;
209 if (! empty($row[
'pfile_fk'])) {
210 $sql =
"select mimetype_name from pfile, mimetype where pfile_pk = $1 and pfile_mimetypefk=mimetype_pk";
211 $this->
dbManager->prepare(__METHOD__ .
"GetMimetype", $sql);
213 __METHOD__ .
"GetMimetype",
214 array($row[
'pfile_fk'])
216 if (pg_num_rows($result)) {
217 $pmRow = pg_fetch_assoc($result);
218 $vars[
'getMimeTypeName'] = $pmRow[
'mimetype_name'];
224 $sql =
"SELECT agent_enabled FROM agent WHERE agent_name ='scanoss' ORDER BY agent_ts LIMIT 1;";
225 $row = $this->
dbManager->getSingleRow($sql, [],
226 __METHOD__ .
"checkScanOss");
227 if (!empty($row) && $row[
"agent_enabled"] ==
't') {
228 $sql =
"SELECT s.purl, s.matchtype, s.lineranges, s.url, s.filepath " .
229 "FROM scanoss_fileinfo s, uploadtree u where u.uploadtree_pk = $1 and s.pfile_fk = u.pfile_fk;";
230 $pmRow = $this->
dbManager->getSingleRow($sql, [$Item],
231 __METHOD__ .
"GetFileMatchInfo");
233 if (!empty($pmRow)) {
234 $vars[
'purl'] = $pmRow[
'purl'];
235 $vars[
'matchType'] = $pmRow[
'matchtype'];
236 $vars[
'lineRange'] = $pmRow[
'lineranges'];
237 $vars[
'url'] = $pmRow[
'url'];
238 $vars[
'path'] = $pmRow[
'filepath'];
239 $vars[
'scanossInfo'] = 1;
241 $vars[
'scanossInfo'] = 0;
244 $sql =
"select * from upload where upload_pk=$1";
247 array($row[
'upload_fk']),
248 __METHOD__ .
"getUploadOrigin"
252 if ($row[
'upload_mode'] & 1 << 2) {
253 $text = _(
"Added by URL");
254 } elseif ($row[
'upload_mode'] & 1 << 3) {
255 $text = _(
"Added by file upload");
256 } elseif ($row[
'upload_mode'] & 1 << 4) {
257 $text = _(
"Added from filesystem");
259 $vars[
'fileUploadOriginInfo'] = $text;
260 $vars[
'fileUploadOrigin'] = $row[
'upload_origin'];
263 $ts = $row[
'upload_ts'];
264 $vars[
'fileUploadDate'] = substr($ts, 0, strrpos($ts,
'.'));
268 $sql =
"SELECT user_name from users, upload where user_pk = user_fk and upload_pk = $1";
269 $row = $this->
dbManager->getSingleRow($sql, array($Upload), __METHOD__ .
"getUploadOwner");
271 $vars[
'fileUploadUser'] = $row[
'user_name'];
272 $userId = $this->uploadDao->getAssignee($Upload, $groupId);
273 $vars[
'fileAssigneeUser'] = ($userId == 1) ?
'Unassigned' : $this->userDao->getUserName($userId);
274 $assignedDate = $this->uploadDao->getAssigneeDate($Upload);
275 $vars[
'fileAssigneeUserOn'] = empty($assignedDate) ?
'NA' : substr($assignedDate, 0, strrpos($assignedDate,
'.'));
276 $vars[
'fileClearingDuration'] = $this->uploadDao->getClearingDuration($Upload)[0];
292 $rpm_info = array(
"Package" =>
"pkg_name",
293 "Alias" =>
"pkg_alias",
294 "Architecture" =>
"pkg_arch",
295 "Version" =>
"version",
296 "License" =>
"license",
297 "Group" =>
"pkg_group",
298 "Packager" =>
"packager",
299 "Release" =>
"release",
300 "BuildDate" =>
"build_date",
301 "Vendor" =>
"vendor",
303 "Summary" =>
"summary",
304 "Description" =>
"description",
305 "Source" =>
"source_rpm");
307 $deb_binary_info = array(
"Package" =>
"pkg_name",
308 "Architecture" =>
"pkg_arch",
309 "Version" =>
"version",
310 "Section" =>
"section",
311 "Priority" =>
"priority",
312 "Installed Size" =>
"installed_size",
313 "Maintainer" =>
"maintainer",
314 "Homepage" =>
"homepage",
315 "Source" =>
"source",
316 "Summary" =>
"summary",
317 "Description" =>
"description");
319 $deb_source_info = array(
"Format" =>
"format",
320 "Source" =>
"source",
321 "Binary" =>
"pkg_name",
322 "Architecture" =>
"pkg_arch",
323 "Version" =>
"version",
324 "Maintainer" =>
"maintainer",
325 "Uploaders" =>
"uploaders",
326 "Standards-Version" =>
"standards_version");
328 if (empty($Item) || empty($Upload)) {
335 $sql =
"SELECT agent_enabled FROM agent WHERE agent_name ='pkgagent' order by agent_ts LIMIT 1;";
336 $row = $this->
dbManager->getSingleRow($sql, array(), __METHOD__ .
"checkPkgagentDisabled");
337 if (isset($row) && ($row[
'agent_enabled'] ==
'f')) {
342 $sql =
"SELECT typlen FROM pg_type where typname='pkgagent_ars' limit 1;";
343 $this->
dbManager->prepare(__METHOD__ .
"displayPackageInfo", $sql);
344 $result = $this->
dbManager->execute(__METHOD__ .
"displayPackageInfo", array());
345 $numrows = pg_num_rows($result);
348 $vars[
'packageAgentNA'] = 1;
353 $agent_status = AgentARSList(
'pkgagent_ars', $Upload);
354 if (empty($agent_status)) {
355 $vars[
'packageAgentStatus'] = 1;
357 "?mod=schedule_agent&upload=$Upload&agent=agent_pkgagent";
360 $sql =
"SELECT mimetype_name
362 INNER JOIN pfile ON uploadtree_pk = $1
363 AND pfile_fk = pfile_pk
364 INNER JOIN mimetype ON pfile_mimetypefk = mimetype_pk;";
365 $this->
dbManager->prepare(__METHOD__ .
"getMimetypeName", $sql);
366 $result = $this->
dbManager->execute(__METHOD__ .
"getMimetypeName", array($Item));
367 while ($row = pg_fetch_assoc($result)) {
368 if (! empty($row[
'mimetype_name'])) {
369 $MIMETYPE = $row[
'mimetype_name'];
377 if ($MIMETYPE ==
"application/x-rpm") {
380 INNER JOIN uploadtree ON uploadtree_pk = $1
381 AND uploadtree.pfile_fk = pkg_rpm.pfile_fk;";
382 $R = $this->
dbManager->getSingleRow($sql, array($Item), __METHOD__ .
"getRPMPackageInfo");
383 if ((! empty($R[
'source_rpm'])) and (
trim($R[
'source_rpm']) !=
"(none)")) {
384 $vars[
'packageType'] = _(
"RPM Binary Package");
386 $vars[
'packageType'] = _(
"RPM Source Package");
390 if (! empty($R[
'pkg_pk'])) {
391 $Require = $R[
'pkg_pk'];
392 foreach ($rpm_info as $key => $value) {
394 $entry[
'count'] = $Count;
395 $entry[
'type'] = _($key);
396 $entry[
'value'] = htmlspecialchars($R[
"$value"], ENT_QUOTES|ENT_HTML5,
'UTF-8');
398 $vars[
'packageEntries'][] = $entry;
401 $sql =
"SELECT * FROM pkg_rpm_req WHERE pkg_fk = $1;";
402 $this->
dbManager->prepare(__METHOD__ .
"getPkg_rpm_req", $sql);
403 $result = $this->
dbManager->execute(__METHOD__ .
"getPkg_rpm_req", array($Require));
405 while ($R = pg_fetch_assoc($result) and ! empty($R[
'req_pk'])) {
407 $entry[
'count'] = $Count;
408 $entry[
'type'] = _(
"Requires");
409 $entry[
'value'] = htmlspecialchars($R[
"$value"], ENT_QUOTES|ENT_HTML5,
'UTF-8');
411 $vars[
'packageRequires'][] = $entry;
415 } elseif ($MIMETYPE ==
"application/x-debian-package") {
416 $vars[
'packageType'] = _(
"Debian Binary Package\n");
420 INNER JOIN uploadtree ON uploadtree_pk = $1
421 AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
422 $R = $this->
dbManager->getSingleRow($sql, array($Item), __METHOD__ .
"debianBinaryPackageInfo");
426 $Require = $R[
'pkg_pk'];
427 foreach ($deb_binary_info as $key => $value) {
429 $entry[
'count'] = $Count;
430 $entry[
'type'] = _($key);
431 $entry[
'value'] = htmlspecialchars($R[
"$value"], ENT_QUOTES|ENT_HTML5,
'UTF-8');
433 $vars[
'packageEntries'][] = $entry;
436 $sql =
"SELECT * FROM pkg_deb_req WHERE pkg_fk = $1;";
437 $this->
dbManager->prepare(__METHOD__ .
"getPkg_rpm_req", $sql);
438 $result = $this->
dbManager->execute(__METHOD__ .
"getPkg_rpm_req", array($Require));
440 while ($R = pg_fetch_assoc($result) and ! empty($R[
'req_pk'])) {
442 $entry[
'count'] = $Count;
443 $entry[
'type'] = _(
"Depends");
444 $entry[
'value'] = htmlspecialchars($R[
"$value"], ENT_QUOTES|ENT_HTML5,
'UTF-8');
446 $vars[
'packageRequires'][] = $entry;
451 } elseif ($MIMETYPE ==
"application/x-debian-source") {
452 $vars[
'packageType'] = _(
"Debian Source Package\n");
456 INNER JOIN uploadtree ON uploadtree_pk = $1
457 AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
458 $R = $this->
dbManager->getSingleRow($sql, array($Item), __METHOD__ .
"debianSourcePakcageInfo");
462 $Require = $R[
'pkg_pk'];
463 foreach ($deb_source_info as $key => $value) {
465 $entry[
'count'] = $Count;
466 $entry[
'type'] = _($key);
467 $entry[
'value'] = htmlspecialchars($R[
"$value"], ENT_QUOTES|ENT_HTML5,
'UTF-8');
469 $vars[
'packageEntries'][] = $entry;
472 $sql =
"SELECT * FROM pkg_deb_req WHERE pkg_fk = $1;";
473 $this->
dbManager->prepare(__METHOD__ .
"getPkg_rpm_req", $sql);
474 $result = $this->
dbManager->execute(__METHOD__ .
"getPkg_rpm_req", array($Require));
476 while ($R = pg_fetch_assoc($result) and ! empty($R[
'req_pk'])) {
478 $entry[
'count'] = $Count;
479 $entry[
'type'] = _(
"Build-Depends");
480 $entry[
'value'] = htmlspecialchars($R[
"$value"], ENT_QUOTES|ENT_HTML5,
'UTF-8');
482 $vars[
'packageRequires'][] = $entry;
488 $vars[
'packageType'] =
"";
500 $groupId = Auth::getGroupId();
501 $row = $this->uploadDao->getUploadEntry($Item);
503 $vars[
'tagInvalid'] = 1;
508 $upload_pk = $row[
"upload_fk"];
511 $vars[
'tagInvalid'] = 2;
514 $sql =
"SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_file,tag WHERE tag_pk = tag_fk) T
515 ON uploadtree.pfile_fk = T.pfile_fk WHERE uploadtree.upload_fk = $1
516 AND uploadtree.lft >= $2 AND uploadtree.rgt <= $3 UNION SELECT * FROM uploadtree INNER JOIN
517 (SELECT * FROM tag_uploadtree,tag WHERE tag_pk = tag_fk) T ON uploadtree.uploadtree_pk = T.uploadtree_fk
518 WHERE uploadtree.upload_fk = $1 AND uploadtree.lft >= $2 AND uploadtree.rgt <= $3 ORDER BY ufile_name";
519 $this->
dbManager->prepare(__METHOD__, $sql);
520 $result = $this->
dbManager->execute(__METHOD__, array($upload_pk, $lft,$rgt));
521 if (pg_num_rows($result) > 0) {
522 while ($row = pg_fetch_assoc($result)) {
524 $entry[
'ufile_name'] = $row[
'ufile_name'];
525 $entry[
'tag'] = $row[
'tag'];
526 if ($this->uploadDao->isAccessible($upload_pk, $groupId)) {
528 "?mod=tag&action=edit&upload=$Upload&item=" . $row[
'uploadtree_pk'] .
529 "&tag_file_pk=" . $row[
'tag_file_pk'];
533 $vars[
'tagsEntries'][] = $entry;
549 $reusedInfo = $this->uploadDao->getReusedUpload(
553 foreach ($reusedInfo as $row) {
555 $reuseUploadFk = $row[
'reused_upload_fk'];
556 $reuseGroupFk = $row[
'reused_group_fk'];
557 $reusedUpload = $this->uploadDao->getUpload($reuseUploadFk);
558 $reuseMode = array();
559 if ($row[
'reuse_mode'] & UploadDao::REUSE_ENHANCED) {
560 $reuseMode[] =
"Enhanced";
562 $reuseMode[] =
"Normal";
564 if ($row[
'reuse_mode'] & UploadDao::REUSE_MAIN) {
565 $reuseMode[] =
"Main license";
567 if ($row[
'reuse_mode'] & UploadDao::REUSE_CONF) {
568 $reuseMode[] =
"Report configuration settings";
570 $entry[
'name'] = $reusedUpload->getFilename();
572 "?mod=license&upload=$reuseUploadFk&item=" .
573 $this->uploadDao->getUploadParent($reuseUploadFk);
574 $entry[
'group'] = $this->userDao->getGroupNameById($reuseGroupFk) .
576 $entry[
'sha1'] = $this->uploadDao->getUploadHashes($reuseUploadFk)[
'sha1'];
577 $entry[
'mode'] = implode(
", ", $reuseMode) .
" reuse";
579 $vars[
'reusedPackageList'][] = $entry;
587 if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
592 $this->vars[
'micromenu'] =
Dir2Browse(
"browse", $itemId,
null, $showBox = 0,
"View-Meta");
594 $this->vars += $this->
ShowTagInfo($uploadId, $itemId);
595 $this->vars += $this->ShowPackageinfo($uploadId, $itemId, 1);
598 $this->vars += $this->
ShowView($uploadId, $itemId);
602 public function getTemplateName()
604 return "ui-view-info.html.twig";
608 $NewPlugin->Initialize();
This is the Plugin class. All plugins should:
Contains the constants and helpers for authentication of user.
ShowMetaView($Upload, $Item)
Display the meta data associated with the file.
ShowPackageInfo($Upload, $Item, $ShowMenu=0)
Display the package info associated with the rpm/debian package.
Output()
This function is called when user output is requested. This function is responsible for content....
ShowView($Upload, $Item, $ShowMenu=0)
Display the info data associated with the file.
ShowTagInfo($Upload, $Item)
Display the tag info data associated with the file.
showReuseInfo($uploadId)
Get the info regarding reused package.
ShowSightings($Upload, $Item)
Show Sightings, List the directory locations where this pfile is found.
RegisterMenus()
Customize submenus.
__construct()
base constructor. Most plugins will just use this
Dir2FileList(&$Listing, $IfDirPlugin, $IfFilePlugin, $Count=-1, $ShowPhrase=0)
Given an array of pfiles/uploadtree, sorted by pfile, list all of the breadcrumbs for each file....
Dir2Browse($Mod, $UploadtreePk, $LinkLast=NULL, $ShowBox=1, $ShowMicro=NULL, $Enumerate=-1, $PreText='', $PostText='', $uploadtree_tablename="uploadtree")
Get an html linked string of a file browse path.
Traceback_uri()
Get the URI without query to this location.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
Traceback_parm_keep($List)
Create a new URI, keeping only these items.
HumanSize( $bytes)
Translate a byte number to a proper type, xxx bytes to xxx B/KB/MB/GB/TB/PB.
char * trim(char *ptext)
Trimming whitespace.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
fo_dbManager * dbManager
fo_dbManager object