Example #1
0
 /**
  * @todo without wrapper
  */
 function processUploadId($uploadId)
 {
     $groupId = $this->groupId;
     $args = $this->args;
     $this->additionalUploadIds = array_key_exists(self::UPLOAD_ADDS, $args) ? explode(',', $args[self::UPLOAD_ADDS]) : array();
     $uploadIds = $this->additionalUploadIds;
     array_unshift($uploadIds, $uploadId);
     $this->heartbeat(0);
     $licenseStmts = array();
     $copyrightStmts = array();
     foreach ($uploadIds as $addUploadId) {
         if (!$this->uploadDao->isAccessible($addUploadId, $groupId)) {
             continue;
         }
         $moreLicenses = $this->licenseClearedGetter->getCleared($addUploadId, $groupId);
         $licenseStmts = array_merge($licenseStmts, $moreLicenses['statements']);
         $this->heartbeat(count($moreLicenses['statements']));
         $moreCopyrights = $this->cpClearedGetter->getCleared($addUploadId, $groupId);
         $copyrightStmts = array_merge($copyrightStmts, $moreCopyrights['statements']);
         $this->heartbeat(count($moreCopyrights['statements']));
     }
     $contents = array('licenses' => $licenseStmts, 'copyrights' => $copyrightStmts);
     $this->writeReport($contents, $uploadId);
     return true;
 }
Example #2
0
 /**
  * 
  * @param int $uploadTreeId
  * @param Request $request
  * @return int $jobQueueId
  */
 private function getJobQueueId($uploadTreeId, Request $request)
 {
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId);
     $uploadId = intval($uploadEntry['upload_fk']);
     $userId = Auth::getUserId();
     $groupId = Auth::getGroupId();
     if ($uploadId <= 0 || !$this->uploadDao->isAccessible($uploadId, $groupId)) {
         throw new Exception('permission denied');
     }
     $bulkScope = $request->get('bulkScope');
     switch ($bulkScope) {
         case 'u':
             $uploadTreeTable = $this->uploadDao->getUploadtreeTableName($uploadId);
             $topBounds = $this->uploadDao->getParentItemBounds($uploadId, $uploadTreeTable);
             $uploadTreeId = $topBounds->getItemId();
             break;
         case 'f':
             if (!Isdir($uploadEntry['ufile_mode']) && !Iscontainer($uploadEntry['ufile_mode']) && !Isartifact($uploadEntry['ufile_mode'])) {
                 $uploadTreeId = $uploadEntry['parent'] ?: $uploadTreeId;
             }
             break;
         default:
             throw new InvalidArgumentException('bad scope request');
     }
     $refText = $request->get('refText');
     $actions = $request->get('bulkAction');
     $licenseRemovals = array();
     foreach ($actions as $licenseAction) {
         $licenseRemovals[$licenseAction['licenseId']] = $licenseAction['action'] == 'remove';
     }
     $bulkId = $this->licenseDao->insertBulkLicense($userId, $groupId, $uploadTreeId, $licenseRemovals, $refText);
     if ($bulkId <= 0) {
         throw new Exception('cannot insert bulk reference');
     }
     $upload = $this->uploadDao->getUpload($uploadId);
     $uploadName = $upload->getFilename();
     $job_pk = JobAddJob($userId, $groupId, $uploadName, $uploadId);
     /** @var DeciderJobAgentPlugin $deciderPlugin */
     $deciderPlugin = plugin_find("agent_deciderjob");
     $dependecies = array(array('name' => 'agent_monk_bulk', 'args' => $bulkId));
     $conflictStrategyId = intval($request->get('forceDecision'));
     $errorMsg = '';
     $jqId = $deciderPlugin->AgentAdd($job_pk, $uploadId, $errorMsg, $dependecies, $conflictStrategyId);
     if (!empty($errorMsg)) {
         throw new Exception(str_replace('<br>', "\n", $errorMsg));
     }
     return $jqId;
 }
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $upload = intval($request->get("upload"));
     $groupId = Auth::getGroupId();
     if (!$this->uploadDao->isAccessible($upload, $groupId)) {
         return $this->flushContent(_("Permission Denied"));
     }
     $item = intval($request->get("item"));
     $vars['baseuri'] = Traceback_uri();
     $vars['uploadId'] = $upload;
     $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload);
     if ($request->get('show') == 'quick') {
         $item = $this->uploadDao->getFatItemId($item, $upload, $this->uploadtree_tablename);
     }
     $vars['itemId'] = $item;
     $vars['micromenu'] = Dir2Browse($this->Name, $item, NULL, $showBox = 0, "Browse", -1, '', '', $this->uploadtree_tablename);
     $vars['licenseArray'] = $this->licenseDao->getLicenseArray();
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
     $left = $itemTreeBounds->getLeft();
     if (empty($left)) {
         return $this->flushContent(_("Job unpack/adj2nest hasn't completed."));
     }
     $histVars = $this->showUploadHist($itemTreeBounds);
     if (is_a($histVars, 'Symfony\\Component\\HttpFoundation\\RedirectResponse')) {
         return $histVars;
     }
     $vars = array_merge($vars, $histVars);
     $vars['content'] = js_url();
     return $this->render("browse.html.twig", $this->mergeWithDefault($vars));
 }
