]> git.pld-linux.org Git - projects/buildlogs.git/blob - obsolete/buildlogs/index.php
- some sorting, Ac rpmqa fixed, ac-sparc64 added
[projects/buildlogs.git] / obsolete / buildlogs / index.php
1 <?php
2 $buildlogs_server = "buildlogs.pld-linux.org";
3 $url = "index.php";
4 $addr = array(
5         "/th/SRPMS",
6         "/th/i486",
7         "/th/i686",
8         "/th/athlon",
9         "/th/amd64",
10         "/th/ia64",
11         "/th/alpha",    
12         "/th/ppc",
13         "/th/sparc",
14         "/ac/SRPMS",
15         "/ac/i386",
16         "/ac/i586",
17         "/ac/i686",
18         "/ac/athlon",
19         "/ac/amd64",
20         "/ac/alpha",    
21         "/ac/ppc",
22         "/ac/sparc",
23         "/ac/sparc64",
24         "/ra/i386",
25         "/ra/i586",
26         "/ra/i686",
27         "/ra/alpha",    
28         "/ra/ppc",
29         "/ra/sparc",
30         "/nest/i486",
31         "/nest/i686",
32         "/nest/alpha",
33         "/nest/ppc"
34 );
35 $qa_addr = array(
36         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-SRPMS.txt",
37         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-i486.txt",
38         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-i686.txt",
39         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-athlon.txt",
40         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-amd64.txt",
41         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-ia64.txt",
42         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-alpha.txt",   
43         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-ppc.txt",
44         "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-sparc.txt",
45         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-SRPMS.txt",
46         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-i386.txt",
47         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-i586.txt",
48         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-i686.txt",
49         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-athlon.txt",
50         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-amd64.txt",
51         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-alpha.txt",   
52         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-ppc.txt",
53         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-sparc.txt",
54         "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-sparc64.txt",
55         "http://ftp.pld-linux.org/dists/ra/.stat/builder/liniowiec/rpmqa-ra-i386.txt",
56         "http://ftp.pld-linux.org/dists/ra/.stat/builder/liniowiec/rpmqa-ra-i586.txt",
57         "http://ftp.pld-linux.org/dists/ra/.stat/builder/liniowiec/rpmqa-ra-i686.txt",
58         "http://ftp.pld-linux.org/dists/ra/.stat/builder/fly/rpmqa-ra-alpha.txt",       
59         "http://ftp.pld-linux.org/dists/ra/.stat/builder/an2/rpmqa-ra-ppc.txt",
60         "http://ftp.pld-linux.org/dists/ra/.stat/builder/ares/rpmqa-ra-sparc.txt",
61         "http://ftp.nest.pld-linux.org/.stat/builder/kenny/rpmqa-nest-i486.txt",
62         "http://ftp.nest.pld-linux.org/.stat/builder/kenny/rpmqa-nest-i686.txt",
63         "http://ftp.nest.pld-linux.org/.stat/builder/alpha/rpmqa-nest-alpha.txt",
64         "http://ftp.nest.pld-linux.org/.stat/builder/an2/rpmqa-nest-ppc.txt"
65 );
66 $local = 1; /* $local=0 for FTP */ 
67 $root_directory = "/home/services/ftp/pub/pld-buildlogs";
68 $ftp_conn = 0;
69 /* It should be set */
70
71 $langs["en_US"]["charset"]="ISO-8859-1";
72 $langs["pl_PL"]["charset"]="ISO-8859-2";
73
74 $lang="en_US";
75 if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
76 {
77   $rows=explode(";",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
78   $rows=explode(",",$rows[0]);
79   $lang_detected=rtrim($rows[0]);
80 } else if (preg_match("/opera/i",$_SERVER["HTTP_USER_AGENT"]))
81 {
82   $lang_detected=preg_replace("/.*\[(.*)\].*/i","\\1",$_SERVER["HTTP_USER_AGENT"]);
83 }
84
85 // FIXME - some array
86 $lang_detected=preg_replace("/^pl$/i","pl_PL",$lang_detected);
87
88 if (isset($lang_detected) && isset($langs[$lang_detected]))
89 {
90   $lang=$lang_detected;
91 }
92
93 if (isset($_GET["lang"]))$_SESSION["lang"]=$_GET["lang"];
94 if (isset($_SESSION["lang"]))$lang=$_SESSION["lang"];
95
96 putenv("LANG=$lang");
97 setlocale(LC_ALL,$lang);
98 bindtextdomain("messages","locale");
99 textdomain("messages");
100
101 if (isset($_GET["idx"]))$idx=$_GET["idx"];
102 if (isset($_GET["dist"]))
103 {
104         $dist=$_GET["dist"];
105         if (isset($_GET["arch"]))
106         {
107                 $arch=$_GET["arch"];
108                 for ($i = 0; $i < count($addr); $i++)
109                 {
110                         if ($addr[$i]=="/".$dist."/".$arch)
111                                 $idx=$i;
112                 }
113         }
114 }
115 if (isset($_GET["ok"]))$ok=$_GET["ok"];
116 else $ok="";
117 if (isset($_GET["ns"]))$ns=$_GET["ns"];
118 else $ns="";
119 if (isset($_GET["cnt"]))$cnt=$_GET["cnt"];
120 if (isset($_GET["action"]))$action=$_GET["action"];
121 else $action="";
122 if (isset($_GET["off"]))$off=$_GET["off"];
123 if (isset($_GET["id"]))$id=$_GET["id"];
124
125 if (isset($_POST["str"]))$str=$_POST["str"];
126 if (isset($_POST["idx"]))$idx=$_POST["idx"];
127 if (isset($_POST["action"]))$action=$_POST["action"];
128
129 function myheader()
130 {
131 echo '<' . '?xml version="1.0" encoding="' . _("ISO-8859-1") .'"?' . ">\n";
132 echo '<' . '?xml-stylesheet href="#internalStyle" type="text/css"?' . ">\n";
133 ?>
134 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
135     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
136 <html xmlns="http://www.w3.org/1999/xhtml">
137  <head>
138   <title>PLD Build Logs</title>
139   <?php echo '<meta http-equiv="Content-type" content="text/html; charset=' . _("ISO-8859-1") .'"/>' ."\n";?>
140   <style type="text/css"><!--
141 A { text-decoration: none; }
142 A:hover { text-decoration: underline; }
143 H1 { font-family: arial,helvetica,sans-serif; 
144      font-size: 20pt; 
145      font-weight: bold;}
146 H2 { font-family: arial,helvetica,sans-serif; 
147      font-size: 18pt; 
148      font-weight: bold;}
149 BODY,TD { font-family: arial,helvetica,sans-serif; 
150           font-size: 13pt; }
151 TH { font-family: arial,helvetica,sans-serif; 
152      font-size: 13pt; 
153      font-weight: bold; }
154 //-->
155 </style>
156  </head>
157  <!-- Diffrent color for visited link doesn't make much sense here...
158       this page is autogenerated and it might be misleading after some
159       build log changes. -->
160  <body bgcolor="#ffffff" text="#000000" link="#5f26cd" vlink="#5f26cd">
161 <?php
162 }
163
164 function start_pre()
165 {
166         echo "<table cellpadding=\"10\"><tr><td bgcolor=\"#000000\">".
167                 "<font color=\"#cccccc\"><pre style=\"width: 2048px;overflow: scroll\">";
168 }
169
170 function end_pre()
171 {
172         echo "</pre></font></td></tr></table>\n";
173 }
174
175 function trailer()
176 {
177         echo "</body></html>";
178 }
179
180
181 function mydie($msg)
182 {
183         echo "Fatal error: $msg";
184 }
185
186 function open_ftp($pidx="", $pok="")
187 {
188         global $idx, $addr, $buildlogs_server, $ok;
189         global $ftp_conn, $big_url, $url, $ns;
190         global $off, $cnt;
191         
192         if ($pidx==="")$pidx=$idx;
193         if ($pok==="")$pok=$ok;
194
195         if (!isset($pidx) || !isset($addr[$pidx]))
196                 return false;
197
198         if ($pok != 1)
199                 $pok = 0;
200         if ($ns != 1)
201                 $ns = 0;
202
203         if ($pok == 1) {
204                 $a = "$addr[$pidx]/OK";
205         } else {
206                 $a = "$addr[$pidx]/FAIL";
207         }
208
209         if (!isset($off))
210                 $off = 0;
211         if (!isset($cnt))
212                 $cnt = 16;
213
214         $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
215
216         $ftp = ftp_connect($buildlogs_server);
217
218         if ($ftp == false) {
219                 mydie(_("cannot connect to")." $buildlogs_server");
220                 return false;
221         }
222
223         if (ftp_login($ftp, "anonymous", 
224                       "buildlogs-iface@pld-linux.org") == false) {
225                 ftp_quit($ftp);
226                 mydie(_("cannot ftp login to")." $buildlogs_server");
227                 return false;
228         }
229
230         $list = ftp_nlist($ftp, $a);
231         if ($list == false) {
232                 ftp_quit($ftp);
233                 mydie(_("cannot list")." $a");
234                 return false;
235         }
236
237         $ftp_conn = $ftp;
238
239         return $list;
240 }
241
242 function directory_list($pidx="",$pok="")
243 {
244         global $idx, $addr, $buildlogs_server, $ok;
245         global $root_directory, $big_url, $url, $ns;
246         global $off, $cnt;
247
248         if ($pidx==="")$pidx=$idx;
249         if ($pok==="")$pok=$ok;
250         if (!isset($pidx) || !isset($addr[$pidx]))
251                 return false;
252
253         if ($pok != 1)
254                 $pok = 0;
255         if ($ns != 1)
256                 $ns = 0;
257
258         if ($pok == 1) {
259                 $a = "$addr[$pidx]/OK";
260         } else {
261                 $a = "$addr[$pidx]/FAIL";
262         }
263
264         if (!isset($off))
265                 $off = 0;
266         if (!isset($cnt))
267                 $cnt = 16;
268
269         $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
270
271         $dir = opendir("$root_directory$a");
272         $i = 0;
273         $list = array ();
274         while ($file = readdir($dir)) {
275                 if (($file != ".") && ($file != "..")) {
276                         $list[$i] = "$a/$file";
277                         $i++;
278                 }
279         }
280         closedir($dir);
281         return $list;
282 }
283
284 function list_logs()
285 {
286         global $idx, $addr, $ok;
287         global $ftp_conn, $big_url, $ns, $qa_addr;
288         global $off, $cnt, $local, $root_directory;
289
290         if ($local) {
291                 $list = directory_list();
292         } else {
293                 $list = open_ftp();
294         }
295         if ($list == false)
296                 return;
297
298         if ($ok == 1) {
299                 echo "<h1>"._("Listing of")." $addr[$idx]/OK "
300                         ."(<a href=\"$big_url&amp;ok=0\">"._("fail")."</a>)</h1>\n";
301         } else {
302                 echo "<h1>"._("Listing of")." $addr[$idx]/FAIL "
303                         ."(<a href=\"$big_url&amp;ok=1\">"._("ok")."</a>)</h1>\n";
304         }
305
306         echo "<div align=\"center\"><table cols=\"4\" border=\"0\" cellspacing=\"1\" ".
307                 "cellpadding=\"3\" bgcolor=\"#000000\" width=\"90%\">\n";
308         echo "<tr><th bgcolor=\"#CCCCFF\" align=\"right\" width=\"1%\">"._("No.")."</th>".
309                  "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"80%\">"._("Log File").
310                         "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
311                  "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
312                  "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
313                          "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
314                  "</tr>";
315
316         function cmp($f1, $f2) {
317                 global $ftp_conn, $root_directory, $local;
318                 if ($local)
319                         return filemtime("$root_directory$f2") - filemtime("$root_directory$f1");
320                 return ftp_mdtm($ftp_conn, $f2) - ftp_mdtm($ftp_conn, $f1);
321         }
322
323         if ($ns != 1) {
324                 $ns = 0;
325                 usort($list, "cmp");
326         } else {
327                 sort($list);
328         }
329
330         $now = time();
331         for ($i = $off; $i < $cnt + $off; $i++) {
332                 if (!isset($list[$i]))
333                         continue;
334                 $h = bin2hex(mhash(MHASH_MD5, $list[$i]));
335                 $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $list[$i]);
336                 $f = preg_replace("/\.(bz2|gz)$/", "", $f);
337                 if ($local) {
338                         $s = filesize("$root_directory$list[$i]");
339                         $t = $now - filemtime("$root_directory$list[$i]");
340                 } else {
341                         $s = ftp_size($ftp_conn, $list[$i]);
342                         $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
343                 }
344                 $t /= 60;
345                 if ($t >= 60) {
346                         $t /= 60;
347                         if ($t >= 24) {
348                                 $t /= 24;
349                                 $t = round($t);
350                                 $t = $t . "&nbsp;" . ngettext("day","days",$t);
351                         } else {
352                                 $t = round($t);
353                                 $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
354                         }
355                 } else {
356                         $t = round($t);
357                         $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
358                 }
359                 $u = "$big_url&amp;off=$off&amp;id=$h";
360                 echo "<tr><td bgcolor=\"#CCCCCC\" align=\"right\">".($i+1).".</td>".
361                      "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ".
362                      "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
363                       "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
364                      "</td><td bgcolor=\"#CCCCCC\" align=\"right\">".
365                      "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n";
366         }
367         echo "</table></div>\n";
368
369         $backarr = "&lt;&lt;&lt;&nbsp;";
370         $back = _("Page back");
371         $forward = _("Page forward");
372         $forwardarr = "&nbsp;&gt;&gt;&gt;";
373
374         echo "<p><table width=\"90%\" align=\"center\"><tr><td align=\"left\" width=\"1%\">";
375
376         if ($off > 0) {
377                 $noff = $off - $cnt;
378                 if ($noff < 0)  
379                         $noff = 0;
380                 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
381                 echo "$hrefurl$backarr</a></td><td align=\"left\">$hrefurl$back</a>";
382         } else {
383                 echo "$backarr</td><td align=\"left\">$back";
384         }
385
386         echo "</td>\n<td align=\"center\">";
387
388         if ($qa_addr[$idx] != "") {
389                 echo "[<a href=\"$big_url&amp;action=qa\">"._("View <quot>rpm&nbsp;-qa</quot> of builder")."</a>]";
390         } else {
391                 echo "&nbsp;";
392         }
393
394         echo "</td>\n<td align=right>";
395         if ($off + $cnt < count($list)) {
396                 $noff = $off + $cnt;
397                 if ($noff < 0)  
398                         $noff = 0;
399                 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
400                 echo "$hrefurl$forward</a></td><td align=right width=1%>$hrefurl$forwardarr</a>";
401         } else {
402                 echo "$forward</td><td align=right width=1%>$forwardarr";
403         }
404         echo "</td>\n</tr></table></p>";
405         if ($local == 0) {
406                 ftp_quit($ftp_conn);
407                 $ftp_conn = 0;
408         }
409 }
410
411 function file_name()
412 {
413         global $idx, $addr, $ok;
414         global $ftp_conn, $root_directory, $big_url, $ns, $id;
415         global $buildlogs_server, $local;
416
417         if (!isset($id))
418                 return false;
419         if ($local) {
420                 $list = directory_list();
421         } else {
422                 $list = open_ftp();
423         }
424         if ($list == false)
425                 return false;
426
427         $f = false;
428         for ($i = 0; $i < count($list); $i++) {
429                 $h = bin2hex(mhash(MHASH_MD5, $list[$i]));
430                 if ($h == $id) {
431                         $f = $list[$i];
432                 }
433         }
434
435         if ($f == false) {
436                 mydie(_("cannot find specified file:")." $id");
437                 if ($local == 0)
438                         ftp_quit($ftp_conn);
439                 return false;
440         }
441
442         return $f;
443 }
444
445 function dump_log($tail)
446 {
447         global $idx, $addr, $ok, $url;
448         global $ftp_conn, $root_directory, $big_url, $ns, $id, $cnt, $off;
449         global $buildlogs_server, $local, $qa_addr;
450
451         $f = file_name();
452
453         if ($f == false)
454                 return;
455
456         $df = preg_replace("/.*\/([^\/]*)$/", "\\1", $f);
457         $df = preg_replace("/\.(bz2|gz)$/", "", $df);
458
459         echo "<h1>$df</h1>";
460
461         echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\">";
462
463         function one_item($h, $t) {
464                 echo "<tr><td bgcolor=\"#ccccff\">$h:</td>".
465                          "<td bgcolor=\"#cccccc\">$t</td></tr>";
466         }
467
468         function href($h, $c) {
469                 return "<a href=\"$h\">$c</a>";
470         }
471
472         one_item(_("Status"), ($ok == 1 ?  
473                                 "<font color=\"green\"><b>"._("OK")."</b></font>" : 
474                                 "<font color=\"red\"><b>"._("Failed")."</b></a>"));
475         one_item(_("Source URL"), 
476                  href("ftp://$buildlogs_server$f", 
477                       "ftp://$buildlogs_server$f"));
478
479         $bu = "$big_url&amp;off=$off";
480
481         one_item(_("text/plain URL"), 
482                  href("$bu&amp;id=$id&amp;action=text",
483                       _("View!")));
484         if ($tail) {
485                 one_item(_("full text"), 
486                          href("$bu&amp;id=$id",
487                               "View!"));
488         }
489
490         if ($qa_addr[$idx] != "") {
491                 one_item(_("rpm -qa of builder"), href("$bu&amp;action=qa", _("View!")));
492         } else {
493                 one_item(_("rpm -qa of builder"), _("Not available"));
494         }
495         if ($local) {
496                 one_item("Data", date("Y/m/d H:i:s", filemtime("$root_directory$f")));
497         } else {
498                 one_item("Data", date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)));
499         }
500         /*
501         echo "<tr><td>Here:</td><td>" . 
502                 "<a href=\"$url?idx=$idx&amp;ok=$ok&amp;id=$id\">".
503                 "http://" . getenv("SERVER_NAME") .
504                 getenv("SCRIPT_NAME") . "?idx=$idx&amp;ok=$ok&amp;id=$id</a>" .
505              "</td></tr>"; */
506
507         echo "</table><h2>"._("Content:")."</h2>";
508
509         if ($local == 0) {
510                 ftp_quit($ftp_conn);
511                 $ftp_conn = 0;
512         }
513
514
515         # what can I say beside PHP suxx? how the fuck should I create
516         # bidirectional pipe? gotta use wget
517
518         if (preg_match("/\.bz2$/", $f)) {
519                 $filter = "bzcat";
520         } elseif (preg_match("/\.gz$/", $f)) {
521                 $filter = "zcat";
522         } else {
523                 $filter = "cat";
524         }
525
526         if ($local) {
527                 $cmd = "$filter $root_directory$f";
528         } else {
529                 $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
530         }
531         if ($tail)
532                 $cmd = "$cmd | tail -n 100";
533         $fd = popen($cmd, "r");
534         start_pre();
535         while (($s = fgets($fd, 102400)) != false) {
536                 if (strlen($s) > 800) {
537                         $s = chunk_split($s, 800, "\n    ");
538                         $s = trim($s);
539                 }
540                 $s = htmlspecialchars($s);
541                 echo $s;
542         }
543         end_pre();
544         pclose($fd);
545
546 ?>
547         <table width="100%">
548          <tr>
549           <td align=left>
550            [<a href="<?php echo $bu; ?>"><?=_("Back to list of logs")?></a>]
551           </td>
552           <td align=right>
553            [<a href="<?php echo "$bu&amp;action=qa" 
554                 ?>"><?=_("View rpm -qa of builder")?></a>]
555           </td>
556          </tr>
557         </table>
558 <?php
559
560 }
561
562 function dump_text()
563 {
564         global $ftp_conn, $root_directory;
565         global $buildlogs_server, $local;
566
567         header("Content-type: text/plain");
568
569         $f = file_name();
570
571         if ($f == false)
572                 return;
573
574         echo "# src  : ftp://$buildlogs_server$f\n";
575         if ($local) {
576                 echo "# date   : " .  
577                         date("Y/m/d H:i:s", filemtime("$root_directory$f")) . "\n";
578         } else {
579                 echo "# date   : " .  
580                         date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)) . "\n";
581                 ftp_quit($ftp_conn);
582                 $ftp_conn = 0;
583         }
584
585         if (preg_match("/\.bz2$/", $f)) {
586                 $filter = "bzcat";
587         } elseif (preg_match("/\.gz$/", $f)) {
588                 $filter = "zcat";
589         } else {
590                 $filter = "cat";
591         }
592
593         if ($local) {
594                 $cmd = "$filter $root_directory$f";
595         } else {
596                 $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
597         }
598         $fd = popen($cmd, "r");
599         while (($s = fgets($fd, 1000)) != false) {
600                 echo $s;
601         }
602         pclose($fd);
603 }
604
605 function list_archs()
606 {
607         global $addr, $url, $idx, $cnt,$ok,$ns;
608
609         if (!isset($cnt))
610                 $cnt = 16;
611
612         $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
613
614         echo "<table width=\"100%\" border=\"0\">\n";
615         echo "<tr><td bgcolor=\"#cccccc\" nowrap=\"nowrap\">"._("Failed")."</td><td bgcolor=\"#cccccc\">"._("Ok")."</td></tr>\n";
616         for ($i = 0; $i < count($addr); $i++)
617                 echo "<tr><td nowrap=\"nowrap\">".
618                      "<a href=\"$url?idx=$i&amp;ok=0&amp;cnt=$cnt\">$addr[$i]</a></td><td nowrap=\"nowrap\">".
619                      "[<a href=\"$url?idx=$i&amp;ok=1&amp;cnt=$cnt\">OK</a>]</td>".
620                      #"<td>[<a href=\"$url?idx=$i&amp;action=qa\">qa</a>]</td>".
621                      "</tr>\n";
622         echo "</table><hr />\n";
623         
624         echo "<div align=\"center\">";
625         echo "<a href=\"$big_url&amp;action=adv_search\">"._("Advanced Search")."</a><br />\n";
626         
627         echo "<a href=\"$url\">main()</a><hr />\n";
628         echo "<a href=\"http://www.pld-linux.org/\"><img src=\"powpld.png\" ".
629                 "alt=\""._("Powered by PLD Linux")."\" border=\"0\" /></a><br />\n" .
630              "<small>(c) 2002 ".
631              "<a href=\"mailto:feedback@pld-linux.org\">PLD&nbsp;Team</a><br />\n".
632              '$Revision: 1.85 $'.
633              "</small></div>\n";
634
635         # smile ;)
636         echo "<div align=\"center\"><small>";
637         $pow = array("vim", "php", "brain", "power", "electricity",
638                      "coffee", "ufo", "penguin", "GNOME", "ELF", "DWARF",
639                      "voodoo magic", "Linux", "x-files", "X", "foobar",
640                      "/dev/null", "/dev/zero", "/dev/drzewo", 
641                      "Leppe'", "matrix", "Neo", "PDP-11",
642                      "Ken", "GNU antilope", "PDP-7", "ITS", "Multics",
643                      "foobarbaz", "ed", "Joe", "Unix conspiracy", 
644                      "overclock", "The Right Thing",
645                      "The Bad Thing", "Star Treck", "NSA", "NASA",
646                      "achelon", "VAX", "Real Programmer",
647                      "Real Operating System", "Real Computer",
648                      "computron", "bogon", "quantum bogodynamics",
649                      "BOFH", "/dev/ill", "nasi tu byli",
650                      "Paranoid Android", "Lunatic Corp", "Parallel thinking",
651                      "sfistak", "Linus", "The Golden Path", "Dark Side of the Force",
652                      "Przewodniczacego Lepper-a", "KDE", "Microsoft Windows 2003"
653                      # feel free to add sth if you change this file ;)
654                      );
655         echo _("Powered by")." ";
656         $max = 1;
657         for ($i = 0; $i < $max; $i++) {
658                 $x = rand(0, count($pow) - 1);
659                 if ($pow[$x] == "") $i--;
660                 else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
661                 $pow[$x] = "";
662         }
663         echo "</small></div>";
664
665         global $qa_addr;
666
667         if (isset($qa_addr[$idx]) && $qa_addr[$idx] != "") {
668         echo "<form action=\"index.php\" method=\"post\">";
669         echo "<input type=\"hidden\" name=\"idx\" value=\"$idx\" />";
670         echo "<input type=\"hidden\" name=\"action\" value=\"sqa\" />";
671         echo "<input type=\"text\" size=\"14\" name=\"str\" /><br />";
672         echo "<input type=\"submit\" name=\"submit\" value=\""._("Search rpmqa!")."\" />";
673         echo "</form>";
674         }
675 }
676
677 function get_qa()
678 {
679         global $idx, $qa_addr;
680
681         if (!isset($idx) || !isset($qa_addr[$idx]))
682                 return false;
683
684         $a = $qa_addr[$idx];
685
686         if ($qa_addr[$idx] == "")
687                 return false;
688         else
689                 return fopen("$qa_addr[$idx]", "r");
690 }
691
692 function search_qa()
693 {
694         global $url, $idx, $qa_addr, $str;
695
696         $f = get_qa();
697         echo "<h1>"._("Search results for")." '$str' "._("in")." $qa_addr[$idx]</h1>";
698
699         start_pre();
700
701         if ($f == 0) {
702                 echo _("Sorry, cannot open.");
703         } else {
704                 while (($s = fgets($f, 1000)) != false) {
705                         if (stristr($s, $str))
706                                 echo $s;
707                 }
708                 echo "/* EOF */";
709         }
710         end_pre();
711 }
712
713 function dump_qa($plain)
714 {
715         global $url, $idx, $qa_addr;
716
717         $a = $qa_addr[$idx];
718
719         $f = get_qa();
720
721         if ($plain) {
722                 header("Content-type: text/plain"); 
723                 echo _("# rpm -qa of")." $a\n";
724         } else {
725                 echo "<h1>"._("rpm -qa of")." $a</h1>";
726                 echo "<a href=\"$url?idx=$idx&amp;action=qatxt\">"._("text/plain version")."</a>";
727                 start_pre();
728         }
729
730         if ($f == 0) {
731                 echo _("Sorry, cannot open.");
732         } else {
733                 while (($s = fgets($f, 1000)) != false) {
734                         echo $s;
735                 }
736         }
737
738         if (!$plain)
739                 end_pre();
740 }
741
742
743 function adv_search()
744 {
745   global $addr, $url, $local, $_POST, $off, $cnt, $root_directory;
746
747   $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
748
749   echo "<form action=\"index.php?action=adv_search\" method=\"post\">";
750
751   echo "<div align=\"center\">";
752   echo "<table border=\"0\">\n";
753   echo "<tr>\n";
754   echo "<td>"._("Package name")."</td>\n";
755   echo "<td><input type=\"text\" size=\"20\" name=\"name\" value=\"".$_POST[name]."\"/></td>\n";
756   echo "</tr>\n";
757
758   echo "<tr>\n";
759   echo "<td>"._("Days")."</td>\n";
760   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"age1\" value=\"".$_POST["age1"]."\" /></td>\n";
761   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"age2\" value=\"".$_POST["age2"]."\" /></td>\n";
762   echo "</tr>\n";
763
764   echo "<tr>\n";
765   echo "<td>"._("Size")."</td>\n";
766   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"size1\" value=\"".$_POST["size1"]."\" /></td>\n";
767   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"size2\" value=\"".$_POST["size2"]."\" /></td>\n";
768   echo "</tr>\n";
769
770   echo "<tr>\n";
771   echo "<td>"._("Search logs:")."</td>\n";
772   echo "</tr>\n";
773
774   echo "<tr>\n";
775   echo "<td>"._("Failed")."</td>\n";
776   echo "<td>"._("OK")."</td>\n";
777   echo "</tr>\n";
778
779   for ($i = 0; $i < count($addr); $i++)
780   {
781     echo "<tr>\n";
782     $name="as0_".$i;
783     $check=" checked=\"on\"";
784     echo "<td><input name=\"$name\" type=\"checkbox\"$check>".$addr[$i]."</input></td>\n";
785     $name="as1_".$i;
786     $check=" checked=\"on\"";
787     echo "<td><input name=\"$name\" type=\"checkbox\"$check>".$addr[$i]."</input></td>\n";
788     echo "</tr>\n";
789   }
790         
791   echo "<tr>\n";
792   echo "<td><input type=\"submit\" name=\"submit\" value=\""._("Search!")."\" /></td>";
793   echo "</tr>\n";
794
795   echo "</table>\n";
796
797 //      if (isset($_POST["name"]) || isset($_POST["age1"]) || isset($_POST["age2"]) ||
798 //        isset($_POST["size1"]) || isset($_POST["size2"]))
799   if (($_POST["name"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") ||
800     ($_POST["size1"]!="") || ($_POST["size2"]!=""))
801   {
802     unset($list);
803     $now = time();
804     for ($i = 0; $i < count($addr); $i++)
805     
806       for ($j=0;$j<2;$j++)
807         {
808           unset($tmp_list);
809           if (isset($_POST["as".$j."_".$i]))
810           {
811             if ($local) {
812                 $tmp_list = directory_list($i,$j);
813             } else {
814                 $tmp_list = open_ftp($i,$j);
815             }
816             if (is_array($tmp_list))
817             {
818               while (list($k,$name)=each($tmp_list))
819               {
820                 $s = filesize("$root_directory$name");
821                 $t = $now - filemtime("$root_directory$name");
822                 $t/=(24*3600);
823                 if (($_POST["name"]!="") && (!preg_match("/".$_POST["name"]."/i",$name)))continue;
824                 if (($_POST["age1"]) && ($_POST["age1"]>$t))continue;
825                 if (($_POST["age2"]) && ($_POST["age2"]<$t))continue;
826
827                 if (($_POST["size1"]) && ($_POST["size1"]>$s))continue;
828                 if (($_POST["size2"]) && ($_POST["size2"]<$s))continue;
829
830                 $list[$i."_".$j."_".$k]=$name;
831               }
832             }
833           }
834         }
835         
836         if (sizeof($list)==0)
837         {
838           echo _("Nothing found");
839         } else
840         {
841
842         echo "<table border=\"0\" cellspacing=\"1\" ".
843                 "cellpadding=3 bgcolor=\"#000000\" width=\"90%\">\n";
844         echo "<tr><th bgcolor=\"#CCCCFF\" align=\"left\" width=\"10%\">"._("Builder").
845              "[<a href=\"$big_url&amp;ns=2\">"._("sort")."</a>]</th>";
846         echo "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"60%\">"._("Log File").
847                         "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
848                  "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
849                  "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
850                          "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
851                  "</th></tr>";
852
853         function cmp1($f1, $f2) {
854                 global $ftp_conn, $root_directory, $local;
855                 if ($local)
856                         return filemtime("$root_directory$f2") - filemtime("$root_directory$f1");
857                 return ftp_mdtm($ftp_conn, $f2) - ftp_mdtm($ftp_conn, $f1);
858         }
859
860         function cmp2($f1, $f2) {
861           list($p11,$p12,$p13)=explode("_",$f1);
862           list($p21,$p22,$p23)=explode("_",$f2);
863           return strcmp($f2,$f1);
864         }
865
866         if ($ns == 1)
867         {
868           usort($list, "cmp1");
869 //      } else if ($ns == 2)
870 //      {
871 //        uksort($list, "cmp2");
872         } else
873         {
874           asort($list);
875         }
876
877         $counter=0;
878         while (list($k,$name)=each($list))
879         {
880         if (($counter<$off) || ($counter>$off+$cnt-1))
881         {
882           $counter++;
883           continue;
884         }
885
886           $counter++;
887           list($i,$j,$k)=explode("_",$k);
888
889                 $h = bin2hex(mhash(MHASH_MD5, $name));
890                 $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $name);
891                 $f = preg_replace("/\.(bz2|gz)$/", "", $f);
892                 if ($local) {
893                         $s = filesize("$root_directory$name");
894                         $t = $now - filemtime("$root_directory$name");
895                 } else {
896                         $s = ftp_size($ftp_conn, $list[$i]);
897                         $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
898                 }
899                 $t /= 60;
900                 if ($t >= 60) {
901                         $t /= 60;
902                         if ($t >= 24) {
903                                 $t /= 24;
904                                 $t = round($t);
905                                 $t = $t . "&nbsp;" . ngettext("day","days",$t);
906                         } else {
907                                 $t = round($t);
908                                 $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
909                         }
910                 } else {
911                         $t = round($t);
912                         $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
913                 }
914                 $big_url = "$url?idx=$i&amp;ok=$j&amp;ns=$ns&amp;cnt=$cnt";
915                 $u = "$big_url&amp;off=$off&amp;id=$h";
916
917                 $builder=$addr[$i]."/".(($j=="1")?"OK":"FAIL");
918                 echo "<tr>";
919                 echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$builder</a></td>";
920                 echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ".
921                      "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
922                       "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
923                      "</td><td bgcolor=\"#CCCCCC\" align=\"right\">".
924                      "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n";
925         }
926         echo "</table></div>\n";
927
928         $backarr = "&lt;&lt;&lt;&nbsp;";
929         $back = _("Page back");
930         $forward = _("Page forward");
931         $forwardarr = "&nbsp;&gt;&gt;&gt;";
932
933 // FIXME
934 /*
935         echo "<p><table width=\"90%\" align=\"center\"><tr><td align=left width=1%>";
936
937         if ($off > 0) {
938                 $noff = $off - $cnt;
939                 if ($noff < 0)  
940                         $noff = 0;
941                 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
942                 echo "$hrefurl$backarr</a></td><td align=left>$hrefurl$back</a>";
943         } else {
944                 echo "$backarr</td><td align=left>$back";
945         }
946
947     echo "</td>\n<td align=\"center\">";
948     echo "</td>\n<td align=\"right\">";
949
950     if ($off + $cnt < count($list))
951     {
952       $noff = $off + $cnt;
953       if ($noff < 0)    
954         $noff = 0;
955       $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
956       echo "$hrefurl$forward</a></td><td align=\"right\" width=\"1%\">$hrefurl$forwardarr</a>";
957     }
958     else
959     {
960       echo "$forward</td><td align=\"right\" width=\"1%\">$forwardarr";
961     }
962
963     echo "</td>\n</tr></table></p>";
964 */
965     }
966     if ($local == 0)
967     {
968       ftp_quit($ftp_conn);
969       $ftp_conn = 0;
970     }
971   } else
972   {
973     echo _("Enter something!");
974   }
975   echo "</form>\n";
976 }
977
978 function welcome()
979 {
980 ?>
981 <table border="0" width="100%"><tr><td width="20%">&nbsp;</td><td>
982 <h1><?=_("Welcome!")?></h1>
983 <p><?=_("Welcome to PLD Build Logs WWW interface.")?></p><p>
984 <?=_("Feel free to email bug reports, complaints and feature requests ")?>
985 <!-- ech... niech strace... -->
986 <a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?> 
987 <a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a> ;)</p>
988 <p>Version: $Id: index.php,v 1.85 2005/09/05 10:30:08 arekm Exp $</p>
989 </td><td width="20%">&nbsp;</td></tr>
990 </table>
991 <?php
992 }
993
994 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
995 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
996 header("Cache-Control: no-cache, must-revalidate");
997 header("Pragma: no-cache");
998
999 //phpinfo();
1000 if ($local) {
1001         if ($action == "text") {
1002                 dump_text();
1003         } else if ($action == "adv_search") {
1004                 myheader();
1005                 adv_search();
1006                 trailer();
1007         } else if ($action == "qatxt") {
1008                 dump_qa(1);
1009         } else {
1010                 myheader();
1011                 echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=\"top\" width=\"10%\">";
1012                 list_archs();
1013                 echo "</td><td valign=\"top\">";
1014                 flush();
1015                 if ($action == "qa")
1016                         dump_qa(0);
1017                 else if ($action == "sqa")
1018                         search_qa();
1019                 else if (isset($id))
1020                         dump_log($action == "tail");
1021                 else if (isset($idx))
1022                         list_logs();
1023                 else 
1024                         welcome();
1025                 echo "</td></tr></table>";
1026                 trailer();
1027         }
1028 }
1029 else {
1030
1031         if ($action == "text") {
1032                 dump_text();
1033         } else if ($action == "qatxt") {
1034                 dump_qa(1);
1035         } else {
1036                 myheader();
1037                 echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=top width=\"10%\">";
1038                 list_archs();
1039                 echo "</td><td valign=\"top\">";
1040                 flush();
1041                 if ($action == "qa")
1042                         dump_qa(0);
1043                 else if (isset($id))
1044                         dump_log($action == "tail");
1045                 else if (isset($idx))
1046                         list_logs();
1047                 else 
1048                         welcome();
1049                 echo "</td></tr></table>";
1050                 trailer();
1051         }
1052 }
1053 ?>
This page took 0.562499 seconds and 3 git commands to generate.