PageSpec ip() (implementation match_ip) supports globs, but it would be useful to be able to write say 154.12.192.0/22 to block a range of addresses that aren't matchable with a simple glob.

Perhaps not in the same PageSpec, but it might also be useful to support looking up AS assignments and blocking ranges that way, see https://feeding.cloud.geek.nz/posts/blocking-comment-spammers-ikiwiki/. For the example IP above, this would be 6,171 IP ranges, and considerably more lines in banned_users without features like these.

Jon, 2025-01-24

#!/usr/bin/perl
# Copyright © 2008 Joey Hess <joey@ikiwiki.info>
# Copyright © 2025 Jonathan Dowland <jon@dow.land>
# Licensed under the GNU GPL, version 2, or any later version published by the
# Free Software Foundation

use warnings;
use strict;
use IkiWiki 3.00;
use Net::Netmask;

package IkiWiki::PageSpec;

sub match_ipblock ($$;@) {
    shift;
    my $string=shift;
    my %params=@_;

    if (! exists $params{ip}) {
        return IkiWiki::ErrorReason->new("no IP specified");
    }
    my $block = Net::Netmask->safe_new($string);
    unless ($block) {
        return IkiWiki::ErrorReason->new("invalid netmask specified");
    }
    if ($block->match($params{ip})) {
        return IkiWiki::SuccessReason->new("IP is in block $string");
    } else {
        return IkiWiki::FailReason->new("IP is $params{ip}, not in block $string");
    }
}

1

If I look at this further I'd move it into a plugin rather than add Net::Netmask to IkiWiki.pm. Jon, 2025-01-24

I've altered the code block above; I'm now testing this plugin on my site. Jon, 2025-01-27