Example #4
0
 /**
  * @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));
 }
Example #5
0
 /**
  * \brief The Picker page
  */
 function Output()
 {
     global $PG_CONN;
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     /**
      * create table if it doesn't exist (not assuming Install() was run.
      * eg. source update
      */
     $this->Create_file_picker();
     $RtnMod = GetParm("rtnmod", PARM_TEXT);
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     if (!$uploadtree_pk) {
         return "<h2>Unidentified item 1</h2>";
     }
     $uploadtree_pk2 = GetParm("item2", PARM_INTEGER);
     $folder_pk = GetParm("folder", PARM_INTEGER);
     $user_pk = Auth::getUserId();
     /* Item to start Browse window on */
     $Browseuploadtree_pk = GetParm("bitem", PARM_INTEGER);
     /* Check item1 and item2 upload permissions */
     $Item1Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}");
     if (!$this->uploadDao->isAccessible($Item1Row['upload_fk'], Auth::getGroupId())) {
         $text = _("Permission Denied");
         return "<h2>{$text} item 1</h2>";
     }
     if (!empty($uploadtree_pk2)) {
         $Item2Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk2}");
         if (!$this->uploadDao->isAccessible($Item2Row['upload_fk'], Auth::getGroupId())) {
             $text = _("Permission Denied");
             return "<h2>{$text} item 2</h2>";
         }
     }
     /**
      * After picking an item2, this logic will record the pick in
      * the picker history, and then redirect both item1 and item2 to the
      * comparison app.
      */
     if (!empty($user_pk) && !empty($RtnMod) && !empty($uploadtree_pk) && !empty($uploadtree_pk2)) {
         $sql = "insert into file_picker (user_fk, uploadtree_fk1, uploadtree_fk2, last_access_date)\n             values({$user_pk}, {$uploadtree_pk}, {$uploadtree_pk2}, now())";
         // ignore errors (most probably a duplicate key)
         @($result = pg_query($PG_CONN, $sql));
         // Redirect to diff module
         $uri = Traceback_uri() . "?mod={$RtnMod}&item1={$uploadtree_pk}&item2={$uploadtree_pk2}";
         echo "<script type='text/javascript'> window.location.assign('{$uri}');</script>";
         exit;
     }
     $OutBuf = "";
     if ($this->OutputType == 'HTML') {
         if (empty($uploadtree_pk)) {
             $OutBuf = "<h2>Picker URL is missing the first comparison file.</h2>";
         } else {
             $PathArray = Dir2Path($uploadtree_pk, 'uploadtree');
             $OutBuf .= $this->HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
         }
     }
     return $OutBuf;
 }
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $upload = intval($request->get("upload"));
     $groupId = Auth::getGroupId();
     if (!$this->uploadDao->isAccessible($upload, $groupId)) {
         throw new \Exception("Permission Denied");
     }
     $item = intval($request->get("item"));
     $this->uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($upload);
     $itemTreeBounds = $this->uploadDao->getItemTreeBounds($item, $this->uploadtree_tablename);
     $left = $itemTreeBounds->getLeft();
     if (empty($left)) {
         throw new \Exception("Job unpack/adj2nest hasn't completed.");
     }
     $scannerAgents = array_keys($this->agentNames);
     $scanJobProxy = new ScanJobProxy($this->agentDao, $upload);
     $scanJobProxy->createAgentStatus($scannerAgents);
     $selectedAgentId = intval($request->get('agentId'));
     $tag_pk = intval($request->get('tag'));
     $UniqueTagArray = array();
     $this->licenseProjector = new LicenseMap($this->getObject('db.manager'), $groupId, LicenseMap::CONCLUSION, true);
     $vars = $this->createFileListing($tag_pk, $itemTreeBounds, $UniqueTagArray, $selectedAgentId, $groupId, $scanJobProxy);
     return new JsonResponse(array('sEcho' => intval($request->get('sEcho')), 'aaData' => $vars['fileData'], 'iTotalRecords' => intval($request->get('totalRecords')), 'iTotalDisplayRecords' => $vars['iTotalDisplayRecords']));
 }
