예제 #1
0
 /**
  * \brief Display the loaded menu and plugins.
  */
 function Output()
 {
     global $PG_CONN;
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     if (!$PG_CONN) {
         return "NO DB connection";
     }
     $bucket_pk = GetParm("bucket_pk", PARM_RAW);
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     /* Get the uploadtree table name */
     $uploadtree_rec = GetSingleRec("uploadtree", "where uploadtree_pk='{$uploadtree_pk}'");
     $uploadtree_tablename = GetUploadtreeTableName($uploadtree_rec['upload_fk']);
     /* Get all the non-artifact children */
     $children = GetNonArtifactChildren($uploadtree_pk, $uploadtree_tablename);
     /* Loop through children and create a list of those that contain $bucket_pk */
     $outstr = $bucket_pk;
     foreach ($children as $child) {
         if (BucketInTree($bucket_pk, $child['uploadtree_pk'])) {
             $outstr .= ",{$child['uploadtree_pk']}";
         }
     }
     return $outstr;
 }
예제 #2
0
 function AgentHasResults($uploadId = 0)
 {
     $dbManager = $GLOBALS['container']->get('db.manager');
     $uploadtree_tablename = GetUploadtreeTableName($uploadId);
     if (NULL == $uploadtree_tablename) {
         strcpy($uploadtree_tablename, "uploadtree");
     }
     /* see if the latest nomos and bucket agents have scaned this upload for this bucketpool */
     $uploadtreeRec = $dbManager->getSingleRow("SELECT * FROM {$uploadtree_tablename} WHERE upload_fk=\$1 and lft is not null", array($uploadId), __METHOD__ . '.lftNotSet');
     if (empty($uploadtreeRec)) {
         return 0;
     }
     $stmt = __METHOD__ . $uploadtree_tablename;
     $sql = "SELECT parent,lft FROM {$uploadtree_tablename} WHERE upload_fk=\$1 ORDER BY parent, ufile_mode&(1<<29) DESC, ufile_name";
     $dbManager->prepare($stmt, $sql);
     $res = $dbManager->execute($stmt, array($uploadId));
     $prevRow = array('parent' => 0, 'lft' => 0);
     $wrongOrder = false;
     while ($row = $dbManager->fetchArray($res)) {
         $wrongOrder = $prevRow['parent'] == $row['parent'] && $prevRow['lft'] > $row['lft'];
         if ($wrongOrder) {
             break;
         }
         $prevRow = $row;
     }
     $dbManager->freeResult($res);
     return $wrongOrder ? 2 : 1;
 }
예제 #3
0
 /**
  * \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 initialization
  */
 protected function setUp()
 {
     global $PG_CONN;
     global $upload_pk;
     global $uploadtree_pk_parent;
     global $uploadtree_pk_child;
     global $pfile_pk_parent;
     global $pfile_pk_child;
     global $agent_pk;
     global $DB_COMMAND;
     global $DB_NAME;
     #$sysconfig = './sysconfigDirTest';
     $DB_COMMAND = "../../../testing/db/createTestDB.php";
     exec($DB_COMMAND, $dbout, $rc);
     preg_match("/(\\d+)/", $dbout[0], $matches);
     $test_name = $matches[1];
     $db_conf = $dbout[0];
     $DB_NAME = "fosstest" . $test_name;
     $PG_CONN = DBconnect($db_conf);
     /** preparation, add uploadtree, upload, pfile, license_file record */
     $upload_filename = "license_file_test";
     /* upload file name */
     /** add a pfile record */
     $sql = "INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES" . "('AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC', '2239AA7DAC291B6F8D0A56396B1B8530', '4560'), " . "('B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6', '55EFE7F9B9D106047718F1CE9173B869', '1892');";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     pg_free_result($result);
     /** add nomos agent record **/
     $sql = "INSERT INTO agent (agent_name) VALUES('nomos');";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     pg_free_result($result);
     /** if didn't have license_ref record, add it */
     $sql = "SELECT rf_shortname FROM license_ref where rf_pk = 1;";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     if (pg_num_rows($result) <= 0) {
         $sql = "INSERT INTO license_ref (rf_pk, rf_shortname, rf_text, marydone, rf_active, rf_text_updatable, rf_detector_type) VALUES(1, 'test_ref', 'test_ref', false, true, false, 1);";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
     }
     pg_free_result($result);
     /** get pfile id */
     $sql = "SELECT pfile_pk from pfile where pfile_sha1 IN ('AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC', 'B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6');";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result, 0);
     $pfile_pk_parent = $row['pfile_pk'];
     $row = pg_fetch_assoc($result, 1);
     $pfile_pk_child = $row['pfile_pk'];
     pg_free_result($result);
     /** add a license_file record */
     /** at first, get agent_id of 'nomos' */
     $sql = "SELECT agent_pk from agent where agent_name = 'nomos';";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $agent_pk = $row['agent_pk'];
     pg_free_result($result);
     /** secondly add license_file record */
     $sql = "INSERT INTO license_file(rf_fk, agent_fk, pfile_fk) VALUES(1, {$agent_pk}, {$pfile_pk_parent}), (2, {$agent_pk}, {$pfile_pk_child});";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     pg_free_result($result);
     /** add an upload record */
     $sql = "INSERT INTO upload (upload_filename,upload_mode,upload_ts, pfile_fk, uploadtree_tablename) VALUES ('{$upload_filename}',40,now(), '{$pfile_pk_parent}', '{$this->uploadtree_tablename}');";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     pg_free_result($result);
     /** get upload id */
     $sql = "SELECT upload_pk from upload where upload_filename = '{$upload_filename}';";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $upload_pk = $row['upload_pk'];
     pg_free_result($result);
     /** add parent uploadtree record */
     $sql = "INSERT INTO uploadtree (parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name) VALUES(NULL, {$upload_pk}, {$pfile_pk_parent}, 33188, 1, 2, 'license_test.file.parent');";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     pg_free_result($result);
     /** get uploadtree id */
     $sql = "SELECT uploadtree_pk from uploadtree where pfile_fk = {$pfile_pk_parent};";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $uploadtree_pk_parent = $row['uploadtree_pk'];
     pg_free_result($result);
     /** add child uploadtree record */
     $sql = "INSERT INTO uploadtree (parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name) VALUES({$uploadtree_pk_parent}, {$upload_pk}, {$pfile_pk_child}, 33188, 1, 2, 'license_test.file.child')";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     pg_free_result($result);
     /** get uploadtree id */
     $sql = "SELECT uploadtree_pk from uploadtree where pfile_fk = {$pfile_pk_child};";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $uploadtree_pk_child = $row['uploadtree_pk'];
     pg_free_result($result);
     $this->uploadtree_tablename = GetUploadtreeTableName($upload_pk);
 }
예제 #5
0
 /**
  * \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;
 }
/**
 * @brief get nomos license list of one specified uploadtree_id
 *
 * @param int $uploadtree_pk - uploadtree id
 * @param int $upload_pk - upload id
 * @param int $showContainer - include container or not, 1: yes, 0: no 
 * @param string $excluding
 * @param bool $ignore ignore files without license
 */
