]> git.pld-linux.org Git - projects/buildlogs.git/commitdiff
- simplify dual interface
authorankry <ankry@pld-linux.org>
Sun, 22 Sep 2002 16:10:17 +0000 (16:10 +0000)
committerankry <ankry@pld-linux.org>
Sun, 22 Sep 2002 16:10:17 +0000 (16:10 +0000)
obsolete/buildlogs/index.php

index 0e639cb9fda9681a2684aad10de104be2913640b..302fe0ffa5fe98ec45b7a6eacff6c14b45787e4e 100644 (file)
@@ -30,6 +30,7 @@ $qa_addr = array(
 );
 $local = 1; /* $local=0 for FTP */ 
 $root_directory = "/home/services/ftp/pub/logs";
+$ftp_conn = 0;
 /* It should be set */
 
 
@@ -92,30 +93,30 @@ function open_ftp()
        global $idx, $addr, $buildlogs_server, $ok;
        global $ftp_conn, $big_url, $url, $ns;
        global $off, $cnt;
-       
+
        if (!isset($idx) || !isset($addr[$idx]))
                return false;
-       
+
        if ($ok != 1)
                $ok = 0;
        if ($ns != 1)
                $ns = 0;
-               
+
        if ($ok == 1) {
                $a = "$addr[$idx]/OK";
        } else {
                $a = "$addr[$idx]/FAIL";
        }
-       
+
        if (!isset($off))
                $off = 0;
        if (!isset($cnt))
                $cnt = 16;
-               
+
        $big_url = "$url?idx=$idx&ok=$ok&ns=$ns&cnt=$cnt";
-       
+
        $ftp = ftp_connect($buildlogs_server);
-       
+
        if ($ftp == false) {
                mydie("cannot connect to $buildlogs_server");
                return false;
@@ -136,7 +137,7 @@ function open_ftp()
        }
 
        $ftp_conn = $ftp;
-       
+
        return $list;
 }
 
@@ -145,28 +146,28 @@ function directory_list()
        global $idx, $addr, $buildlogs_server, $ok;
        global $root_directory, $big_url, $url, $ns;
        global $off, $cnt;
-       
+
        if (!isset($idx) || !isset($addr[$idx]))
                return false;
-       
+
        if ($ok != 1)
                $ok = 0;
        if ($ns != 1)
                $ns = 0;
-               
+
        if ($ok == 1) {
                $a = "$addr[$idx]/OK";
        } else {
                $a = "$addr[$idx]/FAIL";
        }
-       
+
        if (!isset($off))
                $off = 0;
        if (!isset($cnt))
                $cnt = 16;
-               
+
        $big_url = "$url?idx=$idx&ok=$ok&ns=$ns&cnt=$cnt";
