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