function GetLicenseList($uploadtree_pk, $upload_pk, $showContainer, $excluding, $ignore)
{
    /* @var $dbManager DbManager */
    $dbManager = $GLOBALS['container']->get('db.manager');
    if (empty($uploadtree_pk)) {
        $uploadtreeRec = $dbManager->getSingleRow('SELECT uploadtree_pk FROM uploadtree WHERE parent IS NULL AND upload_fk=$1', array($upload_pk), __METHOD__ . '.find.uploadtree.to.use.in.browse.link');
        $uploadtree_pk = $uploadtreeRec['uploadtree_pk'];
    }
    /* get last nomos agent_pk that has data for this upload */
    $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1);
    $agent_pk = $AgentRec[0]["agent_fk"];
    if ($AgentRec === false) {
        echo _("No data available \n");
        return;
    }
    $bottomItem = $dbManager->getSingleRow("SELECT upload_fk, ufile_name path, lft, rgt FROM uploadtree WHERE uploadtree_pk=\$1", array($uploadtree_pk), __METHOD__ . '.get.top.of.tree');
    $bottomItem['uploadtree_pk'] = $uploadtree_pk;
    $bottomItem['include'] = empty($excluding) || false === strpos("/{$bottomItem['path']}/", $excluding);
    $pathStack = array();
    $uploadtree_tablename = GetUploadtreeTableName($bottomItem['upload_fk']);
    $sql = "SELECT uploadtree_pk, ufile_name, lft, rgt, ufile_mode FROM {$uploadtree_tablename}\n              WHERE (lft BETWEEN \$1 AND \$2) AND (ufile_mode & (1<<28)) = 0";
    $params = array($bottomItem['lft'] + 1, $bottomItem['rgt']);
    $stmt = __METHOD__ . '.loop.through';
    if ($uploadtree_tablename == 'uploadtree_a') {
        $sql .= ' AND upload_fk=$3';
        $params[] = $bottomItem['upload_fk'];
        $stmt .= '.ut_a';
    }
    $sql .= ' ORDER BY lft';
    $dbManager->prepare($stmt, $sql);
    $res = $dbManager->execute($stmt, $params);
    while ($item = $dbManager->fetchArray($res)) {
        while ($bottomItem['rgt'] <= $item['lft']) {
            $bottomItem = array_pop($pathStack);
        }
        if (!$bottomItem['include']) {
            continue;
        }
        $item['path'] = "{$bottomItem['path']}/{$item['ufile_name']}";
        if (($item['ufile_mode'] & 1 << 29) == 0) {
            $license_name = GetFileLicenses_string($agent_pk, 0, $item['uploadtree_pk'], $uploadtree_tablename);
            if (!$ignore || !empty($license_name) && 'No_license_found' != $license_name) {
                print "{$item['path']}: {$license_name}\n";
            }
            continue;
        }
        $item['include'] = $bottomItem['include'] && (empty($excluding) || false === strpos("/{$item['ufile_name']}/", $excluding));
        if ($item['include'] && $showContainer) {
            print "{$item['path']}\n";
        }
        array_push($pathStack, $bottomItem);
        $bottomItem = $item;
    }
    $dbManager->freeResult($res);
}
예제 #7
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;
 }
예제 #8
0
 /**
  * \brief This function returns the scheduler status.
  */
 function Output()
 {
     global $PG_CONN;
     global $SysConf;
     $V = "";
     $formVars = array();
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     if (empty($uploadtree_pk)) {
         return;
     }
     $upload_pk = GetParm("upload", PARM_INTEGER);
     if (empty($upload_pk)) {
         return;
     }
     if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
         $text = _("Permission Denied");
         return "<h2>{$text}</h2>";
     }
     $uploadtreeTablename = GetUploadtreeTableName($upload_pk);
     $warnings = array();
     $agent_pks_dict = $this->getAgentPksFromRequest($upload_pk);
     $agent_pks = array();
     foreach ($agent_pks_dict as $agent_name => $agent_pk) {
         if ($agent_pk === false) {
             $warnings[] = _("No information for agent: {$agent_name}");
         } else {
             $agent_pks[] = $agent_pk;
             $formVars["agentToInclude_" . $agent_name] = "1";
         }
     }
     $dltext = GetParm("output", PARM_STRING) == 'dltext';
     $formVars["dltext"] = $dltext;
     $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
     $formVars["NomostListNum"] = $NomostListNum;
     $includeSubfolder = GetParm("doNotIncludeSubfolder", PARM_STRING) !== "yes";
     $formVars["includeSubfolder"] = $includeSubfolder;
     $ignore = GetParm("showContainers", PARM_STRING) !== "yes";
     $formVars["showContainers"] = !$ignore;
     $exclude = GetParm("exclude", PARM_STRING);
     $formVars["exclude"] = $exclude;
     $V .= $this->renderString("ui-license-list-form.html.twig", $formVars);
     $V .= "<hr/>";
     $lines = $this->createListOfLines($uploadtreeTablename, $uploadtree_pk, $agent_pks, $NomostListNum, $includeSubfolder, $exclude, $ignore);
     if (array_key_exists("warn", $lines)) {
         $warnings[] = $lines["warn"];
         unset($lines["warn"]);
     }
     foreach ($warnings as $warning) {
         $V .= "<br><b>{$warning}</b><br>";
     }
     if ($dltext) {
         $request = $this->getRequest();
         $itemId = intval($request->get('item'));
         $path = Dir2Path($itemId, $uploadtreeTablename);
         $fileName = $path[count($path) - 1]['ufile_name'] . ".txt";
         $headers = array("Content-Type" => "text", "Content-Disposition" => "attachment; filename=\"{$fileName}\"");
         $response = new Response(implode("\n", $lines), Response::HTTP_OK, $headers);
         return $response;
     } else {
         return $V . '<pre>' . implode("\n", $lines) . '</pre>';
     }
 }