-       
+
        $dir = opendir("$root_directory$a");
        $i = 0;
        while ($file = readdir($dir)) {
@@ -182,14 +183,17 @@ function directory_list()
 function list_logs()
 {
        global $idx, $addr, $ok;
-       global $ftp_conn, $big_url, $ns;
-       global $off, $cnt, $qa_addr;
-
-       $list = open_ftp();
+       global $ftp_conn, $big_url, $ns, $qa_addr;
+       global $off, $cnt, $local, $root_directory;
 
+       if ($local) {
+               $list = directory_list();
+       } else {
+               $list = open_ftp();
+       }
        if ($list == false)
                return;
-       
+
        if ($ok == 1) {
                echo "<h1>Listing of $addr[$idx]/OK "
                        ."(<a href=\"$big_url&ok=0\">fail</a>)</h1>";
@@ -197,7 +201,7 @@ function list_logs()
                echo "<h1>Listing of $addr[$idx]/FAIL "
                        ."(<a href=\"$big_url&ok=1\">ok</a>)</h1>";
        }
-       
+
        echo "<div align=center><table border=0 cellspacing=1 ".
                "cellpadding=3 bgcolor=#000000 width=90%>\n";
        echo "<tr><th bgcolor=#CCCCFF align=left width=60%>Log File ".
@@ -206,10 +210,11 @@ function list_logs()
                 "<th bgcolor=#CCCCFF align=left>Age ".
                         "[<a href=\"$big_url&ns=0\">sort</a>]</th>".
                 "</th></tr>";
-       
-       function cmp($f1, $f2) {
-               global $ftp_conn;
 
+       function cmp($f1, $f2) {
+               global $ftp_conn, $root_directory, $local;
+               if ($local)
+                       return filemtime("$root_directory$f2") - filemtime("$root_directory$f1");
                return ftp_mdtm($ftp_conn, $f2) - ftp_mdtm($ftp_conn, $f1);
        }
 
@@ -219,7 +224,7 @@ function list_logs()
        } else {
                sort($list);
        }
-       
+
        $now = time();
        for ($i = $off; $i < $cnt + $off; $i++) {
                if (!isset($list[$i]))
@@ -227,134 +232,13 @@ function list_logs()
                $h = bin2hex(mhash(MHASH_MD5, $list[$i]));
                $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $list[$i]);
                $f = preg_replace("/\.(bz2|gz)$/", "", $f);
-               $s = ftp_size($ftp_conn, $list[$i]);
-               $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
-               $t /= 60;
-               if ($t >= 60) {
-                       $t /= 60;
-                       if ($t >= 24) {
-                               $t /= 24;
-                               $t = round($t);
-                               if ($t > 1) {
-                                       $t = $t . " days";
-                               } else {
-                                       $t = $t . " day";
-                               }
-                       } else {
-                               $t = round($t);
-                               if ($t > 1) {
-                                       $t = $t . " hours";
-                               } else {
-                                       $t = $t . " hour";
-                               }
-                       }
+               if ($local) {
+                       $s = filesize("$root_directory$list[$i]");
+                       $t = $now - filemtime("$root_directory$list[$i]");
                } else {
-                       $t = round($t);
-                       if ($t != 1) {
-                               $t = $t . " minutes";
-                       } else {
-                               $t = $t . " minute";
-                       }
+                       $s = ftp_size($ftp_conn, $list[$i]);
+                       $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
                }
-               $u = "$big_url&off=$off&id=$h";
-               echo "<tr><td bgcolor=#CCCCCC><a ".
-                       "href=\"$u\">".
-                    "$f</a> ".
-                    "[<a href=\"$u&action=text\">text</a> | ".
-                     "<a href=\"$u&action=tail\">tail</a>]".
-                    "</td><td bgcolor=#CCCCCC align=right>".
-                    "$s</td><td bgcolor=#CCCCCC>$t</td></tr>\n";
-       }
-       echo "</table></div>\n";
-
-       $back = "&lt;&lt;&lt; Page back";
-       $forward = "Page forward &gt;&gt;&gt;";
-
-       echo "<p align=center><table width=90%><tr><td align=left width=25%>";
-
-       if ($off > 0) {
-               $noff = $off - $cnt;
-               if ($noff < 0)  
-                       $noff = 0;
-               echo "<a href=\"$big_url&off=$noff\">$back</a>\n";
-       } else {
-               echo "$back\n";
-       }
-
-       echo "</td><td width=50% align=center>";
-
-       if ($qa_addr[$idx] != "") {
-               echo "[<a href=\"$big_url&action=qa\">View rpm -qa of ".
-                       "builder</a>]\n";
-       } else {
-               echo "&nbsp;";
-        }
-
-       echo "</td><td align=right width=25%>";
-       if ($off + $cnt < count($list)) {
-               $noff = $off + $cnt;
-               if ($noff < 0)  
-                       $noff = 0;
-               echo "<a href=\"$big_url&off=$noff\">$forward</a>\n";
-       } else {
-               echo "$forward\n";
-       }
-       echo "</td></tr></table></p>";
-
-       ftp_quit($ftp_conn);
-       $ftp_conn = 0;
-}
-
-function local_list_logs()
-{
-       global $idx, $addr, $ok;
-       global $root_directory, $big_url, $ns;
-       global $off, $cnt, $qa_addr;
-
-       $list = directory_list();
-
-       if ($list == false)
-               return;
-       
-       if ($ok == 1) {
-               echo "<h1>Listing of $addr[$idx]/OK "
-                       ."(<a href=\"$big_url&ok=0\">fail</a>)</h1>";
-       } else {
-               echo "<h1>Listing of $addr[$idx]/FAIL "
-                       ."(<a href=\"$big_url&ok=1\">ok</a>)</h1>";
-       }
-       
-       echo "<div align=center><table border=0 cellspacing=1 ".
-               "cellpadding=3 bgcolor=#000000 width=90%>\n";
-       echo "<tr><th bgcolor=#CCCCFF align=left width=60%>Log File ".
-                       "[<a href=\"$big_url&ns=1\">sort</a>]</th>".
-                "<th bgcolor=#CCCCFF align=right width=15%>Size</th> ".
-                "<th bgcolor=#CCCCFF align=left>Age ".
-                        "[<a href=\"$big_url&ns=0\">sort</a>]</th>".
-                "</th></tr>";
-       
-       function cmp($f1, $f2) {
-               global $root_directory;
-               
-       return filemtime("$root_directory$f2") - filemtime("$root_directory$f1");
-       }
-
-       if ($ns != 1) {
-               $ns = 0;
-               usort($list, cmp);
-       } else {
-               sort($list);
-       }
-       
-       $now = time();
-       for ($i = $off; $i < $cnt + $off; $i++) {
-               if (!isset($list[$i]))
-                       continue;
-               $h = bin2hex(mhash(MHASH_MD5, $list[$i]));
-               $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $list[$i]);
-               $f = preg_replace("/\.(bz2|gz)$/", "", $f);
-               $s = filesize("$root_directory$list[$i]");
-               $t = $now - filemtime("$root_directory$list[$i]");
                $t /= 60;
                if ($t >= 60) {
                        $t /= 60;
@@ -393,8 +277,8 @@ function local_list_logs()
        }
        echo "</table></div>\n";
 
-       $back = "&lt;&lt;&lt; Page back";
-       $forward = "Page forward &gt;&gt;&gt;";
+       $back = "<table><tr><td>&lt;&lt;&lt;</td><td> Poprzednia strona</td></tr></table>";
+       $forward = "<table><tr><td>Nastêpna strona </td><td>&gt;&gt;&gt;</td></tr></table>";
 
        echo "<p align=center><table width=90%><tr><td align=left width=25%>";
 
@@ -414,8 +298,8 @@ function local_list_logs()
                        "builder</a>]\n";
        } else {
                echo "&nbsp;";
-        }
+       }
+
        echo "</td><td align=right width=25%>";
        if ($off + $cnt < count($list)) {
                $noff = $off + $cnt;
@@ -426,51 +310,25 @@ function local_list_logs()
                echo "$forward\n";
        }
        echo "</td></tr></table></p>";
