diff --git a/src/www/ui/ui-view-info.php b/src/www/ui/ui-view-info.php index f5da7d39..90ba3f34 100644 --- a/src/www/ui/ui-view-info.php +++ b/src/www/ui/ui-view-info.php @@ -1,615 +1,615 @@ Name = "view_info"; $this->Title = _("View File Information"); $this->Dependency = array("browse"); $this->DBaccess = PLUGIN_DB_READ; $this->LoginFlag = 0; parent::__construct(); $this->uploadDao = $GLOBALS['container']->get('dao.upload'); $this->dbManager = $GLOBALS['container']->get('db.manager'); } /** * \brief Customize submenus. */ function RegisterMenus() { $tooltipText = _("View file information"); menu_insert("Browse-Pfile::Info",5,$this->Name,$tooltipText); // For the Browse menu, permit switching between detail and summary. $Parm = Traceback_parm_keep(array("upload","item","format")); $URI = $this->Name . $Parm; $menuPosition = 60; $menuText = "Info"; if (GetParm("mod",PARM_STRING) == $this->Name) { menu_insert("View::[BREAK]", 61); menu_insert("View::[BREAK]", 50); menu_insert("View::{$menuText}", $menuPosition); menu_insert("View-Meta::[BREAK]", 61); menu_insert("View-Meta::[BREAK]", 50); menu_insert("View-Meta::{$menuText}", $menuPosition); menu_insert("Browse::Info",-3); } else { $tooltipText = _("View information about this file"); menu_insert("View::[BREAK]", 61); menu_insert("View::[BREAK]", 50); menu_insert("View::{$menuText}", $menuPosition, $URI, $tooltipText); menu_insert("View-Meta::[BREAK]", 61); menu_insert("View-Meta::[BREAK]", 50); menu_insert("View-Meta::{$menuText}", $menuPosition, $URI, $tooltipText); menu_insert("Browse::Info", -3, $URI, $tooltipText); } } // RegisterMenus() /** * \brief Display the info data associated with the file. */ function ShowView($Upload, $Item, $ShowMenu=0) { $V = ""; if (empty($Upload) || empty($Item)) { return; } $Page = GetParm("page",PARM_INTEGER); if (empty($Page)) { $Page=0; } /********************************** List File Info **********************************/ if ($Page == 0) { $text = _("Repository Locator"); $V .= "

$text

\n"; $sql = "SELECT * FROM uploadtree INNER JOIN pfile ON uploadtree_pk = $1 AND pfile_fk = pfile_pk LIMIT 1;"; $R = $this->dbManager->getSingleRow($sql,array($Item),__METHOD__."GetFileDescribingRow"); $V .= "\n"; $text = _("Attribute"); $text1 = _("Value"); $V .= "\n"; $Bytes = $R['pfile_size']; $BytesH = HumanSize($Bytes); $Bytes = number_format($Bytes, 0, "", ",").' B'; if ($BytesH == $Bytes) { $BytesH = ""; } else { $BytesH = '(' . $BytesH . ')'; } $text = _("File Size"); $V .= "\n"; $text = _("SHA1 Checksum"); $V .= "\n"; $text = _("MD5 Checksum"); $V .= "\n"; $text = _("Repository ID"); $V .= "\n"; $text = _("Pfile ID"); $V .= "\n"; $V .= "
$text$text1
$text$Bytes $BytesH
$text" . $R['pfile_sha1'] . "
$text" . $R['pfile_md5'] . "
$text" . $R['pfile_sha1'] . "." . $R['pfile_md5'] . "." . $R['pfile_size'] . "
$text" . $R['pfile_fk'] . "
\n"; } return($V); } // ShowView() /** * \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 .= "

$text

\n"; $sql = "SELECT * FROM pfile,uploadtree WHERE pfile_pk=pfile_fk AND pfile_pk IN (SELECT pfile_fk FROM uploadtree WHERE uploadtree_pk = $1) LIMIT $2 OFFSET $3"; $this->dbManager->prepare(__METHOD__."getListOfFiles",$sql); - $result = $this->dbManager->execute(__METHOD__,array($Item,$Max,$Offset)); + $result = $this->dbManager->execute(__METHOD__."getListOfFiles",array($Item,$Max,$Offset)); $Count = pg_num_rows($result); if (($Page > 0) || ($Count >= $Max)) { $VM = "

\n" . MenuEndlessPage($Page, ($Count >= $Max)) . "

\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); }//ShowSightings() /** * \brief Display the meta data associated with the file. */ function ShowMetaView($Upload, $Item) { $V = ""; $Count = 1; if (empty($Item) || empty($Upload)) { return; } /********************************** Display meta data **********************************/ $text = _("File Info"); $V .= "

