]> git.pld-linux.org Git - projects/buildlogs.git/blob - obsolete/buildlogs/index.php
- this location is kosher now :)
[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/pld-buildlogs";
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", "The Golden Path", "Dark Side of the Force",
609                      "Przewodniczacego Lepper-a", "KDE", "Microsoft Windows 2003"
610                      # feel free to add sth if you change this file ;)
611                      );
612         echo _("Powered by")." ";
613         $max = 1;
614         for ($i = 0; $i < $max; $i++) {
615                 $x = rand(0, count($pow) - 1);
616                 if ($pow[$x] == "") $i--;
617                 else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
618                 $pow[$x] = "";
619         }
620         echo "</small></div>";
621
622         global $qa_addr;
623
624         if ($qa_addr[$idx] != "") {
625         echo "<form action=\"index.php\" method=\"post\">";
626         echo "<input type=hidden name=idx value=$idx />";
627         echo "<input type=hidden name=action value=sqa />";
628         echo "<input type=text size=14 name=str /><br />";
629         echo "<input type=submit name=submit value=\""._("Search rpmqa!")."\" />";
630         echo "</form>";
631         }
632 }
633
634 function get_qa()
635 {
636         global $idx, $qa_addr, $qa_base;
637
638         if (!isset($idx) || !isset($qa_addr[$idx]))
639                 return false;
640
641         $a = $qa_addr[$idx];
642
643         if ($qa_addr[$idx] == "")
644                 return false;
645         else
646                 return fopen("$qa_base$qa_addr[$idx]", "r");
647 }
648
649 function search_qa()
650 {
651         global $url, $idx, $qa_addr, $str;
652
653         $f = get_qa();
654         echo "<h1>"._("Search results for")." '$str' "._("in")." $qa_addr[$idx]</h1>";
655
656         start_pre();
657
658         if ($f == 0) {
659                 echo _("Sorry, cannot open.");
660         } else {
661                 while (($s = fgets($f, 1000)) != false) {
662                         if (stristr($s, $str))
663                                 echo $s;
664                 }
665                 echo "/* EOF */";
666         }
667         end_pre();
668 }
669
670 function dump_qa($plain)
671 {
672         global $url, $idx, $qa_addr;
673
674         $a = $qa_addr[$idx];
675
676         $f = get_qa();
677
678         if ($plain) {
679                 header("Content-type: text/plain"); 
680                 echo _("# rpm -qa of")." $a\n";
681         } else {
682                 echo "<h1>"._("rpm -qa of")." $a</h1>";
683                 echo "<a href=\"$url?idx=$idx&amp;action=qatxt\">"._("text/plain version")."</a>";
684                 start_pre();
685         }
686
687         if ($f == 0) {
688                 echo _("Sorry, cannot open.");
689         } else {
690                 while (($s = fgets($f, 1000)) != false) {
691                         echo $s;
692                 }
693         }
694
695         if (!$plain)
696                 end_pre();
697 }
698
699
700 function adv_search()
701 {
702   global $addr, $url, $local, $_POST, $off, $cnt, $root_directory;
703
704   $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
705
706   echo "<form action=\"index.php?action=adv_search\" method=\"post\">";
707
708   echo "<div align=\"center\">";
709   echo "<table border=\"0\">\n";
710   echo "<tr>\n";
711   echo "<td>"._("Package name")."</td>\n";
712   echo "<td><input type=\"text\" size=\"20\" name=\"name\" value=\"".$_POST[name]."\"/></td>\n";
713   echo "</tr>\n";
714
715   echo "<tr>\n";
716   echo "<td>"._("Days")."</td>\n";
717   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"age1\" value=\"".$_POST["age1"]."\" /></td>\n";
718   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"age2\" value=\"".$_POST["age2"]."\" /></td>\n";
719   echo "</tr>\n";
720
721   echo "<tr>\n";
722   echo "<td>"._("Size")."</td>\n";
723   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"size1\" value=\"".$_POST["size1"]."\" /></td>\n";
724   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"size2\" value=\"".$_POST["size2"]."\" /></td>\n";
725   echo "</tr>\n";
726
727   echo "<tr>\n";
728   echo "<td>"._("Search logs:")."</td>\n";
729   echo "</tr>\n";
730
731   echo "<tr>\n";
732   echo "<td>"._("Failed")."</td>\n";
733   echo "<td>"._("OK")."</td>\n";
734   echo "</tr>\n";
735
736   for ($i = 0; $i < count($addr); $i++)
737   {
738     echo "<tr>\n";
739     $name="as0_".$i;
740     $check=" checked=\"on\"";
741     echo "<td><input name=$name type=\"checkbox\"$check>".$addr[$i]."</input></td>\n";
742     $name="as1_".$i;
743     $check=" checked=\"on\"";
744     echo "<td><input name=$name type=\"checkbox\"$check>".$addr[$i]."</input></td>\n";
745     echo "</tr>\n";
746   }
747         
748   echo "<tr>\n";
749   echo "<td><input type=submit name=submit value=\""._("Search!")."\" /></td>";
750   echo "</tr>\n";
751
752   echo "</table>\n";
753
754 //      if (isset($_POST["name"]) || isset($_POST["age1"]) || isset($_POST["age2"]) ||
755 //        isset($_POST["size1"]) || isset($_POST["size2"]))
756   if (($_POST["name"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") ||
757     ($_POST["size1"]!="") || ($_POST["size2"]!=""))
758   {
759     unset($list);
760     $now = time();
761     for ($i = 0; $i < count($addr); $i++)
762     
763       for ($j=0;$j<2;$j++)
764         {
765           unset($tmp_list);
766           if (isset($_POST["as".$j."_".$i]))
767           {
768             if ($local) {
769                 $tmp_list = directory_list($i,$j);
770             } else {
771                 $tmp_list = open_ftp($i,$j);
772             }
773             if (is_array($tmp_list))
774             {
775               while (list($k,$name)=each($tmp_list))
776               {
777                 $s = filesize("$root_directory$name");
778                 $t = $now - filemtime("$root_directory$name");
779                 $t/=(24*3600);
780                 if (($_POST["name"]!="") && (!preg_match("/".$_POST["name"]."/i",$name)))continue;
781                 if (($_POST["age1"]) && ($_POST["age1"]>$t))continue;
782                 if (($_POST["age2"]) && ($_POST["age2"]<$t))continue;
783
784                 if (($_POST["size1"]) && ($_POST["size1"]>$s))continue;
785                 if (($_POST["size2"]) && ($_POST["size2"]<$s))continue;
786
787                 $list[$i."_".$j."_".$k]=$name;
788               }
789             }
790           }
791         }
792         
793         if (sizeof($list)==0)
794         {
795           echo _("Nothing found");
796         } else
797         {
798
799         echo "<table border=\"0\" cellspacing=\"1\" ".
800                 "cellpadding=3 bgcolor=\"#000000\" width=\"90%\">\n";
801         echo "<tr><th bgcolor=\"#CCCCFF\" align=\"left\" width=\"10%\">"._("Builder").
802              "[<a href=\"$big_url&amp;ns=2\">"._("sort")."</a>]</th>";
803         echo "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"60%\">"._("Log File").
804                         "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
805                  "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
806                  "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
807                          "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
808                  "</th></tr>";
809
810         function cmp1($f1, $f2) {
811                 global $ftp_conn, $root_directory, $local;
812                 if ($local)
813                         return filemtime("$root_directory$f2") - filemtime("$root_directory$f1");
814                 return ftp_mdtm($ftp_conn, $f2) - ftp_mdtm($ftp_conn, $f1);
815         }
816
817         function cmp2($f1, $f2) {
818           list($p11,$p12,$p13)=explode("_",$f1);
819           list($p21,$p22,$p23)=explode("_",$f2);
820           return strcmp($f2,$f1);
821         }
822
823         if ($ns == 1)
824         {
825           usort($list, "cmp1");
826 //      } else if ($ns == 2)
827 //      {
828 //        uksort($list, "cmp2");
829         } else
830         {
831           asort($list);
832         }
833
834         $counter=0;
835         while (list($k,$name)=each($list))
836         {
837         if (($counter<$off) || ($counter>$off+$cnt-1))
838         {
839           $counter++;
840           continue;
841         }
842
843           $counter++;
844           list($i,$j,$k)=explode("_",$k);
845
846                 $h = bin2hex(mhash(MHASH_MD5, $name));
847                 $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $name);
848                 $f = preg_replace("/\.(bz2|gz)$/", "", $f);
849                 if ($local) {
850                         $s = filesize("$root_directory$name");
851                         $t = $now - filemtime("$root_directory$name");
852                 } else {
853                         $s = ftp_size($ftp_conn, $list[$i]);
854                         $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
855                 }
856                 $t /= 60;
857                 if ($t >= 60) {
858                         $t /= 60;
859                         if ($t >= 24) {
860                                 $t /= 24;
861                                 $t = round($t);
862                                 $t = $t . "&nbsp;" . ngettext("day","days",$t);
863                         } else {
864                                 $t = round($t);
865                                 $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
866                         }
867                 } else {
868                         $t = round($t);
869                         $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
870                 }
871                 $big_url = "$url?idx=$i&amp;ok=$j&amp;ns=$ns&amp;cnt=$cnt";
872                 $u = "$big_url&amp;off=$off&amp;id=$h";
873
874                 $builder=$addr[$i]."/".(($j=="1")?"OK":"FAIL");
875                 echo "<tr>";
876                 echo "<td bgcolor=#CCCCCC><a href=\"$u\">$builder</a></td>";
877                 echo "<td bgcolor=#CCCCCC><a href=\"$u\">$f</a> ".
878                      "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
879                       "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
880                      "</td><td bgcolor=#CCCCCC align=right>".
881                      "$s</td><td bgcolor=#CCCCCC>$t</td></tr>\n";
882         }
883         echo "</table></div>\n";
884
885         $backarr = "&lt;&lt;&lt;&nbsp;";
886         $back = _("Page back");
887         $forward = _("Page forward");
888         $forwardarr = "&nbsp;&gt;&gt;&gt;";
889
890 // FIXME
891 /*
892         echo "<p><table width=\"90%\" align=\"center\"><tr><td align=left width=1%>";
893
894         if ($off > 0) {
895                 $noff = $off - $cnt;
896                 if ($noff < 0)  
897                         $noff = 0;
898                 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
899                 echo "$hrefurl$backarr</a></td><td align=left>$hrefurl$back</a>";
900         } else {
901                 echo "$backarr</td><td align=left>$back";
902         }
903
904     echo "</td>\n<td align=\"center\">";
905     echo "</td>\n<td align=\"right\">";
906
907     if ($off + $cnt < count($list))
908     {
909       $noff = $off + $cnt;
910       if ($noff < 0)    
911         $noff = 0;
912       $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
913       echo "$hrefurl$forward</a></td><td align=\"right\" width=\"1%\">$hrefurl$forwardarr</a>";
914     }
915     else
916     {
917       echo "$forward</td><td align=\"right\" width=\"1%\">$forwardarr";
918     }
919
920     echo "</td>\n</tr></table></p>";
921 */
922     }
923     if ($local == 0)
924     {
925       ftp_quit($ftp_conn);
926       $ftp_conn = 0;
927     }
928   } else
929   {
930     echo _("Enter something!");
931   }
932   echo "</form>\n";
933 }
934
935 function welcome()
936 {
937 ?>
938 <table border="0" width="100%"><tr><td width="20%">&nbsp;</td><td>
939 <h1><?=_("Welcome!")?></h1>
940 <p><?=_("Welcome to PLD Build Logs WWW interface.")?></p><p>
941 <?=_("Feel free to email bug reports, complaints and feature requests ")?>
942 <!-- ech... niech strace... -->
943 <a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?> 
944 <a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a> ;)</p>
945 <p>Version: $Id: index.php,v 1.61 2003/06/07 15:14:31 blues Exp $</p>
946 </td><td width="20%">&nbsp;</td></tr>
947 </table>
948 <?php
949 }
950
951 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
952 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
953 header("Cache-Control: no-cache, must-revalidate");
954 header("Pragma: no-cache");
955
956 //phpinfo();
957 if ($local) {
958         if ($action == "text") {
959                 dump_text();
960         } else if ($action == "adv_search") {
961                 myheader();
962                 adv_search();
963                 trailer();
964         } else if ($action == "qatxt") {
965                 dump_qa(1);
966         } else {
967                 myheader();
968                 echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=\"top\" width=\"10%\">";
969                 list_archs();
970                 echo "</td><td valign=\"top\">";
971                 flush();
972                 if ($action == "qa")
973                         dump_qa(0);
974                 else if ($action == "sqa")
975                         search_qa();
976                 else if (isset($id))
977                         dump_log($action == "tail");
978                 else if (isset($idx))
979                         list_logs();
980                 else 
981                         welcome();
982                 echo "</td></tr></table>";
983                 trailer();
984         }
985 }
986 else {
987
988         if ($action == "text") {
989                 dump_text();
990         } else if ($action == "qatxt") {
991                 dump_qa(1);
992         } else {
993                 myheader();
994                 echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=top width=\"10%\">";
995                 list_archs();
996                 echo "</td><td valign=\"top\">";
997                 flush();
998                 if ($action == "qa")
999                         dump_qa(0);
1000                 else if (isset($id))
1001                         dump_log($action == "tail");
1002                 else if (isset($idx))
1003                         list_logs();
1004                 else 
1005                         welcome();
1006                 echo "</td></tr></table>";
1007                 trailer();
1008         }
1009 }
1010 ?>
This page took 0.136229 seconds and 3 git commands to generate.