コード例 #1
0
ファイル: bucket-diff.php プロジェクト: DanielDobre/fossology
 /**
  * @brief Get uploadtree info for a given uploadtree_pk.
  * @param $Uploadtree_pk
  * @return array with uploadtree record and:\n
  *   agent_pk\n
  *   bucketagent_pk\n
  *   nomosagent_pk\n
  *   bucketpool_pk\n
  */
 function GetTreeInfo($Uploadtree_pk)
 {
     global $PG_CONN;
     $TreeInfo = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$Uploadtree_pk}");
     $TreeInfo['agent_pk'] = LatestAgentpk($TreeInfo['upload_fk'], "nomos_ars");
     /* Get the ars_pk of the scan to display, also the select list  */
     $ars_pk = GetArrayVal("ars", $_GET);
     $BucketSelect = SelectBucketDataset($TreeInfo['upload_fk'], $ars_pk, "selectbdata", "onchange=\"addArsGo('newds','selectbdata');\"");
     $TreeInfo['ars_pk'] = $ars_pk;
     if ($ars_pk == 0) {
         /* No bucket data for this upload */
         return $BucketSelect;
         // $BucketSelect is error message
     }
     /* Get scan keys */
     $where = "where ars_pk={$ars_pk}";
     $row = GetSingleRec("bucket_ars", $where);
     if (empty($row)) {
         Fatal("No bucket data {$where}", __FILE__, __LINE__);
     }
     $TreeInfo['bucketagent_pk'] = $row["agent_fk"];
     $TreeInfo['nomosagent_pk'] = $row["nomosagent_fk"];
     $TreeInfo['bucketpool_pk'] = $row["bucketpool_fk"];
     unset($row);
     return $TreeInfo;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 /**
  * \brief Given an $Uploadtree_pk, display: 
  *   - The histogram for the directory BY LICENSE.
  *   - The file listing for the directory.
  */
 function ShowUploadHist($Uploadtree_pk, $Uri, $tag_pk)
 {
     global $PG_CONN;
     $VF = "";
     // return values for file listing
     $VLic = "";
     // return values for license histogram
     $V = "";
     // total return value
     $UniqueTagArray = array();
     global $Plugins;
     $ModLicView =& $Plugins[plugin_find_id("view-license")];
     /*******  Get license names and counts  ******/
     /* Find lft and rgt bounds for this $Uploadtree_pk  */
     $sql = "SELECT lft,rgt,upload_fk FROM {$this->uploadtree_tablename}\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);
     if (empty($lft)) {
         $text = _("Job unpack/adj2nest hasn't completed.");
         $VLic = "<b>{$text}</b><p>";
         return $VLic;
     }
     /* Find total number of files for this $Uploadtree_pk
      * Exclude artifacts and directories.
      */
     $sql = "SELECT count(*) as count FROM {$this->uploadtree_tablename}\n              WHERE upload_fk = {$upload_pk} \n                    and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt}\n                    and ((ufile_mode & (1<<28))=0) \n                    and ((ufile_mode & (1<<29))=0) and pfile_fk!=0";
     //$uTime = microtime(true);
     $result = pg_query($PG_CONN, $sql);
     //printf( "<small>count files Elapsed time: %.2f seconds</small>", microtime(true) - $uTime);  // convert usecs to secs
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $FileCount = $row["count"];
     pg_free_result($result);
     /*  Get the counts for each license under this UploadtreePk*/
     if (empty($tag_pk)) {
         $TagTable = "";
         $TagClause = "";
     } else {
         $TagTable = " right join tag_file on tag_file.pfile_fk=license_file_ref.pfile_fk ";
         $TagClause = " and tag_fk={$tag_pk}";
     }
     /** advanced interface allowing user to select dataset (agent version) */
     $Agent_name = 'nomos';
     $dataset = "nomos_dataset";
     $Agent_pk = GetParm("agent", PARM_STRING);
     /** if do not specify agent, get the latest agent result for this upload */
     if (empty($Agent_pk)) {
         $Agent_pk = LatestAgentpk($upload_pk, "nomos_ars");
     }
     if ($Agent_pk == 0) {
         $text = _("No data available.  Use Jobs > Agents to schedule a license scan.");
         $VLic = "<b>{$text}</b><p>";
         return $VLic;
     }
     /** get nomos select dataset */
     $AgentSelect = AgentSelect($Agent_name, $upload_pk, true, $dataset, $dataset, $Agent_pk, "onchange=\"addArsGo('newds', 'nomos_dataset');\"");
     /** change the nomos license result when selecting one version of nomos */
     if (!empty($AgentSelect)) {
         $action = Traceback_uri() . "?mod=nomoslicense&upload={$upload_pk}&item={$Uploadtree_pk}";
         $VLic .= "<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 */
         $VLic .= "<form action='{$action}' id='newds' method='POST'>\n";
         $VLic .= $AgentSelect;
         $VLic .= "</form>";
     }
     $orderBy = array('count', 'license_name');
     $ordersql = "liccount desc";
     static $ordercount = 1;
     static $orderlic = 1;
     /** sorting by count/licnese name */
     if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
         $order = $_GET['orderBy'];
         if (isset($_GET['orderc'])) {
             $ordercount = $_GET['orderc'];
         }
         if (isset($_GET['orderl'])) {
             $orderlic = $_GET['orderl'];
         }
         if ('count' == $order && 1 == $ordercount) {
             $ordersql = "liccount desc";
             $ordercount = 0;
         } else {
             if ('count' == $order && 0 == $ordercount) {
                 $ordersql = "liccount ";
                 $ordercount = 1;
             } else {
                 if ('license_name' == $order && 1 == $orderlic) {
                     $ordersql = "rf_shortname ";
                     $orderlic = 0;
                 } else {
                     if ('license_name' == $order && 0 == $orderlic) {
                         $ordersql = "rf_shortname desc";
                         $orderlic = 1;
                     }
                 }
             }
         }
     }
     // Void ARE EXCLUDED FROM LICENSE COUNT
     $sql = "SELECT distinct(SS.rf_shortname) as licname, count(SS.rf_shortname) as liccount, SS.rf_shortname from \n            (SELECT distinct(license_file_ref.pfile_fk), rf_shortname\n            from license_file_ref {$TagTable}\n            right join {$this->uploadtree_tablename} on license_file_ref.pfile_fk={$this->uploadtree_tablename}.pfile_fk \n            where rf_shortname <> 'Void' and upload_fk='{$upload_pk}' and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt} \n              and agent_fk={$Agent_pk} {$TagClause} group by license_file_ref.pfile_fk, rf_shortname\n            ) as SS\n            group by rf_shortname order by {$ordersql}";
     //$uTime = microtime(true);
     $result = pg_query($PG_CONN, $sql);
     //$Time = microtime(true) - $uTime;  // convert usecs to secs
     //$text = _("histogram Elapsed time: %.2f seconds");
     //printf( "<small>$text</small>", $Time);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     /* Write license histogram to $VLic  */
     $LicCount = 0;
     $UniqueLicCount = 0;
     $NoLicFound = 0;
     $VLic .= "<table border=1 width='100%' id='lichistogram'>\n";
     $text = _("Count");
     $VLic .= "<tr><th>";
     $VLic .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "tag", "agent")) . "&orderBy=count&orderc={$ordercount}>{$text}</a>";
     $VLic .= "</th>";
     $text = _("Files");
     $VLic .= "<th width='10%'>{$text}</th>";
     $text = _("License Name");
     $VLic .= "<th>";
     $VLic .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "tag", "agent")) . "&orderBy=license_name&orderl={$orderlic}>{$text}</a>";
     $VLic .= "</th></tr>\n";
     while ($row = pg_fetch_assoc($result)) {
         $UniqueLicCount++;
         $LicCount += $row['liccount'];
         /*  Count  */
         $VLic .= "<tr><td align='right'>{$row['liccount']}</td>";
         /*  Show  */
         $VLic .= "<td align='center'><a href='";
         $VLic .= Traceback_uri();
         $text = _("Show");
         $tagClause = $tag_pk ? "&tag={$tag_pk}" : "";
         $VLic .= "?mod=list_lic_files&napk={$Agent_pk}&item={$Uploadtree_pk}&lic=" . urlencode($row['rf_shortname']) . $tagClause . "'>{$text}</a></td>";
         /*  License name  */
         $VLic .= "<td align='left'>";
         $rf_shortname = rawurlencode($row['rf_shortname']);
         $VLic .= "<a id='{$rf_shortname}' onclick='FileColor_Get(\"" . Traceback_uri() . "?mod=ajax_filelic&napk={$Agent_pk}&item={$Uploadtree_pk}&lic={$rf_shortname}&ut={$this->uploadtree_tablename}\")'";
         $VLic .= ">{$row['licname']} </a>";
         $VLic .= "</td>";
         $VLic .= "</tr>\n";
         if ($row['licname'] == "No_license_found") {
             $NoLicFound = $row['liccount'];
         }
     }
     $VLic .= "</table>\n";
     $VLic .= "<p>\n";
     $VLic .= _("Hint: Click on the license name to ");
     $text = _("highlight");
     $VLic .= "<span style='background-color:{$this->HighlightColor}'>{$text} </span>";
     $VLic .= _("where the license is found in the file listing.<br>\n");
     $VLic .= "<table border=0 id='licsummary'>";
     $text = _("Unique licenses");
     $VLic .= "<tr><td align=right>{$UniqueLicCount}</td><td>{$text}</td></tr>";
     $NetLic = $LicCount - $NoLicFound;
     $text = _("Licenses found");
     $VLic .= "<tr><td align=right>{$NetLic}</td><td>{$text}</td></tr>";
     $text = _("Files with no licenses");
     $VLic .= "<tr><td align=right>{$NoLicFound}</td><td>{$text}</td></tr>";
     $text = _("Files");
     $VLic .= "<tr><td align=right>{$FileCount}</td><td>{$text}</td></tr>";
     $VLic .= "</table>";
     pg_free_result($result);
     /*******    File Listing     ************/
     /* Get ALL the items under this Uploadtree_pk */
     $Children = GetNonArtifactChildren($Uploadtree_pk, $this->uploadtree_tablename);
     /* Filter out Children that don't have tag */
     if (!empty($tag_pk)) {
         TagFilter($Children, $tag_pk, $this->uploadtree_tablename);
     }
     $ChildCount = 0;
     $ChildLicCount = 0;
     //$uTime = microtime(true);
     if (!empty($Children)) {
         /* For alternating row background colors */
         $RowStyle1 = "style='background-color:#ecfaff'";
         // pale blue
         $RowStyle2 = "style='background-color:#ffffe3'";
         // pale yellow
         $ColorSpanRows = 1;
         // Alternate background color every $ColorSpanRows
         $RowNum = 0;
         $VF .= "<table border=0 id='dirlist'>";
         foreach ($Children as $C) {
             if (empty($C)) {
                 continue;
             }
             $IsDir = Isdir($C['ufile_mode']);
             $IsContainer = Iscontainer($C['ufile_mode']);
             /* Determine the hyperlink for non-containers to view-license  */
             if (!empty($C['pfile_fk']) && !empty($ModLicView)) {
                 $LinkUri = Traceback_uri();
                 $LinkUri .= "?mod=view-license&napk={$Agent_pk}&upload={$upload_pk}&item={$C['uploadtree_pk']}";
             } else {
                 $LinkUri = NULL;
             }
             /* Determine link for containers */
             if (Iscontainer($C['ufile_mode'])) {
                 $uploadtree_pk = DirGetNonArtifact($C['uploadtree_pk'], $this->uploadtree_tablename);
                 $LicUri = "{$Uri}&item=" . $uploadtree_pk;
             } else {
                 $LicUri = NULL;
             }
             /* Populate the output ($VF) - file list */
             /* id of each element is its uploadtree_pk */
             /* Set alternating row background color - repeats every $ColorSpanRows rows */
             $RowStyle = $RowNum++ % (2 * $ColorSpanRows) < $ColorSpanRows ? $RowStyle1 : $RowStyle2;
             $VF .= "<tr {$RowStyle}>";
             $VF .= "<td id='{$C['uploadtree_pk']}' align='left'>";
             $HasHref = 0;
             $HasBold = 0;
             if ($IsContainer) {
                 $VF .= "<a href='{$LicUri}'>";
                 $HasHref = 1;
                 $VF .= "<b>";
                 $HasBold = 1;
             } else {
                 if (!empty($LinkUri)) {
                     $VF .= "<a href='{$LinkUri}'>";
                     $HasHref = 1;
                 }
             }
             $VF .= $C['ufile_name'];
             if ($IsDir) {
                 $VF .= "/";
             }
             if ($HasBold) {
                 $VF .= "</b>";
             }
             if ($HasHref) {
                 $VF .= "</a>";
             }
             /* show licenses under file name */
             $VF .= "<br>";
             $VF .= GetFileLicenses_string($Agent_pk, $C['pfile_fk'], $C['uploadtree_pk'], $this->uploadtree_tablename);
             $VF .= "</td><td valign='top'>";
             /* display file links */
             $VF .= FileListLinks($C['upload_fk'], $C['uploadtree_pk'], $Agent_pk, $C['pfile_fk'], true, $UniqueTagArray, $this->uploadtree_tablename);
             $VF .= "</td>";
             $VF .= "</tr>\n";
             $ChildCount++;
         }
         $VF .= "</table>\n";
     }
     //$Time = microtime(true) - $uTime;  // convert usecs to secs
     //$text = _("Sum of children Elapsed time: %.2f seconds");
     //printf( "<small>$text</small>", $Time);
     /***************************************
          Problem: $ChildCount can be zero!
         This happens if you have a container that does not
         unpack to a directory.  For example:
         file.gz extracts to archive.txt that contains a license.
         Same problem seen with .pdf and .Z files.
         Solution: if $ChildCount == 0, then just view the license!
     
         $ChildCount can also be zero if the directory is empty.
         ***************************************/
     if ($ChildCount == 0) {
         $sql = "SELECT * FROM {$this->uploadtree_tablename} WHERE uploadtree_pk = '{$Uploadtree_pk}';";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $row = pg_fetch_assoc($result);
         pg_free_result($result);
         if (IsDir($row['ufile_mode'])) {
             return;
         }
         $ModLicView =& $Plugins[plugin_find_id("view-license")];
         return $ModLicView->Output();
     }
     $V .= ActiveHTTPscript("FileColor");
     /* Add javascript for color highlighting
         This is the response script needed by ActiveHTTPscript
        responseText is license name',' followed by a comma seperated list of uploadtree_pk's */
     $script = "\n      <script type=\"text/javascript\" charset=\"utf-8\">\n        var Lastutpks='';   /* save last list of uploadtree_pk's */\n        var LastLic='';   /* save last License (short) name */\n        var color = '{$this->HighlightColor}';\n        function FileColor_Reply()\n        {\n          if ((FileColor.readyState==4) && (FileColor.status==200))\n          {\n            /* remove previous highlighting */\n            var numpks = Lastutpks.length;\n            if (numpks > 0) document.getElementById(LastLic).style.backgroundColor='white';\n            while (numpks)\n            {\n              document.getElementById(Lastutpks[--numpks]).style.backgroundColor='white';\n            }\n\n            utpklist = FileColor.responseText.split(',');\n            LastLic = utpklist.shift();\n            numpks = utpklist.length;\n            Lastutpks = utpklist;\n\n            /* apply new highlighting */\n            elt = document.getElementById(LastLic);\n            if (elt != null) elt.style.backgroundColor=color;\n            while (numpks)\n            {\n              document.getElementById(utpklist[--numpks]).style.backgroundColor=color;\n            }\n          }\n          return;\n        }\n      </script>\n    ";
     $V .= $script;
     /******  Filters  *******/
     /* Only display the filter pulldown if there are filters available 
      * Currently, this is only tags.
      */
     /** @todo qualify with tag namespace to avoid tag name collisions.  **/
     /* turn $UniqueTagArray into key value pairs ($SelectData) for select list */
     $SelectData = array();
     if (count($UniqueTagArray)) {
         foreach ($UniqueTagArray as $UTA_row) {
             $SelectData[$UTA_row['tag_pk']] = $UTA_row['tag_name'];
         }
         $V .= "Tag filter";
         $myurl = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "item"));
         $Options = " id='filterselect' onchange=\"js_url(this.value, '{$myurl}&tag=')\"";
         $V .= Array2SingleSelectTag($SelectData, "tag_ns_pk", $tag_pk, true, false, $Options);
     }
     /****** Combine VF and VLic ********/
     $V .= "<table border=0 width='100%'>\n";
     $V .= "<tr><td valign='top' >{$VLic}</td><td valign='top'>{$VF}</td></tr>\n";
     $V .= "</table>\n";
     $V .= "<hr />\n";
     return $V;
 }
