diff --git a/Portscout/SQL.pm b/Portscout/SQL.pm index b6bf5ad..a360ecc 100644 --- a/Portscout/SQL.pm +++ b/Portscout/SQL.pm @@ -264,6 +264,24 @@ $sql{portdata_selectupdated} = WHERE ver != newver ORDER BY lower(maintainer)); +# ShowUpdatesByPort (and generate category) + +$sql{portdata_selectupdatedbyport} = + q(SELECT cat, name, ver, newver + FROM portdata + WHERE ver != newver + ORDER BY cat,name); + +$sql{portdata_catcount} = + q(SELECT cat, COUNT(*) as count + FROM portdata + GROUP BY cat); + +$sql{portdata_updatedcatcount} = + q(SELECT cat, COUNT(*) as count + FROM portdata + WHERE ver != newver + GROUP BY cat); # MovePorts diff --git a/Portscout/Template.pm b/Portscout/Template.pm index b25ed6b..ef6b7e7 100644 --- a/Portscout/Template.pm +++ b/Portscout/Template.pm @@ -175,7 +175,7 @@ sub applyglobal return 1; } - + #------------------------------------------------------------------------------ # Func: pushrow() # Desc: Interpolate data into the template's "repeat" section, and add the @@ -190,9 +190,12 @@ sub pushrow { my $self = shift; my $data = shift; + my $tag = shift; my $var; - + # Commented just for understanding: If there is anything in 'repeat', use that as the template + # for 'rows', otherwise use 'template_repeat'. This is in case you never called applyglobal() on + # the template. if (@{$self->{repeat}}) { $var = 'repeat'; } else { @@ -201,6 +204,11 @@ sub pushrow foreach (@{$self->{$var}}) { my $val = $_; + + # This allows you to say %%:[] and have + # only be output if pushrow gets called with that tag in the 3rd argument + next if (defined($tag) && ! ($val =~ s/^\[$tag\]//)); + $val =~ s/\%\%\((.+?)(?::(.*?))?\)/ if (exists $data->{$1}) { _format_var($data->{$1}, $2); diff --git a/portscout.pl b/portscout.pl index 2ed6ff1..b6ee93f 100755 --- a/portscout.pl +++ b/portscout.pl @@ -241,6 +241,10 @@ sub ExecArgs { $res = ShowUpdates(); } + elsif ($cmd eq 'showupdatesbyport') + { + $res = ShowUpdatesByPort(); + } elsif ($cmd eq 'add-mail' or $cmd eq 'remove-mail') { my (@addrs) = @ARGV; # Should be a list of addrs @@ -1310,7 +1314,15 @@ sub GenerateHTML $dbh = connect_db(); prepare_sql($dbh, \%sths, - qw(portdata_genresults portdata_selectall portdata_selectmaintainer portdata_selectall_limited) + qw( + portdata_genresults + portdata_selectall + portdata_selectmaintainer + portdata_selectall_limited + portdata_selectupdatedbyport + portdata_updatedcatcount + portdata_catcount + ) ); if ($Portscout::SQL::sql{portdata_genresults_init}) { @@ -1442,6 +1454,48 @@ sub GenerateHTML $template->output('restricted-ports.html'); + ### New index category code - dave@jetcafe.org + $template = undef; + + print "Creating index by category page...\n"; + + # Category data first + my %catcount = (); + $sths{portdata_updatedcatcount}->execute; + while (my $row = $sths{portdata_updatedcatcount}->fetchrow_hashref) { + $catcount{ $row->{cat} } = [ $row->{count} ] + } + $sths{portdata_catcount}->execute; + while (my $row = $sths{portdata_catcount}->fetchrow_hashref) { + push(@{ $catcount{ $row->{cat} } }, $row->{count}) if (defined($catcount{ $row->{cat} })); + } + + # Now muck with template since we already have our category data, this lets us use the database + # as a sorting engine as it should be. + $template = Portscout::Template->new('index-category.html') + or die "index-category.html template not found!\n"; + + $template->applyglobal(\%outdata); + $sths{portdata_selectupdatedbyport}->execute; + + my $lastcat; + while (my $row = $sths{portdata_selectupdatedbyport}->fetchrow_hashref) { + my $cat = $row->{cat}; + if (!defined($lastcat) || $lastcat ne $cat) { + my ($numerator, $denominator) = @{ $catcount{ $row->{cat} } }; + $numerator //= 0; $denominator //= 0; + $row->{'catdata'} = sprintf("Out of date: %.2f%%", (($denominator > 0) ? ($numerator/$denominator) : 0.0)); + + $template->pushrow($row, 'catrow'); + $lastcat = $cat; + } + $row->{namelink} = '' . $row->{name} . ''; + + $template->pushrow($row, 'portrow'); + } + + $template->output('index-category.html'); + print "Creating JSON dump of all data...\n"; open my $jf, '>', $settings{html_data_dir} . '/dump.json' @@ -1616,6 +1670,35 @@ sub ShowUpdates return 1; } +#------------------------------------------------------------------------------ +# Func: ShowUpdatesByPort() +# Desc: Produce a simple report showing ports with updates ordered by port not maintainer +# +# Args: n/a +# +# Retn: $success - true/false +#------------------------------------------------------------------------------ + +sub ShowUpdatesByPort +{ + my (%sths, $dbh); + + $dbh = connect_db(); + + prepare_sql($dbh, \%sths, 'portdata_selectupdatedbyport'); + + $sths{portdata_selectupdatedbyport}->execute(); + + while (my $port = $sths{portdata_selectupdatedbyport}->fetchrow_hashref) { + print " $port->{cat}/$port->{name} $port->{ver} -> $port->{newver}\n"; + } + + finish_sql($dbh, \%sths); + $dbh->disconnect; + + return 1; +} + #------------------------------------------------------------------------------ # Func: AddMailAddrs() @@ -1899,6 +1982,7 @@ sub Usage print STDERR " $s mail\n"; print STDERR " $s generate\n"; print STDERR " $s showupdates\n"; + print STDERR " $s showupdatesbyport\n"; print STDERR "\n"; print STDERR " $s add-mail user\@host ...\n"; print STDERR " $s remove-mail user\@host ...\n"; diff --git a/templates/index-category.html b/templates/index-category.html new file mode 100644 index 0000000..b86692b --- /dev/null +++ b/templates/index-category.html @@ -0,0 +1,105 @@ + + + + portscout - new distfile scanner + + + + + + +

portscout - Changed port summary by category

+ +
+ +

Generated on %%(date) at %%(time), by portscout v%%(appver)

+ +

Restricted ports <-- Please check this!

+ + + Filter Category (regex): + + + +

+ + + + + + + + + + + +%%:[catrow] +%%:[portrow] + +
CategoryPortCurrentNew
%%(cat)%%(catdata)
%%(cat)%%(namelink)%%(ver)%%(newver)
+ + +