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