/** * \brief test for Traceback() */ function test_Traceback() { print "test function Traceback()\n"; $expected = "http://fossology.org/"; $_SERVER['REQUEST_URI'] = $expected; $result = Traceback(); $this->assertEquals($expected, $result); }
function DisplayGroupMembership() { global $SysConf; global $PG_CONN; global $PERM_NAMES; $group_pk = GetParm('group_pk', PARM_INTEGER); $user_pk = $SysConf['auth']['UserId']; $V = ""; $text = _("To edit group memberships "); $text2 = _("click here"); $V .= "<p>{$text}" . "<a href='" . Traceback_uri() . "?mod=group_manage_users'>" . $text2 . "</a>"; $text = _("Look up who is a member of group "); /* Get array of groups that this user is an admin of */ $GroupArray = GetGroupArray($user_pk); if (empty($GroupArray)) { $text = _("You have no permission to manage any group."); echo "<p>{$text}<p>"; return; } reset($GroupArray); if (empty($group_pk)) { $group_pk = key($GroupArray); } $text = _("To list the users in a group, select the group: \n"); $V .= "<p>{$text}"; /*** Display group select list, on change request new page with group= in url ***/ $url = preg_replace('/&group_pk=[0-9]*/', "", Traceback()) . "&group_pk="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($GroupArray, "groupuserselect", $group_pk, false, false, $onchange); /* Select all the user members of this group */ $sql = "select group_user_member_pk, user_fk, group_perm, user_name from group_user_member, users\n where group_fk='{$group_pk}' and user_fk=user_pk"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $GroupMembersArray = pg_fetch_all($result); pg_free_result($result); /* Permissions Table */ $V .= "<p><table border=1>"; $UserText = _("User"); $V .= "<tr><th>{$UserText}</th></tr>"; foreach ($GroupMembersArray as $GroupMember) { $V .= "<tr>"; $V .= "<td>"; // user $V .= $GroupMember['user_name']; $V .= "</td>"; $V .= "</tr>"; } $V .= "</table>"; return $V; }
/** * \brief This function returns the FOSSology logo and * Folder Navigation bar */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; global $Plugins; switch ($this->OutputType) { case "XML": break; case "HTML": /* Load the logo image */ $Uri = Traceback_uri(); $V .= "<center><a href='http://fossology.org' target='_top'><img alt='FOSSology' title='FOSSology' src='{$Uri}images/fossology-logo.gif' align=absmiddle border=0></a></center><br>\n"; $V .= FolderListScript(); $V .= "<small><center>"; $text = _("Expand"); $V .= "<a href='javascript:Expand();'>{$text}</a> |"; $text = _("Collapse"); $V .= "<a href='javascript:Collapse();'>{$text}</a> |"; $text = _("Refresh"); $V .= "<a href='" . Traceback() . "'>{$text}</a>"; $V .= "</center></small>"; $V .= "<P>\n"; /* Display the tree */ $V .= "<form>\n"; $V .= FolderListDiv(-1, 0); $V .= "</form>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
/** * \brief This function returns the scheduler status. */ public function Output() { $uTime = microtime(true); $V = ""; $Upload = GetParm("upload", PARM_INTEGER); /** @var UploadDao $uploadDao */ $uploadDao = $GLOBALS['container']->get('dao.upload'); if (!$uploadDao->isAccessible($Upload, Auth::getGroupId())) { $text = _("Permission Denied"); return "<h2>{$text}</h2>"; } $Item = GetParm("item", PARM_INTEGER); if (!$Item) { return _('No item selected'); } $updcache = GetParm("updcache", PARM_INTEGER); $tagbucket = GetParm("tagbucket", PARM_INTEGER); $this->uploadtree_tablename = GetUploadtreeTableName($Upload); /* Remove "updcache" from the GET args and set $this->UpdCache * This way all the url's based on the input args won't be * polluted with updcache * Use Traceback_parm_keep to ensure that all parameters are in order */ $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "item", "folder", "ars")); if ($updcache) { $_SERVER['REQUEST_URI'] = preg_replace("/&updcache=[0-9]*/", "", $_SERVER['REQUEST_URI']); unset($_GET['updcache']); $V = ReportCachePurgeByKey($CacheKey); } else { $V = ReportCacheGet($CacheKey); } if (!empty($tagbucket)) { $bucketagent_pk = GetParm("bapk", PARM_INTEGER); $bucket_pk = GetParm("bpk", PARM_INTEGER); $bucketpool_pk = GetParm("bp", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $this->TagBucket($Upload, $Item, $bucketagent_pk, $bucket_pk, $bucketpool_pk, $nomosagent_pk); } $Cached = !empty($V); if (!$Cached) { $V .= "<font class='text'>\n"; $Children = GetNonArtifactChildren($Item, $this->uploadtree_tablename); if (count($Children) == 0) { // no children, display View-Meta micromenu $V .= Dir2Browse($this->Name, $Item, NULL, 1, "View-Meta", -1, '', '', $this->uploadtree_tablename) . "<P />\n"; } else { // has children, display Browse micormenu $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $this->uploadtree_tablename) . "<P />\n"; } if (!empty($Upload)) { $Uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); $V .= $this->ShowUploadHist($Item, $Uri); } $V .= "</font>\n"; $text = _("Loading..."); } $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); $V .= sprintf("<p><small>{$text}</small>", $Time); if ($Cached) { $text = _("cached"); $text1 = _("Update"); echo " <i>{$text}</i> <a href=\"{$_SERVER['REQUEST_URI']}&updcache=1\"> {$text1} </a>"; } else { if ($Time > 0.5) { ReportCachePut($CacheKey, $V); } } return $V; }
/** * \brief This function returns the scheduler status. */ function Output() { $uTime = microtime(true); if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $Folder = GetParm("folder", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); $Item = GetParm("item", PARM_INTEGER); switch (GetParm("show", PARM_STRING)) { case 'detail': $Show = 'detail'; break; case 'summary': default: $Show = 'summary'; break; } /* Use Traceback_parm_keep to ensure that all parameters are in order */ $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "item", "folder")) . "&show={$Show}"; if ($this->UpdCache != 0) { $V = ""; $Err = ReportCachePurgeByKey($CacheKey); } else { $V = ReportCacheGet($CacheKey); } if (empty($V)) { switch ($this->OutputType) { case "XML": break; case "HTML": $V .= "<font class='text'>\n"; /************************/ /* Show the folder path */ /************************/ $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse") . "<P />\n"; /******************************/ /* Get the folder description */ /******************************/ if (!empty($Folder)) { // $V .= $this->ShowFolder($Folder); } if (!empty($Upload)) { $Uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); $V .= $this->ShowUploadHist($Upload, $Item, $Uri); } $V .= "</font>\n"; break; case "Text": break; default: break; } $Cached = false; /* Cache Report if this took longer than 1 seconds */ if ($Time > 1) { ReportCachePut($CacheKey, $V); } } else { $Cached = true; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); printf("<small>{$text}</small>", $Time); $text = _("cached"); $text1 = _("Update"); if ($Cached) { echo " <i>{$text}</i> <a href=\"{$_SERVER['REQUEST_URI']}&updcache=1\"> {$text1} </a>"; } return; }
public function Output() { $OutBuf = ""; $uploadId = GetParm("upload", PARM_INTEGER); $item = GetParm("item", PARM_INTEGER); $filter = GetParm("filter", PARM_STRING); /* check upload permissions */ if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) { $text = _("Permission Denied"); return "<h2>{$text}</h2>"; } /* Get uploadtree_tablename */ $uploadtree_tablename = GetUploadtreeTableName($uploadId); $this->uploadtree_tablename = $uploadtree_tablename; /************************/ /* Show the folder path */ /************************/ $this->vars['dir2browse'] = Dir2Browse($this->Name, $item, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename); if (empty($uploadId)) { return 'no item selected'; } /** advanced interface allowing user to select dataset (agent version) */ $dataset = $this->agentName . "_dataset"; $arstable = $this->agentName . "_ars"; /** get proper agent_id */ $agentId = GetParm("agent", PARM_INTEGER); if (empty($agentId)) { $agentId = LatestAgentpk($uploadId, $arstable); } if ($agentId == 0) { /** schedule copyright */ $OutBuf .= ActiveHTTPscript("Schedule"); $OutBuf .= "<script language='javascript'>\n"; $OutBuf .= "function Schedule_Reply()\n"; $OutBuf .= " {\n"; $OutBuf .= " if ((Schedule.readyState==4) && (Schedule.status==200 || Schedule.status==400))\n"; $OutBuf .= " document.getElementById('msgdiv').innerHTML = Schedule.responseText;\n"; $OutBuf .= " }\n"; $OutBuf .= "</script>\n"; $OutBuf .= "<form name='formy' method='post'>\n"; $OutBuf .= "<div id='msgdiv'>\n"; $OutBuf .= _("No data available."); $OutBuf .= "<input type='button' name='scheduleAgent' value='Schedule Agent'"; $OutBuf .= "onClick=\"Schedule_Get('" . Traceback_uri() . "?mod=schedule_agent&upload={$uploadId}&agent=agent_{$this->agentName}')\">\n"; $OutBuf .= "</input>"; $OutBuf .= "</div> \n"; $OutBuf .= "</form>\n"; $this->vars['pageContent'] = $OutBuf; return; } $AgentSelect = AgentSelect($this->agentName, $uploadId, $dataset, $agentId, "onchange=\"addArsGo('newds', 'copyright_dataset');\""); /** change the copyright result when selecting one version of copyright */ if (!empty($AgentSelect)) { $action = Traceback_uri() . '?mod=' . GetParm('mod', PARM_RAW) . Traceback_parm_keep(array('upload', 'item')); $OutBuf .= "<script type='text/javascript'>\n function addArsGo(formid, selectid)\n {\n var selectobj = document.getElementById(selectid);\n var Agent_pk = selectobj.options[selectobj.selectedIndex].value;\n document.getElementById(formid).action='{$action}'+'&agent='+Agent_pk;\n document.getElementById(formid).submit();\n return;\n }\n </script>"; $OutBuf .= "<form action=\"{$action}\" id=\"newds\" method=\"POST\">{$AgentSelect}</form>"; } $selectKey = $filter == 'nolic' ? 'nolic' : 'all'; $OutBuf .= "<select name='view_filter' id='view_filter' onchange='ChangeFilter(this,{$uploadId}, {$item});'>"; foreach (array('all' => _("Show all"), 'nolic' => _("Show files without licenses")) as $key => $text) { $selected = $selectKey == $key ? "selected" : ""; $OutBuf .= "<option {$selected} value=\"{$key}\">{$text}</option>"; } $OutBuf .= "</select>"; $uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); list($tables, $tableVars) = $this->ShowUploadHist($uploadId, $item, $uri, $selectKey, $uploadtree_tablename, $agentId); $this->vars['tables'] = $tableVars; $this->vars['pageContent'] = $OutBuf . $tables; $this->vars['scriptBlock'] = $this->createScriptBlock(); return; }
/** * \brief This function returns the scheduler status. */ function Output() { $uTime = microtime(true); if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $Upload = GetParm("upload", PARM_INTEGER); $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } $Item = GetParm("item", PARM_INTEGER); $tag_pk = GetParm("tag", PARM_INTEGER); $updcache = GetParm("updcache", PARM_INTEGER); $this->uploadtree_tablename = GetUploadtreeTableName($Upload); /* Remove "updcache" from the GET args. * This way all the url's based on the input args won't be * polluted with updcache * Use Traceback_parm_keep to ensure that all parameters are in order */ $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "item", "tag", "agent", "orderBy", "orderl", "orderc")); if ($updcache) { $_SERVER['REQUEST_URI'] = preg_replace("/&updcache=[0-9]*/", "", $_SERVER['REQUEST_URI']); unset($_GET['updcache']); $V = ReportCachePurgeByKey($CacheKey); } else { $V = ReportCacheGet($CacheKey); } if (empty($V)) { switch ($this->OutputType) { case "XML": break; case "HTML": $V .= "<font class='text'>\n"; /************************/ /* Show the folder path */ /************************/ $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $this->uploadtree_tablename) . "<P />\n"; if (!empty($Upload)) { $Uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); $V .= js_url(); $V .= $this->ShowUploadHist($Item, $Uri, $tag_pk); } $V .= "</font>\n"; $text = _("Loading..."); /*$V .= "<div id='ajax_waiting'><img src='images/ajax-loader.gif'>$text</div>"; */ break; case "Text": break; default: } $Cached = false; } else { $Cached = true; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); printf("<small>{$text}</small>", $Time); if ($Cached) { $text = _("cached"); $text1 = _("Update"); echo " <i>{$text}</i> <a href=\"{$_SERVER['REQUEST_URI']}&updcache=1\"> {$text1} </a>"; } else { /* Cache Report if this took longer than 1/2 second*/ if ($Time > 0.5) { ReportCachePut($CacheKey, $V); } } return; }
/** * \brief Generate the view contents in HTML * * @param resource $inputFile * @param string $BackMod * @param int $ShowMenu * @param int $ShowHeader * @param null $ShowText * @param bool $ViewOnly * @param bool $DispView * @param Highlight[] $highlightEntries * @param bool $insertBacklink * * \note This function is intended to be called from other plugins. */ function getView($inputFile = NULL, $BackMod = "browse", $ShowHeader = 1, $ShowText = NULL, $highlightEntries = array(), $insertBacklink = false, $getPageMenuInline = false) { if ($this->State != PLUGIN_STATE_READY) { $output = "Invalid plugin state: " . $this->State; return $getPageMenuInline ? array("Error", $output) : $output; } $Upload = GetParm("upload", PARM_INTEGER); if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) { $output = "Access denied"; return $getPageMenuInline ? array("Error", $output) : $output; } $Item = GetParm("item", PARM_INTEGER); $Page = GetParm("page", PARM_INTEGER); $licenseId = GetParm("licenseId", PARM_INTEGER); if (!$inputFile && empty($Item)) { $output = "invalid input file"; return $getPageMenuInline ? array("Error", $output) : $output; } $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload); if ($ShowHeader) { $Uri = Traceback_uri() . "?mod=browse" . Traceback_parm_keep(array('item', 'show', 'folder', 'upload')); /* No item */ $header = Dir2Browse($BackMod, $Item, NULL, $showBox = 0, "View", -1, '', '', $uploadtree_tablename); $this->vars['micromenu'] = $header; } /* Display file contents */ $output = ""; $openedFin = False; $Format = $this->microMenu->getFormatParameter($Item); if (empty($inputFile)) { $inputFile = @fopen(RepPathItem($Item), "rb"); if ($inputFile) { $openedFin = true; } if (empty($inputFile)) { $output = $this->outputWhenFileNotInRepo($Upload, $Item); return $getPageMenuInline ? array("Error", $output) : $output; } } rewind($inputFile); $Uri = preg_replace('/&page=[0-9]*/', '', Traceback()); $blockSize = $Format == 'hex' ? $this->blockSizeHex : $this->blockSizeText; if (!isset($Page) && !empty($licenseId)) { $startPos = -1; foreach ($highlightEntries as $highlightEntry) { if ($highlightEntry->getLicenseId() == $licenseId && ($startPos == -1 || $startPos > $highlightEntry->getStart())) { $startPos = $highlightEntry->getStart(); } } if ($startPos != -1) { $Page = floor($startPos / $blockSize); } } if (!empty($ShowText)) { echo $ShowText, "<hr>"; } $PageMenu = $this->GetFileJumpMenu($inputFile, $Page, $blockSize, $Uri); $PageSize = $blockSize * $Page; if (!empty($PageMenu) and !$getPageMenuInline) { $output .= "<center>{$PageMenu}</center><br>\n"; } $startAt = $PageSize; $endAt = $PageSize + $blockSize; $relevantHighlightEntries = array(); foreach ($highlightEntries as $highlightEntry) { if ($highlightEntry->getStart() < $endAt && $highlightEntry->getEnd() >= $startAt) { $relevantHighlightEntries[] = $highlightEntry; } } $this->highlightProcessor->sortHighlights($relevantHighlightEntries); $splitPositions = $this->highlightProcessor->calculateSplitPositions($relevantHighlightEntries); if ($Format == 'hex') { $output .= $this->getHex($inputFile, $PageSize, $this->blockSizeHex, $splitPositions); } else { $output .= $this->getText($inputFile, $PageSize, $Format == 'text' ? 0 : 1, $this->blockSizeText, $splitPositions, $insertBacklink); } if (!empty($PageMenu) and !$getPageMenuInline) { $output .= "<P /><center>{$PageMenu}</center><br>\n"; } if ($openedFin) { fclose($inputFile); } return $getPageMenuInline ? array($PageMenu, $output) : $output; }
/** * \brief This function returns the scheduler status. */ function Output() { $uTime = microtime(true); if ($this->State != PLUGIN_STATE_READY) { return 0; } $OutBuf = ""; $Folder = GetParm("folder", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); $Item = GetParm("item", PARM_INTEGER); $filter = GetParm("filter", PARM_STRING); /* check upload permissions */ $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } /* Get uploadtree_tablename */ $uploadtree_tablename = GetUploadtreeTableName($Upload); $this->uploadtree_tablename = $uploadtree_tablename; /* Use Traceback_parm_keep to ensure that all parameters are in order */ /******** disable cache to see if this is fast enough without it ***** $CacheKey = "?mod=" . $this->Name . Traceback_parm_keep(array("upload","item","folder", "orderBy", "orderc", "ordercp")) . "&show=$Show"; if ($this->UpdCache != 0) { $OutBuf .= ""; $Err = ReportCachePurgeByKey($CacheKey); } else $OutBuf .= ReportCacheGet($CacheKey); ***********************************************/ if (empty($OutBuf)) { switch ($this->OutputType) { case "XML": break; case "HTML": $OutBuf .= "\n<script language='javascript'>\n"; /* function to replace this page specifying a new filter parameter */ $OutBuf .= "function ChangeFilter(selectObj, upload, item){"; $OutBuf .= " var selectidx = selectObj.selectedIndex;"; $OutBuf .= " var filter = selectObj.options[selectidx].value;"; $OutBuf .= ' window.location.assign("?mod=' . $this->Name . '&upload="+upload+"&item="+item +"&filter=" + filter); '; $OutBuf .= "}</script>\n"; $OutBuf .= "<font class='text'>\n"; /************************/ /* Show the folder path */ /************************/ $OutBuf .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename) . "<P />\n"; if (!empty($Upload)) { /** advanced interface allowing user to select dataset (agent version) */ $Agent_name = "copyright"; $dataset = "copyright_dataset"; $arstable = "copyright_ars"; /** get proper agent_id */ $Agent_pk = GetParm("agent", PARM_INTEGER); if (empty($Agent_pk)) { $Agent_pk = LatestAgentpk($Upload, $arstable); } if ($Agent_pk == 0) { $text = _("No data available. Use Jobs > Agents to schedule a copyright scan."); $Msg = "<b>{$text}</b><p>"; $OutBuf .= $Msg; break; } $AgentSelect = AgentSelect($Agent_name, $Upload, true, $dataset, $dataset, $Agent_pk, "onchange=\"addArsGo('newds', 'copyright_dataset');\""); /** change the copyright result when selecting one version of copyright */ if (!empty($AgentSelect)) { $action = Traceback_uri() . "?mod=copyrighthist&upload={$Upload}&item={$Item}"; $OutBuf .= "<script type='text/javascript'>\n function addArsGo(formid, selectid)\n {\n var selectobj = document.getElementById(selectid);\n var Agent_pk = selectobj.options[selectobj.selectedIndex].value;\n document.getElementById(formid).action='{$action}'+'&agent='+Agent_pk;\n document.getElementById(formid).submit();\n return;\n }\n </script>"; /* form to select new dataset, show dataset */ $OutBuf .= "<form action='{$action}' id='newds' method='POST'>\n"; $OutBuf .= $AgentSelect; $OutBuf .= "</form>"; } $Uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); /* Select list for filters */ $SelectFilter = "<select name='view_filter' id='view_filter' onchange='ChangeFilter(this,{$Upload}, {$Item})'>"; $text = _("Show all"); $Selected = $filter == 'none' ? "selected" : ""; $SelectFilter .= "<option {$Selected} value='none'>{$text}"; $text = _("Show files without licenses"); $Selected = $filter == 'nolics' ? "selected" : ""; $SelectFilter .= "<option {$Selected} value='nolics'>{$text}"; $SelectFilter .= "</select>"; $OutBuf .= $SelectFilter; $OutBuf .= $this->ShowUploadHist($Item, $Uri, $filter, $uploadtree_tablename, $Agent_pk); } $OutBuf .= "</font>\n"; break; case "Text": break; default: } /* Cache Report */ /******** disable cache to see if this is fast enough without it ***** $Cached = false; ReportCachePut($CacheKey, $OutBuf); **************************************************/ } else { $Cached = true; } if (!$this->OutputToStdout) { return $OutBuf; } print "{$OutBuf}"; $Time = microtime(true) - $uTime; // convert usecs to secs $text = _("Elapsed time: %.2f seconds"); printf("<small>{$text}</small>", $Time); /******** disable cache to see if this is fast enough without it ***** $text = _("cached"); $text1 = _("Update"); if ($Cached) echo " <i>$text</i> <a href=\"$_SERVER[REQUEST_URI]&updcache=1\"> $text1 </a>"; **************************************************/ return; }
/** * \brief This function returns the scheduler status. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return 0; } $V = ""; $Folder = GetParm("folder", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); $Item = GetParm("item", PARM_INTEGER); if (empty($Item)) { return; } switch ($this->OutputType) { case "CSV": $text = _("License Count|License Summary|Path"); print "{$text}\n"; $this->ShowLicenseTree($Upload, $Item, $Uri); break; case "XML": break; case "HTML": $V .= "<font class='text'>\n"; /************************/ /* Show the folder path */ /************************/ $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse") . "<P />\n"; /******************************/ /* Get the folder description */ /******************************/ if (!empty($Folder)) { // $V .= $this->ShowFolder($Folder); } if (!empty($Upload)) { print $V; $V = ""; $Uri = preg_replace("/&item=([0-9]*)/", "", Traceback()); print "<table border='0' width='100%'>"; $this->ShowLicenseTree($Upload, $Item, $Uri); print "</table>"; } $V .= "</font>\n"; break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
function menu_to_1html($Menu, $ShowRefresh = 1, $ShowTraceback = 0, $ShowAll = 1) { $V = ""; $Std = ""; global $menu_to_1html_counter; if ($ShowTraceback) { global $Plugins; $Refresh =& $Plugins[plugin_find_id("refresh")]; if (!empty($Refresh)) { $text = _("Traceback"); $URL = Traceback_dir() . "?" . $Refresh->GetRefresh(); $Std .= "<a href='{$URL}' target='_top'>{$text}</a>"; } } if ($ShowRefresh) { if (!empty($Std)) { $Std .= " | "; } $text = _("Refresh"); $Std .= "<a href='" . Traceback() . "'>{$text}</a>"; } $First = 1; if (!empty($Menu)) { foreach ($Menu as $Val) { if ($Val->Name == "[BREAK]") { if (!$First) { $V .= " • "; } $First = 1; } else { if (!empty($Val->HTML)) { $V .= $Val->HTML; $First = 0; } else { if (!empty($Val->URI)) { if (!$First) { $V .= " | "; } $V .= "<a href='" . Traceback_uri() . "?mod=" . $Val->URI . "'"; if (!empty($Val->Title)) { $V .= " title='" . htmlentities($Val->Title, ENT_QUOTES) . "'"; } $V .= ">"; if (@$_SESSION['fullmenudebug'] == 1) { $V .= $Val->FullName . "(" . $Val->Order . ")"; } else { $V .= $Val->Name; } $V .= "</a>"; $First = 0; } else { if ($ShowAll) { if (!$First) { $V .= " | "; } if (@$_SESSION['fullmenudebug'] == 1) { $V .= $Val->FullName . "(" . $Val->Order . ")"; } else { $V .= $Val->Name; } $First = 0; } } } } } } if (!empty($Std)) { if (!$First) { $V .= " • "; } $V .= $Std; $Std = NULL; } $menu_to_1html_counter++; return "<div id='menu1html-{$menu_to_1html_counter}' align='right' style='padding:0px 5px 0px 5px'><small>{$V}</small></div>"; }
/** * \brief Generate the view contents in HTML and sends it * to stdout. * * \param $Name - the name for this plugin. * * \note This function is intended to be called from other plugins. */ function ShowView($Fin = NULL, $BackMod = "browse", $ShowMenu = 1, $ShowHeader = 1, $ShowText = NULL, $ViewOnly = False, $DispView = True) { if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; global $Plugins; $Upload = GetParm("upload", PARM_INTEGER); if (!empty($Upload)) { $UploadPerm = GetUploadPerm($Upload); if ($UploadPerm < PERM_READ) { return; } } $Folder = GetParm("folder", PARM_INTEGER); $Show = GetParm("show", PARM_STRING); $Item = GetParm("item", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $Page = GetParm("page", PARM_INTEGER); $bucketagent_pk = GetParm("bapk", PARM_INTEGER); if (!$Fin && (empty($Item) || empty($Upload))) { return; } if (empty($Page)) { $Page = 0; } /* Get uploadtree table name */ $uploadtree_tablename = "uploadtree"; if (!empty($Upload)) { $uploadtree_tablename = GetUploadtreeTablename($Upload); } switch (GetParm("format", PARM_STRING)) { case 'hex': $Format = 'hex'; break; case 'text': $Format = 'text'; break; case 'flow': $Format = 'flow'; break; default: /* Determine default show based on mime type */ if (empty($Item)) { $Format = 'text'; } else { $Meta = GetMimeType($Item); list($Type, $Junk) = explode("/", $Meta, 2); if ($Type == 'text') { $Format = 'flow'; } else { switch ($Meta) { case "application/octet-string": case "application/x-awk": case "application/x-csh": case "application/x-javascript": case "application/x-perl": case "application/x-shellscript": case "application/x-rpm-spec": case "application/xml": case "message/rfc822": $Format = 'flow'; break; default: $Format = 'flow'; } } } break; } /********************************** Display micro header **********************************/ if ($ShowHeader) { $Uri = Traceback_uri() . "?mod=browse"; $Opt = ""; if (!empty($Item)) { $Opt .= "&item={$Item}"; } if (!empty($Upload)) { $Opt .= "&upload={$Upload}"; } if (!empty($Folder)) { $Opt .= "&folder={$Folder}"; } if (!empty($Show)) { $Opt .= "&show={$Show}"; } /* No item */ $V .= Dir2Browse($BackMod, $Item, NULL, 1, "View", -1, '', '', $uploadtree_tablename) . "<P />\n"; } // if ShowHeader $this->SortHighlightMenu(); /*********************************** Display file contents ***********************************/ print $V; $V = ""; $openedFin = False; if (empty($Fin)) { $Fin = @fopen(RepPathItem($Item), "rb"); if ($Fin) { $openedFin = true; } if (empty($Fin)) { /* Added by vincent implement when view files which not in repository, ask user if want to reunpack*/ /** BEGIN **/ /* If this is a POST, then process the request. */ $uploadunpack = GetParm('uploadunpack', PARM_INTEGER); $uploadpk = $Upload; $flag = 0; $P =& $Plugins[plugin_find_id("ui_reunpack")]; $state = $P->CheckStatus($uploadpk, "reunpack", "ununpack"); //print "<p>$state</p>"; if ($state == 0 || $state == 2) { if (!empty($uploadunpack)) { $rc = $P->AgentAdd($uploadpk); if (empty($rc)) { /* Need to refresh the screen */ $text = _("Unpack added to job queue"); $V .= displayMessage($text); $flag = 1; $text = _("Reunpack job is running: you can see it in"); $text1 = _("jobqueue"); print "<p> <font color=red>{$text} <a href='" . Traceback_uri() . "?mod=showjobs'>{$text1}</a></font></p>"; } else { $text = _("Unpack of Upload failed"); $V .= displayMessage("{$text}: {$rc}"); } print $V; } } else { $flag = 1; $text = _("Reunpack job is running: you can see it in"); $text1 = _("jobqueue"); print "<p> <font color=red>{$text} <a href='" . Traceback_uri() . "?mod=showjobs'>{$text1}</a></font></p>"; } $text = _("File contents are not available in the repository."); print "{$text}\n"; $P =& $Plugins[plugin_find_id("ui_reunpack")]; print $P->ShowReunpackView($Item, $flag); return; } /** END **/ } rewind($Fin); $Pages = ""; $Uri = preg_replace('/&page=[0-9]*/', '', Traceback()); $HighlightMenu = ""; $HighlightMenu .= "</center>"; // some fcn left a dangling center if ($Format == 'hex') { $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_HEX, $ViewOnly, $DispView); if (!empty($HighlightMenu)) { print "<center>{$HighlightMenu}</center><hr>\n"; } $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_HEX, $Uri); $PageSize = VIEW_BLOCK_HEX * $Page; if (!empty($PageMenu)) { print "<center>{$PageMenu}</center><br>\n"; } $this->ShowHex($Fin, $PageSize, VIEW_BLOCK_HEX); if (!empty($PageMenu)) { print "<P /><center>{$PageMenu}</center><br>\n"; } } else { if ($Format == 'text') { $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_TEXT, $ViewOnly, $DispView); if (!empty($HighlightMenu)) { print "<center>{$HighlightMenu}</center><hr>\n"; } $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_TEXT, $Uri); $PageSize = VIEW_BLOCK_TEXT * $Page; if (!empty($PageMenu)) { print "<center>{$PageMenu}</center><br>\n"; } $this->ShowText($Fin, $PageSize, 0, VIEW_BLOCK_TEXT); if (!empty($PageMenu)) { print "<P /><center>{$PageMenu}</center><br>\n"; } } else { if ($Format == 'flow') { $HighlightMenu .= $this->GetHighlightMenu(VIEW_BLOCK_TEXT, $ViewOnly, $DispView); if (!empty($HighlightMenu)) { print "<center>{$HighlightMenu}</center><hr>\n"; } $PageMenu = $this->GetFileJumpMenu($Fin, $Page, VIEW_BLOCK_TEXT, $Uri); $PageSize = VIEW_BLOCK_TEXT * $Page; if (!empty($PageMenu)) { print "<center>{$PageMenu}</center><br>\n"; } if (!empty($ShowText)) { echo $ShowText, "<hr>"; } $this->ShowText($Fin, $PageSize, 1, VIEW_BLOCK_TEXT); if (!empty($PageMenu)) { print "<P /><center>{$PageMenu}</center><br>\n"; } } } } if ($openedFin) { fclose($Fin); } return; }
/** * This function is called when user output is * requested. This function is responsible for content. * The $ToStdout flag is "1" if output should go to stdout, and * 0 if it should be returned as a string. (Strings may be parsed * and used by other plugins.) */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; global $Plugins; $View =& $Plugins[plugin_find_id("view")]; $LicShortname = GetParm("lic", PARM_TEXT); $LicIdSet = GetParm("licset", PARM_INTEGER); $Item = GetParm("item", PARM_INTEGER); $nomosagent_pk = GetParm("napk", PARM_INTEGER); $Upload = GetParm("upload", PARM_INTEGER); $LicenseFileId = GetParm("fl_pk", PARM_INTEGER); /* only display nomos results if we know the nomosagent_pk Otherwise, we don't know what results to display. */ $nomos_out = ""; if (!empty($nomosagent_pk)) { $pfile_pk = 0; // unknown, only have uploadtree_pk aka $Item $nomos_license_array = GetFileLicenses($nomosagent_pk, $pfile_pk, $Item, "uploadtree", "yes"); //$nomos_license_array = explode(",", $nomos_license_string); //print "nomos_license_string is:$nomos_license_string\n"; //print_r($nomos_license_array); if (!empty($nomos_license_array)) { $text = _("The Nomos license scanner found:"); $nomos_out = "{$text} <b>"; } $rec_flag = 0; foreach ($nomos_license_array as $fl_pk => $one_license) { $one_license = trim($one_license); if (0 == $rec_flag) { $rec_flag = 1; } else { $nomos_out .= " ,"; } $url_one_license = urlencode($one_license); $text = _("License Reference"); $nomos_out .= "<a title='{$text}' href='javascript:;'"; $nomos_out .= "onClick=\"javascript:window.open('"; $nomos_out .= Traceback_uri(); $nomos_out .= "?mod=view-license"; $nomos_out .= "&lic="; $nomos_out .= $url_one_license; $nomos_out .= "&upload="; $nomos_out .= $Upload; $nomos_out .= "&item="; $nomos_out .= $Item; $text = _("License Text"); $nomos_out .= "','{$text}','width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes');\""; $nomos_out .= ">{$one_license}"; $nomos_out .= "</a>"; /** edit this license */ $text = _("Edit"); $nomosAgentpk = LatestAgentpk($Upload, "nomos_ars"); /** go to the license change page */ if (plugin_find_id('change_license') >= 0) { $text1 = _("Edit This Licence Reference"); $nomos_out .= "<a title='{$text1}' href='" . Traceback_uri() . "?mod=change_license&fl_pk={$fl_pk}"; $nomos_out .= "&upload={$Upload}&item={$Item}&napk={$nomosAgentpk}"; $nomos_out .= "' style='color:#ff0000;font-style:italic'>[{$text}]</a>"; } } } if (!empty($LicShortname)) { $this->ViewLicenseText($Item, $LicShortname, $LicIdSet, $nomos_out); return; } if (empty($Item)) { return; } $ModBack = GetParm("modback", PARM_STRING); if (empty($ModBack) && !empty($nomos_out)) { $ModBack = "nomoslicense"; } /* Load bSAM licenses for this file */ $bsam_plugin_key = plugin_find_id("license"); /** -1, can not find bsam plugin, or find */ /** if the bsam plugin does exist, get and show bSAM licenses */ if (-1 != $bsam_plugin_key) { $Results = $this->LicenseGetForFile($Item); /* Show bSAM licenses */ if (count($Results) <= 0) { /* Since LicenseGetForFile() doesn't distinguish between files that bSAM ran on and found no licenses, and files that bSAM was never run on (both cases return no $Results rows), don't tell the user a misleading "No licenses found". */ // $View->AddHighlight(-1,-1,'white',NULL,"No licenses found"); if (empty($ModBack)) { $ModBack = "browse"; } } else { foreach ($Results as $R) { if (empty($R['pfile_path'])) { continue; } if (!empty($R['phrase_text'])) { $RefURL = NULL; if ($R['licterm_name'] != 'Phrase') { $R['phrase_text'] = ''; } } else { $RefURL = Traceback() . "&lic=" . $R['lic_fk'] . "&licset=" . $R['tok_pfile_start']; } $this->ConvertLicPathToHighlighting($R, $R['licterm_name'], $RefURL); } if (empty($ModBack)) { $ModBack = "license"; } } } $View->ShowView(NULL, $ModBack, 1, 1, $nomos_out); return; }
/** * \brief Given a Folder_pk, list every upload in the folder. */ function ShowFolder($Folder, $Show) { global $Plugins; global $PG_CONN; $V = ""; /* Get list of uploads in this folder */ $sql = "SELECT * FROM upload\n INNER JOIN uploadtree ON upload_fk = upload_pk\n AND upload.pfile_fk = uploadtree.pfile_fk\n AND parent IS NULL\n AND lft IS NOT NULL \n WHERE upload_pk IN\n (SELECT child_id FROM foldercontents WHERE foldercontents_mode & 2 != 0 AND parent_fk = {$Folder})\n ORDER BY upload_filename,upload_desc,upload_pk,upload_origin;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $Uri = Traceback_uri() . "?mod=" . $this->Name; $V .= "<table border=1 width='100%'>"; $V .= "<tr><td valign='top' width='20%'>\n"; $V .= FolderListScript(); $text = _("Folder Navigation"); $V .= "<center><H3>{$text}</H3></center>\n"; $V .= "<center><small>"; if ($Folder != GetUserRootFolder()) { $text = _("Top"); $V .= "<a href='" . Traceback_uri() . "?mod=" . $this->Name . "'>{$text}</a> |"; } $text = _("Expand"); $V .= "<a href='javascript:Expand();'>{$text}</a> |"; $text = _("Collapse"); $V .= "<a href='javascript:Collapse();'>{$text}</a> |"; $text = _("Refresh"); $V .= "<a href='" . Traceback() . "'>{$text}</a>"; $V .= "</small></center>"; $V .= "<P>\n"; $V .= "<form>\n"; $V .= FolderListDiv($Folder, 0, $Folder, 1); $V .= "</form>\n"; $V .= "</td><td valign='top'>\n"; $text = _("Uploads"); $V .= "<center><H3>{$text}</H3></center>\n"; $V .= "<table class='text' id='browsetbl' border=0 width='100%' cellpadding=0>\n"; $text = _("Upload Name and Description"); $text1 = _("Upload Date"); $V .= "<th>{$text}</th><th>{$text1}</th></tr>\n"; /* Browse-Pfile menu */ $MenuPfile = menu_find("Browse-Pfile", $MenuDepth); /* Browse-Pfile menu without the compare menu item */ $MenuPfileNoCompare = menu_remove($MenuPfile, "Compare"); while ($Row = pg_fetch_assoc($result)) { if (empty($Row['upload_pk'])) { continue; } $Desc = htmlentities($Row['upload_desc']); $UploadPk = $Row['upload_pk']; /* check permission on upload */ $UploadPerm = GetUploadPerm($UploadPk); if ($UploadPerm < PERM_READ) { continue; } $Name = $Row['ufile_name']; if (empty($Name)) { $Name = $Row['upload_filename']; } /* If UploadtreePk is not an artifact, then use it as the root. Else get the first non artifact under it. */ if (Isartifact($Row['ufile_mode'])) { $UploadtreePk = DirGetNonArtifact($Row['uploadtree_pk'], $uploadtree_tablename); } else { $UploadtreePk = $Row['uploadtree_pk']; } $V .= "<tr><td>"; if (IsContainer($Row['ufile_mode'])) { $V .= "<a href='{$Uri}&upload={$UploadPk}&folder={$Folder}&item={$UploadtreePk}&show={$Show}'>"; $V .= "<b>" . $Name . "</b>"; $V .= "</a>"; } else { $V .= "<b>" . $Name . "</b>"; } $V .= "<br>"; if (!empty($Desc)) { $V .= "<i>" . $Desc . "</i><br>"; } $Upload = $Row['upload_pk']; $Parm = "upload={$Upload}&show={$Show}&item=" . $Row['uploadtree_pk']; if (Iscontainer($Row['ufile_mode'])) { $V .= menu_to_1list($MenuPfile, $Parm, " ", " ", 1, $UploadPk); } else { $V .= menu_to_1list($MenuPfileNoCompare, $Parm, " ", " ", 1, $UploadPk); } /* Job queue link */ $text = _("History"); if (plugin_find_id('showjobs') >= 0) { $V .= "<a href='" . Traceback_uri() . "?mod=showjobs&upload={$UploadPk}'>[{$text}]</a>"; $V .= "</td>\n"; $V .= "<td align='right'>" . substr($Row['upload_ts'], 0, 19) . "</td>"; } $V .= "<tr><td colspan=2> </td></tr>\n"; } pg_free_result($result); $V .= "</table>\n"; $V .= "</td></tr>\n"; $V .= "</table>\n"; return $V; }
/** * \brief Generate the text for this plugin. */ function Output() { if ($this->State != PLUGIN_STATE_READY) { return; } global $PG_CONN; $V = ""; switch ($this->OutputType) { case "XML": break; case "HTML": $Filename = GetParm("filename", PARM_STRING); $Uri = preg_replace("/&filename=[^&]*/", "", Traceback()); /* Prompt for the string to search for */ $V .= "<form action='{$Uri}' method='POST'>\n"; $V .= "<ul>\n"; $V .= "<li>Enter the string to search for:<P>"; $V .= "<INPUT type='text' name='filename' size='40' value='" . htmlentities($Filename) . "'>\n"; $V .= "</ul>\n"; $V .= "<input type='submit' value='Search!'>\n"; $V .= "</form>\n"; if (!empty($Filename)) { /* Get uploadtree_pk's for all debian uploads */ $sql = "SELECT uploadtree_pk, upload_pk, upload_filename FROM upload INNER JOIN uploadtree ON upload_fk=upload_pk AND parent IS NULL WHERE upload_filename LIKE '%{$Filename}%';"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); if (empty($row['upload_pk'])) { $V = "There are no uploads with {$Filename} in the description."; } else { /* Loop thru results to obtain all licenses in their uploadtree recs*/ $Lics = array(); while ($Row = pg_fetch_array($result)) { if (empty($Row['upload_pk'])) { continue; } else { LicenseGetAll($Row[uploadtree_pk], $Lics); } $V = "<option value='" . $Row['upload_pk'] . "'>{$Name}</option>\n"; } pg_free_result($result); $V .= "</select><P />\n"; arsort($Lics); $V .= "<table border=1>\n"; foreach ($Lics as $key => $value) { if ($key == " Total ") { $V .= "<tr><th>{$key}<th>{$value}\n"; } else { if (plugin_find_id('search_file_by_license') >= 0) { $V .= "<tr><td><a href='/repo/?mod=search_file_by_license&item={$Row['uploadtree_pk']}&lic=" . urlencode($key) . "'>{$key}</a><td align='right'>{$value}\n"; } else { $V .= "<tr><td>{$key}<td align='right'>{$value}\n"; } } } $V .= "</table>\n"; // print "<pre>"; print_r($Lics); print "</pre>"; } } break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print $V; return; }