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