コード例 #4
0
ファイル: hist.php プロジェクト: pombredanne/fossology-test
 /**
  * \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;
 }
コード例 #5
0
ファイル: acme_review.php プロジェクト: DanielDobre/fossology
 /**
  * \brief Display the loaded menu and plugins.
  */
 function Output()
 {
     global $Plugins;
     global $PG_CONN;
     //phpinfo();
     $CriteriaCount = 0;
     $V = "";
     $GETvars = "";
     $upload_pk = GetParm("upload", PARM_INTEGER);
     $detail = GetParm("detail", PARM_INTEGER);
     $detail = empty($detail) ? 0 : 1;
     $folic = GetParm("folic", PARM_INTEGER);
     $savebtn = GetParm("savebtn", PARM_RAW);
     $spdxbtn = GetParm("spdxbtn", PARM_RAW);
     $agent_pk = LatestAgentpk($upload_pk, "nomos_ars");
     if (empty($agent_pk)) {
         echo "Missing fossology license data.  Run a license scan on this upload.<br>";
         exit;
     }
     $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
     // Check if we have data in the acme_upload table, if not then load it
     $acme_uploadRec = GetSingleRec("acme_upload", "where upload_fk={$upload_pk} ");
     if (empty($acme_uploadRec)) {
         // populate acme_upload
         $MinCount = 1;
         $nomosAgentpk = LatestAgentpk($upload_pk, "nomos_ars");
         $acme_project_array = $this->GetProjectArray1($upload_pk, $nomosAgentpk, $MinCount);
         // low level
         $this->Populate_acme_upload($acme_project_array, $upload_pk, 1);
         $acme_project_array = $this->GetProjectArray0($upload_pk, $nomosAgentpk, $MinCount);
         // high level
         $this->Populate_acme_upload($acme_project_array, $upload_pk, 0);
     }
     $sql = "select * from acme_upload, acme_project where acme_project_pk=acme_project_fk and detail={$detail} and upload_fk={$upload_pk}";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $acme_project_array = pg_fetch_all($result);
     $acme_project_array_orig = $acme_project_array;
     // save the original state so we know which records to update
     /* If the save or spdx buttons were clicked, update $acme_project_array and save the data in the acme_upload table */
     if (!empty($savebtn) or !empty($spdxbtn)) {
         /* First set all projects include to false */
         foreach ($acme_project_array as &$project) {
             $project['include'] = 'f';
         }
         /* Now turn on projects include to match form */
         if (array_key_exists('includeproj', $_POST)) {
             $includeArray = $_POST['includeproj'];
             foreach ($acme_project_array as &$project) {
                 if (array_key_exists($project['acme_project_fk'], $includeArray)) {
                     $project['include'] = "t";
                 }
             }
         }
         /* Finally, update the db with any changed include states */
         $NumRecs = count($acme_project_array);
         for ($i = 0; $i < $NumRecs; $i++) {
             $project = $acme_project_array[$i];
             $project_orig = $acme_project_array_orig[$i];
             if ($project['include'] != $project_orig['include']) {
                 $include = $project['include'] ? "true" : "false";
                 $sql = "update acme_upload set include='{$include}' where acme_upload_pk='{$project['acme_upload_pk']}'";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 pg_free_result($result);
             }
         }
     }
     /* aggregate the fossology licenses for each pfile and each acme_project */
     if ($folic) {
         foreach ($acme_project_array as &$project) {
             $sql = "select uploadtree_pk from acme_pfile, uploadtree where acme_project_fk={$project['acme_project_fk']} \n                and acme_pfile.pfile_fk=uploadtree.pfile_fk and uploadtree.upload_fk={$upload_pk}";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             $LicArray = array();
             $ItemLicArray = array();
             while ($acme_pfileRow = pg_fetch_assoc($result)) {
                 $LicArray = GetFileLicenses($agent_pk, '', $acme_pfileRow['uploadtree_pk'], $uploadtree_tablename);
                 foreach ($LicArray as $key => $license) {
                     $ItemLicArray[$key] = $license;
                 }
             }
             $project['licenses'] = '';
             foreach ($ItemLicArray as $license) {
                 if ($license == "No_license_found") {
                     continue;
                 }
                 if (!empty($project['licenses'])) {
                     $project['licenses'] .= ", ";
                 }
                 $project['licenses'] .= $license;
             }
         }
     }
     /* sort $acme_project_array by count desc */
     usort($acme_project_array, 'proj_cmp');
     /* generate and download spdx file */
     if (!empty($spdxbtn)) {
         $spdxfile = $this->GenerateSPDX($acme_project_array);
         $rv = DownloadString2File($spdxfile, "SPDX.rdf file", "xml");
         if ($rv !== true) {
             echo $rv;
         }
     }
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             $this->NoHeader = 0;
             $this->OutputOpen("HTML", 1);
             $V .= $this->HTMLForm($acme_project_array, $upload_pk);
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print $V;
     return;
 }
