/** * @brief Returns an upload job status in html * @param $JobData * @return Returns an upload job status in html **/ function Show($JobData, $Page) { global $PG_CONN; $OutBuf = ''; $NumJobs = count($JobData); if ($NumJobs == 0) { return _("There are no jobs to display"); } /* Next/Prev menu */ $Next = $NumJobs > $this->MaxUploadsPerPage; if ($NumJobs > $this->MaxUploadsPerPage) { $OutBuf .= MenuEndlessPage($Page, $Next); } /*****************************************************************/ /* Now display the summary */ /*****************************************************************/ $Job = -1; $Blocked = array(); $First = 1; $Upload = "-1"; $Uri = Traceback_uri() . "?mod=" . $this->Name; $UriFull = $Uri . Traceback_parm_keep(array("upload")); $uploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:white;'"; $jobStyle = "style='font:bold 8pt verdana, arial, helvetica; background:lavender; color:black;'"; $prevupload_pk = ""; $OutBuf .= "<table class='text' border=1 width='100%' name='jobtable'>\n"; $FirstJob = $Page * $this->MaxUploadsPerPage; $LastJob = $Page * $this->MaxUploadsPerPage + $this->MaxUploadsPerPage; $JobNumber = -1; /** if $single_browse is 1, represent alread has an upload browse link, if single_browse is 0, no upload browse link */ $single_browse = 0; foreach ($JobData as $job_pk => $Job) { /* Upload */ if (!empty($Job["upload"])) { $UploadName = GetArrayVal("upload_filename", $Job["upload"]); $UploadDesc = GetArrayVal("upload_desc", $Job["upload"]); $upload_pk = GetArrayVal("upload_pk", $Job["upload"]); /** the column pfile_fk of the record in the table(upload) is NULL when this record is inserted */ if (!empty($upload_pk) && $prevupload_pk != $upload_pk || empty($upload_pk) && 0 == $single_browse) { $prevupload_pk = $upload_pk; $JobNumber++; /* Only display the jobs for this page */ if ($JobNumber >= $LastJob) { break; } if ($JobNumber < $FirstJob) { continue; } /* blank line separator between pfiles */ $OutBuf .= "<tr><td colspan=7> <hr> </td></tr>"; $OutBuf .= "<tr>"; $OutBuf .= "<th {$uploadStyle}></th>"; $OutBuf .= "<th colspan=4 {$uploadStyle}>"; if (!empty($Job['uploadtree'])) { $uploadtree_pk = $Job['uploadtree']['uploadtree_pk']; $OutBuf .= "<a title='Click to browse' href='" . Traceback_uri() . "?mod=browse&upload=" . $Job['job']['job_upload_fk'] . "&item=" . $uploadtree_pk . "'>"; } else { $OutBuf .= "<a title='Click to browse' href='" . Traceback_uri() . "?mod=browse'>"; } /* get $UserName if all jobs are shown */ $UserName = ""; $allusers = GetParm("allusers", PARM_INTEGER); if ($allusers > 0) { $UploadRec = GetSingleRec("upload", "where upload_pk={$Job['job']['job_upload_fk']}"); if (!empty($UploadRec)) { $UserRec = GetSingleRec("users", "where user_pk={$UploadRec['user_fk']}"); $UserName = "******"; } else { $UserRec = GetSingleRec("users", "where user_pk={$Job['job']['job_user_fk']}"); $UserName = "******"; } } $OutBuf .= $UploadName . $UserName; if (!empty($UploadDesc)) { $OutBuf .= " (" . $UploadDesc . ")"; } $OutBuf .= "</a>"; $OutBuf .= "</th>"; $OutBuf .= "<th {$uploadStyle}></th>"; $OutBuf .= "</tr>"; $single_browse = 1; } else { if ($JobNumber < $FirstJob) { continue; } } } else { /* blank line separator between pfiles */ $NoUploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:black;'"; $OutBuf .= "<tr><td colspan=7> <hr> </td></tr>"; $OutBuf .= "<tr>"; $OutBuf .= "<th {$NoUploadStyle}></th>"; $OutBuf .= "<th colspan=4 {$NoUploadStyle}>"; $OutBuf .= $Job["job"]["job_name"]; $OutBuf .= "</th>"; $OutBuf .= "<th {$NoUploadStyle}></th>"; $OutBuf .= "</tr>"; } /* Job data */ $OutBuf .= "<tr>"; $OutBuf .= "<th {$jobStyle}>"; $OutBuf .= _("Job/Dependency"); $OutBuf .= "</th>"; $OutBuf .= "<th {$jobStyle}>"; $OutBuf .= _("Status"); $OutBuf .= "</th>"; $OutBuf .= "<th colspan=3 {$jobStyle}>"; $OutBuf .= $Job["job"]["job_name"]; $OutBuf .= "</th>"; $OutBuf .= "<th {$jobStyle}>"; $OutBuf .= "</th></tr>"; /* Job queue */ foreach ($Job['jobqueue'] as $jq_pk => $jobqueueRec) { $RowColor = $this->GetColor($jobqueueRec); $jobqueueStyle = $this->jobqueueStyle($RowColor); $OutBuf .= "<tr {$jobqueueStyle}>"; /* Job/Dependency */ $OutBuf .= "<td {$jobqueueStyle}>"; $OutBuf .= "<a href='{$UriFull}&show=job&job=" . $jq_pk . "'>"; $OutBuf .= $jq_pk; $OutBuf .= "</a>"; $count = 0; if (!empty($jobqueueRec["depends"])) { foreach ($jobqueueRec["depends"] as $depend_jq_pk) { $OutBuf .= $count++ == 0 ? " / " : ", "; $OutBuf .= "<a href='{$UriFull}&show=job&job=" . $depend_jq_pk . "'>"; $OutBuf .= $depend_jq_pk; $OutBuf .= "</a>"; } } $OutBuf .= "</td>"; /* status */ $Status = $jobqueueRec["jq_endtext"]; $OutBuf .= "<td style='text-align:center'>{$Status}</td>"; $isPaused = $Status == "Paused" ? true : false; /* agent name */ $OutBuf .= "<td>{$jobqueueRec['jq_type']}</td>"; /* items processed */ if ($jobqueueRec["jq_itemsprocessed"] > 0) { $items = number_format($jobqueueRec['jq_itemsprocessed']); $OutBuf .= "<td style='text-align:right'>{$items} items</td>"; } else { $OutBuf .= "<td></td>"; } /* dates */ $OutBuf .= "<td>"; $OutBuf .= substr($jobqueueRec['jq_starttime'], 0, 16); if (!empty($jobqueueRec["jq_endtime"])) { $OutBuf .= " - " . substr($jobqueueRec['jq_endtime'], 0, 16); $NumSecs = strtotime($jobqueueRec['jq_endtime']) - strtotime($jobqueueRec['jq_starttime']); } else { $NumSecs = time() - strtotime($jobqueueRec['jq_starttime']); } /* Don't display items/sec unless the job has started */ if ($jobqueueRec['jq_starttime']) { if ($NumSecs > 0) { $ItemsPerSec = round($jobqueueRec['jq_itemsprocessed'] / $NumSecs); if ($ItemsPerSec < 1) { $OutBuf .= sprintf(" : (%01.2f items/sec)", $jobqueueRec['jq_itemsprocessed'] / $NumSecs); } else { $OutBuf .= sprintf(" : (%d items/sec)", $ItemsPerSec); } } } $OutBuf .= "</td>"; /* actions, must be admin or own the upload */ if ($jobqueueRec['jq_end_bits'] == 0 && ($_SESSION["UserLevel"] == PLUGIN_DB_ADMIN || $_SESSION["UserId"] == $Job['job']['job_user_fk'])) { $OutBuf .= "<th {$jobStyle}>"; if ($isPaused) { $text = _("Unpause"); $OutBuf .= "<a href='{$UriFull}&action=restart&jobid={$jq_pk}' title='Un-Pause this job'>{$text}</a>"; } else { $text = _("Pause"); $OutBuf .= "<a href='{$UriFull}&action=pause&jobid={$jq_pk}' title='Pause this job'>{$text}</a>"; } $OutBuf .= " | "; $text = _("Cancel"); $OutBuf .= "<a href='{$UriFull}&action=cancel&jobid={$jq_pk}' title='Cancel this job'>{$text}</a>"; } else { $OutBuf .= "<th>"; } $OutBuf .= "</th></tr>"; } } $OutBuf .= "</table>\n"; if ($NumJobs > $this->MaxUploadsPerPage) { $OutBuf .= "<p>" . MenuEndlessPage($Page, $Next); } return $OutBuf; }
/** * \brief Given an $Uploadtree_pk, display: \n * (1) The histogram for the directory BY bucket. \n * (2) The file listing for the directory. */ function ShowUploadHist($Uploadtree_pk, $Uri) { global $PG_CONN; $VF = ""; // return values for file listing $VLic = ""; // return values for output $V = ""; // total return value $UniqueTagArray = array(); global $Plugins; $ModLicView =& $Plugins[plugin_find_id("view-license")]; /******* Get Bucket 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__); if (pg_num_rows($result) < 1) { pg_free_result($result); $text = _("Invalid URL, nonexistant item"); return "<h2>{$text} {$Uploadtree_pk}</h2>"; } $row = pg_fetch_assoc($result); $lft = $row["lft"]; $rgt = $row["rgt"]; $upload_pk = $row["upload_fk"]; pg_free_result($result); /* Get the ars_pk of the scan to display, also the select list */ $ars_pk = GetArrayVal("ars", $_GET); $BucketSelect = SelectBucketDataset($upload_pk, $ars_pk, "selectbdata", "onchange=\"addArsGo('newds','selectbdata');\""); if ($ars_pk == 0) { /* No bucket data for this upload */ return $BucketSelect; } /* Get scan keys */ $sql = "select agent_fk, nomosagent_fk, bucketpool_fk from bucket_ars where ars_pk={$ars_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $bucketagent_pk = $row["agent_fk"]; $nomosagent_pk = $row["nomosagent_fk"]; $bucketpool_pk = $row["bucketpool_fk"]; pg_free_result($result); /* Create bucketDefArray as individual query this is MUCH faster than incorporating it with a join in the following queries. */ $bucketDefArray = initBucketDefArray($bucketpool_pk); /*select all the buckets for entire tree for this bucketpool */ $sql = "SELECT distinct(bucket_fk) as bucket_pk,\n count(bucket_fk) as bucketcount, bucket_reportorder\n from bucket_file, bucket_def,\n (SELECT distinct(pfile_fk) as PF from {$this->uploadtree_tablename} \n where upload_fk={$upload_pk} \n and ((ufile_mode & (1<<28))=0)\n and ((ufile_mode & (1<<29))=0)\n and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt}) as SS\n where PF=pfile_fk and agent_fk={$bucketagent_pk} \n and bucket_file.nomosagent_fk={$nomosagent_pk}\n and bucket_pk=bucket_fk\n and bucketpool_fk={$bucketpool_pk}\n group by bucket_fk,bucket_reportorder\n order by bucket_reportorder asc"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $historows = pg_fetch_all($result); pg_free_result($result); /* Show dataset list */ if (!empty($BucketSelect)) { $action = Traceback_uri() . "?mod=bucketbrowser&upload={$upload_pk}&item={$Uploadtree_pk}"; $VLic .= "<script type='text/javascript'>\nfunction addArsGo(formid, selectid ) \n{\nvar selectobj = document.getElementById(selectid);\nvar ars_pk = selectobj.options[selectobj.selectedIndex].value;\ndocument.getElementById(formid).action='{$action}'+'&ars='+ars_pk;\ndocument.getElementById(formid).submit();\nreturn;\n}\n</script>"; /* form to select new dataset (ars_pk) */ $VLic .= "<form action='{$action}' id='newds' method='POST'>\n"; $VLic .= $BucketSelect; $VLic .= "</form>"; } $sql = "select bucketpool_name, version from bucketpool where bucketpool_pk={$bucketpool_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $row = pg_fetch_assoc($result); $bucketpool_name = $row['bucketpool_name']; $bucketpool_version = $row['version']; pg_free_result($result); /* Write bucket histogram to $VLic */ $bucketcount = 0; $Uniquebucketcount = 0; $NoLicFound = 0; if (is_array($historows)) { $text = _("Bucket Pool"); $VLic .= "{$text}: {$bucketpool_name} v{$bucketpool_version}<br>"; $VLic .= "<table border=1 width='100%'>\n"; $text = _("Count"); $VLic .= "<tr><th width='10%'>{$text}</th>"; $text = _("Files"); $VLic .= "<th width='10%'>{$text}</th>"; $text = _("Bucket"); $VLic .= "<th align='left'>{$text}</th></tr>\n"; foreach ($historows as $bucketrow) { $Uniquebucketcount++; $bucket_pk = $bucketrow['bucket_pk']; $bucketcount = $bucketrow['bucketcount']; $bucket_name = $bucketDefArray[$bucket_pk]['bucket_name']; $bucket_color = $bucketDefArray[$bucket_pk]['bucket_color']; /* Count */ $VLic .= "<tr><td align='right' style='background-color:{$bucket_color}'>{$bucketcount}</td>"; /* Show */ $VLic .= "<td align='center'><a href='"; $VLic .= Traceback_uri(); $text = _("Show"); $VLic .= "?mod=list_bucket_files&bapk={$bucketagent_pk}&item={$Uploadtree_pk}&bpk={$bucket_pk}&bp={$bucketpool_pk}&napk={$nomosagent_pk}" . "'>{$text}</a></td>"; /* Bucket name */ $VLic .= "<td align='left'>"; $VLic .= "<a id='{$bucket_pk}' onclick='FileColor_Get(\"" . Traceback_uri() . "?mod=ajax_filebucket&bapk={$bucketagent_pk}&item={$Uploadtree_pk}&bucket_pk={$bucket_pk}\")'"; $VLic .= ">{$bucket_name} </a>"; /* Allow users to tag an entire bucket */ /* Future, maybe v 2.1 $TagHref = "<a href=" . Traceback_uri() . "?mod=bucketbrowser&upload=$upload_pk&item=$Uploadtree_pk&bapk=$bucketagent_pk&bpk=$bucket_pk&bp=$bucketpool_pk&napk=$nomosagent_pk&tagbucket=1>Tag</a>"; $VLic .= " [$TagHref]"; */ $VLic .= "</td>"; $VLic .= "</tr>\n"; // if ($row['bucket_name'] == "No Buckets Found") $NoLicFound = $row['bucketcount']; } $VLic .= "</table>\n"; $VLic .= "<p>\n"; $text = _("Unique buckets"); $VLic .= "{$text}: {$Uniquebucketcount}<br>\n"; } /******* File Listing ************/ /* Get ALL the items under this Uploadtree_pk */ $Children = GetNonArtifactChildren($Uploadtree_pk, $this->uploadtree_tablename); if (count($Children) == 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 (empty($row) || IsDir($row['ufile_mode'])) { return; } // $ModLicView = &$Plugins[plugin_find_id("view-license")]; // return($ModLicView->Output() ); } $ChildCount = 0; $Childbucketcount = 0; /* Countd disabled until we know we need them $NumSrcPackages = 0; $NumBinPackages = 0; $NumBinNoSrcPackages = 0; */ /* get mimetypes for packages */ $MimetypeArray = GetPkgMimetypes(); $VF .= "<table border=0>"; foreach ($Children as $C) { if (empty($C)) { continue; } /* update package counts */ /* This is an expensive count. Comment out until we know we really need it IncrSrcBinCounts($C, $MimetypeArray, $NumSrcPackages, $NumBinPackages, $NumBinNoSrcPackages); */ $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={$nomosagent_pk}&bapk={$bucketagent_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); $tmpuri = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "folder", "ars")); $LicUri = "{$tmpuri}&item=" . $uploadtree_pk; } else { $LicUri = NULL; } /* Populate the output ($VF) - file list */ /* id of each element is its uploadtree_pk */ $VF .= "<tr><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>"; } /* print buckets */ $VF .= "<br>"; $VF .= "<span style='position:relative;left:1em'>"; /* get color coded string of bucket names */ $VF .= GetFileBuckets_string($nomosagent_pk, $bucketagent_pk, $C['uploadtree_pk'], $bucketDefArray, ",", True); $VF .= "</span>"; $VF .= "</td><td valign='top'>"; /* display item links */ $VF .= FileListLinks($C['upload_fk'], $C['uploadtree_pk'], $nomosagent_pk, $C['pfile_fk'], True, $UniqueTagArray, $this->uploadtree_tablename); $VF .= "</td>"; $VF .= "</tr>\n"; $ChildCount++; } $VF .= "</table>\n"; $V .= ActiveHTTPscript("FileColor"); /* Add javascript for color highlighting This is the response script needed by ActiveHTTPscript responseText is bucket_pk',' 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 Lastbupk=''; /* save last bucket_pk */\n var color = '#4bfe78';\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(Lastbupk).style.backgroundColor='white';\n while (numpks)\n {\n document.getElementById(Lastutpks[--numpks]).style.backgroundColor='white';\n }\n\n utpklist = FileColor.responseText.split(',');\n Lastbupk = utpklist.shift();\n numpks = utpklist.length;\n Lastutpks = utpklist;\n\n /* apply new highlighting */\n elt = document.getElementById(Lastbupk);\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; /* Display source, binary, and binary missing source package counts */ /* Counts disabled above until we know we need these $VLic .= "<ul>"; $text = _("source packages"); $VLic .= "<li> $NumSrcPackages $text"; $text = _("binary packages"); $VLic .= "<li> $NumBinPackages $text"; $text = _("binary packages with no source package"); $VLic .= "<li> $NumBinNoSrcPackages $text"; $VLic .= "</ul>"; */ /* Combine VF and VLic */ $V .= "<table border=0 width='100%'>\n"; $V .= "<tr><td valign='top' width='50%'>{$VLic}</td><td valign='top'>{$VF}</td></tr>\n"; $V .= "</table>\n"; $V .= "<hr />\n"; return $V; }
/** * @brief remove files that contain identical bucket lists * @param &$Master * @return updated $Master */ function filter_samebucketlist(&$Master) { foreach ($Master as $Key => &$Pair) { $Pair1 = GetArrayVal("1", $Pair); $Pair2 = GetArrayVal("2", $Pair); if (empty($Pair1) or empty($Pair2)) { continue; } if ($Pair1['bucketstr'] == $Pair2['bucketstr']) { unset($Master[$Key]); } } return; }
/** * @brief Returns an upload job status in html * @param $jobData * @return Returns an upload job status in html **/ protected function show($jobData, $page) { global $container; /** @var DbManager */ $dbManager = $container->get('db.manager'); $outBuf = ''; $pagination = ''; $numJobs = count($jobData); if ($numJobs == 0) { return array('showJobsData' => "There are no jobs to display"); } $uri = Traceback_uri() . "?mod=showjobs"; $uriFull = $uri . Traceback_parm_keep(array("upload")); $uriFullMenu = $uri . Traceback_parm_keep(array("allusers")); /* Next/Prev menu */ $next = $numJobs > $this->maxUploadsPerPage; if ($numJobs > $this->maxUploadsPerPage) { $pagination .= MenuEndlessPage($page, $next, $uriFullMenu); } /*****************************************************************/ /* Now display the summary */ /*****************************************************************/ $job = -1; $uploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:white;'"; $noUploadStyle = "style='font:bold 10pt verdana, arial, helvetica; background:gold; color:black;'"; $jobStyle = "style='font:bold 8pt verdana, arial, helvetica; background:lavender; color:black;'"; $prevupload_pk = ""; $firstJob = $page * $this->maxUploadsPerPage; $lastJob = $page * $this->maxUploadsPerPage + $this->maxUploadsPerPage; $jobNumber = -1; /** if $single_browse is 1, represent alread has an upload browse link, if single_browse is 0, no upload browse link */ $single_browse = 0; foreach ($jobData as $job) { /* Upload */ if (!empty($job["upload"])) { $uploadName = GetArrayVal("upload_filename", $job["upload"]); $uploadDesc = GetArrayVal("upload_desc", $job["upload"]); $upload_pk = GetArrayVal("upload_pk", $job["upload"]); $jobId = GetArrayVal("job_pk", $job["job"]); /** the column pfile_fk of the record in the table(upload) is NULL when this record is inserted */ if (!empty($upload_pk) && $prevupload_pk != $upload_pk || empty($upload_pk) && 0 == $single_browse) { $prevupload_pk = $upload_pk; $jobNumber++; /* Only display the jobs for this page */ if ($jobNumber >= $lastJob) { break; } if ($jobNumber < $firstJob) { continue; } /* blank line separator between pfiles */ $outBuf .= "<tr><td colspan=8> <hr> </td></tr>"; $outBuf .= "<tr>"; $outBuf .= "<th {$uploadStyle}></th>"; $outBuf .= "<th colspan=6 {$uploadStyle}>"; if (!empty($job['uploadtree'])) { $uploadtree_pk = $job['uploadtree']['uploadtree_pk']; $outBuf .= "<a title='Click to browse' href='" . Traceback_uri() . "?mod=browse&upload=" . $job['job']['job_upload_fk'] . "&item=" . $uploadtree_pk . "'>"; } else { $outBuf .= "<a {$noUploadStyle}>"; } /* get $userName if all jobs are shown */ $userName = ""; $allusers = GetParm("allusers", PARM_INTEGER); if ($allusers > 0) { $statementName = __METHOD__ . "UploadRec"; $uploadRec = $dbManager->getSingleRow("select * from upload where upload_pk=\$1", array($job['job']['job_upload_fk']), $statementName); if (!empty($uploadRec['user_fk'])) { $statementName = __METHOD__ . "UserRec"; $userRec = $dbManager->getSingleRow("select * from users where user_pk=\$1", array($uploadRec['user_fk']), $statementName); $userName = "******"; } else { $statementName = __METHOD__ . "UserRec1"; $userRec = $dbManager->getSingleRow("select * from users where user_pk=\$1", array($job['job']['job_user_fk']), $statementName); $userName = "******"; } } $outBuf .= $uploadName . $userName; if (!empty($uploadDesc)) { $outBuf .= " (" . $uploadDesc . ")"; } $outBuf .= "</a>"; $outBuf .= "</th>"; $outBuf .= "<th {$uploadStyle}><a>" . $this->showJobsDao->getEstimatedTime($jobId) . "</a></th>"; $outBuf .= "</tr>"; $single_browse = 1; } else { if ($jobNumber < $firstJob) { continue; } } } else { /* Show Jobs that are not attached to an upload */ $jobNumber++; /* Only display the jobs for this page */ if ($jobNumber >= $lastJob) { break; } if ($jobNumber < $firstJob) { continue; } /* blank line separator between pfiles */ $outBuf .= "<tr><td colspan=8> <hr> </td></tr>"; $outBuf .= "<tr>"; $outBuf .= "<th {$noUploadStyle}></th>"; $outBuf .= "<th colspan=6 {$noUploadStyle}>"; $outBuf .= htmlentities($job["job"]["job_name"], ENT_QUOTES); $outBuf .= "</th>"; $outBuf .= "<th {$noUploadStyle}></th>"; $outBuf .= "</tr>"; } /* Job data */ $outBuf .= "<tr>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("Job/Dependency"); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("Status"); $outBuf .= "</th>"; $outBuf .= "<th colspan=3 {$jobStyle}>"; $outBuf .= htmlentities($job["job"]["job_name"], ENT_QUOTES); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("Average items/sec"); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= _("ETA"); $outBuf .= "</th>"; $outBuf .= "<th {$jobStyle}>"; $outBuf .= "</th></tr>"; /* Job queue */ foreach ($job['jobqueue'] as $jq_pk => $jobqueueRec) { $varJobQueueRow = array('jqId' => $jq_pk, 'jobId' => $jobqueueRec['jq_job_fk'], 'class' => $this->getClass($jobqueueRec), 'uriFull' => $uriFull, 'depends' => $jobqueueRec['jdep_jq_depends_fk'] ? $jobqueueRec['depends'] : array(), 'status' => $jobqueueRec['jq_endtext'], 'agentName' => $jobqueueRec['jq_type'], 'itemsProcessed' => $jobqueueRec['jq_itemsprocessed'], 'startTime' => substr($jobqueueRec['jq_starttime'], 0, 16), 'endTime' => empty($jobqueueRec["jq_endtime"]) ? '' : substr($jobqueueRec['jq_endtime'], 0, 16), 'endText' => $jobqueueRec['jq_endtext']); if (!empty($jobqueueRec["jq_endtime"])) { $numSecs = strtotime($jobqueueRec['jq_endtime']) - strtotime($jobqueueRec['jq_starttime']); } else { $numSecs = time() - strtotime($jobqueueRec['jq_starttime']); } $itemsPerSec = null; if ($jobqueueRec['jq_starttime']) { $itemsPerSec = $this->showJobsDao->getNumItemsPerSec($jobqueueRec['jq_itemsprocessed'], $numSecs); $varJobQueueRow['itemsPerSec'] = $itemsPerSec; } if (empty($jobqueueRec['jq_endtime'])) { $varJobQueueRow['eta'] = $this->showJobsDao->getEstimatedTime($jobId, $jobqueueRec['jq_type'], $itemsPerSec, $job['job']['job_upload_fk']); } $varJobQueueRow['canDoActions'] = $_SESSION[Auth::USER_LEVEL] == PLUGIN_DB_ADMIN || Auth::getUserId() == $job['job']['job_user_fk']; $varJobQueueRow['isInProgress'] = $jobqueueRec['jq_end_bits'] == 0; $varJobQueueRow['isReady'] = $jobqueueRec['jq_end_bits'] == 1; switch ($jobqueueRec['jq_type']) { case 'readmeoss': $varJobQueueRow['download'] = "ReadMeOss"; break; case 'spdx2': $varJobQueueRow['download'] = "SPDX2 report"; break; case 'spdx2tv': $varJobQueueRow['download'] = "SPDX2 tag/value report"; break; case 'dep5': $varJobQueueRow['download'] = "DEP5 copyright file"; break; default: $varJobQueueRow['download'] = ""; } $outBuf .= $this->renderString('ui-showjobs-jobqueue-row.html.twig', $varJobQueueRow); } } if ($numJobs > $this->maxUploadsPerPage) { $pagination = "<p>" . MenuEndlessPage($page, $next, $uriFullMenu); } return array('showJobsData' => $outBuf, 'pagination' => $pagination); }
function Output() { global $PG_CONN; if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; $folder_pk = GetParm('folder', PARM_TEXT); $FolderSelectId = GetParm('selectfolderid', PARM_INTEGER); if (empty($FolderSelectId)) { $FolderSelectId = GetUserRootFolder(); } $NewName = GetArrayVal("newname", $_POST); $NewDesc = GetArrayVal("newdesc", $_POST); $upload_pk = GetArrayVal("upload_pk", $_POST); if (empty($upload_pk)) { $upload_pk = GetParm('upload', PARM_INTEGER); } /* Check Upload permission */ if (!empty($upload_pk)) { $UploadPerm = GetUploadPerm($upload_pk); if ($UploadPerm < PERM_WRITE) { $text = _("Permission Denied"); echo "<h2>{$text}<h2>"; return; } } $rc = $this->UpdateUploadProperties($upload_pk, $NewName, $NewDesc); if ($rc == 0) { $text = _("Nothing to Change"); $V .= displayMessage($text); } else { if ($rc == 1) { $text = _("Upload Properties successfully changed"); $V .= displayMessage($text); } } /* define js_url */ $V .= js_url(); /* Build the HTML form */ $V .= "<form name='formy' method='post'>\n"; // no url = this url $V .= "<ol>\n"; $text = _("Select the folder that contains the upload: \n"); $V .= "<li>{$text}"; /*** Display folder select list, on change request new page with folder= in url ***/ $Uri = Traceback_uri() . "?mod=" . $this->Name . "&selectfolderid="; $V .= "<select name='oldfolderid' onChange='window.location.href=\"{$Uri}\" + this.value'>\n"; $V .= FolderListOption(-1, 0, 1, $FolderSelectId); $V .= "</select><P />\n"; /*** Display upload select list, on change, request new page with new upload= in url ***/ $text = _("Select the upload you wish to edit: \n"); $V .= "<li>{$text}"; // Get list of all upload records in this folder $UploadList = FolderListUploads_perm($FolderSelectId, PERM_WRITE); // Make data array for upload select list. Key is upload_pk, value is a composite // of the upload_filename and upload_ts. $UploadArray = array(); foreach ($UploadList as $UploadRec) { $SelectText = htmlentities($UploadRec['name']); if (!empty($UploadRec['upload_ts'])) { $SelectText .= ", " . substr($UploadRec['upload_ts'], 0, 19); } $UploadArray[$UploadRec['upload_pk']] = $SelectText; } /* Get selected upload info to display*/ if (empty($upload_pk)) { // no upload selected, so use the top one in the select list reset($UploadArray); $upload_pk = key($UploadArray); } if ($upload_pk) { // case where upload is set in the URL $sql = "SELECT * FROM upload WHERE upload_pk = '{$upload_pk}'"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); if (pg_num_rows($result) == 0) { /* Bad upload_pk */ $text = _("Missing upload."); $V .= displayMessage($text); pg_free_result($result); return 0; } $UploadRec = pg_fetch_assoc($result); pg_free_result($result); $V .= "<INPUT type='hidden' name='upload_pk' value='{$upload_pk}' />\n"; } else { // no uploads in the folder $UploadRec = array(); } $url = Traceback_uri() . "?mod=upload_properties&folder={$folder_pk}&upload="; $onchange = "onchange=\"js_url(this.value, '{$url}')\""; $V .= Array2SingleSelect($UploadArray, "uploadselect", $upload_pk, false, false, $onchange); /* Input upload_filename */ $text = _("Upload name: \n"); $V .= "<li>{$text}"; if (empty($UploadRec['upload_filename'])) { $upload_filename = ""; } else { $upload_filename = htmlentities($UploadRec['upload_filename']); } $V .= "<INPUT type='text' name='newname' size=40 value='{$upload_filename}' />\n"; /* Input upload_desc */ $text = _("Upload description: \n"); $V .= "<li>{$text}"; if (empty($UploadRec['upload_desc'])) { $upload_desc = ""; } else { $upload_desc = htmlentities($UploadRec['upload_desc'], ENT_QUOTES); } $V .= "<INPUT type='text' name='newdesc' size=60 value='{$upload_desc}' />\n"; $V .= "</ol>\n"; $text = _("Edit"); $V .= "<input type='submit' value='{$text}!'>\n"; $V .= "</form>\n"; if (!$this->OutputToStdout) { return $V; } print "{$V}"; return; }
public function Output() { $groupId = Auth::getGroupId(); $rootFolder = $this->folderDao->getRootFolder(Auth::getUserId()); $folderStructure = $this->folderDao->getFolderStructure($rootFolder->getId()); $V = ""; $folder_pk = GetParm('folder', PARM_INTEGER); if (empty($folder_pk)) { $folder_pk = $rootFolder->getId(); } $NewName = GetArrayVal("newname", $_POST); $NewDesc = GetArrayVal("newdesc", $_POST); $upload_pk = GetArrayVal("upload_pk", $_POST); if (empty($upload_pk)) { $upload_pk = GetParm('upload', PARM_INTEGER); } /* Check Upload permission */ if (!empty($upload_pk) && !$this->uploadDao->isEditable($upload_pk, $groupId)) { $text = _("Permission Denied"); return "<h2>{$text}</h2>"; } $rc = $this->UpdateUploadProperties($upload_pk, $NewName, $NewDesc); if ($rc == 0) { $text = _("Nothing to Change"); $this->vars['message'] = $text; } else { if ($rc == 1) { $text = _("Upload Properties successfully changed"); $this->vars['message'] = $text; } } $this->vars['folderStructure'] = $folderStructure; $this->vars['folderId'] = $folder_pk; $this->vars['baseUri'] = $Uri = Traceback_uri() . "?mod=" . $this->Name . "&folder="; $folderUploads = $this->folderDao->getFolderUploads($folder_pk, $groupId); $uploadsById = array(); /* @var $uploadProgress UploadProgress */ foreach ($folderUploads as $uploadProgress) { if ($uploadProgress->getGroupId() != $groupId) { continue; } if (!$this->uploadDao->isEditable($uploadProgress->getId(), $groupId)) { continue; } $display = $uploadProgress->getFilename() . _(" from ") . date("Y-m-d H:i", $uploadProgress->getTimestamp()); $uploadsById[$uploadProgress->getId()] = $display; } $this->vars['uploadList'] = $uploadsById; if (empty($upload_pk)) { reset($uploadsById); $upload_pk = key($uploadsById); } $this->vars['uploadId'] = $upload_pk; if ($upload_pk) { $upload = $this->uploadDao->getUpload($upload_pk); if (empty($upload)) { $this->vars['message'] = _("Missing upload."); return 0; } } else { $upload = null; } $baseFolderUri = $this->vars['baseUri'] . "{$folder_pk}&upload="; $this->vars['uploadAction'] = "onchange=\"js_url(this.value, '{$baseFolderUri}')\""; $this->vars['uploadFilename'] = $upload ? $upload->getFilename() : ''; $this->vars['uploadDesc'] = $upload ? $upload->getDescription() : ''; $this->vars['content'] = $V; return $this->render('admin_upload_edit.html.twig'); }
/** * \brief This is only called when the user logs out. */ public function Output() { $userName = GetParm("username", PARM_TEXT); $password = GetParm("password", PARM_TEXT); $referrer = GetParm("HTTP_REFERER", PARM_TEXT); if (empty($referrer)) { $referrer = GetArrayVal('HTTP_REFERER', $_SERVER); } $referrerQuery = parse_url($referrer, PHP_URL_QUERY); if ($referrerQuery) { $params = array(); parse_str($referrerQuery, $params); if (array_key_exists('mod', $params) && $params['mod'] == $this->Name) { $referrer = Traceback_uri(); } } $validLogin = $this->checkUsernameAndPassword($userName, $password); if ($validLogin) { return new RedirectResponse($referrer); } $initPluginId = plugin_find_id("init"); if ($initPluginId >= 0) { global $Plugins; $this->vars['info'] = $Plugins[$initPluginId]->infoFirstTimeUsage(); } if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") { $this->vars['protocol'] = "HTTPS"; } else { $this->vars['protocol'] = preg_replace("@/.*@", "", @$_SERVER['SERVER_PROTOCOL']); } $this->vars['referrer'] = $referrer; $this->vars['loginFailure'] = !empty($userName) || !empty($password); if (!empty($userName) && $userName != 'Default User') { $this->vars['userName'] = $userName; } return $this->render('login.html.twig', $this->vars); }
/** * @brief Find all the groups a user belongs to. * @param $user_pk optional, defaults to current user * @return array of groups * each group is itself an array with the following elements * - [user_pk] * - [group_pk] * - [group_name] * - [group_perm] **/ function GetUsersGroups($user_pk = '') { global $PG_CONN; $GroupArray = array(); if (empty($user_pk)) { $user_pk = GetArrayVal("UserId", $_SESSION); } if (empty($user_pk)) { return $GroupArray; } /* user has no groups */ /* find all groups with this user */ $sql = "select group_fk as group_pk from group_user_member where user_fk={$user_pk}"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); while ($row = pg_fetch_assoc($result)) { /* Now find all the groups that contain this group */ GetGroupUsers($user_pk, $row['group_pk'], $GroupArray); } pg_free_result($result); return $GroupArray; }
/** * \brief removes pairs of "No_license_found" * Or pairs that only have one file and "No_license_found" * Uses fuzzyname. */ function filter_nolics(&$Master) { $NoLicStr = "No_license_found"; foreach ($Master as $Key => &$Pair) { $Pair1 = GetArrayVal("1", $Pair); $Pair2 = GetArrayVal("2", $Pair); if (empty($Pair1)) { if ($Pair2['licstr'] == $NoLicStr) { unset($Master[$Key]); } else { continue; } } else { if (empty($Pair2)) { if ($Pair1['licstr'] == $NoLicStr) { unset($Master[$Key]); } else { continue; } } else { if ($Pair1['licstr'] == $NoLicStr and $Pair2['licstr'] == $NoLicStr) { unset($Master[$Key]); } } } } return; }
/** * \brief Process the upload request. * * \param $folder_pk * \param $TempFile path to temporary (upload) file * \param $Desc optional upload description. * \param $Name original name of the file on the client machine. * \param $public_perm public permission on the upload * \return NULL on success, error string on failure. */ function Upload($folder_pk, $TempFile, $Desc, $Name, $public_perm) { global $MODDIR; global $SysConf; global $SYSCONFDIR; define("UPLOAD_ERR_EMPTY", 5); define("UPLOAD_ERR_INVALID_FOLDER_PK", 100); $upload_errors = array(UPLOAD_ERR_OK => _("No errors."), UPLOAD_ERR_INI_SIZE => _("Larger than upload_max_filesize ") . ini_get('upload_max_filesize'), UPLOAD_ERR_FORM_SIZE => _("Larger than form MAX_FILE_SIZE."), UPLOAD_ERR_PARTIAL => _("Partial upload."), UPLOAD_ERR_NO_FILE => _("No file."), UPLOAD_ERR_NO_TMP_DIR => _("No temporary directory."), UPLOAD_ERR_CANT_WRITE => _("Can't write to disk."), UPLOAD_ERR_EXTENSION => _("File upload stopped by extension."), UPLOAD_ERR_EMPTY => _("File is empty or you don't have permission to read the file."), UPLOAD_ERR_INVALID_FOLDER_PK => _("Invalid Folder.")); $UploadFile = $_FILES['getfile']; $UploadError = @$UploadFile['error']; /* Additional error checks */ if ($UploadFile['size'] == 0 && $UploadFile['error'] == 0) { $UploadFile['error'] = UPLOAD_ERR_EMPTY; } if (empty($folder_pk)) { $UploadFile['error'] = UPLOAD_ERR_INVALID_FOLDER_PK; } if ($UploadFile['error'] != UPLOAD_ERR_OK) { return $upload_errors[$UploadFile['error']]; } $originName = @$UploadFile['name']; if (empty($Name)) { $Name = basename($originName); } $ShortName = basename($Name); if (empty($ShortName)) { $ShortName = $Name; } // for odd case where $Name is '/' /* Create an upload record. */ $Mode = 1 << 3; // code for "it came from web upload" $user_pk = $SysConf['auth']['UserId']; $uploadpk = JobAddUpload($user_pk, $ShortName, $originName, $Desc, $Mode, $folder_pk, $public_perm); if (empty($uploadpk)) { $text = _("Failed to insert upload record"); return $text; } /* move the temp file */ $UploadedFile = "{$TempFile}" . "-uploaded"; if (!move_uploaded_file($TempFile, "{$UploadedFile}")) { $text = _("Could not save uploaded file"); return $text; } if (!chmod($UploadedFile, 0660)) { $text = _("ERROR! could not update permissions on downloaded file"); return $text; } /* Run wget_agent locally to import the file. */ $Prog = "{$MODDIR}/wget_agent/agent/wget_agent -C -g fossy -k {$uploadpk} '{$UploadedFile}' -c '{$SYSCONFDIR}'"; $wgetOut = array(); $wgetLast = exec($Prog, $wgetOut, $wgetRtn); unlink($UploadedFile); /* Create Job */ $job_pk = JobAddJob($user_pk, $ShortName, $uploadpk); global $Plugins; $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")]; $Dependencies = array(); $adj2nestplugin->AgentAdd($job_pk, $uploadpk, $ErrorMsg, $Dependencies); AgentCheckBoxDo($job_pk, $uploadpk); if ($wgetRtn == 0) { $Msg = ""; /** check if the scheudler is running */ $status = GetRunnableJobList(); if (empty($status)) { $Msg .= _("Is the scheduler running? "); } $text = _("The file"); $text1 = _("has been uploaded. It is"); $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadpk}"; $Msg .= "{$text} {$Name} {$text1} "; $keep = '<a href=' . $Url . '>upload #' . $uploadpk . "</a>.\n"; print displayMessage($Msg, $keep); return NULL; } else { $ErrMsg = GetArrayVal(0, $wgetOut); if (empty($ErrMsg)) { $ErrMsg = _("File upload failed. Error:") . $wgetRtn; } return $ErrMsg; } return NULL; }
/** * \brief This is only called when the user logs out. */ function Output() { global $SysConf; if ($this->State != PLUGIN_STATE_READY) { return; } $V = ""; switch ($this->OutputType) { case "XML": break; case "HTML": if ($_SESSION['User'] == "Default User") { $User = GetParm("username", PARM_TEXT); $Pass = GetParm("password", PARM_TEXT); $Referer = GetParm("HTTP_REFERER", PARM_TEXT); if (empty($Referer)) { $Referer = GetArrayVal('HTTP_REFERER', $_SERVER); } if (!empty($User)) { $VP = $this->CheckUser($User, $Pass, $Referer); } else { $VP = ""; } if (!empty($VP)) { $V .= $VP; } else { /* Check for init and first-time use */ if (plugin_find_id("init") >= 0) { $text = _("The system requires initialization. Please login and use the Initialize option under the Admin menu."); $V .= "<b>{$text}</b>"; $V .= "<P />\n"; /* Check for a default user */ global $PG_CONN; $Level = PLUGIN_DB_ADMIN; $sql = "SELECT * FROM users WHERE user_perm = {$Level} LIMIT 1;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); $R = pg_fetch_assoc($result); pg_free_result($result); if (array_key_exists("user_seed", $R) && array_key_exists("user_pass", $R)) { $sql = "SELECT user_name FROM users WHERE user_seed IS NULL AND user_pass IS NULL;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); } else { $sql = "SELECT user_name FROM users;"; $result = pg_query($PG_CONN, $sql); DBCheckResult($result, $sql, __FILE__, __LINE__); } $R = pg_fetch_assoc($result); pg_free_result($result); if (!empty($R['user_name'])) { $V .= _("If you need an account, use '" . $R['user_name'] . "' with no password.\n"); $V .= "<P />\n"; } } /* Inform about the protocol. */ $Protocol = preg_replace("@/.*@", "", @$_SERVER['SERVER_PROTOCOL']); if ($Protocol != 'HTTPS') { $V .= "This login uses {$Protocol}, so passwords are transmitted in plain text. This is not a secure connection.<P />\n"; } $V .= "<form method='post'>\n"; $V .= "<input type='hidden' name='HTTP_REFERER' value='{$Referer}'>"; $V .= "<table border=0>"; $text = _("Username:"******"<tr><td>{$text}</td><td><input type='text' size=20 name='username' id='unamein'></td></tr>\n"; $text = _("Password:"******"<tr><td>{$text}</td><td><input type='password' size=20 name='password'></td></tr>\n"; $V .= "</table>"; $V .= "<P/>"; $V .= "<script type=\"text/javascript\">document.getElementById(\"unamein\").focus();</script>"; $text = _("Login"); $V .= "<input type='submit' value='{$text}'>\n"; $V .= "</form>\n"; } } else { $this->UpdateSess(""); $Uri = Traceback_uri(); $V .= "<script language='javascript'>\n"; $V .= "window.open('{$Uri}','_top');\n"; $V .= "</script>\n"; } break; case "Text": break; default: break; } if (!$this->OutputToStdout) { return $V; } print $V; return; }