#!/usr/bin/perl -wT # Copyright 1999-2011 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # Author: Christian (idl0r) Ruppert use strict; # The path where the GDatabase.pm is (Can be outside of the wwwroot) use lib qw( /home/idl0r ); use Time::HiRes qw(gettimeofday tv_interval); my $t0 = [gettimeofday]; use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); my %DB = (); use GDatabase; %DB = %GDatabase::DB ? %GDatabase::DB : undef; my $query = new CGI; my $search = $query->param('search'); my $author = 'Christian Ruppert (idl0r) <idl0r <AT> gentoo <DOT> org>'; my $dbdate = $GDatabase::DBDATE ? $GDatabase::DBDATE : 'Timestamp of DB: not available.'; sub is_undef($) { my $var = shift; if(defined($var) && (length($var) > 0)) { return 0; } return 1; } sub error_search { print "
Oops, something went wrong! Sorry :(
\n"; } sub table_start($) { my $caption = shift; # print <<_TABLE_START_;
_TABLE_START_ } sub table_end() { print "\t\t\t
Query: ${caption}
Category Package Herd Maintainer File Size
\n\t\t\t
\n"; } sub print_data(\%$$) { my $hashref = shift; my $cat = shift; my $pkg = shift; my $i = 0; my %hash = %{$hashref}; print "\t\t\t\t\n"; print "\t\t\t\t\t${cat}\n"; print "\t\t\t\t\t${pkg}\n"; if( @{$hash{$cat}{$pkg}{'herd'}} eq 0 ) { print "\t\t\t\t\tno-herd\n"; } else { print "\t\t\t\t\t".join("
", sort(@{$hash{$cat}{$pkg}{'herd'}}))."\n"; } if( @{$hash{$cat}{$pkg}{'maintainer'}} eq 0 ) { if( @{$hash{$cat}{$pkg}{'herd'}} eq 0 ) { print "\t\t\t\t\tmaintainer-needed\n"; } else { print "\t\t\t\t\t-\n"; } } else { print "\t\t\t\t\t".join("
", sort(@{$hash{$cat}{$pkg}{'maintainer'}}))."\n"; } print "\t\t\t\t\t"; $i = 0; foreach my $f (sort(@{$hash{$cat}{$pkg}{'files'}})) { $i++; my ($fname, $size) = split(":", $f, 2); print "${fname}"; if($i < @{$hash{$cat}{$pkg}{'files'}}) { print "
"; } } print "\n"; print "\t\t\t\t\t"; $i = 0; foreach my $f (sort(@{$hash{$cat}{$pkg}{'files'}})) { $i++; my ($fname, $size) = split(":", $f, 2); print "${size}"; if($i < @{$hash{$cat}{$pkg}{'files'}}) { print "
"; } } print "\n"; print "\t\t\t\t\n"; } sub parse_data { my ($maintainer, $herd) = @_; my $all = 0; my $noherd = 0; my $needed = 0; if( is_undef($maintainer) && is_undef($herd) ) { $all = 1; table_start("All"); } elsif(!is_undef($maintainer) && ($maintainer =~ m/^\Qmaintainer-needed\E$/)) { $needed = 1; $maintainer = 'maintainer-needed'; } elsif(!is_undef($herd) && ($herd =~ m/^\Qno-herd\E$/)) { $noherd = 1; $herd = "no-herd" } if(!is_undef($herd)) { table_start("herd => ${herd}"); } elsif(!is_undef($maintainer)) { table_start("maintainer => ${maintainer}"); } # foreach my $cat (sort(keys(%DB))) { foreach my $pkg (sort(keys(%{$DB{$cat}}))) { if($all eq 1) { # print all print_data(%DB, $cat, $pkg); next; } elsif(!is_undef($herd)) { # print by herd # no-herd if($noherd eq 1) { if( @{$DB{$cat}{$pkg}{'herd'}} eq 0 || grep(/^\Q${herd}\E$/, @{$DB{$cat}{$pkg}{'herd'}}) ) { print_data(%DB, $cat, $pkg); } next; } else { if( @{$DB{$cat}{$pkg}{'herd'}} > 0 && grep(/^\Q${herd}\E$/, @{$DB{$cat}{$pkg}{'herd'}}) ) { print_data(%DB, $cat, $pkg); } next; } } elsif(!is_undef($maintainer)) { # print by maintainer # no maintainer != maintainer-needed except there is also no-herd if($needed eq 1) { if ( (@{$DB{$cat}{$pkg}{'herd'}} eq 0 || grep(/^\Qno-herd\E$/, @{$DB{$cat}{$pkg}{'herd'}})) && (@{$DB{$cat}{$pkg}{'maintainer'}} eq 0 || grep(/^\Qmaintainer-needed\E$/, @{$DB{$cat}{$pkg}{'maintainer'}})) ) { print_data(%DB, $cat, $pkg); } next; } elsif( @{$DB{$cat}{$pkg}{'maintainer'}} > 0 && grep(/^\Q${maintainer}\E$/, @{$DB{$cat}{$pkg}{'maintainer'}}) ) { print_data(%DB, $cat, $pkg); } next; } table_end(); error_search(); return; } } table_end(); } sub get_data { my $qry = shift; my $m = undef; my $h = undef; if(defined($qry) && length($qry) == 0) { parse_data(undef, undef); return; } elsif(defined($qry) && length($qry) >= 2) { if(length($qry) == 2 && $qry =~ m/^(mn|nh)$/) { if($qry =~ m/^mn$/) { parse_data("maintainer-needed", undef); return; } elsif($qry =~ m/^nh$/) { parse_data(undef, "no-herd"); return; } } elsif($qry =~ m/^[mh]\:\w+(\-\w*)?$/) { ($m, $h) = split(":", $qry, 2); if( (defined($m) && length($m) == 1) && (defined($h) && length($h) >= 1) ) { if($m =~ m/^m$/) { parse_data($h, undef); return; } elsif($m =~ m/^h$/) { parse_data(undef, $h); return; } } } } error_search(); } print "Content-Type: application/xhtml+xml\n\n"; print <<_HEADER_; list of _possible_ unused files from package files dirs

*** NOTE: THERE MIGHT BE FALSE-POSITIVES ***

_HEADER_ print <<_SEARCH_;
${dbdate}

Search through the DB by: herd, maintainer or leave empty to view all.
Examples:
maintainer = m:idl0r
herd = h:perl
maintainer-needed: mn
no-herd: nh

_SEARCH_ if(defined($search)) { get_data($search); } else { print"\t\t\t
\n"; } my $elapsed = tv_interval($t0, [gettimeofday]); print <<_BOTTOM_;

Valid XHTML 1.0 Strict!

${author}
Page generated in ${elapsed} seconds.

Fight Spam! Click Here!

_BOTTOM_