Updated to take their configurable parameters from the config file.
This commit is contained in:
parent
55108689b4
commit
0f2350d4c5
5 changed files with 46 additions and 45 deletions
|
|
@ -31,43 +31,41 @@ sub _alias {
|
|||
sub process {
|
||||
my (@date, $userId, $u, $uri, $port, %args, $fieldName, $ldap, $search, $a, $b);
|
||||
@date = WebGUI::DateTime::localtime();
|
||||
if ($date[3] == 6) { # only do this at 6 am.
|
||||
if ($session{config}{syncProfilesToLDAP} == 1) {
|
||||
$a = WebGUI::SQL->read("select userId from users where authMethod='LDAP'");
|
||||
while (($userId) = $a->array) {
|
||||
$u = WebGUI::User->new($userId);
|
||||
$uri = URI->new($u->ldapURL);
|
||||
if ($uri->port < 1) {
|
||||
$port = 389;
|
||||
} else {
|
||||
$port = $uri->port;
|
||||
}
|
||||
%args = (port => $port);
|
||||
$ldap = Net::LDAP->new($uri->host, %args);
|
||||
if ($ldap) {
|
||||
$ldap->bind;
|
||||
$search = $ldap->search (base => $uri->dn, filter => $u->connectDN);
|
||||
if (defined $search->entry(0)) {
|
||||
$b = WebGUI::SQL->read("select fieldName from userProfileField where profileCategoryId<>4");
|
||||
while (($fieldName) = $b->array) {
|
||||
if ($search->entry(0)->get_value(_alias($fieldName)) ne "") {
|
||||
WebGUI::SQL->write("replace into userProfileData
|
||||
(userId,fieldName,fieldData) values ("
|
||||
.$userId.","
|
||||
.quote($fieldName).","
|
||||
.quote($search->entry(0)->get_value(_alias($fieldName)))
|
||||
.")");
|
||||
}
|
||||
if ($date[3] == $session{config}{SyncProfilesToLDAP_hour}) {
|
||||
$a = WebGUI::SQL->read("select userId from users where authMethod='LDAP'");
|
||||
while (($userId) = $a->array) {
|
||||
$u = WebGUI::User->new($userId);
|
||||
$uri = URI->new($u->ldapURL);
|
||||
if ($uri->port < 1) {
|
||||
$port = 389;
|
||||
} else {
|
||||
$port = $uri->port;
|
||||
}
|
||||
%args = (port => $port);
|
||||
$ldap = Net::LDAP->new($uri->host, %args);
|
||||
if ($ldap) {
|
||||
$ldap->bind;
|
||||
$search = $ldap->search (base => $uri->dn, filter => $u->connectDN);
|
||||
if (defined $search->entry(0)) {
|
||||
$b = WebGUI::SQL->read("select fieldName from userProfileField where profileCategoryId<>4");
|
||||
while (($fieldName) = $b->array) {
|
||||
if ($search->entry(0)->get_value(_alias($fieldName)) ne "") {
|
||||
WebGUI::SQL->write("replace into userProfileData
|
||||
(userId,fieldName,fieldData) values ("
|
||||
.$userId.","
|
||||
.quote($fieldName).","
|
||||
.quote($search->entry(0)->get_value(_alias($fieldName)))
|
||||
.")");
|
||||
}
|
||||
$b->finish;
|
||||
$ldap->unbind;
|
||||
} else {
|
||||
print "Couldn't connect to LDAP host ".$uri->host." to find user ".$u->username." (".$userId.").\n";
|
||||
}
|
||||
$b->finish;
|
||||
$ldap->unbind;
|
||||
} else {
|
||||
print "Couldn't connect to LDAP host ".$uri->host." to find user ".$u->username." (".$userId.").\n";
|
||||
}
|
||||
}
|
||||
$a->finish;
|
||||
}
|
||||
$a->finish;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue