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