]> git.sven.stormbind.net Git - sven/scripts.git/blobdiff - bposearch/search.php
Import bposearch
[sven/scripts.git] / bposearch / search.php
diff --git a/bposearch/search.php b/bposearch/search.php
new file mode 100644 (file)
index 0000000..efc07b5
--- /dev/null
@@ -0,0 +1,94 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+  <title>bpo package search</title>
+</head>
+<body>
+<?php
+
+/**************************************/
+//function block
+
+
+function sendtheform () {
+  echo "<form action=\"search.php\" method=\"POST\">\n";
+  echo "<H1>bpo package search</H1>\n";
+  echo "<input type=\"text\" name=\"query\" size=\"40\" maxlength=\"40\">\n";
+  echo "<td valign=\"top\"><input type=\"submit\" name=\"send\" value=\"send\"></td>\n";
+  echo "</form>\n";
+}
+
+
+function performsearch () {
+  $query = $_POST["query"]; 
+  echo "<p>";
+   echo "Server performed a query with the keyword \"$query\"<br>";
+   echo "</p>"; 
+
+   $parts = array("main","contrib","non-free");
+   foreach ($parts as $value) {
+
+   echo "<h1>Results for packages listed in $value:</h1>\n";
+
+    $sourcesfile = file_get_contents("$value/Sources");
+    $sourcesarray = explode("\n", $sourcesfile);
+
+    for ($i = 0; $i < count($sourcesarray); $i++) {
+       if (eregi("^Package:.*$query.*", $sourcesarray[$i])) {
+                    $pver=findnextver($i, $sourcesarray);
+                    $pdir=findnextdir($i, $sourcesarray);
+                    echo "<p>\n";
+                    echo "$sourcesarray[$i]<br>\n";
+                    echo "$pver<br>\n";
+                    echo "<a href=\"http://www.backports.org/debian/$pdir\">http://www.backports.org/debian/$pdir/</a><br>\n";
+                    echo "</p>\n";
+       }
+    }
+   }
+}
+
+function findnextver ($startpos, $sourcesarray) {
+   for ($i = $startpos; $i < count($sourcesarray); $i++) {
+       if (eregi("^Version:.*", $sourcesarray[$i])) {
+               return $sourcesarray[$i];
+       }
+   }
+}
+
+function findnextdir ($startpos, $sourcesarray) {
+   for ($i = $startpos; $i < count($sourcesarray); $i++) {
+       if (eregi("^Directory:.*", $sourcesarray[$i])) {
+               $dirsplit = explode(" ", $sourcesarray[$i]);
+               return $dirsplit[1]; 
+       }
+   }        
+}
+
+
+//function block end
+/*********************************************/
+
+//check if someone has hit the send button
+if ($_POST["send"] == "send") {
+  $invalidquery = "0";
+
+  //check if the query field is empty
+  if (empty($_POST['query'])) {
+       $invalidquery = "1";
+  }
+
+  //check if we've a reason to believe the query is invalid
+  if ($invalidquery == "0") {
+    performsearch();
+  } else {
+    sendtheerror($invalidreason);
+  }
+
+} else {
+//nothing send to us so print the search form
+sendtheform();
+}
+?>
+
+</body>
+</html>