Ejemplo n.º 1
0
 public function Output()
 {
     $V = "";
     /* If this is a POST, then process the request. */
     $groupname = GetParm('groupname', PARM_TEXT);
     if (!empty($groupname)) {
         try {
             /* @var $userDao UserDao */
             $userDao = $GLOBALS['container']->get('dao.user');
             $groupId = $userDao->addGroup($groupname);
             $userDao->addGroupMembership($groupId, Auth::getUserId());
             $text = _("Group");
             $text1 = _("added");
             $this->vars['message'] = "{$text} {$groupname} {$text1}.";
         } catch (Exception $e) {
             $this->vars['message'] = $e->getMessage();
         }
     }
     /* Build HTML form */
     $text = _("Add a Group");
     $V .= "<h4>{$text}</h4>\n";
     $V .= "<form name='formy' method='POST' action=" . Traceback_uri() . "?mod=group_add>\n";
     $Val = htmlentities(GetParm('groupname', PARM_TEXT), ENT_QUOTES);
     $text = _("Enter the groupname:");
     $V .= "{$text}\n";
     $V .= "<input type='text' value='{$Val}' name='groupname' size=20>\n";
     $text = _("Add");
     $V .= "<input type='submit' value='{$text}'>\n";
     $V .= "</form>\n";
     return $V;
 }
Ejemplo n.º 2
0
 /**
  * @brief Allow user to change their account settings (users db table).  
  *        If the user is an Admin, they can change settings for any user.\n
  *        This is called in the following circumstances:\n
  *        1) User clicks on Admin > Edit User Account\n
  *        2) User has chosen a user to edit from the 'userid' select list  \n
  *        3) User hit submit to update user data\n
  */
 protected function handle(Request $request)
 {
     /* Is the session owner an admin?  */
     $user_pk = Auth::getUserId();
     $SessionUserRec = $this->GetUserRec($user_pk);
     $SessionIsAdmin = $this->IsSessionAdmin($SessionUserRec);
     $user_pk_to_modify = intval($request->get('user_pk'));
     if (!($SessionIsAdmin or empty($user_pk_to_modify) or $user_pk == $user_pk_to_modify)) {
         $vars['content'] = _("Your request is not valid.");
         return $this->render('include/base.html.twig', $this->mergeWithDefault($vars));
     }
     $vars = array('refreshUri' => Traceback_uri() . "?mod=" . self::NAME);
     /* If this is a POST (the submit button was clicked), then process the request. */
     $BtnText = $request->get('UpdateBtn');
     if (!empty($BtnText)) {
         /* Get the form data to in an associated array */
         $UserRec = $this->CreateUserRec($request, "");
         $rv = $this->UpdateUser($UserRec, $SessionIsAdmin);
         if (empty($rv)) {
             // Successful db update
             $vars['message'] = "User {$UserRec['user_name']} updated.";
             /* Reread the user record as update verification */
             $UserRec = $this->CreateUserRec($request, $UserRec['user_pk']);
         } else {
             $vars['message'] = $rv;
         }
     } else {
         $NewUserpk = intval($request->get('newuser'));
         $UserRec = empty($NewUserpk) ? $this->CreateUserRec($request, $user_pk) : $this->CreateUserRec($request, $NewUserpk);
     }
     /* display the edit form with the requested user data */
     $vars = array_merge($vars, $this->DisplayForm($UserRec, $SessionIsAdmin));
     $vars['userId'] = $UserRec['user_pk'];
     return $this->render('user_edit.html.twig', $this->mergeWithDefault($vars));
 }
Ejemplo n.º 3
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $vars['URI'] = Traceback_uri();
     $this->renderer->clearTemplateCache();
     $this->renderer->clearCacheFiles();
     return $this->render('upload_instructions.html.twig', $this->mergeWithDefault($vars));
 }
Ejemplo n.º 4
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $userId = Auth::getUserId();
     $vars = array();
     /** @var UserDao $userDao */
     $userDao = $this->getObject('dao.user');
     $groupMap = $userDao->getDeletableAdminGroupMap($userId, $_SESSION[Auth::USER_LEVEL]);
     $groupId = $request->get('grouppk');
     if (!empty($groupId)) {
         try {
             $userDao->deleteGroup($groupId);
             $vars['message'] = _("Group") . ' ' . $groupMap[$groupId] . ' ' . _("deleted") . '.';
             unset($groupMap[$groupId]);
         } catch (\Exception $e) {
             $vars['message'] = $e->getMessage();
         }
     }
     if (empty($groupMap)) {
         $vars['content'] = _("You have no groups you can delete.");
         return $this->render('include/base.html.twig', $this->mergeWithDefault($vars));
     }
     $vars['groupMap'] = $groupMap;
     $vars['uri'] = Traceback_uri() . "?mod=group_delete";
     $vars['groupMap'] = $groupMap;
     return $this->render('admin_group_delete.html.twig', $this->mergeWithDefault($vars));
 }
Ejemplo n.º 5
0
 /**
  * \brief Generate the text for this plugin.
  */
 function Output()
 {
     global $PG_CONN;
     global $SysConf;
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $user_pk = $SysConf['auth']['UserId'];
     /* Get array of groups that this user is an admin of */
     $GroupArray = GetGroupArray($user_pk);
     $V = "";
     /* If this is a POST, then process the request. */
     $Group = GetParm('grouppk', PARM_TEXT);
     if (!empty($Group)) {
         $rc = DeleteGroup($Group);
         if (empty($rc)) {
             /* Need to refresh the screen */
             $text = _("Group");
             $text1 = _("Deleted");
             $V .= displayMessage("{$text} {$GroupArray[$Group]} {$text1}.");
         } else {
             $V .= displayMessage($rc);
         }
     }
     /* Build HTML form */
     $text = _("Delete a Group");
     $V .= "<h4>{$text}</h4>\n";
     $V .= "<form name='formy' method='POST' action=" . Traceback_uri() . "?mod=group_delete>\n";
     /* Get array of users */
     $UserArray = Table2Array('user_pk', 'user_name', 'users');
     /* Remove from $GroupArray any active users.  A user must always have a group by the same name */
     foreach ($GroupArray as $group_fk => $group_name) {
         if (array_search($group_name, $UserArray)) {
             unset($GroupArray[$group_fk]);
         }
     }
     if (empty($GroupArray)) {
         $text = _("You have no groups you can delete.");
         echo "<p>{$text}<p>";
         return;
     }
     reset($GroupArray);
     if (empty($group_pk)) {
         $group_pk = key($GroupArray);
     }
     $text = _("Select the group to delete:  \n");
     $V .= "{$text}";
     /*** Display group select list, on change request new page with group= in url ***/
     $V .= Array2SingleSelect($GroupArray, "grouppk", $group_pk, false, false);
     $text = _("Delete");
     $V .= "<input type='submit' value='{$text}'>\n";
     $V .= "</form>\n";
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Ejemplo n.º 6
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     /* Get array of groups that this user is an admin of */
     $groupsWhereUserIsAdmin = GetGroupArray(Auth::getUserId());
     if (empty($groupsWhereUserIsAdmin)) {
         $text = _("You have no permission to manage any group.");
         return $this->render('include/base.html.twig', $this->mergeWithDefault(array('content' => $text)));
     }
     $folder_pk = intval($request->get('folder'));
     $upload_pk = intval($request->get('upload'));
     $perm_upload_pk = intval($request->get('permupk'));
     $perm = intval($request->get('perm'));
     $newgroup = intval($request->get('newgroup'));
     $newperm = intval($request->get('newperm'));
     $public_perm = $request->get('public', -1);
     /* @var $folderDao FolderDao */
     $folderDao = $this->getObject('dao.folder');
     $root_folder_pk = $folderDao->getRootFolder(Auth::getUserId())->getId();
     if (empty($folder_pk)) {
         $folder_pk = $root_folder_pk;
     }
     $UploadList = FolderListUploads_perm($folder_pk, Auth::PERM_WRITE);
     if (empty($upload_pk) && !empty($UploadList)) {
         $upload_pk = $UploadList[0]['upload_pk'];
     }
     if (!empty($perm_upload_pk)) {
         $this->uploadPermDao->updatePermissionId($perm_upload_pk, $perm);
     } else {
         if (!empty($newgroup) && !empty($newperm)) {
             $this->insertPermission($newgroup, $upload_pk, $newperm, $UploadList);
             $newperm = $newgroup = 0;
         } else {
             if ($public_perm >= 0) {
                 $this->uploadPermDao->setPublicPermission($upload_pk, $public_perm);
             }
         }
     }
     $vars = array('folderStructure' => $folderDao->getFolderStructure($root_folder_pk), 'groupArray' => $groupsWhereUserIsAdmin, 'uploadId' => $upload_pk, 'folderId' => $folder_pk, 'baseUri' => Traceback_uri() . '?mod=upload_permissions', 'newPerm' => $newperm, 'newGroup' => $newgroup, 'uploadList' => $UploadList, 'permNames' => $GLOBALS['PERM_NAMES']);
     if (!empty($UploadList)) {
         $vars['publicPerm'] = $this->uploadPermDao->getPublicPermission($upload_pk);
         $permGroups = $this->uploadPermDao->getPermissionGroups($upload_pk);
         $vars['permGroups'] = $permGroups;
         $additableGroups = array(0 => '-- select group --');
         foreach ($groupsWhereUserIsAdmin as $gId => $gName) {
             if (!array_key_exists($gId, $permGroups)) {
                 $additableGroups[$gId] = $gName;
             }
         }
         $vars['additableGroups'] = $additableGroups;
     }
     $vars['gumJson'] = json_encode($this->getGroupMembers($groupsWhereUserIsAdmin));
     if (!empty($upload_pk)) {
         $vars['permNamesWithReuse'] = $this->getPermNamesWithReuse($upload_pk);
     }
     return $this->render('upload_permissions.html.twig', $this->mergeWithDefault($vars));
 }
Ejemplo n.º 7
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $show = $request->get('show');
     if ($show == 'licensebrowser') {
         return $this->render("getting_started_licensebrowser.html.twig");
     }
     $login = _("Login");
     if (empty($_SESSION['User']) && plugin_find_id("auth") >= 0) {
         $login = "******" . Traceback_uri() . "?mod=auth'>{$login}</a>";
     }
     $vars = array('login' => $login, 'SiteURI' => Traceback_uri());
     return $this->render('getting_started.html.twig', $this->mergeWithDefault($vars));
 }
Ejemplo n.º 8
0
 /**
  * @param Request $request
  * @return Response
  */
 protected function handle(Request $request)
 {
     $folderId = intval($request->get('folder'));
     if (empty($folderId)) {
         $folderId = FolderGetTop();
     }
     $uploadId = intval($request->get('upload'));
     $agents = $request->get('agents') ?: '';
     if (!empty($uploadId) && !empty($agents) && is_array($agents)) {
         $rc = $this->agentsAdd($uploadId, $agents, $request);
         if (empty($rc)) {
             $status = GetRunnableJobList();
             $scheduler_msg = empty($status) ? _("Is the scheduler running? ") : '';
             $url = Traceback_uri() . "?mod=showjobs&upload={$uploadId}";
             $text = _("Your jobs have been added to job queue.");
             $linkText = _("View Jobs");
             $msg = "{$scheduler_msg}" . "{$text} <a href=\"{$url}\">{$linkText}</a>";
             $vars['message'] = $msg;
         } else {
             $text = _("Scheduling of Agent(s) failed: ");
             $vars['message'] = $text . $rc;
         }
     }
     $vars['uploadScript'] = ActiveHTTPscript("Uploads");
     $vars['agentScript'] = ActiveHTTPscript("Agents");
     $vars['folderId'] = $folderId;
     $vars['folderListOptions'] = FolderListOption(-1, 0, 1, $folderId);
     $vars['folderListUploads'] = FolderListUploads_perm($folderId, Auth::PERM_WRITE);
     $vars['baseUri'] = Traceback_uri();
     $vars['uploadId'] = $uploadId;
     $parmAgentList = MenuHook::getAgentPluginNames("ParmAgents");
     $out = '<ol>';
     $parmAgentFoots = '';
     foreach ($parmAgentList as $parmAgent) {
         $agent = plugin_find($parmAgent);
         $out .= "<br/><b>" . $agent->AgentName . ":</b><br/>";
         $out .= $agent->renderContent($vars);
         $parmAgentFoots .= $agent->renderFoot($vars);
     }
     $out .= '</ol>';
     $vars['out'] = $out;
     $vars['outFoot'] = '<script language="javascript"> ' . $parmAgentFoots . '</script>';
     return $this->render('agent_adder.html.twig', $this->mergeWithDefault($vars));
 }
Ejemplo n.º 9
0
 protected function handle(Request $request)
 {
     $groupId = Auth::getGroupId();
     $uploadIds = $request->get('uploads') ?: array();
     $uploadIds[] = intval($request->get('upload'));
     $addUploads = array();
     foreach ($uploadIds as $uploadId) {
         if (empty($uploadId)) {
             continue;
         }
         try {
             $addUploads[$uploadId] = $this->getUpload($uploadId, $groupId);
         } catch (Exception $e) {
             return $this->flushContent($e->getMessage());
         }
     }
     $folderId = $request->get('folder');
     if (!empty($folderId)) {
         /* @var $folderDao FolderDao */
         $folderDao = $this->getObject('dao.folder');
         $folderUploads = $folderDao->getFolderUploads($folderId, $groupId);
         foreach ($folderUploads as $uploadProgress) {
             $addUploads[$uploadProgress->getId()] = $uploadProgress;
         }
     }
     if (empty($addUploads)) {
         return $this->flushContent(_('No upload selected'));
     }
     $upload = array_pop($addUploads);
     try {
         list($jobId, $jobQueueId) = $this->getJobAndJobqueue($groupId, $upload, $addUploads);
     } catch (Exception $ex) {
         return $this->flushContent($ex->getMessage());
     }
     $vars = array('jqPk' => $jobQueueId, 'downloadLink' => Traceback_uri() . "?mod=download&report=" . $jobId, 'reportType' => $this->outputFormat);
     $text = sprintf(_("Generating " . $this->outputFormat . " report for '%s'"), $upload->getFilename());
     $vars['content'] = "<h2>" . $text . "</h2>";
     $content = $this->renderer->loadTemplate("report.html.twig")->render($vars);
     $message = '<h3 id="jobResult"></h3>';
     $request->duplicate(array('injectedMessage' => $message, 'injectedFoot' => $content, 'mod' => 'showjobs'))->overrideGlobals();
     $showJobsPlugin = \plugin_find('showjobs');
     $showJobsPlugin->OutputOpen();
     return $showJobsPlugin->getResponse();
 }
Ejemplo n.º 10
0
 /**
  * \brief Display the loaded menu and plugins.
  */
 public function Output()
 {
     global $Plugins;
     global $PG_CONN;
     $UploadPk = GetParm("upload", PARM_INTEGER);
     $Agent = GetParm("agent", PARM_STRING);
     if (empty($UploadPk) || empty($Agent)) {
         return new Response('missing parameter', Response::HTTP_BAD_REQUEST, array('Content-type' => 'text/plain'));
     }
     $sql = "SELECT upload_pk, upload_filename FROM upload WHERE upload_pk = '{$UploadPk}'";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     if (pg_num_rows($result) < 1) {
         $errMsg = __FILE__ . ":" . __LINE__ . " " . _("Upload") . " " . $UploadPk . " " . _("not found");
         return new Response($errMsg, Response::HTTP_BAD_REQUEST, array('Content-type' => 'text/plain'));
     }
     $UploadRow = pg_fetch_assoc($result);
     $ShortName = $UploadRow['upload_filename'];
     pg_free_result($result);
     $user_pk = Auth::getUserId();
     $group_pk = Auth::getGroupId();
     $job_pk = JobAddJob($user_pk, $group_pk, $ShortName, $UploadPk);
     $Dependencies = array();
     $P =& $Plugins[plugin_find_id($Agent)];
     $rv = $P->AgentAdd($job_pk, $UploadPk, $ErrorMsg, $Dependencies);
     if ($rv <= 0) {
         $text = _("Scheduling of Agent(s) failed: ");
         return new Response($text . $rv . $ErrorMsg, Response::HTTP_BAD_REQUEST, array('Content-type' => 'text/plain'));
     }
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     $scheduler_msg = "";
     if (empty($status)) {
         $scheduler_msg .= _("Is the scheduler running? ");
     }
     $URL = Traceback_uri() . "?mod=showjobs&upload={$UploadPk}";
     /* Need to refresh the screen */
     $text = _("Your jobs have been added to job queue.");
     $LinkText = _("View Jobs");
     $msg = "{$scheduler_msg}" . "{$text} <a href={$URL}>{$LinkText}</a>";
     $this->vars['message'] = $msg;
     return new Response($msg, Response::HTTP_OK, array('Content-type' => 'text/plain'));
 }
Ejemplo n.º 11
0
 private function getArrayArrayData($groupId, $canEdit)
 {
     $sql = "SELECT rf_pk,rf_shortname,rf_fullname,rf_text,rf_url,marydone FROM license_candidate WHERE group_fk=\$1";
     /** @var DbManager */
     $dbManager = $this->getObject('db.manager');
     $dbManager->prepare($stmt = __METHOD__, $sql);
     $res = $dbManager->execute($stmt, array($groupId));
     $aaData = array();
     while ($row = $dbManager->fetchArray($res)) {
         $aData = array(htmlentities($row['rf_shortname']), htmlentities($row['rf_fullname']), '<div style="overflow-y:scroll;max-height:150px;margin:0;">' . nl2br(htmlentities($row['rf_text'])) . '</div>', htmlentities($row['rf_url']), $this->bool2checkbox($dbManager->booleanFromDb($row['marydone'])));
         if ($canEdit) {
             $link = Traceback_uri() . '?mod=' . Traceback_parm() . '&rf=' . $row['rf_pk'];
             $edit = '<a href="' . $link . '"><img border="0" src="images/button_edit.png"></a>';
             array_unshift($aData, $edit);
         }
         $aaData[] = $aData;
     }
     $dbManager->freeResult($res);
     return $aaData;
 }
Ejemplo n.º 12
0
 /**
  * \brief This function returns the FOSSology logo and
  * Folder Navigation bar
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     global $Plugins;
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             /* Load the logo image */
             $Uri = Traceback_uri();
             $V .= "<center><a href='http://fossology.org' target='_top'><img alt='FOSSology' title='FOSSology' src='{$Uri}images/fossology-logo.gif' align=absmiddle border=0></a></center><br>\n";
             $V .= FolderListScript();
             $V .= "<small><center>";
             $text = _("Expand");
             $V .= "<a href='javascript:Expand();'>{$text}</a> |";
             $text = _("Collapse");
             $V .= "<a href='javascript:Collapse();'>{$text}</a> |";
             $text = _("Refresh");
             $V .= "<a href='" . Traceback() . "'>{$text}</a>";
             $V .= "</center></small>";
             $V .= "<P>\n";
             /* Display the tree */
             $V .= "<form>\n";
             $V .= FolderListDiv(-1, 0);
             $V .= "</form>\n";
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Ejemplo n.º 13
0
 /**
  * \brief Build the input form
  * 
  * \param $namestr - license family name
  * \param $filter - marydone value requested
  *
  * \return The input form as a string
  */
 function LicenseList($namestr, $filter)
 {
     global $PG_CONN;
     $ob = "";
     // output buffer
     // look at all
     if ($namestr == "All") {
         $where = "";
     } else {
         $where = "where rf_shortname like '" . pg_escape_string($namestr) . "' ";
     }
     // $filter is one of these: "All", "done", "notdone"
     if ($filter != "all") {
         if (empty($where)) {
             $where .= "where ";
         } else {
             $where .= " and ";
         }
         if ($filter == "done") {
             $where .= " marydone=true";
         }
         if ($filter == "notdone") {
             $where .= " marydone=false";
         }
     }
     $sql = "select * from ONLY license_ref {$where} order by rf_shortname";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     // print simple message if we have no results
     if (pg_num_rows($result) == 0) {
         $text = _("No licenses matching the filter");
         $text1 = _("and name pattern");
         $text2 = _("were found");
         $ob .= "<br>{$text} ({$filter}) {$text1} ({$namestr}) {$text2}.<br>";
         pg_free_result($result);
         return $ob;
     }
     $plural = pg_num_rows($result) == 1 ? "" : "s";
     $ob .= pg_num_rows($result) . " license{$plural} found.";
     //$ob .= "<table style='border: thin dotted gray'>";
     $ob .= "<table rules='rows' cellpadding='3'>";
     $ob .= "<tr>";
     $text = _("Edit");
     $ob .= "<th>{$text}</th>";
     $text = _("Checked");
     $ob .= "<th>{$text}</th>";
     $text = _("Shortname");
     $ob .= "<th>{$text}</th>";
     $text = _("Fullname");
     $ob .= "<th>{$text}</th>";
     $text = _("Text");
     $ob .= "<th>{$text}</th>";
     $text = _("URL");
     $ob .= "<th>{$text}</th>";
     $ob .= "</tr>";
     $lineno = 0;
     while ($row = pg_fetch_assoc($result)) {
         if ($lineno++ % 2) {
             $style = "style='background-color:lavender'";
         } else {
             $style = "";
         }
         $ob .= "<tr {$style}>";
         // Edit button brings up full screen edit of all license_ref fields
         $ob .= "<td align=center><a href='";
         $ob .= Traceback_uri();
         $ob .= "?mod=" . $this->Name . "&rf_pk={$row['rf_pk']}" . "&req_marydone={$_REQUEST['req_marydone']}&req_shortname={$_REQUEST['req_shortname']}' >" . "<img border=0 src='" . Traceback_uri() . "images/button_edit.png'></a></td>";
         $marydone = $row['marydone'] == 't' ? "Yes" : "No";
         $text = _("{$marydone}");
         $ob .= "<td align=center>{$text}</td>";
         $ob .= "<td>{$row['rf_shortname']}</td>";
         $ob .= "<td>{$row['rf_fullname']}</td>";
         $vetext = htmlspecialchars($row['rf_text']);
         $ob .= "<td><textarea readonly=readonly rows=3 cols=40>{$vetext}</textarea></td> ";
         $ob .= "<td>{$row['rf_url']}</td>";
         $ob .= "</tr>";
     }
     pg_free_result($result);
     $ob .= "</table>";
     return $ob;
 }
Ejemplo n.º 14
0
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $Page = "";
     $UploadPk = GetParm('upload', PARM_INTEGER);
     if (empty($UploadPk)) {
         $UploadPk = -1;
     } else {
         $UploadPerm = GetUploadPerm($UploadPk);
         if ($UploadPerm < PERM_WRITE) {
             $text = _("Permission Denied");
             echo "<h2>{$text}<h2>";
             return;
         }
     }
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             // micro menus
             $V .= menu_to_1html(menu_find($this->Name, $MenuDepth), 0);
             /* Process any actions */
             if (@$_SESSION['UserLevel'] >= PLUGIN_DB_WRITE) {
                 $jq_pk = GetParm("jobid", PARM_INTEGER);
                 $Action = GetParm("action", PARM_STRING);
                 $UploadPk = GetParm("upload", PARM_INTEGER);
                 if (!empty($UploadPk)) {
                     $UploadPerm = GetUploadPerm($UploadPk);
                     if ($UploadPerm < PERM_WRITE) {
                         $text = _("Permission Denied");
                         echo "<h2>{$text}<h2>";
                         return;
                     }
                 }
                 $Page = GetParm('page', PARM_INTEGER);
                 if (empty($Page)) {
                     $Page = 0;
                 }
                 $jqtype = GetParm("jqtype", PARM_STRING);
                 $ThisURL = Traceback_uri() . "?mod=" . $this->Name . "&upload={$UploadPk}";
                 $Job = GetParm('job', PARM_INTEGER);
                 switch ($Action) {
                     case 'pause':
                         if (empty($jq_pk)) {
                             break;
                         }
                         $Command = "pause {$jq_pk}";
                         $rv = fo_communicate_with_scheduler($Command, $response_from_scheduler, $error_info);
                         if ($rv == false) {
                             $V .= _("Unable to pause job.") . " " . $response_from_scheduler . $error_info;
                         }
                         echo "<script type=\"text/javascript\"> window.location.replace(\"{$ThisURL}\"); </script>";
                         break;
                     case 'restart':
                         if (empty($jq_pk)) {
                             break;
                         }
                         $Command = "restart {$jq_pk}";
                         $rv = fo_communicate_with_scheduler($Command, $response_from_scheduler, $error_info);
                         if ($rv == false) {
                             $V .= _("Unable to restart job.") . " " . $response_from_scheduler . $error_info;
                         }
                         echo "<script type=\"text/javascript\"> window.location.replace(\"{$ThisURL}\"); </script>";
                         break;
                     case 'cancel':
                         if (empty($jq_pk)) {
                             break;
                         }
                         $Msg = "\"" . _("Killed by") . " " . @$_SESSION['User'] . "\"";
                         $Command = "kill {$jq_pk} {$Msg}";
                         $rv = fo_communicate_with_scheduler($Command, $response_from_scheduler, $error_info);
                         if ($rv == false) {
                             $V .= _("Unable to cancel job.") . $response_from_scheduler . $error_info;
                         }
                         echo "<script type=\"text/javascript\"> window.location.replace(\"{$ThisURL}\"); </script>";
                         break;
                     default:
                         break;
                 }
             }
             if (!empty($Job)) {
                 $V .= $this->ShowJobDB($Job);
             } else {
                 if ($UploadPk) {
                     $upload_pks = array($UploadPk);
                     $Jobs = $this->Uploads2Jobs($upload_pks, $Page);
                 } else {
                     $Jobs = $this->MyJobs($this->nhours);
                 }
                 $JobsInfo = $this->GetJobInfo($Jobs, $Page);
                 /* Sort jobs by job_pk (so most recent comes out first) */
                 usort($JobsInfo, "CompareJobsInfo");
                 $V .= $this->Show($JobsInfo, $Page);
             }
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Ejemplo n.º 15
0
 /**
  * \brief Generate the text for this plugin.
  */
 public function Output()
 {
     $V = "";
     /* If this is a POST, then process the request. */
     $uploadpk = GetParm('upload', PARM_INTEGER);
     if (!empty($uploadpk)) {
         $rc = $this->Delete($uploadpk);
         if (empty($rc)) {
             /* Need to refresh the screen */
             $URL = Traceback_uri() . "?mod=showjobs&upload={$uploadpk} ";
             $LinkText = _("View Jobs");
             $text = _("Deletion added to job queue.");
             $msg = "{$text} <a href={$URL}>{$LinkText}</a>";
             $V .= displayMessage($msg);
         } else {
             $text = _("Deletion Scheduling failed: ");
             $V .= DisplayMessage($text . $rc);
         }
     }
     /* Create the AJAX (Active HTTP) javascript for doing the reply
        and showing the response. */
     $V .= ActiveHTTPscript("Uploads");
     $V .= "<script language='javascript'>\n";
     $V .= "function Uploads_Reply()\n";
     $V .= "  {\n";
     $V .= "  if ((Uploads.readyState==4) && (Uploads.status==200))\n";
     $V .= "    {\n";
     /* Remove all options */
     //$V.= "    document.formy.upload.innerHTML = Uploads.responseText;\n";
     $V .= "    document.getElementById('uploaddiv').innerHTML = '<BR><select name=\\'upload\\' size=\\'10\\'>' + Uploads.responseText + '</select><P />';\n";
     /* Add new options */
     $V .= "    }\n";
     $V .= "  }\n";
     $V .= "</script>\n";
     /* Build HTML form */
     $V .= "<form name='formy' method='post'>\n";
     // no url = this url
     $text = _("Select the uploaded file to");
     $text1 = _("delete");
     $V .= "{$text} <em>{$text1}</em>\n";
     $V .= "<ul>\n";
     $text = _("This will");
     $text1 = _("delete");
     $text2 = _("the upload file!");
     $V .= "<li>{$text} <em>{$text1}</em> {$text2}\n";
     $text = _("Be very careful with your selection since you can delete a lot of work!\n");
     $V .= "<li>{$text}";
     $text = _("All analysis only associated with the deleted upload file will also be deleted.\n");
     $V .= "<li>{$text}";
     $text = _("THERE IS NO UNDELETE. When you select something to delete, it will be removed from the database and file repository.\n");
     $V .= "<li>{$text}";
     $V .= "</ul>\n";
     $text = _("Select the uploaded file to delete:");
     $V .= "<P>{$text}<P>\n";
     $V .= "<ol>\n";
     $text = _("Select the folder containing the file to delete: ");
     $V .= "<li>{$text}";
     $V .= "<select name='folder' ";
     $V .= "onLoad='Uploads_Get((\"" . Traceback_uri() . "?mod=upload_options&folder=-1' ";
     $V .= "onChange='Uploads_Get(\"" . Traceback_uri() . "?mod=upload_options&folder=\" + this.value)'>\n";
     $root_folder_pk = GetUserRootFolder();
     $V .= FolderListOption($root_folder_pk, 0);
     $V .= "</select><P />\n";
     $text = _("Select the uploaded project to delete:");
     $V .= "<li>{$text}";
     $V .= "<div id='uploaddiv'>\n";
     $V .= "<BR><select name='upload' size='10'>\n";
     $List = FolderListUploads_perm($root_folder_pk, Auth::PERM_WRITE);
     foreach ($List as $L) {
         $V .= "<option value='" . $L['upload_pk'] . "'>";
         $V .= htmlentities($L['name']);
         if (!empty($L['upload_desc'])) {
             $V .= " (" . htmlentities($L['upload_desc']) . ")";
         }
         if (!empty($L['upload_ts'])) {
             $V .= " :: " . substr($L['upload_ts'], 0, 19);
         }
         $V .= "</option>\n";
     }
     $V .= "</select><P />\n";
     $V .= "</div>\n";
     $V .= "</ol>\n";
     $text = _("Delete");
     $V .= "<input type='submit' value='{$text}!'>\n";
     $V .= "</form>\n";
     return $V;
 }
Ejemplo n.º 16
0
 /**
  * @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);
 }
 /**
  * \brief Update forms
  *
  * \param $rf_pk - for the license to update, empty to add
  *
  * \return The input form as a string
  */
 function Updatefm($rf_pk)
 {
     global $PG_CONN;
     $text = _("The Short Name and License Text must be unique.");
     echo "<b>{$text}</b><br>";
     $rf_active = $marydone = $rf_shortname = $rf_fullname = $rf_text_updatable = $rf_detector_type = $rf_text = $rf_url = $rf_notes = "";
     $rf_pk_update = "";
     if (0 < count($_POST)) {
         $rf_pk_update = $_POST['rf_pk'];
         if (!empty($rf_pk)) {
             $rf_pk_update = $rf_pk;
         } else {
             if (empty($rf_pk_update)) {
                 $rf_pk_update = $_GET['rf_pk'];
             }
         }
         $rf_active = $_POST['rf_active'];
         $marydone = $_POST['marydone'];
         $rf_text_updatable = $_POST['rf_text_updatable'];
         $rf_detector_type = $_POST['rf_detector_type'];
         $rf_shortname = pg_escape_string($_POST['rf_shortname']);
         $rf_fullname = pg_escape_string($_POST['rf_fullname']);
         $rf_url = pg_escape_string($_POST['rf_url']);
         $rf_notes = pg_escape_string($_POST['rf_notes']);
         $rf_text = pg_escape_string($_POST['rf_text']);
     }
     $ob = "";
     // output buffer
     $ob .= "<FORM name='Updatefm' action='?mod=" . $this->Name . "&rf_pk={$rf_pk_update}" . "' method='POST'>";
     $req_marydone = $req_shortname = "";
     if ($rf_pk) {
         $req_marydone = $_GET['req_marydone'];
         $req_shortname = $_GET['req_shortname'];
     }
     $ob .= "<input type=hidden name=rf_pk value='{$rf_pk}'>";
     $ob .= "<input type=hidden name=req_marydone value='{$req_marydone}'";
     $ob .= "<input type=hidden name=req_shortname value='{$req_shortname}'>";
     $ob .= "<table>";
     if ($rf_pk) {
         $sql = "select * from license_ref where rf_pk='{$rf_pk}'";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         // print simple message if we have no results
         if (pg_num_rows($result) == 0) {
             $ob .= "</table>";
             $text = _("No licenses matching this key");
             $text1 = _("was found");
             $ob .= "<br>{$text} ({$rf_pk}) {$text1}.<br>";
             pg_free_result($result);
             return $ob;
         }
         $ob .= "<input type=hidden name=updateit value=true>";
         $row = pg_fetch_assoc($result);
         pg_free_result($result);
     } else {
         $ob .= "<input type=hidden name=addit value=true>";
         $row = array();
     }
     if ($row) {
         $rf_active = $row['rf_active'];
         $marydone = $row['marydone'];
         $rf_shortname = $row['rf_shortname'];
         $rf_fullname = $row['rf_fullname'];
         $rf_text_updatable = $row['rf_text_updatable'];
         $rf_detector_type = $row['rf_detector_type'];
         $rf_text = $row['rf_text'];
         $rf_url = $row['rf_url'];
         $rf_notes = $row['rf_notes'];
     }
     $ob .= "<tr>";
     $active = $rf_active == 't' || $rf_active == 'true' ? "Yes" : "No";
     $select = Array2SingleSelect(array("true" => "Yes", "false" => "No"), "rf_active", $active);
     $text = _("Active");
     $ob .= "<td align=right>{$text}</td>";
     $ob .= "<td align=left>{$select}</td>";
     $ob .= "</tr>";
     $ob .= "<tr>";
     $marydone = $marydone == 't' || 'true' == $marydone ? "Yes" : "No";
     $select = Array2SingleSelect(array("true" => "Yes", "false" => "No"), "marydone", $marydone);
     $text = _("Checked");
     $ob .= "<td align=right>{$text}</td>";
     $ob .= "<td align=left>{$select}</td>";
     $ob .= "</tr>";
     $ob .= "<tr>";
     //    $ob .= "<td align=right>Short name<br>(read only)</td>";
     //    $ob .= "<td><input readonly='readonly' type='text' name='rf_shortname' value='$row[rf_shortname]' size=80></td>";
     $text = _("Short name");
     $ob .= "<td align=right>{$text}</td>";
     $ob .= "<td><input type='text' name='rf_shortname' value='{$rf_shortname}' size=80></td>";
     $ob .= "</tr>";
     $ob .= "<tr>";
     $text = _("Full name");
     $ob .= "<td align=right>{$text}</td>";
     $ob .= "<td><input type='text' name='rf_fullname' value='{$rf_fullname}' size=80></td>";
     $ob .= "</tr>";
     $ob .= "<tr>";
     $updatable = $rf_text_updatable == 't' || 'true' == $rf_text_updatable ? true : false;
     if (empty($rf_pk) || $updatable) {
         $rotext = '';
         $rooption = '';
     } else {
         $text = _("(read only)");
         $rotext = "<br>{$text}";
         $rooption = "readonly='readonly'";
     }
     $text = _("License Text");
     $ob .= "<td align=right>{$text} {$rotext}</td>";
     $ob .= "<td><textarea name='rf_text' rows=10 cols=80 {$rooption}>" . $rf_text . "</textarea></td> ";
     $ob .= "</tr>";
     $ob .= "<tr>";
     $tupable = $rf_text_updatable == 't' || 'true' == $rf_text_updatable ? "Yes" : "No";
     $select = Array2SingleSelect(array("true" => "Yes", "false" => "No"), "rf_text_updatable", $tupable);
     $text = _("Text Updatable");
     $ob .= "<td align=right>{$text}</td>";
     $ob .= "<td align=left>{$select}</td>";
     $ob .= "</tr>";
     $ob .= "<tr>";
     $dettype = $rf_detector_type == '2' ? "Nomos" : "Reference License";
     $select = Array2SingleSelect(array("1" => "Reference License", "2" => "Nomos"), "rf_detector_type", $dettype);
     $text = _("Detector Type");
     $ob .= "<td align=right>{$text}</td>";
     $ob .= "<td align=left>{$select}</td>";
     $ob .= "</tr>";
     $ob .= "<tr>";
     $text = _("URL");
     $ob .= "<td align=right>{$text}";
     $ob .= "<a href='{$rf_url}'><image border=0 src=" . Traceback_uri() . "images/right-point-bullet.gif></a></td>";
     $ob .= "<td><input type='text' name='rf_url' value='{$rf_url}' size=80></td>";
     $ob .= "</tr>";
     $ob .= "<tr>";
     $text = _("Public Notes");
     $ob .= "<td align=right>{$text}</td>";
     $ob .= "<td><textarea name='rf_notes' rows=5 cols=80>" . $rf_notes . "</textarea></td> ";
     $ob .= "</tr>";
     $ob .= "</table>";
     if ($rf_pk || $rf_pk_update) {
         $text = _("Update");
         $ob .= "<INPUT type='submit' value='{$text}'>\n";
     } else {
         $text = _("Add License");
         $ob .= "<INPUT type='submit' value='{$text}'>\n";
     }
     $ob .= "</FORM>\n";
     return $ob;
 }
Ejemplo n.º 18
0
/**
 * \brief Get an html linked string of a file browse path.
 *
 * \param $Mod - Module name (e.g. "browse")
 * \param $UploadtreePk
 * \param $LinkLast - create link (a href) for last item and use LinkLast as the module name
 * \param $ShowBox - true to draw a box around the string
 * \param $ShowMicro - true to show micro menu
 * \param $Enumerate - if >= zero number the folder/file path (the stuff in the yellow bar)
 *   starting with the value $Enumerate
 * \param $PreText - optional additional text to preceed the folder path
 * \param $PostText - optional text to follow the folder path
 * \param $uploadtree_tablename
 *
 * \return string of browse paths
 */
