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