]> git.sven.stormbind.net Git - sven/scripts.git/commitdiff
Import bposearch
authorSven Hoexter <sven@stormbind.net>
Mon, 17 Jan 2011 17:00:17 +0000 (18:00 +0100)
committerSven Hoexter <sven@stormbind.net>
Mon, 17 Jan 2011 17:00:17 +0000 (18:00 +0100)
bposearch/getsources.sh [new file with mode: 0644]
bposearch/search.php [new file with mode: 0644]
bposearch/search.pl [new file with mode: 0644]

diff --git a/bposearch/getsources.sh b/bposearch/getsources.sh
new file mode 100644 (file)
index 0000000..bfa8b9d
--- /dev/null
@@ -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 (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>
diff --git a/bposearch/search.pl b/bposearch/search.pl
new file mode 100644 (file)
index 0000000..e0a272a
--- /dev/null
@@ -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 '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">', "\n";
+print "<html><head><title>bpo package search</title></head><body>\n";
+
+
+sub sendtheform {
+    print "<form action=\"search.pl\" method=\"POST\">\n";
+    print "<H1>bpo package search</H1>\n";
+    print "<input type=\"text\" name=\"query\" size=\"40\" maxlength=\"40\">\n";
+    print "<td valign=\"top\"><input type=\"submit\" name=\"send\" value=\"send\"></td>\n";
+    print "</form>\n";
+}
+
+sub performsearch {
+    my $query = @_[0];
+    print "<p>Server performed a query with the keyword ";
+    print $query;
+    print "</p>\n";
+
+    foreach my $value (qw/ main contrib non-free /) {
+       print "<h1>Results for packages listed in ", $value, ":</h1>\n";
+
+       open SOURCES, "$value/Sources" or die "Can't open Source file: $!";
+       my @sourceslist=<SOURCES>;
+       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 "<p>\n";
+               print @sourceslist[$i],"<br>\n";
+               print $pver, "<br>\n";
+                print "<a href=\"http://www.backports.org/debian/", $pdir,"\">http://www.backports.org/debian/",$pdir,"</a><br>\n";
+               print "</p>\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 "</body></html>\n";