예제 #9
0
 /**
  * \brief get the entire <td> ... </td> for $Child file listing table
  * License differences are highlighted.
  */
 function ChildElt($Child, $agent_pk, $OtherChild)
 {
     $UniqueTagArray = array();
     $licstr = $Child['licstr'];
     /* If both $Child and $OtherChild are specified,
      * reassemble licstr and highlight the differences
      */
     if ($OtherChild and $OtherChild) {
         $licstr = "";
         $DiffLicStyle = "style='background-color:#ffa8a8'";
         // mid red pastel
         foreach ($Child['licarray'] as $rf_pk => $rf_shortname) {
             if (!empty($licstr)) {
                 $licstr .= ", ";
             }
             if (@$OtherChild['licarray'][$rf_pk]) {
                 /* license is in both $Child and $OtherChild */
                 $licstr .= $rf_shortname;
             } else {
                 /* license is missing from $OtherChild */
                 $licstr .= "<span {$DiffLicStyle}>{$rf_shortname}</span>";
             }
         }
     }
     $ColStr = "<td id='{$Child['uploadtree_pk']}' align='left'>";
     $ColStr .= "{$Child['linkurl']}";
     /* show licenses under file name */
     $ColStr .= "<br>";
     $ColStr .= "<span style='position:relative;left:1em'>";
     $ColStr .= $licstr;
     $ColStr .= "</span>";
     $ColStr .= "</td>";
     /* display item links */
     $ColStr .= "<td valign='top'>";
     $uploadtree_tablename = GetUploadtreeTableName($Child['upload_fk']);
     $ColStr .= FileListLinks($Child['upload_fk'], $Child['uploadtree_pk'], $agent_pk, $Child['pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
     $ColStr .= "</td>";
     return $ColStr;
 }
예제 #10
0
 /** 
  * \brief display license audit trail on the pop up window
  *
  * \param $LicenseFileId - file license ID (fl_pk in table license_file)
  * \param $Upload - upload id
  * \param $Item - uploadtree id
  *
  * \return audit trail html
  */
 function ViewLicenseAuditTrail($LicenseFileId, $Upload, $Item)
 {
     global $PG_CONN;
     $FileName = "";
     /** get file name */
     $uploadtree_tablename = GetUploadtreeTableName($Upload);
     $sql = "SELECT ufile_name from {$uploadtree_tablename} where uploadtree_pk = {$Item};";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $FileName = $row['ufile_name'];
     pg_free_result($result);
     /** query license_file_audit, license_file_audit record the origial license */
     $sql = "SELECT rf_fk, user_fk, date, reason from license_file_audit where fl_fk = {$LicenseFileId} order by date DESC;";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $org_lic = "";
     $obj_lic = "";
     $user = "";
     $V = "";
     $text = _("Change History");
     $V .= "<H2>{$text}</H2>\n";
     $V .= "<table border='1'>\n";
     $text = _("License");
     $text1 = _("Changed To");
     $text2 = _("Reason");
     $text3 = _("By");
     $text4 = _("Date");
     $V .= "<tr><th>{$text}</th><th>{$text1}</th><th>{$text4}</th><th>{$text3}</th><th>{$text2}</th></tr>\n";
     $changed_times = pg_num_rows($result);
     /** get latest license, rf_shortname in license_file alway is latest license  */
     $sql = "SELECT rf_shortname from license_file_ref where fl_pk = {$LicenseFileId};";
     $result1 = pg_query($PG_CONN, $sql);
     DBCheckResult($result1, $sql, __FILE__, __LINE__);
     $row1 = pg_fetch_assoc($result1);
     $obj_lic = $row1['rf_shortname'];
     // get the lastest license from license_file_ref
     pg_free_result($result1);
     $date = "";
     while ($row = pg_fetch_assoc($result)) {
         $user_id = $row['user_fk'];
         $sql = "select user_name from users where user_pk = {$user_id};";
         $result1 = pg_query($PG_CONN, $sql);
         DBCheckResult($result1, $sql, __FILE__, __LINE__);
         $row1 = pg_fetch_assoc($result1);
         $user = $row1['user_name'];
         pg_free_result($result1);
         $sql = "SELECT rf_shortname from license_ref where rf_pk = {$row['rf_fk']};";
         $result1 = pg_query($PG_CONN, $sql);
         DBCheckResult($result1, $sql, __FILE__, __LINE__);
         $row1 = pg_fetch_assoc($result1);
         $org_lic = $row1['rf_shortname'];
         pg_free_result($result1);
         $date = substr($row['date'], 0, 16);
         $reason = htmlspecialchars($row['reason']);
         $V .= "<tr>";
         $V .= "<td>{$org_lic}</td>";
         $V .= "<td>{$obj_lic}</td>";
         $V .= "<td>{$date}</td>";
         $V .= "<td>{$user}</td>";
         $V .= "<td>{$reason}</td>";
         $V .= "</tr>";
         $obj_lic = $row1['rf_shortname'];
     }
     pg_free_result($result);
     $V .= "</table><br>\n";
     return $V;
 }
예제 #11
0
 /**
  * \brief This function returns the output html
  */
 function Output()
 {
     global $PG_CONN;
     global $Plugins;
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $folder_pk = GetParm("folder", PARM_INTEGER);
     $Upload = GetParm("upload", PARM_INTEGER);
     // upload_pk to browse
     $Item = GetParm("item", PARM_INTEGER);
     // uploadtree_pk to browse
     /* check permission if $Upload is given */
     if (!empty($Upload)) {
         $UploadPerm = GetUploadPerm($Upload);
         if ($UploadPerm < PERM_READ) {
             $text = _("Permission Denied");
             echo "<h2>{$text}<h2>";
             return;
         }
     }
     /* kludge for plugins not supplying a folder parameter.
      * Find what folder this upload is in.  Error if in multiple folders.
      */
     if (empty($folder_pk)) {
         if (empty($Upload)) {
             $folder_pk = GetUserRootFolder();
         } else {
             /* Make sure the upload record exists */
             $sql = "select upload_pk from upload where upload_pk={$Upload}";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             if (pg_num_rows($result) < 1) {
                 echo "This upload no longer exists on this system.";
                 return;
             }
             $sql = "select parent_fk from foldercontents where child_id={$Upload} and foldercontents_mode=2";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             if (pg_num_rows($result) > 1) {
                 Fatal("Upload {$Upload} found in multiple folders.", __FILE__, __LINE__);
             }
             if (pg_num_rows($result) < 1) {
                 Fatal("Upload {$Upload} missing from foldercontents.", __FILE__, __LINE__);
             }
             $row = pg_fetch_assoc($result);
             $folder_pk = $row['parent_fk'];
             pg_free_result($result);
         }
     }
     $Folder = $folder_pk;
     $Show = 'detail';
     // always use detail
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             /************************/
             /* Show the folder path */
             /************************/
             $uploadtree_tablename = "";
             if (!empty($Item)) {
                 /* Make sure the item is not a file */
                 $sql = "SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = '{$Item}';";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 $row = pg_fetch_assoc($result);
                 pg_free_result($result);
                 $Upload = $row['upload_fk'];
                 $UploadPerm = GetUploadPerm($Upload);
                 if ($UploadPerm < PERM_READ) {
                     $text = _("Permission Denied");
                     echo "<h2>{$text}<h2>";
                     return;
                 }
                 if (!Iscontainer($row['ufile_mode'])) {
                     /* Not a container! */
                     $View =& $Plugins[plugin_find_id("view")];
                     if (!empty($View)) {
                         return $View->ShowView(NULL, "browse");
                     }
                 }
                 $V .= "<font class='text'>\n";
                 $uploadtree_tablename = GetUploadtreeTableName($row['upload_fk']);
                 $V .= Dir2Browse($this->Name, $Item, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename) . "\n";
             } else {
                 if (!empty($Upload)) {
                     $V .= "<font class='text'>\n";
                     $uploadtree_tablename = GetUploadtreeTableName($Upload);
                     $V .= Dir2BrowseUpload($this->Name, $Upload, NULL, 1, "Browse", $uploadtree_tablename) . "\n";
                 } else {
                     $V .= "<font class='text'>\n";
                 }
             }
             /******************************/
             /* Get the folder description */
             /******************************/
             if (!empty($Upload)) {
                 if (empty($Item)) {
                     $sql = "select uploadtree_pk from uploadtree\n                where parent is NULL and upload_fk={$Upload} ";
                     $result = pg_query($PG_CONN, $sql);
                     DBCheckResult($result, $sql, __FILE__, __LINE__);
                     if (pg_num_rows($result)) {
                         $row = pg_fetch_assoc($result);
                         $Item = $row['uploadtree_pk'];
                     } else {
                         $text = _("Missing upload tree parent for upload");
                         $V .= "<hr><h2>{$text} {$Upload}</h2><hr>";
                         break;
                     }
                     pg_free_result($result);
                 }
                 $V .= $this->ShowItem($Upload, $Item, $Show, $Folder, $uploadtree_tablename);
             } else {
                 $V .= $this->ShowFolder($Folder, $Show);
             }
             $V .= "</font>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
예제 #12
0
/**
 * \brief get bucket list of one specified upload or all uploads
 *
 * \pamam $upload_pk - upload id
 * \param $bucket_pk - bucket id
 */
function GetBucketList($bucket_pk, $upload_pk = 0)
{
    global $PG_CONN;
    $sql = "SELECT bucket_name from  bucket_def where bucket_pk = {$bucket_pk};";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $row = pg_fetch_assoc($result);
    pg_free_result($result);
    if ($upload_pk) {
        $text = "upload {$upload_pk}";
    } else {
        $text = "all uploads";
    }
    print "Get all files have bucket {$row['bucket_name']} for {$text} \n";
    $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
    $sql_upload = '';
    if ($upload_pk) {
        $sql_upload = "and upload_fk = {$upload_pk}";
    }
    $sql = "SELECT DISTINCT uploadtree_pk from pfile, bucket_file, uploadtree where pfile_pk = bucket_file.pfile_fk and pfile_pk = uploadtree.pfile_fk and bucket_fk = {$bucket_pk} and ((ufile_mode & (1<<28)) = 0) and ((ufile_mode & (1<<29)) = 0) {$sql_upload} order by uploadtree_pk;";
    $outerresult = pg_query($PG_CONN, $sql);
    DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
    /* Select each uploadtree row in this tree, write out text:
     * filepath : bucket list
     */
    while ($row = pg_fetch_assoc($outerresult)) {
        $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
        $filepath = "";
        foreach ($filepatharray as $uploadtreeRow) {
            if (!empty($filepath)) {
                $filepath .= "/";
            }
            $filepath .= $uploadtreeRow['ufile_name'];
        }
        $V = $filepath;
        print "{$V}";
        print "\n";
    }
    pg_free_result($outerresult);
}
 /**
  * \brief This function returns the scheduler status.
  */
 function Output()
 {
     global $SysConf;
     global $PG_CONN;
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     if (empty($uploadtree_pk)) {
         return;
     }
     $upload_pk = GetParm("upload", PARM_INTEGER);
     if (empty($upload_pk)) {
         return;
     }
     $UploadPerm = GetUploadPerm($upload_pk);
     if ($UploadPerm < PERM_READ) {
         $text = _("Permission Denied");
         echo "<h2>{$text}<h2>";
         return;
     }
     if (GetParm("output", PARM_STRING) == 'dltext') {
         $dltext = true;
     } else {
         $dltext = false;
     }
     /* get last nomos agent_pk that has data for this upload */
     $Agent_name = "nomos";
     $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1);
     $agent_pk = $AgentRec[0]["agent_fk"];
     if ($AgentRec === false) {
         echo _("No data available");
         return;
     }
     /* how many lines of data do you want to display */
     $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
     /* get the top of tree */
     $sql = "SELECT upload_fk, lft, rgt from uploadtree where uploadtree_pk='{$uploadtree_pk}'";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $toprow = pg_fetch_assoc($result);
     pg_free_result($result);
     /* loop through all the records in this tree */
     $sql = "select uploadtree_pk, ufile_name, lft, rgt from uploadtree\n              where upload_fk='{$toprow['upload_fk']}' \n                    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n                    and ((ufile_mode & (1<<28)) = 0) and ((ufile_mode & (1<<29)) = 0) limit {$NomostListNum}";
     $outerresult = pg_query($PG_CONN, $sql);
     DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
     /* Select each uploadtree row in this tree, write out text:
      * filepath : license list
      * e.g. Pound-2.4.tgz/Pound-2.4/svc.c: GPL_v3+, Indemnity
      */
     $uploadtree_tablename = GetUploadtreeTableName($toprow['upload_fk']);
     while ($row = pg_fetch_assoc($outerresult)) {
         $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
         $filepath = "";
         foreach ($filepatharray as $uploadtreeRow) {
             if (!empty($filepath)) {
                 $filepath .= "/";
             }
             $filepath .= $uploadtreeRow['ufile_name'];
         }
         $V .= $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtree_tablename);
         if ($dltext) {
             $V .= "\n";
         } else {
             $V .= "<br>";
         }
     }
     $RealNumber = pg_num_rows($outerresult);
     pg_free_result($outerresult);
     if ($RealNumber == $NomostListNum) {
         $V .= _("<br><B>Warning: Only the last {$NomostListNum} lines are displayed.  To see the whole list, run fo_nomos_license_list from the command line.</B><br>");
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
 /**
  * \brief Display all the files for a bucket in this subtree.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     global $Plugins;
     global $PG_CONN;
     /*  Input parameters */
     $bucketagent_pk = GetParm("bapk", PARM_INTEGER);
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     $bucket_pk = GetParm("bpk", PARM_INTEGER);
     $bucketpool_pk = GetParm("bp", PARM_INTEGER);
     $nomosagent_pk = GetParm("napk", PARM_INTEGER);
     $BinNoSrc = GetParm("bns", PARM_INTEGER);
     // 1 if requesting binary with no src
     $Excl = GetParm("excl", PARM_RAW);
     if (empty($uploadtree_pk) || empty($bucket_pk) || empty($bucketpool_pk)) {
         $text = _("is missing required parameters.");
         echo $this->Name . " {$text}";
         return;
     }
     /* Check upload permission */
     $Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}");
     $UploadPerm = GetUploadPerm($Row['upload_fk']);
     if ($UploadPerm < PERM_READ) {
         $text = _("Permission Denied");
         echo "<h2>{$text} item 1<h2>";
         return;
     }
     $Page = GetParm("page", PARM_INTEGER);
     if (empty($Page)) {
         $Page = 0;
     }
     $V = "";
     $Time = time();
     $Max = 200;
     // Create cache of bucket_pk => bucket_name
     // Since we are going to do a lot of lookups
     $sql = "select bucket_pk, bucket_name from bucket_def where bucketpool_fk={$bucketpool_pk}";
     $result_name = pg_query($PG_CONN, $sql);
     DBCheckResult($result_name, $sql, __FILE__, __LINE__);
     $bucketNameCache = array();
     while ($name_row = pg_fetch_assoc($result_name)) {
         $bucketNameCache[$name_row['bucket_pk']] = $name_row['bucket_name'];
     }
     pg_free_result($result_name);
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             // micro menus
             $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0);
             /* Get all the files under this uploadtree_pk with this bucket */
             $V .= _("The following files are in bucket: '<b>");
             $V .= $bucketNameCache[$bucket_pk];
             $V .= "</b>'.\n";
             $text = _("Display");
             $text1 = _("excludes");
             $text2 = _("files with these licenses");
             if (!empty($Excl)) {
                 $V .= "<br>{$text} <b>{$text1}</b> {$text2}: {$Excl}";
             }
             $Offset = $Page <= 0 ? 0 : $Page * $Max;
             $PkgsOnly = false;
             // Get bounds of subtree (lft, rgt) for this uploadtree_pk
             $sql = "SELECT lft,rgt,upload_fk FROM uploadtree\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);
             /* Get uploadtree table */
             $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
             /* If $BinNoSrc, then only list binary packages in this subtree
              * that do not have Source packages.
              * Else list files in the asked for bucket.
              */
             if ($BinNoSrc) {
             } else {
                 $Offset = $Page < 0 ? 0 : $Page * $Max;
                 $limit = $Page < 0 ? "ALL" : $Max;
                 // Get all the uploadtree_pk's with this bucket (for this agent and bucketpool)
                 // in this subtree.
                 // It would be best to sort by pfile_pk, so that the duplicate pfiles are
                 // correctly indented, but pfile_pk has no meaning to the user.  So a compromise,
                 // sorting by ufile_name is used.
                 $sql = "select uploadtree.*, bucket_file.nomosagent_fk as nomosagent_fk\n               from uploadtree, bucket_file, bucket_def\n               where upload_fk={$upload_pk} and uploadtree.lft between {$lft} and {$rgt}\n                 and ((ufile_mode & (1<<28)) = 0)\n                 and ((ufile_mode & (1<<29))=0)\n                 and uploadtree.pfile_fk=bucket_file.pfile_fk\n                 and agent_fk={$bucketagent_pk}\n                 and bucket_fk={$bucket_pk}\n                 and bucketpool_fk={$bucketpool_pk}\n                 and bucket_pk=bucket_fk \n                 order by uploadtree.ufile_name\n                 limit {$limit} offset {$Offset}";
                 $fileresult = pg_query($PG_CONN, $sql);
                 DBCheckResult($fileresult, $sql, __FILE__, __LINE__);
                 $Count = pg_num_rows($fileresult);
             }
             $file_result_temp = pg_fetch_all($fileresult);
             $sourted_file_result = array();
             // the final file list will display
             $max_num = $Count;
             /** sorting by ufile_name from DB, then reorder the duplicates indented */
             for ($i = 0; $i < $max_num; $i++) {
                 $row = $file_result_temp[$i];
                 if (empty($row)) {
                     continue;
                 }
                 array_push($sourted_file_result, $row);
                 for ($j = $i + 1; $j < $max_num; $j++) {
                     $row_next = $file_result_temp[$j];
                     if (!empty($row_next) && $row['pfile_fk'] == $row_next['pfile_fk']) {
                         array_push($sourted_file_result, $row_next);
                         $file_result_temp[$j] = null;
                     }
                 }
             }
             if ($Count < 1.25 * $Max) {
                 $Max = $Count;
             }
             if ($Max < 1) {
                 $Max = 1;
             }
             // prevent div by zero in corner case of no files
             /* Get the page menu */
             if ($Count >= $Max && $Page >= 0) {
                 $VM = "<P />\n" . MenuEndlessPage($Page, intval(($Count + $Offset) / $Max)) . "<P />\n";
                 $V .= $VM;
             } else {
                 $VM = "";
             }
             // base url
             $baseURL = "?mod=" . $this->Name . "&bapk={$bucketagent_pk}&item={$uploadtree_pk}&bpk={$bucket_pk}&bp={$bucketpool_pk}&napk={$nomosagent_pk}&page=-1";
             // for each uploadtree rec ($fileresult), find all the licenses in it and it's children
             $ShowBox = 1;
             $ShowMicro = NULL;
             $RowNum = $Offset;
             $Header = "";
             $LinkLast = "list_bucket_files&bapk={$bucketagent_pk}";
             /* file display loop/table */
             $V .= "<table>";
             $text = _("File");
             $V .= "<tr><th>{$text}</th><th>&nbsp";
             $ExclArray = explode(":", $Excl);
             $ItemNumb = 0;
             $PrevPfile_pk = 0;
             if ($Count > 0) {
                 foreach ($sourted_file_result as $row) {
                     // get all the licenses in this subtree (bucket uploadtree_pk)
                     $pfile_pk = $row['pfile_fk'];
                     $licstring = GetFileLicenses_string($nomosagent_pk, $row['pfile_fk'], $row['uploadtree_pk'], $uploadtree_tablename);
                     if (empty($licstring)) {
                         $licstring = '-';
                     }
                     $URLlicstring = urlencode($licstring);
                     /* Allow user to exclude files with this exact license list */
                     if (!empty($Excl)) {
                         $URL = $baseURL . "&excl=" . urlencode($Excl) . ":" . $URLlicstring;
                     } else {
                         $URL = $baseURL . "&excl={$URLlicstring}";
                     }
                     $text = _("Exclude files with license");
                     $Header = "<a href={$URL}>{$text}: {$licstring}.</a>";
                     $ok = true;
                     if ($Excl) {
                         if (in_array($licstring, $ExclArray)) {
                             $ok = false;
                         }
                     }
                     if ($ok) {
                         $nomosagent_pk = $row['nomosagent_fk'];
                         $LinkLast = "view-license&bapk={$bucketagent_pk}&napk={$nomosagent_pk}";
                         $V .= "<tr><td>";
                         if ($PrevPfile_pk == $pfile_pk) {
                             $V .= "<div style='margin-left:2em;'>";
                         } else {
                             $V .= "<div>";
                         }
                         $V .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLast, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename);
                         $V .= "</div>";
                         $V .= "</td>";
                         $V .= "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                         // spaces to seperate licenses
                         // show the entire license list as a single string with links to the files
                         // in this container with that license.
                         $V .= "<td>{$licstring}</td></tr>";
                         $V .= "<tr><td colspan=3><hr></td></tr>";
                         // separate files
                     }
                     $PrevPfile_pk = $pfile_pk;
                 }
             }
             pg_free_result($fileresult);
             $V .= "</table>";
             if (!empty($VM)) {
                 $V .= $VM . "\n";
             }
             $V .= "<hr>\n";
             $Time = time() - $Time;
             $text = _("Elapsed time");
             $text1 = _("seconds");
             $V .= "<small>{$text}: {$Time} {$text1}</small>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print $V;
     return;
 }