function Dir2Browse($Mod, $UploadtreePk, $LinkLast = NULL, $ShowBox = 1, $ShowMicro = NULL, $Enumerate = -1, $PreText = '', $PostText = '', $uploadtree_tablename = "uploadtree")
{
    $V = "";
    if ($ShowBox) {
        $V .= "<div style='border: thin dotted gray; background-color:lightyellow'>\n";
    }
    if ($Enumerate >= 0) {
        $V .= "<table border=0 width='100%'><tr><td width='5%'>";
        $V .= "<font size='+2'>" . number_format($Enumerate, 0, "", ",") . ":</font>";
        $V .= "</td><td>";
    }
    $Opt = Traceback_parm_keep(array("folder", "show"));
    $Uri = Traceback_uri() . "?mod={$Mod}";
    /* Get array of upload recs for this path, in top down order.
       This does not contain artifacts.
       */
    $Path = Dir2Path($UploadtreePk, $uploadtree_tablename);
    $Last =& $Path[count($Path) - 1];
    $V .= "<font class='text'>\n";
    /* Add in additional text */
    if (!empty($PreText)) {
        $V .= "{$PreText}<br>\n";
    }
    /* Get the FOLDER list for the upload */
    $text = _("Folder");
    $V .= "<b>{$text}</b>: ";
    if (array_key_exists(0, $Path)) {
        $List = FolderGetFromUpload($Path[0]['upload_fk']);
        $Uri2 = Traceback_uri() . "?mod=browse" . Traceback_parm_keep(array("show"));
        for ($i = 0; $i < count($List); $i++) {
            $Folder = $List[$i]['folder_pk'];
            $FolderName = htmlentities($List[$i]['folder_name']);
            $V .= "<b><a href='{$Uri2}&folder={$Folder}'>{$FolderName}</a></b>/ ";
        }
    }
    $FirstPath = 1;
    /* every firstpath belongs on a new line */
    /* Print the upload, itself (on the next line since it is not a folder) */
    if (count($Path) == -1) {
        $Upload = $Path[0]['upload_fk'];
        $UploadName = htmlentities($Path[0]['ufile_name']);
        $UploadtreePk = $Path[0]['uploadtree_pk'];
        $V .= "<br><b><a href='{$Uri2}&folder={$Folder}&upload={$Upload}&item={$UploadtreePk}'>{$UploadName}</a></b>";
        // $FirstPath=0;
    } else {
        $V .= "<br>";
    }
    /* Show the path within the upload */
    if ($FirstPath != 0) {
        for ($p = 0; !empty($Path[$p]['uploadtree_pk']); $p++) {
            $P =& $Path[$p];
            if (empty($P['ufile_name'])) {
                continue;
            }
            $UploadtreePk = $P['uploadtree_pk'];
            if (!$FirstPath) {
                $V .= "/ ";
            }
            if (!empty($LinkLast) || $P != $Last) {
                if ($P == $Last) {
                    $Uri = Traceback_uri() . "?mod={$LinkLast}";
                }
                $V .= "<a href='{$Uri}&upload=" . $P['upload_fk'] . $Opt . "&item=" . $UploadtreePk . "'>";
            }
            if (Isdir($P['ufile_mode'])) {
                $V .= $P['ufile_name'];
            } else {
                if (!$FirstPath && Iscontainer($P['ufile_mode'])) {
                    $V .= "<br>\n&nbsp;&nbsp;";
                }
                $V .= "<b>" . $P['ufile_name'] . "</b>";
            }
            if (!empty($LinkLast) || $P != $Last) {
                $V .= "</a>";
            }
            $FirstPath = 0;
        }
    }
    $V .= "</font>\n";
    if (!empty($ShowMicro)) {
        $MenuDepth = 0;
        /* unused: depth of micro menu */
        $V .= menu_to_1html(menu_find($ShowMicro, $MenuDepth), 1);
    }
    if ($Enumerate >= 0) {
        if ($PostText) {
            $V .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{$PostText}";
        }
        $V .= "</td></tr></table>";
    }
    if ($ShowBox) {
        $V .= "</div>\n";
    }
    return $V;
}
Ejemplo n.º 19
0
 /**
  * \brief Given an Upload and UploadtreePk item, display:
  * - The histogram for the directory BY LICENSE.
  * - The file listing for the directory, with license navigation.
  */
 function ShowUploadHist($Upload, $Item, $Uri)
 {
     /*****
         Get all the licenses PER item (file or directory) under this
         UploadtreePk.
         Save the data 3 ways:
         - Number of licenses PER item.
         - Number of items PER license.
         - Number of items PER license family.
        *****/
     $VF = "";
     // return values for file listing
     $VH = "";
     // return values for license histogram
     $V = "";
     // total return value
     global $Plugins;
     global $PG_CONN;
     $Lics = array();
     // license summary for an item in the directory
     $ModLicView =& $Plugins[plugin_find_id("view-license")];
     /* Arrays for storying item->license and license->item mappings */
     $LicGID2Item = array();
     $LicItem2GID = array();
     $MapLic2GID = array();
     /* every license should have an ID number */
     /*  Get the counts for each license under this UploadtreePk*/
     LicenseGetAll($Item, $Lics);
     // key is license name, value is count
     $LicTotal = $Lics[' Total '];
     /* Ensure that every license is associated with an ID */
     /* MapLic2Gid key is license name, value is a sequence number (GID) */
     $MapNext = 0;
     foreach ($Lics as $Key => $Val) {
         $MapLic2GID[$Key] = $MapNext++;
     }
     /****************************************/
     /* Get ALL the items under this UploadtreePk */
     $Children = DirGetList($Upload, $Item);
     $ChildCount = 0;
     $ChildLicCount = 0;
     $ChildDirCount = 0;
     /* total number of directory or containers */
     foreach ($Children as $C) {
         if (Iscontainer($C['ufile_mode'])) {
             $ChildDirCount++;
         }
     }
     $VF .= "<table border=0>";
     foreach ($Children as $C) {
         if (empty($C)) {
             continue;
         }
         /* Store the item information */
         $IsDir = Isdir($C['ufile_mode']);
         $IsContainer = Iscontainer($C['ufile_mode']);
         /* Determine the hyperlinks */
         if (!empty($C['pfile_fk']) && !empty($ModLicView)) {
             $LinkUri = "{$Uri}&item=" . $C['uploadtree_pk'];
             $LinkUri = preg_replace("/mod=license/", "mod=view-license", $LinkUri);
         } else {
             $LinkUri = NULL;
         }
         if (Iscontainer($C['ufile_mode'])) {
             $uploadtree_pk = DirGetNonArtifact($C['uploadtree_pk']);
             $LicUri = "{$Uri}&item=" . $uploadtree_pk;
         } else {
             $LicUri = NULL;
         }
         /* Populate the output ($VF) - file list */
         /* Find number of licenses in child */
         //      if (($ChildDirCount < 20) || (!$IsContainer))
         //        { $LicCount = LicenseCount($C['uploadtree_pk']); }
         //      else { $LicCount=0; }
         $LicCount = 0;
         $VF .= '<tr><td id="Lic-' . $LicCount . '" 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>";
         }
         $VF .= "</td><td>";
         if ($LicCount) {
             $VF .= "[" . number_format($LicCount, 0, "", ",") . "&nbsp;";
             //$VF .= "<a href=\"javascript:LicColor('Lic-$ChildCount','LicGroup-','" . trim($LicItem2GID[$ChildCount]) . "','lightgreen');\">";
             $VF .= "license" . ($LicCount == 1 ? "" : "s");
             $VF .= "</a>";
             $VF .= "]";
             $ChildLicCount += $LicCount;
         }
         $VF .= "</td>";
         $VF .= "</tr>\n";
         $ChildCount++;
     }
     $VF .= "</table>\n";
     // print "ChildCount=$ChildCount  ChildLicCount=$ChildLicCount\n";
     /***************************************
     Problem: $ChildCount can be zero!
     This happens if you have a container that does not
     unpack to a directory.  For example:
     file.gz extracts to archive.txt that contains a license.
     Same problem seen with .pdf and .Z files.
     Solution: if $ChildCount == 0, then just view the license!
     
     $ChildCount can also be zero if the directory is empty.
          ***************************************/
     if ($ChildCount == 0) {
         $sql = "SELECT * FROM uploadtree WHERE uploadtree_pk = '{$Item}';";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $row = pg_fetch_assoc($result);
         pg_free_result($result);
         if (IsDir($row['ufile_mode'])) {
             return;
         }
         $ModLicView =& $Plugins[plugin_find_id("view-license")];
         return $ModLicView->Output();
     }
     /****************************************/
     /* List the licenses */
     $VH .= "<table border=1 width='100%'>\n";
     $SFbL = plugin_find_id("search_file_by_license");
     $text = _("Count");
     $VH .= "<tr><th width='10%'>{$text}</th>";
     $text = _("Files");
     if ($SFbL >= 0) {
         $VH .= "<th width='10%'>{$text}</th>";
     }
     $text = _("License");
     $VH .= "<th>{$text}</th>\n";
     /* krsort + arsort = consistent sorting order */
     arsort($Lics);
     /* Redo the sorting */
     $SortOrder = array();
     foreach ($Lics as $Key => $Val) {
         if (empty($Val)) {
             continue;
         }
         $SortOrder[] = $Val . "|" . str_replace("'", "", $Key) . "|" . $Key;
     }
     usort($SortOrder, array($this, "SortName"));
     $LicsTotal = array();
     foreach ($SortOrder as $Key => $Val) {
         if (empty($Val)) {
             continue;
         }
         list($x, $y, $z) = explode("\\|", $Val, 3);
         $LicsTotal[$z] = $x;
     }
     $Total = 0;
     foreach ($Lics as $Key => $Val) {
         if ($Key != ' Total ') {
             $GID = $MapLic2GID[$Key];
             $VH .= "<tr><td align='right'>{$Val}</td>";
             $Total += $Val;
             if ($SFbL >= 0) {
                 $VH .= "<td align='center'><a href='";
                 $VH .= Traceback_uri();
                 $text = _("Show");
                 $VH .= "?mod=search_file_by_license&item={$Item}&lic=" . urlencode($Key) . "'>{$text}</a></td>";
             }
             $VH .= "<td id='LicGroup-{$GID}'>";
             $Uri = Traceback_uri() . "?mod=license_listing&item={$Item}&lic={$GID}";
             // $VH .= "<a href=\"javascript:LicColor('LicGroup-$GID','Lic-','" . trim($LicGID2Item[$GID]) . "','yellow'); ";
             // $VH .= "\">";
             $VH .= htmlentities($Key);
             $VH .= "</a>";
             $VH .= "</td></tr>\n";
         }
     }
     $VH .= "</table>\n";
     $VH .= "<br>\n";
     $text = _("Total licenses");
     $VH .= "{$text}: {$Total}\n";
     /****************************************/
     /* Licenses use Javascript to highlight */
     $VJ = "";
     // return values for the javascript
     $VJ .= "<script language='javascript'>\n";
     $VJ .= "<!--\n";
     $VJ .= "var LastSelf='';\n";
     $VJ .= "var LastPrefix='';\n";
     $VJ .= "var LastListing='';\n";
     $VJ .= "function LicColor(Self,Prefix,Listing,color)\n";
     $VJ .= "{\n";
     $VJ .= "if (LastSelf!='')\n";
     $VJ .= "  { document.getElementById(LastSelf).style.backgroundColor='white'; }\n";
     $VJ .= "LastSelf = Self;\n";
     $VJ .= "if (LastPrefix!='')\n";
     $VJ .= "  {\n";
     $VJ .= "  List = LastListing.split(' ');\n";
     $VJ .= "  for(var i in List)\n";
     $VJ .= "    {\n";
     $VJ .= "    document.getElementById(LastPrefix + List[i]).style.backgroundColor='white';\n";
     $VJ .= "    }\n";
     $VJ .= "  }\n";
     $VJ .= "LastPrefix = Prefix;\n";
     $VJ .= "LastListing = Listing;\n";
     $VJ .= "if (Self!='')\n";
     $VJ .= "  {\n";
     $VJ .= "  document.getElementById(Self).style.backgroundColor=color;\n";
     $VJ .= "  }\n";
     $VJ .= "if (Listing!='')\n";
     $VJ .= "  {\n";
     $VJ .= "  List = Listing.split(' ');\n";
     $VJ .= "  for(var i in List)\n";
     $VJ .= "    {\n";
     $VJ .= "    document.getElementById(Prefix + List[i]).style.backgroundColor=color;\n";
     $VJ .= "    }\n";
     $VJ .= "  }\n";
     $VJ .= "}\n";
     $VJ .= "// -->\n";
     $VJ .= "</script>\n";
     /* Combine VF and VH */
     $V .= "<table border=0 width='100%'>\n";
     $V .= "<tr><td valign='top' width='50%'>{$VH}</td><td valign='top'>{$VF}</td></tr>\n";
     $V .= "</table>\n";
     $V .= "<hr />\n";
     $V .= $VJ;
     return $V;
 }
