+<!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>