/**
  * @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;
 }
示例#2
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;
}
示例#3
0
 /**
  * \brief The Picker page
  */
 function Output()
 {
     global $PG_CONN;
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     /**
      * create table if it doesn't exist (not assuming Install() was run.
      * eg. source update
      */
     $this->Create_file_picker();
     $RtnMod = GetParm("rtnmod", PARM_TEXT);
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     $uploadtree_pk2 = GetParm("item2", PARM_INTEGER);
     $folder_pk = GetParm("folder", PARM_INTEGER);
     $user_pk = $_SESSION['UserId'];
     /* Item to start Browse window on */
     $Browseuploadtree_pk = GetParm("bitem", PARM_INTEGER);
     /* Check item1 and item2 upload permissions */
     $Item1Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk}");
     $UploadPerm = GetUploadPerm($Item1Row['upload_fk']);
     if ($UploadPerm < PERM_READ) {
         $text = _("Permission Denied");
         echo "<h2>{$text} item 1<h2>";
         return;
     }
     if (!empty($uploadtree_pk2)) {
         $Item2Row = GetSingleRec("uploadtree", "WHERE uploadtree_pk = {$uploadtree_pk2}");
         $UploadPerm = GetUploadPerm($Item2Row['upload_fk']);
         if ($UploadPerm < PERM_READ) {
             $text = _("Permission Denied");
             echo "<h2>{$text} item 2<h2>";
             return;
         }
     }
     /**
      * After picking an item2, this logic will record the pick in
      * the picker history, and then redirect both item1 and item2 to the
      * comparison app.
      */
     if (!empty($user_pk) && !empty($RtnMod) && !empty($uploadtree_pk) && !empty($uploadtree_pk2)) {
         // Record pick
         $sql = "insert into file_picker (user_fk, uploadtree_fk1, uploadtree_fk2, last_access_date)\n             values({$user_pk}, {$uploadtree_pk}, {$uploadtree_pk2}, now())";
         // ignore errors (most probably a duplicate key)
         @($result = pg_query($PG_CONN, $sql));
         // Redirect to diff module
         $uri = Traceback_uri() . "?mod={$RtnMod}&item1={$uploadtree_pk}&item2={$uploadtree_pk2}";
         echo "<script type='text/javascript'> window.location.assign('{$uri}');</script>";
         exit;
     }
     $OutBuf = "";
     switch ($this->OutputType) {
         case "XML":
             break;
         case "HTML":
             if (empty($uploadtree_pk)) {
                 $OutBuf = "<h2>Picker URL is missing the first comparison file.</h2>";
             } else {
                 $PathArray = Dir2Path($uploadtree_pk, 'uploadtree');
                 $OutBuf .= $this->HTMLout($RtnMod, $uploadtree_pk, $Browseuploadtree_pk, $folder_pk, $PathArray);
             }
             break;
         case "Text":
             break;
         default:
     }
     if (!$this->OutputToStdout) {
         return $OutBuf;
     }
     print "{$OutBuf}";
     return;
 }
