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