This commit is contained in:
Wolfram Schneider 2007-08-02 18:30:21 +00:00
parent 20c3606135
commit 37edf79a84
Notes: svn2git 2020-12-08 03:00:23 +00:00
svn path=/www/; revision=30574

View file

@ -24,7 +24,7 @@
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $FreeBSD: www/en/cgi/ports.cgi,v 1.94 2006/08/19 21:40:25 simon Exp $
# $FreeBSD: www/en/cgi/ports.cgi,v 1.95 2007/08/02 18:28:26 wosch Exp $
#
# ports.cgi - search engine for FreeBSD ports
# o search for a port by name or description
@ -47,19 +47,21 @@ sub init_variables {
# Ports database file to use
if ( -f "$portsDatabaseHeadDir/INDEX-6" ) {
$ports_database = 'INDEX-6';
} elsif (-f "$portsDatabaseHeadDir/INDEX-5") {
}
elsif ( -f "$portsDatabaseHeadDir/INDEX-5" ) {
$ports_database = 'INDEX-5';
} else {
}
else {
$ports_database = 'INDEX';
}
# URL of ports tree for browsing
$remotePrefixFtp = 'ports';
# 'ftp://ftp.FreeBSD.org/pub/FreeBSD/branches/-current/ports';
# URL of ports tree for download
$remotePrefixFtpDownload =
'http://cvsweb.FreeBSD.org/ports';
$remotePrefixFtpDownload = 'http://cvsweb.FreeBSD.org/ports';
$remoteSuffixFtpDownload = '%s.tar.gz?tarball=1';
# where to get -current packages
@ -72,8 +74,7 @@ sub init_variables {
$remotePrefixFtpPackagesDefault = '6-STABLE/i386';
# This is currently unused
%remotePrefixFtpPackages =
(
%remotePrefixFtpPackages = (
'7-CURRENT/i386', "$p/packages-7-current/All",
'6-STABLE/i386', " $p/packages-6-stable/All",
'5-STABLE/i386', " $p/packages-5-stable/All",
@ -109,18 +110,17 @@ sub init_variables {
'5.4-RELEASE/sparc64', "$psparc64/packages-5.4-release/All",
);
$remotePrefixHtml =
"$hsty_base/ports";
$remotePrefixHtml = "$hsty_base/ports";
# CVS Web interface
$remotePrefixCvs =
'http://cvsweb.FreeBSD.org/ports';
$remotePrefixCvs = 'http://cvsweb.FreeBSD.org/ports';
# Ports documentation
$portsDesc = "$hsty_base/ports/";
# location of the tiny BSD daemon
$daemonGif = "<img src='$hsty_base/gifs/littlelogo.gif' alt='Really small BSD Daemon'>";
$daemonGif =
"<img src='$hsty_base/gifs/littlelogo.gif' alt='Really small BSD Daemon'>";
# visible E-Mail address, plain text
$mailto = 'www@FreeBSD.org';
@ -151,7 +151,6 @@ sub init_variables {
}
sub packages_exist {
local ( $file, *p ) = @_;
@ -169,7 +168,6 @@ sub packages_exist {
return 0;
}
# return the date of the last ports database update
sub last_update {
local ($file) = "$portsDatabaseHeadDir/$ports_database";
@ -178,7 +176,8 @@ sub last_update {
$modtime = ( stat($file) )[9];
if ( defined($modtime) && $modtime > 0 ) {
$modtimestr = strftime( "%G-%m-%d %H:%M:%S UTC", gmtime($modtime) );
} else {
}
else {
$modtimestr = "Unknown";
}
@ -198,8 +197,6 @@ sub dec {
return ($_);
}
# $indent is a bit of optional data processing I put in for
# formatting the data nicely when you are emailing it.
# This is derived from code by Denis Howe <dbh@doc.ic.ac.uk>
@ -232,13 +229,14 @@ sub escapeHTML {
sub encode_url {
local ($_) = @_;
s/([\000-\032\;\/\?\:\@\&\=\%\'\"\`\<\>\177-\377 ])/sprintf('%%%02x',ord($1))/eg;
# s/%20/+/g;
$_;
}
sub warn { print "$_[0]" }
sub env { defined( $ENV{ $_[0] } ) ? $ENV{ $_[0] } : undef; }
sub exit { exit 0 };
sub exit { exit 0 }
sub readindex {
local ( *var, *msec ) = @_;
@ -246,7 +244,8 @@ sub readindex {
local ( @tmp, @s );
open( C, $localportsdb ) || do {
warn "Cannot open ports database $localportsdb: $!\n"; &exit;
warn "Cannot open ports database $localportsdb: $!\n";
&exit;
};
while (<C>) {
@ -283,10 +282,12 @@ sub readcoll {
}
}
}
} else {
}
else {
if ( -r $localportsdb ) {
open( C, $localportsdb ) || do {
warn "Cannot open ports database $localportsdb: $!\n"; &exit;
warn "Cannot open ports database $localportsdb: $!\n";
&exit;
}
}
@ -316,15 +317,17 @@ sub readcoll {
# basic function for HTML output
sub out {
local ($line) = @_;
local($version, $path, $local, $comment, $descfile, $email,
$sections, $bdepends, $rdepends, @rest) = split(/\|/, $line);
local (
$version, $path, $local, $comment, $descfile,
$email, $sections, $bdepends, $rdepends, @rest
) = split( /\|/, $line );
if ( $path =~ m%^$localPrefix/([^/]+)%o ) {
if ( !$out_sec || $1 ne $out_sec ) {
print "</dl>\n" if $counter > 0;
print qq{\n<h3>} .
qq{<a href="$remotePrefixHtml/$1.html">Category $1</a>} .
"</h3>\n<dl>\n";
print qq{\n<h3>}
. qq{<a href="$remotePrefixHtml/$1.html">Category $1</a>}
. "</h3>\n<dl>\n";
$out_sec = $1;
}
}
@ -340,18 +343,21 @@ sub out {
if ( substr( $remoteSuffixFtpDownload, 0, 2 ) eq '%s' ) {
$pathDownload =~ m,([^/]+)$,;
$pathDownload .= "/$1" . substr( $remoteSuffixFtpDownload, 2 );
} else {
}
else {
$pathDownload .= $remoteSuffixFtpDownload;
}
}
$descfile =~ s/^$localPrefix/$remotePrefixFtp/o;
$version = &encode_url($version);
#$version =~ s/[\+,]/X/g;
local ($l) = $path;
$l =~ s%^$remotePrefixFtp%$remotePrefixCvs%o;
print qq{<dt><b><a name="$version"></a><a href="$l">$version</a></b></dt>\n};
print
qq{<dt><b><a name="$version"></a><a href="$l">$version</a></b></dt>\n};
print qq{<dd>}, &escapeHTML($comment), qq{<br />\n};
print qq[<a href="$url?$descfile">Long description</a> <b>:</b>\n];
@ -359,16 +365,20 @@ sub out {
# Link package in "default" arch/release. Verify it's existence on ftp-master.
if ( $packages{"$version.$packageExt"} ) {
print qq[<a href="$remotePrefixFtpPackages{$remotePrefixFtpPackagesDefault}/$version.$packageExt">Package</a> <b>:</b>\n];
print
qq[<a href="$remotePrefixFtpPackages{$remotePrefixFtpPackagesDefault}/$version.$packageExt">Package</a> <b>:</b>\n];
}
print qq[<a href="$l">Changes</a> <b>:</b>\n];
print qq[<a href="$pathDownload">Download</a><br />\n];
print qq{<i>Maintained by:</i> <a href="mailto:$email} .
($mailtoAdvanced ?
qq{?cc=$mailtoList&amp;subject=FreeBSD%20Port:%20} .
&encode_url($version) : '') . qq{">$email</a><br />\n};
print qq{<i>Maintained by:</i> <a href="mailto:$email}
. (
$mailtoAdvanced
? qq{?cc=$mailtoList&amp;subject=FreeBSD%20Port:%20}
. &encode_url($version)
: ''
) . qq{">$email</a><br />\n};
local (@s) = split( /\s+/, $sections );
if ( $#s > 0 ) {
@ -385,6 +395,7 @@ sub out {
local ($last) = '';
print qq{<i>Requires:</i> };
foreach ( sort split( /\s+/, "$bdepends $rdepends" ) ) {
# delete double entries
next if $_ eq $last;
$last = $_;
@ -402,7 +413,7 @@ sub out {
print qq[<dd>&nbsp;</dd>];
print qq[\n\n];
};
}
# search and output
sub search_ports {
@ -423,22 +434,27 @@ sub search_ports {
#warn "$stype:$query: $name $text\n";
if ( $stype eq "name" && $name =~ /$query/o ) {
&out( $today{$key} );
} elsif ($stype eq "text" && $text =~ /$query/oi) {
}
elsif ( $stype eq "text" && $text =~ /$query/oi ) {
&out( $today{$key} );
} elsif ($stype eq "all" &&
($text =~ /$query/oi || $name =~ /$query/io)) {
}
elsif ( $stype eq "all"
&& ( $text =~ /$query/oi || $name =~ /$query/io ) )
{
&out( $today{$key} );
} elsif ($stype eq 'maintainer' && $a[5] =~ /$query/io) {
}
elsif ( $stype eq 'maintainer' && $a[5] =~ /$query/io ) {
&out( $today{$key} );
} elsif ($stype eq 'requires' &&
($a[7] =~ /$query/io || $a[8] =~ /$query/io)) {
}
elsif ( $stype eq 'requires'
&& ( $a[7] =~ /$query/io || $a[8] =~ /$query/io ) )
{
&out( $today{$key} );
}
}
}
sub forms {
print qq{<p>
FreeBSD Ports [short description <a href="$portsDesc">followed</a> ...]
@ -460,17 +476,18 @@ Search for:
};
local (%d);
%d = ('name', 'Package Name',
'all', 'All',
'maintainer', 'Maintainer',
'text', 'Description',
'pkgdescr', 'Long Description',
'requires', 'Requires',
%d = (
'name', 'Package Name', 'all', 'All',
'maintainer', 'Maintainer', 'text', 'Description',
'pkgdescr', 'Long Description', 'requires', 'Requires',
);
foreach ( 'all', 'name', 'text', 'pkgdescr', 'maintainer', 'requires' ) {
print "<option" . (($_ eq $stype) ? ' selected="selected" ' : ' ') .
qq{value="$_">} . ($d{$_} ? $d{$_} : $_) . qq{</option>\n};
print "<option"
. ( ( $_ eq $stype ) ? ' selected="selected" ' : ' ' )
. qq{value="$_">}
. ( $d{$_} ? $d{$_} : $_ )
. qq{</option>\n};
}
print qq{</select>
@ -480,9 +497,9 @@ Search for:
};
foreach (@sec) {
print "<option" .
(($_ eq $section) ? ' selected="selected" ' : ' ') .
qq{value="$_">$_</option>\n};
print "<option"
. ( ( $_ eq $section ) ? ' selected="selected" ' : ' ' )
. qq{value="$_">$_</option>\n};
}
print q{</select>
@ -499,28 +516,36 @@ sub footer {
<img align="right" src="$hsty_base/gifs/powerlogo.gif" alt="Powered by FreeBSD" />
&copy; 1996-2007 by Wolfram Schneider. All rights reserved.<br />
};
#print q{$FreeBSD: www/en/cgi/ports.cgi,v 1.94 2006/08/19 21:40:25 simon Exp $} . "<br />\n";
#print q{$FreeBSD: www/en/cgi/ports.cgi,v 1.95 2007/08/02 18:28:26 wosch Exp $} . "<br />\n";
print qq{Please direct questions about this service to
<i><a href="$mailtoURL">$mailto</a></i><br />\n};
print qq{General questions about FreeBSD ports should be sent to } .
qq{<a href="mailto:$mailtoList">} .
qq{<i>$mailtoList</i></a><br />\n};
print qq{General questions about FreeBSD ports should be sent to }
. qq{<a href="mailto:$mailtoList">}
. qq{<i>$mailtoList</i></a><br />\n};
print &last_update_message;
print qq{<hr noshade="noshade" />\n<p />\n};
}
sub check_input {
if ($query) {
$stype = "all" if !$stype;
if (!($stype eq "name" ||
$stype eq "text" ||
$stype eq "maintainer" ||
$stype eq "requires" ||
$stype eq "all")) {
&warn("unknown search type ``$type'', use `all', `text', `name', 'requires', or `maintainer'\n");
if (
!(
$stype eq "name"
|| $stype eq "text"
|| $stype eq "maintainer"
|| $stype eq "requires"
|| $stype eq "all"
)
)
{
&warn(
"unknown search type ``$type'', use `all', `text', `name', 'requires', or `maintainer'\n"
);
&exit(0);
} else {
}
else {
return;
}
}
@ -575,6 +600,7 @@ $stype = $form{'stype'};
$script_name = &env('SCRIPT_NAME');
if ( $path_info eq "/source" ) {
# XXX
print "Content-type: text/plain\n\n";
open( R, $0 ) || do { print "ick!\n"; &exit; };
@ -595,7 +621,9 @@ if ($stype eq 'pkgdescr') {
if ( $stype eq "faq" ) {
print &short_html_header( "FreeBSD Ports Search FAQ", 1 );
&faq;
&footer; print &html_footer; &exit(0);
&footer;
print &html_footer;
&exit(0);
}
print &html_header( "FreeBSD Ports Search", 1 );
@ -614,7 +642,9 @@ $query =~ s/^\s+//;
$query =~ s/\s+$//;
if ( $query_string eq "" || !$query ) {
&footer; print &html_footer; &exit(0);
&footer;
print &html_footer;
&exit(0);
}
&check_input;
@ -629,9 +659,10 @@ if ($query) {
if ( !$counter ) {
print "Sorry, nothing found.\n";
print qq{You may look for other } .
qq{<a href="/search/search.html">FreeBSD Search Services</a>.\n};
} else {
print qq{You may look for other }
. qq{<a href="/search/search.html">FreeBSD Search Services</a>.\n};
}
else {
print "</dl>\n";
}