32 $this->Name =
"view_info";
33 $this->Title = _(
"View File Information");
34 $this->Dependency = array(
"browse");
37 parent::__construct();
38 $this->uploadDao = $GLOBALS[
'container']->get(
'dao.upload');
39 $this->
dbManager = $GLOBALS[
'container']->get(
'db.manager');
40 $this->userDao = $GLOBALS[
'container']->get(
'dao.user');
48 $tooltipText = _(
"View file information");
49 menu_insert(
"Browse-Pfile::Info", 5, $this->Name, $tooltipText);
52 $URI = $this->Name . $Parm;
62 menu_insert(
"View-Meta::{$menuText}", $menuPosition);
66 $tooltipText = _(
"View information about this file");
69 menu_insert(
"View::{$menuText}", $menuPosition, $URI, $tooltipText);
72 menu_insert(
"View-Meta::{$menuText}", $menuPosition, $URI, $tooltipText);
74 menu_insert(
"Browse::Info", -3, $URI, $tooltipText);
81 function ShowView($Upload, $Item, $ShowMenu = 0)
84 if (empty($Upload) || empty($Item)) {
92 $vars[
'repoLocPage'] = $Page;
100 $sql =
"SELECT * FROM uploadtree
101 INNER JOIN pfile ON uploadtree_pk = $1
102 AND pfile_fk = pfile_pk
107 __METHOD__ .
"GetFileDescribingRow"
109 $bytes = $row[
'pfile_size'];
111 $bytes = number_format($bytes, 0,
"",
",") .
' B';
112 if ($bytesH == $bytes) {
115 $bytesH =
'(' . $bytesH .
')';
117 $vars[
'sizeInBytes'] = $bytes;
118 $vars[
'sizeInMB'] = $bytesH;
119 $vars[
'fileSha1'] = $row[
'pfile_sha1'];
120 $vars[
'fileMd5'] = $row[
'pfile_md5'];
121 $vars[
'fileSha256'] = $row[
'pfile_sha256'];
122 $vars[
'fileSize'] = $row[
'pfile_size'];
123 $vars[
'filePfileId'] = $row[
'pfile_fk'];
134 if (empty($Upload) || empty($Item)) {
143 $offset = $page * $MAX;
147 $sql =
"SELECT * FROM pfile,uploadtree
148 WHERE pfile_pk=pfile_fk
150 (SELECT pfile_fk FROM uploadtree WHERE uploadtree_pk = $1)
152 $this->
dbManager->prepare(__METHOD__ .
"getListOfFiles", $sql);
153 $result = $this->
dbManager->execute(__METHOD__ .
"getListOfFiles", array($Item,$MAX,$offset));
154 $count = pg_num_rows($result);
155 if (($page > 0) || ($count >= $MAX)) {
156 $vMenu =
"<p>\n" .
MenuEndlessPage($page, ($count >= $MAX)) .
"</p>\n";
161 $v .= _(
"This exact file appears in the following locations:\n");
166 } elseif ($page > 0) {
167 $v .= _(
"End of listing.\n");
169 $v .= _(
"This file does not appear in any other known location.\n");
171 pg_free_result($result);
174 $vars[
'sightingsContent'] = $v;
184 if (empty($Item) || empty($Upload)) {
189 $sql =
"SELECT * FROM uploadtree where uploadtree_pk = $1";
190 $this->
dbManager->prepare(__METHOD__ .
"DisplayMimetype", $sql);
191 $result = $this->
dbManager->execute(__METHOD__ .
"DisplayMimetype", array($Item));
192 if (pg_num_rows($result)) {
193 $vars[
'fileInfo'] = 1;
194 $row = pg_fetch_assoc($result);
196 if (! empty($row[
'mimetype_pk'])) {
197 $vars[
'displayMimeTypeName'] = $row[
'mimetype_name'];
201 $vars[
'fileInfo'] = 0;
207 if (! empty($row[
'pfile_fk'])) {
208 $sql =
"select mimetype_name from pfile, mimetype where pfile_pk = $1 and pfile_mimetypefk=mimetype_pk";
209 $this->
dbManager->prepare(__METHOD__ .
"GetMimetype", $sql);
211 __METHOD__ .
"GetMimetype",
212 array($row[
'pfile_fk'])
214 if (pg_num_rows($result)) {
215 $pmRow = pg_fetch_assoc($result);
216 $vars[
'getMimeTypeName'] = $pmRow[
'mimetype_name'];
222 $sql =
"SELECT agent_enabled FROM agent WHERE agent_name ='scanoss' ORDER BY agent_ts LIMIT 1;";
223 $row = $this->
dbManager->getSingleRow($sql, [],
224 __METHOD__ .
"checkScanOss");
225 if (!empty($row) && $row[
"agent_enabled"] ==
't') {
226 $sql =
"SELECT s.purl, s.matchtype, s.lineranges, s.url, s.filepath " .
227 "FROM scanoss_fileinfo s WHERE s.pfile_fk = $1;";
228 $pmRow = $this->
dbManager->getSingleRow($sql, [$row[
'pfile_fk']],
229 __METHOD__ .
"GetFileMatchInfo");
231 if (!empty($pmRow)) {
232 $vars[
'purl'] = $pmRow[
'purl'];
233 $vars[
'matchType'] = $pmRow[
'matchtype'];
234 $vars[
'lineRange'] = $pmRow[
'lineranges'];
235 $vars[
'url'] = $pmRow[
'url'];
236 $vars[
'path'] = $pmRow[
'filepath'];
237 $vars[
'scanossInfo'] = 1;
239 $vars[
'scanossInfo'] = 0;
243 $sql =
"select * from upload where upload_pk=$1";
246 array($row[
'upload_fk']),
247 __METHOD__ .
"getUploadOrigin"
251 if ($row[
'upload_mode'] & 1 << 2) {
252 $text = _(
"Added by URL");
253 } elseif ($row[
'upload_mode'] & 1 << 3) {
254 $text = _(
"Added by file upload");
255 } elseif ($row[
'upload_mode'] & 1 << 4) {
256 $text = _(
"Added from filesystem");
258 $vars[
'fileUploadOriginInfo'] = $text;
259 $vars[
'fileUploadOrigin'] = $row[
'upload_origin'];
262 $ts = $row[
'upload_ts'];
263 $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'];
287 $rpm_info = array(
"Package" =>
"pkg_name",
288 "Alias" =>
"pkg_alias",
289 "Architecture" =>
"pkg_arch",
290 "Version" =>
"version",
291 "License" =>
"license",
292 "Group" =>
"pkg_group",
293 "Packager" =>
"packager",
294 "Release" =>
"release",
295 "BuildDate" =>
"build_date",
296 "Vendor" =>
"vendor",
298 "Summary" =>
"summary",
299 "Description" =>
"description",
300 "Source" =>
"source_rpm");
302 $deb_binary_info = array(
"Package" =>
"pkg_name",
303 "Architecture" =>
"pkg_arch",
304 "Version" =>
"version",
305 "Section" =>
"section",
306 "Priority" =>
"priority",
307 "Installed Size" =>
"installed_size",
308 "Maintainer" =>
"maintainer",
309 "Homepage" =>
"homepage",
310 "Source" =>
"source",
311 "Summary" =>
"summary",
312 "Description" =>
"description");
314 $deb_source_info = array(
"Format" =>
"format",
315 "Source" =>
"source",
316 "Binary" =>
"pkg_name",
317 "Architecture" =>
"pkg_arch",
318 "Version" =>
"version",
319 "Maintainer" =>
"maintainer",
320 "Uploaders" =>
"uploaders",
321 "Standards-Version" =>
"standards_version");
323 if (empty($Item) || empty($Upload)) {
330 $sql =
"SELECT agent_enabled FROM agent WHERE agent_name ='pkgagent' order by agent_ts LIMIT 1;";
331 $row = $this->
dbManager->getSingleRow($sql, array(), __METHOD__ .
"checkPkgagentDisabled");
332 if (isset($row) && ($row[
'agent_enabled'] ==
'f')) {
337 $sql =
"SELECT typlen FROM pg_type where typname='pkgagent_ars' limit 1;";
338 $this->
dbManager->prepare(__METHOD__ .
"displayPackageInfo", $sql);
339 $result = $this->
dbManager->execute(__METHOD__ .
"displayPackageInfo", array());
340 $numrows = pg_num_rows($result);
343 $vars[
'packageAgentNA'] = 1;
348 $agent_status = AgentARSList(
'pkgagent_ars', $Upload);
349 if (empty($agent_status)) {
350 $vars[
'packageAgentStatus'] = 1;
352 "?mod=schedule_agent&upload=$Upload&agent=agent_pkgagent";
355 $sql =
"SELECT mimetype_name
357 INNER JOIN pfile ON uploadtree_pk = $1
358 AND pfile_fk = pfile_pk
359 INNER JOIN mimetype ON pfile_mimetypefk = mimetype_pk;";
360 $this->
dbManager->prepare(__METHOD__ .
"getMimetypeName", $sql);
361 $result = $this->
dbManager->execute(__METHOD__ .
"getMimetypeName", array($Item));
362 while ($row = pg_fetch_assoc($result)) {
363 if (! empty($row[
'mimetype_name'])) {
364 $MIMETYPE = $row[
'mimetype_name'];
372 if ($MIMETYPE ==
"application/x-rpm") {
375 INNER JOIN uploadtree ON uploadtree_pk = $1
376 AND uploadtree.pfile_fk = pkg_rpm.pfile_fk;";
377 $R = $this->
dbManager->getSingleRow($sql, array($Item), __METHOD__ .
"getRPMPackageInfo");
378 if ((! empty($R[
'source_rpm'])) and (
trim($R[
'source_rpm']) !=
"(none)")) {
379 $vars[
'packageType'] = _(
"RPM Binary Package");
381 $vars[
'packageType'] = _(
"RPM Source Package");
385 if (! empty($R[
'pkg_pk'])) {
386 $Require = $R[
'pkg_pk'];
387 foreach ($rpm_info as $key => $value) {
389 $entry[
'count'] = $Count;
390 $entry[
'type'] = _($key);
391 $entry[
'value'] = htmlentities($R[
"$value"]);
393 $vars[
'packageEntries'][] = $entry;
396 $sql =
"SELECT * FROM pkg_rpm_req WHERE pkg_fk = $1;";
397 $this->
dbManager->prepare(__METHOD__ .
"getPkg_rpm_req", $sql);
398 $result = $this->
dbManager->execute(__METHOD__ .
"getPkg_rpm_req", array($Require));
400 while ($R = pg_fetch_assoc($result) and ! empty($R[
'req_pk'])) {
402 $entry[
'count'] = $Count;
403 $entry[
'type'] = _(
"Requires");
404 $entry[
'value'] = htmlentities($R[
'req_value']);
406 $vars[
'packageRequires'][] = $entry;
410 } elseif ($MIMETYPE ==
"application/x-debian-package") {
411 $vars[
'packageType'] = _(
"Debian Binary Package\n");
415 INNER JOIN uploadtree ON uploadtree_pk = $1
416 AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
417 $R = $this->
dbManager->getSingleRow($sql, array($Item), __METHOD__ .
"debianBinaryPackageInfo");
421 $Require = $R[
'pkg_pk'];
422 foreach ($deb_binary_info as $key => $value) {
424 $entry[
'count'] = $Count;
425 $entry[
'type'] = _($key);
426 $entry[
'value'] = htmlentities($R[
"$value"]);
428 $vars[
'packageEntries'][] = $entry;
430 pg_free_result($result);
432 $sql =
"SELECT * FROM pkg_deb_req WHERE pkg_fk = $1;";
433 $this->
dbManager->prepare(__METHOD__ .
"getPkg_rpm_req", $sql);
434 $result = $this->
dbManager->execute(__METHOD__ .
"getPkg_rpm_req", array($Require));
436 while ($R = pg_fetch_assoc($result) and ! empty($R[
'req_pk'])) {
438 $entry[
'count'] = $Count;
439 $entry[
'type'] = _(
"Depends");
440 $entry[
'value'] = htmlentities($R[
'req_value']);
442 $vars[
'packageRequires'][] = $entry;
447 } elseif ($MIMETYPE ==
"application/x-debian-source") {
448 $vars[
'packageType'] = _(
"Debian Source Package\n");
452 INNER JOIN uploadtree ON uploadtree_pk = $1
453 AND uploadtree.pfile_fk = pkg_deb.pfile_fk;";
454 $R = $this->
dbManager->getSingleRow($sql, array($Item), __METHOD__ .
"debianSourcePakcageInfo");
458 $Require = $R[
'pkg_pk'];
459 foreach ($deb_source_info as $key => $value) {
461 $entry[
'count'] = $Count;
462 $entry[
'type'] = _($key);
463 $entry[
'value'] = htmlentities($R[
"$value"]);
465 $vars[
'packageEntries'][] = $entry;
467 pg_free_result($result);
469 $sql =
"SELECT * FROM pkg_deb_req WHERE pkg_fk = $1;";
470 $this->
dbManager->prepare(__METHOD__ .
"getPkg_rpm_req", $sql);
471 $result = $this->
dbManager->execute(__METHOD__ .
"getPkg_rpm_req", array($Require));
473 while ($R = pg_fetch_assoc($result) and ! empty($R[
'req_pk'])) {
475 $entry[
'count'] = $Count;
476 $entry[
'type'] = _(
"Build-Depends");
477 $entry[
'value'] = htmlentities($R[
'req_value']);
479 $vars[
'packageRequires'][] = $entry;
485 $vars[
'packageType'] =
"";
497 $groupId = Auth::getGroupId();
498 $row = $this->uploadDao->getUploadEntry($Item);
500 $vars[
'tagInvalid'] = 1;
505 $upload_pk = $row[
"upload_fk"];
508 $vars[
'tagInvalid'] = 2;
511 $sql =
"SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_file,tag WHERE tag_pk = tag_fk) T
512 ON uploadtree.pfile_fk = T.pfile_fk WHERE uploadtree.upload_fk = $1
513 AND uploadtree.lft >= $2 AND uploadtree.rgt <= $3 UNION SELECT * FROM uploadtree INNER JOIN
514 (SELECT * FROM tag_uploadtree,tag WHERE tag_pk = tag_fk) T ON uploadtree.uploadtree_pk = T.uploadtree_fk
515 WHERE uploadtree.upload_fk = $1 AND uploadtree.lft >= $2 AND uploadtree.rgt <= $3 ORDER BY ufile_name";
516 $this->
dbManager->prepare(__METHOD__, $sql);
517 $result = $this->
dbManager->execute(__METHOD__, array($upload_pk, $lft,$rgt));
518 if (pg_num_rows($result) > 0) {
519 while ($row = pg_fetch_assoc($result)) {
521 $entry[
'ufile_name'] = $row[
'ufile_name'];
522 $entry[
'tag'] = $row[
'tag'];
523 if ($this->uploadDao->isAccessible($upload_pk, $groupId)) {
525 "?mod=tag&action=edit&upload=$Upload&item=" . $row[
'uploadtree_pk'] .
526 "&tag_file_pk=" . $row[
'tag_file_pk'];
530 $vars[
'tagsEntries'][] = $entry;
546 $reusedInfo = $this->uploadDao->getReusedUpload(
550 foreach ($reusedInfo as $row) {
552 $reuseUploadFk = $row[
'reused_upload_fk'];
553 $reuseGroupFk = $row[
'reused_group_fk'];
554 $reusedUpload = $this->uploadDao->getUpload($reuseUploadFk);
555 $reuseMode = array();
556 if ($row[
'reuse_mode'] & UploadDao::REUSE_ENHANCED) {
557 $reuseMode[] =
"Enhanced";
559 $reuseMode[] =
"Normal";
561 if ($row[
'reuse_mode'] & UploadDao::REUSE_MAIN) {
562 $reuseMode[] =
"Main license";
564 if ($row[
'reuse_mode'] & UploadDao::REUSE_CONF) {
565 $reuseMode[] =
"Report configuration settings";
567 $entry[
'name'] = $reusedUpload->getFilename();
569 "?mod=license&upload=$reuseUploadFk&item=" .
570 $this->uploadDao->getUploadParent($reuseUploadFk);
571 $entry[
'group'] = $this->userDao->getGroupNameById($reuseGroupFk) .
573 $entry[
'sha1'] = $this->uploadDao->getUploadHashes($reuseUploadFk)[
'sha1'];
574 $entry[
'mode'] = implode(
", ", $reuseMode) .
" reuse";
576 $vars[
'reusedPackageList'][] = $entry;
584 if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
589 $this->vars[
'micromenu'] =
Dir2Browse(
"browse", $itemId,
null, $showBox = 0,
"View-Meta");
591 $this->vars += $this->
ShowTagInfo($uploadId, $itemId);
592 $this->vars += $this->ShowPackageinfo($uploadId, $itemId, 1);
595 $this->vars += $this->
ShowView($uploadId, $itemId);
599 public function getTemplateName()
601 return "ui-view-info.html.twig";
605 $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