Bugzilla – Attachment 9640 Details for
Bug 8123
Cronjob to pre-populate/update patrons using LDAP
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
proposed patch
0001-Bug-8123-cronjob-to-pre-populate-Update-patrons-from.patch (text/plain), 3.87 KB, created by
laurenthdl
on 2012-05-18 14:23:37 UTC
(
hide
)
Description:
proposed patch
Filename:
MIME Type:
Creator:
laurenthdl
Created:
2012-05-18 14:23:37 UTC
Size:
3.87 KB
patch
obsolete
>From eb46be86645d79a95bbff04d9c961eb07e90ba07 Mon Sep 17 00:00:00 2001 >From: Henri-Damien LAURENT <henridamien.laurent@biblibre.com> >Date: Fri, 18 May 2012 16:16:46 +0200 >Subject: [PATCH] Bug 8123 : cronjob to pre-populate/Update patrons from ldap > data > >This script is meant to regulary and automatically add user >data from LDAP entries based on the Configuration. >In order to do so, the script supposes that you have a user with read >access or even anonymous access to LDAP and that users have uid. >--- > misc/cronjobs/update_patrons_from_LDAP.pl | 72 +++++++++++++++++++++++++++++ > 1 file changed, 72 insertions(+) > create mode 100644 misc/cronjobs/update_patrons_from_LDAP.pl > >diff --git a/misc/cronjobs/update_patrons_from_LDAP.pl b/misc/cronjobs/update_patrons_from_LDAP.pl >new file mode 100644 >index 0000000..194c1e1 >--- /dev/null >+++ b/misc/cronjobs/update_patrons_from_LDAP.pl >@@ -0,0 +1,72 @@ >+#!/usr/bin/perl >+use Net::LDAP; >+use Net::LDAP::Filter; >+use C4::Auth_with_ldap; >+use C4::Members; >+use C4::Context; >+use C4::Debug; >+use YAML; >+use strict; >+ >+my $dbh = C4::Context->dbh; >+## La bonne façon de faire serait d'exporter les variables de Auth_with_ldap et de les utiliser directement Je pense. >+ >+#Copier coller du début du script. >+ >+my $ldap = C4::Context->config("ldapserver") or die 'No "ldapserver" in server hash from KOHA_CONF: ' . $ENV{KOHA_CONF}; >+my $prefhost = $ldap->{hostname} or die ldapserver_error('hostname'); >+my $base = $ldap->{base} or die ldapserver_error('base'); >+my $ldapname = $ldap->{user}; >+my $ldappassword = $ldap->{pass}; >+our %mapping = %{ $ldap->{mapping} }; >+$debug && warn Dump($ldap); >+ >+# Infos to do an anonymous bind >+ >+my %config = ( >+ anonymous => ( $ldapname and $ldappassword ) ? 0 : 1, >+ replicate => defined( $ldap->{replicate} ) ? $ldap->{replicate} : 1, # add from LDAP to Koha database for new user >+ update => defined( $ldap->{update} ) ? $ldap->{update} : 1, # update from LDAP to Koha database for existing user >+); >+ >+my @hosts = split( ',', $prefhost ); >+my $db = Net::LDAP->new( \@hosts ); >+unless ($db) { >+ warn " host $ldap doesnot exist !"; >+ return 0; >+} >+my $res = ( $config{anonymous} ) ? $db->bind : $db->bind( $ldapname, password => $ldappassword ); >+warn "LDAP Auth impossible : server not responding" if ( $res->code ); >+ >+## based on Koha Members >+#my $filter = Net::LDAP::Filter->new("uid=*"); >+my $filter = Net::LDAP::Filter->new("uid=*"); >+my $userdnsearch = $db->search( base => $base, filter => $filter ); >+$userdnsearch->code and die $userdnsearch->error; >+while ( my $userldapentry = $userdnsearch->shift_entry ) { >+ >+ #warn Data::Dumper::Dumper($userldapentry); >+ my $uid_field = $mapping{userid}->{is} or die ldapserver_error("mapping for 'userid'"); >+ my $userid = $userldapentry->{$uid_field}; >+ $debug && warn Dump($userldapentry); >+ >+ my %borrower = C4::Auth_with_ldap::ldap_entry_2_hash( $userldapentry, $userid ); >+ $debug and print "checkpw_ldap received \%borrower w/ " . keys(%borrower), " keys: ", join( ' ', keys %borrower ), "\n"; >+ my ( $borrowernumber, $cardnumber, $savedpw ); >+ ( $borrowernumber, $cardnumber, $userid, $savedpw ) = C4::Auth_with_ldap::exists_local( $borrower{'userid'} ); >+ if ($borrowernumber) { >+ ( $config{update} ) and my $c2 = C4::Auth_with_ldap::update_local( $userid, "!", $borrowernumber, \%borrower ) || ''; >+ ( $cardnumber eq $c2 ) or warn "update_local returned cardnumber '$c2' instead of '$cardnumber'"; >+ } else { >+ if ( $config{replicate} ) { >+ $borrowernumber = eval { AddMember(%borrower) }; >+ if ($@) { >+ warn Dump(%borrower), " $@"; >+ } >+ } >+ } >+} >+$db->unbind; >+### NOTICE It could also rely on data in LDAP and populate the data in Koha... >+#Pb a) Search the whole annuary >+# b) Adds data that could be useless in Koha. >-- >1.7.10 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 8123
:
9640
|
9642