$text

\n"; $V .= "\n"; $text = _("Item"); $text1 = _("Meta Data"); $text2 = _("Value"); $V .= "\n"; /* display mimetype */ $sql = "SELECT * FROM uploadtree where uploadtree_pk = $1"; $this->dbManager->prepare(__METHOD__."DisplayMimetype",$sql); - $result = $this->dbManager->execute(__METHOD__."getUploadTree",array($Item)); + $result = $this->dbManager->execute(__METHOD__."DisplayMimetype",array($Item)); if (pg_num_rows($result)) { $row = pg_fetch_assoc($result); if (!empty($row['mimetype_pk'])) { $V .= "\n"; } } else { // bad uploadtree_pk pg_free_result($result); $text = _("File does not exist in database"); return $text; } $this->dbManager->freeResult($result); /* get mimetype */ if (!empty($row['pfile_fk'])) { $sql = "select mimetype_name from pfile, mimetype where pfile_pk = $1 and pfile_mimetypefk=mimetype_pk"; $this->dbManager->prepare(__METHOD__."GetMimetype",$sql); - $result = $this->dbManager->execute(__METHOD__."getMimetype",array($row[pfile_fk])); + $result = $this->dbManager->execute(__METHOD__."GetMimetype",array($row[pfile_fk])); if (pg_num_rows($result)) { $pmRow = pg_fetch_assoc($result); $V .= "\n"; } $this->dbManager->freeResult($result); } /* display upload origin */ $sql = "select * from upload where upload_pk=$1"; $row = $this->dbManager->getSingleRow($sql,array($row[upload_fk]),__METHOD__."getUploadOrigin"); if ($row) { /* upload source */ if ($row['upload_mode'] & 1 << 2) $text = _("Added by URL: "); else if ($row['upload_mode'] & 1 << 3) $text = _("Added by file upload: "); else if ($row['upload_mode'] & 1 << 4) $text = _("Added from filesystem: "); $V .= ""; $V .= "\n"; /* upload time */ $text = _("Added to repo"); $V .= ""; $ts = $row['upload_ts']; $V .= "\n"; } /* display where it was uploaded from */ /* display upload owner*/ $sql = "SELECT user_name from users, upload where user_pk = user_fk and upload_pk = $1"; $row = $this->dbManager->getSingleRow($sql,array($Upload),__METHOD__."getUploadOwner"); $text = _("Added by"); $V .= ""; $V .= "\n"; $V .= "
$text$text1$text2
" . $Count++ . "Unpacked file type"; $V .= "" . htmlentities($row['mimetype_name']) . "
" . $Count++ . "Unpacked file type"; $V .= "" . htmlentities($pmRow['mimetype_name']) . "
" . $Count++ . "$text" . htmlentities($row['upload_origin']) . "
" . $Count++ . "$text" . substr($ts, 0, strrpos($ts, '.')) . "
" . $Count++ . "$text" . $row['user_name'] . "

\n"; return($V); } // ShowMetaView() /** * \brief Display the package info associated with * the rpm/debian package. */ function ShowPackageInfo($Upload, $Item, $ShowMenu=0) { $V = ""; $Require = ""; $MIMETYPE = ""; $Count = 0; $rpm_info = array("Package"=>"pkg_name", "Alias"=>"pkg_alias", "Architecture"=>"pkg_arch", "Version"=>"version", "License"=>"license", "Group"=>"pkg_group", "Packager"=>"packager", "Release"=>"release", "BuildDate"=>"build_date", "Vendor"=>"vendor", "URL"=>"url", "Summary"=>"summary", "Description"=>"description", "Source"=>"source_rpm"); $deb_binary_info = array("Package"=>"pkg_name", "Architecture"=>"pkg_arch", "Version"=>"version", "Section"=>"section", "Priority"=>"priority", "Installed Size"=>"installed_size", "Maintainer"=>"maintainer", "Homepage"=>"homepage", "Source"=>"source", "Summary"=>"summary", "Description"=>"description"); $deb_source_info = array("Format"=>"format", "Source"=>"source", "Binary"=>"pkg_name", "Architecture"=>"pkg_arch", "Version"=>"version", "Maintainer"=>"maintainer", "Uploaders"=>"uploaders", "Standards-Version"=>"standards_version"); if (empty($Item) || empty($Upload)) { return; } /********************************** Check if pkgagent disabled ***********************************/ $sql = "SELECT agent_enabled FROM agent WHERE agent_name ='pkgagent' order by agent_ts LIMIT 1;"; $row = $this->dbManager->getSingleRow($sql,array(),__METHOD__."checkPkgagentDisabled"); if (isset($row) && ($row['agent_enabled']== 'f')){return;} /********************************** Display package info **********************************/ $text = _("Package Info"); $V .= "