예제 #15
0
/**
 * @brief get monk license list of one specified uploadtree_id
 *
 * @param int $uploadtree_pk - uploadtree id
 * @param int $upload_pk - upload id
 * @param int $showContainer - include container or not, 1: yes, 0: no 
 * @param string $excluding
 * @param bool $ignore ignore files without license
 */
function GetLicenseList($uploadtree_pk, $upload_pk, $showContainer, $excluding, $ignore)
{
    /* @var $dbManager DbManager */
    $dbManager = $GLOBALS['container']->get('db.manager');
    /* @var $uploadDao UploadDao */
    $uploadDao = $GLOBALS['container']->get("dao.upload");
    /* @var $licenseDao LicenseDao */
    $licenseDao = $GLOBALS['container']->get("dao.license");
    if (empty($uploadtree_pk)) {
        $uploadtreeRec = $dbManager->getSingleRow('SELECT uploadtree_pk FROM uploadtree WHERE parent IS NULL AND upload_fk=$1', array($upload_pk), __METHOD__ . '.find.uploadtree.to.use.in.browse.link');
        $uploadtree_pk = $uploadtreeRec['uploadtree_pk'];
    }
    /* get last monk agent_pk that has data for this upload */
    $AgentRec = AgentARSList("monk_ars", $upload_pk, 1);
    if ($AgentRec === false) {
        echo _("No data available \n");
        return;
    }
    $agent_pk = $AgentRec[0]["agent_fk"];
    $uploadtreeTablename = GetUploadtreeTableName($upload_pk);
    /** @var ItemTreeBounds */
    $itemTreeBounds = $uploadDao->getItemTreeBounds($uploadtree_pk, $uploadtreeTablename);
    $licensesPerFileName = $licenseDao->getLicensesPerFileNameForAgentId($itemTreeBounds, array($agent_pk), true, array(), $excluding, $ignore);
    foreach ($licensesPerFileName as $fileName => $licenseNames) {
        if (!$ignore || $licenseNames !== false && $licenseNames !== array()) {
            if ($licenseNames !== false) {
                print $fileName . ': ' . implode($licenseNames, ', ') . "\n";
            } else {
                if ($showContainer) {
                    print $filename . "\n";
                }
            }
        }
    }
}
 /**
  * \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;
 }
예제 #17
0
 /**
  * \brief Display the loaded menu and plugins.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     global $Plugins;
     global $PG_CONN;
     // make sure there is a db connection
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     $OutBuf = "";
     $Time = microtime(true);
     $Max = 50;
     /*  Input parameters */
     $agent_pk = GetParm("agent", PARM_INTEGER);
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     $hash = GetParm("hash", PARM_RAW);
     $type = GetParm("type", PARM_RAW);
     $excl = GetParm("excl", PARM_RAW);
     $filter = GetParm("filter", PARM_RAW);
     if (empty($uploadtree_pk) || empty($hash) || empty($type) || empty($agent_pk)) {
         $text = _("is missing required parameters");
         echo $this->Name . " {$text}.";
         return;
     }
     /* Check item1 and item2 upload permissions */
     $Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}");
     $UploadPerm = GetUploadPerm($Row['upload_fk']);
     if ($UploadPerm < PERM_READ) {
         $text = _("Permission Denied");
         echo "<h2>{$text}<h2>";
         return;
     }
     $Page = GetParm("page", PARM_INTEGER);
     if (empty($Page)) {
         $Page = 0;
     }
     /* get all rows */
     $rows = $this->GetRows($uploadtree_pk, $agent_pk, $upload_pk);
     /* Get uploadtree_tablename */
     $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
     /* slim down to all rows with this hash and type,  and filter */
     $NumInstances = 0;
     $rows = $this->GetRequestedRows($rows, $hash, $type, $excl, $NumInstances, $filter);
     //debugprint($rows, "rows");
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             // micro menus
             $OutBuf .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0);
             $RowCount = count($rows);
             if ($RowCount) {
                 $Content = htmlentities($rows[0]['content']);
                 $Offset = $Page < 0 ? 0 : $Page * $Max;
                 $PkgsOnly = false;
                 $text = _("files");
                 $text1 = _("unique");
                 $text3 = _("copyright");
                 $text4 = _("email");
                 $text5 = _("url");
                 switch ($type) {
                     case "statement":
                         $TypeStr = "{$text3}";
                         break;
                     case "email":
                         $TypeStr = "{$text4}";
                         break;
                     case "url":
                         $TypeStr = "{$text5}";
                         break;
                 }
                 $OutBuf .= "{$NumInstances} {$TypeStr} instances found in {$RowCount}  {$text}";
                 $OutBuf .= ": <b>{$Content}</b>";
                 $text = _("Display excludes files with these extensions");
                 if (!empty($excl)) {
                     $OutBuf .= "<br>{$text}: {$excl}";
                 }
                 /* Get the page menu */
                 if ($RowCount >= $Max && $Page >= 0) {
                     $PagingMenu = "<P />\n" . MenuEndlessPage($Page, intval(($RowCount + $Offset) / $Max)) . "<P />\n";
                     $OutBuf .= $PagingMenu;
                 } else {
                     $PagingMenu = "";
                 }
                 /* Offset is +1 to start numbering from 1 instead of zero */
                 $RowNum = $Offset;
                 $LinkLast = "copyrightview&agent={$agent_pk}";
                 $ShowBox = 1;
                 $ShowMicro = NULL;
                 // base url
                 $ucontent = rawurlencode($Content);
                 $baseURL = "?mod=" . $this->Name . "&agent={$agent_pk}&item={$uploadtree_pk}&hash={$hash}&type={$type}&page=-1";
                 // display rows
                 foreach ($rows as $row) {
                     // Allow user to exclude files with this extension
                     $FileExt = GetFileExt($row['ufile_name']);
                     if (empty($excl)) {
                         $URL = $baseURL . "&excl={$FileExt}";
                     } else {
                         $URL = $baseURL . "&excl={$excl}:{$FileExt}";
                     }
                     $text = _("Exclude this file type");
                     $Header = "<a href={$URL}>{$text}.</a>";
                     $ok = true;
                     if ($excl) {
                         $ExclArray = explode(":", $excl);
                         if (in_array($FileExt, $ExclArray)) {
                             $ok = false;
                         }
                     }
                     if ($ok) {
                         $OutBuf .= Dir2Browse("browse", $row['uploadtree_pk'], $LinkLast, $ShowBox, $ShowMicro, ++$RowNum, $Header, '', $uploadtree_tablename);
                     }
                 }
             } else {
                 $OutBuf .= _("No files found");
             }
             if (!empty($PagingMenu)) {
                 $OutBuf .= $PagingMenu . "\n";
             }
             $OutBuf .= "<hr>\n";
             $Time = microtime(true) - $Time;
             $text = _("Elapsed time");
             $text1 = _("seconds");
             $OutBuf .= sprintf("<small>{$text}: %.2f {$text1}</small>\n", $Time);
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $OutBuf;
     }
     print $OutBuf;
     return;
 }
