ispman/lib/ISPMan UserMan.pm,1.58.4.9,1.58.4.10
Pedro Algarvio <[email protected]> Thu, 26 Oct 2006 03:31:05 +0000
| Newsgroups | gmane.comp.isp.ispman.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvsroot/ispman/ispman/lib/ISPMan
In directory sc8-pr-cvs2.sourceforge.net:/tmp/cvs-serv21910/lib/ISPMan
Modified Files:
Tag: dev_1_3-cyrus_virtdomain2
UserMan.pm
Log Message:
So stupid, I broke functionality with the HEAD merges, now fixed! I guess...
Index: UserMan.pm
===================================================================
RCS file: /cvsroot/ispman/ispman/lib/ISPMan/UserMan.pm,v
retrieving revision 1.58.4.9
retrieving revision 1.58.4.10
diff -u -d -r1.58.4.9 -r1.58.4.10
--- UserMan.pm 25 Oct 2006 23:50:05 -0000 1.58.4.9
+++ UserMan.pm 26 Oct 2006 03:31:03 -0000 1.58.4.10
@@ -50,7 +50,6 @@
addUserFileServerProcess
containsInvalidMailAliases
- getDNForMailAddress
);
$VERSION = '0.01';
@@ -59,8 +58,8 @@
my $self = shift;
my $r = shift;
my $domain = $r->param("ispmanDomain");
- print "Sorry cannot add users to a replica domain<br>"
- . "Instead add users to its master domain which is ";
+ print
+"Sorry cannot add users to a replica domain<br>Instead add users to its master domain which is ";
my $replicaMaster =
$self->getEntry(
"ispmanDomain=$domain, $self->{'Config'}->{'ldapBaseDN'}",
@@ -125,9 +124,7 @@
my $domainUserCount = $self->getUserCount($domain);
if ( $domainMaxUsers > 0 && $domainUserCount >= $domainMaxUsers ) {
$self->{'message'} =
- "Max accounts limit exceeded. <br>"
- . "Your limit is $domainMaxUsers <br>"
- . "You cannot create any more users.";
+"Max accounts limit exceeded. <br>Your limit is $domainMaxUsers <br>You cannot create any more users.";
print $self->{'message'};
return;
}
@@ -137,14 +134,6 @@
$self->create_uid( $r->param("userid"), $r->param("ispmanDomain") );
$r->param( "uid", $_uid );
- # check uid conflicts with existing mail addresses
- if ( my $check = $self->getDNForMailAddress(
- join '@', ($r->param("userid"), $r->param("ispmanDomain"))) ) {
- print "Unable to create user \"$_uid\", because mail address is<br>"
- . "already blocked by \"$check\".";
- return;
- }
-
# build new DN for user
my $dn =
"uid=$_uid, ou=users, ispmanDomain=$domain, "
@@ -154,11 +143,17 @@
$self->prepareBranchForDN(
"ou=users, ispmanDomain=$domain, @{[$self->getConf('ldapBaseDN')]}");
- # get domain info and supply it to session data
- # so we can use it in user ldif template
+# get domain info and supply it to session data so we can use it in user ldif template
my $domain_info = $self->getDomainInfo( $r->param("ispmanDomain") );
$r->param( "domaininfo", $domain_info );
+# moved to user template
+#my $homeDirectory=join '/', ($domain_info->{'homeDirectory'}, "users", $r->param("uid"), "");
+#my $cn=($r->param("givenName") && $r->param("sn"))? join " ", ($r->param("givenName"), $r->param("sn")) :$r->param("userid");
+#$r->param("cn", $cn);
+#$r->param("sn", ($r->param("sn")? $r->param("sn"):$r->param("userid")));
+#$r->param("homeDirectory", $homeDirectory);
+
# validate ftp quota
if ( $r->param("FTPQuotaMBytes") !~ /\d\d*/
|| $r->param("FTPQuotaMBytes") < 0 )
@@ -178,42 +173,39 @@
# add user to LDAP from user ldif template
if ( $self->addDataFromLdif( "templates/users.ldif.template", $r ) ) {
+
+ # reread user from LDAP to get computed values
+ my $_userInfo=$self->getUserInfo($_uid);
+
if ( $r->param("mailHost") ) {
- $self->addProcessToHost( $domain, $r->param("mailHost"),
- "createMailbox", "mailbox=$_uid" );
- my $quota = $r->param("mailQuota") * 1024;
- $self->addProcessToHost( $domain, $r->param("mailHost"),
- "setMailboxQuota", "mailbox=$_uid"a=$quota" );
+ my $quota=$r->param("mailQuota") * 1024;
+ $self->addProcessToHost($domain, $_userInfo->{'mailHost'},
+ "createMailbox",
+ "mailbox=".$_userInfo->{'mailLocalAddress'});
+
+ $self->addProcessToHost($domain, $_userInfo->{'mailHost'},
+ "setMailboxQuota",
+ "mailbox=".$_userInfo->{'mailLocalAddress'}."&".
+ "quota=$quota");
}
- # send the process to method addUserFileServerProcess
- # the process will only be sent to fileHost if one is defined
- # if not defined then we fall back to the old method and
- # send to the filserver group
+ # send the process to method addUserFileServerProcess
+ # the process will only be sent to fileHost if one is defined
+ # if not defined then we fall back to the old method and send to the filserver group
# passing domain, username, process and username as params
- my $_userInfo = $self->getUserInfo($_uid);
- $self->addUserFileServerProcess( $domain, $_uid, 'createHomeDirectory',
- "uid=$_uid&homeDirectory=$_userInfo->{'homeDirectory'}&"
- . "uidNumber=$_userInfo->{'uidNumber'}&"
- . "gidNumber=$_userInfo->{'gidNumber'}" );
+ $self->addUserFileServerProcess( $domain, $_uid,
+ 'createHomeDirectory',
+ "uid=$_uid&".
+ "homeDirectory=$_userInfo->{'homeDirectory'}&".
+ "uidNumber=$_userInfo->{'uidNumber'}&".
+ "gidNumber=$_userInfo->{'gidNumber'}");
+
return 1;
}
}
-sub getDNForMailAddress {
- my $self = shift;
- my $found = "";
- while ( ! $found && (my $mail = shift )) {
- my $entries =
- $self->getEntriesAsHashRef( $self->{'Config'}->{'ldapBaseDN'},
- "|(mailLocalAddress=$mail)(mailAlias=$mail)" );
- ($found) = keys %$entries;
- }
- return $found;
-}
-
sub getUserInfo {
my $self = shift;
my $uid = shift;
@@ -255,6 +247,7 @@
print "Deleting $dn<br>";
$self->{'user'} = $self->{'ldap'}->getEntryAsHashRef($dn);
+
#it is possible that as user has multiple uids.
#hint
#aghaffar_ispman_org
@@ -265,31 +258,33 @@
# first send processes.
- # %%% new method %%
- # send the process to method addUserFileServerProcess
- # the process will only be sent to fileHost if one is defined
- # if not defined then we fall back to the old method and
- # send to the filserver group
+# %%% new method %%
+# send the process to method addUserFileServerProcess
+# the process will only be sent to fileHost if one is defined
+# if not defined then we fall back to the old method and send to the filserver group
+
+# passing domain, username, process and username,homedirecory,uid,gid as params
$self->addUserFileServerProcess(
$self->{'user'}{'ispmanDomain'},
$self->{'user'}{'uid'},
'deleteHomeDirectory',
- join '&',
- (
- "uid=" . $self->{'user'}{'uid'},
- "homeDirectory=" . $self->{'user'}{'homeDirectory'},
- "uidNumber=" . $self->{'user'}{'uidNumber'},
- "gidNumber=" . $self->{'user'}{'gidNumber'}
+ join '&', (
+ "uid=" . $self->{'user'}{'uid'},
+ "homeDirectory=" . $self->{'user'}{'homeDirectory'},
+ "uidNumber=" . $self->{'user'}{'uidNumber'},
+ "gidNumber=" . $self->{'user'}{'gidNumber'}
)
);
if ( $self->{'user'}{"mailHost"} ) {
$self->addProcessToHost(
- $self->{'user'}{'ispmanDomain'}, $self->{'user'}{"mailHost"},
- "deleteMailbox", "mailbox=$self->{'user'}{'uid'}"
- );
+ $self->{'user'}{'ispmanDomain'},
+ $self->{'user'}{"mailHost"},
+ "deleteMailbox",
+ "mailbox=".$self->{'user'}{'mailLocalAddress'});
}
+
$self->deleteEntry($dn);
}
@@ -297,9 +292,9 @@
my $self = shift;
my $r = shift;
- my $dn = $self->getUserDN( $r->param("ispmanDomain"), $r->param("uid") );
+ my $dn = $self->getUserDN( $r->param("ispmanDomain"), $r->param("uid") );
- $self->killUser($dn);
+ $self->killUser( $dn );
print $self->refreshSignal( $r->param("ispmanDomain") );
@@ -317,26 +312,28 @@
}
# added by Michael Bunk, Jan 2006
-sub containsInvalidMailAliases {
- my $self = shift;
- my $aliases = shift;
- my $masterDomain = shift;
- my $replicas = $self->getReplicasOfDomain($masterDomain);
- my @validDomains;
- if ( defined($replicas) ) { @validDomains = keys %$replicas; }
- push @validDomains, $masterDomain;
- OUTER: foreach (@$aliases) {
- next if (/^[\w\.\-\+]*$/);
- if (/^[\w\.\-\+]*@([\w\.\-]+)$/) {
- foreach my $d (@validDomains) {
- next OUTER if ( $d eq $1 );
- }
- }
- return ( 1,
- _("Mail aliases to users from foreign domains are forbidden: '$_'")
- );
+sub containsInvalidMailAliases
+{
+ my $self = shift;
+ my $aliases = shift;
+ my $masterDomain = shift;
+ my $replicas = $self->getReplicasOfDomain($masterDomain);
+ my @validDomains;
+ if(defined($replicas)) { @validDomains = keys %$replicas; }
+ push @validDomains, $masterDomain;
+OUTER: foreach(@$aliases)
+ {
+ next if(/^[\w\.\-\+]*$/);
+ if(/^[\w\.\-\+]*@([\w\.\-]+)$/)
+ {
+ foreach my $d (@validDomains)
+ {
+ next OUTER if($d eq $1);
+ }
}
- return ( 0, undef );
+ return (1, _("Mail aliases to users from foreign domains are forbidden: '$_'"));
+ }
+ return (0, undef);
}
sub update_user {
@@ -344,7 +341,7 @@
my $r = shift;
my $dn = $self->getUserDN( $r->param("ispmanDomain"), $r->param("uid") );
my $userInfo = $self->getUserInfo( $r->param("uid") );
- my $data = {};
+ my $data = {};
for (
qw(sn givenName homeDirectory loginShell mailLocalAddress mailRoutingAddress FTPStatus FTPQuotaMBytes)
)
@@ -360,41 +357,32 @@
$data->{'mailAlias'} =
$self->as_arrayref( split( /\s+/, $r->param("mailAlias") ) );
- # check uniqueness of mail aliases
- if ( my $check =
- $self->getDNForMailAddress( split( /\s+/, $r->param("mailAlias") ) ) )
- {
- print "Mail aliases conflict with \"$check\".<br>";
- print "Aborting update!";
- return 0;
- }
-
# added by Michael Bunk, Jan 2006
- my ( $invalid, $errmsg ) =
- $self->containsInvalidMailAliases( $data->{'mailAlias'},
- $userInfo->{'ispmanDomain'} );
- if ($invalid) {
- print $errmsg;
- return 0;
+ my ($invalid, $errmsg) = $self->containsInvalidMailAliases($data->{'mailAlias'},
+ $userInfo->{'ispmanDomain'});
+ if($invalid)
+ {
+ print $errmsg;
+ return 0;
}
$data->{'mailForwardingAddress'} =
$self->as_arrayref( split( /\s+/, $r->param("mailForwardingAddress") ) );
- # don't set objectclasses here! It would dishonor non-ispman
+ # don't set objectclasses here! It would dishonor non-ispman
# objectclasses and attributes. Update issues are handled by
# ldifupdate anyways.
# $data->{'objectClass'} = $self->{'Config'}{'ispmanUserObjectclasses'};
if ( $userInfo->{'mailHost'} && $r->param("mailQuota") ) {
- my $quota = $r->param("mailQuota") * 1024;
- my $mailbox = $r->param("uid");
+ my $quota = $r->param("mailQuota") * 1024;
+ my $mailbox=$r->param("uid");
unless ( $quota == $userInfo->{'mailQuota'} ) {
$data->{'mailQuota'} = $quota;
$self->addProcessToHost(
- $userInfo->{'ispmanDomain'}, $userInfo->{'mailHost'},
- "setMailboxQuota", "mailbox=$mailbox"a=$quota"
- );
+ $userInfo->{'ispmanDomain'},
+ $userInfo->{'mailHost'},
+ "setMailboxQuota", "mailbox=$mailbox"a=$quota");
}
}
@@ -428,14 +416,13 @@
my ( $uid, $domain, $values ) = @_;
# added by Michael Bunk, Jan 2006
- my ( $invalid, $errmsg ) =
- $self->containsInvalidMailAliases( $values, $domain );
- if ($invalid) {
- print $errmsg;
-
- # actually, we should return a Net::LDAP::Message to return the same
- # type as addUserAttributeValues()
- return 0;
+ my ($invalid, $errmsg) = $self->containsInvalidMailAliases($values, $domain);
+ if($invalid)
+ {
+ print $errmsg;
+ # actually, we should return a Net::LDAP::Message to return the same
+ # type as addUserAttributeValues()
+ return 0;
}
return $self->addUserAttributeValues( $uid, $domain, 'mailAlias', $values );
@@ -446,14 +433,13 @@
my ( $uid, $domain, $values ) = @_;
# added by Michael Bunk, Jan 2006
- my ( $invalid, $errmsg ) =
- $self->containsInvalidMailAliases( $values, $domain );
- if ($invalid) {
- print $errmsg;
-
- # actually, we should return a Net::LDAP::Message to return the same
- # type as addUserAttributeValues()
- return 0;
+ my ($invalid, $errmsg) = $self->containsInvalidMailAliases($values, $domain);
+ if($invalid)
+ {
+ print $errmsg;
+ # actually, we should return a Net::LDAP::Message to return the same
+ # type as addUserAttributeValues()
+ return 0;
}
return $self->replaceUserAttributeValues( $uid, $domain, 'mailAlias',
@@ -513,6 +499,7 @@
sub getUserDN {
my $self = shift;
my ( $domain, $uid ) = @_;
+ $uid =~ s/\.|\@/_/g;
return join( ",", "uid=$uid", $self->getUsersBranchDN($domain) );
}
@@ -608,11 +595,14 @@
{ $attribute => $_values } );
}
-# generate unique uid from userid and domain
sub create_uid {
my $self = shift;
my ( $userId, $domain ) = @_;
+ # here is the logic to convert userName to user_domain_tld
+ # If you don't want this behaviour and just wasn't uid uncomment the next line;
+ # return $userId;
+
$domain =~ s/\./_/g;
$userId =~ s/\./_/g;
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642