示例#4
0
 /**
  * \brief This function returns the scheduler status.
  */
 function Output()
 {
     global $PG_CONN;
     global $SysConf;
     $V = "";
     $formVars = array();
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     if (empty($uploadtree_pk)) {
         return;
     }
     $upload_pk = GetParm("upload", PARM_INTEGER);
     if (empty($upload_pk)) {
         return;
     }
     if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
         $text = _("Permission Denied");
         return "<h2>{$text}</h2>";
     }
     $uploadtreeTablename = GetUploadtreeTableName($upload_pk);
     $warnings = array();
     $agent_pks_dict = $this->getAgentPksFromRequest($upload_pk);
     $agent_pks = array();
     foreach ($agent_pks_dict as $agent_name => $agent_pk) {
         if ($agent_pk === false) {
             $warnings[] = _("No information for agent: {$agent_name}");
         } else {
             $agent_pks[] = $agent_pk;
             $formVars["agentToInclude_" . $agent_name] = "1";
         }
     }
     $dltext = GetParm("output", PARM_STRING) == 'dltext';
     $formVars["dltext"] = $dltext;
     $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
     $formVars["NomostListNum"] = $NomostListNum;
     $includeSubfolder = GetParm("doNotIncludeSubfolder", PARM_STRING) !== "yes";
     $formVars["includeSubfolder"] = $includeSubfolder;
     $ignore = GetParm("showContainers", PARM_STRING) !== "yes";
     $formVars["showContainers"] = !$ignore;
     $exclude = GetParm("exclude", PARM_STRING);
     $formVars["exclude"] = $exclude;
     $V .= $this->renderString("ui-license-list-form.html.twig", $formVars);
     $V .= "<hr/>";
     $lines = $this->createListOfLines($uploadtreeTablename, $uploadtree_pk, $agent_pks, $NomostListNum, $includeSubfolder, $exclude, $ignore);
     if (array_key_exists("warn", $lines)) {
         $warnings[] = $lines["warn"];
         unset($lines["warn"]);
     }
     foreach ($warnings as $warning) {
         $V .= "<br><b>{$warning}</b><br>";
     }
     if ($dltext) {
         $request = $this->getRequest();
         $itemId = intval($request->get('item'));
         $path = Dir2Path($itemId, $uploadtreeTablename);
         $fileName = $path[count($path) - 1]['ufile_name'] . ".txt";
         $headers = array("Content-Type" => "text", "Content-Disposition" => "attachment; filename=\"{$fileName}\"");
         $response = new Response(implode("\n", $lines), Response::HTTP_OK, $headers);
         return $response;
     } else {
         return $V . '<pre>' . implode("\n", $lines) . '</pre>';
     }
 }
示例#5
0
/**
 * \brief get bucket list of one specified upload or all uploads
 *
 * \pamam $upload_pk - upload id
 * \param $bucket_pk - bucket id
 * \param $bucket_agent - bucket agent ID
 * \param $nomos_agent - nomos agent ID
 * \prram $uploadtree_pk - uploadtree ID
 */
function GetBucketList($bucket_pk, $bucket_agent, $nomos_agent, $uploadtree_pk, $upload_pk = 0)
{
    global $PG_CONN;
    global $excluding;
    /** get bucket name */
    $sql = "SELECT bucket_name from bucket_def where bucket_pk = {$bucket_pk};";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $row = pg_fetch_assoc($result);
    pg_free_result($result);
    $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
    /* get the top of tree */
    $sql = "SELECT upload_fk, lft, rgt, uploadtree_pk  from {$uploadtree_tablename}";
    if ($uploadtree_pk) {
        // if uploadtree_pk is null, that means get all data on an upload
        $sql .= " where uploadtree_pk='{$uploadtree_pk}';";
    } else {
        $sql .= " where upload_fk='{$upload_pk}' and parent is null;";
    }
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $toprow = pg_fetch_assoc($result);
    $uploadtree_pk = $toprow['uploadtree_pk'];
    pg_free_result($result);
    if (empty($toprow)) {
        print "Sorry, Can not find upload {$upload_pk}.\n";
        return 1;
    }
    print "For uploadtree {$uploadtree_pk} under upload {$upload_pk} has bucket {$row['bucket_name']}:\n";
    /* loop through all the records in this tree */
    $sql = "select uploadtree_pk, ufile_name, lft, rgt from {$uploadtree_tablename}, bucket_file\n    where upload_fk={$upload_pk}\n    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n    and ((ufile_mode & (1<<28)) = 0)  and ((ufile_mode & (1<<29)) = 0) and bucket_file.pfile_fk = {$uploadtree_tablename}.pfile_fk\n    and bucket_fk = '{$bucket_pk}' and agent_fk = '{$bucket_agent}' and nomosagent_fk = '{$nomos_agent}'\n    order by uploadtree_pk";
    $outerresult = pg_query($PG_CONN, $sql);
    /* Select each uploadtree row in this tree, write out text */
    $excluding_flag = 0;
    // 1: exclude 0: not exclude
    while ($row = pg_fetch_assoc($outerresult)) {
        $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
        $filepath = "";
        foreach ($filepatharray as $uploadtreeRow) {
            if (!empty($filepath)) {
                $filepath .= "/";
                /* filepath contains 'xxxx/', '/xxxx/', 'xxxx', '/xxxx' */
                $excluding_flag = ContainExcludeString($filepath, $excluding);
                if (1 == $excluding_flag) {
                    break;
                }
            }
            $filepath .= $uploadtreeRow['ufile_name'];
        }
        if (1 == $excluding_flag) {
            continue;
        }
        // excluding files whose path contains excluding text
        $V = $filepath;
        print "{$V}";
        print "\n";
    }
    pg_free_result($outerresult);
}
/**
 * \brief get nomos license list of one specified uploadtree_id
 *
 * \param $uploadtree_pk - uploadtree id
 * \param $upload_pk - upload id
 * \param $container - include container or not, 1: yes, 0: no (default)
 */
