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