Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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 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

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
86 changes: 85 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,48 @@ 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) {
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} = '<a href="https://www.freshports.org/' . $cat . '/' . $row->{name} . '">' . $row->{name} . '</a>';

$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 +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()
Expand Down Expand Up @@ -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";
Expand Down
105 changes: 105 additions & 0 deletions templates/index-category.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<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; }
.resultshead { color: #FFFFFF; font-weight: bold; background-color: #999999; }

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

.resultshead a { color: #FFFFFF; text-decoration: none; }

.box { border: 1px solid #000000; padding: 6px; }
//-->
</style>
<script type="text/javascript">
var fproc = null;

function FilterResults() {
if (!fproc) {
var button = document.getElementById('submitbutton');
if (!button)
return;

button.setAttribute('disabled', 'disabled');
button.value = 'Processing...';

fproc = setTimeout(DoFilter, 100);
}
}

function DoFilter() {

let category = document.getElementById('filter_category');
let button = document.getElementById('submitbutton');
if (!category || !button) { return; }

let regex = new RegExp(category.value, 'i');

document.querySelectorAll("[data-cat]").forEach(function (row) {
console.log(row);

let row_category = row.getAttribute('data-cat');
console.log(row_category);

if (!regex.test(row_category)) {
row.style.display = 'none';
} else {
// Why the try/catch here? Leaving it in for now
try {
row.style.display = 'table-row';
} catch(e) {
row.style.display = 'block';
}
}
});

fproc = null;

button.value = 'Apply';
button.removeAttribute('disabled');
}
</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>

<span class="box">
Filter Category (regex): <input type="text" id="filter_category" />
<input type="button" value="Apply" id="submitbutton" onclick="FilterResults()" />
</span>

<br /><br />

<table id="results" cellspacing="1" cellpadding="2">
<thead>
<tr id="resultshead">
<td>Category</td>
<td>Port</td>
<td>Current</td>
<td>New</td>
</tr>
</thead>
<tbody id="resultsbody">
%%:[catrow] <tr class="resultsrow catrow" data-cat="%%(cat)"><td class="cat">%%(cat)</td><td class="catdata" colspan="3">%%(catdata)</td></tr>
%%:[portrow] <tr class="resultsrow portrow" data-cat="%%(cat)"> <td class="cat">%%(cat)</td><td class="port">%%(namelink)</td><td class="ver">%%(ver)</td><td class="newver">%%(newver)</td></tr>
</tbody>
</table>

</body>
</html>