Commit b488bbe921cf269e251813d3ba307bb60a837099

Authored by Georg GH. Hopp
Committed by Georg Hopp
1 parent 56b9c94a

change mail alias handling

now i have separated mailAlias into mailAliasRole and mailAliasPerson.
mailAliasRole holds mail aliases that are not assoziated to a concrete
person but to an organizational role
mailAliasPerson holds mail aliases for concrete people
  1 +require 'SystemData'
  2 +
  3 +class MailAliasPerson < SystemData
  4 + attr_accessor :mail, :maildrop, :surname, :name
  5 +
  6 + def initialize(args = {})
  7 + super(args)
  8 +
  9 + @mail = args[:mail]
  10 + @maildrop = args[:maildrop]
  11 + @surname = args[:surname]
  12 + @name = args[:name]
  13 + end
  14 +
  15 + def site
  16 + @mail.sub(/.*@/, '')
  17 + end
  18 +end
1 require 'SystemData' 1 require 'SystemData'
2 2
3 -class MailAlias < SystemData 3 +class MailAliasRole < SystemData
4 attr_accessor :mail, :maildrop, :user 4 attr_accessor :mail, :maildrop, :user
5 5
6 def initialize(args = {}) 6 def initialize(args = {})
1 require 'User' 1 require 'User'
2 require 'Group' 2 require 'Group'
3 require 'Site' 3 require 'Site'
4 -require 'MailAlias' 4 +require 'MailAliasRole'
  5 +require 'MailAliasPerson'
5 require 'MailAccount' 6 require 'MailAccount'
6 7
7 class SystemDataBackend 8 class SystemDataBackend
@@ -23,8 +24,12 @@ class SystemDataBackend @@ -23,8 +24,12 @@ class SystemDataBackend
23 load(:Site) 24 load(:Site)
24 end 25 end
25 26
26 - def mailAliases  
27 - load(:MailAlias) 27 + def mailAliasRoles
  28 + load(:MailAliasRole)
  29 + end
  30 +
  31 + def mailAliasPeople
  32 + load(:MailAliasPerson)
28 end 33 end
29 34
30 def mailAccounts 35 def mailAccounts
@@ -54,8 +59,12 @@ class SystemDataBackend @@ -54,8 +59,12 @@ class SystemDataBackend
54 end 59 end
55 end 60 end
56 61
57 - def mailAliasesBySite(site)  
58 - mailAliases.find_all{|mail| mail.site == site.name} 62 + def mailAliasRolesBySite(site)
  63 + mailAliasRoles.find_all{|mail| mail.site == site.name}
  64 + end
  65 +
  66 + def mailAliasPeopleBySite(site)
  67 + mailAliasPeople.find_all{|mail| mail.site == site.name}
59 end 68 end
60 69
61 def mailAccountsBySite(site) 70 def mailAccountsBySite(site)
@@ -18,27 +18,36 @@ @@ -18,27 +18,36 @@
18 :memberuid => :members 18 :memberuid => :members
19 } 19 }
20 20
21 - LDAP_SITE_MAP = {:o => :name} 21 + LDAP_MAILALIASPERSON_MAP = {
  22 + :sn => :surname,
  23 + :cn => :name
  24 + }