function GetLicenseList($uploadtree_pk, $upload_pk, $container = 0)
{
    global $PG_CONN;
    if (empty($uploadtree_pk)) {
        /* Find the uploadtree_pk for this upload so that it can be used in the browse link */
        $uploadtreeRec = GetSingleRec("uploadtree", "where parent is NULL and upload_fk='{$upload_pk}'");
        $uploadtree_pk = $uploadtreeRec['uploadtree_pk'];
    }
    //  print "Upload ID:$upload_pk; Uploadtree ID:$uploadtree_pk\n";
    /* get last nomos agent_pk that has data for this upload */
    $Agent_name = "nomos";
    $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1);
    $agent_pk = $AgentRec[0]["agent_fk"];
    if ($AgentRec === false) {
        echo _("No data available");
        return;
    }
    /* get the top of tree */
    $sql = "SELECT upload_fk, lft, rgt from uploadtree where uploadtree_pk='{$uploadtree_pk}';";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $toprow = pg_fetch_assoc($result);
    pg_free_result($result);
    $uploadtree_tablename = GetUploadtreeTableName($toprow['upload_fk']);
    /* loop through all the records in this tree */
    $sql = "select uploadtree_pk, ufile_name, lft, rgt from {$uploadtree_tablename} \n              where upload_fk='{$toprow['upload_fk']}' \n                    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n                    and ((ufile_mode & (1<<28)) = 0)";
    $container_sql = " and ((ufile_mode & (1<<29)) = 0)";
    /* include container or not */
    if (empty($container)) {
        $sql .= $container_sql;
        // do not include container
    }
    $sql .= "order by uploadtree_pk";
    $outerresult = pg_query($PG_CONN, $sql);
    DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
    /* Select each uploadtree row in this tree, write out text:
     * filepath : license list
     * e.g. Pound-2.4.tgz/Pound-2.4/svc.c: GPL_v3+, Indemnity
     */
    while ($row = pg_fetch_assoc($outerresult)) {
        $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
        $filepath = "";
        foreach ($filepatharray as $uploadtreeRow) {
            if (!empty($filepath)) {
                $filepath .= "/";
            }
            $filepath .= $uploadtreeRow['ufile_name'];
        }
        $V = $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtree_tablename);
        #$V = $filepath;
        print "{$V}";
        print "\n";
    }
    pg_free_result($outerresult);
}
 /**
  * \brief This function is called when user output is
  * requested.  This function is responsible for assigning headers.
  * If $Type is "HTML" then generate an HTTP header.
  * If $Type is "XML" then begin an XML header.
  * If $Type is "Text" then generate a text header as needed.
  * The $ToStdout flag is "1" if output should go to stdout, and
  * 0 if it should be returned as a string.  (Strings may be parsed
  * and used by other plugins.)
  */
 function OutputOpen($Type, $ToStdout)
 {
     global $Plugins;
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     if (GetParm("output", PARM_STRING) == 'csv') {
         $Type = 'CSV';
     }
     $this->OutputType = $Type;
     $this->OutputToStdout = $ToStdout;
     $Item = GetParm("item", PARM_INTEGER);
     if (empty($Item)) {
         return;
     }
     switch ($this->OutputType) {
         case "CSV":
             $this->NoHeader = 1;
             $Path = Dir2Path($Item);
             $Name = $Path[count($Path) - 1]['ufile_name'] . ".csv";
             header("Content-Type: text/comma-separated-values");
             header('Content-Disposition: attachment; filename="' . $Name . '"');
             break;
         case "XML":
             $V = "<xml>\n";
             break;
         case "HTML":
             header('Content-type: text/html');
             if ($this->NoHTML) {
                 return;
             }
             $V = "";
             if ($this->NoMenu == 0 && $this->Name != "menus") {
                 $Menu =& $Plugins[plugin_find_id("menus")];
                 $Menu->OutputSet($Type, $ToStdout);
             } else {
                 $Menu = NULL;
             }
             /* DOCTYPE is required for IE to use styles! (else: css menu breaks) */
             $V .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "xhtml1-frameset.dtd">' . "\n";
             // $V .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">' . "\n";
             // $V .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Loose//EN" "http://www.w3.org/TR/html4/loose.dtd">' . "\n";
             // $V .= '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "xhtml1-strict.dtd">' . "\n";
             $V .= "<html>\n";
             $V .= "<head>\n";
             if ($this->NoHeader == 0) {
                 /** Known bug: DOCTYPE "should" be in the HEADER
                     and the HEAD tags should come first.
                     Also, IE will ignore <style>...</style> tags that are NOT
                     in a <head>...</head> block.
                     *
                     */
                 if (!empty($this->Title)) {
                     $V .= "<title>" . htmlentities($this->Title) . "</title>\n";
                 }
                 $V .= "<link rel='stylesheet' href='fossology.css'>\n";
                 print $V;
                 $V = "";
                 if (!empty($Menu)) {
                     print $Menu->OutputCSS();
                 }
                 $V .= "</head>\n";
                 $V .= "<body class='text'>\n";
                 print $V;
                 $V = "";
                 if (!empty($Menu)) {
                     $Menu->Output($this->Title);
                 }
             }
             break;
         case "Text":
             break;
         default:
             break;
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print $V;
     return;
 }
 /**
  * \brief HTML output, returns HTML as string.
  */
 function HTMLout($Master, $uploadtree_pk1, $uploadtree_pk2, $in_uploadtree_pk1, $in_uploadtree_pk2, $filter, $TreeInfo1, $TreeInfo2)
 {
     /* Initialize */
     $FreezeText = _("Freeze Path");
     $unFreezeText = _("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 .= "}";
     /* 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');";
     /* change the freeze labels to denote their new status */
     $OutBuf .= "if (FreezeColNo == '1')";
     $OutBuf .= "{";
     $OutBuf .= "if (FreezeElt1.innerHTML == '{$unFreezeText}') ";
     $OutBuf .= "{";
     $OutBuf .= "FreezeElt1.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt1.style.backgroundColor = 'white';";
     $OutBuf .= "}";
     $OutBuf .= "else {";
     $OutBuf .= "FreezeElt1.innerHTML = '{$unFreezeText}';";
     $OutBuf .= "FreezeElt1.style.backgroundColor = '#EAF7FB';";
     $OutBuf .= "FreezeElt2.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
     $OutBuf .= "}";
     $OutBuf .= "}";
     $OutBuf .= "else {";
     $OutBuf .= "if (FreezeElt2.innerHTML == '{$unFreezeText}') ";
     $OutBuf .= "{";
     $OutBuf .= "FreezeElt2.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt2.style.backgroundColor = 'white';";
     $OutBuf .= "}";
     $OutBuf .= "else {";
     $OutBuf .= "FreezeElt1.innerHTML = '{$FreezeText}';";
     $OutBuf .= "FreezeElt1.style.backgroundColor = 'white';";
     $OutBuf .= "FreezeElt2.innerHTML = '{$unFreezeText}';";
     $OutBuf .= "FreezeElt2.style.backgroundColor = '#EAF7FB';";
     $OutBuf .= "}";
     $OutBuf .= "}";
     /* Alter the url to add freeze={column number}  */
     $OutBuf .= "var i=0;";
     $OutBuf .= "var linkid;";
     $OutBuf .= "var linkelt;";
     $OutBuf .= "var UpdateCol;";
     $OutBuf .= "if (FreezeColNo == 1) UpdateCol=2;else UpdateCol=1;";
     $OutBuf .= "var numlinks = document.links.length;";
     $OutBuf .= "for (i=0; i < numlinks; i++)";
     $OutBuf .= "{";
     $OutBuf .= "linkelt = document.links[i];";
     $OutBuf .= "if (linkelt.href.indexOf('col='+UpdateCol) >= 0)";
     $OutBuf .= "{";
     $OutBuf .= "linkelt.href = linkelt.href + '&freeze=' + FreezeColNo;";
     $OutBuf .= "}";
     $OutBuf .= "}";
     $OutBuf .= "}";
     $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'>0. Remove nothing";
     $Selected = $filter == 'samehash' ? "selected" : "";
     $SelectFilter .= "<option {$Selected} value='samehash'>1. Remove duplicate (same hash) files";
     $Selected = $filter == 'samelic' ? "selected" : "";
     $SelectFilter .= "<option {$Selected} value='samelic'>2. Remove duplicate files (different hash) with unchanged licenses";
     $Selected = $filter == 'samelicfuzzy' ? "selected" : "";
     $SelectFilter .= "<option {$Selected} value='samelicfuzzy'>2b. Same as 2 but fuzzy match file names";
     $Selected = $filter == 'nolics' ? "selected" : "";
     $SelectFilter .= "<option {$Selected} value='nolics'>3. Same as 2b. but also remove files with no license";
     $SelectFilter .= "</select>";
     $StyleRt = "style='float:right'";
     $OutBuf .= "<a name='flist' href='#histo' {$StyleRt} > Jump to histogram </a><br>";
     /* Switch to bucket diff view */
     $text = _("Switch to bucket view");
     $BucketURL = Traceback_uri();
     $BucketURL .= "?mod=bucketsdiff&item1={$uploadtree_pk1}&item2={$uploadtree_pk2}";
     $OutBuf .= "<a href='{$BucketURL}' {$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, $TreeInfo1['uploadtree_tablename']);
     $Path2 = Dir2Path($uploadtree_pk2, $TreeInfo2['uploadtree_tablename']);
     $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']);
     /*  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);
     $OutBuf .= "<td colspan=2 valign='top' align='center'>{$Tree1Hist}</td>";
     $OutBuf .= "<td {$this->ColumnSeparatorStyleL}>&nbsp;</td>";
     $Tree2Hist = $this->UploadHist($uploadtree_pk2, $TreeInfo2);
     $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;
 }
示例#9
0
 /**
  * \brief This function returns the scheduler status.
  */
 function Output()
 {
     global $SysConf;
     global $PG_CONN;
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     if (empty($uploadtree_pk)) {
         return;
     }
     $upload_pk = GetParm("upload", PARM_INTEGER);
     if (empty($upload_pk)) {
         return;
     }
     if (!$this->uploadDao->isAccessible($upload_pk, Auth::getGroupId())) {
         $text = _("Permission Denied");
         return "<h2>{$text}</h2>";
     }
     $dltext = GetParm("output", PARM_STRING) == 'dltext';
     /* get last nomos agent_pk that has data for this upload */
     $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1);
     $agent_pk = $AgentRec[0]["agent_fk"];
     if ($AgentRec === false) {
         return _("No data available");
     }
     /* how many lines of data do you want to display */
     $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
     /* get the top of tree */
     $toprow = $this->uploadDao->getUploadEntry($uploadtree_pk);
     /* loop through all the records in this tree */
     $sql = "select uploadtree_pk, ufile_name, lft, rgt from uploadtree\n              where upload_fk='{$toprow['upload_fk']}' \n                    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n                    and (ufile_mode & (3<<28)) = 0 limit {$NomostListNum}";
     $outerresult = pg_query($PG_CONN, $sql);
     DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
     /* Select each uploadtree row in this tree, write out text:
      * filepath : license list
      * e.g. Pound-2.4.tgz/Pound-2.4/svc.c: GPL_v3+, Indemnity
      */
     $uploadtreeTablename = $this->uploadDao->getUploadtreeTableName($toprow['upload_fk']);
     $lines = array();
     while ($row = pg_fetch_assoc($outerresult)) {
         $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtreeTablename);
         $filepath = "";
         foreach ($filepatharray as $uploadtreeRow) {
             if (!empty($filepath)) {
                 $filepath .= "/";
             }
             $filepath .= $uploadtreeRow['ufile_name'];
         }
         $lines[] = $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtreeTablename);
     }
     $RealNumber = pg_num_rows($outerresult);
     pg_free_result($outerresult);
     if ($RealNumber == $NomostListNum) {
         $V .= _("<br><b>Warning: Only the last {$NomostListNum} lines are displayed.  To see the whole list, run fo_nomos_license_list from the command line.</b><br>");
     }
     if ($dltext) {
         $request = $this->getRequest();
         $itemId = intval($request->get('item'));
         $path = Dir2Path($itemId, $uploadtreeTablename);
         $fileName = $path[count($path) - 1]['ufile_name'] . ".txt";
         $headers = array("Content-Type" => "text", "Content-Disposition" => "attachment; filename=\"{$fileName}\"");
         $response = new Response(implode("\n", $lines), Response::HTTP_OK, $headers);
         return $response;
     } else {
         return $V . '<pre>' . implode("\n", $lines) . '</pre>';
     }
 }
