]> git.pld-linux.org Git - projects/buildlogs.git/blob - index.php
Escape few things (that can be escaped early without breaking functionality). Should...
[projects/buildlogs.git] / index.php
1 <?php
2 if (!function_exists("ob_gzhandler"))
3   die("ob_gzhandler function is missing - install php zlib module");
4
5 ob_start("ob_gzhandler", 1);
6 $buildlogs_server = "buildlogs.pld-linux.org";
7 $url = "index.php";
8 $fail_or_ok = array( "FAIL", "OK" );
9 /*
10 $database = 'sqlite:/home/services/ftp/buildlogs2.db';
11 $root_directory = "/home/services/ftp/pub/pld-buildlogs";
12 */
13
14 // $database, $root_directory and others are taken from buildlogs.inc
15 include('buildlogs.inc');
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";
23 $lang_detected="";
24 if (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
37 if (isset($lang_detected) && isset($langs[$lang_detected]))
38 {
39   $lang=$lang_detected;
40 }
41
42 if (isset($_GET["lang"]))$_SESSION["lang"]=$_GET["lang"];
43 if (isset($_SESSION["lang"]))$lang=$_SESSION["lang"];
44
45 putenv("LANG=$lang");
46 setlocale(LC_ALL,$lang);
47 bindtextdomain("messages","locale");
48 textdomain("messages");
49
50 if (isset($_GET["dist"]) && isset($_GET["arch"]))
51 {
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'));
56 }
57
58 if (isset($_POST["dist"])) $dist = basename($_POST["dist"]);
59 if (isset($_POST["arch"])) $arch = basename($_POST["arch"]);
60
61 if (isset($_GET["name"])) {
62         $name_url = urlencode($_GET["name"]);
63         $name = $_GET["name"];
64         $name = $dist = basename(htmlspecialchars($name, ENT_QUOTES, 'UTF-8'));
65 }
66 if (isset($_GET["ok"]))$ok=(int)$_GET["ok"];
67 else $ok="";
68 if (isset($_GET["ns"]))$ns=(int)$_GET["ns"];
69 else $ns="";
70 if (isset($_GET["cnt"]))$cnt=(int)$_GET["cnt"];
71 else $cnt = 50;
72 if (isset($_GET["action"])) {
73         $action = $_GET["action"];
74         $action = htmlspecialchars($action, ENT_QUOTES, 'UTF-8');
75 } else
76         $action="";
77 if (isset($_GET["off"]))$off=(int)$_GET["off"];
78 else $off = 0;
79 if (isset($_GET["id"])) {
80         $id = $_GET["id"];
81         $id = htmlspecialchars($id, ENT_QUOTES, 'UTF-8');
82 }
83
84 if (isset($_POST["str"])) {
85         $str = $_POST["str"];
86         $str = htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
87 }
88 if (isset($_POST["action"])) {
89         $action = $_POST["action"];
90         $action = htmlspecialchars($action, ENT_QUOTES, 'UTF-8');
91 }
92
93 if (isset($arch) && $arch == "src")
94         $arch = "SRPMS";
95
96 function myheader()
97 {
98 echo '<' . '?xml version="1.0" encoding="' . _("ISO-8859-1") .'"?' . ">\n";
99 echo '<' . '?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"><!--
108 A { text-decoration: none; }
109 A:hover { text-decoration: underline; }
110 H1 { font-family: arial,helvetica,sans-serif;
111      font-size: 20pt;
112      font-weight: bold;}
113 H2 { font-family: arial,helvetica,sans-serif;
114      font-size: 18pt;
115      font-weight: bold;}
116 BODY,TD { font-family: arial,helvetica,sans-serif;
117           font-size: 13pt; }
118 TH { font-family: arial,helvetica,sans-serif;
119      font-size: 13pt;
120      font-weight: bold; }
121 /* error lines from build logs */
122 .error {
123         background-color: #b00;
124 }
125 .verbose {
126         color: #886;
127 }
128 .section {
129         color: #111;
130         background-color: #161;
131 }
132 .changelog a {
133         color: #fff;
134 }
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
145 function start_pre()
146 {
147         echo "<table cellpadding=\"10\"><tr><td bgcolor=\"#000000\">".
148                 "<font color=\"#cccccc\"><pre style=\"white-space: pre-line; word-break: break-all;\">";
149 }
150
151 function end_pre()
152 {
153         echo "</pre></font></td></tr></table>\n";
154 }
155
156 function trailer()
157 {
158         echo "</body></html>";
159 }
160
161
162 function mydie($msg)
163 {
164         echo "Fatal error: $msg";
165 }
166
167
168
169 function list_logs()
170 {
171         global $database;
172         global $arch, $dist, $ok;
173         global $big_url, $ns;
174         global $off, $cnt, $root_directory, $url;
175
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);
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
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 ";
211
212         try {
213                 $dbh = new PDO("$database");
214                 $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
215                 $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
216         } catch (PDOException $e) {
217                 mydie("new PDO: " . $e->getMessage());
218         }
219         $now = time();
220         $i = $off;
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"];
233                 $f = $name;
234                 $name_url = urlencode($name);
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                 }
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);
261                 echo "<tr><td bgcolor=\"#CCCCCC\" align=\"right\">".($i+1).".</td>".
262                      "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">".htmlspecialchars($f, ENT_QUOTES, 'UTF-8')."</a> ".
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
310 function file_name()
311 {
312         global $ok, $dist, $arch, $name, $name_url, $id;
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
323 function 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
338 function dump_log($tail)
339 {
340         global $ok, $url, $dist, $arch, $name, $name_url;
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);
351         list($name, $id) = explode(',', $df);
352
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>";
358
359         echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\" width=\"100%\">";
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
370         one_item(_("Status"), ($ok == 1 ?
371                                 "<font color=\"green\"><b>"._("OK")."</b></font>" :
372                                 "<font color=\"red\"><b>"._("Failed")."</b></a>"));
373         one_item(_("Source URL"),
374                  href("ftp://$buildlogs_server/$f",
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
380         one_item(_("text/plain URL"),
381                  href("$bu&amp;name=$name_url&amp;id=$id&amp;action=text",
382                       _("View!")));
383         if ($tail) {
384                 one_item(_("full text"),
385                          href("$bu&amp;name=$name_url&amp;id=$id",
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         }
394         one_item("Date", date("Y/m/d H:i:s", filemtime("$root_directory/$f")));
395         /*
396         echo "<tr><td>Here:</td><td>" .
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
402
403
404         # what can I say beside PHP suxx? how the fuck should I create
405         # bidirectional pipe? gotta use wget
406
407         $filter = get_filter($f);
408
409         $cmd = "$filter '$root_directory/$f'";
410         $fd = popen($cmd, "r");
411         $toc = array();
412         $err = array();
413         $first_cut = false;
414         $first_cut_done = false;
415         $time = "";
416         $out_buf = array();
417         $out_buf_size = 0;
418         $err_count = 0;
419         while (($s = fgets($fd, 102400)) != false) {
420
421                 $toc_elem = false;
422                 $err_elem = false;
423
424                 $s = htmlspecialchars($s);
425                 // highlight errors
426                 if (preg_match("/(?:fail|error(s|\sCS\d+)?):/i", $s)) {
427                         $first_cut = true;
428                         $err_count++;
429                         $toc_elem = "error $err_count";
430                         $err_elem = $s;
431                         $s = "<span class=error id=error-$err_count>$s</span>";
432                 } elseif (preg_match("/(?:undefined reference to|recipe for target '.*?' failed|compilation terminated|make\[.*:.* (Stop\.$|Error))/i", $s)) {
433                         $first_cut = true;
434                         $err_count++;
435                         $toc_elem = "error $err_count";
436                         $err_elem = $s;
437                         $s = "<span class=error id=error-$err_count>$s</span>";
438                 } elseif (preg_match("#^\+ /usr/bin/make\b.*\b(?P<target>check)\b#", $s, $m)) {
439                         // rpm build section
440                         $toc_elem = "make {$m['target']}";
441                         $err_elem = $s;
442                         $s = "<span class=line id=make-{$m['target']}>$s</span>";
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>";
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
457                         $toc_elem = $m['section'];
458                         $err_elem = $s;
459                         $s = "<span class=section id={$m['section']}>$s</span>";
460                 } elseif (preg_match("/^Processing files: (?P<pkg>(?P<name>.+)-[^-]+-[^-]+)/", $s, $m)) {
461                         $first_cut = true;
462                         // processing files
463                         $toc_elem = "files ".$m['name'];
464                         $err_elem = $s;
465                         $s = "<span class=section id=files-{$m['name']}>$s</span>";
466                 } elseif (preg_match("/^ended at: (?P<date>.+), done in (?P<time>[\d:.]+)/", $s, $m)) {
467                         $time = $m['time'];
468                 }
469
470                 $out_buf[] = $s;
471                 $out_buf_size++;
472
473                 // if error/processing found truncate early but keep last 100 lines before error
474                 if ($tail && $first_cut && !$first_cut_done && $out_buf_size > 100) {
475                         array_splice($out_buf, 0, $out_buf_size - 100);
476                         $out_buf_size = 100;
477                         $first_cut_done = true;
478                 }
479
480                 // if (not in tail mode) or (in tail mode but we have an error)
481                 if (!$tail || $first_cut) {
482                         if ($toc_elem)
483                                 $toc[] = $toc_elem;
484                         if ($err_elem)
485                                 $err[] = $err_elem;
486                 }
487         }
488         pclose($fd);
489
490         // no errors found, no processing found but we are in tail mode
491         if ($tail && !$first_cut_done && $out_buf_size > 100) {
492                 array_splice($out_buf, 0, $out_buf_size - 100);
493                 $out_buf_size = 100;
494         }
495
496         $code = join('', $out_buf);
497
498         if ($time) {
499                 one_item(_("Runtime"), $time);
500         }
501
502         echo "</table>";
503
504         if (!empty($toc)) {
505                 echo "<h2>"._("Toc:")."</h2>";
506                 echo "<ul class=toc>";
507                 foreach ($toc as $i => $section) {
508                         $id = str_replace(" ", "-", $section);
509                         echo "<li><a href=#{$id}>{$section}</a></li>";
510                         echo "<code>{$err[$i]}</code>";
511                 }
512                 echo "</ul>";
513         }
514
515         echo "<h2>"._("Content:")."</h2>";
516
517         start_pre();
518         echo $code;
519         end_pre();
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>
528            [<a href="<?php echo "$bu&amp;action=qa"
529                 ?>"><?=_("View rpm -qa of builder")?></a>]
530           </td>
531          </tr>
532         </table>
533 <?php
534
535 }
536
537 function 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";
549         echo "# date   : " .
550                         date("Y/m/d H:i:s", filemtime("$root_directory/$f")) . "\n";
551
552         $filter = get_filter($f);
553
554         $cmd = "$filter '$root_directory/$f'";
555         $fd = popen($cmd, "r");
556         fpassthru($fd);
557         pclose($fd);
558 }
559
560 function 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";
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         }
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\" ".
589              "alt=\""._("Powered by PLD Linux")."\" border=\"0\" /></a><br />\n" .
590              "<small>(c) 2002-". date("Y") . " ". 
591              "<a href=\"mailto:feedback@pld-linux.org\">PLD&nbsp;Team</a><br />\n".
592              '$Revision: 1.37 $'.
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",
600                      "/dev/null", "/dev/zero", "/dev/drzewo",
601                      "Leppe'", "matrix", "Neo", "PDP-11",
602                      "Ken", "GNU antilope", "PDP-7", "ITS", "Multics",
603                      "foobarbaz", "ed", "Joe", "Unix conspiracy",
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",
613          "synergy", "six Cray XMT Supercomputers"
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
626         echo "<div align=\"center\"><small>";
627                 echo "Your IP: " . $_SERVER['REMOTE_ADDR'];
628         echo "</small></div>";
629
630         if (isset($dist) && isset($arch)) {
631         echo "<form action=\"index.php\" method=\"post\">";
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
641 function get_qa()
642 {
643     global $dist, $arch;
644
645         if (!isset($dist) || !isset($arch))
646                 return false;
647         $addr = "http://ftp1.pld-linux.org/dists/$dist/.stat/builder/$dist/rpmqa-$arch.txt";
648     return fopen("$addr", "r");
649 }
650
651 function 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) {
664                         if (stristr($s, "Query done at:")) {
665                                 echo "rpmqa database from " . strstr($s, ":") . "\n";
666                                 continue;
667                         }
668
669                         if (stristr($s, $str))
670                                 echo $s;
671                 }
672                 echo "\n/* EOF */";
673         }
674         end_pre();
675 }
676
677 function dump_qa($plain)
678 {
679         global $url, $dist, $arch;
680
681         $f = get_qa();
682
683         if ($plain) {
684                 header("Content-type: text/plain");
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
705 function 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 */
720   if (!isset($_POST["n2"])) $_POST["n2"] = "";
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
726   echo "<form action=\"index.php?action=adv_search\" method=\"post\">";
727
728   echo "<div align=\"center\">";
729   echo "<table border=\"0\">\n";
730   echo "<tr>\n";
731   echo "<td>"._("Package name")."</td>\n";
732   echo "<td><input type=\"text\" size=\"20\" name=\"n2\" value=\"". $_POST["name"] ."\"/></td>\n";
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
756   $i = 1;
757   foreach ($addr as $dist => $ddist) {
758     foreach ($ddist as $arch) {
759     echo "<tr>\n";
760     $name="as0_".$i;
761     if (!isset($_POST["$name"])) {
762         $check = " ";
763     } else {
764         $check=" checked='checked'";
765     }
766     echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">". "$dist/$arch" ."</label></td>\n";
767     $name="as1_".$i;
768     if (!isset($_POST["$n2"])) {
769         $check = " ";
770     } else {
771         $check=" checked='checked'";
772     }
773     echo "<td><input name=\"$name\" id=\"$name\" type=\"checkbox\"$check /><label for=\"$name\">". "$dist/$arch" ."</label></td>\n";
774     echo "</tr>\n";
775     $i++;
776     }
777   }
778         
779   echo "<tr>\n";
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>";
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"])
787   if (($_POST["n2"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") ||
788     ($_POST["size1"]!="") || ($_POST["size2"]!=""))
789   {
790         $query = "SELECT log_id, dist, arch, ok, name, size, mtime, id FROM logs WHERE 1 ";
791         if ($_POST["n2"] != "") {
792                 $n = addslashes($_POST["n2"]);
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 (";
818   $i = 1;
819   foreach ($addr as $dist => $ddist) {
820     foreach ($ddist as $arch) {
821       for ($j = 0; $j < 2; $j++) {
822                           if (isset($_POST["as" . $j . "_" .$i])) {
823                                 $query .= "$or (dist = '$dist' AND arch = '$arch' AND ok = $j)";
824                                 $or = " OR ";
825                         }
826                 }
827     $i++;
828     }
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 ";
846
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"];
873       $name_url = urlencode($name);
874       $id = $row["id"];
875                         $f = $name;
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"];
896                         $u = "$url?dist=$dist&amp;arch=$arch&amp;name=$name_url&amp;ok=$ok&amp;id=$id";
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   }
953   echo "</div></form>\n";
954 }
955
956 function 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... -->
964 <a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?>
965  <a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a>.</p>
966 </td><td width="20%">&nbsp;</td></tr>
967 </table>
968 <?php
969 }
970
971 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
972 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
973 header("Cache-Control: no-cache, must-revalidate");
974 header("Pragma: no-cache");
975
976 //phpinfo();
977 if ($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 7.212528 seconds and 3 git commands to generate.