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