]> git.pld-linux.org Git - projects/buildlogs.git/blob - index.php
044bd40468d7251e035972aafe530fa099908bbb
[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=\"width: 2048px;overflow: scroll\">";
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         echo "</table>";
340
341
342         # what can I say beside PHP suxx? how the fuck should I create
343         # bidirectional pipe? gotta use wget
344
345         if (preg_match("/\.bz2$/", $f)) {
346                 $filter = "bzcat";
347         } elseif (preg_match("/\.gz$/", $f)) {
348                 $filter = "zcat";
349         } else {
350                 $filter = "cat";
351         }
352
353         $cmd = "$filter '$root_directory/$f'";
354         if ($tail)
355                 $cmd = "$cmd | tail -n 100";
356         $fd = popen($cmd, "r");
357         $toc = array();
358         ob_start();
359         $err_count = 0;
360         while (($s = fgets($fd, 102400)) != false) {
361                 if (strlen($s) > 800) {
362                         $s = chunk_split($s, 800, "\n    ");
363                         $s = trim($s);
364                 }
365                 $s = htmlspecialchars($s);
366                 // highlight errors
367                 if (preg_match("/errors?:/i", $s)) {
368                         $err_count++;
369                         $toc[] = "error $err_count";
370                         $err[] = $s;
371                         $s = "<span class=error id=error-$err_count>$s</span>";
372                 } elseif (substr($s, 0, 2) == "+ ") {
373                         // shell verbose
374                         $s = "<span class=verbose>$s</span>";
375                 } elseif (preg_match("/^Executing\(%(?P<section>\w+)\)/", $s, $m)) {
376                         // rpm build section
377                         $toc[] = $m['section'];
378                         $err[] = $s;
379                         $s = "<span class=section id={$m['section']}>$s</span>";
380                 } elseif (preg_match("/^Processing files: (?P<pkg>(?P<name>.+)-[^-]+-[^-]+)/", $s, $m)) {
381                         // processing files
382                         $toc[] = "files ".$m['name'];
383                         $err[] = $s;
384                         $s = "<span class=section id=files-{$m['name']}>$s</span>";
385                 }
386                 echo $s;
387         }
388         pclose($fd);
389         $code = ob_get_contents();
390         ob_end_clean();
391
392         if (!empty($toc)) {
393                 echo "<h2>"._("Toc:")."</h2>";
394                 echo "<ul class=toc>";
395                 foreach ($toc as $i => $section) {
396                         $id = str_replace(" ", "-", $section);
397                         echo "<li><a href=#{$id}>{$section}</a></li>";
398                         echo "<code>{$err[$i]}</code>";
399                 }
400                 echo "</ul>";
401         }
402
403         echo "<h2>"._("Content:")."</h2>";
404
405         start_pre();
406         echo $code;
407         end_pre();
408
409 ?>
410         <table width="100%">
411          <tr>
412           <td align=left>
413            [<a href="<?php echo $bu; ?>"><?=_("Back to list of logs")?></a>]
414           </td>
415           <td align=right>
416            [<a href="<?php echo "$bu&amp;action=qa"
417                 ?>"><?=_("View rpm -qa of builder")?></a>]
418           </td>
419          </tr>
420         </table>
421 <?php
422
423 }
424
425 function dump_text()
426 {
427         global $root_directory;
428         global $buildlogs_server;
429
430         header("Content-type: text/plain");
431
432         $f = file_name();
433         if ($f == false)
434                 return;
435
436         echo "# src  : ftp://$buildlogs_server/$f\n";
437         echo "# date   : " .
438                         date("Y/m/d H:i:s", filemtime("$root_directory/$f")) . "\n";
439
440         if (preg_match("/\.bz2$/", $f)) {
441                 $filter = "bzcat";
442         } elseif (preg_match("/\.gz$/", $f)) {
443                 $filter = "zcat";
444         } else {
445                 $filter = "cat";
446         }
447
448   $cmd = "$filter '$root_directory/$f'";
449         $fd = popen($cmd, "r");
450         while (($s = fgets($fd, 1000)) != false) {
451                 echo $s;
452         }
453         pclose($fd);
454 }
455
456 function list_archs()
457 {
458         global $addr, $url, $cnt,$ok,$ns;
459
460         if (!isset($cnt))
461                 $cnt = 50;
462
463         $big_url = "$url?ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
464
465         echo "<table width=\"100%\" border=\"0\">\n";
466         echo "<tr><td bgcolor=\"#cccccc\" nowrap=\"nowrap\">"._("Failed")."</td><td bgcolor=\"#cccccc\">"._("Ok")."</td></tr>\n";
467   foreach ($addr as $dist => $ddist) {
468     foreach ($ddist as $arch) {
469                 echo "<tr><td nowrap=\"nowrap\">".
470                      "<a href=\"$url?dist=$dist&amp;arch=$arch&amp;ok=0&amp;cnt=$cnt\">
471              $dist/$arch</a></td><td nowrap=\"nowrap\">".
472                      "[<a href=\"$url?dist=$dist&amp;arch=$arch&amp;ok=1&amp;cnt=$cnt\">OK</a>]</td>".
473                      #"<td>[<a href=\"$url?idx=$i&amp;action=qa\">qa</a>]</td>".
474                      "</tr>\n";
475     }
476   }
477         echo "</table><hr />\n";
478         
479         echo "<div align=\"center\">";
480         echo "<a href=\"$big_url&amp;action=adv_search\">"._("Advanced Search")."</a><br />\n";
481         
482         echo "<a href=\"$url\">main()</a><hr />\n";
483         echo "<a href=\"http://www.pld-linux.org/\"><img src=\"powpld.png\" ".
484                 "alt=\""._("Powered by PLD Linux")."\" border=\"0\" /></a><br />\n" .
485              "<small>(c) 2002 ".
486              "<a href=\"mailto:feedback@pld-linux.org\">PLD&nbsp;Team</a><br />\n".
487              '$Revision: 1.20 $'.
488              "</small></div>\n";
489
490         # smile ;)
491         echo "<div align=\"center\"><small>";
492         $pow = array("vim", "php", "brain", "power", "electricity",
493                      "coffee", "ufo", "penguin", "GNOME", "ELF", "DWARF",
494                      "voodoo magic", "Linux", "x-files", "X", "foobar",
495                      "/dev/null", "/dev/zero", "/dev/drzewo",
496                      "Leppe'", "matrix", "Neo", "PDP-11",
497                      "Ken", "GNU antilope", "PDP-7", "ITS", "Multics",
498                      "foobarbaz", "ed", "Joe", "Unix conspiracy",
499                      "overclock", "The Right Thing",
500                      "The Bad Thing", "Star Treck", "NSA", "NASA",
501                      "achelon", "VAX", "Real Programmer",
502                      "Real Operating System", "Real Computer",
503                      "computron", "bogon", "quantum bogodynamics",
504                      "BOFH", "/dev/ill", "nasi tu byli",
505                      "Paranoid Android", "Lunatic Corp", "Parallel thinking",
506                      "sfistak", "Linus", "The Golden Path", "Dark Side of the Force",
507                      "Przewodniczacego Lepper-a", "KDE", "Microsoft Windows 2003", "sqlite3",
508          "synergy", "six Cray XMT Supercomputers"
509                      # feel free to add sth if you change this file ;)
510                      );
511         echo _("Powered by")." ";
512         $max = 1;
513         for ($i = 0; $i < $max; $i++) {
514                 $x = rand(0, count($pow) - 1);
515                 if ($pow[$x] == "") $i--;
516                 else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
517                 $pow[$x] = "";
518         }
519         echo "</small></div>";
520
521         echo "<div align=\"center\"><small>";
522                 echo "Your IP: " . $_SERVER['REMOTE_ADDR'];
523         echo "</small></div>";
524
525         if (isset($dist) && isset($arch)) {
526         echo "<form action=\"index.php\" method=\"post\">";
527         echo "<input type=\"hidden\" name=\"dist\" value=\"$dist\" />";
528         echo "<input type=\"hidden\" name=\"arch\" value=\"$arch\" />";
529         echo "<input type=\"hidden\" name=\"action\" value=\"sqa\" />";
530         echo "<input type=\"text\" size=\"14\" name=\"str\" /><br />";
531         echo "<input type=\"submit\" name=\"submit\" value=\""._("Search rpmqa!")."\" />";
532         echo "</form>";
533         }
534 }
535
536 function get_qa()
537 {
538     global $dist, $arch;
539
540         if (!isset($dist) || !isset($arch))
541                 return false;
542         $addr = "http://ftp1.pld-linux.org/dists/$dist/.stat/builder/$dist/rpmqa-$arch.txt";
543     return fopen("$addr", "r");
544 }
545
546 function search_qa()
547 {
548         global $url, $str, $dist, $arch;
549
550         $f = get_qa();
551         echo "<h1>"._("Search results for")." '$str' "._("in")." $dist/$arch</h1>";
552
553         start_pre();
554
555         if ($f == 0) {
556                 echo _("Sorry, cannot open.");
557         } else {
558                 while (($s = fgets($f, 1000)) != false) {
559                         if (stristr($s, $str))
560                                 echo $s;
561                 }
562                 echo "/* EOF */";
563         }
564         end_pre();
565 }
566
567 function dump_qa($plain)
568 {
569         global $url, $dist, $arch;
570
571         $f = get_qa();
572
573         if ($plain) {
574                 header("Content-type: text/plain");
575                 echo _("# rpm -qa of")." $dist/$arch\n";
576         } else {
577                 echo "<h1>"._("rpm -qa of")." $a</h1>";
578                 echo "<a href=\"$url?dist=$dist&amp;arch=$arch&amp;action=qatxt\">"._("text/plain version")."</a>";
579                 start_pre();
580         }
581
582         if ($f == 0) {
583                 echo _("Sorry, cannot open.");
584         } else {
585                 while (($s = fgets($f, 1000)) != false) {
586                         echo $s;
587                 }
588         }
589
590         if (!$plain)
591                 end_pre();
592 }
593
594
595 function adv_search()
596 {
597   global $database, $addr, $fail_or_ok, $url, $_POST, $off, $cnt, $root_directory, $ok, $ns;
598
599   $big_url = "$url?ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
600
601   echo "<script><!--\n".
602        "function checkboxToggle() {\n".
603        "for (var i=0;i<document.forms[0].elements.length;i++) {\n".
604        "var e = document.forms[0].elements[i];\n".
605        "if ((e.name != 'all') && (e.type=='checkbox'))\n".
606        "e.checked = document.forms[0].all.checked;\n".
607        "}\n }\n -->\n </script>\n";
608
609 /* Shut up warnings */
610   if (!isset($_POST["n2"])) $_POST["n2"] = "";
611   if (!isset($_POST["age1"])) $_POST["age1"] = "";
612   if (!isset($_POST["age2"])) $_POST["age2"] = "";
613   if (!isset($_POST["size1"])) $_POST["size1"] = "";
614   if (!isset($_POST["size2"])) $_POST["size2"] = "";
615
616   echo "<form action=\"index.php?action=adv_search\" method=\"post\">";
617
618   echo "<div align=\"center\">";
619   echo "<table border=\"0\">\n";
620   echo "<tr>\n";
621   echo "<td>"._("Package name")."</td>\n";
622   echo "<td><input type=\"text\" size=\"20\" name=\"n2\" value=\"". $_POST["name"] ."\"/></td>\n";
623   echo "</tr>\n";
624
625   echo "<tr>\n";
626   echo "<td>"._("Days")."</td>\n";
627   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"age1\" value=\"". $_POST["age1"] ."\" /></td>\n";
628   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"age2\" value=\"". $_POST["age2"] ."\" /></td>\n";
629   echo "</tr>\n";
630
631   echo "<tr>\n";
632   echo "<td>"._("Size")."</td>\n";
633   echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"size1\" value=\"". $_POST["size1"] ."\" /></td>\n";
634   echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"size2\" value=\"". $_POST["size2"] ."\" /></td>\n";
635   echo "</tr>\n";
636
637   echo "<tr>\n";
638   echo "<td>"._("Search logs:")."</td>\n";
639   echo "</tr>\n";
640
641   echo "<tr>\n";
642   echo "<td>"._("Failed")."</td>\n";
643   echo "<td>"._("OK")."</td>\n";
644   echo "</tr>\n";
645
646   $i = 1;
647   foreach ($addr as $dist => $ddist) {
648     foreach ($ddist as $arch) {
649     echo "<tr>\n";
650     $name="as0_".$i;
651     if (!isset($_POST["$name"])) {
652         $check = " ";
653     } else {
654         $check=" checked='checked'";
655     }
656     echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">". "$dist/$arch" ."</label></td>\n";
657     $name="as1_".$i;
658     if (!isset($_POST["$n2"])) {
659         $check = " ";
660     } else {
661         $check=" checked='checked'";
662     }
663     echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">". "$dist/$arch" ."</label></td>\n";
664     echo "</tr>\n";
665     $i++;
666     }
667   }
668         
669   echo "<tr>\n";
670   echo "<td><label><input name=\"all\" type=\"checkbox\" checked=\"on\" onClick=\"checkboxToggle()\">"._("Toggle checkboxes")."</label>&nbsp;<input type=\"submit\" name=\"submit\" value=\""._("Search!")."\" /></td>";
671   echo "</tr>\n";
672
673   echo "</table>\n";
674
675 //      if (isset($_POST["name"]) || isset($_POST["age1"]) || isset($_POST["age2"]) ||
676 //        isset($_POST["size1"]) || isset($_POST["size2"])
677   if (($_POST["n2"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") ||
678     ($_POST["size1"]!="") || ($_POST["size2"]!=""))
679   {
680         $query = "SELECT log_id, dist, arch, ok, name, size, mtime, id FROM logs WHERE 1 ";
681         if ($_POST["n2"] != "") {
682                 $n = addslashes($_POST["n2"]);
683                 $query .= "AND name LIKE '$n%' ";
684         }
685         $now = time();
686
687         if ($_POST["age1"] != "") {
688                 $age = $now - (int)$_POST["age1"] * 24 * 3600;
689                 $query .= "AND mtime > $age ";
690         }
691
692         if ($_POST["age2"] != "") {
693                 $age = $now - (int)$_POST["age2"] * 24 * 3600;
694                 $query .= "AND mtime < $age ";
695         }
696
697         if ($_POST["size1"] != "") {
698                 $size = (int)$_POST["size1"];
699                 $query .= "AND size > $size ";
700         }
701
702         if ($_POST["size2"] != "") {
703                 $size = (int)$_POST["size2"];
704                 $query .= "AND size < $size ";
705         }
706
707         $or = "AND (";
708   $i = 1;
709   foreach ($addr as $dist => $ddist) {
710     foreach ($ddist as $arch) {
711       for ($j = 0; $j < 2; $j++) {
712                           if (isset($_POST["as" . $j . "_" .$i])) {
713                                 $query .= "$or (dist = '$dist' AND arch = '$arch' AND ok = $j)";
714                                 $or = " OR ";
715                         }
716                 }
717     $i++;
718     }
719         }
720         if ($or == " OR ") $query .= ")";
721 //      if (!isset($cnt)) $cnt = 50;
722 //      if (!isset($off)) $off = 0;
723         if (!isset($ns)) $ns = 0;
724         switch ($ns) {
725                 case 0:
726                         $query .= " ORDER BY mtime DESC";
727                         break;
728                 case 1:
729                         $query .= " ORDER BY name";
730                         break;
731                 case 2:
732                         $query .= " ORDER BY dist, arch, name";
733                         break;
734         }
735         $query .= " LIMIT $cnt OFFSET $off ";
736
737         try {
738                 $dbh = new PDO("$database");
739         } catch (PDOException $e) {
740                 mydie("new PDO: " . $e->getMessage());
741         }
742         $result = $dbh->query("$query")->fetchAll();
743
744         if ($result == FALSE) {
745                 echo _("Nothing found");
746         } else {
747                 echo "<table border=\"0\" cellspacing=\"1\" ".
748                         "cellpadding=3 bgcolor=\"#000000\" width=\"90%\">\n";
749                 echo "<tr><th bgcolor=\"#CCCCFF\" align=\"left\" width=\"10%\">"._("Builder").
750                         "[<a href=\"$big_url&amp;ns=2\">"._("sort")."</a>]</th>";
751                 echo "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"60%\">"._("Log File").
752                         "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
753                         "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
754                          "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
755                          "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
756                          "</th></tr>";
757                 $i = $off;
758 //              for ($i = $off; $i < $off + $count; $i++) {
759                 foreach ($result as $row) {
760       $dist = $row["dist"];
761       $arch = $row["arch"];
762       $name = $row["name"];
763       $name_url = urlencode($name);
764       $id = $row["id"];
765                         $f = $name;
766                         $t = $now - $row["mtime"];
767                         $s = $row["size"];
768                         $t /= 60;
769                         if ($t >= 60) {
770                                 $t /= 60;
771                                 if ($t >= 24) {
772                                         $t /= 24;
773                                         $t = round($t);
774                                         $t = $t . "&nbsp;" . ngettext("day","days",$t);
775                                 } else {
776                                         $t = round($t);
777                                         $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
778                                 }
779                         } else {
780                                 $t = round($t);
781                                 $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
782                         }
783                         
784 //                $big_url = "$url?idx=$i&amp;ok=$j&amp;ns=$ns&amp;cnt=$cnt";
785       $ok = $row["ok"];
786                         $u = "$url?dist=$dist&amp;arch=$arch&amp;name=$name_url&amp;ok=$ok&amp;id=$id";
787                         $b = "$url?dist=$dist&amp;arch=$arch&amp;ok=$ok&amp;ns=$ns&amp;off=$off&amp;cnt=$cnt";
788
789                         $builder = "$dist/$arch/". $fail_or_ok[$ok];
790                         echo "<tr>";
791                         echo "<td bgcolor=\"#CCCCCC\"><a href=\"$b\">$builder</a></td>";
792                         echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ".
793                         "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
794                         "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
795                         "</td><td bgcolor=\"#CCCCCC\" align=\"right\">".
796                         "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n";
797                         $i++;
798                 }
799                 echo "</table></div>\n";
800
801                 $backarr = "&lt;&lt;&lt;&nbsp;";
802                 $back = _("Page back");
803                 $forward = _("Page forward");
804                 $forwardarr = "&nbsp;&gt;&gt;&gt;";
805
806         }
807 // FIXME
808 /*
809         echo "<p><table width=\"90%\" align=\"center\"><tr><td align=left width=1%>";
810
811         if ($off > 0) {
812                 $noff = $off - $cnt;
813                 if ($noff < 0)  
814                         $noff = 0;
815                 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
816                 echo "$hrefurl$backarr</a></td><td align=left>$hrefurl$back</a>";
817         } else {
818                 echo "$backarr</td><td align=left>$back";
819         }
820
821     echo "</td>\n<td align=\"center\">";
822     echo "</td>\n<td align=\"right\">";
823
824     if ($off + $cnt < count($list))
825     {
826       $noff = $off + $cnt;
827       if ($noff < 0)    
828         $noff = 0;
829       $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
830       echo "$hrefurl$forward</a></td><td align=\"right\" width=\"1%\">$hrefurl$forwardarr</a>";
831     }
832     else
833     {
834       echo "$forward</td><td align=\"right\" width=\"1%\">$forwardarr";
835     }
836
837     echo "</td>\n</tr></table></p>";
838 */
839   } else
840   {
841     echo _("Enter something!");
842   }
843   echo "</div></form>\n";
844 }
845
846 function welcome()
847 {
848 ?>
849 <table border="0" width="100%"><tr><td width="20%">&nbsp;</td><td>
850 <h1><?=_("Welcome!")?></h1>
851 <p><?=_("Welcome to PLD Build Logs WWW interface.")?></p><p>
852 <?=_("Feel free to email bug reports, complaints and feature requests ")?>
853 <!-- ech... niech strace... -->
854 <a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?>
855 <a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a> ;)</p>
856 <p>Version: $Id: index.php,v 1.20 2012/06/22 12:11:12 arekm Exp $</p>
857 </td><td width="20%">&nbsp;</td></tr>
858 </table>
859 <?php
860 }
861
862 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
863 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
864 header("Cache-Control: no-cache, must-revalidate");
865 header("Pragma: no-cache");
866
867 //phpinfo();
868 if ($action == "text") {
869         dump_text();
870 } else if ($action == "adv_search") {
871         myheader();
872         adv_search();
873         trailer();
874 } else if ($action == "qatxt") {
875         dump_qa(1);
876 } else {
877         myheader();
878         echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=\"top\" width=\"10%\">";
879         list_archs();
880         echo "</td><td valign=\"top\">";
881         flush();
882         if ($action == "qa")
883                 dump_qa(0);
884         else if ($action == "sqa")
885                 search_qa();
886         else if (isset($id) || isset($name))
887                 dump_log($action == "tail");
888         else if (isset($dist))
889                 list_logs();
890         else
891                 welcome();
892         echo "</td></tr></table>";
893         trailer();
894 }
895 ?>
This page took 0.143908 seconds and 2 git commands to generate.