예제 #18
0
 /**
  * @brief Return the entire <td> ... </td> for $Child file listing table
  *        differences are highlighted.
  * @param $Child
  * @param $agent_pk
  * @param $OtherChild
  * @param $BucketDefArray
  *
  * @return the entire html <td> ... </td> for $Child file listing table
  * differences are highlighted.
  */
 function ChildElt($Child, $agent_pk, $OtherChild, $BucketDefArray)
 {
     $UniqueTagArray = array();
     $bucketstr = $Child['bucketstr'];
     /* If both $Child and $OtherChild are specified,
      * reassemble bucketstr and highlight the differences 
      */
     if ($OtherChild and $OtherChild) {
         $bucketstr = "";
         foreach ($Child['bucketarray'] as $bucket_pk) {
             $bucket_color = $BucketDefArray[$bucket_pk]['bucket_color'];
             $BucketStyle = "style='color:#606060;background-color:{$bucket_color}'";
             $DiffStyle = "style='background-color:{$bucket_color};text-decoration:underline;text-transform:uppercase;border-style:outset'";
             $bucket_name = $BucketDefArray[$bucket_pk]['bucket_name'];
             if (!empty($bucketstr)) {
                 $bucketstr .= ", ";
             }
             if (in_array($bucket_pk, $OtherChild['bucketarray'])) {
                 /* license is in both $Child and $OtherChild */
                 $Style = $BucketStyle;
             } else {
                 /* license is missing from $OtherChild */
                 $Style = $DiffStyle;
             }
             $bucketstr .= "<span {$Style}>{$bucket_name}</span>";
         }
     }
     $ColStr = "<td id='{$Child['uploadtree_pk']}' align='left'>";
     $ColStr .= "{$Child['linkurl']}";
     /* show buckets under file name */
     $ColStr .= "<br>";
     $ColStr .= "<span style='position:relative;left:1em'>";
     $ColStr .= $bucketstr;
     $ColStr .= "</span>";
     $ColStr .= "</td>";
     /* display file links if this is a real file */
     $ColStr .= "<td valign='top'>";
     $uploadtree_tablename = GetUploadtreeTableName($Child['upload_fk']);
     $ColStr .= FileListLinks($Child['upload_fk'], $Child['uploadtree_pk'], $agent_pk, $Child['pfile_fk'], True, $UniqueTagArray, $uploadtree_tablename);
     $ColStr .= "</td>";
     return $ColStr;
 }
