Added missing sub session
Fixed whitespace
This commit is contained in:
parent
8e683580f4
commit
78c547ad66
2 changed files with 127 additions and 113 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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] = '<tr><td valign="top" class="tableData"> </td><td valign="top" class="tableData">'.$i18n->get("LDAPLink_1076").'</td><td>'.$i18n->get("LDAPLink_1077").'</td></tr>';
|
||||
$i++;
|
||||
while ($data = $sth->hashRef) {
|
||||
$row[$i] = '<tr><td valign="top" class="tableData">'
|
||||
.$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] = '<tr><td valign="top" class="tableData"> </td><td valign="top" class="tableData">'.$i18n->get("LDAPLink_1076").'</td><td>'.$i18n->get("LDAPLink_1077").'</td></tr>';
|
||||
$i++;
|
||||
while ($data = $sth->hashRef) {
|
||||
$row[$i] = '<tr><td valign="top" class="tableData">'
|
||||
.$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)
|
||||
.'</td>';
|
||||
$row[$i] .= '<td valign="top" class="tableData">'.$data->{ldapLinkName}.'</td>';
|
||||
$row[$i] .= '<td valign="top" class="tableData">'.$data->{ldapLinkName}.'</td>';
|
||||
|
||||
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] .= '<td valign="top" class="tableData">'.$status.'</td>';
|
||||
$row[$i] .= '</tr>';
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
$p = WebGUI::Paginator->new($session,$session->url->page('op=listLDAPLinks'));
|
||||
$p->setDataByArrayRef(\@row);
|
||||
$output .= '<table border="1" cellpadding="3" cellspacing="0" align="center">';
|
||||
$output .= $p->getPage;
|
||||
$output .= '</table>';
|
||||
$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] .= '<td valign="top" class="tableData">'.$status.'</td>';
|
||||
$row[$i] .= '</tr>';
|
||||
$i++;
|
||||
}
|
||||
$sth->finish;
|
||||
$p = WebGUI::Paginator->new($session,$session->url->page('op=listLDAPLinks'));
|
||||
$p->setDataByArrayRef(\@row);
|
||||
$output .= '<table border="1" cellpadding="3" cellspacing="0" align="center">';
|
||||
$output .= $p->getPage;
|
||||
$output .= '</table>';
|
||||
$output .= $p->getBarTraditional;
|
||||
return _submenu($session,$output,"ldap connection links manage");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue