Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Portscout/SQL.pm
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ $sql{portdata_selectupdated} =
WHERE ver != newver
ORDER BY lower(maintainer));

# ShowUpdatesByPort (and generate)

$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

Expand Down
12 changes: 10 additions & 2 deletions Portscout/Template.pm
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ sub applyglobal
return 1;
}


#------------------------------------------------------------------------------
# Func: pushrow()
# Desc: Interpolate data into the template's "repeat" section, and add the
Expand All @@ -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 {
Expand All @@ -201,6 +204,11 @@ sub pushrow

foreach (@{$self->{$var}}) {
my $val = $_;

# This allows you to say %%:[<tag>] and have <tag>
# 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);
Expand Down
83 changes: 82 additions & 1 deletion portscout.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}) {
Expand Down Expand Up @@ -1442,6 +1454,45 @@ sub GenerateHTML

$template->output('restricted-ports.html');

### New index category code - [email protected]
$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) {
$row->{'catdata'} = sprintf("New versions: %5d out of %5d", @{ $catcount{$cat} });

$template->pushrow($row, 'catrow');
$lastcat = $cat;
}

$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'
Expand Down Expand Up @@ -1616,6 +1667,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()
Expand Down Expand Up @@ -1899,6 +1979,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";
Expand Down
65 changes: 65 additions & 0 deletions templates/index-category.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<html>

<head>
<title>portscout - new distfile scanner</title>
<style>
<!--
body, table { font-family: "Verdana", "Helvetica", Sans-Serif; }
h2 { font-family: "Verdana", "Helvetica", Sans-Serif; }
tr { background-color: #FFFFFF; font-family: "Verdana", "Helvetica", Sans-Serif; }
td, p, ul, span { font-family: "Verdana", "Helvetica", Sans-Serif; font-size: 85%; }
.results { background-color: #444444; }
.catdata { background-color: #2222DD; color: #ffff99; }
.catrow > .cat { background-color: #2222DD; font-weight: bold; color: #ffffff; }
.resultshead { color: #FFFFFF; font-weight: bold; background-color: #999999; }

.resultsrow { background-color: #FFFFFF; }
.resultsrowupdated { background-color: #AAAADD; }

.resultshead a { color: #FFFFFF; text-decoration: none; }
.box { border: 1px solid #000000; padding: 6px; }
.hidden { display: none; }
.expand { margin-right: 0.5em; font-size: 110%; background-color: #ffffff; color=#0000ff;}
//-->
</style>

<script type="text/javascript">
function ToggleCat(mycat) {
console.log(mycat);
let nodes = document.querySelectorAll("[data-cat=" + mycat + "]");
nodes.forEach(function(thing) {
thing.classList.toggle("hidden");
});
}
</script>
</head>

<body>

<h1>portscout - Changed port summary by category</h1>

<hr>

<p>Generated on %%(date) at %%(time), by <a href="http://www.inerd.com/software/portscout/">portscout</a> v%%(appver)</p>

<p><a href="restricted-ports.html">Restricted ports</a> <font color="#CC0000"><b>&lt;-- Please check this!</b></font></p>

<br /><br />

<table class="results" cellspacing="1" cellpadding="2">
<thead>
<tr class="resultshead">
<td>Category</td>
<td>Portname</td>
<td>Old Version</td>
<td>New Version</td>
</tr>
</thead>
<tbody>
%%:[catrow] <tr class="resultsrow catrow"><td class="cat"><button onclick="ToggleCat('%%(cat)')" class="expand">+</button>%%(cat)</td><td class="catdata" colspan="3">%%(catdata)</td></tr>
%%:[portrow] <tr class="hidden resultsrow portrow" data-cat="%%(cat)"> <td class="cat">%%(cat)</td><td class="port">%%(name)</td><td class="ver">%%(ver)</td><td class="newver">%%(newver)</td></tr>
</tbody>
</table>

</body>
</html>