예제 #19
0
/**
 * \brief get bucket list of one specified upload or all uploads
 *
 * \pamam $upload_pk - upload id
 * \param $bucket_pk - bucket id
 * \param $bucket_agent - bucket agent ID
 * \param $nomos_agent - nomos agent ID
 * \prram $uploadtree_pk - uploadtree ID
 */
function GetBucketList($bucket_pk, $bucket_agent, $nomos_agent, $uploadtree_pk, $upload_pk = 0)
{
    global $PG_CONN;
    global $excluding;
    /** get bucket name */
    $sql = "SELECT bucket_name from bucket_def where bucket_pk = {$bucket_pk};";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $row = pg_fetch_assoc($result);
    pg_free_result($result);
    $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
    /* get the top of tree */
    $sql = "SELECT upload_fk, lft, rgt, uploadtree_pk  from {$uploadtree_tablename}";
    if ($uploadtree_pk) {
        // if uploadtree_pk is null, that means get all data on an upload
        $sql .= " where uploadtree_pk='{$uploadtree_pk}';";
    } else {
        $sql .= " where upload_fk='{$upload_pk}' and parent is null;";
    }
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $toprow = pg_fetch_assoc($result);
    $uploadtree_pk = $toprow['uploadtree_pk'];
    pg_free_result($result);
    if (empty($toprow)) {
        print "Sorry, Can not find upload {$upload_pk}.\n";
        return 1;
    }
    print "For uploadtree {$uploadtree_pk} under upload {$upload_pk} has bucket {$row['bucket_name']}:\n";
    /* loop through all the records in this tree */
    $sql = "select uploadtree_pk, ufile_name, lft, rgt from {$uploadtree_tablename}, bucket_file\n    where upload_fk={$upload_pk}\n    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n    and ((ufile_mode & (1<<28)) = 0)  and ((ufile_mode & (1<<29)) = 0) and bucket_file.pfile_fk = {$uploadtree_tablename}.pfile_fk\n    and bucket_fk = '{$bucket_pk}' and agent_fk = '{$bucket_agent}' and nomosagent_fk = '{$nomos_agent}'\n    order by uploadtree_pk";
    $outerresult = pg_query($PG_CONN, $sql);
    /* Select each uploadtree row in this tree, write out text */
    $excluding_flag = 0;
    // 1: exclude 0: not exclude
    while ($row = pg_fetch_assoc($outerresult)) {
        $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
        $filepath = "";
        foreach ($filepatharray as $uploadtreeRow) {
            if (!empty($filepath)) {
                $filepath .= "/";
                /* filepath contains 'xxxx/', '/xxxx/', 'xxxx', '/xxxx' */
                $excluding_flag = ContainExcludeString($filepath, $excluding);
                if (1 == $excluding_flag) {
                    break;
                }
            }
            $filepath .= $uploadtreeRow['ufile_name'];
        }
        if (1 == $excluding_flag) {
            continue;
        }
        // excluding files whose path contains excluding text
        $V = $filepath;
        print "{$V}";
        print "\n";
    }
    pg_free_result($outerresult);
}
예제 #20
0
/**
 * \brief Given an array of pfiles/uploadtree, sorted by
 *  pfile, list all of the breadcrumbs for each file.
 *  If the pfile is a duplicate, then indent it.
 *
 * \param $Listing = array from a database selection.  The SQL query should
 *	use "ORDER BY pfile_fk" so that the listing can indent duplicate pfiles
 * \param $IfDirPlugin = string containing plugin name to use if this is a directory or any other container
 * \param $IfFilePlugin = string containing plugin name to use if this is a file
 * \param $Count = first number for indexing the entries (may be -1 for no count)
 * \param $ShowPhrase Obsolete from bsam
 *
 * \return string containing the listing.
 */