コード例 #6
0
 /**
  * \brief get an array with uploadtree record and agent_pk
  */
 function GetTreeInfo($Uploadtree_pk)
 {
     $TreeInfo = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$Uploadtree_pk}");
     $TreeInfo['agent_pk'] = LatestAgentpk($TreeInfo['upload_fk'], "nomos_ars");
     // Get the uploadtree table
     $UploadRec = GetSingleRec("upload", "where upload_pk={$TreeInfo['upload_fk']}");
     $TreeInfo['uploadtree_tablename'] = $UploadRec['uploadtree_tablename'];
     return $TreeInfo;
 }
コード例 #7
0
 /**
  * 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;
 }
コード例 #8
0
/**
 * \brief Check the ARS table to see if an agent has successfully scanned an upload.
 *
 * \param $upload_pk - the upload will be checked
 * \param $AgentName - Agent name, eg "nomos"
 * \param $AgentDesc - Agent description, eg "license scanner"
 * \param $AgentARSTableName - Agent ars table name, eg "nomos_ars"
 *
 * \returns:
 * - 0 = no
 * - 1 = yes, from latest agent version
 * - 2 = yes, from older agent version (does not apply to adj2nest)
 */
function CheckARS($upload_pk, $AgentName, $AgentDesc, $AgentARSTableName)
{
    /* get the latest agent_pk */
    $Latest_agent_pk = GetAgentKey($AgentName, $AgentDesc);
    /* get last agent pk with successful results */
    $Last_successful_agent_pk = LatestAgentpk($upload_pk, $AgentARSTableName);
    if (!empty($Latest_agent_pk) and !empty($Last_successful_agent_pk) and $Latest_agent_pk == $Last_successful_agent_pk) {
        return 1;
    }
    if (!empty($Latest_agent_pk) and !empty($Last_successful_agent_pk)) {
        return 2;
    }
    return 0;
}