Ejemplo n.º 20
0
 /**
  * @param $Uploadtree_pk
  * @param $Uri
  * @param $uploadtree_tablename
  * @param $Agent_pk
  * @param $upload_pk
  * @return array
  */
 protected function getFileListing($Uploadtree_pk, $Uri, $uploadtree_tablename, $Agent_pk, $upload_pk)
 {
     $VF = "";
     // return values for file listing
     /*******    File Listing     ************/
     /* Get ALL the items under this Uploadtree_pk */
     $Children = GetNonArtifactChildren($Uploadtree_pk, $uploadtree_tablename);
     $ChildCount = 0;
     $ChildLicCount = 0;
     $ChildDirCount = 0;
     /* total number of directory or containers */
     foreach ($Children as $c) {
         if (Iscontainer($c['ufile_mode'])) {
             $ChildDirCount++;
         }
     }
     $VF .= "<table border=0>";
     foreach ($Children as $child) {
         if (empty($child)) {
             continue;
         }
         $ChildCount++;
         global $Plugins;
         $ModLicView =& $Plugins[plugin_find_id($this->viewName)];
         /* Determine the hyperlink for non-containers to view-license  */
         if (!empty($child['pfile_fk']) && !empty($ModLicView)) {
             $LinkUri = Traceback_uri();
             $LinkUri .= "?mod=" . $this->viewName . "&agent={$Agent_pk}&upload={$upload_pk}&item={$child['uploadtree_pk']}";
         } else {
             $LinkUri = NULL;
         }
         /* Determine link for containers */
         if (Iscontainer($child['ufile_mode'])) {
             $uploadtree_pk = DirGetNonArtifact($child['uploadtree_pk'], $uploadtree_tablename);
             $LicUri = "{$Uri}&item=" . $uploadtree_pk;
         } else {
             $LicUri = NULL;
         }
         /* Populate the output ($VF) - file list */
         /* id of each element is its uploadtree_pk */
         $LicCount = 0;
         $cellContent = Isdir($child['ufile_mode']) ? $child['ufile_name'] . '/' : $child['ufile_name'];
         if (Iscontainer($child['ufile_mode'])) {
             $cellContent = "<a href='{$LicUri}'><b>{$cellContent}</b></a>";
         } else {
             if (!empty($LinkUri)) {
                 $cellContent = "<a href='{$LinkUri}'>{$cellContent}</a>";
             }
         }
         $VF .= "<tr><td id='{$child['uploadtree_pk']}' align='left'>{$cellContent}</td><td>";
         if ($LicCount) {
             $VF .= "[" . number_format($LicCount, 0, "", ",") . "&nbsp;";
             $VF .= "license" . ($LicCount == 1 ? "" : "s");
             $VF .= "</a>";
             $VF .= "]";
             $ChildLicCount += $LicCount;
         }
         $VF .= "</td></tr>\n";
     }
     $VF .= "</table>\n";
     return array($ChildCount, $VF);
 }
 /**
  * \brief Generate the text for this plugin.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $V = "";
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             /* Display instructions */
             $Uri = Traceback_uri();
             $V .= _("FOSSology has many options for importing and uploading files for analysis.\n");
             $V .= _("The options vary based on <i>where</i> the data to upload is located.\n");
             $V .= _("The data may be located:\n");
             $V .= "<ul>\n";
             $text = _("On your browser system");
             $V .= "<li><b>{$text}</b>.\n";
             $text = _("Use the");
             $text1 = _("Upload File");
             $text2 = _("option to select and upload the file.");
             $V .= "{$text} <a href='{$Uri}?mod=upload_file'>{$text1}</a> {$text2}\n";
             $V .= _("While this can be very convenient (particularly if the file is not readily accessible online),\n");
             $V .= _("uploading via your web browser can be slow for large files,\n");
             $V .= _("and files larger than 650 Megabytes may not be uploadable.\n");
             $V .= "<P />\n";
             $text = _("On a remote server");
             $V .= "<li><b>{$text}</b>.\n";
             $text = _("Use the");
             $text1 = _("Upload from URL");
             $text2 = _("option to specify a remote server.");
             $V .= "{$text} <a href='{$Uri}?mod=upload_url'>{$text1}</a> {$text2}\n";
             $V .= _("This is the most flexible option, but the URL must denote a publicly accessible HTTP, HTTPS, or FTP location.\n");
             $V .= _("URLs that require authentication or human interactions cannot be downloaded through this automated system.\n");
             $V .= "<P />\n";
             $text = _("On the FOSSology web server");
             $V .= "<li><b>{$text}</b>.\n";
             $text = _("Use the");
             $text1 = _("Upload from Server");
             $text2 = _("option to specify a file or path on the server.");
             $V .= "{$text} <a href='{$Uri}?mod=upload_srv_files'>{$text1}</a> {$text2}\n";
             $V .= _("This option is intended for developers who have mounted directories containing source trees.\n");
             $V .= _("The directory must be accessible via the web server's user.\n");
             $V .= "<P />\n";
             $text = _("On the version control system");
             $V .= "<li><b>{$text}</b>.\n";
             $text = _("Use the");
             $text1 = _("Upload from Version Control System");
             $text2 = _("option to specify URL of a repo.");
             $V .= "{$text} <a href='{$Uri}?mod=upload_vcs'>{$text1}</a> {$text2}\n";
             $V .= "<P />\n";
             $V .= _("If your system is configured to use multiple agent servers, the data area must be\n");
             $V .= _("mounted and accessible to the FOSSology user (fossy) on every agent system.  See\n");
             $text = _("the section");
             $text1 = _("Configuring the Scheduler in the ");
             $text2 = _("Scheduler documentation");
             $V .= "{$text} <em>{$text1}</em><a href='http://www.fossology.org/projects/fossology/wiki/Sched-20'>{$text2}</a>.\n";
             $V .= "</ul>\n";
             if (0) {
                 $V .= "<P />\n";
                 $V .= _("Select the type of upload based on where the data is located:\n");
                 /* ASCII ART ROCKS! */
                 $V .= "<table border=0>\n";
                 $V .= "<tr>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "</tr><tr>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $text = _("Your computer");
                 $V .= "<td bgcolor='white' align='center'><a href='{$Uri}?mod=upload_file'>{$text}</a></td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'> &rarr; </td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $text = _("FOSSology web server");
                 $V .= "<td bgcolor='white' align='center'><a href='{$Uri}?mod=upload_srv_files'>{$text}</a></td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "</tr><tr>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "</tr><tr>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white' align='center'>&darr;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "</tr><tr>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "</tr><tr>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $text = _("Remote web or FTP server");
                 $V .= "<td bgcolor='white' align='center'><a href='{$Uri}?mod=upload_url'>{$text}</a></td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "</tr><tr>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='blue'>&nbsp;</td>";
                 $V .= "<td bgcolor='white'>&nbsp;</td>";
                 $V .= "</tr>";
                 $V .= "</table>\n";
             }
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Ejemplo n.º 22
0
 /**
  * \brief Process the upload request.
  * \param $Folder
  * \param  $GetURL
  * \param  $Desc
  * \param  $Name
  * \param  $Accept
  * \param  $Reject
  * \param  $Level
  * \param $public_perm public permission on the upload
  * Returns NULL on success, string on failure.
  */
 function Upload($Folder, $GetURL, $Desc, $Name, $Accept, $Reject, $Level, $public_perm)
 {
     global $SysConf;
     /* See if the URL looks valid */
     if (empty($Folder)) {
         $text = _("Invalid folder");
         return $text;
     }
     $GetURL = trim($GetURL);
     if (empty($GetURL)) {
         $text = _("Invalid URL");
         return $text;
     }
     if (preg_match("@^((http)|(https)|(ftp))://([[:alnum:]]+)@i", $GetURL) != 1) {
         $text = _("Invalid URL");
         return "{$text}: " . htmlentities($GetURL);
     }
     if (preg_match("@[[:space:]]@", $GetURL) != 0) {
         $text = _("Invalid URL (no spaces permitted)");
         return "{$text}: " . htmlentities($GetURL);
     }
     if (empty($Name)) {
         $Name = basename($GetURL);
     }
     $ShortName = basename($Name);
     if (empty($ShortName)) {
         $ShortName = $Name;
     }
     /* Create an upload record. */
     $Mode = 1 << 2;
     // code for "it came from wget"
     $user_pk = $SysConf['auth']['UserId'];
     $uploadpk = JobAddUpload($user_pk, $ShortName, $GetURL, $Desc, $Mode, $Folder, $public_perm);
     if (empty($uploadpk)) {
         $text = _("Failed to insert upload record");
         return $text;
     }
     /* Set default values */
     if (empty($Level) && !is_numeric($Level) || $Level < 0) {
         $Level = 1;
     }
     /* first trim, then get rid of whitespaces before and after each comma letter */
     $Accept = preg_replace('/\\s*,\\s*/', ',', trim($Accept));
     $Reject = preg_replace('/\\s*,\\s*/', ',', trim($Reject));
     /* Create the job: job "wget" */
     $jobpk = JobAddJob($user_pk, "wget", $uploadpk);
     if (empty($jobpk) || $jobpk < 0) {
         $text = _("Failed to insert job record");
         return $text;
     }
     $jq_args = "{$uploadpk} - {$GetURL} -l {$Level} ";
     if (!empty($Accept)) {
         $jq_args .= "-A {$Accept} ";
     }
     if (!empty($Reject)) {
         // reject the files index.html*
         $jq_args .= "-R {$Reject},index.html* ";
     } else {
         $jq_args .= "-R index.html* ";
     }
     $jobqueuepk = JobQueueAdd($jobpk, "wget_agent", $jq_args, NULL, NULL);
     if (empty($jobqueuepk)) {
         $text = _("Failed to insert task 'wget_agent' into job queue");
         return $text;
     }
     global $Plugins;
     /* schedule agents */
     $unpackplugin =& $Plugins[plugin_find_id("agent_unpack")];
     $ununpack_jq_pk = $unpackplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array("wget_agent"));
     if ($ununpack_jq_pk < 0) {
         return $ErrorMsg;
     }
     $adj2nestplugin =& $Plugins[plugin_find_id("agent_adj2nest")];
     $adj2nest_jq_pk = $adj2nestplugin->AgentAdd($jobpk, $uploadpk, $ErrorMsg, array());
     if ($adj2nest_jq_pk < 0) {
         return $ErrorMsg;
     }
     AgentCheckBoxDo($jobpk, $uploadpk);
     $msg = "";
     /** check if the scheudler is running */
     $status = GetRunnableJobList();
     if (empty($status)) {
         $msg .= _("Is the scheduler running? ");
     }
     $Url = Traceback_uri() . "?mod=showjobs&upload={$uploadpk}";
     $text = _("The upload");
     $text1 = _("has been queued. It is");
     $msg .= "{$text} {$Name} {$text1} ";
     $keep = "<a href='{$Url}'>upload #" . $uploadpk . "</a>.\n";
     print displayMessage($msg, $keep);
     return NULL;
 }