function UploadtreeFileList($Listing, $IfDirPlugin, $IfFilePlugin, $Count = -1, $ShowPhrase = 0)
{
    $LastPfilePk = -1;
    $V = "";
    foreach ($Listing as $R) {
        if (array_key_exists("licenses", $R)) {
            $Licenses = $R["licenses"];
        } else {
            $Licenses = '';
        }
        $Phrase = '';
        if ($ShowPhrase && !empty($R['phrase_text'])) {
            $text = _("Phrase");
            $Phrase = "<b>{$text}:</b> " . htmlentities($R['phrase_text']);
        }
        $uploadtree_tablename = GetUploadtreeTableName($R['upload_fk']);
        if (IsDir($R['ufile_mode']) || Iscontainer($R['ufile_mode'])) {
            $V .= "<P />\n";
            $V .= Dir2Browse("browse", $R['uploadtree_pk'], $IfDirPlugin, 1, NULL, $Count, $Phrase, $Licenses, $uploadtree_tablename) . "\n";
        } else {
            if ($R['pfile_fk'] != $LastPfilePk) {
                $V .= "<P />\n";
                $V .= Dir2Browse("browse", $R['uploadtree_pk'], $IfFilePlugin, 1, NULL, $Count, $Phrase, $Licenses, $uploadtree_tablename) . "\n";
                $LastPfilePk = $R['pfile_fk'];
            } else {
                $V .= "<div style='margin-left:2em;'>";
                $V .= Dir2Browse("browse", $R['uploadtree_pk'], $IfFilePlugin, 1, NULL, $Count, $Phrase, $Licenses, $uploadtree_tablename) . "\n";
                $V .= "</div>";
            }
        }
        $Count++;
    }
    return $V;
}
/**
 * \brief get nomos license list of one specified uploadtree_id
 *
 * \param $uploadtree_pk - uploadtree id
 * \param $upload_pk - upload id
 * \param $container - include container or not, 1: yes, 0: no (default)
 */