22 25
23 LDAP_MAP = { 26 LDAP_MAP = {
24 - :User => LDAP_USER_MAP,  
25 - :Group => LDAP_GROUP_MAP,  
26 - :Site => LDAP_SITE_MAP 27 + :User => LDAP_USER_MAP,
  28 + :Group => LDAP_GROUP_MAP,
  29 + :Site => { :o => :name },
  30 + :MailAliasRole => { :cn => :user },
  31 + :MailAliasPerson => LDAP_MAILALIASPERSON_MAP,
  32 + :mailAccount => { :homedirectory => :home }
27 } 33 }
28 34
29 LDAP_FILTER = { 35 LDAP_FILTER = {
30 - :User => Net::LDAP::Filter::eq('objectClass', 'posixAccount'),  
31 - :Group => Net::LDAP::Filter::eq('objectClass', 'posixGroup'),  
32 - :Site => Net::LDAP::Filter::eq('objectClass', 'organization') &  
33 - (~Net::LDAP::Filter::eq('o', 'hosting')),  
34 - :MailAlias => Net::LDAP::Filter::eq('objectClass', 'mailAlias'),  
35 - :MailAccount => Net::LDAP::Filter::eq('objectClass', 'mailAccount') 36 + :User => '(objectClass=posixAccount)',
  37 + :Group => '(objectClass=posixGroup)',
  38 + :Site => '(&(objectClass=organization)(!(o=hosting)))',
  39 + :MailAliasRole => '(&(objectClass=MailAlias)(objectClass=organizationalrole))',
  40 + :MailAliasPerson => '(&(objectClass=MailAlias)(objectClass=person))',
  41 + :MailAccount => '(objectClass=mailAccount)'
36 } 42 }
37 43
38 LDAP_OBJECTCLASS = { 44 LDAP_OBJECTCLASS = {
39 - :User => [ 'account', 'posixAccount', 'shadowAccount' ],  
40 - :Group => 'posixGroup',  
41 - :Site => 'organization' 45 + :User => [ 'account', 'posixAccount', 'shadowAccount' ],
  46 + :Group => 'posixGroup',
  47 + :Site => 'organization',
  48 + :MailAliasRole => [ 'organizationalRole', 'MailAlias' ],
  49 + :MailAliasPerson => [ 'person', 'MailAlias' ],
  50 + :MailAccount => [ 'person', 'MailAccount' ]
42 } 51 }
43 52
44 LDAP_LAMBDA_USER = lambda do |entry| 53 LDAP_LAMBDA_USER = lambda do |entry|
@@ -68,7 +77,7 @@ @@ -68,7 +77,7 @@
68 77
69 @ldapData[kind][:internal] = @ldap.search( 78 @ldapData[kind][:internal] = @ldap.search(
70 :base => ldapBase(kind), 79 :base => ldapBase(kind),
71 - :filter => LDAP_FILTER[kind] 80 + :filter => Net::LDAP::Filter::construct(LDAP_FILTER[kind])
72 ) 81 )
73 end 82 end
74 83
@@ -84,9 +93,9 @@ @@ -84,9 +93,9 @@
84 ydata.merge!({ map[key] || key => value.size==1?value[0]:value.to_a }) 93 ydata.merge!({ map[key] || key => value.size==1?value[0]:value.to_a })
85 end 94 end
86 ydata 95 ydata
87 - end if ! @ldapData[kind][:external] 96 + end if ! @ldapData[kind][:external] && @ldapData[kind][:internal]
88 97
89 - @ldapData[kind][:external].each{|ydata| yield ydata} 98 + @ldapData[kind][:external].each{|ydata| yield ydata} if @ldapData[kind][:external]
90 end 99 end
91 100
92 def update(kind, data) 101 def update(kind, data)
@@ -164,7 +173,7 @@ @@ -164,7 +173,7 @@
164 def ldapBase(kind) 173 def ldapBase(kind)
165 case(kind) 174 case(kind)
166 when :User, :Group: @systemDn 175 when :User, :Group: @systemDn
167 - when :Site, :MailAlias, :MailAccount: @hostingDn 176 + when :Site, :MailAliasRole, :MailAliasPerson, :MailAccount: @hostingDn
168 end 177 end
169 end 178 end
170 179
@@ -26,15 +26,24 @@ end @@ -26,15 +26,24 @@ end
26 26
27 backend.sites.each do |site| 27 backend.sites.each do |site|
28 puts 'site: ' + site.name 28 puts 'site: ' + site.name
29 - puts ' MailAliases:'  
30 - backend.mailAliasesBySite(site).each{|account| puts ' ' + account.mail} 29 + puts ' MailAliasRoles:'
  30 + backend.mailAliasRolesBySite(site).each{|account| puts ' ' + account.mail}
  31 + puts
  32 + puts ' MailAliasPeople:'
  33 + backend.mailAliasPeopleBySite(site).each{|account| puts ' ' + account.mail}
31 puts 34 puts
32 puts ' MailAccounts:' 35 puts ' MailAccounts:'
33 backend.mailAccountsBySite(site).each{|account| puts ' ' + account.mail} 36 backend.mailAccountsBySite(site).each{|account| puts ' ' + account.mail}
34 puts 37 puts
35 end 38 end
36 39
37 -backend.mailAliases.each do |mailAlias| 40 +backend.mailAliasRoles.each do |mailAlias|
  41 + puts 'mailAlias: '+mailAlias.mail.inspect+','+mailAlias.maildrop.inspect
  42 +end
  43 +
  44 +puts
  45 +
  46 +backend.mailAliasPeople.each do |mailAlias|
38 puts 'mailAlias: '+mailAlias.mail.inspect+','+mailAlias.maildrop.inspect 47 puts 'mailAlias: '+mailAlias.mail.inspect+','+mailAlias.maildrop.inspect
39 end 48 end
40 49
Please register or login to post a comment