[Koha-devel] Kanopy and SIP2 hack

Mark Alexander marka at pobox.com
Fri Oct 12 19:46:12 CEST 2018


Our little library is preparing to use the Kanopy video streaming
service.  Kanopy can use SIP2 to query our Koha server for the purpose
of user authentication.  That's great; I can enable SIP2 pretty
easily.

The problem is that our librarian wants to put limits on which patrons
can use Kanopy.  The idea is that we don't want to allow more than
one person per household to be able stream videos; otherwise mom, pop,
and all the kids could go crazy one weekend on a Buffy The Vampire Slayer
binge, for example.

But Kanopy and Koha don't have a way to impose this kind of limit.
So I came up with the following idea, which does seem to work in
my test VM:

1. Add a new patron attribute called "KANOPY_OK", which has a yes/no value.
   Set it to yes for those patrons that will be allowed access to Kanopy.

2. Hack the SIP server code for "handle patron status" to check the incoming client's
   IP address against a Kanopy-provided list of IP addresses.  If there is a match,
   authenticate the patron only if their "KANOPY_OK" atribute is "yes" (actually "1").

But I hate the fact that I had to hack Koha to do this (see part of
the hack below).  Am I'm going at this the wrong way?  Would it make
more sense to enhance the plugin architecture to add a SIP2 patron
filter function like the one below?  Is this just too ugly to ever
be considered seriously?

Thanks in advance,
Mark

P.S. Here's the main part of the hack, which is a function that is called
from handle_patron_status and handle_patron_info.

my @kanopy_ips = (
  "208.66.24.46",
  "104.239.197.182",
  "18.209.148.51",
  "34.232.89.121",
  "34.234.81.211",
  "34.235.227.70",
  "34.235.53.173",
  "52.203.108.44"
);

sub sip2_check_patron {
    my ( $patron, $server ) = @_;

    if ( $patron ) {
        my $ipaddr = $server->{server}->{client}->peerhost;
        foreach my $kanopy ( @kanopy_ips ) {
            if ( $ipaddr =~ /^(::ffff:)?\Q$kanopy\E$/ ) {
                my $borrowernumber = $patron->{borrowernumber};
                my $value = C4::Members::Attributes::GetBorrowerAttributeValue( $borrowernumber, 'KANOPY_OK' $
                return $value eq "1";
            }
        }
    }
    return 1;
}


More information about the Koha-devel mailing list