From 78c547ad66940c0d4d25d04dbd0126301bb89322 Mon Sep 17 00:00:00 2001 From: Wouter van Oijen Date: Fri, 19 May 2006 19:56:37 +0000 Subject: [PATCH] Added missing sub session Fixed whitespace --- lib/WebGUI/LDAPLink.pm | 174 +++++++++++++++++-------------- lib/WebGUI/Operation/LDAPLink.pm | 66 ++++++------ 2 files changed, 127 insertions(+), 113 deletions(-) diff --git a/lib/WebGUI/LDAPLink.pm b/lib/WebGUI/LDAPLink.pm index 3c1e7c34f..957853c7c 100644 --- a/lib/WebGUI/LDAPLink.pm +++ b/lib/WebGUI/LDAPLink.pm @@ -66,41 +66,41 @@ sub bind { my $connectDn = $self->{_ldapLink}->{connectDn}; my $identifier = $self->{_ldapLink}->{identifier}; - if($ldapUrl eq "") { - $self->{_error} = 100; - return 0; + if ($ldapUrl eq "") { + $self->{_error} = 100; + return 0; } elsif ($connectDn eq "") { - $self->{_error} = 101; - return 0; + $self->{_error} = 101; + return 0; } elsif ($identifier eq "") { - $self->{_error} = 102; - return 0; + $self->{_error} = 102; + return 0; } - if($uri = URI->new($ldapUrl)) { - unless($ldap = Net::LDAP->new($uri->host, (port=>($uri->port || 389)))){ - $self->{_error} = 103; - return 0; - } - - $auth = $ldap->bind(dn=>$connectDn, password=>$identifier); - if ($auth->code == 48 || $auth->code == 49){ - $self->{_error} = 104; - }elsif($auth->code > 0){ - $self->{_error} = $auth->code; - } - $self->{_connection} = $ldap; - }else{ - $self->{_error} = 105; - return 0; + if ($uri = URI->new($ldapUrl)) { + unless ($ldap = Net::LDAP->new($uri->host, (port=>($uri->port || 389)))) { + $self->{_error} = 103; + return 0; + } + + $auth = $ldap->bind(dn=>$connectDn, password=>$identifier); + if ($auth->code == 48 || $auth->code == 49) { + $self->{_error} = 104; + } elsif($auth->code > 0) { + $self->{_error} = $auth->code; + } + $self->{_connection} = $ldap; + } else { + $self->{_error} = 105; + return 0; } return $self->{_connection}; } #------------------------------------------------------------------- sub DESTROY { - my $self = shift; - $self->unbind; + my $self = shift; + $self->unbind; undef $self; } @@ -131,7 +131,7 @@ A valid ldap error code. sub getErrorMessage { my $self = shift; - my $errorCode = $_[0] || $self->{_error}; + my $errorCode = shift || $self->{_error}; return "" unless $errorCode; my $i18nCode = "LDAPLink_".$errorCode; my $i18n = WebGUI::International->new($self->session,"AuthLDAP"); @@ -193,15 +193,29 @@ The ldapLinkId of the ldapLink you're creating an object reference for. =cut sub new { - my ( $ldapLinkId, $ldapLink); - my $class = shift; + my ($ldapLinkId, $ldapLink); + my $class = shift; my $session = shift; $ldapLinkId = shift; return undef unless $ldapLinkId; $ldapLink = $session->db->quickHashRef("select * from ldapLink where ldapLinkId=".$session->db->quote($ldapLinkId)); - bless {_session=>$session, _ldapLinkId => $ldapLinkId, _ldapLink => $ldapLink }, $class; + bless {_session=>$session, _ldapLinkId=>$ldapLinkId, _ldapLink=>$ldapLink }, $class; } +#------------------------------------------------------------------- + +=head2 session ( ) + +Returns a reference to the current session. + +=cut + +sub session { + my $self = shift; + return $self->{_session}; +} + + #------------------------------------------------------------------- =head2 getProperty(dn,property) @@ -219,22 +233,22 @@ sub new { =cut sub getProperty { - my $self = shift; - my $ldap = $self->bind; - my $dn = shift; - my $property = shift; - return [] unless($ldap && $dn && $property); - my $results = []; - my $msg = $ldap->search( - base => $dn, - scope => 'sub', - filter => "&(objectClass=*)" - ); - if(!$msg->code && $msg->count > 0 ){ - my $entry = $msg->entry(($msg->count)-1); - $results = $entry->get_value($property,asref => 1); - } - return $results; + my $self = shift; + my $ldap = $self->bind; + my $dn = shift; + my $property = shift; + return [] unless($ldap && $dn && $property); + my $results = []; + my $msg = $ldap->search( + base => $dn, + scope => 'sub', + filter => "&(objectClass=*)" + ); + if (!$msg->code && $msg->count > 0) { + my $entry = $msg->entry(($msg->count)-1); + $results = $entry->get_value($property,asref => 1); + } + return $results; } #------------------------------------------------------------------- @@ -246,42 +260,42 @@ sub getProperty { =cut sub recurseProperty { - my $self = shift; - my $ldap = $self->bind; - my $base = $_[0]; - my $array = $_[1] || []; - my $property = $_[2]; - my $recProperty = $_[3] || $property; - my $count = $_[4] || 0; - return unless($ldap && $base && $property); - - #Prevent infinate recursion - $count++; - return if $count == 99; - - #search the base - my $msg = $ldap->search( - base => $base, - scope => 'sub', - filter => "&(objectClass=*)" - ); - #return if nothing found - return if($msg->code || $msg->count == 0); - #loop through the results - for (my $i = 0; $i < $msg->count; $i++) { - my $entry = $msg->entry($i); - #push all the values stored in the property on to the array stack - my $properties = $entry->get_value($property,asref => 1); - $properties = [] unless ref $properties eq "ARRAY"; - push(@{$array},@{$properties}); - #Loop through the recursive keys - if($property ne $recProperty) { - $properties = $entry->get_value($recProperty,asref => 1); + my $self = shift; + my $ldap = $self->bind; + my $base = $_[0]; + my $array = $_[1] || []; + my $property = $_[2]; + my $recProperty = $_[3] || $property; + my $count = $_[4] || 0; + return unless($ldap && $base && $property); + + #Prevent infinate recursion + $count++; + return if $count == 99; + + #search the base + my $msg = $ldap->search( + base => $base, + scope => 'sub', + filter => "&(objectClass=*)" + ); + #return if nothing found + return if($msg->code || $msg->count == 0); + #loop through the results + for (my $i = 0; $i < $msg->count; $i++) { + my $entry = $msg->entry($i); + #push all the values stored in the property on to the array stack + my $properties = $entry->get_value($property,asref => 1); + $properties = [] unless ref $properties eq "ARRAY"; + push(@{$array},@{$properties}); + #Loop through the recursive keys + if ($property ne $recProperty) { + $properties = $entry->get_value($recProperty,asref => 1); + } + foreach my $prop (@{$properties}) { + $self->recurseProperty($prop,$array,$property,$recProperty,$count); + } } - foreach my $prop (@{$properties}) { - $self->recurseProperty($prop,$array,$property,$recProperty,$count); - } - } } 1; diff --git a/lib/WebGUI/Operation/LDAPLink.pm b/lib/WebGUI/Operation/LDAPLink.pm index e74ff399a..e6c0c4946 100644 --- a/lib/WebGUI/Operation/LDAPLink.pm +++ b/lib/WebGUI/Operation/LDAPLink.pm @@ -284,44 +284,44 @@ links. Each LDAP link is tested and the status of that test is returned. sub www_listLDAPLinks { my $session = shift; - return $session->privilege->adminOnly() unless($session->user->isInGroup(3)); - my ($output, $p, $sth, $data, @row, $i); + return $session->privilege->adminOnly() unless($session->user->isInGroup(3)); + my ($output, $p, $sth, $data, @row, $i); my $i18n = WebGUI::International->new($session,"AuthLDAP"); - my $returnUrl = ""; - if($session->form->process("returnUrl")) { - $returnUrl = ";returnUrl=".$session->url->escape($session->form->process("returnUrl")); - } - $sth = $session->db->read("select * from ldapLink order by ldapLinkName"); - $row[$i] = ' '.$i18n->get("LDAPLink_1076").''.$i18n->get("LDAPLink_1077").''; - $i++; - while ($data = $sth->hashRef) { - $row[$i] = '' - .$session->icon->delete('op=deleteLDAPLink;llid='.$data->{ldapLinkId},$session->url->page(),$i18n->get("LDAPLink_988")) + my $returnUrl = ""; + if ($session->form->process("returnUrl")) { + $returnUrl = ";returnUrl=".$session->url->escape($session->form->process("returnUrl")); + } + $sth = $session->db->read("select * from ldapLink order by ldapLinkName"); + $row[$i] = ' '.$i18n->get("LDAPLink_1076").''.$i18n->get("LDAPLink_1077").''; + $i++; + while ($data = $sth->hashRef) { + $row[$i] = '' + .$session->icon->delete('op=deleteLDAPLink;llid='.$data->{ldapLinkId},$session->url->page(),$i18n->get("LDAPLink_988")) .$session->icon->edit('op=editLDAPLink;llid='.$data->{ldapLinkId}.$returnUrl) .$session->icon->copy('op=copyLDAPLink;llid='.$data->{ldapLinkId}.$returnUrl) .''; - $row[$i] .= ''.$data->{ldapLinkName}.''; + $row[$i] .= ''.$data->{ldapLinkName}.''; - my $ldapLink = WebGUI::LDAPLink->new($session,$data->{ldapLinkId}); - my $status = $i18n->get("LDAPLink_1078"); - if($ldapLink->bind) { - $status = $i18n->get("LDAPLink_1079"); - }else{ - $session->errorHandler->warn($ldapLink->getErrorMessage()); - } - $ldapLink->unbind; - $row[$i] .= ''.$status.''; - $row[$i] .= ''; - $i++; - } - $sth->finish; - $p = WebGUI::Paginator->new($session,$session->url->page('op=listLDAPLinks')); - $p->setDataByArrayRef(\@row); - $output .= ''; - $output .= $p->getPage; - $output .= '
'; - $output .= $p->getBarTraditional; - return _submenu($session,$output,"ldap connection links manage"); + my $ldapLink = WebGUI::LDAPLink->new($session,$data->{ldapLinkId}); + my $status = $i18n->get("LDAPLink_1078"); + if ($ldapLink->bind) { + $status = $i18n->get("LDAPLink_1079"); + } else { + $session->errorHandler->warn($ldapLink->getErrorMessage()); + } + $ldapLink->unbind; + $row[$i] .= ''.$status.''; + $row[$i] .= ''; + $i++; + } + $sth->finish; + $p = WebGUI::Paginator->new($session,$session->url->page('op=listLDAPLinks')); + $p->setDataByArrayRef(\@row); + $output .= ''; + $output .= $p->getPage; + $output .= '
'; + $output .= $p->getBarTraditional; + return _submenu($session,$output,"ldap connection links manage"); }