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 $connectDn = $self->{_ldapLink}->{connectDn};
|
||||||
my $identifier = $self->{_ldapLink}->{identifier};
|
my $identifier = $self->{_ldapLink}->{identifier};
|
||||||
|
|
||||||
if($ldapUrl eq "") {
|
if ($ldapUrl eq "") {
|
||||||
$self->{_error} = 100;
|
$self->{_error} = 100;
|
||||||
return 0;
|
return 0;
|
||||||
} elsif ($connectDn eq "") {
|
} elsif ($connectDn eq "") {
|
||||||
$self->{_error} = 101;
|
$self->{_error} = 101;
|
||||||
return 0;
|
return 0;
|
||||||
} elsif ($identifier eq "") {
|
} elsif ($identifier eq "") {
|
||||||
$self->{_error} = 102;
|
$self->{_error} = 102;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($uri = URI->new($ldapUrl)) {
|
if ($uri = URI->new($ldapUrl)) {
|
||||||
unless($ldap = Net::LDAP->new($uri->host, (port=>($uri->port || 389)))){
|
unless ($ldap = Net::LDAP->new($uri->host, (port=>($uri->port || 389)))) {
|
||||||
$self->{_error} = 103;
|
$self->{_error} = 103;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$auth = $ldap->bind(dn=>$connectDn, password=>$identifier);
|
$auth = $ldap->bind(dn=>$connectDn, password=>$identifier);
|
||||||
if ($auth->code == 48 || $auth->code == 49){
|
if ($auth->code == 48 || $auth->code == 49) {
|
||||||
$self->{_error} = 104;
|
$self->{_error} = 104;
|
||||||
}elsif($auth->code > 0){
|
} elsif($auth->code > 0) {
|
||||||
$self->{_error} = $auth->code;
|
$self->{_error} = $auth->code;
|
||||||
}
|
}
|
||||||
$self->{_connection} = $ldap;
|
$self->{_connection} = $ldap;
|
||||||
}else{
|
} else {
|
||||||
$self->{_error} = 105;
|
$self->{_error} = 105;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return $self->{_connection};
|
return $self->{_connection};
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
sub DESTROY {
|
sub DESTROY {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
$self->unbind;
|
$self->unbind;
|
||||||
undef $self;
|
undef $self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -131,7 +131,7 @@ A valid ldap error code.
|
||||||
|
|
||||||
sub getErrorMessage {
|
sub getErrorMessage {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $errorCode = $_[0] || $self->{_error};
|
my $errorCode = shift || $self->{_error};
|
||||||
return "" unless $errorCode;
|
return "" unless $errorCode;
|
||||||
my $i18nCode = "LDAPLink_".$errorCode;
|
my $i18nCode = "LDAPLink_".$errorCode;
|
||||||
my $i18n = WebGUI::International->new($self->session,"AuthLDAP");
|
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
|
=cut
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ( $ldapLinkId, $ldapLink);
|
my ($ldapLinkId, $ldapLink);
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
$ldapLinkId = shift;
|
$ldapLinkId = shift;
|
||||||
return undef unless $ldapLinkId;
|
return undef unless $ldapLinkId;
|
||||||
$ldapLink = $session->db->quickHashRef("select * from ldapLink where ldapLinkId=".$session->db->quote($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)
|
=head2 getProperty(dn,property)
|
||||||
|
|
@ -219,22 +233,22 @@ sub new {
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub getProperty {
|
sub getProperty {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $ldap = $self->bind;
|
my $ldap = $self->bind;
|
||||||
my $dn = shift;
|
my $dn = shift;
|
||||||
my $property = shift;
|
my $property = shift;
|
||||||
return [] unless($ldap && $dn && $property);
|
return [] unless($ldap && $dn && $property);
|
||||||
my $results = [];
|
my $results = [];
|
||||||
my $msg = $ldap->search(
|
my $msg = $ldap->search(
|
||||||
base => $dn,
|
base => $dn,
|
||||||
scope => 'sub',
|
scope => 'sub',
|
||||||
filter => "&(objectClass=*)"
|
filter => "&(objectClass=*)"
|
||||||
);
|
);
|
||||||
if(!$msg->code && $msg->count > 0 ){
|
if (!$msg->code && $msg->count > 0) {
|
||||||
my $entry = $msg->entry(($msg->count)-1);
|
my $entry = $msg->entry(($msg->count)-1);
|
||||||
$results = $entry->get_value($property,asref => 1);
|
$results = $entry->get_value($property,asref => 1);
|
||||||
}
|
}
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -246,42 +260,42 @@ sub getProperty {
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub recurseProperty {
|
sub recurseProperty {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $ldap = $self->bind;
|
my $ldap = $self->bind;
|
||||||
my $base = $_[0];
|
my $base = $_[0];
|
||||||
my $array = $_[1] || [];
|
my $array = $_[1] || [];
|
||||||
my $property = $_[2];
|
my $property = $_[2];
|
||||||
my $recProperty = $_[3] || $property;
|
my $recProperty = $_[3] || $property;
|
||||||
my $count = $_[4] || 0;
|
my $count = $_[4] || 0;
|
||||||
return unless($ldap && $base && $property);
|
return unless($ldap && $base && $property);
|
||||||
|
|
||||||
#Prevent infinate recursion
|
#Prevent infinate recursion
|
||||||
$count++;
|
$count++;
|
||||||
return if $count == 99;
|
return if $count == 99;
|
||||||
|
|
||||||
#search the base
|
#search the base
|
||||||
my $msg = $ldap->search(
|
my $msg = $ldap->search(
|
||||||
base => $base,
|
base => $base,
|
||||||
scope => 'sub',
|
scope => 'sub',
|
||||||
filter => "&(objectClass=*)"
|
filter => "&(objectClass=*)"
|
||||||
);
|
);
|
||||||
#return if nothing found
|
#return if nothing found
|
||||||
return if($msg->code || $msg->count == 0);
|
return if($msg->code || $msg->count == 0);
|
||||||
#loop through the results
|
#loop through the results
|
||||||
for (my $i = 0; $i < $msg->count; $i++) {
|
for (my $i = 0; $i < $msg->count; $i++) {
|
||||||
my $entry = $msg->entry($i);
|
my $entry = $msg->entry($i);
|
||||||
#push all the values stored in the property on to the array stack
|
#push all the values stored in the property on to the array stack
|
||||||
my $properties = $entry->get_value($property,asref => 1);
|
my $properties = $entry->get_value($property,asref => 1);
|
||||||
$properties = [] unless ref $properties eq "ARRAY";
|
$properties = [] unless ref $properties eq "ARRAY";
|
||||||
push(@{$array},@{$properties});
|
push(@{$array},@{$properties});
|
||||||
#Loop through the recursive keys
|
#Loop through the recursive keys
|
||||||
if($property ne $recProperty) {
|
if ($property ne $recProperty) {
|
||||||
$properties = $entry->get_value($recProperty,asref => 1);
|
$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;
|
1;
|
||||||
|
|
|
||||||
|
|
@ -284,44 +284,44 @@ links. Each LDAP link is tested and the status of that test is returned.
|
||||||
|
|
||||||
sub www_listLDAPLinks {
|
sub www_listLDAPLinks {
|
||||||
my $session = shift;
|
my $session = shift;
|
||||||
return $session->privilege->adminOnly() unless($session->user->isInGroup(3));
|
return $session->privilege->adminOnly() unless($session->user->isInGroup(3));
|
||||||
my ($output, $p, $sth, $data, @row, $i);
|
my ($output, $p, $sth, $data, @row, $i);
|
||||||
my $i18n = WebGUI::International->new($session,"AuthLDAP");
|
my $i18n = WebGUI::International->new($session,"AuthLDAP");
|
||||||
my $returnUrl = "";
|
my $returnUrl = "";
|
||||||
if($session->form->process("returnUrl")) {
|
if ($session->form->process("returnUrl")) {
|
||||||
$returnUrl = ";returnUrl=".$session->url->escape($session->form->process("returnUrl"));
|
$returnUrl = ";returnUrl=".$session->url->escape($session->form->process("returnUrl"));
|
||||||
}
|
}
|
||||||
$sth = $session->db->read("select * from ldapLink order by ldapLinkName");
|
$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>';
|
$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++;
|
$i++;
|
||||||
while ($data = $sth->hashRef) {
|
while ($data = $sth->hashRef) {
|
||||||
$row[$i] = '<tr><td valign="top" class="tableData">'
|
$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->delete('op=deleteLDAPLink;llid='.$data->{ldapLinkId},$session->url->page(),$i18n->get("LDAPLink_988"))
|
||||||
.$session->icon->edit('op=editLDAPLink;llid='.$data->{ldapLinkId}.$returnUrl)
|
.$session->icon->edit('op=editLDAPLink;llid='.$data->{ldapLinkId}.$returnUrl)
|
||||||
.$session->icon->copy('op=copyLDAPLink;llid='.$data->{ldapLinkId}.$returnUrl)
|
.$session->icon->copy('op=copyLDAPLink;llid='.$data->{ldapLinkId}.$returnUrl)
|
||||||
.'</td>';
|
.'</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 $ldapLink = WebGUI::LDAPLink->new($session,$data->{ldapLinkId});
|
||||||
my $status = $i18n->get("LDAPLink_1078");
|
my $status = $i18n->get("LDAPLink_1078");
|
||||||
if($ldapLink->bind) {
|
if ($ldapLink->bind) {
|
||||||
$status = $i18n->get("LDAPLink_1079");
|
$status = $i18n->get("LDAPLink_1079");
|
||||||
}else{
|
} else {
|
||||||
$session->errorHandler->warn($ldapLink->getErrorMessage());
|
$session->errorHandler->warn($ldapLink->getErrorMessage());
|
||||||
}
|
}
|
||||||
$ldapLink->unbind;
|
$ldapLink->unbind;
|
||||||
$row[$i] .= '<td valign="top" class="tableData">'.$status.'</td>';
|
$row[$i] .= '<td valign="top" class="tableData">'.$status.'</td>';
|
||||||
$row[$i] .= '</tr>';
|
$row[$i] .= '</tr>';
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
$sth->finish;
|
$sth->finish;
|
||||||
$p = WebGUI::Paginator->new($session,$session->url->page('op=listLDAPLinks'));
|
$p = WebGUI::Paginator->new($session,$session->url->page('op=listLDAPLinks'));
|
||||||
$p->setDataByArrayRef(\@row);
|
$p->setDataByArrayRef(\@row);
|
||||||
$output .= '<table border="1" cellpadding="3" cellspacing="0" align="center">';
|
$output .= '<table border="1" cellpadding="3" cellspacing="0" align="center">';
|
||||||
$output .= $p->getPage;
|
$output .= $p->getPage;
|
||||||
$output .= '</table>';
|
$output .= '</table>';
|
||||||
$output .= $p->getBarTraditional;
|
$output .= $p->getBarTraditional;
|
||||||
return _submenu($session,$output,"ldap connection links manage");
|
return _submenu($session,$output,"ldap connection links manage");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue