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