-}
-
-function file_name()
-{
-       global $idx, $addr, $ok;
-       global $ftp_conn, $big_url, $ns, $id;
-       global $buildlogs_server;
-
-       if (!isset($id))
-               return false;
-               
-       $list = open_ftp();
-
-       if ($list == false)
-               return false;
-
-       $f = false;
-       for ($i = 0; $i < count($list); $i++) {
-               $h = bin2hex(mhash(MHASH_MD5, $list[$i]));
-               if ($h == $id) {
-                       $f = $list[$i];
-               }
-       }
-
-       if ($f == false) {
-               mydie("cannot find specified file: $id");
+       if ($local == 0) {
                ftp_quit($ftp_conn);
-               return false;
+               $ftp_conn = 0;
        }
-
-       return $f;
 }
 
-
-function local_file_name()
+function file_name()
 {
        global $idx, $addr, $ok;
-       global $root_directory, $big_url, $ns, $id;
-       global $buildlogs_server;
+       global $ftp_conn, $root_directory, $big_url, $ns, $id;
+       global $buildlogs_server, $local;
 
        if (!isset($id))
                return false;
-               
-       $list = directory_list();
-
+       if ($local) {
+               $list = directory_list();
+       } else {
+               $list = open_ftp();
+       }
        if ($list == false)
                return false;
 
@@ -484,18 +342,19 @@ function local_file_name()
 
        if ($f == false) {
                mydie("cannot find specified file: $id");
+               if ($local == 0)
+                       ftp_quit($ftp_conn);
                return false;
        }
 
        return $f;
 }
 
-
 function dump_log($tail)
 {
        global $idx, $addr, $ok, $url;
-       global $ftp_conn, $big_url, $ns, $id, $cnt, $off;
-       global $buildlogs_server, $qa_addr;
+       global $ftp_conn, $root_directory, $big_url, $ns, $id, $cnt, $off;
+       global $buildlogs_server, $local, $qa_addr;
 
        $f = file_name();
 
@@ -504,7 +363,7 @@ function dump_log($tail)
 
        $df = preg_replace("/.*\/([^\/]*)$/", "\\1", $f);
        $df = preg_replace("/\.(bz2|gz)$/", "", $df);
-       
+
        echo "<h1>$df</h1>";
 
        echo "<table border=0 cellpadding=3 cellspacing=1 bgcolor=#000000>";
@@ -517,7 +376,7 @@ function dump_log($tail)
        function href($h, $c) {
                return "<a href=\"$h\">$c</a>";
        }
-       
+
        one_item("Status", ($ok == 1 ?  
                                "<font color=green><b>OK</b></font>" : 
                                "<font color=red><b>Failed</b></a>"));
@@ -526,7 +385,7 @@ function dump_log($tail)
                      "ftp://$buildlogs_server$f"));
 
        $bu = "$big_url&off=$off";
