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