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