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