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