195 lines
9 KiB
Perl
195 lines
9 KiB
Perl
package WebGUI::Operation::LDAPLink;
|
|
|
|
#-------------------------------------------------------------------
|
|
# WebGUI is Copyright 2001-2005 Plain Black Corporation.
|
|
#-------------------------------------------------------------------
|
|
# Please read the legal notices (docs/legal.txt) and the license
|
|
# (docs/license.txt) that came with this distribution before using
|
|
# this software.
|
|
#-------------------------------------------------------------------
|
|
# http://www.plainblack.com info@plainblack.com
|
|
#-------------------------------------------------------------------
|
|
|
|
use strict;
|
|
use Tie::CPHash;
|
|
use WebGUI::AdminConsole;
|
|
use WebGUI::LDAPLink;
|
|
use WebGUI::Grouping;
|
|
use WebGUI::Icon;
|
|
use WebGUI::Id;
|
|
use WebGUI::International;
|
|
use WebGUI::Paginator;
|
|
use WebGUI::Privilege;
|
|
use WebGUI::Session;
|
|
use WebGUI::SQL;
|
|
use WebGUI::URL;
|
|
|
|
#-------------------------------------------------------------------
|
|
sub _submenu {
|
|
my $workarea = shift;
|
|
my $title = shift;
|
|
$title = WebGUI::International::get($title,"AuthLDAP") if ($title);
|
|
my $help = shift;
|
|
my $ac = WebGUI::AdminConsole->new("ldapconnections");
|
|
if ($help) {
|
|
$ac->setHelp($help,"AuthLDAP");
|
|
}
|
|
my $returnUrl = "";
|
|
if($session{form}{returnUrl}) {
|
|
$returnUrl = "&returnUrl=".WebGUI::URL::escape($session{form}{returnUrl});
|
|
}
|
|
$ac->addSubmenuItem(WebGUI::URL::page('op=editLDAPLink&llid=new'.$returnUrl), WebGUI::International::get("LDAPLink_982","AuthLDAP"));
|
|
if ($session{form}{op} eq "editLDAPLink" && $session{form}{llid} ne "new") {
|
|
$ac->addSubmenuItem(WebGUI::URL::page('op=editLDAPLink&llid='.$session{form}{llid}.$returnUrl), WebGUI::International::get("LDAPLink_983","AuthLDAP"));
|
|
$ac->addSubmenuItem(WebGUI::URL::page('op=copyLDAPLink&llid='.$session{form}{llid}.$returnUrl), WebGUI::International::get("LDAPLink_984","AuthLDAP"));
|
|
$ac->addSubmenuItem(WebGUI::URL::page('op=deleteLDAPLink&llid='.$session{form}{llid}), WebGUI::International::get("LDAPLink_985","AuthLDAP"));
|
|
$ac->addSubmenuItem(WebGUI::URL::page('op=listLDAPLinks'.$returnUrl), WebGUI::International::get("LDAPLink_986","AuthLDAP"));
|
|
}
|
|
return $ac->render($workarea, $title);
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub www_copyLDAPLink {
|
|
return WebGUI::Privilege::insufficient unless (WebGUI::Grouping::isInGroup(3));
|
|
my (%db);
|
|
tie %db, 'Tie::CPHash';
|
|
%db = WebGUI::SQL->quickHash("select * from ldapLink where ldapLinkId=".quote($session{form}{llid}));
|
|
$db{ldapLinkId} = "new";
|
|
$db{ldapLinkName} = "Copy of ".$db{ldapLinkName};
|
|
WebGUI::SQL->setRow("ldapLink","ldapLinkId",\%db);
|
|
#WebGUI::SQL->write("insert into databaseLink (databaseLinkId,title,DSN,username,identifier) values (".quote(WebGUI::Id::generate()).", ".quote($db{title}." (copy)").", ".quote($db{DSN}).", ".quote($db{username}).", ".quote($db{identifier}).")");
|
|
$session{form}{op} = "listLDAPLinks";
|
|
return www_listLDAPLinks();
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub www_deleteLDAPLink {
|
|
return WebGUI::Privilege::insufficient unless (WebGUI::Grouping::isInGroup(3));
|
|
WebGUI::SQL->write("delete from ldapLink where ldapLinkId=".quote($session{form}{llid}));
|
|
$session{form}{op} = "listLDAPLinks";
|
|
return www_listLDAPLinks();
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub www_editLDAPLink {
|
|
return WebGUI::Privilege::insufficient unless (WebGUI::Grouping::isInGroup(3));
|
|
my ($output, %db, $f);
|
|
tie %db, 'Tie::CPHash';
|
|
%db = WebGUI::SQL->quickHash("select * from ldapLink where ldapLinkId=".quote($session{form}{llid}));
|
|
|
|
$f = WebGUI::HTMLForm->new( -extras=>'autocomplete="off"' );
|
|
$f->hidden("op","editLDAPLinkSave");
|
|
$f->hidden("llid",$session{form}{llid});
|
|
$f->hidden("returnUrl",$session{form}{returnUrl});
|
|
$f->readOnly($session{form}{llid},WebGUI::International::get("LDAPLink_991","AuthLDAP"));
|
|
$f->text("ldapLinkName",WebGUI::International::get("LDAPLink_992","AuthLDAP"),$db{ldapLinkName});
|
|
$f->text("ldapUrl",WebGUI::International::get("LDAPLink_993","AuthLDAP"),$db{ldapUrl});
|
|
$f->text("connectDn",WebGUI::International::get("LDAPLink_994","AuthLDAP"),$db{connectDn});
|
|
$f->password("identifier",WebGUI::International::get("LDAPLink_995","AuthLDAP"),$db{identifier});
|
|
|
|
$f->text("ldapUserRDN",WebGUI::International::get(9,'AuthLDAP'),$db{ldapUserRDN});
|
|
$f->text("ldapIdentity",WebGUI::International::get(6,'AuthLDAP'),$db{ldapIdentity});
|
|
$f->text("ldapIdentityName",WebGUI::International::get(7,'AuthLDAP'),$db{ldapIdentityName});
|
|
$f->text("ldapPasswordName",WebGUI::International::get(8,'AuthLDAP'),$db{ldapPasswordName});
|
|
$f->yesNo(
|
|
-name=>"ldapSendWelcomeMessage",
|
|
-value=>$db{ldapSendWelcomeMessage},
|
|
-label=>WebGUI::International::get(868)
|
|
);
|
|
$f->textarea(
|
|
-name=>"ldapWelcomeMessage",
|
|
-value=>$db{ldapWelcomeMessage},
|
|
-label=>WebGUI::International::get(869)
|
|
);
|
|
$f->template(
|
|
-name=>"ldapAccountTemplate",
|
|
-value=>$db{ldapAccountTemplate},
|
|
-namespace=>"Auth/LDAP/Account",
|
|
-label=>WebGUI::International::get("account template","AuthLDAP")
|
|
);
|
|
$f->template(
|
|
-name=>"ldapCreateAccountTemplate",
|
|
-value=>$db{ldapCreateAccountTemplate},
|
|
-namespace=>"Auth/LDAP/Create",
|
|
-label=>WebGUI::International::get("create account template","AuthLDAP")
|
|
);
|
|
$f->template(
|
|
-name=>"ldapLoginTemplate",
|
|
-value=>$db{ldapLoginTemplate},
|
|
-namespace=>"Auth/LDAP/Login",
|
|
-label=>WebGUI::International::get("login template","AuthLDAP")
|
|
);
|
|
|
|
$f->submit;
|
|
$output .= $f->print;
|
|
return _submenu($output,"LDAPLink_990","ldap connection add/edit");
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub www_editLDAPLinkSave {
|
|
return WebGUI::Privilege::insufficient unless (WebGUI::Grouping::isInGroup(3));
|
|
my $properties = {};
|
|
$properties->{ldapLinkId} = $session{form}{llid};
|
|
$properties->{ldapLinkName} = $session{form}{ldapLinkName};
|
|
$properties->{ldapUrl} = $session{form}{ldapUrl};
|
|
$properties->{connectDn} = $session{form}{connectDn};
|
|
$properties->{identifier} = $session{form}{identifier};
|
|
$properties->{ldapUserRDN} = $session{form}{ldapUserRDN};
|
|
$properties->{ldapIdentity} = $session{form}{ldapIdentity};
|
|
$properties->{ldapIdentityName} = $session{form}{ldapIdentityName};
|
|
$properties->{ldapPasswordName} = $session{form}{ldapPasswordName};
|
|
$properties->{ldapSendWelcomeMessage} = WebGUI::FormProcessor::yesNo("ldapSendWelcomeMessage");
|
|
$properties->{ldapWelcomeMessage} = WebGUI::FormProcessor::textarea("ldapWelcomeMessage");
|
|
$properties->{ldapAccountTemplate} = WebGUI::FormProcessor::template("ldapAccountTemplate");
|
|
$properties->{ldapCreateAccountTemplate} = WebGUI::FormProcessor::template("ldapCreateAccountTemplate");
|
|
$properties->{ldapLoginTemplate} = WebGUI::FormProcessor::template("ldapLoginTemplate");
|
|
WebGUI::SQL->setRow("ldapLink","ldapLinkId",$properties);
|
|
if($session{form}{returnUrl}) {
|
|
WebGUI::HTTP::setRedirect($session{form}{returnUrl});
|
|
}
|
|
return www_listLDAPLinks();
|
|
}
|
|
|
|
#-------------------------------------------------------------------
|
|
sub www_listLDAPLinks {
|
|
return WebGUI::Privilege::adminOnly() unless(WebGUI::Grouping::isInGroup(3));
|
|
my ($output, $p, $sth, $data, @row, $i);
|
|
my $returnUrl = "";
|
|
if($session{form}{returnUrl}) {
|
|
$returnUrl = "&returnUrl=".WebGUI::URL::escape($session{form}{returnUrl});
|
|
}
|
|
$sth = WebGUI::SQL->read("select * from ldapLink order by ldapLinkName");
|
|
$row[$i] = '<tr><td valign="top" class="tableData"> </td><td valign="top" class="tableData">'.WebGUI::International::get("LDAPLink_1076","AuthLDAP").'</td><td>'.WebGUI::International::get("LDAPLink_1077","AuthLDAP").'</td></tr>';
|
|
$i++;
|
|
while ($data = $sth->hashRef) {
|
|
$row[$i] = '<tr><td valign="top" class="tableData">'
|
|
.deleteIcon('op=deleteLDAPLink&llid='.$data->{ldapLinkId},WebGUI::URL::page(),WebGUI::International::get("LDAPLink_988","AuthLDAP"))
|
|
.editIcon('op=editLDAPLink&llid='.$data->{ldapLinkId}.$returnUrl)
|
|
.copyIcon('op=copyLDAPLink&llid='.$data->{ldapLinkId}.$returnUrl)
|
|
.'</td>';
|
|
$row[$i] .= '<td valign="top" class="tableData">'.$data->{ldapLinkName}.'</td>';
|
|
|
|
my $ldapLink = WebGUI::LDAPLink->new($data->{ldapLinkId});
|
|
my $status = WebGUI::International::get("LDAPLink_1078","AuthLDAP");
|
|
if($ldapLink->bind) {
|
|
$status = WebGUI::International::get("LDAPLink_1079","AuthLDAP");
|
|
}else{
|
|
WebGUI::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(WebGUI::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($output,"ldap connection links manage");
|
|
}
|
|
|
|
|
|
1;
|