Example #7
0
 /**
  * @param int $uploadTreeId
  * @param int $Folder
  * @param int $Upload
  * @return string
  */
 function outputItemHtml($uploadTreeId, $Folder, $Upload)
 {
     global $container;
     $dbManager = $container->get('db.manager');
     $show = 'quick';
     $html = '';
     $uploadtree_tablename = "";
     if (!empty($uploadTreeId)) {
         $sql = "SELECT ufile_mode, upload_fk FROM uploadtree WHERE uploadtree_pk = \$1";
         $row = $dbManager->getSingleRow($sql, array($uploadTreeId));
         $Upload = $row['upload_fk'];
         if (!$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
             $this->vars['message'] = _("Permission Denied");
             return $this->render('include/base.html.twig');
         }
         if (!Iscontainer($row['ufile_mode'])) {
             global $Plugins;
             $View =& $Plugins[plugin_find_id("view")];
             if (!empty($View)) {
                 $this->vars['content'] = $View->ShowView(NULL, "browse");
                 return $this->render('include/base.html.twig');
             }
         }
         $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($row['upload_fk']);
         $html .= Dir2Browse($this->Name, $uploadTreeId, NULL, 1, "Browse", -1, '', '', $uploadtree_tablename) . "\n";
     } else {
         if (!empty($Upload)) {
             $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
             $html .= Dir2BrowseUpload($this->Name, $Upload, NULL, 1, "Browse", $uploadtree_tablename) . "\n";
         }
     }
     if (empty($Upload)) {
         $this->vars['show'] = $show;
         $this->ShowFolder($Folder);
         return $html;
     }
     if (empty($uploadTreeId)) {
         try {
             $uploadTreeId = $this->uploadDao->getUploadParent($Upload);
         } catch (Exception $e) {
             $this->vars['message'] = $e->getMessage();
             return $this->render('include/base.html.twig');
         }
     }
     $html .= $this->ShowItem($Upload, $uploadTreeId, $show, $Folder, $uploadtree_tablename);
     $this->vars['content'] = $html;
     return $this->render('include/base.html.twig');
 }
Example #8
0
 public function Output()
 {
     $uploadId = GetParm("upload", PARM_INTEGER);
     if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
         return;
     }
     $itemId = GetParm("item", PARM_INTEGER);
     $this->vars['micromenu'] = Dir2Browse("browse", $itemId, NULL, $showBox = 0, "View-Meta");
     $V = "";
     $V .= $this->ShowTagInfo($uploadId, $itemId);
     $V .= $this->ShowPackageinfo($uploadId, $itemId, 1);
     $V .= $this->ShowMetaView($uploadId, $itemId);
     $V .= $this->ShowSightings($uploadId, $itemId);
     $V .= $this->ShowView($uploadId, $itemId);
     return $V;
 }
Example #9
0
 /**
  * @brief Find all of my jobs submitted within the last n hours.
  *
  * @param $allusers
  *
  * @return array of job_pk's 
  **/
 public function myJobs($allusers)
 {
     $jobArray = array();
     $allusers_str = $allusers == 0 ? "job_user_fk='" . Auth::getUserId() . "' and " : ($allusers_str = "");
     $statementName = __METHOD__ . "{$allusers_str}";
     $this->dbManager->prepare($statementName, "SELECT job_pk, job_upload_fk FROM job WHERE {$allusers_str} job_queued >= (now() - interval '" . $this->nhours . " hours') ORDER BY job_queued DESC");
     $result = $this->dbManager->execute($statementName);
     while ($row = $this->dbManager->fetchArray($result)) {
         if (!empty($row['job_upload_fk'])) {
             $uploadIsAccessible = $this->uploadDao->isAccessible($row['job_upload_fk'], Auth::getGroupId());
             if (!$uploadIsAccessible) {
                 continue;
             }
         }
         $jobArray[] = $row['job_pk'];
     }
     $this->dbManager->freeResult($result);
     return $jobArray;
 }