-       
+
        one_item("text/plain URL", 
                 href("$bu&id=$id&action=text",
                      "View!"));
@@ -541,7 +400,11 @@ function dump_log($tail)
        } else {
                one_item("rpm -qa of builder", "Not available");
         }
-       one_item("Date", date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)));
+       if ($local) {
+               one_item("Data", date("Y/m/d H:i:s", filemtime("$root_directory$f")));
+       } else {
+               one_item("Data", date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)));
+       }
        /*
        echo "<tr><td>Here:</td><td>" . 
                "<a href=\"$url?idx=$idx&ok=$ok&id=$id\">".
@@ -550,122 +413,29 @@ function dump_log($tail)
             "</td></tr>"; */
 
        echo "</table><h2>Content:</h2>";
-       
-       ftp_quit($ftp_conn);
-       $ftp_conn = 0;
-       
-       
-       # what can I say beside PHP suxx? how the fuck should I create
-       # bidirectional pipe? gotta use wget
-       
-       if (preg_match("/\.bz2$/", $f)) {
-               $filter = "| bzcat 2>&1";
-       } elseif (preg_match("/\.gz$/", $f)) {
-               $filter = "| zcat 2>&1";
-       } else {
-               $filter = "";
-       }
 
-       $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 $filter";
-       if ($tail)
-               $cmd = "$cmd | tail -n 100";
-       $fd = popen($cmd, "r");
-       start_pre();
-       while (($s = fgets($fd, 1000)) != false) {
-               $s = htmlspecialchars($s);
-               echo $s;
-       }
-       end_pre();
-       pclose($fd);
-
-?>
-       <table width=100%>
-        <tr>
-         <td align=left>
-          [<a href="<?php echo $bu; ?>">Back to list of logs</a>]
-         </td>
-         <td align=right>
-          [<a href="<?php echo "$bu&action=qa" 
-               ?>">View rpm -qa of builder</a>]
-         </td>
-        </tr>
-       </table>
-<?php
-
-}
-
-
-function local_dump_log($tail)
-{
-       global $idx, $addr, $ok, $url;
-       global $root_directory, $big_url, $ns, $id, $cnt, $off;
-       global $buildlogs_server, $qa_addr;
-
-       $f = local_file_name();
-
-       if ($f == false)
-               return;
-
-       $df = preg_replace("/.*\/([^\/]*)$/", "\\1", $f);
-       $df = preg_replace("/\.(bz2|gz)$/", "", $df);
-       
-       echo "<h1>$df</h1>";
-
-       echo "<table border=0 cellpadding=3 cellspacing=1 bgcolor=#000000>";
-
-       function one_item($h, $t) {
-               echo "<tr><td bgcolor=#ccccff>$h:</td>".
-                        "<td bgcolor=#cccccc>$t</td></tr>";
-       }
-
-       function href($h, $c) {
-               return "<a href=\"$h\">$c</a>";
+       if ($local == 0) {
+               ftp_quit($ftp_conn);
+               $ftp_conn = 0;
        }
-       
-       one_item("Status", ($ok == 1 ?  
-                               "<font color=green><b>OK</b></font>" : 
-                               "<font color=red><b>Failed</b></a>"));
-       one_item("Source URL", 
-                href("ftp://$buildlogs_server$f", 
-                     "ftp://$buildlogs_server$f"));
 
-       $bu = "$big_url&off=$off";
-       
-       one_item("text/plain URL", 
-                href("$bu&id=$id&action=text",
-                     "View!"));
-       if ($tail) {
-               one_item("full text", 
-                        href("$bu&&id=$id",
-                             "View!"));
-       }
-       
-       if ($qa_addr[$idx] != "") {
-               one_item("rpm -qa of builder", href("$bu&action=qa", "View!"));
-       } else {
-               one_item("rpm -qa of builder", "Not available");
-        }
-       one_item("Date", date("Y/m/d H:i:s", filemtime("$root_directory$f")));
-       /*
-       echo "<tr><td>Here:</td><td>" . 
-               "<a href=\"$url?idx=$idx&ok=$ok&id=$id\">".
-               "http://" . getenv("SERVER_NAME") .
-               getenv("SCRIPT_NAME") . "?idx=$idx&ok=$ok&id=$id</a>" .
-            "</td></tr>"; */
 
-       echo "</table><h2>Content:</h2>";
-       
        # what can I say beside PHP suxx? how the fuck should I create
        # bidirectional pipe? gotta use wget
-       
+
        if (preg_match("/\.bz2$/", $f)) {
-               $cmd = "bzcat $root_directory$f";
+               $filter = "bzcat";
        } elseif (preg_match("/\.gz$/", $f)) {
-               $cmd = "zcat $root_directory$f";
+               $filter = "zcat";
        } else {
-               $cmd = "cat $root_directory$f";
+               $filter = "cat";
        }
 
+       if ($local) {
+               $cmd = "$filter $root_directory$f";
+       } else {
+               $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
+       }
        if ($tail)
                $cmd = "$cmd | tail -n 100";
        $fd = popen($cmd, "r");
@@ -695,9 +465,9 @@ function local_dump_log($tail)
 
 function dump_text()
 {
-       global $ftp_conn;
-       global $buildlogs_server;
-       
+       global $ftp_conn, $root_directory;
+       global $buildlogs_server, $local;
+
        header("Content-type: text/plain");
 
        $f = file_name();
@@ -706,61 +476,36 @@ function dump_text()
                return;
 
        echo "# src  : ftp://$buildlogs_server$f\n";
-       echo "# date : " .  
-               date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)) . "\n";
-
-       ftp_quit($ftp_conn);
-       $ftp_conn = 0;
-       
-       if (preg_match("/\.bz2$/", $f)) {
-               $filter = "| bzcat 2>&1";
-       } elseif (preg_match("/\.gz$/", $f)) {
-               $filter = "| zcat 2>&1";
+       if ($local) {
+               echo "# date   : " .  
+                       date("Y/m/d H:i:s", filemtime("$root_directory$f")) . "\n";
        } else {
-               $filter = "";
-       }
-
-       $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 $filter";
-       $fd = popen($cmd, "r");
-       while (($s = fgets($fd, 1000)) != false) {
-               echo $s;
+               echo "# date   : " .  
+                       date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)) . "\n";
+               ftp_quit($ftp_conn);
+               $ftp_conn = 0;
        }
