/** * @param Request $request * @return JsonResponse */ protected function respondFolderGetTableData(Request $request) { /* Get list of uploads in this folder */ list($result, $iTotalDisplayRecords, $iTotalRecords) = $this->getListOfUploadsOfFolder($request); $uri = Traceback_uri() . "?mod=license"; /* Browse-Pfile menu */ $menuPfile = menu_find("Browse-Pfile", $menuDepth); /* Browse-Pfile menu without the compare menu item */ $menuPfileNoCompare = menu_remove($menuPfile, "Compare"); $users = $this->userDao->getUserChoices(); $statusTypesAvailable = $this->uploadDao->getStatusTypeMap(); if (!$this->userPerm) { unset($statusTypesAvailable[4]); } $output = array(); $rowCounter = 0; while ($row = $this->dbManager->fetchArray($result)) { if (empty($row['upload_pk']) || !$this->uploadDao->isAccessible($row['upload_pk'], Auth::getGroupId())) { continue; } $rowCounter++; $output[] = $this->showRow($row, $request, $uri, $menuPfile, $menuPfileNoCompare, $statusTypesAvailable, $users, $rowCounter); } $this->dbManager->freeResult($result); return new JsonResponse(array('sEcho' => intval($request->get('sEcho')), 'aaData' => $output, 'iTotalRecords' => $iTotalRecords, 'iTotalDisplayRecords' => $iTotalDisplayRecords)); }
public function testAddGroupMembership() { $this->testDb->createPlainTables(array('users', 'groups', 'group_user_member')); $this->testDb->insertData(array('users', 'groups', 'group_user_member')); $this->userDao->addGroupMembership($groupId = 2, $userId = 1); $map = $this->userDao->getUserGroupMap($userId); assertThat($map, hasKey($groupId)); }
public function getFolderStructure($parentId = null) { $statementName = __METHOD__ . ($parentId ? '.relativeToParent' : ''); $parameters = $parentId ? array($parentId) : array(); $this->dbManager->prepare($statementName, $this->getFolderTreeCte($parentId) . " SELECT folder_pk, parent_fk, folder_name, folder_desc, folder_perm, depth FROM folder_tree ORDER BY name_path"); $res = $this->dbManager->execute($statementName, $parameters); $userGroupMap = $this->userDao->getUserGroupMap(Auth::getUserId()); $results = array(); while ($row = $this->dbManager->fetchArray($res)) { $countUploads = $this->countFolderUploads(intval($row['folder_pk']), $userGroupMap); $results[] = array(self::FOLDER_KEY => new Folder(intval($row['folder_pk']), $row['folder_name'], $row['folder_desc'], intval($row['folder_perm'])), self::DEPTH_KEY => $row['depth'], self::REUSE_KEY => $countUploads); } $this->dbManager->freeResult($res); return $results; }
/** * \brief See if a username/password is valid. * * @return boolean */ function checkUsernameAndPassword($userName, $password) { if (empty($userName) || $userName == 'Default User') { return false; } try { $row = $this->userDao->getUserAndDefaultGroupByUserName($userName); } catch (Exception $e) { return false; } if (empty($row['user_name'])) { return false; } /* Check the password -- only if a password exists */ if (!empty($row['user_seed']) && !empty($row['user_pass'])) { $passwordHash = sha1($row['user_seed'] . $password); if (strcmp($passwordHash, $row['user_pass']) != 0) { return false; } } else { if (!empty($row['user_seed'])) { /* Seed with no password hash = no login */ return false; } else { if (!empty($password)) { /* empty password required */ return false; } } } /* If you make it here, then username and password were good! */ $this->updateSession($row); $_SESSION['time_check'] = time() + 480 * 60; /* No specified permission means ALL permission */ if ("X" . $row['user_perm'] == "X") { $_SESSION[Auth::USER_LEVEL] = PLUGIN_DB_ADMIN; } else { $_SESSION[Auth::USER_LEVEL] = $row['user_perm']; } $_SESSION['checkip'] = GetParm("checkip", PARM_STRING); /* Check for the no-popup flag */ if (GetParm("nopopup", PARM_INTEGER) == 1) { $_SESSION['NoPopup'] = 1; } else { $_SESSION['NoPopup'] = 0; } return true; }
/** * @brief Returns geeky scan details about the jobqueue item * @param $job_pk * @return Return job and jobqueue record data in an html table. **/ protected function showJobDB($job_pk) { global $container; /** @var DbManager */ $dbManager = $container->get('db.manager'); $i = 0; $fields = array('jq_pk' => 'jq_pk', 'job_pk' => 'jq_job_fk', 'Job Name' => 'job_name', 'Agent Name' => 'jq_type', 'Priority' => 'job_priority', 'Args' => 'jq_args', 'jq_runonpfile' => 'jq_runonpfile', 'Queued' => 'job_queued', 'Started' => 'jq_starttime', 'Ended' => 'jq_endtime', 'Elapsed HH:MM:SS' => 'elapsed', 'Status' => 'jq_end_bits', 'Items processed' => 'jq_itemsprocessed', 'Submitter' => 'job_user_fk', 'Upload' => 'job_upload_fk', 'Log' => 'jq_log'); $uri = Traceback_uri() . "?mod=showjobs&upload="; $statementName = __METHOD__ . "ShowJobDBforjob"; $dbManager->prepare($statementName, "SELECT *, jq_endtime-jq_starttime as elapsed FROM jobqueue LEFT JOIN job ON job.job_pk = jobqueue.jq_job_fk WHERE jobqueue.jq_pk =\$1"); $result = $dbManager->execute($statementName, array($job_pk)); $row = $dbManager->fetchArray($result); $dbManager->freeResult($result); $table = array(); foreach ($fields as $labelKey => $field) { $value = ""; $label = $labelKey; switch ($field) { case 'jq_itemsprocessed': $value = number_format($row[$field]); break; case 'jq_end_bits': $value = $this->jobqueueStatus($row); break; case 'jq_pk': if (!empty($row['job_upload_fk'])) { $value = "<a href='{$uri}" . $row['job_upload_fk'] . "'>" . htmlentities($row[$field]) . "</a>" . " (" . _("Click to view jobs for this upload") . ")"; } else { $uri2 = Traceback_uri() . "?mod=showjobs"; $back = "(" . _("Click to return to Show Jobs") . ")"; $value = "<a href='{$uri2}'>{$row[$field]} {$back}</a>"; } break; case 'job_upload_fk': if (!empty($row[$field])) { $browse = Traceback_uri() . "?mod=browse&upload=" . htmlentities($row[$field]); $value = "<a href='{$browse}'>" . htmlentities($row[$field]) . "</a>" . " (" . _("Click to browse upload") . ")"; } break; case 'jq_log': if (empty($row[$field]) || !file_exists($row[$field])) { break; } if (filesize($row[$field]) > self::MAX_LOG_OUTPUT) { $value = "<pre>" . file_get_contents($row[$field], false, null, -1, self::MAX_LOG_OUTPUT) . "</pre>" . '<a href="' . Traceback_uri() . '?mod=download&log=' . $row['jq_pk'] . '">...</a>'; } else { $value = "<pre>" . file_get_contents($row[$field]) . "</pre>"; } break; case 'job_user_fk': if (!empty($row[$field])) { $value = $this->userDao->getUserName($row[$field]); } break; case 'jq_args': $jq_args_temp = $row[$field]; $jq_args_show = $jq_args_temp; if (!empty($jq_args_temp)) { $pos = strpos($jq_args_temp, ' SVN '); if ($pos) { $jq_args_show = substr($jq_args_temp, 0, $pos + 4); } $pos = strpos($jq_args_temp, ' CVS '); if ($pos) { $jq_args_show = substr($jq_args_temp, 0, $pos + 4); } $pos = strpos($jq_args_temp, ' Git '); if ($pos) { $jq_args_show = substr($jq_args_temp, 0, $pos + 4); } $value = $jq_args_show; } break; default: if (array_key_exists($field, $row)) { $value = htmlentities($row[$field]); } break; } $table[] = array('DT_RowId' => $i++, '0' => $label, '1' => $value); } $tableData = array_values($table); return new JsonResponse(array('sEcho' => intval($_GET['sEcho']), 'aaData' => $tableData, 'iTotalRecords' => count($tableData), 'iTotalDisplayRecords' => count($tableData))); }
/** * @brief Returns an upload job status in html * @param $jobData, $page, $allusers * @return Returns an upload job status in html **/ protected function getShowJobsForEachJob($jobData, $page, $allusers) { $outBuf = ''; $pagination = ''; $uploadtree_pk = 0; $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 */ /*****************************************************************/ $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 = ""; if ($allusers > 0) { $statementName = __METHOD__ . "UploadRec"; $uploadRec = $this->dbManager->getSingleRow("select user_fk from upload where upload_pk=\$1", array($job['job']['job_upload_fk']), $statementName); if (!empty($uploadRec['user_fk'])) { $userName = $this->userDao->getUserName($uploadRec['user_fk']); } else { $userName = $this->userDao->getUserName($job['job']['job_user_fk']); } $userName = "******" . htmlentities($userName, ENT_QUOTES) . ")"; } $outBuf .= htmlentities($uploadName, ENT_QUOTES) . $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'], 'page' => $page, 'allusers' => $allusers); 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); }