$text

\n"; /* If pkgagent_ars table didn't exists, don't show the result. */ $sql = "SELECT typlen FROM pg_type where typname='pkgagent_ars' limit 1;"; $this->dbManager->prepare(__METHOD__."displayPackageInfo",$sql); $result = $this->dbManager->execute(__METHOD__."displayPackageInfo",array()); $numrows = pg_num_rows($result); $this->dbManager->freeResult($result); if ($numrows <= 0) { $V .= _("No data available. Use Jobs > Agents to schedule a pkgagent scan."); return($V); } /* If pkgagent_ars table didn't have record for this upload, don't show the result. */ $agent_status = AgentARSList('pkgagent_ars', $Upload); if (empty($agent_status)) { /** schedule pkgagent */ $V .= ActiveHTTPscript("Schedule"); $V .= "\n"; $V .= "
\n"; $V .= "
\n"; $V .= _("No data available."); $V .= "\n"; $V .= ""; $V .= "
\n"; $V .= "
\n"; return($V); } $sql = "SELECT mimetype_name FROM uploadtree INNER JOIN pfile ON uploadtree_pk = $1 AND pfile_fk = pfile_pk INNER JOIN mimetype ON pfile_mimetypefk = mimetype_pk;"; $this->dbManager->prepare(__METHOD__."getMimetypeName",$sql); $result = $this->dbManager->execute(__METHOD__."getMimetypeName",array($Item)); while ($row = pg_fetch_assoc($result)) { if (!empty($row['mimetype_name'])) { $MIMETYPE = $row['mimetype_name']; } } $this->dbManager->freeResult($result); /** RPM Package Info **/ if ($MIMETYPE == "application/x-rpm") { $sql = "SELECT * FROM pkg_rpm INNER JOIN uploadtree ON uploadtree_pk = $1 AND uploadtree.pfile_fk = pkg_rpm.pfile_fk;"; $R = $this->dbManager->getSingleRow($sql,array($Item),__METHOD__."getRPMPackageInfo"); if((!empty($R['source_rpm']))and(trim($R['source_rpm']) != "(none)")) { $V .= _("RPM Binary Package"); } else { $V .= _("RPM Source Package"); } $Count=1; $V .= "\n"; $text = _("Item"); $text1 = _("Type"); $text2 = _("Value"); $V .= "\n"; if (!empty($R['pkg_pk'])) { $Require = $R['pkg_pk']; foreach ($rpm_info as $key=>$value) { $text = _($key); $V .= "\n"; $Count++; } $sql = "SELECT * FROM pkg_rpm_req WHERE pkg_fk = $1;"; $this->dbManager->prepare(__METHOD__."getPkg_rpm_req",$sql); $result = $this->dbManager->execute(__METHOD__."getPkg_rpm_req",array($Require)); while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) { $text = _("Requires"); $V .= "\n"; $Count++; } $this->dbManager->freeResult($result); } $V .= "
$text$text1$text2
$Count$text"; $V .= "" . htmlentities($R["$value"]) . "
$Count$text"; $Val = htmlentities($R['req_value']); $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i","\$1",$Val); $V .= "$Val
\n"; } else if ($MIMETYPE == "application/x-debian-package") { $V .= _("Debian Binary Package\n"); $sql = "SELECT * FROM pkg_deb INNER JOIN uploadtree ON uploadtree_pk = $1 AND uploadtree.pfile_fk = pkg_deb.pfile_fk;"; $R = $this->dbManager->getSingleRow($sql,array($Item),__METHOD__."debianBinaryPackageInfo"); $Count=1; $V .= "\n"; $text = _("Item"); $text1 = _("Type"); $text2 = _("Value"); $V .= "\n"; if ($R) { $Require = $R['pkg_pk']; foreach ($deb_binary_info as $key=>$value) { $text = _($key); $V .= "\n"; $Count++; } pg_free_result($result); $sql = "SELECT * FROM pkg_deb_req WHERE pkg_fk = $1;"; $this->dbManager->prepare(__METHOD__."getPkg_rpm_req",$sql); $result = $this->dbManager->execute(__METHOD__."getPkg_rpm_req",array($Require)); while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) { $text = _("Depends"); $V .= "\n"; $Count++; } $this->dbManager->freeResult($result); } $V .= "
$text$text1$text2
$Count$text"; $V .= "" . htmlentities($R["$value"]) . "
$Count$text"; $Val = htmlentities($R['req_value']); $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i","\$1",$Val); $V .= "$Val
\n"; } else if ($MIMETYPE == "application/x-debian-source") { $V .= _("Debian Source Package\n"); $sql = "SELECT * FROM pkg_deb INNER JOIN uploadtree ON uploadtree_pk = $1 AND uploadtree.pfile_fk = pkg_deb.pfile_fk;"; $R = $this->dbManager->getSingleRow($sql,array($Item),__METHOD__."debianSourcePakcageInfo"); $Count=1; $V .= "\n"; $text = _("Item"); $text1 = _("Type"); $text2 = _("Value"); $V .= "\n"; if ($R) { $Require = $R['pkg_pk']; foreach ($deb_source_info as $key=>$value) { $text = _($key); $V .= "\n"; $Count++; } pg_free_result($result); $sql = "SELECT * FROM pkg_deb_req WHERE pkg_fk = $1;"; $this->dbManager->prepare(__METHOD__."getPkg_rpm_req",$sql); $result = $this->dbManager->execute(__METHOD__."getPkg_rpm_req",array($Require)); while ($R = pg_fetch_assoc($result) and !empty($R['req_pk'])) { $text = _("Build-Depends"); $V .= "\n"; $Count++; } $this->dbManager->freeResult($result); } $V .= "
$text$text1$text2
$Count$text"; $V .= "" . htmlentities($R["$value"]) . "
$Count$text"; $Val = htmlentities($R['req_value']); $Val = preg_replace("@((http|https|ftp)://[^{}<>&[:space:]]*)@i","\$1",$Val); $V .= "$Val
\n"; } else { /* Not a package */ return ""; } return($V); } // ShowPackageInfo() /** * \brief Display the tag info data associated with the file. */ function ShowTagInfo($Upload, $Item) { $VT = ""; $text = _("Tag Info"); $VT .= "

$text

\n"; $groupId = Auth::getGroupId(); $row = $this->uploadDao->getUploadEntry($Item); if (empty($row)) { $text = _("Invalid URL, nonexistant item"); return "

$text $Item

"; } $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 "

$text uploadtree_pk: $Item

"; } $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 = $1 AND uploadtree.lft >= $2 AND uploadtree.rgt <= $3 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 = $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 .= "\n"; $text = _("FileName"); $text2 = _("Tag"); $VT .= "\n"; while ($row = pg_fetch_assoc($result)) { $VT .= ""; if ($this->uploadDao->isAccessible($upload_pk, $groupId)) { $VT .= "\n"; }else{ $VT .= "\n"; } } $VT .= "
$text$text2
" . $row['ufile_name'] . "" . $row['tag'] . "View

\n"; } $this->dbManager->freeResult($result); return $VT; } public function Output() { $uploadId = GetParm("upload",PARM_INTEGER); if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) return; $itemId = GetParm("item",PARM_INTEGER); $this->vars['micromenu'] = Dir2Browse("browse", $itemId, NULL, $showBox=0, "View-Meta"); $V=""; $V .= $this->ShowTagInfo($uploadId, $itemId); $V .= $this->ShowPackageinfo($uploadId, $itemId, 1); $V .= $this->ShowMetaView($uploadId, $itemId); $V .= $this->ShowSightings($uploadId, $itemId); $V .= $this->ShowView($uploadId, $itemId); return $V; } } $NewPlugin = new ui_view_info; $NewPlugin->Initialize();