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