Ignore:
Timestamp:
Oct 20, 2008, 12:24:51 AM (13 years ago)
Author:
Dominic Hargreaves
Message:

Add the ability to whitelist hosts who can change moderated nodes
without explicit moderation - thanks Oliver (fixes #203)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/OpenGuides/Utils.pm

    r1231 r1240  
    1111use URI::Escape;
    1212use MIME::Lite;
     13use Net::Netmask;
     14use List::Util qw( first );
    1315use Data::Validate::URI qw( is_web_uri );
    1416
     
    498500}
    499501
     502=item B<in_moderate_whitelist>
     503
     504 if (OpenGuides::Utils->in_moderate_whitelist( '127.0.0.1' )) {
     505     # skip moderation and apply new verson to published site
     506 }
     507
     508Admins can supply a comma separated list of IP addresses or CIDR-notation
     509subnets indicating the hosts which can bypass enforced moderation. Any
     510values which cannot be parsed by C<NetAddr::IP> will be ignored.
     511
     512=cut
     513
     514sub in_moderate_whitelist {
     515    my ($self, $config, $ip) = @_;
     516    return undef if not defined $ip;
     517
     518    # create NetAddr::IP object of the test IP
     519    my $addr = Net::Netmask->new2($ip) or return undef;
     520
     521    # load the configured whitelist
     522    my @whitelist
     523        = split ',', $config->moderate_whitelist;
     524
     525    # test each entry in the whitelist
     526    return eval{
     527        first { Net::Netmask->new2($_)->match($addr->base) } @whitelist
     528    };
     529}
     530
    500531=back
    501532
Note: See TracChangeset for help on using the changeset viewer.