function GetLicenseList($uploadtree_pk, $upload_pk, $container = 0)
{
    global $PG_CONN;
    if (empty($uploadtree_pk)) {
        /* Find the uploadtree_pk for this upload so that it can be used in the browse link */
        $uploadtreeRec = GetSingleRec("uploadtree", "where parent is NULL and upload_fk='{$upload_pk}'");
        $uploadtree_pk = $uploadtreeRec['uploadtree_pk'];
    }
    //  print "Upload ID:$upload_pk; Uploadtree ID:$uploadtree_pk\n";
    /* get last nomos agent_pk that has data for this upload */
    $Agent_name = "nomos";
    $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1);
    $agent_pk = $AgentRec[0]["agent_fk"];
    if ($AgentRec === false) {
        echo _("No data available");
        return;
    }
    /* get the top of tree */
    $sql = "SELECT upload_fk, lft, rgt from uploadtree where uploadtree_pk='{$uploadtree_pk}';";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $toprow = pg_fetch_assoc($result);
    pg_free_result($result);
    $uploadtree_tablename = GetUploadtreeTableName($toprow['upload_fk']);
    /* loop through all the records in this tree */
    $sql = "select uploadtree_pk, ufile_name, lft, rgt from {$uploadtree_tablename} \n              where upload_fk='{$toprow['upload_fk']}' \n                    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n                    and ((ufile_mode & (1<<28)) = 0)";
    $container_sql = " and ((ufile_mode & (1<<29)) = 0)";
    /* include container or not */
    if (empty($container)) {
        $sql .= $container_sql;
        // do not include container
    }
    $sql .= "order by uploadtree_pk";
    $outerresult = pg_query($PG_CONN, $sql);
    DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
    /* Select each uploadtree row in this tree, write out text:
     * filepath : license list
     * e.g. Pound-2.4.tgz/Pound-2.4/svc.c: GPL_v3+, Indemnity
     */
    while ($row = pg_fetch_assoc($outerresult)) {
        $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
        $filepath = "";
        foreach ($filepatharray as $uploadtreeRow) {
            if (!empty($filepath)) {
                $filepath .= "/";
            }
            $filepath .= $uploadtreeRow['ufile_name'];
        }
        $V = $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtree_tablename);
        #$V = $filepath;
        print "{$V}";
        print "\n";
    }
    pg_free_result($outerresult);
}
예제 #22
0
 /**
  * \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 initialization
  */
 protected function setUp()
 {
     global $PG_CONN;
     global $upload_pk;
     global $pfile_pk_parent;
     global $pfile_pk_child;
     global $agent_pk;
     global $DB_COMMAND;
     global $DB_NAME;
     $DB_COMMAND = dirname(dirname(dirname(dirname(__FILE__)))) . "/testing/db/createTestDB.php";
     print "*** path to test db creation command: " . $DB_COMMAND;
     exec($DB_COMMAND, $dbout, $rc);
     if (!empty($rc)) {
         throw new Exception(implode("\n", $dbout));
     }
     preg_match("/(\\d+)/", $dbout[0], $matches);
     $test_name = $matches[1];
     $db_conf = $dbout[0];
     $DB_NAME = "fosstest" . $test_name;
     $PG_CONN = DBconnect($db_conf);
     $logger = new Monolog\Logger('default');
     $this->logFileName = dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/db.sqlite.log';
     $logger->pushHandler(new Monolog\Handler\StreamHandler($this->logFileName, Monolog\Logger::ERROR));
     $this->dbManager = new ModernDbManager($logger);
     $this->dbManager->setDriver(new Fossology\Lib\Db\Driver\Postgres($PG_CONN));
     /** preparation, add uploadtree, upload, pfile, license_file record */
     $upload_filename = "license_file_test";
     /* upload file name */
     $this->dbManager->prepare($stmt = 'pfile.insert', $sql = "INSERT INTO pfile (pfile_sha1,pfile_md5,pfile_size) VALUES (\$1,\$2,\$3)");
     $this->dbManager->freeResult($this->dbManager->execute($stmt, array('AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC', '2239AA7DAC291B6F8D0A56396B1B8530', '4560')));
     $this->dbManager->freeResult($this->dbManager->execute($stmt, array('B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6', '55EFE7F9B9D106047718F1CE9173B869', '1892')));
     /** add nomos agent record **/
     $this->dbManager->queryOnce($sql = "INSERT INTO agent (agent_name) VALUES('nomos')");
     /** add license_ref record */
     $this->dbManager->prepare($stmt = 'license_ref.insert', $sql = "INSERT INTO license_ref" . " (rf_pk, rf_shortname, rf_text, marydone, rf_active, rf_text_updatable, rf_detector_type)" . " VALUES (\$1,\$2,\$3,\$4,\$5,\$6,\$7)");
     $this->dbManager->freeResult($this->dbManager->execute($stmt, array(1, 'test_ref', 'test_ref', 'false', 'true', 'false', 1)));
     /** get pfile id */
     $this->dbManager->prepare($stmt = 'license_ref.select', $sql = "SELECT pfile_pk from pfile where pfile_sha1" . " IN ('AF1DF2C4B32E4115DB5F272D9EFD0E674CF2A0BC', 'B1938B14B9A573D59ABCBD3BF0F9200CE6E79FB6')");
     $result = $this->dbManager->execute($stmt);
     $row = $this->dbManager->fetchArray($result);
     $pfile_pk_parent = $row['pfile_pk'];
     $row = $this->dbManager->fetchArray($result);
     $pfile_pk_child = $row['pfile_pk'];
     $this->dbManager->freeResult($result);
     /** add a license_file record */
     $agent_nomos = $this->dbManager->getSingleRow("SELECT agent_pk from agent where agent_name = 'nomos'", array(), __METHOD__ . '.agent.select');
     $agent_pk = $agent_nomos['agent_pk'];
     $this->dbManager->prepare($stmt = 'license_file.insert', $sql = "INSERT INTO license_file(rf_fk, agent_fk, pfile_fk) VALUES (\$1,\$2,\$3)");
     $this->dbManager->freeResult($this->dbManager->execute($stmt, array(1, $agent_pk, $pfile_pk_parent)));
     $this->dbManager->freeResult($this->dbManager->execute($stmt, array(2, $agent_pk, $pfile_pk_child)));
     $this->dbManager->queryOnce("INSERT INTO upload (upload_filename,upload_mode,upload_ts, pfile_fk, uploadtree_tablename)" . " VALUES ('{$upload_filename}',40,now(), '{$pfile_pk_parent}', '{$this->uploadtree_tablename}')");
     $row = $this->dbManager->getSingleRow("SELECT upload_pk from upload where upload_filename = '{$upload_filename}'", array(), __METHOD__ . '.upload.select');
     $upload_pk = $row['upload_pk'];
     $this->dbManager->prepare($stmtIn = __METHOD__ . '.uploadtree.insert', "INSERT INTO uploadtree (parent, upload_fk, pfile_fk, ufile_mode, lft, rgt, ufile_name) VALUES (\$1,\$2,\$3,\$4,\$5,\$6,\$7)");
     $this->dbManager->freeResult($this->dbManager->execute($stmtIn, array(NULL, $upload_pk, $pfile_pk_parent, 33188, 1, 2, 'license_test.file.parent')));
     $this->dbManager->prepare($stmtOut = __METHOD__ . 'uploadtree.select', "SELECT uploadtree_pk from uploadtree where pfile_fk=\$1");
     $res = $this->dbManager->execute($stmtOut, array($pfile_pk_parent));
     $row = $this->dbManager->fetchArray($res);
     $this->dbManager->freeResult($res);
     $this->uploadtree_pk_parent = $row['uploadtree_pk'];
     /** add child uploadtree record */
     $this->dbManager->freeResult($this->dbManager->execute($stmtIn, array($this->uploadtree_pk_parent, $upload_pk, $pfile_pk_child, 33188, 1, 2, 'license_test.file.child')));
     $res = $this->dbManager->execute($stmtOut, array($pfile_pk_child));
     $row = $this->dbManager->fetchArray($res);
     $this->dbManager->freeResult($res);
     $this->uploadtree_pk_child = $row['uploadtree_pk'];
     $this->uploadtree_tablename = GetUploadtreeTableName($upload_pk);
     print '.';
 }