]> git.pld-linux.org Git - projects/buildlogs.git/blob - obsolete/buildlogs/index.php
- restored English text
[projects/buildlogs.git] / obsolete / buildlogs / index.php
1 <?php
2 $buildlogs_server = "buildlogs.pld.org.pl";
3 $url = "index.php";
4 $addr = array(
5         "/nest/athlon",
6         "/nest/i386",
7         "/nest/i586",
8         "/nest/i686",
9         "/nest/ppc",
10         "/ra/i386",
11         "/ra/i586",
12         "/ra/i686",
13         "/ra/alpha",
14         "/ra/sparc",
15         "/ra/ppc"
16 );
17 $qa_base = "http://ftp.pld.org.pl/.stat/builder";
18 $qa_addr = array(
19         "",
20         "/kenny/rpmqa-nest-i386.txt",
21         "/kenny/rpmqa-nest-i586.txt",
22         "/kenny/rpmqa-nest-i686.txt",
23         "",
24         "/ep/rpmqa-ra-i386.txt",
25         "/ep/rpmqa-ra-i586.txt",
26         "/ep/rpmqa-ra-i686.txt",
27         "/mifgate/rpmqa-ra-alpha.txt",
28         "/team/rpmqa-ra-sparc.txt",
29         ""
30 );
31 $local = 1; /* $local=0 for FTP */ 
32 $root_directory = "/home/services/ftp/pub/logs";
33 $ftp_conn = 0;
34 /* It should be set */
35
36
37 function myheader()
38 {
39 ?>
40 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
41     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
42 <html xmlns="http://www.w3.org/1999/xhtml">
43  <head>
44   <title>PLD Build Logs</title>
45   <style TYPE="text/css"><!--
46 A { text-decoration: none; }
47 A:hover { text-decoration: underline; }
48 H1 { font-family: arial,helvetica,sans-serif; 
49      font-size: 20pt; 
50      font-weight: bold;}
51 H2 { font-family: arial,helvetica,sans-serif; 
52      font-size: 18pt; 
53      font-weight: bold;}
54 BODY,TD { font-family: arial,helvetica,sans-serif; 
55           font-size: 13pt; }
56 TH { font-family: arial,helvetica,sans-serif; 
57      font-size: 13pt; 
58      font-weight: bold; }
59 //-->
60 </style>
61  </head>
62  <!-- Diffrent color for visited link doesn't make much sense here...
63       this page is autogenerated and it might be misleading after some
64       build log changes. -->
65  <body bgcolor="#ffffff" text="#000000" link="#5f26cd" vlink="#5f26cd">
66 <?php
67 }
68
69 function start_pre()
70 {
71         echo "<table cellpadding=10><tr><td bgcolor=\"#000000\">".
72                 "<font color=\"#cccccc\"><pre>";
73 }
74
75 function end_pre()
76 {
77         echo "</pre></font></td></tr></table>\n";
78 }
79
80 function trailer()
81 {
82         echo "</body></html>";
83 }
84
85
86 function mydie($msg)
87 {
88         echo "Fatal error: $msg";
89 }
90
91 function open_ftp()
92 {
93         global $idx, $addr, $buildlogs_server, $ok;
94         global $ftp_conn, $big_url, $url, $ns;
95         global $off, $cnt;
96
97         if (!isset($idx) || !isset($addr[$idx]))
98                 return false;
99
100         if ($ok != 1)
101                 $ok = 0;
102         if ($ns != 1)
103                 $ns = 0;
104
105         if ($ok == 1) {
106                 $a = "$addr[$idx]/OK";
107         } else {
108                 $a = "$addr[$idx]/FAIL";
109         }
110
111         if (!isset($off))
112                 $off = 0;
113         if (!isset($cnt))
114                 $cnt = 16;
115
116         $big_url = "$url?idx=$idx&ok=$ok&ns=$ns&cnt=$cnt";
117
118         $ftp = ftp_connect($buildlogs_server);
119
120         if ($ftp == false) {
121                 mydie("cannot connect to $buildlogs_server");
122                 return false;
123         }
124
125         if (ftp_login($ftp, "anonymous", 
126                       "buildlogs-iface@pld.org.pl") == false) {
127                 ftp_quit($ftp);
128                 mydie("cannot ftp login to $buildlogs_server");
129                 return false;
130         }
131
132         $list = ftp_nlist($ftp, $a);
133         if ($list == false) {
134                 ftp_quit($ftp);
135                 mydie("cannot list $a");
136                 return false;
137         }
138
139         $ftp_conn = $ftp;
140
141         return $list;
142 }
143
144 function directory_list()
145 {
146         global $idx, $addr, $buildlogs_server, $ok;
147         global $root_directory, $big_url, $url, $ns;
148         global $off, $cnt;
149
150         if (!isset($idx) || !isset($addr[$idx]))
151                 return false;
152
153         if ($ok != 1)
154                 $ok = 0;
155         if ($ns != 1)
156                 $ns = 0;
157
158         if ($ok == 1) {
159                 $a = "$addr[$idx]/OK";
160         } else {
161                 $a = "$addr[$idx]/FAIL";
162         }
163
164         if (!isset($off))
165                 $off = 0;
166         if (!isset($cnt))
167                 $cnt = 16;
168
169         $big_url = "$url?idx=$idx&ok=$ok&ns=$ns&cnt=$cnt";
170
171         $dir = opendir("$root_directory$a");
172         $i = 0;
173         while ($file = readdir($dir)) {
174                 if (($file != ".") && ($file != "..")) {
175                         $list[$i] = "$a/$file";
176                         $i++;
177                 }
178         }
179         closedir($dir);
180         return $list;
181 }
182
183 function list_logs()
184 {
185         global $idx, $addr, $ok;
186         global $ftp_conn, $big_url, $ns, $qa_addr;
187         global $off, $cnt, $local, $root_directory;
188
189         if ($local) {
190                 $list = directory_list();
191         } else {
192                 $list = open_ftp();
193         }
194         if ($list == false)
195                 return;
196
197         if ($ok == 1) {
198                 echo "<h1>Listing of $addr[$idx]/OK "
199                         ."(<a href=\"$big_url&ok=0\">fail</a>)</h1>";
200         } else {
201                 echo "<h1>Listing of $addr[$idx]/FAIL "
202                         ."(<a href=\"$big_url&ok=1\">ok</a>)</h1>";
203         }
204
205         echo "<div align=center><table border=0 cellspacing=1 ".
206                 "cellpadding=3 bgcolor=#000000 width=90%>\n";
207         echo "<tr><th bgcolor=#CCCCFF align=left width=60%>Log File ".
208                         "[<a href=\"$big_url&ns=1\">sort</a>]</th>".
209                  "<th bgcolor=#CCCCFF align=right width=15%>Size</th> ".
210                  "<th bgcolor=#CCCCFF align=left>Age ".
211                          "[<a href=\"$big_url&ns=0\">sort</a>]</th>".
212                  "</th></tr>";
213
214         function cmp($f1, $f2) {
215                 global $ftp_conn, $root_directory, $local;
216                 if ($local)
217                         return filemtime("$root_directory$f2") - filemtime("$root_directory$f1");
218                 return ftp_mdtm($ftp_conn, $f2) - ftp_mdtm($ftp_conn, $f1);
219         }
220
221         if ($ns != 1) {
222                 $ns = 0;
223                 usort($list, cmp);
224         } else {
225                 sort($list);
226         }
227
228         $now = time();
229         for ($i = $off; $i < $cnt + $off; $i++) {
230                 if (!isset($list[$i]))
231                         continue;
232                 $h = bin2hex(mhash(MHASH_MD5, $list[$i]));
233                 $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $list[$i]);
234                 $f = preg_replace("/\.(bz2|gz)$/", "", $f);
235                 if ($local) {
236                         $s = filesize("$root_directory$list[$i]");
237                         $t = $now - filemtime("$root_directory$list[$i]");
238                 } else {
239                         $s = ftp_size($ftp_conn, $list[$i]);
240                         $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
241                 }
242                 $t /= 60;
243                 if ($t >= 60) {
244                         $t /= 60;
245                         if ($t >= 24) {
246                                 $t /= 24;
247                                 $t = round($t);
248                                 if ($t > 1) {
249                                         $t = $t . " days";
250                                 } else {
251                                         $t = $t . " day";
252                                 }
253                         } else {
254                                 $t = round($t);
255                                 if ($t > 1) {
256                                         $t = $t . " hours";
257                                 } else {
258                                         $t = $t . " hour";
259                                 }
260                         }
261                 } else {
262                         $t = round($t);
263                         if ($t != 1) {
264                                 $t = $t . " minutes";
265                         } else {
266                                 $t = $t . " minute";
267                         }
268                 }
269                 $u = "$big_url&off=$off&id=$h";
270                 echo "<tr><td bgcolor=#CCCCCC><a ".
271                         "href=\"$u\">".
272                      "$f</a> ".
273                      "[<a href=\"$u&action=text\">text</a> | ".
274                       "<a href=\"$u&action=tail\">tail</a>]".
275                      "</td><td bgcolor=#CCCCCC align=right>".
276                      "$s</td><td bgcolor=#CCCCCC>$t</td></tr>\n";
277         }
278         echo "</table></div>\n";
279
280         $back = "<table><tr><td>&lt;&lt;&lt;</td><td> Page back</td></tr></table>";
281         $forward = "<table><tr><td>Page forward </td><td>&gt;&gt;&gt;</td></tr></table>";
282
283         echo "<p align=center><table width=90%><tr><td align=left width=25%>";
284
285         if ($off > 0) {
286                 $noff = $off - $cnt;
287                 if ($noff < 0)  
288                         $noff = 0;
289                 echo "<a href=\"$big_url&off=$noff\">$back</a>\n";
290         } else {
291                 echo "$back\n";
292         }
293
294         echo "</td><td width=50% align=center>";
295
296         if ($qa_addr[$idx] != "") {
297                 echo "[<a href=\"$big_url&action=qa\">View rpm -qa of ".
298                         "builder</a>]\n";
299         } else {
300                 echo "&nbsp;";
301         }
302
303         echo "</td><td align=right width=25%>";
304         if ($off + $cnt < count($list)) {
305                 $noff = $off + $cnt;
306                 if ($noff < 0)  
307                         $noff = 0;
308                 echo "<a href=\"$big_url&off=$noff\">$forward</a>\n";
309         } else {
310                 echo "$forward\n";
311         }
312         echo "</td></tr></table></p>";
313         if ($local == 0) {
314                 ftp_quit($ftp_conn);
315                 $ftp_conn = 0;
316         }
317 }
318
319 function file_name()
320 {
321         global $idx, $addr, $ok;
322         global $ftp_conn, $root_directory, $big_url, $ns, $id;
323         global $buildlogs_server, $local;
324
325         if (!isset($id))
326                 return false;
327         if ($local) {
328                 $list = directory_list();
329         } else {
330                 $list = open_ftp();
331         }
332         if ($list == false)
333                 return false;
334
335         $f = false;
336         for ($i = 0; $i < count($list); $i++) {
337                 $h = bin2hex(mhash(MHASH_MD5, $list[$i]));
338                 if ($h == $id) {
339                         $f = $list[$i];
340                 }
341         }
342
343         if ($f == false) {
344                 mydie("cannot find specified file: $id");
345                 if ($local == 0)
346                         ftp_quit($ftp_conn);
347                 return false;
348         }
349
350         return $f;
351 }
352
353 function dump_log($tail)
354 {
355         global $idx, $addr, $ok, $url;
356         global $ftp_conn, $root_directory, $big_url, $ns, $id, $cnt, $off;
357         global $buildlogs_server, $local, $qa_addr;
358
359         $f = file_name();
360
361         if ($f == false)
362                 return;
363
364         $df = preg_replace("/.*\/([^\/]*)$/", "\\1", $f);
365         $df = preg_replace("/\.(bz2|gz)$/", "", $df);
366
367         echo "<h1>$df</h1>";
368
369         echo "<table border=0 cellpadding=3 cellspacing=1 bgcolor=#000000>";
370
371         function one_item($h, $t) {
372                 echo "<tr><td bgcolor=#ccccff>$h:</td>".
373                          "<td bgcolor=#cccccc>$t</td></tr>";
374         }
375
376         function href($h, $c) {
377                 return "<a href=\"$h\">$c</a>";
378         }
379
380         one_item("Status", ($ok == 1 ?  
381                                 "<font color=green><b>OK</b></font>" : 
382                                 "<font color=red><b>Failed</b></a>"));
383         one_item("Source URL", 
384                  href("ftp://$buildlogs_server$f", 
385                       "ftp://$buildlogs_server$f"));
386
387         $bu = "$big_url&off=$off";
388
389         one_item("text/plain URL", 
390                  href("$bu&id=$id&action=text",
391                       "View!"));
392         if ($tail) {
393                 one_item("full text", 
394                          href("$bu&&id=$id",
395                               "View!"));
396         }
397
398         if ($qa_addr[$idx] != "") {
399                 one_item("rpm -qa of builder", href("$bu&action=qa", "View!"));
400         } else {
401                 one_item("rpm -qa of builder", "Not available");
402         }
403         if ($local) {
404                 one_item("Data", date("Y/m/d H:i:s", filemtime("$root_directory$f")));
405         } else {
406                 one_item("Data", date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)));
407         }
408         /*
409         echo "<tr><td>Here:</td><td>" . 
410                 "<a href=\"$url?idx=$idx&ok=$ok&id=$id\">".
411                 "http://" . getenv("SERVER_NAME") .
412                 getenv("SCRIPT_NAME") . "?idx=$idx&ok=$ok&id=$id</a>" .
413              "</td></tr>"; */
414
415         echo "</table><h2>Content:</h2>";
416
417         if ($local == 0) {
418                 ftp_quit($ftp_conn);
419                 $ftp_conn = 0;
420         }
421
422
423         # what can I say beside PHP suxx? how the fuck should I create
424         # bidirectional pipe? gotta use wget
425
426         if (preg_match("/\.bz2$/", $f)) {
427                 $filter = "bzcat";
428         } elseif (preg_match("/\.gz$/", $f)) {
429                 $filter = "zcat";
430         } else {
431                 $filter = "cat";
432         }
433
434         if ($local) {
435                 $cmd = "$filter $root_directory$f";
436         } else {
437                 $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
438         }
439         if ($tail)
440                 $cmd = "$cmd | tail -n 100";
441         $fd = popen($cmd, "r");
442         start_pre();
443         while (($s = fgets($fd, 1000)) != false) {
444                 $s = htmlspecialchars($s);
445                 echo $s;
446         }
447         end_pre();
448         pclose($fd);
449
450 ?>
451         <table width=100%>
452          <tr>
453           <td align=left>
454            [<a href="<?php echo $bu; ?>">Back to list of logs</a>]
455           </td>
456           <td align=right>
457            [<a href="<?php echo "$bu&action=qa" 
458                 ?>">View rpm -qa of builder</a>]
459           </td>
460          </tr>
461         </table>
462 <?php
463
464 }
465
466 function dump_text()
467 {
468         global $ftp_conn, $root_directory;
469         global $buildlogs_server, $local;
470
471         header("Content-type: text/plain");
472
473         $f = file_name();
474
475         if ($f == false)
476                 return;
477
478         echo "# src  : ftp://$buildlogs_server$f\n";
479         if ($local) {
480                 echo "# date   : " .  
481                         date("Y/m/d H:i:s", filemtime("$root_directory$f")) . "\n";
482         } else {
483                 echo "# date   : " .  
484                         date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)) . "\n";
485                 ftp_quit($ftp_conn);
486                 $ftp_conn = 0;
487         }
488
489         if (preg_match("/\.bz2$/", $f)) {
490                 $filter = "bzcat";
491         } elseif (preg_match("/\.gz$/", $f)) {
492                 $filter = "zcat";
493         } else {
494                 $filter = "cat";
495         }
496
497         if ($local) {
498                 $cmd = "$filter $root_directory$f";
499         } else {
500                 $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
501         }
502         $fd = popen($cmd, "r");
503         while (($s = fgets($fd, 1000)) != false) {
504                 echo $s;
505         }
506         pclose($fd);
507 }
508
509 function list_archs()
510 {
511         global $addr, $url, $idx;
512
513         echo "<table width=100% border=0>\n";
514         echo "<tr><td bgcolor=#cccccc nowrap=1>Failed</td><td bgcolor=#cccccc>Ok</td></tr>\n";
515         for ($i = 0; $i < count($addr); $i++)
516                 echo "<tr><td nowrap=1>".
517                      "<a href=\"$url?idx=$i&ok=0\">$addr[$i]</a></td><td nowrap=1>".
518                      "[<a href=\"$url?idx=$i&ok=1\">OK</a>]</td>".
519                      #"<td>[<a href=\"$url?idx=$i&action=qa\">qa</a>]</td>".
520                      "</tr>\n";
521         echo "</table><hr />\n";
522         echo "<div align=\"center\"><a href=\"$url\">main()</a><hr />\n";
523         echo "<a href=\"http://www.pld.org.pl/\"><img src=powpld.png ".
524                 "alt=\"Powered by PLD Linux\" border=0></a><br />\n" .
525              "<small>(c) 2002 ".
526              "<a href=\"mailto:feedback@pld.org.pl\">PLD&nbsp;Team</a>\n".
527              "</small></div>\n";
528
529         # smile ;)
530         echo "<div align=center><small>";
531         $pow = array("vim", "php", "brain", "power", "electricity",
532                      "coffee", "ufo", "penguin", "GNOME", "ELF", "DWARF",
533                      "voodoo magic", "Linux", "x-files", "X", "foobar",
534                      "/dev/null", "/dev/zero", "/dev/drzewo", 
535                      "Leppe'", "matrix", "Neo", "PDP-11",
536                      "Ken", "GNU antilope", "PDP-7", "ITS", "Multics",
537                      "foobarbaz", "ed", "Joe", "Unix conspiracy", 
538                      "overclock", "The Right Thing",
539                      "The Bad Thing", "Star Treck", "NSA", "NASA",
540                      "achelon", "VAX", "Real Programmer",
541                      "Real Operating System", "Real Computer",
542                      "computron", "bogon", "quantum bogodynamics",
543                      "BOFH", "/dev/ill", "nasi tu byli",
544                      "Paranoid Android", "Lunatic Corp"
545                      # feel free to add sth if you change this file ;)
546                      );
547         echo "Powered by ";
548         $max = 1;
549         for ($i = 0; $i < $max; $i++) {
550                 $x = rand(0, count($pow) - 1);
551                 if ($pow[$x] == "") $i--;
552                 else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
553                 $pow[$x] = "";
554         }
555
556         echo "</small></div>";
557
558         global $qa_addr;
559
560         if ($qa_addr[$idx] != "") {
561         echo "<form action=\"index.php\" method=\"post\">";
562         echo "<input type=hidden name=idx value=$idx />";
563         echo "<input type=hidden name=action value=sqa />";
564         echo "<input type=text size=14 name=str /><br/>";
565         echo "<input type=submit name=submit value=\"Search rpmqa!\" />";
566         echo "</form>";
567         }
568
569 }
570
571 function get_qa()
572 {
573         global $idx, $qa_addr, $qa_base;
574
575         if (!isset($idx) || !isset($qa_addr[$idx]))
576                 return false;
577
578         $a = $qa_addr[$idx];
579
580         if ($qa_addr[$idx] == "")
581                 return false;
582         else
583                 return fopen("$qa_base$qa_addr[$idx]", "r");
584 }
585
586 function search_qa()
587 {
588         global $url, $idx, $qa_addr, $str;
589
590         $f = get_qa();
591         echo "<h1>Search results for '$str' in $qa_addr[$idx]</h1>";
592
593         start_pre();
594
595         if ($f == 0) {
596                 echo "Sorry, cannot open.";
597         } else {
598                 while (($s = fgets($f, 1000)) != false) {
599                         if (stristr($s, $str))
600                                 echo $s;
601                 }
602                 echo "/* EOF */";
603         }
604         end_pre();
605 }
606
607 function dump_qa($plain)
608 {
609         global $url, $idx, $qa_addr;
610
611         $a = $qa_addr[$idx];
612
613         $f = get_qa();
614
615         if ($plain) {
616                 header("Content-type: text/plain"); 
617                 echo "# rpm -qa of $a\n";
618         } else {
619                 echo "<h1>rpm -qa of $a</h1>";
620                 echo "<a href=\"$url?idx=$idx&action=qatxt\">text/plain "
621                         ."version</a>";
622                 start_pre();
623         }
624
625         if ($f == 0) {
626                 echo "Sorry, cannot open.";
627         } else {
628                 while (($s = fgets($f, 1000)) != false) {
629                         echo $s;
630                 }
631         }
632
633         if (!$plain)
634                 end_pre();
635 }
636
637 function welcome()
638 {
639 ?>
640 <table border=0 width=100%><tr><td width=20%>&nbsp;</td><td>
641 <h1>Zdrastwuj!</h1>
642 <p>Welcome to PLD Build Logs WWW interface.</p><p>
643 Feel free to email bug reports, complaints and feature requests 
644 <!-- ech... niech strace... -->
645 <a href="mailto:malekith /at/ pld-linux org">to us</a>. Positive opinions are also 
646 <a href="mailto:malekith /at/ pld-linux org">welcome</a> ;)</p>
647 <p>Version: $Id: index.php,v 1.20 2002/09/22 16:10:17 ankry Exp $</p>
648 </td><td width=20%>&nbsp;</td></tr>
649 </table>
650 <?php
651 }
652
653 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
654 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
655 header("Cache-Control: no-cache, must-revalidate");
656 header("Pragma: no-cache");
657
658 //phpinfo();
659 if ($local) {
660         if ($action == "text") {
661                 dump_text();
662         } else if ($action == "qatxt") {
663                 dump_qa(1);
664         } else {
665                 myheader();
666                 echo "<table cellpadding=10 width=100%><tr><td valign=top width=10%>";
667                 list_archs();
668                 echo "</td><td valign=top>";
669                 flush();
670                 if ($action == "qa")
671                         dump_qa(0);
672                 else if ($action == "sqa")
673                         search_qa();
674                 else if (isset($id))
675                         dump_log($action == "tail");
676                 else if (isset($idx))
677                         list_logs();
678                 else 
679                         welcome();
680                 echo "</td></tr></table>";
681                 trailer();
682         }
683 }
684 else {
685
686         if ($action == "text") {
687                 dump_text();
688         } else if ($action == "qatxt") {
689                 dump_qa(1);
690         } else {
691                 myheader();
692                 echo "<table cellpadding=10 width=100%><tr><td valign=top width=10%>";
693                 list_archs();
694                 echo "</td><td valign=top>";
695                 flush();
696                 if ($action == "qa")
697                         dump_qa(0);
698                 else if (isset($id))
699                         dump_log($action == "tail");
700                 else if (isset($idx))
701                         list_logs();
702                 else 
703                         welcome();
704                 echo "</td></tr></table>";
705                 trailer();
706         }
707 }
708 ?>
This page took 1.061 seconds and 3 git commands to generate.