Ejemplo n.º 23
0
 /**
  * \brief Generate the text for this plugin.
  */
 function Output()
 {
     global $PG_CONN;
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     $V = "";
     /* If this is a POST, then process the request. */
     $Group = GetParm('groupname', PARM_TEXT);
     if (!empty($Group)) {
         $rc = $this->Add($Group);
         if (empty($rc)) {
             /* Need to refresh the screen */
             $text = _("Group");
             $text1 = _("added");
             $V .= displayMessage("{$text} {$Group} {$text1}.");
         } else {
             $V .= displayMessage($rc);
         }
     }
     /* Build HTML form */
     $text = _("Add a Group");
     $V .= "<h4>{$text}</h4>\n";
     $V .= "<form name='formy' method='POST' action=" . Traceback_uri() . "?mod=group_add>\n";
     $Val = htmlentities(GetParm('groupname', PARM_TEXT), ENT_QUOTES);
     $text = _("Enter the groupname:");
     $V .= "{$text}\n";
     $V .= "<input type='text' value='{$Val}' name='groupname' size=20>\n";
     $text = _("Add");
     $V .= "<input type='submit' value='{$text}'>\n";
     $V .= "</form>\n";
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Ejemplo n.º 24
0
 /**
  * \brief Given an $Uploadtree_pk, display: 
  *   - The histogram for the directory BY LICENSE.
  *   - The file listing for the directory.
  */
 function ShowUploadHist($Uploadtree_pk, $Uri, $tag_pk)
 {
     global $PG_CONN;
     $VF = "";
     // return values for file listing
     $VLic = "";
     // return values for license histogram
     $V = "";
     // total return value
     $UniqueTagArray = array();
     global $Plugins;
     $ModLicView =& $Plugins[plugin_find_id("view-license")];
     /*******  Get license names and counts  ******/
     /* Find lft and rgt bounds for this $Uploadtree_pk  */
     $sql = "SELECT lft,rgt,upload_fk FROM {$this->uploadtree_tablename}\n              WHERE uploadtree_pk = {$Uploadtree_pk}";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $lft = $row["lft"];
     $rgt = $row["rgt"];
     $upload_pk = $row["upload_fk"];
     pg_free_result($result);
     if (empty($lft)) {
         $text = _("Job unpack/adj2nest hasn't completed.");
         $VLic = "<b>{$text}</b><p>";
         return $VLic;
     }
     /* Find total number of files for this $Uploadtree_pk
      * Exclude artifacts and directories.
      */
     $sql = "SELECT count(*) as count FROM {$this->uploadtree_tablename}\n              WHERE upload_fk = {$upload_pk} \n                    and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt}\n                    and ((ufile_mode & (1<<28))=0) \n                    and ((ufile_mode & (1<<29))=0) and pfile_fk!=0";
     //$uTime = microtime(true);
     $result = pg_query($PG_CONN, $sql);
     //printf( "<small>count files Elapsed time: %.2f seconds</small>", microtime(true) - $uTime);  // convert usecs to secs
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $row = pg_fetch_assoc($result);
     $FileCount = $row["count"];
     pg_free_result($result);
     /*  Get the counts for each license under this UploadtreePk*/
     if (empty($tag_pk)) {
         $TagTable = "";
         $TagClause = "";
     } else {
         $TagTable = " right join tag_file on tag_file.pfile_fk=license_file_ref.pfile_fk ";
         $TagClause = " and tag_fk={$tag_pk}";
     }
     /** advanced interface allowing user to select dataset (agent version) */
     $Agent_name = 'nomos';
     $dataset = "nomos_dataset";
     $Agent_pk = GetParm("agent", PARM_STRING);
     /** if do not specify agent, get the latest agent result for this upload */
     if (empty($Agent_pk)) {
         $Agent_pk = LatestAgentpk($upload_pk, "nomos_ars");
     }
     if ($Agent_pk == 0) {
         $text = _("No data available.  Use Jobs > Agents to schedule a license scan.");
         $VLic = "<b>{$text}</b><p>";
         return $VLic;
     }
     /** get nomos select dataset */
     $AgentSelect = AgentSelect($Agent_name, $upload_pk, true, $dataset, $dataset, $Agent_pk, "onchange=\"addArsGo('newds', 'nomos_dataset');\"");
     /** change the nomos license result when selecting one version of nomos */
     if (!empty($AgentSelect)) {
         $action = Traceback_uri() . "?mod=nomoslicense&upload={$upload_pk}&item={$Uploadtree_pk}";
         $VLic .= "<script type='text/javascript'>\n        function addArsGo(formid, selectid)\n        {\n          var selectobj = document.getElementById(selectid);\n          var Agent_pk = selectobj.options[selectobj.selectedIndex].value;\n          document.getElementById(formid).action='{$action}'+'&agent='+Agent_pk;\n          document.getElementById(formid).submit();\n          return;\n        }\n      </script>";
         /* form to select new dataset, show dataset */
         $VLic .= "<form action='{$action}' id='newds' method='POST'>\n";
         $VLic .= $AgentSelect;
         $VLic .= "</form>";
     }
     $orderBy = array('count', 'license_name');
     $ordersql = "liccount desc";
     static $ordercount = 1;
     static $orderlic = 1;
     /** sorting by count/licnese name */
     if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
         $order = $_GET['orderBy'];
         if (isset($_GET['orderc'])) {
             $ordercount = $_GET['orderc'];
         }
         if (isset($_GET['orderl'])) {
             $orderlic = $_GET['orderl'];
         }
         if ('count' == $order && 1 == $ordercount) {
             $ordersql = "liccount desc";
             $ordercount = 0;
         } else {
             if ('count' == $order && 0 == $ordercount) {
                 $ordersql = "liccount ";
                 $ordercount = 1;
             } else {
                 if ('license_name' == $order && 1 == $orderlic) {
                     $ordersql = "rf_shortname ";
                     $orderlic = 0;
                 } else {
                     if ('license_name' == $order && 0 == $orderlic) {
                         $ordersql = "rf_shortname desc";
                         $orderlic = 1;
                     }
                 }
             }
         }
     }
     // Void ARE EXCLUDED FROM LICENSE COUNT
     $sql = "SELECT distinct(SS.rf_shortname) as licname, count(SS.rf_shortname) as liccount, SS.rf_shortname from \n            (SELECT distinct(license_file_ref.pfile_fk), rf_shortname\n            from license_file_ref {$TagTable}\n            right join {$this->uploadtree_tablename} on license_file_ref.pfile_fk={$this->uploadtree_tablename}.pfile_fk \n            where rf_shortname <> 'Void' and upload_fk='{$upload_pk}' and {$this->uploadtree_tablename}.lft BETWEEN {$lft} and {$rgt} \n              and agent_fk={$Agent_pk} {$TagClause} group by license_file_ref.pfile_fk, rf_shortname\n            ) as SS\n            group by rf_shortname order by {$ordersql}";
     //$uTime = microtime(true);
     $result = pg_query($PG_CONN, $sql);
     //$Time = microtime(true) - $uTime;  // convert usecs to secs
     //$text = _("histogram Elapsed time: %.2f seconds");
     //printf( "<small>$text</small>", $Time);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     /* Write license histogram to $VLic  */
     $LicCount = 0;
     $UniqueLicCount = 0;
     $NoLicFound = 0;
     $VLic .= "<table border=1 width='100%' id='lichistogram'>\n";
     $text = _("Count");
     $VLic .= "<tr><th>";
     $VLic .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "tag", "agent")) . "&orderBy=count&orderc={$ordercount}>{$text}</a>";
     $VLic .= "</th>";
     $text = _("Files");
     $VLic .= "<th width='10%'>{$text}</th>";
     $text = _("License Name");
     $VLic .= "<th>";
     $VLic .= "<a href=?mod=" . "{$this->Name}" . Traceback_parm_keep(array("upload", "item", "tag", "agent")) . "&orderBy=license_name&orderl={$orderlic}>{$text}</a>";
     $VLic .= "</th></tr>\n";
     while ($row = pg_fetch_assoc($result)) {
         $UniqueLicCount++;
         $LicCount += $row['liccount'];
         /*  Count  */
         $VLic .= "<tr><td align='right'>{$row['liccount']}</td>";
         /*  Show  */
         $VLic .= "<td align='center'><a href='";
         $VLic .= Traceback_uri();
         $text = _("Show");
         $tagClause = $tag_pk ? "&tag={$tag_pk}" : "";
         $VLic .= "?mod=list_lic_files&napk={$Agent_pk}&item={$Uploadtree_pk}&lic=" . urlencode($row['rf_shortname']) . $tagClause . "'>{$text}</a></td>";
         /*  License name  */
         $VLic .= "<td align='left'>";
         $rf_shortname = rawurlencode($row['rf_shortname']);
         $VLic .= "<a id='{$rf_shortname}' onclick='FileColor_Get(\"" . Traceback_uri() . "?mod=ajax_filelic&napk={$Agent_pk}&item={$Uploadtree_pk}&lic={$rf_shortname}&ut={$this->uploadtree_tablename}\")'";
         $VLic .= ">{$row['licname']} </a>";
         $VLic .= "</td>";
         $VLic .= "</tr>\n";
         if ($row['licname'] == "No_license_found") {
             $NoLicFound = $row['liccount'];
         }
     }
     $VLic .= "</table>\n";
     $VLic .= "<p>\n";
     $VLic .= _("Hint: Click on the license name to ");
     $text = _("highlight");
     $VLic .= "<span style='background-color:{$this->HighlightColor}'>{$text} </span>";
     $VLic .= _("where the license is found in the file listing.<br>\n");
     $VLic .= "<table border=0 id='licsummary'>";
     $text = _("Unique licenses");
     $VLic .= "<tr><td align=right>{$UniqueLicCount}</td><td>{$text}</td></tr>";
     $NetLic = $LicCount - $NoLicFound;
     $text = _("Licenses found");
     $VLic .= "<tr><td align=right>{$NetLic}</td><td>{$text}</td></tr>";
     $text = _("Files with no licenses");
     $VLic .= "<tr><td align=right>{$NoLicFound}</td><td>{$text}</td></tr>";
     $text = _("Files");
     $VLic .= "<tr><td align=right>{$FileCount}</td><td>{$text}</td></tr>";
     $VLic .= "</table>";
     pg_free_result($result);
     /*******    File Listing     ************/
     /* Get ALL the items under this Uploadtree_pk */
     $Children = GetNonArtifactChildren($Uploadtree_pk, $this->uploadtree_tablename);
     /* Filter out Children that don't have tag */
     if (!empty($tag_pk)) {
         TagFilter($Children, $tag_pk, $this->uploadtree_tablename);
     }
     $ChildCount = 0;
     $ChildLicCount = 0;
     //$uTime = microtime(true);
     if (!empty($Children)) {
         /* For alternating row background colors */
         $RowStyle1 = "style='background-color:#ecfaff'";
         // pale blue
         $RowStyle2 = "style='background-color:#ffffe3'";
         // pale yellow
         $ColorSpanRows = 1;
         // Alternate background color every $ColorSpanRows
         $RowNum = 0;
         $VF .= "<table border=0 id='dirlist'>";
         foreach ($Children as $C) {
             if (empty($C)) {
                 continue;
             }
             $IsDir = Isdir($C['ufile_mode']);
             $IsContainer = Iscontainer($C['ufile_mode']);
             /* Determine the hyperlink for non-containers to view-license  */
             if (!empty($C['pfile_fk']) && !empty($ModLicView)) {
                 $LinkUri = Traceback_uri();
                 $LinkUri .= "?mod=view-license&napk={$Agent_pk}&upload={$upload_pk}&item={$C['uploadtree_pk']}";
             } else {
                 $LinkUri = NULL;
             }
             /* Determine link for containers */
             if (Iscontainer($C['ufile_mode'])) {
                 $uploadtree_pk = DirGetNonArtifact($C['uploadtree_pk'], $this->uploadtree_tablename);
                 $LicUri = "{$Uri}&item=" . $uploadtree_pk;
             } else {
                 $LicUri = NULL;
             }
             /* Populate the output ($VF) - file list */
             /* id of each element is its uploadtree_pk */
             /* Set alternating row background color - repeats every $ColorSpanRows rows */
             $RowStyle = $RowNum++ % (2 * $ColorSpanRows) < $ColorSpanRows ? $RowStyle1 : $RowStyle2;
             $VF .= "<tr {$RowStyle}>";
             $VF .= "<td id='{$C['uploadtree_pk']}' align='left'>";
             $HasHref = 0;
             $HasBold = 0;
             if ($IsContainer) {
                 $VF .= "<a href='{$LicUri}'>";
                 $HasHref = 1;
                 $VF .= "<b>";
                 $HasBold = 1;
             } else {
                 if (!empty($LinkUri)) {
                     $VF .= "<a href='{$LinkUri}'>";
                     $HasHref = 1;
                 }
             }
             $VF .= $C['ufile_name'];
             if ($IsDir) {
                 $VF .= "/";
             }
             if ($HasBold) {
                 $VF .= "</b>";
             }
             if ($HasHref) {
                 $VF .= "</a>";
             }
             /* show licenses under file name */
             $VF .= "<br>";
             $VF .= GetFileLicenses_string($Agent_pk, $C['pfile_fk'], $C['uploadtree_pk'], $this->uploadtree_tablename);
             $VF .= "</td><td valign='top'>";
             /* display file links */
             $VF .= FileListLinks($C['upload_fk'], $C['uploadtree_pk'], $Agent_pk, $C['pfile_fk'], true, $UniqueTagArray, $this->uploadtree_tablename);
             $VF .= "</td>";
             $VF .= "</tr>\n";
             $ChildCount++;
         }
         $VF .= "</table>\n";
     }
     //$Time = microtime(true) - $uTime;  // convert usecs to secs
     //$text = _("Sum of children Elapsed time: %.2f seconds");
     //printf( "<small>$text</small>", $Time);
     /***************************************
          Problem: $ChildCount can be zero!
         This happens if you have a container that does not
         unpack to a directory.  For example:
         file.gz extracts to archive.txt that contains a license.
         Same problem seen with .pdf and .Z files.
         Solution: if $ChildCount == 0, then just view the license!
     
         $ChildCount can also be zero if the directory is empty.
         ***************************************/
     if ($ChildCount == 0) {
         $sql = "SELECT * FROM {$this->uploadtree_tablename} WHERE uploadtree_pk = '{$Uploadtree_pk}';";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $row = pg_fetch_assoc($result);
         pg_free_result($result);
         if (IsDir($row['ufile_mode'])) {
             return;
         }
         $ModLicView =& $Plugins[plugin_find_id("view-license")];
         return $ModLicView->Output();
     }
     $V .= ActiveHTTPscript("FileColor");
     /* Add javascript for color highlighting
         This is the response script needed by ActiveHTTPscript
        responseText is license name',' followed by a comma seperated list of uploadtree_pk's */
     $script = "\n      <script type=\"text/javascript\" charset=\"utf-8\">\n        var Lastutpks='';   /* save last list of uploadtree_pk's */\n        var LastLic='';   /* save last License (short) name */\n        var color = '{$this->HighlightColor}';\n        function FileColor_Reply()\n        {\n          if ((FileColor.readyState==4) && (FileColor.status==200))\n          {\n            /* remove previous highlighting */\n            var numpks = Lastutpks.length;\n            if (numpks > 0) document.getElementById(LastLic).style.backgroundColor='white';\n            while (numpks)\n            {\n              document.getElementById(Lastutpks[--numpks]).style.backgroundColor='white';\n            }\n\n            utpklist = FileColor.responseText.split(',');\n            LastLic = utpklist.shift();\n            numpks = utpklist.length;\n            Lastutpks = utpklist;\n\n            /* apply new highlighting */\n            elt = document.getElementById(LastLic);\n            if (elt != null) elt.style.backgroundColor=color;\n            while (numpks)\n            {\n              document.getElementById(utpklist[--numpks]).style.backgroundColor=color;\n            }\n          }\n          return;\n        }\n      </script>\n    ";
     $V .= $script;
     /******  Filters  *******/
     /* Only display the filter pulldown if there are filters available 
      * Currently, this is only tags.
      */
     /** @todo qualify with tag namespace to avoid tag name collisions.  **/
     /* turn $UniqueTagArray into key value pairs ($SelectData) for select list */
     $SelectData = array();
     if (count($UniqueTagArray)) {
         foreach ($UniqueTagArray as $UTA_row) {
             $SelectData[$UTA_row['tag_pk']] = $UTA_row['tag_name'];
         }
         $V .= "Tag filter";
         $myurl = "?mod=" . $this->Name . Traceback_parm_keep(array("upload", "item"));
         $Options = " id='filterselect' onchange=\"js_url(this.value, '{$myurl}&tag=')\"";
         $V .= Array2SingleSelectTag($SelectData, "tag_ns_pk", $tag_pk, true, false, $Options);
     }
     /****** Combine VF and VLic ********/
     $V .= "<table border=0 width='100%'>\n";
     $V .= "<tr><td valign='top' >{$VLic}</td><td valign='top'>{$VF}</td></tr>\n";
     $V .= "</table>\n";
     $V .= "<hr />\n";
     return $V;
 }
