]>
Commit | Line | Data |
---|---|---|
a7f1713c | 1 | <?php |
2 | ob_start("ob_gzhandler", 1); | |
3 | $buildlogs_server = "buildlogs.pld-linux.org"; | |
4 | $url = "index2.php"; | |
5 | $fail_or_ok = array( "FAIL", "OK" ); | |
6 | /* | |
7 | $database = 'sqlite:/home/services/ftp/buildlogs.db'; | |
8 | $root_directory = "/home/services/ftp/pub/pld-buildlogs"; | |
9 | */ | |
10 | ||
11 | // $database, $root_directory and others are taken from buildlogs.inc | |
12 | include('buildlogs2.inc'); | |
13 | ||
14 | /* It should be set */ | |
15 | ||
16 | $langs["en_US"]["charset"]="ISO-8859-1"; | |
17 | $langs["pl_PL"]["charset"]="ISO-8859-2"; | |
18 | ||
19 | $lang="en_US"; | |
20 | if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"])) | |
21 | { | |
22 | $rows=explode(";",$_SERVER["HTTP_ACCEPT_LANGUAGE"]); | |
23 | $rows=explode(",",$rows[0]); | |
24 | $lang_detected=rtrim($rows[0]); | |
25 | } else if (preg_match("/opera/i",$_SERVER["HTTP_USER_AGENT"])) | |
26 | { | |
27 | $lang_detected=preg_replace("/.*\[(.*)\].*/i","\\1",$_SERVER["HTTP_USER_AGENT"]); | |
28 | } | |
29 | ||
30 | // FIXME - some array | |
31 | $lang_detected=preg_replace("/^pl$/i","pl_PL",$lang_detected); | |
32 | ||
33 | if (isset($lang_detected) && isset($langs[$lang_detected])) | |
34 | { | |
35 | $lang=$lang_detected; | |
36 | } | |
37 | ||
38 | if (isset($_GET["lang"]))$_SESSION["lang"]=$_GET["lang"]; | |
39 | if (isset($_SESSION["lang"]))$lang=$_SESSION["lang"]; | |
40 | ||
41 | putenv("LANG=$lang"); | |
42 | setlocale(LC_ALL,$lang); | |
43 | bindtextdomain("messages","locale"); | |
44 | textdomain("messages"); | |
45 | ||
46 | if (isset($_GET["dist"]) && isset($_GET["arch"])) | |
47 | { | |
48 | $dist = basename($_GET["dist"]); | |
49 | $arch = basename($_GET["arch"]); | |
50 | } | |
51 | ||
52 | if (isset($_POST["dist"])) $dist = basename($_POST["dist"]); | |
53 | if (isset($_POST["arch"])) $arch = basename($_POST["arch"]); | |
54 | ||
55 | if (isset($_GET["name"])) { | |
56 | $name = basename($_GET["name"]); | |
57 | } | |
58 | if (isset($_GET["ok"]))$ok=(int)$_GET["ok"]; | |
59 | else $ok=""; | |
60 | if (isset($_GET["ns"]))$ns=(int)$_GET["ns"]; | |
61 | else $ns=""; | |
62 | if (isset($_GET["cnt"]))$cnt=(int)$_GET["cnt"]; | |
63 | else $cnt = 50; | |
64 | if (isset($_GET["action"]))$action=$_GET["action"]; | |
65 | else $action=""; | |
66 | if (isset($_GET["off"]))$off=(int)$_GET["off"]; | |
67 | else $off = 0; | |
68 | if (isset($_GET["id"]))$id=$_GET["id"]; | |
69 | ||
70 | if (isset($_POST["str"]))$str=$_POST["str"]; | |
71 | if (isset($_POST["action"]))$action=$_POST["action"]; | |
72 | ||
73 | function myheader() | |
74 | { | |
75 | echo '<' . '?xml version="1.0" encoding="' . _("ISO-8859-1") .'"?' . ">\n"; | |
76 | echo '<' . '?xml-stylesheet href="#internalStyle" type="text/css"?' . ">\n"; | |
77 | ?> | |
78 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" | |
79 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
80 | <html xmlns="http://www.w3.org/1999/xhtml"> | |
81 | <head> | |
82 | <title>PLD Build Logs</title> | |
83 | <?php echo '<meta http-equiv="Content-type" content="text/html; charset=' . _("ISO-8859-1") .'"/>' ."\n";?> | |
84 | <style type="text/css"><!-- | |
85 | A { text-decoration: none; } | |
86 | A:hover { text-decoration: underline; } | |
87 | H1 { font-family: arial,helvetica,sans-serif; | |
88 | font-size: 20pt; | |
89 | font-weight: bold;} | |
90 | H2 { font-family: arial,helvetica,sans-serif; | |
91 | font-size: 18pt; | |
92 | font-weight: bold;} | |
93 | BODY,TD { font-family: arial,helvetica,sans-serif; | |
94 | font-size: 13pt; } | |
95 | TH { font-family: arial,helvetica,sans-serif; | |
96 | font-size: 13pt; | |
97 | font-weight: bold; } | |
98 | //--> | |
99 | </style> | |
100 | </head> | |
101 | <!-- Diffrent color for visited link doesn't make much sense here... | |
102 | this page is autogenerated and it might be misleading after some | |
103 | build log changes. --> | |
104 | <body bgcolor="#ffffff" text="#000000" link="#5f26cd" vlink="#5f26cd"> | |
105 | <?php | |
106 | } | |
107 | ||
108 | function start_pre() | |
109 | { | |
110 | echo "<table cellpadding=\"10\"><tr><td bgcolor=\"#000000\">". | |
111 | "<font color=\"#cccccc\"><pre style=\"width: 2048px;overflow: scroll\">"; | |
112 | } | |
113 | ||
114 | function end_pre() | |
115 | { | |
116 | echo "</pre></font></td></tr></table>\n"; | |
117 | } | |
118 | ||
119 | function trailer() | |
120 | { | |
121 | echo "</body></html>"; | |
122 | } | |
123 | ||
124 | ||
125 | function mydie($msg) | |
126 | { | |
127 | echo "Fatal error: $msg"; | |
128 | } | |
129 | ||
130 | ||
131 | ||
132 | function list_logs() | |
133 | { | |
134 | global $database; | |
135 | global $arch, $dist, $ok; | |
136 | global $big_url, $ns; | |
137 | global $off, $cnt, $root_directory, $url; | |
138 | ||
139 | $big_url = "$url?dist=$dist&arch=$arch&ok=$ok&ns=$ns&cnt=$cnt"; | |
140 | ||
141 | if ($ok == 1) { | |
142 | echo "<h1>"._("Listing of")." $dist/$arch/OK " | |
143 | ."(<a href=\"$big_url&ok=0\">"._("fail")."</a>)</h1>\n"; | |
144 | } else { | |
145 | echo "<h1>"._("Listing of")." $dist/$arch/FAIL " | |
146 | ."(<a href=\"$big_url&ok=1\">"._("ok")."</a>)</h1>\n"; | |
147 | } | |
148 | ||
149 | echo "<div align=\"center\"><table cols=\"4\" border=\"0\" cellspacing=\"1\" ". | |
150 | "cellpadding=\"3\" bgcolor=\"#000000\" width=\"90%\">\n"; | |
151 | echo "<tr><th bgcolor=\"#CCCCFF\" align=\"right\" width=\"1%\">"._("No.")."</th>". | |
152 | "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"80%\">"._("Log File"). | |
153 | "[<a href=\"$big_url&ns=1\">"._("sort")."</a>]</th>". | |
154 | "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ". | |
155 | "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age"). | |
156 | "[<a href=\"$big_url&ns=0\">"._("sort")."</a>]</th>". | |
157 | "</tr>"; | |
158 | ||
159 | if ($ns != 1) $ns = 0; | |
160 | if (!isset($ok)) $ok = 0; | |
161 | // if (!isset($off)) $off = 0; | |
162 | // if (!isset($cnt)) $cnt = 50; | |
163 | if ($ns == 0) $order = "mtime DESC"; | |
164 | else $order = "name"; | |
165 | ||
166 | $query = "SELECT log_id, dist, arch, ok, name, mtime, size, id FROM logs WHERE " | |
167 | . "dist = '$dist' AND arch = '$arch' AND ok = $ok ORDER BY $order LIMIT $cnt OFFSET $off"; | |
168 | ||
169 | try { | |
170 | $dbh = new PDO("$database"); | |
171 | } catch (PDOException $e) { | |
172 | mydie("new PDO: " . $e->getMessage()); | |
173 | } | |
174 | $now = time(); | |
175 | $i = $off; | |
176 | foreach ($dbh->query("$query") as $row) { | |
177 | $f = $row["name"]; | |
178 | $t = $now - $row["mtime"]; | |
179 | $s = $row["size"]; | |
180 | $h = $row["log_id"]; | |
181 | ||
182 | $t /= 60; | |
183 | if ($t >= 60) { | |
184 | $t /= 60; | |
185 | if ($t >= 24) { | |
186 | $t /= 24; | |
187 | $t = round($t); | |
188 | $t = $t . " " . ngettext("day","days",$t); | |
189 | } else { | |
190 | $t = round($t); | |
191 | $t = $t . " " . ngettext("hour","hours",$t); | |
192 | } | |
193 | } else { | |
194 | $t = round($t); | |
195 | $t = $t . " " . ngettext("minute","minutes",$t); | |
196 | } | |
197 | $u = "$url?dist=$dist&arch=$arch&ok=$ok&name=$name&id=$id"; | |
198 | echo "<tr><td bgcolor=\"#CCCCCC\" align=\"right\">".($i+1).".</td>". | |
199 | "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ". | |
200 | "[<a href=\"$u&action=text\">"._("text")."</a> | ". | |
201 | "<a href=\"$u&action=tail\">"._("tail")."</a>]". | |
202 | "</td><td bgcolor=\"#CCCCCC\" align=\"right\">". | |
203 | "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n"; | |
204 | $i++; | |
205 | } | |
206 | $count = $i - $off; | |
207 | echo "</table></div>\n"; | |
208 | ||
209 | $backarr = "<<< "; | |
210 | $back = _("Page back"); | |
211 | $forward = _("Page forward"); | |
212 | $forwardarr = " >>>"; | |
213 | ||
214 | echo "<p><table width=\"90%\" align=\"center\"><tr><td align=\"left\" width=\"1%\">"; | |
215 | ||
216 | if ($off > 0) { | |
217 | $noff = $off - $count; | |
218 | if ($noff < 0) | |
219 | $noff = 0; | |
220 | $hrefurl = "<a href=\"$big_url&off=$noff\">"; | |
221 | echo "$hrefurl$backarr</a></td><td align=\"left\">$hrefurl$back</a>"; | |
222 | } else { | |
223 | echo "$backarr</td><td align=\"left\">$back"; | |
224 | } | |
225 | ||
226 | echo "</td>\n<td align=\"center\">"; | |
227 | ||
228 | if (isset($dist) && isset($arch)) { | |
229 | echo "[<a href=\"$big_url&action=qa\">"._("View <quot>rpm -qa</quot> of builder")."</a>]"; | |
230 | } else { | |
231 | echo " "; | |
232 | } | |
233 | ||
234 | echo "</td>\n<td align=right>"; | |
235 | if ($cnt == $count) { | |
236 | $noff = $off + $cnt; | |
237 | if ($noff < 0) | |
238 | $noff = 0; | |
239 | $hrefurl = "<a href=\"$big_url&off=$noff\">"; | |
240 | echo "$hrefurl$forward</a></td><td align=right width=1%>$hrefurl$forwardarr</a>"; | |
241 | } else { | |
242 | echo "$forward</td><td align=right width=1%>$forwardarr"; | |
243 | } | |
244 | echo "</td>\n</tr></table></p>"; | |
245 | } | |
246 | ||
247 | function file_name() | |
248 | { | |
249 | global $ok, $dist, $arch, $name, $id; | |
250 | ||
251 | if (isset($name) && isset($ok) && isset($arch) && isset($dist)) { | |
252 | if (isset($id) && $id != '') { | |
253 | $name = $name . ",$id"; | |
254 | } | |
255 | $w = $ok ? "OK" : "FAIL"; | |
256 | return "$dist/$arch/$w/$name.bz2"; | |
257 | } | |
258 | } | |
259 | ||
260 | function dump_log($tail) | |
261 | { | |
262 | global $ok, $url, $dist, $arch; | |
263 | global $root_directory, $big_url, $ns, $id, $cnt, $off; | |
264 | global $buildlogs_server; | |
265 | ||
266 | $f = file_name(); | |
267 | ||
268 | if ($f == false) | |
269 | return; | |
270 | ||
271 | $df = preg_replace("/.*\/([^\/]*)$/", "\\1", $f); | |
272 | $df = preg_replace("/\.(bz2|gz)$/", "", $df); | |
273 | ||
274 | echo "<h1>$df</h1>"; | |
275 | ||
276 | echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\">"; | |
277 | ||
278 | function one_item($h, $t) { | |
279 | echo "<tr><td bgcolor=\"#ccccff\">$h:</td>". | |
280 | "<td bgcolor=\"#cccccc\">$t</td></tr>"; | |
281 | } | |
282 | ||
283 | function href($h, $c) { | |
284 | return "<a href=\"$h\">$c</a>"; | |
285 | } | |
286 | ||
287 | one_item(_("Status"), ($ok == 1 ? | |
288 | "<font color=\"green\"><b>"._("OK")."</b></font>" : | |
289 | "<font color=\"red\"><b>"._("Failed")."</b></a>")); | |
290 | one_item(_("Source URL"), | |
291 | href("ftp://$buildlogs_server/$f", | |
292 | "ftp://$buildlogs_server/$f")); | |
293 | ||
294 | $big_url = "$url?dist=$dist&arch=$arch&ok=$ok&ns=$ns&cnt=$cnt"; | |
295 | $bu = "$big_url&off=$off"; | |
296 | ||
297 | one_item(_("text/plain URL"), | |
298 | href("$bu&id=$id&action=text", | |
299 | _("View!"))); | |
300 | if ($tail) { | |
301 | one_item(_("full text"), | |
302 | href("$bu&id=$id", | |
303 | _("View!"))); | |
304 | } | |
305 | ||
306 | if (isset($dist) && isset($arch)) { | |
307 | one_item(_("rpm -qa of builder"), href("$bu&action=qa", _("View!"))); | |
308 | } else { | |
309 | one_item(_("rpm -qa of builder"), _("Not available")); | |
310 | } | |
311 | one_item("Data", date("Y/m/d H:i:s", filemtime("$root_directory/$f"))); | |
312 | /* | |
313 | echo "<tr><td>Here:</td><td>" . | |
314 | "<a href=\"$url?idx=$idx&ok=$ok&id=$id\">". | |
315 | "http://" . getenv("SERVER_NAME") . | |
316 | getenv("SCRIPT_NAME") . "?idx=$idx&ok=$ok&id=$id</a>" . | |
317 | "</td></tr>"; */ | |
318 | ||
319 | echo "</table><h2>"._("Content:")."</h2>"; | |
320 | ||
321 | ||
322 | # what can I say beside PHP suxx? how the fuck should I create | |
323 | # bidirectional pipe? gotta use wget | |
324 | ||
325 | if (preg_match("/\.bz2$/", $f)) { | |
326 | $filter = "bzcat"; | |
327 | } elseif (preg_match("/\.gz$/", $f)) { | |
328 | $filter = "zcat"; | |
329 | } else { | |
330 | $filter = "cat"; | |
331 | } | |
332 | ||
333 | $cmd = "$filter $root_directory/$f"; | |
334 | if ($tail) | |
335 | $cmd = "$cmd | tail -n 100"; | |
336 | $fd = popen($cmd, "r"); | |
337 | start_pre(); | |
338 | while (($s = fgets($fd, 102400)) != false) { | |
339 | if (strlen($s) > 800) { | |
340 | $s = chunk_split($s, 800, "\n "); | |
341 | $s = trim($s); | |
342 | } | |
343 | $s = htmlspecialchars($s); | |
344 | echo $s; | |
345 | } | |
346 | end_pre(); | |
347 | pclose($fd); | |
348 | ||
349 | ?> | |
350 | <table width="100%"> | |
351 | <tr> | |
352 | <td align=left> | |
353 | [<a href="<?php echo $bu; ?>"><?=_("Back to list of logs")?></a>] | |
354 | </td> | |
355 | <td align=right> | |
356 | [<a href="<?php echo "$bu&action=qa" | |
357 | ?>"><?=_("View rpm -qa of builder")?></a>] | |
358 | </td> | |
359 | </tr> | |
360 | </table> | |
361 | <?php | |
362 | ||
363 | } | |
364 | ||
365 | function dump_text() | |
366 | { | |
367 | global $root_directory; | |
368 | global $buildlogs_server; | |
369 | ||
370 | header("Content-type: text/plain"); | |
371 | ||
372 | $f = file_name(); | |
373 | if ($f == false) | |
374 | return; | |
375 | ||
376 | echo "# src : ftp://$buildlogs_server/$f\n"; | |
377 | echo "# date : " . | |
378 | date("Y/m/d H:i:s", filemtime("$root_directory/$f")) . "\n"; | |
379 | ||
380 | if (preg_match("/\.bz2$/", $f)) { | |
381 | $filter = "bzcat"; | |
382 | } elseif (preg_match("/\.gz$/", $f)) { | |
383 | $filter = "zcat"; | |
384 | } else { | |
385 | $filter = "cat"; | |
386 | } | |
387 | ||
388 | $cmd = "$filter $root_directory/$f"; | |
389 | $fd = popen($cmd, "r"); | |
390 | while (($s = fgets($fd, 1000)) != false) { | |
391 | echo $s; | |
392 | } | |
393 | pclose($fd); | |
394 | } | |
395 | ||
396 | function list_archs() | |
397 | { | |
398 | global $addr, $url, $cnt,$ok,$ns; | |
399 | ||
400 | if (!isset($cnt)) | |
401 | $cnt = 50; | |
402 | ||
403 | $big_url = "$url?ok=$ok&ns=$ns&cnt=$cnt"; | |
404 | ||
405 | echo "<table width=\"100%\" border=\"0\">\n"; | |
406 | echo "<tr><td bgcolor=\"#cccccc\" nowrap=\"nowrap\">"._("Failed")."</td><td bgcolor=\"#cccccc\">"._("Ok")."</td></tr>\n"; | |
407 | for ($i = 1; $i < count($addr); $i++) { | |
408 | $dist = $addr[$i]['dist']; | |
409 | $arch = $addr[$i]['arch']; | |
410 | echo "<tr><td nowrap=\"nowrap\">". | |
411 | "<a href=\"$url?dist=$dist&arch=$arch&ok=0&cnt=$cnt\">$addr[$i]</a></td><td nowrap=\"nowrap\">". | |
412 | "[<a href=\"$url?dist=$dist&arch=$arch&ok=1&cnt=$cnt\">OK</a>]</td>". | |
413 | #"<td>[<a href=\"$url?idx=$i&action=qa\">qa</a>]</td>". | |
414 | "</tr>\n"; | |
415 | } | |
416 | echo "</table><hr />\n"; | |
417 | ||
418 | echo "<div align=\"center\">"; | |
419 | echo "<a href=\"$big_url&action=adv_search\">"._("Advanced Search")."</a><br />\n"; | |
420 | ||
421 | echo "<a href=\"$url\">main()</a><hr />\n"; | |
422 | echo "<a href=\"http://www.pld-linux.org/\"><img src=\"powpld.png\" ". | |
423 | "alt=\""._("Powered by PLD Linux")."\" border=\"0\" /></a><br />\n" . | |
424 | "<small>(c) 2002 ". | |
425 | "<a href=\"mailto:feedback@pld-linux.org\">PLD Team</a><br />\n". | |
426 | '$Revision: 1.7 $'. | |
427 | "</small></div>\n"; | |
428 | ||
429 | # smile ;) | |
430 | echo "<div align=\"center\"><small>"; | |
431 | $pow = array("vim", "php", "brain", "power", "electricity", | |
432 | "coffee", "ufo", "penguin", "GNOME", "ELF", "DWARF", | |
433 | "voodoo magic", "Linux", "x-files", "X", "foobar", | |
434 | "/dev/null", "/dev/zero", "/dev/drzewo", | |
435 | "Leppe'", "matrix", "Neo", "PDP-11", | |
436 | "Ken", "GNU antilope", "PDP-7", "ITS", "Multics", | |
437 | "foobarbaz", "ed", "Joe", "Unix conspiracy", | |
438 | "overclock", "The Right Thing", | |
439 | "The Bad Thing", "Star Treck", "NSA", "NASA", | |
440 | "achelon", "VAX", "Real Programmer", | |
441 | "Real Operating System", "Real Computer", | |
442 | "computron", "bogon", "quantum bogodynamics", | |
443 | "BOFH", "/dev/ill", "nasi tu byli", | |
444 | "Paranoid Android", "Lunatic Corp", "Parallel thinking", | |
445 | "sfistak", "Linus", "The Golden Path", "Dark Side of the Force", | |
446 | "Przewodniczacego Lepper-a", "KDE", "Microsoft Windows 2003", "sqlite3", | |
447 | "synergy" | |
448 | # feel free to add sth if you change this file ;) | |
449 | ); | |
450 | echo _("Powered by")." "; | |
451 | $max = 1; | |
452 | for ($i = 0; $i < $max; $i++) { | |
453 | $x = rand(0, count($pow) - 1); | |
454 | if ($pow[$x] == "") $i--; | |
455 | else echo $pow[$x] . ($i == $max - 1 ? "." : ", "); | |
456 | $pow[$x] = ""; | |
457 | } | |
458 | echo "</small></div>"; | |
459 | ||
460 | if (isset($dist) && isset($arch)) { | |
461 | echo "<form action=\"index.php\" method=\"post\">"; | |
462 | echo "<input type=\"hidden\" name=\"dist\" value=\"$dist\" />"; | |
463 | echo "<input type=\"hidden\" name=\"arch\" value=\"$arch\" />"; | |
464 | echo "<input type=\"hidden\" name=\"action\" value=\"sqa\" />"; | |
465 | echo "<input type=\"text\" size=\"14\" name=\"str\" /><br />"; | |
466 | echo "<input type=\"submit\" name=\"submit\" value=\""._("Search rpmqa!")."\" />"; | |
467 | echo "</form>"; | |
468 | } | |
469 | } | |
470 | ||
471 | function get_qa() | |
472 | { | |
473 | global $dist, $arch; | |
474 | ||
475 | if (!isset($dist) || !isset($arch)) | |
476 | return false; | |
477 | ||
478 | $addr = "http://ftp.pld-linux.org/dists/$dist/.stat/builder/$dist/rpmqa-$arch.txt"; | |
479 | return fopen("$addr", "r"); | |
480 | } | |
481 | ||
482 | function search_qa() | |
483 | { | |
484 | global $url, $str, $dist, $arch; | |
485 | ||
486 | $f = get_qa(); | |
487 | echo "<h1>"._("Search results for")." '$str' "._("in")." $dist/$arch</h1>"; | |
488 | ||
489 | start_pre(); | |
490 | ||
491 | if ($f == 0) { | |
492 | echo _("Sorry, cannot open."); | |
493 | } else { | |
494 | while (($s = fgets($f, 1000)) != false) { | |
495 | if (stristr($s, $str)) | |
496 | echo $s; | |
497 | } | |
498 | echo "/* EOF */"; | |
499 | } | |
500 | end_pre(); | |
501 | } | |
502 | ||
503 | function dump_qa($plain) | |
504 | { | |
505 | global $url, $dist, $arch; | |
506 | ||
507 | $f = get_qa(); | |
508 | ||
509 | if ($plain) { | |
510 | header("Content-type: text/plain"); | |
511 | echo _("# rpm -qa of")." $dist/$arch\n"; | |
512 | } else { | |
513 | echo "<h1>"._("rpm -qa of")." $a</h1>"; | |
514 | echo "<a href=\"$url?dist=$dist&arch=$arch&action=qatxt\">"._("text/plain version")."</a>"; | |
515 | start_pre(); | |
516 | } | |
517 | ||
518 | if ($f == 0) { | |
519 | echo _("Sorry, cannot open."); | |
520 | } else { | |
521 | while (($s = fgets($f, 1000)) != false) { | |
522 | echo $s; | |
523 | } | |
524 | } | |
525 | ||
526 | if (!$plain) | |
527 | end_pre(); | |
528 | } | |
529 | ||
530 | ||
531 | function adv_search() | |
532 | { | |
533 | global $database, $addr, $fail_or_ok, $url, $_POST, $off, $cnt, $root_directory, $ok, $ns; | |
534 | ||
535 | $big_url = "$url?ok=$ok&ns=$ns&cnt=$cnt"; | |
536 | ||
537 | echo "<script><!--\n". | |
538 | "function checkboxToggle() {\n". | |
539 | "for (var i=0;i<document.forms[0].elements.length;i++) {\n". | |
540 | "var e = document.forms[0].elements[i];\n". | |
541 | "if ((e.name != 'all') && (e.type=='checkbox'))\n". | |
542 | "e.checked = document.forms[0].all.checked;\n". | |
543 | "}\n }\n -->\n </script>\n"; | |
544 | ||
545 | /* Shut up warnings */ | |
546 | if (!isset($_POST["name"])) $_POST["name"] = ""; | |
547 | if (!isset($_POST["age1"])) $_POST["age1"] = ""; | |
548 | if (!isset($_POST["age2"])) $_POST["age2"] = ""; | |
549 | if (!isset($_POST["size1"])) $_POST["size1"] = ""; | |
550 | if (!isset($_POST["size2"])) $_POST["size2"] = ""; | |
551 | ||
552 | echo "<form action=\"index.php?action=adv_search\" method=\"post\">"; | |
553 | ||
554 | echo "<div align=\"center\">"; | |
555 | echo "<table border=\"0\">\n"; | |
556 | echo "<tr>\n"; | |
557 | echo "<td>"._("Package name")."</td>\n"; | |
558 | echo "<td><input type=\"text\" size=\"20\" name=\"name\" value=\"". $_POST["name"] ."\"/></td>\n"; | |
559 | echo "</tr>\n"; | |
560 | ||
561 | echo "<tr>\n"; | |
562 | echo "<td>"._("Days")."</td>\n"; | |
563 | echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"age1\" value=\"". $_POST["age1"] ."\" /></td>\n"; | |
564 | echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"age2\" value=\"". $_POST["age2"] ."\" /></td>\n"; | |
565 | echo "</tr>\n"; | |
566 | ||
567 | echo "<tr>\n"; | |
568 | echo "<td>"._("Size")."</td>\n"; | |
569 | echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"size1\" value=\"". $_POST["size1"] ."\" /></td>\n"; | |
570 | echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"size2\" value=\"". $_POST["size2"] ."\" /></td>\n"; | |
571 | echo "</tr>\n"; | |
572 | ||
573 | echo "<tr>\n"; | |
574 | echo "<td>"._("Search logs:")."</td>\n"; | |
575 | echo "</tr>\n"; | |
576 | ||
577 | echo "<tr>\n"; | |
578 | echo "<td>"._("Failed")."</td>\n"; | |
579 | echo "<td>"._("OK")."</td>\n"; | |
580 | echo "</tr>\n"; | |
581 | ||
582 | for ($i = 1; $i < count($addr); $i++) | |
583 | { | |
584 | echo "<tr>\n"; | |
585 | $name="as0_".$i; | |
586 | $dist = $addr[$i]['dist']; | |
587 | $arch = $addr[$i]['arch']; | |
588 | if (!isset($_POST["$name"])) { | |
589 | $check = " "; | |
590 | } else { | |
591 | $check=" checked=\"on\""; | |
592 | } | |
593 | echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">".$dist/$arch."</label></td>\n"; | |
594 | $name="as1_".$i; | |
595 | if (!isset($_POST["$name"])) { | |
596 | $check = " "; | |
597 | } else { | |
598 | $check=" checked=\"on\""; | |
599 | } | |
600 | echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">".$dist/$arch."</label></td>\n"; | |
601 | echo "</tr>\n"; | |
602 | } | |
603 | ||
604 | echo "<tr>\n"; | |
605 | echo "<td><input name=\"all\" type=\"checkbox\" checked=\"on\" onClick=\"checkboxToggle()\">"._("Toggle checkboxes")." <input type=\"submit\" name=\"submit\" value=\""._("Search!")."\" /></td>"; | |
606 | echo "</tr>\n"; | |
607 | ||
608 | echo "</table>\n"; | |
609 | ||
610 | // if (isset($_POST["name"]) || isset($_POST["age1"]) || isset($_POST["age2"]) || | |
611 | // isset($_POST["size1"]) || isset($_POST["size2"]) | |
612 | if (($_POST["name"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") || | |
613 | ($_POST["size1"]!="") || ($_POST["size2"]!="")) | |
614 | { | |
615 | $query = "SELECT log_id, dist, arch, ok, name, size, mtime, id FROM logs WHERE 1 "; | |
616 | if ($_POST["name"] != "") { | |
617 | $n = addslashes($_POST["name"]); | |
618 | $query .= "AND name LIKE '$n%' "; | |
619 | } | |
620 | $now = time(); | |
621 | ||
622 | if ($_POST["age1"] != "") { | |
623 | $age = $now - (int)$_POST["age1"] * 24 * 3600; | |
624 | $query .= "AND mtime > $age "; | |
625 | } | |
626 | ||
627 | if ($_POST["age2"] != "") { | |
628 | $age = $now - (int)$_POST["age2"] * 24 * 3600; | |
629 | $query .= "AND mtime < $age "; | |
630 | } | |
631 | ||
632 | if ($_POST["size1"] != "") { | |
633 | $size = (int)$_POST["size1"]; | |
634 | $query .= "AND size > $size "; | |
635 | } | |
636 | ||
637 | if ($_POST["size2"] != "") { | |
638 | $size = (int)$_POST["size2"]; | |
639 | $query .= "AND size < $size "; | |
640 | } | |
641 | ||
642 | $or = "AND ("; | |
643 | for ($i = 1; $i < count($addr); $i++) { | |
644 | for ($j = 0; $j < 2; $j++) { | |
645 | if (isset($_POST["as" . $j . "_" .$i])) { | |
646 | $query .= "$or (dist = $addr[$i]['dist'] AND arch = $addr[$i]['arch'] AND ok = $j)"; | |
647 | $or = " OR "; | |
648 | } | |
649 | } | |
650 | } | |
651 | if ($or == " OR ") $query .= ")"; | |
652 | // if (!isset($cnt)) $cnt = 50; | |
653 | // if (!isset($off)) $off = 0; | |
654 | if (!isset($ns)) $ns = 0; | |
655 | switch ($ns) { | |
656 | case 0: | |
657 | $query .= " ORDER BY mtime DESC"; | |
658 | break; | |
659 | case 1: | |
660 | $query .= " ORDER BY name"; | |
661 | break; | |
662 | case 2: | |
663 | $query .= " ORDER BY dist, arch, name"; | |
664 | break; | |
665 | } | |
666 | $query .= " LIMIT $cnt OFFSET $off "; | |
667 | ||
668 | try { | |
669 | $dbh = new PDO("$database"); | |
670 | } catch (PDOException $e) { | |
671 | mydie("new PDO: " . $e->getMessage()); | |
672 | } | |
673 | $result = $dbh->query("$query")->fetchAll(); | |
674 | ||
675 | if ($result == FALSE) { | |
676 | echo _("Nothing found"); | |
677 | } else { | |
678 | echo "<table border=\"0\" cellspacing=\"1\" ". | |
679 | "cellpadding=3 bgcolor=\"#000000\" width=\"90%\">\n"; | |
680 | echo "<tr><th bgcolor=\"#CCCCFF\" align=\"left\" width=\"10%\">"._("Builder"). | |
681 | "[<a href=\"$big_url&ns=2\">"._("sort")."</a>]</th>"; | |
682 | echo "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"60%\">"._("Log File"). | |
683 | "[<a href=\"$big_url&ns=1\">"._("sort")."</a>]</th>". | |
684 | "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ". | |
685 | "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age"). | |
686 | "[<a href=\"$big_url&ns=0\">"._("sort")."</a>]</th>". | |
687 | "</th></tr>"; | |
688 | $i = $off; | |
689 | // for ($i = $off; $i < $off + $count; $i++) { | |
690 | foreach ($result as $row) { | |
691 | $dist = $row["dist"]; | |
692 | $arch = $row["arch"]; | |
693 | $name = $row["name"]; | |
694 | $id = $row["id"]; | |
695 | $f = $name; | |
696 | if ($id != '') $f .= ",$id"; | |
697 | $t = $now - $row["mtime"]; | |
698 | $s = $row["size"]; | |
699 | $t /= 60; | |
700 | if ($t >= 60) { | |
701 | $t /= 60; | |
702 | if ($t >= 24) { | |
703 | $t /= 24; | |
704 | $t = round($t); | |
705 | $t = $t . " " . ngettext("day","days",$t); | |
706 | } else { | |
707 | $t = round($t); | |
708 | $t = $t . " " . ngettext("hour","hours",$t); | |
709 | } | |
710 | } else { | |
711 | $t = round($t); | |
712 | $t = $t . " " . ngettext("minute","minutes",$t); | |
713 | } | |
714 | ||
715 | // $big_url = "$url?idx=$i&ok=$j&ns=$ns&cnt=$cnt"; | |
716 | $ok = $row["ok"]; | |
717 | $u = "$url?dist=$dist&arch=$arch&name=$name&ok=$ok;&id=$id"; | |
718 | $b = "$url?dist=$dist&arch=$arch&ok=$ok&ns=$ns&off=$off&cnt=$cnt"; | |
719 | ||
720 | $builder = "$dist/$arch/". $fail_or_ok[$ok]; | |
721 | echo "<tr>"; | |
722 | echo "<td bgcolor=\"#CCCCCC\"><a href=\"$b\">$builder</a></td>"; | |
723 | echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ". | |
724 | "[<a href=\"$u&action=text\">"._("text")."</a> | ". | |
725 | "<a href=\"$u&action=tail\">"._("tail")."</a>]". | |
726 | "</td><td bgcolor=\"#CCCCCC\" align=\"right\">". | |
727 | "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n"; | |
728 | $i++; | |
729 | } | |
730 | echo "</table></div>\n"; | |
731 | ||
732 | $backarr = "<<< "; | |
733 | $back = _("Page back"); | |
734 | $forward = _("Page forward"); | |
735 | $forwardarr = " >>>"; | |
736 | ||
737 | } | |
738 | // FIXME | |
739 | /* | |
740 | echo "<p><table width=\"90%\" align=\"center\"><tr><td align=left width=1%>"; | |
741 | ||
742 | if ($off > 0) { | |
743 | $noff = $off - $cnt; | |
744 | if ($noff < 0) | |
745 | $noff = 0; | |
746 | $hrefurl = "<a href=\"$big_url&off=$noff\">"; | |
747 | echo "$hrefurl$backarr</a></td><td align=left>$hrefurl$back</a>"; | |
748 | } else { | |
749 | echo "$backarr</td><td align=left>$back"; | |
750 | } | |
751 | ||
752 | echo "</td>\n<td align=\"center\">"; | |
753 | echo "</td>\n<td align=\"right\">"; | |
754 | ||
755 | if ($off + $cnt < count($list)) | |
756 | { | |
757 | $noff = $off + $cnt; | |
758 | if ($noff < 0) | |
759 | $noff = 0; | |
760 | $hrefurl = "<a href=\"$big_url&off=$noff\">"; | |
761 | echo "$hrefurl$forward</a></td><td align=\"right\" width=\"1%\">$hrefurl$forwardarr</a>"; | |
762 | } | |
763 | else | |
764 | { | |
765 | echo "$forward</td><td align=\"right\" width=\"1%\">$forwardarr"; | |
766 | } | |
767 | ||
768 | echo "</td>\n</tr></table></p>"; | |
769 | */ | |
770 | } else | |
771 | { | |
772 | echo _("Enter something!"); | |
773 | } | |
774 | echo "</form>\n"; | |
775 | } | |
776 | ||
777 | function welcome() | |
778 | { | |
779 | ?> | |
780 | <table border="0" width="100%"><tr><td width="20%"> </td><td> | |
781 | <h1><?=_("Welcome!")?></h1> | |
782 | <p><?=_("Welcome to PLD Build Logs WWW interface.")?></p><p> | |
783 | <?=_("Feel free to email bug reports, complaints and feature requests ")?> | |
784 | <!-- ech... niech strace... --> | |
785 | <a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?> | |
786 | <a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a> ;)</p> | |
787 | <p>Version: $Id: index.php,v 1.7 2007/11/28 12:42:52 witekfl Exp $</p> | |
788 | </td><td width="20%"> </td></tr> | |
789 | </table> | |
790 | <?php | |
791 | } | |
792 | ||
793 | header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); | |
794 | header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); | |
795 | header("Cache-Control: no-cache, must-revalidate"); | |
796 | header("Pragma: no-cache"); | |
797 | ||
798 | //phpinfo(); | |
799 | if ($action == "text") { | |
800 | dump_text(); | |
801 | } else if ($action == "adv_search") { | |
802 | myheader(); | |
803 | adv_search(); | |
804 | trailer(); | |
805 | } else if ($action == "qatxt") { | |
806 | dump_qa(1); | |
807 | } else { | |
808 | myheader(); | |
809 | echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=\"top\" width=\"10%\">"; | |
810 | list_archs(); | |
811 | echo "</td><td valign=\"top\">"; | |
812 | flush(); | |
813 | if ($action == "qa") | |
814 | dump_qa(0); | |
815 | else if ($action == "sqa") | |
816 | search_qa(); | |
817 | else if (isset($id) || isset($name)) | |
818 | dump_log($action == "tail"); | |
819 | else if (isset($dist)) | |
820 | list_logs(); | |
821 | else | |
822 | welcome(); | |
823 | echo "</td></tr></table>"; | |
824 | trailer(); | |
825 | } | |
826 | ?> |