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