Ejemplo n.º 25
0
 /**
  * \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;
 }
Ejemplo n.º 26
0
 /**
  * @brief HTML output
  * @param $Master
  * @param $uploadtree_pk1
  * @param $uploadtree_pk2
  * @param $in_uploadtree_pk1
  * @param $in_uploadtree_pk2
  * @param $filter
  * @param $TreeInfo1
  * @param $TreeInfo2
  * @param $BucketDefArray
  * @return HTML as string.
  */
 function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2, $BucketDefArray)
 {
     /* Initialize */
     $FreezeText = _("Freeze Path");
     $FrozenText = _("Frozen, Click to unfreeze");
     $OutBuf = '';
     /******* javascript functions ********/
     $OutBuf .= "\n<script language='javascript'>\n";
     /* function to replace this page specifying a new filter parameter */
     $OutBuf .= "function ChangeFilter(selectObj, utpk1, utpk2){";
     $OutBuf .= "  var selectidx = selectObj.selectedIndex;";
     $OutBuf .= "  var filter = selectObj.options[selectidx].value;";
     $OutBuf .= '  window.location.assign("?mod=' . $this->Name . '&item1="+utpk1+"&item2="+utpk2+"&filter=" + filter); ';
     $OutBuf .= "}\n";
     /* Freeze function (path list in banner)
         FreezeColNo is the ID of the column to freeze: 1 or 2
        Toggle Freeze button label: Freeze Path <-> Unfreeze Path
        Toggle Freeze button background color: white to light blue
        Toggle which paths are frozen: if path1 freezes, then unfreeze path2.
        Rewrite urls: eg &item1 ->  &Fitem1
        */
     $OutBuf .= "function Freeze(FreezeColNo) {";
     $OutBuf .= "var FreezeElt1 = document.getElementById('Freeze1');";
     $OutBuf .= "var FreezeElt2 = document.getElementById('Freeze2');";
     $OutBuf .= "var AddFreezeArg = 1; ";
     //1 to add &freeze=, 0 to remove &freeze= from url
     $OutBuf .= "var old_uploadtree_pk;\n";
     /* change the freeze labels to denote their new status */
     $OutBuf .= "if (FreezeColNo == '1')";
     $OutBuf .= "{";
     $OutBuf .= "if (FreezeElt1.innerHTML == '{$FrozenText}') ";
     $OutBuf .= "{";
     $OutBuf .= "FreezeElt1.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt1.style.backgroundColor = 'white'; ";
     $OutBuf .= "AddFreezeArg = 0;";
     $OutBuf .= "}";
     $OutBuf .= "else { ";
     $OutBuf .= "FreezeElt1.innerHTML = '{$FrozenText}'; ";
     $OutBuf .= "FreezeElt1.style.backgroundColor = '#EAF7FB'; ";
     $OutBuf .= "FreezeElt2.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
     $OutBuf .= "old_uploadtree_pk = {$in_uploadtree_pk1};";
     $OutBuf .= "}";
     $OutBuf .= "}";
     $OutBuf .= "else {";
     $OutBuf .= "if (FreezeElt2.innerHTML == '{$FrozenText}') ";
     $OutBuf .= "{";
     $OutBuf .= "FreezeElt2.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
     $OutBuf .= "AddFreezeArg = 0;";
     $OutBuf .= "}";
     $OutBuf .= "else {";
     $OutBuf .= "FreezeElt1.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt1.style.backgroundColor = 'white';";
     $OutBuf .= "FreezeElt2.innerHTML = '{$FrozenText}';";
     $OutBuf .= "FreezeElt2.style.backgroundColor = '#EAF7FB';";
     $OutBuf .= "old_uploadtree_pk = {$in_uploadtree_pk2};";
     $OutBuf .= "}";
     $OutBuf .= "}";
     /* Alter the url to add or remove freeze={column number}  */
     $OutBuf .= "var i=0;\n";
     $OutBuf .= "var linkid;\n";
     $OutBuf .= "var linkelt;\n";
     $OutBuf .= "var FreezeIdx;\n";
     $OutBuf .= "var BaseURL;\n";
     $OutBuf .= "var numlinks = document.links.length;\n";
     $OutBuf .= "for (i=0; i < numlinks; i++)\n";
     $OutBuf .= "{";
     $OutBuf .= "linkelt = document.links[i];\n";
     // freeze is the last url arg, so trim it off if it exists
     $OutBuf .= "FreezeIdx = linkelt.href.indexOf('&freeze');\n";
     $OutBuf .= "if (FreezeIdx > 0) \n";
     $OutBuf .= "BaseURL = linkelt.href.substr(0,FreezeIdx); \n";
     $OutBuf .= "else ";
     $OutBuf .= "BaseURL = linkelt.href; \n";
     $OutBuf .= "if (AddFreezeArg == 1) \n ";
     $OutBuf .= "linkelt.href = BaseURL + '&freeze=' + FreezeColNo + '&itemf=' + old_uploadtree_pk;";
     $OutBuf .= "else \n";
     $OutBuf .= "linkelt.href = BaseURL;";
     $OutBuf .= "}\n";
     $OutBuf .= "}\n";
     $OutBuf .= "</script>\n";
     /******* END javascript functions  ********/
     /* Select list for filters */
     $SelectFilter = "<select name='diff_filter' id='diff_filter' onchange='ChangeFilter(this,{$uploadtree_pk1}, {$uploadtree_pk2})'>";
     $Selected = $filter == 'none' ? "selected" : "";
     $SelectFilter .= "<option {$Selected} value='none'>Remove nothing";
     $Selected = $filter == 'samebucketlist' ? "selected" : "";
     $SelectFilter .= "<option {$Selected} value='samebucketlist'>Remove unchanged bucket lists";
     $SelectFilter .= "</select>";
     $StyleRt = "style='float:right'";
     $OutBuf .= "<a name='flist' href='#histo' {$StyleRt} > Jump to histogram </a><br>";
     /* Switch to license diff view */
     $text = _("Switch to license view");
     $switchURL = Traceback_uri();
     $switchURL .= "?mod=nomosdiff&item1={$uploadtree_pk1}&item2={$uploadtree_pk2}";
     $OutBuf .= "<a href='{$switchURL}' {$StyleRt} > {$text} </a> ";
     //    $TableStyle = "style='border-style:collapse;border:1px solid black'";
     $TableStyle = "";
     $OutBuf .= "<table border=0 id='dirlist' {$TableStyle}>";
     /* Select filter pulldown */
     $OutBuf .= "<tr><td colspan=5 align='center'>Filter: {$SelectFilter}<br>&nbsp;</td></tr>";
     /* File path */
     $OutBuf .= "<tr>";
     $Path1 = Dir2Path($uploadtree_pk1);
     $Path2 = Dir2Path($uploadtree_pk2);
     $OutBuf .= "<td colspan=2>";
     $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 1, $this);
     $OutBuf .= "</td>";
     $OutBuf .= "<td {$this->ColumnSeparatorStyleL} colspan=3>";
     $OutBuf .= Dir2BrowseDiff($Path1, $Path2, $filter, 2, $this);
     $OutBuf .= "</td></tr>";
     /* File comparison table */
     $OutBuf .= $this->ItemComparisonRows($Master, $TreeInfo1['agent_pk'], $TreeInfo2['agent_pk'], $BucketDefArray);
     /*  Separator row */
     $ColumnSeparatorStyleTop = "style='border:solid 0 #006600; border-top-width:2px; border-bottom-width:2px;'";
     $OutBuf .= "<tr>";
     $OutBuf .= "<td colspan=5 {$ColumnSeparatorStyleTop}>";
     $OutBuf .= "<a name='histo' href='#flist' style='float:right'> Jump to top </a>";
     $OutBuf .= "</a>";
     $OutBuf .= "</tr>";
     /* License histogram */
     $OutBuf .= "<tr>";
     $Tree1Hist = $this->UploadHist($uploadtree_pk1, $TreeInfo1, $BucketDefArray);
     $OutBuf .= "<td colspan=2 valign='top' align='center'>{$Tree1Hist}</td>";
     $OutBuf .= "<td {$this->ColumnSeparatorStyleL}>&nbsp;</td>";
     $Tree2Hist = $this->UploadHist($uploadtree_pk2, $TreeInfo2, $BucketDefArray);
     $OutBuf .= "<td colspan=2 valign='top' align='center'>{$Tree2Hist}</td>";
     $OutBuf .= "</tr></table>\n";
     $OutBuf .= "<a href='#flist' style='float:right'> Jump to top </a><p>";
     return $OutBuf;
 }
 function Output()
 {
     global $PG_CONN;
     global $PERM_NAMES;
     /* GET parameters */
     $folder_pk = GetParm('folder', PARM_INTEGER);
     $upload_pk = GetParm('upload', PARM_INTEGER);
     $users_group_pk = GetParm('group_pk', PARM_INTEGER);
     $group_pk = GetParm('group', PARM_INTEGER);
     $perm_upload_pk = GetParm('permupk', PARM_INTEGER);
     $perm = GetParm('perm', PARM_INTEGER);
     $newgroup = GetParm('newgroup', PARM_INTEGER);
     $newperm = GetParm('newperm', PARM_INTEGER);
     $public_perm = GetParm('public', PARM_INTEGER);
     // start building the output buffer
     $V = "";
     /* If perm_upload_pk is passed in, update either the perm or group_pk */
     $sql = "";
     if (!empty($perm_upload_pk)) {
         if ($perm === 0) {
             $sql = "delete from perm_upload where perm_upload_pk='{$perm_upload_pk}'";
         } else {
             if (!empty($perm)) {
                 $sql = "update perm_upload set perm='{$perm}' where perm_upload_pk='{$perm_upload_pk}'";
             } else {
                 if (!empty($group_pk)) {
                     $sql = "update perm_upload set group_fk='{$group_pk}' where perm_upload_pk='{$perm_upload_pk}'";
                 }
             }
         }
         if (!empty($sql)) {
             $result = @pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             pg_free_result($result);
         }
     } else {
         if (!empty($newgroup) and !empty($newperm)) {
             // before inserting this new record, delete any record for the same upload and group since
             // that would be a duplicate
             $sql = "delete from perm_upload where upload_fk={$upload_pk} and group_fk={$newgroup}";
             $result = pg_query($PG_CONN, $sql);
             DBCheckResult($result, $sql, __FILE__, __LINE__);
             pg_free_result($result);
             // Don't insert a PERM_NONE.  NONE is the default
             if ($newperm != PERM_NONE) {
                 $sql = "insert into perm_upload (perm, upload_fk, group_fk) values ({$newperm}, {$upload_pk}, {$newgroup})";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 pg_free_result($result);
             }
             $newperm = $newgroup = 0;
         } else {
             if (!empty($public_perm)) {
                 $sql = "update upload set public_perm='{$public_perm}' where upload_pk='{$upload_pk}'";
                 $result = pg_query($PG_CONN, $sql);
                 DBCheckResult($result, $sql, __FILE__, __LINE__);
                 pg_free_result($result);
             }
         }
     }
     $root_folder_pk = GetUserRootFolder();
     if (empty($folder_pk)) {
         $folder_pk = $root_folder_pk;
     }
     // Get folder array folder_pk => folder_name
     $FolderArray = array();
     GetFolderArray($root_folder_pk, $FolderArray);
     /* define js_url */
     $V .= js_url();
     $text = _("Select the folder that contains the upload:  \n");
     $V .= "{$text}";
     /*** Display folder select list, on change request new page with folder= in url ***/
     $url = Traceback_uri() . "?mod=upload_permissions&folder=";
     $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
     $V .= Array2SingleSelect($FolderArray, "folderselect", $folder_pk, false, false, $onchange);
     /*** Display upload select list, on change, request new page with new upload= in url ***/
     $text = _("Select the upload you wish to edit:  \n");
     $V .= "<br>{$text}";
     // Get list of all upload records in this folder that the user has PERM_ADMIN
     $UploadList = FolderListUploads_perm($folder_pk, PERM_ADMIN);
     /*
     if (empty($UploadList))
     {
     echo "You have no uploads in this folder for which you are an admin.  Hit the back button";
     return;
     }
     */
     // Make data array for upload select list.  Key is upload_pk, value is a composite
     // of the upload_filename and upload_ts.
     // Note that $UploadList may be empty so $UploadArray will be empty
     $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);
     }
     /* Upload select list */
     $url = Traceback_uri() . "?mod=upload_permissions&folder={$folder_pk}&upload=";
     $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
     $V .= Array2SingleSelect($UploadArray, "uploadselect", $upload_pk, false, false, $onchange);
     /* Get permissions for this upload */
     if (!empty($UploadArray)) {
         // Get upload.public_perm
         $sql = "select public_perm from upload where upload_pk='{$upload_pk}'";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $Row = pg_fetch_all($result);
         $public_perm = $Row[0]['public_perm'];
         pg_free_result($result);
         $text1 = _("Public Permission");
         $V .= "<p>{$text1} &nbsp;";
         $url = Traceback_uri() . "?mod=upload_permissions&folder={$folder_pk}&upload={$upload_pk}&public=";
         $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
         $V .= Array2SingleSelect($PERM_NAMES, "publicpermselect", $public_perm, false, false, $onchange);
         $sql = "select perm_upload_pk, perm, group_pk, group_name from groups, perm_upload where group_fk=group_pk and upload_fk='{$upload_pk}'";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $PermArray = pg_fetch_all($result);
         pg_free_result($result);
         /* Get master array of groups */
         $sql = "select group_pk, group_name from groups order by group_name";
         $result = pg_query($PG_CONN, $sql);
         DBCheckResult($result, $sql, __FILE__, __LINE__);
         $GroupArray = array();
         while ($GroupRow = pg_fetch_assoc($result)) {
             $GroupArray[$GroupRow['group_pk']] = $GroupRow['group_name'];
         }
         pg_free_result($result);
         /* Permissions Table */
         $V .= "<p><table border=1>";
         $GroupText = _("Group");
         $PermText = _("Permission");
         $V .= "<tr><th>{$GroupText}</th><th>{$PermText}</th></tr>";
         foreach ($PermArray as $PermRow) {
             $V .= "<tr>";
             $V .= "<td>";
             // group
             $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&permupk={$PermRow['perm_upload_pk']}&group=";
             $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
             $V .= Array2SingleSelect($GroupArray, "groupselect", $PermRow['group_pk'], false, false, $onchange);
             $V .= "</td>";
             $V .= "<td>";
             // permission
             $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&permupk={$PermRow['perm_upload_pk']}&perm=";
             $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
             $V .= Array2SingleSelect($PERM_NAMES, "permselect", $PermRow['perm'], false, false, $onchange);
             $V .= "</td>";
             $V .= "</tr>";
         }
         /* Print one extra row for adding perms */
         $V .= "<tr>";
         $V .= "<td>";
         // group
         $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&newperm={$newperm}&newgroup=";
         $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
         $Selected = empty($newgroup) ? "" : $newgroup;
         $V .= Array2SingleSelect($GroupArray, "groupselectnew", $Selected, true, false, $onchange);
         $V .= "</td>";
         $V .= "<td>";
         // permission
         $url = Traceback_uri() . "?mod=upload_permissions&group_pk={$users_group_pk}&upload={$upload_pk}&folder={$folder_pk}&newgroup={$newgroup}&newperm=";
         $onchange = "onchange=\"js_url(this.value, '{$url}')\"";
         $Selected = empty($newperm) ? "" : $newperm;
         $V .= Array2SingleSelect($PERM_NAMES, "permselectnew", $Selected, false, false, $onchange);
         $V .= "</td>";
         $V .= "</tr>";
         $V .= "</table>";
         $text = _("All upload permissions take place immediately when a value is changed.  There is no submit button.");
         $V .= "<p>" . $text;
         $text = _("Add new groups on the last line.");
         $V .= "<br>" . $text;
     } else {
         $text = _("You have no permission to change permissions on any upload in this folder.");
         $V .= "<p>{$text}<p>";
     }
     $V .= "<hr>";
     $V .= $this->DisplayGroupMembership();
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }
Ejemplo n.º 28
0
 /**
  * \brief Display the tag info data associated with the file.
  */
 function ShowTagInfo($Upload, $Item)
 {
     $VT = "";
     $text = _("Tag Info");
     $VT .= "<H2>{$text}</H2>\n";
     $groupId = Auth::getGroupId();
     $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"];
     if (empty($lft)) {
         $text = _("Upload data is unavailable.  It needs to be unpacked.");
         return "<h2>{$text} uploadtree_pk: {$Item}</h2>";
     }
     global $PG_CONN;
     $sql = "SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_file,tag WHERE tag_pk = tag_fk) T ON uploadtree.pfile_fk = T.pfile_fk WHERE uploadtree.upload_fk = {$upload_pk} AND uploadtree.lft >= {$lft} AND uploadtree.rgt <= {$rgt} UNION SELECT * FROM uploadtree INNER JOIN (SELECT * FROM tag_uploadtree,tag WHERE tag_pk = tag_fk) T ON uploadtree.uploadtree_pk = T.uploadtree_fk WHERE uploadtree.upload_fk = {$upload_pk} AND uploadtree.lft >= {$lft} AND uploadtree.rgt <= {$rgt} ORDER BY ufile_name";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     if (pg_num_rows($result) > 0) {
         $VT .= "<table border=1>\n";
         $text = _("FileName");
         $text2 = _("Tag");
         $VT .= "<tr><th>{$text}</th><th>{$text2}</th><th></th></tr>\n";
         while ($row = pg_fetch_assoc($result)) {
             $VT .= "<tr><td align='center'>" . $row['ufile_name'] . "</td><td align='center'>" . $row['tag'] . "</td>";
             if ($this->uploadDao->isAccessible($upload_pk, $groupId)) {
                 $VT .= "<td align='center'><a href='" . Traceback_uri() . "?mod=tag&action=edit&upload={$Upload}&item=" . $row['uploadtree_pk'] . "&tag_file_pk=" . $row['tag_file_pk'] . "'>View</a></td></tr>\n";
             } else {
                 $VT .= "<td align='center'></td></tr>\n";
             }
         }
         $VT .= "</table><p>\n";
     }
     pg_free_result($result);
     return $VT;
 }