/**
 * \brief get bucket list of one specified upload or all uploads
 *
 * \pamam $upload_pk - upload id
 * \param $bucket_pk - bucket id
 */
function GetBucketList($bucket_pk, $upload_pk = 0)
{
    global $PG_CONN;
    $sql = "SELECT bucket_name from  bucket_def where bucket_pk = {$bucket_pk};";
    $result = pg_query($PG_CONN, $sql);
    DBCheckResult($result, $sql, __FILE__, __LINE__);
    $row = pg_fetch_assoc($result);
    pg_free_result($result);
    if ($upload_pk) {
        $text = "upload {$upload_pk}";
    } else {
        $text = "all uploads";
    }
    print "Get all files have bucket {$row['bucket_name']} for {$text} \n";
    $uploadtree_tablename = GetUploadtreeTableName($upload_pk);
    $sql_upload = '';
    if ($upload_pk) {
        $sql_upload = "and upload_fk = {$upload_pk}";
    }
    $sql = "SELECT DISTINCT uploadtree_pk from pfile, bucket_file, uploadtree where pfile_pk = bucket_file.pfile_fk and pfile_pk = uploadtree.pfile_fk and bucket_fk = {$bucket_pk} and ((ufile_mode & (1<<28)) = 0) and ((ufile_mode & (1<<29)) = 0) {$sql_upload} order by uploadtree_pk;";
    $outerresult = pg_query($PG_CONN, $sql);
    DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
    /* Select each uploadtree row in this tree, write out text:
     * filepath : bucket list
     */
    while ($row = pg_fetch_assoc($outerresult)) {
        $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
        $filepath = "";
        foreach ($filepatharray as $uploadtreeRow) {
            if (!empty($filepath)) {
                $filepath .= "/";
            }
            $filepath .= $uploadtreeRow['ufile_name'];
        }
        $V = $filepath;
        print "{$V}";
        print "\n";
    }
    pg_free_result($outerresult);
}
 /**
  * \brief This function returns the scheduler status.
  */
 function Output()
 {
     global $SysConf;
     global $PG_CONN;
     if (!$PG_CONN) {
         echo _("NO DB connection");
     }
     if ($this->State != PLUGIN_STATE_READY) {
         return 0;
     }
     $V = "";
     $uploadtree_pk = GetParm("item", PARM_INTEGER);
     if (empty($uploadtree_pk)) {
         return;
     }
     $upload_pk = GetParm("upload", PARM_INTEGER);
     if (empty($upload_pk)) {
         return;
     }
     $UploadPerm = GetUploadPerm($upload_pk);
     if ($UploadPerm < PERM_READ) {
         $text = _("Permission Denied");
         echo "<h2>{$text}<h2>";
         return;
     }
     if (GetParm("output", PARM_STRING) == 'dltext') {
         $dltext = true;
     } else {
         $dltext = false;
     }
     /* get last nomos agent_pk that has data for this upload */
     $Agent_name = "nomos";
     $AgentRec = AgentARSList("nomos_ars", $upload_pk, 1);
     $agent_pk = $AgentRec[0]["agent_fk"];
     if ($AgentRec === false) {
         echo _("No data available");
         return;
     }
     /* how many lines of data do you want to display */
     $NomostListNum = @$SysConf['SYSCONFIG']['NomostListNum'];
     /* get the top of tree */
     $sql = "SELECT upload_fk, lft, rgt from uploadtree where uploadtree_pk='{$uploadtree_pk}'";
     $result = pg_query($PG_CONN, $sql);
     DBCheckResult($result, $sql, __FILE__, __LINE__);
     $toprow = pg_fetch_assoc($result);
     pg_free_result($result);
     /* loop through all the records in this tree */
     $sql = "select uploadtree_pk, ufile_name, lft, rgt from uploadtree\n              where upload_fk='{$toprow['upload_fk']}' \n                    and lft>'{$toprow['lft']}'  and rgt<'{$toprow['rgt']}'\n                    and ((ufile_mode & (1<<28)) = 0) and ((ufile_mode & (1<<29)) = 0) limit {$NomostListNum}";
     $outerresult = pg_query($PG_CONN, $sql);
     DBCheckResult($outerresult, $sql, __FILE__, __LINE__);
     /* Select each uploadtree row in this tree, write out text:
      * filepath : license list
      * e.g. Pound-2.4.tgz/Pound-2.4/svc.c: GPL_v3+, Indemnity
      */
     $uploadtree_tablename = GetUploadtreeTableName($toprow['upload_fk']);
     while ($row = pg_fetch_assoc($outerresult)) {
         $filepatharray = Dir2Path($row['uploadtree_pk'], $uploadtree_tablename);
         $filepath = "";
         foreach ($filepatharray as $uploadtreeRow) {
             if (!empty($filepath)) {
                 $filepath .= "/";
             }
             $filepath .= $uploadtreeRow['ufile_name'];
         }
         $V .= $filepath . ": " . GetFileLicenses_string($agent_pk, 0, $row['uploadtree_pk'], $uploadtree_tablename);
         if ($dltext) {
             $V .= "\n";
         } else {
             $V .= "<br>";
         }
     }
     $RealNumber = pg_num_rows($outerresult);
     pg_free_result($outerresult);
     if ($RealNumber == $NomostListNum) {
         $V .= _("<br><B>Warning: Only the last {$NomostListNum} lines are displayed.  To see the whole list, run fo_nomos_license_list from the command line.</B><br>");
     }
     if (!$this->OutputToStdout) {
         return $V;
     }
     print "{$V}";
     return;
 }