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