-       pclose($fd);
-}
-
-
-function local_dump_text()
-{
-       global $root_directory;
-       global $buildlogs_server;
-       
-       header("Content-type: text/plain");
-
-       $f = local_file_name();
-
-       if ($f == false)
-               return;
-
-       echo "# src  : ftp://$buildlogs_server$f\n";
-       echo "# date : " .  
-               date("Y/m/d H:i:s", filemtime("$root_directory$f")) . "\n";
 
        if (preg_match("/\.bz2$/", $f)) {
-               $cmd = "bzcat";
+               $filter = "bzcat";
        } elseif (preg_match("/\.gz$/", $f)) {
-               $cmd = "zcat";
+               $filter = "zcat";
        } else {
-               $cmd = "cat";
+               $filter = "cat";
        }
 
-       $fd = popen("$cmd $root_directory$f", "r");
+       if ($local) {
+               $cmd = "$filter $root_directory$f";
+       } else {
+               $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
+       }
+       $fd = popen($cmd, "r");
        while (($s = fgets($fd, 1000)) != false) {
                echo $s;
        }
        pclose($fd);
 }
 
-
 function list_archs()
 {
        global $addr, $url, $idx;
@@ -780,7 +525,7 @@ function list_archs()
             "<small>(c) 2002 ".
             "<a href=\"mailto:feedback@pld.org.pl\">PLD&nbsp;Team</a>\n".
             "</small></div>\n";
-       
+
        # smile ;)
        echo "<div align=center><small>";
        $pow = array("vim", "php", "brain", "power", "electricity",
@@ -807,9 +552,9 @@ function list_archs()
                else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
                $pow[$x] = "";
        }
-               
+
        echo "</small></div>";
-       
+
        global $qa_addr;
 
        if ($qa_addr[$idx] != "") {
@@ -826,12 +571,12 @@ function list_archs()
 function get_qa()
 {
        global $idx, $qa_addr, $qa_base;
-       
+
        if (!isset($idx) || !isset($qa_addr[$idx]))
                return false;
 
        $a = $qa_addr[$idx];
-       
+
        if ($qa_addr[$idx] == "")
                return false;
        else
@@ -862,11 +607,11 @@ function search_qa()
 function dump_qa($plain)
 {
        global $url, $idx, $qa_addr;
-       
+
        $a = $qa_addr[$idx];
 
        $f = get_qa();
-       
+
        if ($plain) {
                header("Content-type: text/plain"); 
                echo "# rpm -qa of $a\n";
@@ -884,7 +629,7 @@ function dump_qa($plain)
                        echo $s;
                }
        }
-       
+
        if (!$plain)
                end_pre();
 }
@@ -899,7 +644,7 @@ Feel free to email bug reports, complaints and feature requests
 <!-- ech... niech strace... -->
 <a href="mailto:malekith /at/ pld-linux org">to us</a>. Positive opinions are also 
 <a href="mailto:malekith /at/ pld-linux org">welcome</a> ;)</p>
-<p>Version: $Id: index.php,v 1.18 2002/09/20 15:04:12 ankry Exp $</p>
+<p>Version: $Id: index.php,v 1.19 2002/09/20 16:41:08 ankry Exp $</p>
 </td><td width=20%>&nbsp;</td></tr>
 </table>
 <?php
@@ -913,7 +658,7 @@ header("Pragma: no-cache");
 //phpinfo();
 if ($local) {
        if ($action == "text") {
-               local_dump_text();
+               dump_text();
        } else if ($action == "qatxt") {
                dump_qa(1);
        } else {
@@ -927,9 +672,9 @@ if ($local) {
                else if ($action == "sqa")
                        search_qa();
                else if (isset($id))
-                       local_dump_log($action == "tail");
+                       dump_log($action == "tail");
                else if (isset($idx))
-                       local_list_logs();
+                       list_logs();
                else 
                        welcome();
                echo "</td></tr></table>";
This page took 0.115447 seconds and 4 git commands to generate.