From e3bb0d856b2c61f608a3b0e9237d4179a2757975 Mon Sep 17 00:00:00 2001 From: Frank Dillon Date: Wed, 4 May 2005 11:05:16 +0000 Subject: [PATCH] Added LDAPLink Operation for creating new LDAP Connections --- lib/WebGUI/Operation/LDAPLink.pm | 183 +++++++++++++++++++++++++++++++ 1 file changed, 183 insertions(+) create mode 100644 lib/WebGUI/Operation/LDAPLink.pm diff --git a/lib/WebGUI/Operation/LDAPLink.pm b/lib/WebGUI/Operation/LDAPLink.pm new file mode 100644 index 000000000..a44cdbf1f --- /dev/null +++ b/lib/WebGUI/Operation/LDAPLink.pm @@ -0,0 +1,183 @@ +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) if ($title); + my $help = shift; + my $ac = WebGUI::AdminConsole->new("ldapconnections"); + if ($help) { + $ac->setHelp($help); + } + $ac->addSubmenuItem(WebGUI::URL::page('op=editLDAPLink&llid=new'), WebGUI::International::get("LDAPLink_982")); + if ($session{form}{op} eq "editLDAPLink" && $session{form}{llid} ne "new") { + $ac->addSubmenuItem(WebGUI::URL::page('op=editLDAPLink&llid='.$session{form}{llid}), WebGUI::International::get("LDAPLink_983")); + $ac->addSubmenuItem(WebGUI::URL::page('op=copyLDAPLink&llid='.$session{form}{llid}), WebGUI::International::get("LDAPLink_984")); + $ac->addSubmenuItem(WebGUI::URL::page('op=deleteLDAPLink&llid='.$session{form}{llid}), WebGUI::International::get("LDAPLink_985")); + $ac->addSubmenuItem(WebGUI::URL::page('op=listLDAPLinks'), WebGUI::International::get("LDAPLink_986")); + } + 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->readOnly($session{form}{llid},WebGUI::International::get("LDAPLink_991")); + $f->text("ldapLinkName",WebGUI::International::get("LDAPLink_992"),$db{ldapLinkName}); + $f->text("ldapUrl",WebGUI::International::get("LDAPLink_993"),$db{ldapUrl}); + $f->text("connectDn",WebGUI::International::get("LDAPLink_994"),$db{connectDn}); + $f->password("identifier",WebGUI::International::get("LDAPLink_995"),$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); + return www_listLDAPLinks(); +} + +#------------------------------------------------------------------- +sub www_listLDAPLinks { + return WebGUI::Privilege::adminOnly() unless(WebGUI::Grouping::isInGroup(3)); + my ($output, $p, $sth, $data, @row, $i); + $sth = WebGUI::SQL->read("select * from ldapLink order by ldapLinkName"); + $row[$i] = ' '.WebGUI::International::get("LDAPLink_1076").''.WebGUI::International::get("LDAPLink_1077").''; + $i++; + while ($data = $sth->hashRef) { + $row[$i] = '' + .deleteIcon('op=deleteLDAPLink&llid='.$data->{ldapLinkId},WebGUI::URL::page(),WebGUI::International::get("LDAPLink_988")) + .editIcon('op=editLDAPLink&llid='.$data->{ldapLinkId}) + .copyIcon('op=copyLDAPLink&llid='.$data->{ldapLinkId}) + .''; + $row[$i] .= ''.$data->{ldapLinkName}.''; + + my $ldapLink = WebGUI::LDAPLink->new($data->{ldapLinkId}); + my $status = WebGUI::International::get("LDAPLink_1078"); + if($ldapLink->bind) { + $status = WebGUI::International::get("LDAPLink_1079"); + }else{ + WebGUI::ErrorHandler::warn($ldapLink->getErrorMessage()); + } + $ldapLink->unbind; + $row[$i] .= ''.$status.''; + $row[$i] .= ''; + $i++; + } + $sth->finish; + $p = WebGUI::Paginator->new(WebGUI::URL::page('op=listLDAPLinks')); + $p->setDataByArrayRef(\@row); + $output .= ''; + $output .= $p->getPage; + $output .= '
'; + $output .= $p->getBarTraditional; + return _submenu($output,"ldap connection links manage"); +} + + +1;