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