From 8a4b76f8e7c04607b3dc3155d4b98007c946d74e Mon Sep 17 00:00:00 2001 From: Sven Hoexter Date: Mon, 17 Jan 2011 18:00:17 +0100 Subject: [PATCH] Import bposearch --- bposearch/getsources.sh | 6 +++ bposearch/search.php | 94 +++++++++++++++++++++++++++++++++++++++++ bposearch/search.pl | 85 +++++++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+) create mode 100644 bposearch/getsources.sh create mode 100644 bposearch/search.php create mode 100644 bposearch/search.pl diff --git a/bposearch/getsources.sh b/bposearch/getsources.sh new file mode 100644 index 0000000..bfa8b9d --- /dev/null +++ b/bposearch/getsources.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +cd /home/sven/www/sven_htdocs/bposearch/ +wget -q http://www.backports.org/debian/dists/sarge-backports/main/source/Sources.bz2 && bunzip2 Sources.bz2 && mv Sources main +wget -q http://www.backports.org/debian/dists/sarge-backports/contrib/source/Sources.bz2 && bunzip2 Sources.bz2 && mv Sources contrib +wget -q http://www.backports.org/debian/dists/sarge-backports/non-free/source/Sources.bz2 && bunzip2 Sources.bz2 && mv Sources non-free diff --git a/bposearch/search.php b/bposearch/search.php new file mode 100644 index 0000000..efc07b5 --- /dev/null +++ b/bposearch/search.php @@ -0,0 +1,94 @@ + + + + bpo package search + + +\n"; + echo "

bpo package search

\n"; + echo "\n"; + echo "\n"; + echo "\n"; +} + + +function performsearch () { + $query = $_POST["query"]; + echo "

"; + echo "Server performed a query with the keyword \"$query\"
"; + echo "

"; + + $parts = array("main","contrib","non-free"); + foreach ($parts as $value) { + + echo "

Results for packages listed in $value:

\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 "

\n"; + echo "$sourcesarray[$i]
\n"; + echo "$pver
\n"; + echo "http://www.backports.org/debian/$pdir/
\n"; + echo "

\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(); +} +?> + + + diff --git a/bposearch/search.pl b/bposearch/search.pl new file mode 100644 index 0000000..e0a272a --- /dev/null +++ b/bposearch/search.pl @@ -0,0 +1,85 @@ +#!/usr/bin/perl -w + +use strict; +use CGI; +use CGI::Carp qw(fatalsToBrowser); +my $query = new CGI; + +print "Content-type: text/html\n\n"; +print '', "\n"; +print "bpo package search\n"; + + +sub sendtheform { + print "
\n"; + print "

bpo package search

\n"; + print "\n"; + print "\n"; + print "
\n"; +} + +sub performsearch { + my $query = @_[0]; + print "

Server performed a query with the keyword "; + print $query; + print "

\n"; + + foreach my $value (qw/ main contrib non-free /) { + print "

Results for packages listed in ", $value, ":

\n"; + + open SOURCES, "$value/Sources" or die "Can't open Source file: $!"; + my @sourceslist=; + close SOURCES; + + for (my $i = 0; $i < @sourceslist; $i++) { + $_ = @sourceslist[$i]; + if (/^Package:.*$query.*/) { + my $pver=&findnextver($i, @sourceslist); + my $pdir=&findnextdir($i, @sourceslist); + print "

\n"; + print @sourceslist[$i],"
\n"; + print $pver, "
\n"; + print "http://www.backports.org/debian/",$pdir,"
\n"; + print "

\n"; + + } + } + + } +} + + +sub findnextver { + my ($startpos, @list) = @_; + for (my $i = $startpos; $i < @list; $i++) { + $_ = @list[$i]; + if (/^Version:.*/) { + return $_; + last; + } + } +} + +sub findnextdir { + my ($startpos, @list) = @_; + for (my $i = $startpos; $i < @list; $i++) { + $_ = @list[$i]; + if (/^Directory:.*/) { + my @dirsplit = split / /, $_; + chomp(@dirsplit[1]); + return @dirsplit[1]; + last; + } + } +} + + + + if ($query->param('send') eq "send") { + &performsearch($query->param('query')); +} else { + &sendtheform(); +} + + +print "\n"; -- 2.39.5