Ejemplo n.º 29
0
 /**
  * \brief Display the loaded menu and plugins.
  */
 function Output()
 {
     if ($this->State != PLUGIN_STATE_READY) {
         return;
     }
     global $Plugins;
     $CriteriaCount = 0;
     $V = "";
     $GETvars = "";
     $Item = GetParm("item", PARM_INTEGER);
     if ($this->OutputType != 'HTML') {
         return;
     }
     /* Show path if searching an item tree  (don't show on global searches) */
     if ($Item) {
         $V .= Dir2Browse($this->Name, $Item, NULL, 1, NULL) . "<P />\n";
         $GETvars .= "&item={$Item}";
     }
     $searchtype = GetParm("searchtype", PARM_STRING);
     $GETvars .= "&searchtype=" . urlencode($searchtype);
     $Filename = GetParm("filename", PARM_RAW);
     if (!empty($Filename)) {
         $CriteriaCount++;
         $GETvars .= "&filename=" . urlencode($Filename);
     }
     $tag = GetParm("tag", PARM_RAW);
     if (!empty($tag)) {
         $CriteriaCount++;
         $GETvars .= "&tag=" . urlencode($tag);
     }
     $SizeMin = GetParm("sizemin", PARM_TEXT);
     if (!empty($SizeMin) && $SizeMin >= 0) {
         $SizeMin = intval($SizeMin);
         $CriteriaCount++;
         $GETvars .= "&sizemin={$SizeMin}";
     }
     $SizeMax = GetParm("sizemax", PARM_TEXT);
     if (!empty($SizeMax) && $SizeMax >= 0) {
         $SizeMax = intval($SizeMax);
         $CriteriaCount++;
         $GETvars .= "&sizemax={$SizeMax}";
     }
     $License = GetParm("license", PARM_RAW);
     if (!empty($License)) {
         $CriteriaCount++;
         $GETvars .= "&license=" . urlencode($License);
     }
     $Copyright = GetParm("copyright", PARM_RAW);
     if (!empty($Copyright)) {
         $CriteriaCount++;
         $GETvars .= "&copyright=" . urlencode($Copyright);
     }
     $Page = GetParm("page", PARM_INTEGER);
     /*******  Input form  *******/
     $V .= "<form action='" . Traceback_uri() . "?mod=" . $this->Name . "' method='POST'>\n";
     /* searchtype:  'allfiles' or 'containers' */
     $ContainersChecked = "";
     $DirectoryChecked = "";
     $AllFilesChecked = "";
     if ($searchtype == 'containers') {
         $ContainersChecked = "checked=\"checked\"";
     } else {
         if ($searchtype == 'directory') {
             $DirectoryChecked = "checked=\"checked\"";
         } else {
             $AllFilesChecked = "checked=\"checked\"";
         }
     }
     $text = _("Limit search to (Note: can not limit license and copyright search on containers)");
     $text1 = _("Containers only (rpms, tars, isos, etc), including directories.");
     $V .= "<u><i><b>{$text}:</b></i></u><br> <input type='radio' name='searchtype' value='containers' {$ContainersChecked}><b>{$text1}</b>\n";
     $text2 = _("Containers only (rpms, tars, isos, etc), excluding directories.");
     $V .= "<br> <input type='radio' name='searchtype' value='directory' {$DirectoryChecked}><b>{$text2}</b>\n";
     $text3 = _("All Files");
     $V .= "<br> <input type='radio' name='searchtype' value='allfiles' {$AllFilesChecked}><b>{$text3}</b>\n";
     $V .= "<p><u><i><b>" . _("You must choose one or more search criteria (not case sensitive).") . "</b></i></u>";
     $V .= "<ul>\n";
     /* filename */
     $text = _("Enter the filename to find: ");
     $V .= "<li><b>{$text}</b>";
     $V .= "<INPUT type='text' name='filename' size='40' value='" . htmlentities($Filename) . "'>\n";
     $V .= "<br>" . _("You can use '%' as a wild-card. ");
     $V .= _("For example, '%v3.war', or 'mypkg%.tar'.");
     /* tag  */
     $text = _("Tag to find");
     $V .= "<li><b>{$text}:</b>  <input name='tag' size='30' value='" . htmlentities($tag) . "'>\n";
     /* file size >= */
     $text = _("File size is");
     $text1 = _(" bytes\n");
     $V .= "<li><b>{$text} &ge; </b><input name='sizemin' size=10 value='{$SizeMin}'>{$text1}";
     /* file size <= */
     $text = _("File size is");
     $text1 = _(" bytes\n");
     $V .= "<li><b>{$text} &le; </b><input name='sizemax' size=10 value='{$SizeMax}'>{$text1}";
     $V .= "</ul>\n";
     $V .= "<ul>\n";
     $V .= "<p><u><i><b>" . _("You may also choose one or more optional search filters (not case sensitive).") . "</b></i></u>";
     /* license */
     $text = _("License");
     $V .= "<li><b>{$text}: </b><input name='license' value='{$License}'>";
     $V .= "<br>" . _("For example, 'AGPL%'.");
     $text = _("Copyright");
     $V .= "<li><b>{$text}: </b><input name='copyright' value='{$Copyright}'>";
     $V .= "<br>" . _("For example, 'fsf'.");
     $V .= "</ul>\n";
     $V .= "<input type='hidden' name='item' value='{$Item}'>\n";
     $text = _("Search");
     $V .= "<input type='submit' value='{$text}'>\n";
     $V .= "</form>\n";
     /*******  END Input form  *******/
     if ($CriteriaCount) {
         if (empty($Page)) {
             $Page = 0;
         }
         $V .= "<hr>\n";
         $text = _("Files matching");
         $V .= "<H2>{$text} " . htmlentities($Filename) . "</H2>\n";
         $UploadtreeRecs = $this->GetResults($Item, $Filename, $tag, $Page, $SizeMin, $SizeMax, $searchtype, $License, $Copyright);
         $V .= $this->HTMLResults($UploadtreeRecs, $Page, $GETvars, $License, $Copyright);
     }
     $this->vars['content'] = $V;
 }
Ejemplo n.º 30
0
 /**
  * \brief test for Traceback_uri()
  */
 function test_Traceback_uri()
 {
     print "test function Traceback_uri()\n";
     $source = "http://fossology.org/?mod=test&parm=abc";
     $expected = "http://fossology.org/";
     $_SERVER['REQUEST_URI'] = $source;
     $result = Traceback_uri();
     $this->assertEquals($expected, $result);
 }