Example #10
0
 /**
  * \brief Given a filename, return all uploadtree.
  * \param $Item     uploadtree_pk of tree to search, if empty, do global search
  * \param $Filename filename or pattern to search for, false if unused
  * \param $tag      tag (or tag pattern mytag%) to search for, false if unused
  * \param $Page     display page number
  * \param $SizeMin  Minimum file size, -1 if unused
  * \param $SizeMax  Maximum file size, -1 if unused
  * \param $searchtype "containers" or "allfiles"
  * \return array of uploadtree recs.  Each record contains uploadtree_pk, parent, 
  *         upload_fk, pfile_fk, ufile_mode, and ufile_name
  */
 function GetResults($Item, $Filename, $tag, $Page, $SizeMin, $SizeMax, $searchtype, $License, $Copyright)
 {
     global $PG_CONN;
     $UploadtreeRecs = array();
     // uploadtree record array to return
     $NeedTagfileTable = true;
     $NeedTaguploadtreeTable = true;
     if ($Item) {
         /* Find lft and rgt bounds for this $Uploadtree_pk  */
         $row = $this->uploadDao->getUploadEntry($Item);
         if (empty($row)) {
             $text = _("Invalid URL, nonexistant item");
             return "<h2>{$text} {$Item}</h2>";
         }
         $lft = $row["lft"];
         $rgt = $row["rgt"];
         $upload_pk = $row["upload_fk"];
         /* Check upload permission */
         if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
             return $UploadtreeRecs;
         }
     }
     /* Start the result select stmt */
     $SQL = "SELECT DISTINCT uploadtree_pk, parent, upload_fk, uploadtree.pfile_fk, ufile_mode, ufile_name FROM uploadtree";
     if (!empty($License)) {
         $SQL .= ", ( SELECT license_ref.rf_shortname, license_file.rf_fk, license_file.pfile_fk\n                  FROM license_file JOIN license_ref ON license_file.rf_fk = license_ref.rf_pk) AS pfile_ref";
     }
     if (!empty($Copyright)) {
         $SQL .= ",copyright";
     }
     /* Figure out the tag_pk's of interest */
     if (!empty($tag)) {
         $sql = "select tag_pk from tag where tag ilike '{$tag}'";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         if (pg_num_rows($result) < 1) {
             /* tag doesn't match anything, so no results are possible */
             pg_free_result($result);
             return $UploadtreeRecs;
         }
         /* Make a list of the tag_pk's that satisfy the criteria */
         $tag_pk_array = pg_fetch_all($result);
         pg_free_result($result);
         /* add the tables needed for the tag query */
         $sql = "select tag_file_pk from tag_file limit 1";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         if (pg_num_rows($result) < 1) {
             /* tag_file didn't have data, don't add the tag_file table for tag query */
             $NeedTagfileTable = false;
         } else {
             $SQL .= ", tag_file";
         }
         pg_free_result($result);
         /* add the tables needed for the tag query */
         $sql = "select tag_uploadtree_pk from tag_uploadtree limit 1";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         if (pg_num_rows($result) < 1) {
             /* tag_uploadtree didn't have data, don't add the tag_uploadtree table for tag query */
             $NeedTaguploadtreeTable = false;
         } else {
             $SQL .= ", tag_uploadtree";
         }
         pg_free_result($result);
         if (!$NeedTagfileTable && !$NeedTaguploadtreeTable) {
             $SQL .= ", tag_file, tag_uploadtree";
         }
     }
     /* do we need the pfile table? Yes, if any of these are a search critieria.  */
     if (!empty($SizeMin) or !empty($SizeMax)) {
         $SQL .= ", pfile where pfile_pk=uploadtree.pfile_fk ";
         $NeedAnd = true;
     } else {
         $SQL .= " where ";
         $NeedAnd = false;
     }
     /* add the tag conditions */
     if (!empty($tag)) {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= "(";
         $NeedOr = false;
         foreach ($tag_pk_array as $tagRec) {
             if ($NeedOr) {
                 $SQL .= " OR";
             }
             $SQL .= "(";
             $tag_pk = $tagRec['tag_pk'];
             if ($NeedTagfileTable && $NeedTaguploadtreeTable) {
                 $SQL .= "(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk={$tag_pk}) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk={$tag_pk}) ";
             } else {
                 if ($NeedTaguploadtreeTable) {
                     $SQL .= "uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk={$tag_pk}";
                 } else {
                     if ($NeedTagfileTable) {
                         $SQL .= "uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk={$tag_pk}";
                     } else {
                         $SQL .= "(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk={$tag_pk}) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk={$tag_pk}) ";
                     }
                 }
             }
             $SQL .= ")";
             $NeedOr = 1;
         }
         $NeedAnd = 1;
         $SQL .= ")";
     }
     if ($Filename) {
         $Filename = str_replace("'", "''", $Filename);
         // protect DB
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= " ufile_name ilike '{$Filename}'";
         $NeedAnd = 1;
     }
     if (!empty($SizeMin)) {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= " pfile.pfile_size >= {$SizeMin}";
         $NeedAnd = 1;
     }
     if (!empty($SizeMax)) {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= " pfile.pfile_size <= {$SizeMax}";
         $NeedAnd = 1;
     }
     if ($Item) {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= "  upload_fk = {$upload_pk} AND lft >= {$lft} AND rgt <= {$rgt}";
         $NeedAnd = 1;
     }
     /* search only containers */
     $dir_ufile_mode = 536888320;
     if ($searchtype == 'containers') {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= " ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)";
         $NeedAnd = 1;
     }
     if ($searchtype == 'directory') {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= " ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0) AND (ufile_mode != {$dir_ufile_mode}) and pfile_fk != 0";
         $NeedAnd = 1;
     }
     /** license and copyright */
     if (!empty($License)) {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= " uploadtree.pfile_fk=pfile_ref.pfile_fk and pfile_ref.rf_shortname ilike '{$License}'";
         $NeedAnd = 1;
     }
     if (!empty($Copyright)) {
         if ($NeedAnd) {
             $SQL .= " AND";
         }
         $SQL .= " uploadtree.pfile_fk=copyright.pfile_fk and copyright.content ilike '%{$Copyright}%'";
     }
     $Offset = $Page * $this->MaxPerPage;
     $SQL .= " ORDER BY ufile_name, uploadtree.pfile_fk";
     $SQL .= " LIMIT {$this->MaxPerPage} OFFSET {$Offset};";
     $result = pg_query($PG_CONN, $SQL);
     DBCheckResult($result, $SQL, __FILE__, __LINE__);
     if (pg_num_rows($result)) {
         while ($row = pg_fetch_assoc($result)) {
             if (!$this->uploadDao->isAccessible($row['upload_fk'], Auth::getGroupId())) {
                 continue;
             }
             $UploadtreeRecs[] = $row;
         }
     }
     pg_free_result($result);
     return $UploadtreeRecs;
 }
