]> git.pld-linux.org Git - projects/buildlogs.git/blob - obsolete/buildlogs/index.php
- allow easy checkboxes toggle in advanced search
[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.88 $'.
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 "<script><!--\n".
757        "function checkboxToggle() {\n".
758        "for (var i=0;i<document.forms[0].elements.length;i++) {\n".
759        "var e = document.forms[0].elements[i];\n".
760        "if ((e.name != 'all') && (e.type=='checkbox'))\n".
761        "e.checked = document.forms[0].all.checked;\n".
762        "}\n }\n -->\n </script>\n";
763
764   echo "<form action=\"index.php?action=adv_search\" method=\"post\">";
765
766   echo "<div align=\"center\">";
767   echo "<table border=\"0\">\n";
768   echo "<tr>\n";
769   echo "<td>"._("Package name")."</td>\n";
770   echo "<td><input type=\"text\" size=\"20\" name=\"name\" value=\"".$_POST["name"]."\"/></td>\n";
771   echo "</tr>\n";
772
773   echo "<tr>\n";
774   echo "<td>"._("Days")."</td>\n";
775   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"age1\" value=\"".$_POST["age1"]."\" /></td>\n";
776   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"age2\" value=\"".$_POST["age2"]."\" /></td>\n";
777   echo "</tr>\n";
778
779   echo "<tr>\n";
780   echo "<td>"._("Size")."</td>\n";
781   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"size1\" value=\"".$_POST["size1"]."\" /></td>\n";
782   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"size2\" value=\"".$_POST["size2"]."\" /></td>\n";
783   echo "</tr>\n";
784
785   echo "<tr>\n";
786   echo "<td>"._("Search logs:")."</td>\n";
787   echo "</tr>\n";
788
789   echo "<tr>\n";
790   echo "<td>"._("Failed")."</td>\n";
791   echo "<td>"._("OK")."</td>\n";
792   echo "</tr>\n";
793
794   for ($i = 0; $i < count($addr); $i++)
795   {
796     echo "<tr>\n";
797     $name="as0_".$i;
798     $check=" checked=\"on\"";
799     echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">".$addr[$i]."</label></td>\n";
800     $name="as1_".$i;
801     $check=" checked=\"on\"";
802     echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">".$addr[$i]."</label></td>\n";
803     echo "</tr>\n";
804   }
805         
806   echo "<tr>\n";
807   echo "<td><input name=\"all\" type=\"checkbox\" checked=\"on\" onClick=\"checkboxToggle()\">"._("Toggle checkboxes")."&nbsp;<input type=\"submit\" name=\"submit\" value=\""._("Search!")."\" /></td>";
808   echo "</tr>\n";
809
810   echo "</table>\n";
811
812 //      if (isset($_POST["name"]) || isset($_POST["age1"]) || isset($_POST["age2"]) ||
813 //        isset($_POST["size1"]) || isset($_POST["size2"]))
814   if (($_POST["name"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") ||
815     ($_POST["size1"]!="") || ($_POST["size2"]!=""))
816   {
817     unset($list);
818     $now = time();
819     for ($i = 0; $i < count($addr); $i++)
820     
821       for ($j=0;$j<2;$j++)
822         {
823           unset($tmp_list);
824           if (isset($_POST["as".$j."_".$i]))
825           {
826             if ($local) {
827                 $tmp_list = directory_list($i,$j);
828             } else {
829                 $tmp_list = open_ftp($i,$j);
830             }
831             if (is_array($tmp_list))
832             {
833               while (list($k,$name)=each($tmp_list))
834               {
835                 $s = filesize("$root_directory$name[0]");
836                 $t = $now - $name[1];
837                 $t/=(24*3600);
838                 if (($_POST["name"]!="") && (!preg_match("/".$_POST["name"]."/i",$name[0])))continue;
839                 if (($_POST["age1"]) && ($_POST["age1"]>$t))continue;
840                 if (($_POST["age2"]) && ($_POST["age2"]<$t))continue;
841
842                 if (($_POST["size1"]) && ($_POST["size1"]>$s))continue;
843                 if (($_POST["size2"]) && ($_POST["size2"]<$s))continue;
844
845                 $list[$i."_".$j."_".$k]=$name;
846               }
847             }
848           }
849         }
850         
851         if (sizeof($list)==0)
852         {
853           echo _("Nothing found");
854         } else
855         {
856
857         echo "<table border=\"0\" cellspacing=\"1\" ".
858                 "cellpadding=3 bgcolor=\"#000000\" width=\"90%\">\n";
859         echo "<tr><th bgcolor=\"#CCCCFF\" align=\"left\" width=\"10%\">"._("Builder").
860              "[<a href=\"$big_url&amp;ns=2\">"._("sort")."</a>]</th>";
861         echo "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"60%\">"._("Log File").
862                         "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
863                  "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
864                  "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
865                          "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
866                  "</th></tr>";
867
868         function cmp1($f1, $f2) {
869                 global $ftp_conn, $root_directory, $local;
870                 if ($local)
871                         return $f2[1] - $f1[1];
872                 return ftp_mdtm($ftp_conn, $f2) - ftp_mdtm($ftp_conn, $f1);
873         }
874
875         function cmp2($f1, $f2) {
876           list($p11,$p12,$p13)=explode("_",$f1[0]);
877           list($p21,$p22,$p23)=explode("_",$f2[0]);
878           return strcmp($f1[0],$f2[0]);
879         }
880
881         if ($ns == 1)
882         {
883           usort($list, "cmp1");
884 //      } else if ($ns == 2)
885 //      {
886 //        uksort($list, "cmp2");
887         } else
888         {
889           asort($list);
890         }
891
892         $counter=0;
893         while (list($k,$name)=each($list))
894         {
895         if (($counter<$off) || ($counter>$off+$cnt-1))
896         {
897           $counter++;
898           continue;
899         }
900
901           $counter++;
902           list($i,$j,$k)=explode("_",$k);
903           $filename = $name[0];
904
905                 $h = bin2hex(mhash(MHASH_MD5, $filename));
906                 $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $filename);
907                 $f = preg_replace("/\.(bz2|gz)$/", "", $f);
908                 if ($local) {
909                         $s = filesize("$root_directory$filename");
910                         $t = $now - $name[1];
911                 } else {
912                         $s = ftp_size($ftp_conn, $list[$i]);
913                         $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
914                 }
915                 $t /= 60;
916                 if ($t >= 60) {
917                         $t /= 60;
918                         if ($t >= 24) {
919                                 $t /= 24;
920                                 $t = round($t);
921                                 $t = $t . "&nbsp;" . ngettext("day","days",$t);
922                         } else {
923                                 $t = round($t);
924                                 $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
925                         }
926                 } else {
927                         $t = round($t);
928                         $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
929                 }
930                 $big_url = "$url?idx=$i&amp;ok=$j&amp;ns=$ns&amp;cnt=$cnt";
931                 $u = "$big_url&amp;off=$off&amp;id=$h";
932
933                 $builder=$addr[$i]."/".(($j=="1")?"OK":"FAIL");
934                 echo "<tr>";
935                 echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$builder</a></td>";
936                 echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ".
937                      "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
938                       "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
939                      "</td><td bgcolor=\"#CCCCCC\" align=\"right\">".
940                      "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n";
941         }
942         echo "</table></div>\n";
943
944         $backarr = "&lt;&lt;&lt;&nbsp;";
945         $back = _("Page back");
946         $forward = _("Page forward");
947         $forwardarr = "&nbsp;&gt;&gt;&gt;";
948
949 // FIXME
950 /*
951         echo "<p><table width=\"90%\" align=\"center\"><tr><td align=left width=1%>";
952
953         if ($off > 0) {
954                 $noff = $off - $cnt;
955                 if ($noff < 0)  
956                         $noff = 0;
957                 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
958                 echo "$hrefurl$backarr</a></td><td align=left>$hrefurl$back</a>";
959         } else {
960                 echo "$backarr</td><td align=left>$back";
961         }
962
963     echo "</td>\n<td align=\"center\">";
964     echo "</td>\n<td align=\"right\">";
965
966     if ($off + $cnt < count($list))
967     {
968       $noff = $off + $cnt;
969       if ($noff < 0)    
970         $noff = 0;
971       $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
972       echo "$hrefurl$forward</a></td><td align=\"right\" width=\"1%\">$hrefurl$forwardarr</a>";
973     }
974     else
975     {
976       echo "$forward</td><td align=\"right\" width=\"1%\">$forwardarr";
977     }
978
979     echo "</td>\n</tr></table></p>";
980 */
981     }
982     if ($local == 0)
983     {
984       ftp_quit($ftp_conn);
985       $ftp_conn = 0;
986     }
987   } else
988   {
989     echo _("Enter something!");
990   }
991   echo "</form>\n";
992 }
993
994 function welcome()
995 {
996 ?>
997 <table border="0" width="100%"><tr><td width="20%">&nbsp;</td><td>
998 <h1><?=_("Welcome!")?></h1>
999 <p><?=_("Welcome to PLD Build Logs WWW interface.")?></p><p>
1000 <?=_("Feel free to email bug reports, complaints and feature requests ")?>
1001 <!-- ech... niech strace... -->
1002 <a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?> 
1003 <a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a> ;)</p>
1004 <p>Version: $Id: index.php,v 1.88 2006/09/15 18:16:37 witekfl Exp $</p>
1005 </td><td width="20%">&nbsp;</td></tr>
1006 </table>
1007 <?php
1008 }
1009
1010 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
1011 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
1012 header("Cache-Control: no-cache, must-revalidate");
1013 header("Pragma: no-cache");
1014
1015 //phpinfo();
1016 if ($local) {
1017         if ($action == "text") {
1018                 dump_text();
1019         } else if ($action == "adv_search") {
1020                 myheader();
1021                 adv_search();
1022                 trailer();
1023         } else if ($action == "qatxt") {
1024                 dump_qa(1);
1025         } else {
1026                 myheader();
1027                 echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=\"top\" width=\"10%\">";
1028                 list_archs();
1029                 echo "</td><td valign=\"top\">";
1030                 flush();
1031                 if ($action == "qa")
1032                         dump_qa(0);
1033                 else if ($action == "sqa")
1034                         search_qa();
1035                 else if (isset($id))
1036                         dump_log($action == "tail");
1037                 else if (isset($idx))
1038                         list_logs();
1039                 else 
1040                         welcome();
1041                 echo "</td></tr></table>";
1042                 trailer();
1043         }
1044 }
1045 else {
1046
1047         if ($action == "text") {
1048                 dump_text();
1049         } else if ($action == "qatxt") {
1050                 dump_qa(1);
1051         } else {
1052                 myheader();
1053                 echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=top width=\"10%\">";
1054                 list_archs();
1055                 echo "</td><td valign=\"top\">";
1056                 flush();
1057                 if ($action == "qa")
1058                         dump_qa(0);
1059                 else if (isset($id))
1060                         dump_log($action == "tail");
1061                 else if (isset($idx))
1062                         list_logs();
1063                 else 
1064                         welcome();
1065                 echo "</td></tr></table>";
1066                 trailer();
1067         }
1068 }
1069 ?>
This page took 0.353013 seconds and 3 git commands to generate.