]> git.pld-linux.org Git - projects/buildlogs.git/commitdiff
- buildlogs engine using MySQL database
authorwitekfl <witekfl@pld-linux.org>
Tue, 3 Oct 2006 18:32:27 +0000 (18:32 +0000)
committerwitekfl <witekfl@pld-linux.org>
Tue, 3 Oct 2006 18:32:27 +0000 (18:32 +0000)
PRZECZYTAJ.TO [new file with mode: 0644]
init.sql [new file with mode: 0644]
obsolete/buildlogs.sql/PRZECZYTAJ.TO [new file with mode: 0644]
obsolete/buildlogs.sql/addlog.php [new file with mode: 0644]
obsolete/buildlogs.sql/index.php [new file with mode: 0644]
obsolete/buildlogs.sql/init.sql [new file with mode: 0644]
obsolete/buildlogs.sql/migration.php [new file with mode: 0644]

diff --git a/PRZECZYTAJ.TO b/PRZECZYTAJ.TO
new file mode 100644 (file)
index 0000000..ce4e86e
--- /dev/null
@@ -0,0 +1,12 @@
+Interfejs buildlogów korzystaj±cy z bazy MySQL. Wydajniejszy od obecnego
+enginu. Najpierw nale¿y utworzyæ bazê SQL (skrypt init.sql).
+Nastêpnie wype³niæ bazê danymi. S³u¿y do tego skrypt migration.php. Wymaga on
+do dzia³ania php-cli, a tak¿e zwiêkszenia memory_limit dla skryptów PHP.
+Wykonanie tego skryptu zajmuje du¿o czasu. U mnie dla 200000 rekordów twa³o to
+1,5 h. Pó¼niej baza ju¿ ¶miga.
+Nastêpnie mo¿na umie¶ciæ skrypt index.php na serwerze. Jest on kompatybilny
+wstecz z poprzedni± wersj±. Odno¶niki z kolejek budowania bêd± dzia³aæ.
+Aby uaktualniaæ dane w bazie nale¿y przy ka¿dym nowym logu uruchomiæ skrypt
+addlog.php z parametrem bêd±cym pe³n± ¶cie¿k± do pliku z logiem, np.
+addlog.php /home/services/ftp/pub/pld-buildlogs/ac/i686/OK/kernel.bz2.
+U mnie to dzia³a i jest w miarê szybkie.
diff --git a/init.sql b/init.sql
new file mode 100644 (file)
index 0000000..27f6705
--- /dev/null
+++ b/init.sql
@@ -0,0 +1,82 @@
+-- MySQL dump 9.11
+--
+-- Host: localhost    Database: buildlogs
+-- ------------------------------------------------------
+-- Server version      4.0.22
+
+--
+-- Table structure for table `architectures`
+--
+CREATE DATABASE buildlogs;
+
+USE buildlogs;
+
+
+CREATE TABLE architectures (
+  arch_id tinyint(4) NOT NULL default '0',
+  name varchar(15) default NULL,
+  PRIMARY KEY  (arch_id)
+) TYPE=MyISAM;
+
+--
+-- Dumping data for table `architectures`
+--
+
+INSERT INTO architectures VALUES (0,'th/SRPMS');
+INSERT INTO architectures VALUES (1,'th/i486');
+INSERT INTO architectures VALUES (2,'th/i686');
+INSERT INTO architectures VALUES (3,'th/athlon');
+INSERT INTO architectures VALUES (4,'th/x86_64');
+INSERT INTO architectures VALUES (5,'th/ia64');
+INSERT INTO architectures VALUES (6,'th/alpha');
+INSERT INTO architectures VALUES (7,'th/ppc');
+INSERT INTO architectures VALUES (8,'th/sparc');
+INSERT INTO architectures VALUES (9,'ac/SRPMS');
+INSERT INTO architectures VALUES (10,'ac/i386');
+INSERT INTO architectures VALUES (11,'ac/i586');
+INSERT INTO architectures VALUES (12,'ac/i686');
+INSERT INTO architectures VALUES (13,'ac/athlon');
+INSERT INTO architectures VALUES (14,'ac/amd64');
+INSERT INTO architectures VALUES (15,'ac/alpha');
+INSERT INTO architectures VALUES (16,'ac/ppc');
+INSERT INTO architectures VALUES (17,'ac/sparc');
+INSERT INTO architectures VALUES (18,'ac/sparc64');
+
+
+-- Table structure for table `logs`
+--
+
+CREATE TABLE logs (
+  log_id int(11) NOT NULL auto_increment,
+  arch_id tinyint(4) default NULL,
+  result tinyint(4) default NULL,
+  size int(11) default NULL,
+  spec_id smallint(6) default NULL,
+  mtime int(11) default NULL,
+  PRIMARY KEY  (log_id)
+) TYPE=MyISAM;
+
+
+CREATE TABLE result (
+  result_id tinyint(4) NOT NULL default '0',
+  name varchar(5) default NULL,
+  PRIMARY KEY  (result_id)
+) TYPE=MyISAM;
+
+--
+-- Dumping data for table `result`
+--
+
+INSERT INTO result VALUES (0,'FAIL');
+INSERT INTO result VALUES (1,'OK');
+
+--
+-- Table structure for table `specs`
+--
+
+CREATE TABLE specs (
+  spec_id smallint(6) NOT NULL auto_increment,
+  spec varchar(70) default NULL,
+  PRIMARY KEY  (spec_id)
+) TYPE=MyISAM;
+
diff --git a/obsolete/buildlogs.sql/PRZECZYTAJ.TO b/obsolete/buildlogs.sql/PRZECZYTAJ.TO
new file mode 100644 (file)
index 0000000..ce4e86e
--- /dev/null
@@ -0,0 +1,12 @@
+Interfejs buildlogów korzystaj±cy z bazy MySQL. Wydajniejszy od obecnego
+enginu. Najpierw nale¿y utworzyæ bazê SQL (skrypt init.sql).
+Nastêpnie wype³niæ bazê danymi. S³u¿y do tego skrypt migration.php. Wymaga on
+do dzia³ania php-cli, a tak¿e zwiêkszenia memory_limit dla skryptów PHP.
+Wykonanie tego skryptu zajmuje du¿o czasu. U mnie dla 200000 rekordów twa³o to
+1,5 h. Pó¼niej baza ju¿ ¶miga.
+Nastêpnie mo¿na umie¶ciæ skrypt index.php na serwerze. Jest on kompatybilny
+wstecz z poprzedni± wersj±. Odno¶niki z kolejek budowania bêd± dzia³aæ.
+Aby uaktualniaæ dane w bazie nale¿y przy ka¿dym nowym logu uruchomiæ skrypt
+addlog.php z parametrem bêd±cym pe³n± ¶cie¿k± do pliku z logiem, np.
+addlog.php /home/services/ftp/pub/pld-buildlogs/ac/i686/OK/kernel.bz2.
+U mnie to dzia³a i jest w miarê szybkie.
diff --git a/obsolete/buildlogs.sql/addlog.php b/obsolete/buildlogs.sql/addlog.php
new file mode 100644 (file)
index 0000000..ee5bf1e
--- /dev/null
@@ -0,0 +1,77 @@
+#!/usr/bin/php.cli
+<?php
+$user = 'mysql';
+$password = '';
+$root_directory = '/home/services/ftp/pub/pld-buildlogs';
+// parameter: argv[1] - full path to the log file.
+// Keep in sync with database
+$dist = array("ac" => 1, "th" => 2);
+$result = array("FAIL" => 0, "OK" => 1);
+$arch = array(
+       "th/SRPMS" => 0,
+       "th/i486" => 1,
+       "th/i686" => 2,
+       "th/athlon" => 3,
+       "th/x86_64" => 4,
+       "th/ia64" => 5,
+       "th/alpha" => 6,
+       "th/ppc" => 7,
+       "th/sparc" => 8,
+       "ac/SRPMS" => 9,
+       "ac/i386" => 10,
+       "ac/i586" => 11,
+       "ac/i686" => 12,
+       "ac/athlon" => 13,
+       "ac/amd64" => 14,
+       "ac/alpha" => 15,
+       "ac/ppc" => 16,
+       "ac/sparc" => 17,
+       "ac/sparc64" => 18
+);
+
+
+preg_match("|$root_directory/(.*/.*)/(.*)/(.*)\.bz2|", $argv[1], $matches);
+
+$arch_name = $matches[1];
+if (!array_key_exists($arch_name, $arch)) exit;
+else $arch_id = $arch[$arch_name];
+
+$result_name = $matches[2];
+if (!array_key_exists($result_name, $result)) exit;
+else $result_id = $result[$result_name];
+
+$spec_name = $matches[3];
+if ($spec_name == '') exit;
+
+$spec_name = mysql_escape_string($spec_name);
+$size = filesize($argv[1]);
+$mtime = filemtime($argv[1]);
+
+mysql_connect('localhost', "$user", "$password") or die ("connect error" . mysql_error());
+mysql_select_db("buildlogs");
+$row = mysql_query("SELECT spec_id FROM specs WHERE spec='$spec_name' LIMIT 1") or die("SELECT 1" . mysql_error());
+if (mysql_num_rows($row) == 0) {
+       mysql_query("INSERT INTO specs(spec) VALUES ('$spec_name')") or die("INSERT 1" . mysql_error());
+       $row = mysql_query("SELECT spec_id FROM specs WHERE spec='$spec_name' LIMIT 1") or die("SELECT 1" . mysql_error());
+       if (mysql_num_rows($row) == 0) {
+               mysql_close($link);
+               exit;
+       }
+}
+$linia = mysql_fetch_object($row);
+$spec_id = $linia->spec_id;
+mysql_free_result($row);
+
+$row = mysql_query("SELECT log_id FROM logs WHERE spec_id=$spec_id AND arch_id=$arch_id LIMIT 1");
+if (mysql_num_rows($row) == 0) {
+       mysql_query("INSERT INTO logs(arch_id, spec_id, result, size, mtime) "
+       . "VALUES ($arch_id, $spec_id, $result_id, $size, $mtime)") or die("INSERT 2" . mysql_error());
+} else {
+       $linia = mysql_fetch_object($row);
+       mysql_query("UPDATE logs SET result = $result_id, size = $size, mtime = $mtime WHERE log_id = $linia->log_id")
+       or die ("UPDATE" . mysql_error());
+}
+mysql_free_result($row);
+mysql_close();
+echo "OK $linia->log_id $argv[1]\n";
+?>
diff --git a/obsolete/buildlogs.sql/index.php b/obsolete/buildlogs.sql/index.php
new file mode 100644 (file)
index 0000000..04798bf
--- /dev/null
@@ -0,0 +1,1095 @@
+<?php
+$buildlogs_server = "buildlogs.pld-linux.org";
+$url = "index.php";
+$addr = array(
+       "th/SRPMS",
+       "th/i486",
+       "th/i686",
+       "th/athlon",
+       "th/x86_64",
+       "th/ia64",
+       "th/alpha",     
+       "th/ppc",
+       "th/sparc",
+       "ac/SRPMS",
+       "ac/i386",
+       "ac/i586",
+       "ac/i686",
+       "ac/athlon",
+       "ac/amd64",
+       "ac/alpha",     
+       "ac/ppc",
+       "ac/sparc",
+       "ac/sparc64"/*,
+       "/ra/i386",
+       "/ra/i586",
+       "/ra/i686",
+       "/ra/alpha",    
+       "/ra/ppc",
+       "/ra/sparc",
+       "/nest/i486",
+       "/nest/i686",
+       "/nest/alpha",
+       "/nest/ppc"
+*/
+);
+$qa_addr = array(
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-SRPMS.txt",
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-i486.txt",
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-i686.txt",
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-athlon.txt",
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-x86_64.txt",
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-ia64.txt",
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-alpha.txt",   
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-ppc.txt",
+       "http://ftp.pld-linux.org/dists/th/.stat/builder/th/rpmqa-sparc.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-SRPMS.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-i386.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-i586.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-i686.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-athlon.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-amd64.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-alpha.txt",   
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-ppc.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-sparc.txt",
+       "http://ftp.pld-linux.org/dists/ac/.stat/builder/ac/rpmqa-sparc64.txt"/*,
+       "http://ftp.pld-linux.org/dists/ra/.stat/builder/liniowiec/rpmqa-ra-i386.txt",
+       "http://ftp.pld-linux.org/dists/ra/.stat/builder/liniowiec/rpmqa-ra-i586.txt",
+       "http://ftp.pld-linux.org/dists/ra/.stat/builder/liniowiec/rpmqa-ra-i686.txt",
+       "http://ftp.pld-linux.org/dists/ra/.stat/builder/fly/rpmqa-ra-alpha.txt",       
+       "http://ftp.pld-linux.org/dists/ra/.stat/builder/an2/rpmqa-ra-ppc.txt",
+       "http://ftp.pld-linux.org/dists/ra/.stat/builder/ares/rpmqa-ra-sparc.txt",
+       "http://ftp.nest.pld-linux.org/.stat/builder/kenny/rpmqa-nest-i486.txt",
+       "http://ftp.nest.pld-linux.org/.stat/builder/kenny/rpmqa-nest-i686.txt",
+       "http://ftp.nest.pld-linux.org/.stat/builder/alpha/rpmqa-nest-alpha.txt",
+       "http://ftp.nest.pld-linux.org/.stat/builder/an2/rpmqa-nest-ppc.txt"
+*/
+);
+$local = 1; /* $local=0 for FTP */ 
+$root_directory = "/home/services/ftp/pub/pld-buildlogs";
+$ftp_conn = 0;
+/* It should be set */
+
+$langs["en_US"]["charset"]="ISO-8859-1";
+$langs["pl_PL"]["charset"]="ISO-8859-2";
+
+$lang="en_US";
+if (isset($_SERVER["HTTP_ACCEPT_LANGUAGE"]))
+{
+  $rows=explode(";",$_SERVER["HTTP_ACCEPT_LANGUAGE"]);
+  $rows=explode(",",$rows[0]);
+  $lang_detected=rtrim($rows[0]);
+} else if (preg_match("/opera/i",$_SERVER["HTTP_USER_AGENT"]))
+{
+  $lang_detected=preg_replace("/.*\[(.*)\].*/i","\\1",$_SERVER["HTTP_USER_AGENT"]);
+}
+
+// FIXME - some array
+$lang_detected=preg_replace("/^pl$/i","pl_PL",$lang_detected);
+
+if (isset($lang_detected) && isset($langs[$lang_detected]))
+{
+  $lang=$lang_detected;
+}
+
+if (isset($_GET["lang"]))$_SESSION["lang"]=$_GET["lang"];
+if (isset($_SESSION["lang"]))$lang=$_SESSION["lang"];
+
+putenv("LANG=$lang");
+setlocale(LC_ALL,$lang);
+bindtextdomain("messages","locale");
+textdomain("messages");
+
+if (isset($_GET["idx"]))$idx=(int)$_GET["idx"];
+if (isset($_GET["dist"]))
+{
+       $dist=$_GET["dist"];
+       if (isset($_GET["arch"]))
+       {
+               $arch=$_GET["arch"];
+               for ($i = 0; $i < count($addr); $i++)
+               {
+                       if ($addr[$i]==$dist."/".$arch)
+                               $idx=$i;
+               }
+       }
+}
+if (isset($_GET["ok"]))$ok=(int)$_GET["ok"];
+else $ok="";
+if (isset($_GET["ns"]))$ns=(int)$_GET["ns"];
+else $ns="";
+if (isset($_GET["cnt"]))$cnt=(int)$_GET["cnt"];
+if (isset($_GET["action"]))$action=$_GET["action"];
+else $action="";
+if (isset($_GET["off"]))$off=(int)$_GET["off"];
+if (isset($_GET["id"]))$id=$_GET["id"];
+if (isset($_GET["log"]))$log=(int)$_GET["log"];
+
+if (isset($_POST["str"]))$str=$_POST["str"];
+if (isset($_POST["idx"]))$idx=$_POST["idx"];
+if (isset($_POST["action"]))$action=$_POST["action"];
+
+function myheader()
+{
+echo '<' . '?xml version="1.0" encoding="' . _("ISO-8859-1") .'"?' . ">\n";
+echo '<' . '?xml-stylesheet href="#internalStyle" type="text/css"?' . ">\n";
+?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+  <title>PLD Build Logs</title>
+  <?php echo '<meta http-equiv="Content-type" content="text/html; charset=' . _("ISO-8859-1") .'"/>' ."\n";?>
+  <style type="text/css"><!--
+A { text-decoration: none; }
+A:hover { text-decoration: underline; }
+H1 { font-family: arial,helvetica,sans-serif; 
+     font-size: 20pt; 
+     font-weight: bold;}
+H2 { font-family: arial,helvetica,sans-serif; 
+     font-size: 18pt; 
+     font-weight: bold;}
+BODY,TD { font-family: arial,helvetica,sans-serif; 
+          font-size: 13pt; }
+TH { font-family: arial,helvetica,sans-serif; 
+     font-size: 13pt; 
+     font-weight: bold; }
+//-->
+</style>
+ </head>
+ <!-- Diffrent color for visited link doesn't make much sense here...
+      this page is autogenerated and it might be misleading after some
+      build log changes. -->
+ <body bgcolor="#ffffff" text="#000000" link="#5f26cd" vlink="#5f26cd">
+<?php
+}
+
+function start_pre()
+{
+       echo "<table cellpadding=\"10\"><tr><td bgcolor=\"#000000\">".
+               "<font color=\"#cccccc\"><pre style=\"width: 2048px;overflow: scroll\">";
+}
+
+function end_pre()
+{
+       echo "</pre></font></td></tr></table>\n";
+}
+
+function trailer()
+{
+       echo "</body></html>";
+}
+
+
+function mydie($msg)
+{
+       echo "Fatal error: $msg";
+}
+
+function open_ftp($pidx="", $pok="")
+{
+       global $idx, $addr, $buildlogs_server, $ok;
+       global $ftp_conn, $big_url, $url, $ns;
+       global $off, $cnt;
+       
+       if ($pidx==="")$pidx=$idx;
+       if ($pok==="")$pok=$ok;
+
+       if (!isset($pidx) || !isset($addr[$pidx]))
+               return false;
+
+       if ($pok != 1)
+               $pok = 0;
+       if ($ns != 1)
+               $ns = 0;
+
+       if ($pok == 1) {
+               $a = "$addr[$pidx]/OK";
+       } else {
+               $a = "$addr[$pidx]/FAIL";
+       }
+
+       if (!isset($off))
+               $off = 0;
+       if (!isset($cnt))
+               $cnt = 16;
+
+       $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
+
+       $ftp = ftp_connect($buildlogs_server);
+
+       if ($ftp == false) {
+               mydie(_("cannot connect to")." $buildlogs_server");
+               return false;
+       }
+
+       if (ftp_login($ftp, "anonymous", 
+                     "buildlogs-iface@pld-linux.org") == false) {
+               ftp_quit($ftp);
+               mydie(_("cannot ftp login to")." $buildlogs_server");
+               return false;
+       }
+
+       $list = ftp_nlist($ftp, $a);
+       if ($list == false) {
+               ftp_quit($ftp);
+               mydie(_("cannot list")." $a");
+               return false;
+       }
+
+       $ftp_conn = $ftp;
+
+       return $list;
+}
+
+function directory_list($pidx="",$pok="")
+{
+       global $idx, $addr, $buildlogs_server, $ok;
+       global $root_directory, $big_url, $url, $ns;
+       global $off, $cnt;
+
+       if ($pidx==="")$pidx=$idx;
+       if ($pok==="")$pok=$ok;
+       if (!isset($pidx) || !isset($addr[$pidx]))
+               return false;
+
+       if ($pok != 1)
+               $pok = 0;
+       if ($ns != 1)
+               $ns = 0;
+
+       if ($pok == 1) {
+               $a = "$addr[$pidx]/OK";
+       } else {
+               $a = "$addr[$pidx]/FAIL";
+       }
+
+       if (!isset($off))
+               $off = 0;
+       if (!isset($cnt))
+               $cnt = 16;
+
+       $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
+
+       $dir = opendir("$root_directory/$a");
+       $i = 0;
+       $list = array ();
+       while ($file = readdir($dir)) {
+               if (($file != ".") && ($file != "..")) {
+                       $list[$i] = array("$a/$file", filemtime("$root_directory/$a/$file"));
+                       $i++;
+               }
+       }
+       closedir($dir);
+       return $list;
+}
+
+function list_logs()
+{
+       global $idx, $addr, $ok;
+       global $ftp_conn, $big_url, $ns, $qa_addr;
+       global $off, $cnt, $local, $root_directory, $url;
+/*
+       if ($local) {
+               $list = directory_list();
+       } else {
+               $list = open_ftp();
+       }
+       if ($list == false)
+               return;
+*/
+       $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
+
+       if ($ok == 1) {
+               echo "<h1>"._("Listing of")." $addr[$idx]/OK "
+                       ."(<a href=\"$big_url&amp;ok=0\">"._("fail")."</a>)</h1>\n";
+       } else {
+               echo "<h1>"._("Listing of")." $addr[$idx]/FAIL "
+                       ."(<a href=\"$big_url&amp;ok=1\">"._("ok")."</a>)</h1>\n";
+       }
+
+       echo "<div align=\"center\"><table cols=\"4\" border=\"0\" cellspacing=\"1\" ".
+               "cellpadding=\"3\" bgcolor=\"#000000\" width=\"90%\">\n";
+       echo "<tr><th bgcolor=\"#CCCCFF\" align=\"right\" width=\"1%\">"._("No.")."</th>".
+                "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"80%\">"._("Log File").
+                       "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
+                "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
+                "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
+                        "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
+                "</tr>";
+/*
+       function cmp($f1, $f2) {
+               global $ftp_conn, $root_directory, $local;
+               if ($local)
+                       return $f2[1] - $f1[1];//filemtime("$root_directory$f2") - filemtime("$root_directory$f1");
+               return ftp_mdtm($ftp_conn, $f2) - ftp_mdtm($ftp_conn, $f1);
+       }
+
+       function cmp2($f1, $f2) {
+               return strcmp($f1[0], $f2[0]);
+       }
+
+       if ($ns != 1) {
+               $ns = 0;
+               usort($list, "cmp");
+       } else {
+               usort($list, "cmp2");
+       }
+*/
+       if ($ns != 1) $ns = 0;
+       if (!isset($idx)) $idx = 0;
+       if (!isset($ok)) $ok = 0;
+       if (!isset($off)) $off = 0;
+       if (!isset($cnt)) $cnt = 50;
+       if ($ns == 0) $order = "logs.mtime DESC";
+       else $order = "specs.spec";
+
+       $query = "SELECT specs.spec, logs.log_id, logs.mtime, logs.size FROM specs, logs WHERE "
+       . "specs.spec_id = logs.spec_id AND logs.arch_id = $idx AND logs.result = $ok ORDER BY $order LIMIT $cnt OFFSET $off";
+
+       mysql_connect("localhost", "mysql", "") or die(mysql_error());
+       mysql_select_db("buildlogs") or die(mysql_error()); 
+       $result = mysql_query("$query") or die(mysql_error());
+       $count = mysql_num_rows($result);
+
+       $now = time();
+       for ($i = $off; $i < $count + $off; $i++) {
+               $row = mysql_fetch_assoc($result);
+               $f = $row["spec"];
+               $t = $now - $row["mtime"];
+               $s = $row["size"];
+               $h = $row["log_id"];
+/*             
+               if (!isset($filename))
+                       continue;
+               $h = bin2hex(mhash(MHASH_MD5, $filename));
+               $f = preg_replace("/.*\/([^\/]*)$/", "\\1", $filename);
+               $f = preg_replace("/\.(bz2|gz)$/", "", $f);
+               if ($local) {
+                       $s = filesize("$root_directory/$filename");
+                       $t = $now - $list[$i][1];
+               } else {
+                       $s = ftp_size($ftp_conn, $list[$i]);
+                       $t = $now - ftp_mdtm($ftp_conn, $list[$i]);
+               }
+*/
+               $t /= 60;
+               if ($t >= 60) {
+                       $t /= 60;
+                       if ($t >= 24) {
+                               $t /= 24;
+                               $t = round($t);
+                               $t = $t . "&nbsp;" . ngettext("day","days",$t);
+                       } else {
+                               $t = round($t);
+                               $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
+                       }
+               } else {
+                       $t = round($t);
+                       $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
+               }
+//             $u = "$big_url&amp;off=$off&amp;id=$h";
+               $u = "$url?log=$h";
+               echo "<tr><td bgcolor=\"#CCCCCC\" align=\"right\">".($i+1).".</td>".
+                    "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ".
+                    "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
+                     "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
+                    "</td><td bgcolor=\"#CCCCCC\" align=\"right\">".
+                    "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n";
+       }
+       echo "</table></div>\n";
+
+       $backarr = "&lt;&lt;&lt;&nbsp;";
+       $back = _("Page back");
+       $forward = _("Page forward");
+       $forwardarr = "&nbsp;&gt;&gt;&gt;";
+
+       echo "<p><table width=\"90%\" align=\"center\"><tr><td align=\"left\" width=\"1%\">";
+
+       if ($off > 0) {
+               $noff = $off - $count;
+               if ($noff < 0)  
+                       $noff = 0;
+               $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
+               echo "$hrefurl$backarr</a></td><td align=\"left\">$hrefurl$back</a>";
+       } else {
+               echo "$backarr</td><td align=\"left\">$back";
+       }
+
+       echo "</td>\n<td align=\"center\">";
+
+       if ($qa_addr[$idx] != "") {
+               echo "[<a href=\"$big_url&amp;action=qa\">"._("View <quot>rpm&nbsp;-qa</quot> of builder")."</a>]";
+       } else {
+               echo "&nbsp;";
+       }
+
+       echo "</td>\n<td align=right>";
+//     if ($off + $cnt < count($list)) {
+       if ($cnt == $count) {
+               $noff = $off + $cnt;
+               if ($noff < 0)  
+                       $noff = 0;
+               $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
+               echo "$hrefurl$forward</a></td><td align=right width=1%>$hrefurl$forwardarr</a>";
+       } else {
+               echo "$forward</td><td align=right width=1%>$forwardarr";
+       }
+       echo "</td>\n</tr></table></p>";
+       mysql_free_result($result);
+       mysql_close();
+//     if ($local == 0) {
+//             ftp_quit($ftp_conn);
+//             $ftp_conn = 0;
+//     }
+}
+
+function file_name_log($l)
+{
+       mysql_connect("localhost", "mysql", "") or die(mysql_error());
+       mysql_select_db("buildlogs") or die(mysql_error());
+       $query = "SELECT a.name, result.name as res, specs.spec FROM specs, architectures a, result, logs WHERE "
+       . "logs.log_id = $l AND specs.spec_id = logs.spec_id AND a.arch_id = logs.arch_id AND "
+       . "result.result_id = logs.result LIMIT 1";
+       $result = mysql_query($query) or die(mysql_error());
+       if (mysql_num_rows($result) == 1) {
+               $row = mysql_fetch_assoc($result);
+               $f = $row["name"] . "/" . $row["res"] . "/" . $row["spec"] . ".bz2";
+       } else {
+               $f = false;
+       }
+       mysql_free_result($result);
+       mysql_close();
+       return $f;
+}
+
+function file_name()
+{
+       global $idx, $addr, $ok;
+       global $ftp_conn, $root_directory, $big_url, $ns, $id;
+       global $buildlogs_server, $local, $log;
+
+       if (isset($log)) return file_name_log($log);
+       if (!isset($id))
+               return false;
+       if ($local) {
+               $list = directory_list();
+       } else {
+               $list = open_ftp();
+       }
+       if ($list == false)
+               return false;
+
+       $f = false;
+       for ($i = 0; $i < count($list); $i++) {
+               $h = bin2hex(mhash(MHASH_MD5, $list[$i][0]));
+               if ($h == $id) {
+                       $f = $list[$i][0];
+                       break;
+               }
+       }
+
+       if ($f == false) {
+               mydie(_("cannot find specified file:")." $id");
+               if ($local == 0)
+                       ftp_quit($ftp_conn);
+               return false;
+       }
+
+       return $f;
+}
+
+function dump_log($tail)
+{
+       global $idx, $addr, $ok, $url;
+       global $ftp_conn, $root_directory, $big_url, $ns, $id, $cnt, $off;
+       global $buildlogs_server, $local, $qa_addr, $log;
+
+       $f = file_name();
+
+       if ($f == false)
+               return;
+
+       $df = preg_replace("/.*\/([^\/]*)$/", "\\1", $f);
+       $df = preg_replace("/\.(bz2|gz)$/", "", $df);
+
+       echo "<h1>$df</h1>";
+
+       echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"1\" bgcolor=\"#000000\">";
+
+       function one_item($h, $t) {
+               echo "<tr><td bgcolor=\"#ccccff\">$h:</td>".
+                        "<td bgcolor=\"#cccccc\">$t</td></tr>";
+       }
+
+       function href($h, $c) {
+               return "<a href=\"$h\">$c</a>";
+       }
+
+       one_item(_("Status"), ($ok == 1 ?  
+                               "<font color=\"green\"><b>"._("OK")."</b></font>" : 
+                               "<font color=\"red\"><b>"._("Failed")."</b></a>"));
+       one_item(_("Source URL"), 
+                href("ftp://$buildlogs_server/$f", 
+                     "ftp://$buildlogs_server/$f"));
+
+       $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
+       $bu = "$big_url&amp;off=$off";
+
+       one_item(_("text/plain URL"), 
+                href(isset($log) ? "$url?log=$log&amp;action=text" : "$bu&amp;id=$id&amp;action=text",
+                     _("View!")));
+       if ($tail) {
+               one_item(_("full text"), 
+                        href(isset($log) ? "$url?log=$log" : "$bu&amp;id=$id",
+                             "View!"));
+       }
+
+       if ($qa_addr[$idx] != "") {
+               one_item(_("rpm -qa of builder"), href("$bu&amp;action=qa", _("View!")));
+       } else {
+               one_item(_("rpm -qa of builder"), _("Not available"));
+        }
+       if ($local) {
+               one_item("Data", date("Y/m/d H:i:s", filemtime("$root_directory/$f")));
+       } else {
+               one_item("Data", date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)));
+       }
+       /*
+       echo "<tr><td>Here:</td><td>" . 
+               "<a href=\"$url?idx=$idx&amp;ok=$ok&amp;id=$id\">".
+               "http://" . getenv("SERVER_NAME") .
+               getenv("SCRIPT_NAME") . "?idx=$idx&amp;ok=$ok&amp;id=$id</a>" .
+            "</td></tr>"; */
+
+       echo "</table><h2>"._("Content:")."</h2>";
+
+       if ($local == 0) {
+               ftp_quit($ftp_conn);
+               $ftp_conn = 0;
+       }
+
+
+       # what can I say beside PHP suxx? how the fuck should I create
+       # bidirectional pipe? gotta use wget
+
+       if (preg_match("/\.bz2$/", $f)) {
+               $filter = "bzcat";
+       } elseif (preg_match("/\.gz$/", $f)) {
+               $filter = "zcat";
+       } else {
+               $filter = "cat";
+       }
+
+       if ($local) {
+               $cmd = "$filter $root_directory/$f";
+       } else {
+               $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
+       }
+       if ($tail)
+               $cmd = "$cmd | tail -n 100";
+       $fd = popen($cmd, "r");
+       start_pre();
+       while (($s = fgets($fd, 102400)) != false) {
+               if (strlen($s) > 800) {
+                       $s = chunk_split($s, 800, "\n    ");
+                       $s = trim($s);
+               }
+               $s = htmlspecialchars($s);
+               echo $s;
+       }
+       end_pre();
+       pclose($fd);
+
+?>
+       <table width="100%">
+        <tr>
+         <td align=left>
+          [<a href="<?php echo $bu; ?>"><?=_("Back to list of logs")?></a>]
+         </td>
+         <td align=right>
+          [<a href="<?php echo "$bu&amp;action=qa" 
+               ?>"><?=_("View rpm -qa of builder")?></a>]
+         </td>
+        </tr>
+       </table>
+<?php
+
+}
+
+function dump_text()
+{
+       global $ftp_conn, $root_directory;
+       global $buildlogs_server, $local;
+
+       header("Content-type: text/plain");
+
+       $f = file_name();
+       if ($f == false)
+               return;
+
+       echo "# src  : ftp://$buildlogs_server/$f\n";
+       if ($local) {
+               echo "# date   : " .  
+                       date("Y/m/d H:i:s", filemtime("$root_directory/$f")) . "\n";
+       } else {
+               echo "# date   : " .  
+                       date("Y/m/d H:i:s", ftp_mdtm($ftp_conn, $f)) . "\n";
+               ftp_quit($ftp_conn);
+               $ftp_conn = 0;
+       }
+
+       if (preg_match("/\.bz2$/", $f)) {
+               $filter = "bzcat";
+       } elseif (preg_match("/\.gz$/", $f)) {
+               $filter = "zcat";
+       } else {
+               $filter = "cat";
+       }
+
+       if ($local) {
+               $cmd = "$filter $root_directory/$f";
+       } else {
+               $cmd = "wget -q -O - ftp://$buildlogs_server$f 2>&1 | $filter 2>&1";
+       }
+       $fd = popen($cmd, "r");
+       while (($s = fgets($fd, 1000)) != false) {
+               echo $s;
+       }
+       pclose($fd);
+}
+
+function list_archs()
+{
+       global $addr, $url, $idx, $cnt,$ok,$ns;
+
+       if (!isset($cnt))
+               $cnt = 50;
+
+       $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
+
+       echo "<table width=\"100%\" border=\"0\">\n";
+       echo "<tr><td bgcolor=\"#cccccc\" nowrap=\"nowrap\">"._("Failed")."</td><td bgcolor=\"#cccccc\">"._("Ok")."</td></tr>\n";
+       for ($i = 0; $i < count($addr); $i++)
+               echo "<tr><td nowrap=\"nowrap\">".
+                    "<a href=\"$url?idx=$i&amp;ok=0&amp;cnt=$cnt\">$addr[$i]</a></td><td nowrap=\"nowrap\">".
+                    "[<a href=\"$url?idx=$i&amp;ok=1&amp;cnt=$cnt\">OK</a>]</td>".
+                    #"<td>[<a href=\"$url?idx=$i&amp;action=qa\">qa</a>]</td>".
+                    "</tr>\n";
+       echo "</table><hr />\n";
+       
+       echo "<div align=\"center\">";
+       echo "<a href=\"$big_url&amp;action=adv_search\">"._("Advanced Search")."</a><br />\n";
+       
+       echo "<a href=\"$url\">main()</a><hr />\n";
+       echo "<a href=\"http://www.pld-linux.org/\"><img src=\"powpld.png\" ".
+               "alt=\""._("Powered by PLD Linux")."\" border=\"0\" /></a><br />\n" .
+            "<small>(c) 2002 ".
+            "<a href=\"mailto:feedback@pld-linux.org\">PLD&nbsp;Team</a><br />\n".
+            '$Revision: 1.88 $'.
+            "</small></div>\n";
+
+       # smile ;)
+       echo "<div align=\"center\"><small>";
+       $pow = array("vim", "php", "brain", "power", "electricity",
+                    "coffee", "ufo", "penguin", "GNOME", "ELF", "DWARF",
+                    "voodoo magic", "Linux", "x-files", "X", "foobar",
+                    "/dev/null", "/dev/zero", "/dev/drzewo", 
+                    "Leppe'", "matrix", "Neo", "PDP-11",
+                    "Ken", "GNU antilope", "PDP-7", "ITS", "Multics",
+                    "foobarbaz", "ed", "Joe", "Unix conspiracy", 
+                    "overclock", "The Right Thing",
+                    "The Bad Thing", "Star Treck", "NSA", "NASA",
+                    "achelon", "VAX", "Real Programmer",
+                    "Real Operating System", "Real Computer",
+                    "computron", "bogon", "quantum bogodynamics",
+                    "BOFH", "/dev/ill", "nasi tu byli",
+                    "Paranoid Android", "Lunatic Corp", "Parallel thinking",
+                    "sfistak", "Linus", "The Golden Path", "Dark Side of the Force",
+                    "Przewodniczacego Lepper-a", "KDE", "Microsoft Windows 2003", "MySQL"
+                    # feel free to add sth if you change this file ;)
+                    );
+       echo _("Powered by")." ";
+       $max = 1;
+       for ($i = 0; $i < $max; $i++) {
+               $x = rand(0, count($pow) - 1);
+               if ($pow[$x] == "") $i--;
+               else echo $pow[$x] . ($i == $max - 1 ? "." : ", ");
+               $pow[$x] = "";
+       }
+       echo "</small></div>";
+
+       global $qa_addr;
+
+       if (isset($qa_addr[$idx]) && $qa_addr[$idx] != "") {
+       echo "<form action=\"index.php\" method=\"post\">";
+       echo "<input type=\"hidden\" name=\"idx\" value=\"$idx\" />";
+       echo "<input type=\"hidden\" name=\"action\" value=\"sqa\" />";
+       echo "<input type=\"text\" size=\"14\" name=\"str\" /><br />";
+       echo "<input type=\"submit\" name=\"submit\" value=\""._("Search rpmqa!")."\" />";
+       echo "</form>";
+       }
+}
+
+function get_qa()
+{
+       global $idx, $qa_addr;
+
+       if (!isset($idx) || !isset($qa_addr[$idx]))
+               return false;
+
+       $a = $qa_addr[$idx];
+
+       if ($qa_addr[$idx] == "")
+               return false;
+       else
+               return fopen("$qa_addr[$idx]", "r");
+}
+
+function search_qa()
+{
+       global $url, $idx, $qa_addr, $str;
+
+       $f = get_qa();
+       echo "<h1>"._("Search results for")." '$str' "._("in")." $qa_addr[$idx]</h1>";
+
+       start_pre();
+
+       if ($f == 0) {
+               echo _("Sorry, cannot open.");
+       } else {
+               while (($s = fgets($f, 1000)) != false) {
+                       if (stristr($s, $str))
+                               echo $s;
+               }
+               echo "/* EOF */";
+       }
+       end_pre();
+}
+
+function dump_qa($plain)
+{
+       global $url, $idx, $qa_addr;
+
+       $a = $qa_addr[$idx];
+
+       $f = get_qa();
+
+       if ($plain) {
+               header("Content-type: text/plain"); 
+               echo _("# rpm -qa of")." $a\n";
+       } else {
+               echo "<h1>"._("rpm -qa of")." $a</h1>";
+               echo "<a href=\"$url?idx=$idx&amp;action=qatxt\">"._("text/plain version")."</a>";
+               start_pre();
+       }
+
+       if ($f == 0) {
+               echo _("Sorry, cannot open.");
+       } else {
+               while (($s = fgets($f, 1000)) != false) {
+                       echo $s;
+               }
+       }
+
+       if (!$plain)
+               end_pre();
+}
+
+
+function adv_search()
+{
+  global $addr, $url, $local, $_POST, $off, $cnt, $root_directory, $idx, $ok, $ns;
+
+  $big_url = "$url?idx=$idx&amp;ok=$ok&amp;ns=$ns&amp;cnt=$cnt";
+
+  echo "<form action=\"index.php?action=adv_search\" method=\"post\">";
+
+  echo "<div align=\"center\">";
+  echo "<table border=\"0\">\n";
+  echo "<tr>\n";
+  echo "<td>"._("Package name")."</td>\n";
+  echo "<td><input type=\"text\" size=\"20\" name=\"name\" value=\"".$_POST["name"]."\"/></td>\n";
+  echo "</tr>\n";
+
+  echo "<tr>\n";
+  echo "<td>"._("Days")."</td>\n";
+  echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"age1\" value=\"".$_POST["age1"]."\" /></td>\n";
+  echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"age2\" value=\"".$_POST["age2"]."\" /></td>\n";
+  echo "</tr>\n";
+
+  echo "<tr>\n";
+  echo "<td>"._("Size")."</td>\n";
+  echo "<td>"._("From").": <input type=\"text\" size=\"20\" name=\"size1\" value=\"".$_POST["size1"]."\" /></td>\n";
+  echo "<td>"._("To").": <input type=\"text\" size=\"20\" name=\"size2\" value=\"".$_POST["size2"]."\" /></td>\n";
+  echo "</tr>\n";
+
+  echo "<tr>\n";
+  echo "<td>"._("Search logs:")."</td>\n";
+  echo "</tr>\n";
+
+  echo "<tr>\n";
+  echo "<td>"._("Failed")."</td>\n";
+  echo "<td>"._("OK")."</td>\n";
+  echo "</tr>\n";
+
+  for ($i = 0; $i < count($addr); $i++)
+  {
+    echo "<tr>\n";
+    $name="as0_".$i;
+    $check=" checked=\"on\"";
+    echo "<td><input name=\"$name\" type=\"checkbox\"$check>".$addr[$i]."</input></td>\n";
+    $name="as1_".$i;
+    $check=" checked=\"on\"";
+    echo "<td><input name=\"$name\" type=\"checkbox\"$check>".$addr[$i]."</input></td>\n";
+    echo "</tr>\n";
+  }
+       
+  echo "<tr>\n";
+  echo "<td><input type=\"submit\" name=\"submit\" value=\""._("Search!")."\" /></td>";
+  echo "</tr>\n";
+
+  echo "</table>\n";
+
+//     if (isset($_POST["name"]) || isset($_POST["age1"]) || isset($_POST["age2"]) ||
+//       isset($_POST["size1"]) || isset($_POST["size2"])
+  if (($_POST["name"]!="") || ($_POST["age1"]!="") || ($_POST["age2"]!="") ||
+    ($_POST["size1"]!="") || ($_POST["size2"]!=""))
+  {
+       $query = "SELECT specs.spec, logs.mtime, logs.arch_id, logs.result, logs.log_id, a.name as arch, logs.size, "
+       . "result.name as res FROM specs, logs, "
+       . "architectures a, result WHERE specs.spec_id = logs.spec_id AND logs.arch_id = a.arch_id AND "
+       . "logs.result = result.result_id ";
+       if ($_POST["name"] != "") {
+               $n = mysql_escape_string($_POST["name"]);
+               $query .= "AND spec LIKE '$n%' ";
+       }
+       $now = time();
+
+       if ($_POST["age1"] != "") {
+               $age = $now - (int)$_POST["age1"] * 24 * 3600;
+               $query .= "AND mtime > $age ";
+       }
+
+       if ($_POST["age2"] != "") {
+               $age = $now - (int)$_POST["age2"] * 24 * 3600;
+               $query .= "AND mtime < $age ";
+       }
+
+       if ($_POST["size1"] != "") {
+               $size = (int)$_POST["size1"];
+               $query .= "AND size > $size ";
+       }
+
+       if ($_POST["size2"] != "") {
+               $size = (int)$_POST["size2"];
+               $query .= "AND size < $size ";
+       }
+
+       $or = "AND (";
+       for ($i = 0; $i < count($addr); $i++) {
+               for ($j = 0; $j < 2; $j++) {
+                       if (isset($_POST["as" . $j . "_" .$i])) {
+                               $query .= "$or (logs.arch_id = $i AND logs.result = $j)";
+                               $or = " OR ";
+                       }
+               }
+       }
+       if ($or == " OR ") $query .= ")";
+       if (!isset($cnt)) $cnt = 50;
+       if (!isset($off)) $off = 0;
+       if (!isset($ns)) $ns = 0;
+       switch ($ns) {
+               case 0:
+                       $query .= " ORDER BY mtime DESC";
+                       break;
+               case 1:
+                       $query .= " ORDER BY spec";
+                       break;
+               case 2:
+                       $query .= " ORDER BY arch, spec";
+                       break;
+       }
+       $query .= " LIMIT $cnt OFFSET $off ";
+
+       mysql_connect("localhost", "mysql", "") or die(mysql_error());
+       mysql_select_db("buildlogs") or die(mysql_error());
+       $result = mysql_query("$query") or die("$query " . mysql_error());
+       $count = mysql_num_rows($result);
+
+       if ($count == 0) {
+               echo _("Nothing found");
+       } else {
+               echo "<table border=\"0\" cellspacing=\"1\" ".
+                       "cellpadding=3 bgcolor=\"#000000\" width=\"90%\">\n";
+               echo "<tr><th bgcolor=\"#CCCCFF\" align=\"left\" width=\"10%\">"._("Builder").
+                       "[<a href=\"$big_url&amp;ns=2\">"._("sort")."</a>]</th>";
+               echo "<th bgcolor=\"#CCCCFF\" align=\"left\" width=\"60%\">"._("Log File").
+                       "[<a href=\"$big_url&amp;ns=1\">"._("sort")."</a>]</th>".
+                       "<th bgcolor=\"#CCCCFF\" align=\"right\" width=\"15%\">"._("Size")."</th> ".
+                        "<th bgcolor=\"#CCCCFF\" align=\"left\">"._("Age").
+                        "[<a href=\"$big_url&amp;ns=0\">"._("sort")."</a>]</th>".
+                        "</th></tr>";
+               for ($i = $off; $i < $off + $count; $i++) {
+                       $row = mysql_fetch_assoc($result);
+                       $f = $row["spec"];
+                       $t = $now - $row["mtime"];
+                       $s = $row["size"];
+                       $t /= 60;
+                       if ($t >= 60) {
+                               $t /= 60;
+                               if ($t >= 24) {
+                                       $t /= 24;
+                                       $t = round($t);
+                                       $t = $t . "&nbsp;" . ngettext("day","days",$t);
+                               } else {
+                                       $t = round($t);
+                                       $t = $t . "&nbsp;" . ngettext("hour","hours",$t);
+                               }
+                       } else {
+                               $t = round($t);
+                               $t = $t . "&nbsp;" . ngettext("minute","minutes",$t);
+                       }
+                       
+//                $big_url = "$url?idx=$i&amp;ok=$j&amp;ns=$ns&amp;cnt=$cnt";
+                       $h = $row["log_id"];
+                       $u = "$url?log=$h";
+                       $arch_id = $row["arch_id"];
+                       $ok = $row["result"];
+                       $b = "$url?idx=$arch_id&amp;ok=$ok&amp;ns=$ns&amp;off=$off&amp;cnt=$cnt";
+
+                       $builder=$row["arch"]."/". $row["res"];
+                       echo "<tr>";
+                       echo "<td bgcolor=\"#CCCCCC\"><a href=\"$b\">$builder</a></td>";
+                       echo "<td bgcolor=\"#CCCCCC\"><a href=\"$u\">$f</a> ".
+                       "[<a href=\"$u&amp;action=text\">"._("text")."</a> | ".
+                       "<a href=\"$u&amp;action=tail\">"._("tail")."</a>]".
+                       "</td><td bgcolor=\"#CCCCCC\" align=\"right\">".
+                       "$s</td><td bgcolor=\"#CCCCCC\">$t</td></tr>\n";
+               }
+               echo "</table></div>\n";
+
+               $backarr = "&lt;&lt;&lt;&nbsp;";
+               $back = _("Page back");
+               $forward = _("Page forward");
+               $forwardarr = "&nbsp;&gt;&gt;&gt;";
+
+       }
+       mysql_free_result($result);
+       mysql_close();
+
+// FIXME
+/*
+       echo "<p><table width=\"90%\" align=\"center\"><tr><td align=left width=1%>";
+
+       if ($off > 0) {
+               $noff = $off - $cnt;
+               if ($noff < 0)  
+                       $noff = 0;
+               $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
+               echo "$hrefurl$backarr</a></td><td align=left>$hrefurl$back</a>";
+       } else {
+               echo "$backarr</td><td align=left>$back";
+       }
+
+    echo "</td>\n<td align=\"center\">";
+    echo "</td>\n<td align=\"right\">";
+
+    if ($off + $cnt < count($list))
+    {
+      $noff = $off + $cnt;
+      if ($noff < 0)   
+        $noff = 0;
+      $hrefurl = "<a href=\"$big_url&amp;off=$noff\">";
+      echo "$hrefurl$forward</a></td><td align=\"right\" width=\"1%\">$hrefurl$forwardarr</a>";
+    }
+    else
+    {
+      echo "$forward</td><td align=\"right\" width=\"1%\">$forwardarr";
+    }
+
+    echo "</td>\n</tr></table></p>";
+*/
+  } else
+  {
+    echo _("Enter something!");
+  }
+  echo "</form>\n";
+}
+
+function welcome()
+{
+?>
+<table border="0" width="100%"><tr><td width="20%">&nbsp;</td><td>
+<h1><?=_("Welcome!")?></h1>
+<p><?=_("Welcome to PLD Build Logs WWW interface.")?></p><p>
+<?=_("Feel free to email bug reports, complaints and feature requests ")?>
+<!-- ech... niech strace... -->
+<a href="mailto:feedback@pld-linux.org"><?=_("to us")?></a>. <?=_("Positive opinions are also")?> 
+<a href="mailto:feedback@pld-linux.org"><?=_("welcome")?></a> ;)</p>
+<p>Version: $Id: index.php,v 1.88 2006/09/15 18:16:37 witekfl Exp $</p>
+</td><td width="20%">&nbsp;</td></tr>
+</table>
+<?php
+}
+
+header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
+header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
+header("Cache-Control: no-cache, must-revalidate");
+header("Pragma: no-cache");
+
+//phpinfo();
+if ($local) {
+       if ($action == "text") {
+               dump_text();
+       } else if ($action == "adv_search") {
+               myheader();
+               adv_search();
+               trailer();
+       } else if ($action == "qatxt") {
+               dump_qa(1);
+       } else {
+               myheader();
+               echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=\"top\" width=\"10%\">";
+               list_archs();
+               echo "</td><td valign=\"top\">";
+               flush();
+               if ($action == "qa")
+                       dump_qa(0);
+               else if ($action == "sqa")
+                       search_qa();
+               else if (isset($id) || isset($log))
+                       dump_log($action == "tail");
+               else if (isset($idx))
+                       list_logs();
+               else 
+                       welcome();
+               echo "</td></tr></table>";
+               trailer();
+       }
+}
+else {
+
+       if ($action == "text") {
+               dump_text();
+       } else if ($action == "qatxt") {
+               dump_qa(1);
+       } else {
+               myheader();
+               echo "<table cellpadding=\"10\" width=\"100%\"><tr><td valign=top width=\"10%\">";
+               list_archs();
+               echo "</td><td valign=\"top\">";
+               flush();
+               if ($action == "qa")
+                       dump_qa(0);
+               else if (isset($id))
+                       dump_log($action == "tail");
+               else if (isset($idx))
+                       list_logs();
+               else 
+                       welcome();
+               echo "</td></tr></table>";
+               trailer();
+       }
+}
+?>
diff --git a/obsolete/buildlogs.sql/init.sql b/obsolete/buildlogs.sql/init.sql
new file mode 100644 (file)
index 0000000..27f6705
--- /dev/null
@@ -0,0 +1,82 @@
+-- MySQL dump 9.11
+--
+-- Host: localhost    Database: buildlogs
+-- ------------------------------------------------------
+-- Server version      4.0.22
+
+--
+-- Table structure for table `architectures`
+--
+CREATE DATABASE buildlogs;
+
+USE buildlogs;
+
+
+CREATE TABLE architectures (
+  arch_id tinyint(4) NOT NULL default '0',
+  name varchar(15) default NULL,
+  PRIMARY KEY  (arch_id)
+) TYPE=MyISAM;
+
+--
+-- Dumping data for table `architectures`
+--
+
+INSERT INTO architectures VALUES (0,'th/SRPMS');
+INSERT INTO architectures VALUES (1,'th/i486');
+INSERT INTO architectures VALUES (2,'th/i686');
+INSERT INTO architectures VALUES (3,'th/athlon');
+INSERT INTO architectures VALUES (4,'th/x86_64');
+INSERT INTO architectures VALUES (5,'th/ia64');
+INSERT INTO architectures VALUES (6,'th/alpha');
+INSERT INTO architectures VALUES (7,'th/ppc');
+INSERT INTO architectures VALUES (8,'th/sparc');
+INSERT INTO architectures VALUES (9,'ac/SRPMS');
+INSERT INTO architectures VALUES (10,'ac/i386');
+INSERT INTO architectures VALUES (11,'ac/i586');
+INSERT INTO architectures VALUES (12,'ac/i686');
+INSERT INTO architectures VALUES (13,'ac/athlon');
+INSERT INTO architectures VALUES (14,'ac/amd64');
+INSERT INTO architectures VALUES (15,'ac/alpha');
+INSERT INTO architectures VALUES (16,'ac/ppc');
+INSERT INTO architectures VALUES (17,'ac/sparc');
+INSERT INTO architectures VALUES (18,'ac/sparc64');
+
+
+-- Table structure for table `logs`
+--
+
+CREATE TABLE logs (
+  log_id int(11) NOT NULL auto_increment,
+  arch_id tinyint(4) default NULL,
+  result tinyint(4) default NULL,
+  size int(11) default NULL,
+  spec_id smallint(6) default NULL,
+  mtime int(11) default NULL,
+  PRIMARY KEY  (log_id)
+) TYPE=MyISAM;
+
+
+CREATE TABLE result (
+  result_id tinyint(4) NOT NULL default '0',
+  name varchar(5) default NULL,
+  PRIMARY KEY  (result_id)
+) TYPE=MyISAM;
+
+--
+-- Dumping data for table `result`
+--
+
+INSERT INTO result VALUES (0,'FAIL');
+INSERT INTO result VALUES (1,'OK');
+
+--
+-- Table structure for table `specs`
+--
+
+CREATE TABLE specs (
+  spec_id smallint(6) NOT NULL auto_increment,
+  spec varchar(70) default NULL,
+  PRIMARY KEY  (spec_id)
+) TYPE=MyISAM;
+
diff --git a/obsolete/buildlogs.sql/migration.php b/obsolete/buildlogs.sql/migration.php
new file mode 100644 (file)
index 0000000..3c3447f
--- /dev/null
@@ -0,0 +1,87 @@
+#!/usr/bin/php.cli
+<?php
+// parameter: argv[1] - full path to the log file eg. /home/services/ftp/pub/pld-buildlogs/ac/athlon/kernel.log.bz2
+$user = 'mysql';
+$password = '';
+$root_directory = '/home/services/ftp/pub/pld-buildlogs';
+
+// Keep in sync with database
+
+$result = array("FAIL" => 0, "OK" => 1);
+$arch = array(
+       "th/SRPMS" => 0,
+       "th/i486" => 1,
+       "th/i686" => 2,
+       "th/athlon" => 3,
+       "th/x86_64" => 4,
+       "th/ia64" => 5,
+       "th/alpha" => 6,
+       "th/ppc" => 7,
+       "th/sparc" => 8,
+       "ac/SRPMS" => 9,
+       "ac/i386" => 10,
+       "ac/i586" => 11,
+       "ac/i686" => 12,
+       "ac/athlon" => 13,
+       "ac/amd64" => 14,
+       "ac/alpha" => 15,
+       "ac/ppc" => 16,
+       "ac/sparc" => 17,
+       "ac/sparc64" => 18
+);
+
+$list1 = `find "$root_directory/th $root_directory/ac" -name "*.bz2"`;
+$lista = explode("\n", $list1);
+$counter = 0;
+mysql_connect('localhost', "$user", "$password") or die ("connect error" . mysql_error());
+mysql_select_db("buildlogs");
+foreach ($lista as $file) {
+       preg_match("|$root_directory/(.*/.*)/(.*)/(.*)\.bz2|", $file, $matches);
+
+       $counter = ($counter + 1) % 100;
+       if ($counter == 0) {
+               echo(".");
+       }
+
+       $arch_name = $matches[1];
+       if (!array_key_exists($arch_name, $arch)) continue;
+       else $arch_id = $arch[$arch_name];
+
+       $result_name = $matches[2];
+       if (!array_key_exists($result_name, $result)) continue;
+       else $result_id = $result[$result_name];
+
+       $spec_name = $matches[3];
+       if ($spec_name == '') continue;
+
+       $spec_name = mysql_escape_string($spec_name);
+       $size = filesize($file);
+       $mtime = filemtime($file);
+
+       $row = mysql_query("SELECT spec_id FROM specs WHERE spec='$spec_name' LIMIT 1") or die("SELECT 1" . mysql_error());
+       if (mysql_num_rows($row) == 0) {
+               mysql_query("INSERT INTO specs(spec) VALUES ('$spec_name')") or die("INSERT 1" . mysql_error());
+               $row = mysql_query("SELECT spec_id FROM specs WHERE spec='$spec_name' LIMIT 1") or die("SELECT 1" . mysql_error());
+               if (mysql_num_rows($row) == 0) {
+                       mysql_close();
+                       exit;
+               }
+       }
+
+       $linia = mysql_fetch_object($row);
+       $spec_id = $linia->spec_id;
+       mysql_free_result($row);
+
+       $row = mysql_query("SELECT log_id FROM logs WHERE spec_id=$spec_id AND arch_id=$arch_id LIMIT 1");
+       if (mysql_num_rows($row) == 0) {
+               mysql_query("INSERT INTO logs(arch_id, spec_id, result, size, mtime) "
+               . "VALUES ($arch_id, $spec_id, $result_id, $size, $mtime)") or die("INSERT 2" . mysql_error());
+       } else {
+               $linia = mysql_fetch_object($row);
+               mysql_query("UPDATE logs SET result = $result_id, size = $size, mtime = $mtime WHERE log_id = $linia->log_id")
+               or die ("UPDATE" . mysql_error());
+       }
+       mysql_free_result($row);
+}
+mysql_close();
+?>
This page took 0.089151 seconds and 4 git commands to generate.