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