#!/usr/bin/perl -T
#
# Copyright (c) 1996-2024 Wolfram Schneider
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# ports.cgi - search engine for FreeBSD ports
use POSIX qw(strftime);
use Time::Local;
require "./cgi-style.pl";
$t_style = qq`
`;
# No unlimited result set. A HTML page with 1000 results can be 10MB big.
my $max_hits = 1000;
my $max_hits_default = 250;
my $max;
my $debug = 1;
sub init_variables {
$localPrefix = '/usr/ports'; # ports prefix
# Directory of the up-to-date INDEX*
$portsDatabaseHeadDir = "/usr/local/www/ports";
# Ports database file to use
if ( -f "$portsDatabaseHeadDir/INDEX-14" ) {
$ports_database = 'INDEX-14';
}
elsif ( -f "$portsDatabaseHeadDir/INDEX-13" ) {
$ports_database = 'INDEX-13';
}
else {
$ports_database = 'INDEX';
}
# URL of ports tree for browsing
$remotePrefixFtp = 'ports';
# Web interface for the Ports tree
$remotePrefixRepo = 'https://cgit.FreeBSD.org/ports';
# visible E-Mail address, plain text
$mailto = 'www@FreeBSD.org';
# Mailinglist for FreeBSD Ports
$mailtoList = 'ports@FreeBSD.org';
# use mailto:email?subject
$mailtoAdvanced = 'yes';
# the URL if you click at the E-Mail address (see below)
$mailtoURL = "mailto:$mailto" if !$mailtoURL;
# security
$ENV{'PATH'} = '/bin:/usr/bin';
}
sub packages_exist {
local ( $file, *p ) = @_;
open( P, $file ) || do {
warn "open $file: $!\n";
warn "Cannot create packages links\n";
return 1;
};
while (
) {
chop;
$p{$_} = 1;
}
close P;
return 0;
}
# return the date of the last ports database update
sub last_update {
local ($file) = "$portsDatabaseHeadDir/$ports_database";
local ( $modtime, $modtimestr );
$modtime = ( stat($file) )[9];
if ( defined($modtime) && $modtime > 0 ) {
$modtimestr = strftime( "%Y-%m-%d %H:%M:%S UTC", gmtime($modtime) );
}
else {
$modtimestr = "Unknown";
}
return $modtimestr;
}
sub last_update_message {
return "
The FreeBSD Ports and Packages Collection offers a simple way for users and administrators to install applications.
};
print qq{
"Package Name" searches for the name of a port or distribution.
"Description" searches case-insensitive in a short comment about the port.
"All" searches case-insensitive for the package name and in the
description about the port.