Example #11
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;
 }
Example #12
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>';
     }
 }
Example #13
0
 /**
  * \brief Generate the view contents in HTML
  *
  * @param resource $inputFile
  * @param string $BackMod
  * @param int $ShowMenu
  * @param int $ShowHeader
  * @param null $ShowText
  * @param bool $ViewOnly
  * @param bool $DispView
  * @param Highlight[] $highlightEntries
  * @param bool $insertBacklink
  *
  * \note This function is intended to be called from other plugins.
  */
 function getView($inputFile = NULL, $BackMod = "browse", $ShowHeader = 1, $ShowText = NULL, $highlightEntries = array(), $insertBacklink = false, $getPageMenuInline = false)
 {
     if ($this->State != PLUGIN_STATE_READY) {
         $output = "Invalid plugin state: " . $this->State;
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $Upload = GetParm("upload", PARM_INTEGER);
     if (!empty($Upload) && !$this->uploadDao->isAccessible($Upload, Auth::getGroupId())) {
         $output = "Access denied";
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $Item = GetParm("item", PARM_INTEGER);
     $Page = GetParm("page", PARM_INTEGER);
     $licenseId = GetParm("licenseId", PARM_INTEGER);
     if (!$inputFile && empty($Item)) {
         $output = "invalid input file";
         return $getPageMenuInline ? array("Error", $output) : $output;
     }
     $uploadtree_tablename = $this->uploadDao->getUploadtreeTableName($Upload);
     if ($ShowHeader) {
         $Uri = Traceback_uri() . "?mod=browse" . Traceback_parm_keep(array('item', 'show', 'folder', 'upload'));
         /* No item */
         $header = Dir2Browse($BackMod, $Item, NULL, $showBox = 0, "View", -1, '', '', $uploadtree_tablename);
         $this->vars['micromenu'] = $header;
     }
     /* Display file contents */
     $output = "";
     $openedFin = False;
     $Format = $this->microMenu->getFormatParameter($Item);
     if (empty($inputFile)) {
         $inputFile = @fopen(RepPathItem($Item), "rb");
         if ($inputFile) {
             $openedFin = true;
         }
         if (empty($inputFile)) {
             $output = $this->outputWhenFileNotInRepo($Upload, $Item);
             return $getPageMenuInline ? array("Error", $output) : $output;
         }
     }
     rewind($inputFile);
     $Uri = preg_replace('/&page=[0-9]*/', '', Traceback());
     $blockSize = $Format == 'hex' ? $this->blockSizeHex : $this->blockSizeText;
     if (!isset($Page) && !empty($licenseId)) {
         $startPos = -1;
         foreach ($highlightEntries as $highlightEntry) {
             if ($highlightEntry->getLicenseId() == $licenseId && ($startPos == -1 || $startPos > $highlightEntry->getStart())) {
                 $startPos = $highlightEntry->getStart();
             }
         }
         if ($startPos != -1) {
             $Page = floor($startPos / $blockSize);
         }
     }
     if (!empty($ShowText)) {
         echo $ShowText, "<hr>";
     }
     $PageMenu = $this->GetFileJumpMenu($inputFile, $Page, $blockSize, $Uri);
     $PageSize = $blockSize * $Page;
     if (!empty($PageMenu) and !$getPageMenuInline) {
         $output .= "<center>{$PageMenu}</center><br>\n";
     }
     $startAt = $PageSize;
     $endAt = $PageSize + $blockSize;
     $relevantHighlightEntries = array();
     foreach ($highlightEntries as $highlightEntry) {
         if ($highlightEntry->getStart() < $endAt && $highlightEntry->getEnd() >= $startAt) {
             $relevantHighlightEntries[] = $highlightEntry;
         }
     }
     $this->highlightProcessor->sortHighlights($relevantHighlightEntries);
     $splitPositions = $this->highlightProcessor->calculateSplitPositions($relevantHighlightEntries);
     if ($Format == 'hex') {
         $output .= $this->getHex($inputFile, $PageSize, $this->blockSizeHex, $splitPositions);
     } else {
         $output .= $this->getText($inputFile, $PageSize, $Format == 'text' ? 0 : 1, $this->blockSizeText, $splitPositions, $insertBacklink);
     }
     if (!empty($PageMenu) and !$getPageMenuInline) {
         $output .= "<P /><center>{$PageMenu}</center><br>\n";
     }
     if ($openedFin) {
         fclose($inputFile);
     }
     return $getPageMenuInline ? array($PageMenu, $output) : $output;
 }
Example #14
0
 protected function handle(Request $request)
 {
     $vars = array();
     $uploadId = intval($request->get('upload'));
     $uploadTreeId = intval($request->get('item'));
     if (empty($uploadTreeId) || empty($uploadId)) {
         $text = _("Empty Input");
         $vars['message'] = "<h2>{$text}</h2>";
         return $this->responseBad($vars);
     }
     if (!$this->uploadDao->isAccessible($uploadId, Auth::getGroupId())) {
         $text = _("Permission Denied");
         $vars['message'] = "<h2>{$text}</h2>";
         return $this->responseBad();
     }
     $uploadTreeTableName = $this->uploadDao->getUploadtreeTableName($uploadId);
     $uploadEntry = $this->uploadDao->getUploadEntry($uploadTreeId, $uploadTreeTableName);
     if (Isdir($uploadEntry['ufile_mode']) || Iscontainer($uploadEntry['ufile_mode'])) {
         $parent = $this->uploadDao->getUploadParent($uploadEntry['upload_fk']);
         if (!isset($parent)) {
             return $this->responseBad();
         }
         $uploadTree = $this->uploadDao->getNextItem($uploadEntry['upload_fk'], $parent);
         if ($uploadTree === UploadDao::NOT_FOUND) {
             return $this->responseBad();
         }
         $uploadTreeId = $uploadTree->getId();
         return new RedirectResponse(Traceback_uri() . '?mod=' . $this->getName() . Traceback_parm_keep(array('show', 'upload')) . "&item={$uploadTreeId}");
     }
     if (empty($uploadTreeId)) {
         return $this->responseBad('No item selected.');
     }
     $copyrightDecisionMap = $this->decisionTypes->getMap();
     $vars['micromenu'] = Dir2Browse($this->modBack, $uploadTreeId, NULL, $showBox = 0, "View", -1, '', '', $uploadTreeTableName);
     $lastItem = GetParm("lastItem", PARM_INTEGER);
     $changed = GetParm("changedSomething", PARM_STRING);
     $userId = Auth::getUserId();
     if (!empty($lastItem) && $changed == "true") {
         $lastUploadEntry = $this->uploadDao->getUploadEntry($lastItem, $uploadTreeTableName);
         $clearingType = $_POST['clearingTypes'];
         $description = $_POST['description'];
         $textFinding = $_POST['textFinding'];
         $comment = $_POST['comment'];
         $this->copyrightDao->saveDecision($this->decisionTableName, $lastUploadEntry['pfile_fk'], $userId, $clearingType, $description, $textFinding, $comment);
     }
     $scanJobProxy = new ScanJobProxy($this->agentDao, $uploadId);
     $scanJobProxy->createAgentStatus(array($this->agentName));
     $selectedScanners = $scanJobProxy->getLatestSuccessfulAgentIds();
     $highlights = array();
     if (array_key_exists($this->agentName, $selectedScanners)) {
         $latestXpAgentId = $selectedScanners[$this->agentName];
         $highlights = $this->copyrightDao->getHighlights($uploadTreeId, $this->tableName, $latestXpAgentId, $this->typeToHighlightTypeMap);
     }
     if (count($highlights) < 1) {
         $vars['message'] = _("No ") . $this->tableName . _(" data is available for this file.");
     }
     /* @var $view ui_view */
     $view = plugin_find("view");
     $theView = $view->getView(null, null, $showHeader = 0, "", $highlights, false, true);
     list($pageMenu, $textView) = $theView;
     list($description, $textFinding, $comment, $decisionType) = $this->copyrightDao->getDecision($this->decisionTableName, $uploadEntry['pfile_fk']);
     $vars['description'] = $description;
     $vars['textFinding'] = $textFinding;
     $vars['comment'] = $comment;
     $vars['itemId'] = $uploadTreeId;
     $vars['uploadId'] = $uploadId;
     $vars['pageMenu'] = $pageMenu;
     $vars['textView'] = $textView;
     $vars['legendBox'] = $this->legendBox();
     $vars['uri'] = Traceback_uri() . "?mod=" . $this->Name;
     $vars['optionName'] = $this->optionName;
     $vars['formName'] = "CopyRightForm";
     $vars['ajaxAction'] = $this->ajaxAction;
     $vars['skipOption'] = $this->skipOption;
     $vars['selectedClearingType'] = $decisionType;
     $vars['clearingTypes'] = $copyrightDecisionMap;
     $vars['xptext'] = $this->xptext;
     $agentId = intval($request->get("agent"));
     $vars = array_merge($vars, $this->additionalVars($uploadId, $uploadTreeId, $agentId));
     return $this->render('ui-cp-view.html.twig', $this->mergeWithDefault($vars));
 }
Example #15
0
 /**
  * \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;
     }
     if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
         $text = _("Permission Denied");
         return "<h2>{$text}</h2>";
     }
     $dltext = GetParm("output", PARM_STRING) == 'dltext';
     /* 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) {
         return _("No data available");
     }
     /* how many lines of data do you want to display */
     $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
     /* get the top of tree */
     $toprow = $this->uploadDao->getUploadEntry($uploadtree_pk);
     /* 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 & (3<<28)) = 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
      */
     $uploadtreeTablename = $this->uploadDao->getUploadtreeTableName($toprow['upload_fk']);
     $lines = array();
     while ($row = pg_fetch_assoc($outerresult)) {
         $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtreeTablename);
         $filepath = "";
         foreach ($filepatharray as $uploadtreeRow) {
             if (!empty($filepath)) {
                 $filepath .= "/";
             }
             $filepath .= $uploadtreeRow['ufile_name'];
         }
         $lines[] = $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtreeTablename);
     }
     $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 ($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>';
     }
 }