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