]> git.pld-linux.org Git - projects/buildlogs.git/blame - index.php
Now browser does all word wrapping.
[projects/buildlogs.git] / index.php
CommitLineData
a7f1713c 1<?php
2ob_start("ob_gzhandler", 1);
3$buildlogs_server = "buildlogs.pld-linux.org";
a6cc6dd6 4$url = "index.php";
a7f1713c 5$fail_or_ok = array( "FAIL", "OK" );
6/*
9dcdc6b4 7$database = 'sqlite:/home/services/ftp/buildlogs2.db';
a7f1713c 8$root_directory = "/home/services/ftp/pub/pld-buildlogs";
9*/
10
11// $database, $root_directory and others are taken from buildlogs.inc
f27dac56 12include('buildlogs.inc');
a7f1713c 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"])) {
8f0e31ba 56 $name_url = urlencode($_GET["name"]);
a7f1713c 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
dbb4d4ae
AM
74if ($arch == "src")
75 $arch = "SRPMS";
76
a7f1713c 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; }
2ba2cc91
ER
91H1 { font-family: arial,helvetica,sans-serif;
92 font-size: 20pt;
a7f1713c 93 font-weight: bold;}
2ba2cc91
ER
94H2 { font-family: arial,helvetica,sans-serif;
95 font-size: 18pt;
a7f1713c 96 font-weight: bold;}
2ba2cc91 97BODY,TD { font-family: arial,helvetica,sans-serif;
a7f1713c 98 font-size: 13pt; }
2ba2cc91
ER
99TH { font-family: arial,helvetica,sans-serif;
100 font-size: 13pt;
a7f1713c 101 font-weight: bold; }
2ba2cc91
ER
102/* error lines from build logs */
103.error {
104 background-color: #b00;
105}
e926de50
ER
106.verbose {
107 color: #886;
108}
109.section {
110 color: #111;
111 background-color: #161;
112}
a7f1713c 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\">".
05eb5093 126 "<font color=\"#cccccc\"><pre style=\"white-space: pre-line; word-break: break-all;\">";
a7f1713c 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) {
8f0e31ba 192 $name = $row["name"];
193 $id = $row["id"];
194 $dist = $row["dist"];
195 $arch = $row["arch"];
196 $f = $name;
197 $name_url = urlencode($name);
a7f1713c 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 }
8f0e31ba 217 $u = "$url?dist=$dist&amp;arch=$arch&amp;ok=$ok&amp;name=$name_url&amp;id=$id";
a7f1713c 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{
8f0e31ba 269 global $ok, $dist, $arch, $name, $name_url, $id;
a7f1713c 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{
8f0e31ba 282 global $ok, $url, $dist, $arch, $name, $name_url;
a7f1713c 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
eaa92f33 296 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\" width="\100%\">";
a7f1713c 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
2ba2cc91
ER
307 one_item(_("Status"), ($ok == 1 ?
308 "<font color=\"green\"><b>"._("OK")."</b></font>" :
a7f1713c 309 "<font color=\"red\"><b>"._("Failed")."</b></a>"));
2ba2cc91
ER
310 one_item(_("Source URL"),
311 href("ftp://$buildlogs_server/$f",
a7f1713c 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
2ba2cc91 317 one_item(_("text/plain URL"),
8f0e31ba 318 href("$bu&amp;name=$name_url&amp;id=$id&amp;action=text",
a7f1713c 319 _("View!")));
320 if ($tail) {
2ba2cc91 321 one_item(_("full text"),
8f0e31ba 322 href("$bu&amp;name=$name_url&amp;id=$id",
a7f1713c 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 }
35a4c15e 331 one_item("Date", date("Y/m/d H:i:s", filemtime("$root_directory/$f")));
a7f1713c 332 /*
2ba2cc91 333 echo "<tr><td>Here:</td><td>" .
a7f1713c 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
a7f1713c 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
8f0e31ba 352 $cmd = "$filter '$root_directory/$f'";
a7f1713c 353 $fd = popen($cmd, "r");
e926de50 354 $toc = array();
e69f53b7 355 $err = array();
4a2b3f54
AM
356 $first_cut = false;
357 $first_cut_done = false;
b530f30e 358 $time = "";
e69f53b7 359 $out_buf = array();
77aded7c 360 $out_buf_size = 0;
a7f1713c 361 while (($s = fgets($fd, 102400)) != false) {
015d7b6a 362
e69f53b7
AM
363 $toc_elem = false;
364 $err_elem = false;
365
a7f1713c 366 $s = htmlspecialchars($s);
2ba2cc91 367 // highlight errors
1c26089b 368 if (preg_match("/(?:fail|error(s|\sCS\d+)?):/i", $s)) {
4a2b3f54 369 $first_cut = true;
283f4590 370 $err_count++;
e69f53b7
AM
371 $toc_elem = "error $err_count";
372 $err_elem = $s;
373 $s = "<span class=error id=error-$err_count>$s</span>";
374 } elseif (preg_match("/(?:undefined reference to)/i", $s)) {
4a2b3f54 375 $first_cut = true;
e69f53b7
AM
376 $err_count++;
377 $toc_elem = "error $err_count";
378 $err_elem = $s;
98e99288 379 $s = "<span class=error id=error-$err_count>$s</span>";
1c26089b
ER
380 } elseif (preg_match("#^\+ /usr/bin/make\b.*\b(?P<target>check)\b#", $s, $m)) {
381 // rpm build section
e69f53b7
AM
382 $toc_elem = "make {$m['target']}";
383 $err_elem = $s;
1c26089b 384 $s = "<span class=line id=make-{$m['target']}>$s</span>";
e926de50
ER
385 } elseif (substr($s, 0, 2) == "+ ") {
386 // shell verbose
387 $s = "<span class=verbose>$s</span>";
388 } elseif (preg_match("/^Executing\(%(?P<section>\w+)\)/", $s, $m)) {
389 // rpm build section
e69f53b7
AM
390 $toc_elem = $m['section'];
391 $err_elem = $s;
98e99288 392 $s = "<span class=section id={$m['section']}>$s</span>";
901abf2c 393 } elseif (preg_match("/^Processing files: (?P<pkg>(?P<name>.+)-[^-]+-[^-]+)/", $s, $m)) {
4a2b3f54 394 $first_cut = true;
901abf2c 395 // processing files
e69f53b7
AM
396 $toc_elem = "files ".$m['name'];
397 $err_elem = $s;
98e99288 398 $s = "<span class=section id=files-{$m['name']}>$s</span>";
b530f30e
ER
399 } elseif (preg_match("/^ended at: (?P<date>.+), done in (?P<time>[\d:.]+)/", $s, $m)) {
400 $time = $m['time'];
2ba2cc91 401 }
e69f53b7 402
4a2b3f54 403 $out_buf[] = $s;
77aded7c 404 $out_buf_size++;
015d7b6a
AM
405
406 // if error/processing found truncate early but keep last 100 lines before error
4a2b3f54 407 if ($tail && $first_cut && !$first_cut_done && $out_buf_size > 100) {
015d7b6a
AM
408 array_splice($out_buf, 0, $out_buf_size - 100);
409 $out_buf_size = 100;
4a2b3f54 410 $first_cut_done = true;
015d7b6a
AM
411 }
412
e69f53b7 413 // if (not in tail mode) or (in tail mode but we have an error)
4a2b3f54 414 if (!$tail || $first_cut) {
e69f53b7
AM
415 if ($toc_elem)
416 $toc[] = $toc_elem;
417 if ($err_elem)
418 $err[] = $err_elem;
e69f53b7 419 }
a7f1713c 420 }
a7f1713c 421 pclose($fd);
e69f53b7 422
015d7b6a 423 // no errors found, no processing found but we are in tail mode
4a2b3f54 424 if ($tail && !$first_cut_done && $out_buf_size > 100) {
015d7b6a
AM
425 array_splice($out_buf, 0, $out_buf_size - 100);
426 $out_buf_size = 100;
427 }
428
77aded7c 429 $code = join('', $out_buf);
e926de50 430
b530f30e
ER
431 if ($time) {
432 one_item(_("Runtime"), $time);
433 }
434
f43fc7b7
ER
435 echo "</table>";
436
e926de50
ER
437 if (!empty($toc)) {
438 echo "<h2>"._("Toc:")."</h2>";
439 echo "<ul class=toc>";
98e99288 440 foreach ($toc as $i => $section) {
901abf2c
ER
441 $id = str_replace(" ", "-", $section);
442 echo "<li><a href=#{$id}>{$section}</a></li>";
98e99288 443 echo "<code>{$err[$i]}</code>";
e926de50
ER
444 }
445 echo "</ul>";
446 }
447
448 echo "<h2>"._("Content:")."</h2>";
449
450 start_pre();
451 echo $code;
452 end_pre();
a7f1713c 453
454?>
455 <table width="100%">
456 <tr>
457 <td align=left>
458 [<a href="<?php echo $bu; ?>"><?=_("Back to list of logs")?></a>]
459 </td>
460 <td align=right>
2ba2cc91 461 [<a href="<?php echo "$bu&amp;action=qa"
a7f1713c 462 ?>"><?=_("View rpm -qa of builder")?></a>]
463 </td>
464 </tr>
465 </table>
466<?php
467
468}
469
470function dump_text()
471{
472 global $root_directory;
473 global $buildlogs_server;
474
475 header("Content-type: text/plain");
476
477 $f = file_name();
478 if ($f == false)
479 return;
480
481 echo "# src : ftp://$buildlogs_server/$f\n";
2ba2cc91 482 echo "# date : " .
a7f1713c 483 date("Y/m/d H:i:s", filemtime("$root_directory/$f")) . "\n";
484
485 if (preg_match("/\.bz2$/", $f)) {
486 $filter = "bzcat";
487 } elseif (preg_match("/\.gz$/", $f)) {
488 $filter = "zcat";
489 } else {
490 $filter = "cat";
491 }
492
8f0e31ba 493 $cmd = "$filter '$root_directory/$f'";
a7f1713c 494 $fd = popen($cmd, "r");
495 while (($s = fgets($fd, 1000)) != false) {
496 echo $s;
497 }
498 pclose($fd);
499}
500
501function list_archs()
502{
503 global $addr, $url, $cnt,$ok,$ns;
504
505 if (!isset($cnt))
506 $cnt = 50;
507
508 $big_url = "$url?ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
509
510 echo "<table width=\"100%\" border=\"0\">\n";
511 echo "<tr><td bgcolor=\"#cccccc\" nowrap=\"nowrap\">"._("Failed")."</td><td bgcolor=\"#cccccc\">"._("Ok")."</td></tr>\n";
a918ff2f
AM
512 foreach ($addr as $dist => $ddist) {
513 echo "<tr><td colspan=2 nowrap=\"nowrap\"><hr/></td></tr>\n";
514 foreach ($ddist as $arch) {
515 echo "<tr><td nowrap=\"nowrap\">".
516 "<a href=\"$url?dist=$dist&amp;arch=$arch&amp;ok=0&amp;cnt=$cnt\">
517 $dist/$arch</a></td><td nowrap=\"nowrap\">".
518 "[<a href=\"$url?dist=$dist&amp;arch=$arch&amp;ok=1&amp;cnt=$cnt\">OK</a>]</td>".
519 #"<td>[<a href=\"$url?idx=$i&amp;action=qa\">qa</a>]</td>".
520 "</tr>\n";
521 }
522 }
a7f1713c 523 echo "</table><hr />\n";
524
525 echo "<div align=\"center\">";
526 echo "<a href=\"$big_url&amp;action=adv_search\">"._("Advanced Search")."</a><br />\n";
527
528 echo "<a href=\"$url\">main()</a><hr />\n";
529 echo "<a href=\"http://www.pld-linux.org/\"><img src=\"powpld.png\" ".
4a2b3f54 530 "alt=\""._("Powered by PLD Linux")."\" border=\"0\" /></a><br />\n" .
60845d0a 531 "<small>(c) 2002-". date("Y") . " ".
a7f1713c 532 "<a href=\"mailto:feedback@pld-linux.org\">PLD&nbsp;Team</a><br />\n".
ef845007 533 '$Revision: 1.35 $'.
a7f1713c 534 "</small></div>\n";
535
536 # smile ;)
537 echo "<div align=\"center\"><small>";
538 $pow = array("vim", "php", "brain", "power", "electricity",
539 "coffee", "ufo", "penguin", "GNOME", "ELF", "DWARF",
540 "voodoo magic", "Linux", "x-files", "X", "foobar",
2ba2cc91 541 "/dev/null", "/dev/zero", "/dev/drzewo",
a7f1713c 542 "Leppe'", "matrix", "Neo", "PDP-11",
543 "Ken", "GNU antilope", "PDP-7", "ITS", "Multics",
2ba2cc91 544 "foobarbaz", "ed", "Joe", "Unix conspiracy",
a7f1713c 545 "overclock", "The Right Thing",
546 "The Bad Thing", "Star Treck", "NSA", "NASA",
547 "achelon", "VAX", "Real Programmer",
548 "Real Operating System", "Real Computer",
549 "computron", "bogon", "quantum bogodynamics",
550 "BOFH", "/dev/ill", "nasi tu byli",
551 "Paranoid Android", "Lunatic Corp", "Parallel thinking",
552 "sfistak", "Linus", "The Golden Path", "Dark Side of the Force",
553 "Przewodniczacego Lepper-a", "KDE", "Microsoft Windows 2003", "sqlite3",
3cf4f3e8 554 "synergy", "six Cray XMT Supercomputers"
a7f1713c 555 # feel free to add sth if you change this file ;)
556 );
557 echo _("Powered by")." ";
558 $max = 1;
559 for ($i = 0; $i < $max; $i++) {
560 $x = rand(0, count($pow) - 1);
561 if ($pow[$x] == "") $i--;
562 else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
563 $pow[$x] = "";
564 }
565 echo "</small></div>";
566
774eb927
AM
567 echo "<div align=\"center\"><small>";
568 echo "Your IP: " . $_SERVER['REMOTE_ADDR'];
569 echo "</small></div>";
570
a7f1713c 571 if (isset($dist) && isset($arch)) {
a6cc6dd6 572 echo "<form action=\"index.php\" method=\"post\">";
a7f1713c 573 echo "<input type=\"hidden\" name=\"dist\" value=\"$dist\" />";
574 echo "<input type=\"hidden\" name=\"arch\" value=\"$arch\" />";
575 echo "<input type=\"hidden\" name=\"action\" value=\"sqa\" />";
576 echo "<input type=\"text\" size=\"14\" name=\"str\" /><br />";
577 echo "<input type=\"submit\" name=\"submit\" value=\""._("Search rpmqa!")."\" />";
578 echo "</form>";
579 }
580}
581
582function get_qa()
583{
584 global $dist, $arch;
585
586 if (!isset($dist) || !isset($arch))
587 return false;
f0694a44 588 $addr = "http://ftp1.pld-linux.org/dists/$dist/.stat/builder/$dist/rpmqa-$arch.txt";
a7f1713c 589 return fopen("$addr", "r");
590}
591
592function search_qa()
593{
594 global $url, $str, $dist, $arch;
595
596 $f = get_qa();
597 echo "<h1>"._("Search results for")." '$str' "._("in")." $dist/$arch</h1>";
598
599 start_pre();
600
601 if ($f == 0) {
602 echo _("Sorry, cannot open.");
603 } else {
604 while (($s = fgets($f, 1000)) != false) {
ea35dacf
AM
605 if (stristr($s, "Query done at:")) {
606 echo "rpmqa database from " . strstr($s, ":") . "\n";
4a2b3f54 607 continue;
ea35dacf
AM
608 }
609
a7f1713c 610 if (stristr($s, $str))
611 echo $s;
612 }
ea35dacf 613 echo "\n/* EOF */";
a7f1713c 614 }
615 end_pre();
616}
617
618function dump_qa($plain)
619{
620 global $url, $dist, $arch;
621
622 $f = get_qa();
623
624 if ($plain) {
2ba2cc91 625 header("Content-type: text/plain");
a7f1713c 626 echo _("# rpm -qa of")." $dist/$arch\n";
627 } else {
628 echo "<h1>"._("rpm -qa of")." $a</h1>";
629 echo "<a href=\"$url?dist=$dist&amp;arch=$arch&amp;action=qatxt\">"._("text/plain version")."</a>";
630 start_pre();
631 }
632
633 if ($f == 0) {
634 echo _("Sorry, cannot open.");
635 } else {
636 while (($s = fgets($f, 1000)) != false) {
637 echo $s;
638 }
639 }
640
641 if (!$plain)
642 end_pre();
643}
644
645
646function adv_search()
647{
648 global $database, $addr, $fail_or_ok, $url, $_POST, $off, $cnt, $root_directory, $ok, $ns;
649
650 $big_url = "$url?ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
651
652 echo "<script><!--\n".
653 "function checkboxToggle() {\n".
654 "for (var i=0;i<document.forms[0].elements.length;i++) {\n".
655 "var e = document.forms[0].elements[i];\n".
656 "if ((e.name != 'all') && (e.type=='checkbox'))\n".
657 "e.checked = document.forms[0].all.checked;\n".
658 "}\n }\n -->\n </script>\n";
659
660/* Shut up warnings */
8f0e31ba 661 if (!isset($_POST["n2"])) $_POST["n2"] = "";
a7f1713c 662 if (!isset($_POST["age1"])) $_POST["age1"] = "";
663 if (!isset($_POST["age2"])) $_POST["age2"] = "";
664 if (!isset($_POST["size1"])) $_POST["size1"] = "";
665 if (!isset($_POST["size2"])) $_POST["size2"] = "";
666
a6cc6dd6 667 echo "<form action=\"index.php?action=adv_search\" method=\"post\">";
a7f1713c 668
669 echo "<div align=\"center\">";
670 echo "<table border=\"0\">\n";
671 echo "<tr>\n";
672 echo "<td>"._("Package name")."</td>\n";
8f0e31ba 673 echo "<td><input type=\"text\" size=\"20\" name=\"n2\" value=\"". $_POST["name"] ."\"/></td>\n";
a7f1713c 674 echo "</tr>\n";
675
676 echo "<tr>\n";
677 echo "<td>"._("Days")."</td>\n";
678 echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"age1\" value=\"". $_POST["age1"] ."\" /></td>\n";
679 echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"age2\" value=\"". $_POST["age2"] ."\" /></td>\n";
680 echo "</tr>\n";
681
682 echo "<tr>\n";
683 echo "<td>"._("Size")."</td>\n";
684 echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"size1\" value=\"". $_POST["size1"] ."\" /></td>\n";
685 echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"size2\" value=\"". $_POST["size2"] ."\" /></td>\n";
686 echo "</tr>\n";
687
688 echo "<tr>\n";
689 echo "<td>"._("Search logs:")."</td>\n";
690 echo "</tr>\n";
691
692 echo "<tr>\n";
693 echo "<td>"._("Failed")."</td>\n";
694 echo "<td>"._("OK")."</td>\n";
695 echo "</tr>\n";
696
506bb488 697 $i = 1;
8f0e31ba 698 foreach ($addr as $dist => $ddist) {
506bb488 699 foreach ($ddist as $arch) {
a7f1713c 700 echo "<tr>\n";
701 $name="as0_".$i;
a7f1713c 702 if (!isset($_POST["$name"])) {
703 $check = " ";
704 } else {
1b44998a 705 $check=" checked='checked'";
a7f1713c 706 }
8f0e31ba 707 echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">". "$dist/$arch" ."</label></td>\n";
a7f1713c 708 $name="as1_".$i;
8f0e31ba 709 if (!isset($_POST["$n2"])) {
a7f1713c 710 $check = " ";
711 } else {
1b44998a 712 $check=" checked='checked'";
a7f1713c 713 }
8f0e31ba 714 echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">". "$dist/$arch" ."</label></td>\n";
a7f1713c 715 echo "</tr>\n";
506bb488 716 $i++;
717 }
a7f1713c 718 }
719
720 echo "<tr>\n";
8f0e31ba 721 echo "<td><label><input name=\"all\" type=\"checkbox\" checked=\"on\" onClick=\"checkboxToggle()\">"._("Toggle checkboxes")."</label>&nbsp;<input type=\"submit\" name=\"submit\" value=\""._("Search!")."\" /></td>";
a7f1713c 722 echo "</tr>\n";
723
724 echo "</table>\n";
725
726// if (isset($_POST["name"]) || isset($_POST["age1"]) || isset($_POST["age2"]) ||
727// isset($_POST["size1"]) || isset($_POST["size2"])
8f0e31ba 728 if (($_POST["n2"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") ||
a7f1713c 729 ($_POST["size1"]!="") || ($_POST["size2"]!=""))
730 {
731 $query = "SELECT log_id, dist, arch, ok, name, size, mtime, id FROM logs WHERE 1 ";
8f0e31ba 732 if ($_POST["n2"] != "") {
733 $n = addslashes($_POST["n2"]);
a7f1713c 734 $query .= "AND name LIKE '$n%' ";
735 }
736 $now = time();
737
738 if ($_POST["age1"] != "") {
739 $age = $now - (int)$_POST["age1"] * 24 * 3600;
740 $query .= "AND mtime > $age ";
741 }
742
743 if ($_POST["age2"] != "") {
744 $age = $now - (int)$_POST["age2"] * 24 * 3600;
745 $query .= "AND mtime < $age ";
746 }
747
748 if ($_POST["size1"] != "") {
749 $size = (int)$_POST["size1"];
750 $query .= "AND size > $size ";
751 }
752
753 if ($_POST["size2"] != "") {
754 $size = (int)$_POST["size2"];
755 $query .= "AND size < $size ";
756 }
757
758 $or = "AND (";
506bb488 759 $i = 1;
8f0e31ba 760 foreach ($addr as $dist => $ddist) {
506bb488 761 foreach ($ddist as $arch) {
762 for ($j = 0; $j < 2; $j++) {
763 if (isset($_POST["as" . $j . "_" .$i])) {
8f0e31ba 764 $query .= "$or (dist = '$dist' AND arch = '$arch' AND ok = $j)";
a7f1713c 765 $or = " OR ";
766 }
767 }
506bb488 768 $i++;
769 }
a7f1713c 770 }
771 if ($or == " OR ") $query .= ")";
772// if (!isset($cnt)) $cnt = 50;
773// if (!isset($off)) $off = 0;
774 if (!isset($ns)) $ns = 0;
775 switch ($ns) {
776 case 0:
777 $query .= " ORDER BY mtime DESC";
778 break;
779 case 1:
780 $query .= " ORDER BY name";
781 break;
782 case 2:
783 $query .= " ORDER BY dist, arch, name";
784 break;
785 }
786 $query .= " LIMIT $cnt OFFSET $off ";
2ba2cc91 787
a7f1713c 788 try {
789 $dbh = new PDO("$database");
790 } catch (PDOException $e) {
791 mydie("new PDO: " . $e->getMessage());
792 }
793 $result = $dbh->query("$query")->fetchAll();
794
795 if ($result == FALSE) {
796 echo _("Nothing found");
797 } else {
798 echo "<table border=\"0\" cellspacing=\"1\" ".
799 "cellpadding=3 bgcolor=\"#000000\" width=\"90%\">\n";
800 echo "<tr><th bgcolor=\"#CCCCFF\" align=\"left\" width=\"10%\">"._("Builder").
801 "[<a href=\"$big_url&amp;ns=2\">"._("sort")."</a>]</th>";
802 echo "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"60%\">"._("Log File").
803 "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
804 "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
805 "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
806 "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
807 "</th></tr>";
808 $i = $off;
809// for ($i = $off; $i < $off + $count; $i++) {
810 foreach ($result as $row) {
811 $dist = $row["dist"];
812 $arch = $row["arch"];
813 $name = $row["name"];
8f0e31ba 814 $name_url = urlencode($name);
a7f1713c 815 $id = $row["id"];
816 $f = $name;
a7f1713c 817 $t = $now - $row["mtime"];
818 $s = $row["size"];
819 $t /= 60;
820 if ($t >= 60) {
821 $t /= 60;
822 if ($t >= 24) {
823 $t /= 24;
824 $t = round($t);
825 $t = $t . "&nbsp;" . ngettext("day","days",$t);
826 } else {
827 $t = round($t);
828 $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
829 }
830 } else {
831 $t = round($t);
832 $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
833 }
834
835// $big_url = "$url?idx=$i&amp;ok=$j&amp;ns=$ns&amp;cnt=$cnt";
836 $ok = $row["ok"];
8f0e31ba 837 $u = "$url?dist=$dist&amp;arch=$arch&amp;name=$name_url&amp;ok=$ok&amp;id=$id";
a7f1713c 838 $b = "$url?dist=$dist&amp;arch=$arch&amp;ok=$ok&amp;ns=$ns&amp;off=$off&amp;cnt=$cnt";
839
840 $builder = "$dist/$arch/". $fail_or_ok[$ok];
841 echo "<tr>";
842 echo "<td bgcolor=\"#CCCCCC\"><a href=\"$b\">$builder</a></td>";
843 echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ".
844 "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
845 "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
846 "</td><td bgcolor=\"#CCCCCC\" align=\"right\">".
847 "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n";
848 $i++;
849 }
850 echo "</table></div>\n";
851
852 $backarr = "&lt;&lt;&lt;&nbsp;";
853 $back = _("Page back");
854 $forward = _("Page forward");
855 $forwardarr = "&nbsp;&gt;&gt;&gt;";
856
857 }
858// FIXME
859/*
860 echo "<p><table width=\"90%\" align=\"center\"><tr><td align=left width=1%>";
861
862 if ($off > 0) {
863 $noff = $off - $cnt;
864 if ($noff < 0)
865 $noff = 0;
866 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
867 echo "$hrefurl$backarr</a></td><td align=left>$hrefurl$back</a>";
868 } else {
869 echo "$backarr</td><td align=left>$back";
870 }
871
872 echo "</td>\n<td align=\"center\">";
873 echo "</td>\n<td align=\"right\">";
874
875 if ($off + $cnt < count($list))
876 {
877 $noff = $off + $cnt;
878 if ($noff < 0)
879 $noff = 0;
880 $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
881 echo "$hrefurl$forward</a></td><td align=\"right\" width=\"1%\">$hrefurl$forwardarr</a>";
882 }
883 else
884 {
885 echo "$forward</td><td align=\"right\" width=\"1%\">$forwardarr";
886 }
887
888 echo "</td>\n</tr></table></p>";
889*/
890 } else
891 {
892 echo _("Enter something!");
893 }
4086dafb 894 echo "</div></form>\n";
a7f1713c 895}
896
897function welcome()
898{
899?>
900<table border="0" width="100%"><tr><td width="20%">&nbsp;</td><td>
901<h1><?=_("Welcome!")?></h1>
902<p><?=_("Welcome to PLD Build Logs WWW interface.")?></p><p>
903<?=_("Feel free to email bug reports, complaints and feature requests ")?>
904<!-- ech... niech strace... -->
2ba2cc91 905<a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?>
a7f1713c 906<a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a> ;)</p>
ef845007 907<p>Version: $Id: index.php,v 1.35 2014/10/18 10:25:20 arekm Exp $</p>
a7f1713c 908</td><td width="20%">&nbsp;</td></tr>
909</table>
910<?php
911}
912
913header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
914header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
915header("Cache-Control: no-cache, must-revalidate");
916header("Pragma: no-cache");
917
918//phpinfo();
919if ($action == "text") {
920 dump_text();
921} else if ($action == "adv_search") {
922 myheader();
923 adv_search();
924 trailer();
925} else if ($action == "qatxt") {
926 dump_qa(1);
927} else {
928 myheader();
929 echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=\"top\" width=\"10%\">";
930 list_archs();
931 echo "</td><td valign=\"top\">";
932 flush();
933 if ($action == "qa")
934 dump_qa(0);
935 else if ($action == "sqa")
936 search_qa();
937 else if (isset($id) || isset($name))
938 dump_log($action == "tail");
939 else if (isset($dist))
940 list_logs();
941 else
942 welcome();
943 echo "</td></tr></table>";
944 trailer();
945}
946?>
This page took 0.227502 seconds and 4 git commands to generate.