|
|
|
1 |
# -*- coding: utf-8 -*- |
2 |
# |
3 |
# Univention Directory Manager Mappings |
4 |
# direcory manager module for UDM mappings |
5 |
# |
6 |
# Copyright 2017 Univention GmbH |
7 |
# |
8 |
# http://www.univention.de/ |
9 |
# |
10 |
# All rights reserved. |
11 |
# |
12 |
# The source code of this program is made available |
13 |
# under the terms of the GNU Affero General Public License version 3 |
14 |
# (GNU AGPL V3) as published by the Free Software Foundation. |
15 |
# |
16 |
# Binary versions of this program provided by Univention to you as |
17 |
# well as other copyrighted, protected or trademarked materials like |
18 |
# Logos, graphics, fonts, specific documentations and configurations, |
19 |
# cryptographic keys etc. are subject to a license agreement between |
20 |
# you and Univention and not subject to the GNU AGPL V3. |
21 |
# |
22 |
# In the case you use this program under the terms of the GNU AGPL V3, |
23 |
# the program is provided in the hope that it will be useful, |
24 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
25 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26 |
# GNU Affero General Public License for more details. |
27 |
# |
28 |
# You should have received a copy of the GNU Affero General Public |
29 |
# License with the Debian GNU/Linux or Univention distribution in file |
30 |
# /usr/share/common-licenses/AGPL-3; if not, see |
31 |
# <http://www.gnu.org/licenses/>. |
32 |
|
33 |
from univention.admin.layout import Tab, Group |
34 |
import univention.admin.filter |
35 |
import univention.admin.handlers |
36 |
import univention.admin.password |
37 |
import univention.admin.allocators |
38 |
import univention.admin.localization |
39 |
import apt |
40 |
|
41 |
translation = univention.admin.localization.translation('univention.admin.handlers.settings') |
42 |
_ = translation.translate |
43 |
|
44 |
OC = "univentionUDMMapping" |
45 |
|
46 |
module = 'settings/udm_mapping' |
47 |
superordinate = 'settings/cn' |
48 |
childs = 0 |
49 |
operations = ['add', 'edit', 'remove', 'search', 'move'] |
50 |
short_description = _('Settings: UDM Mapping') |
51 |
long_description = '' |
52 |
options = {} |
53 |
property_descriptions = { |
54 |
'name': univention.admin.property( |
55 |
short_description=_('UDM mapping name'), |
56 |
long_description='', |
57 |
syntax=univention.admin.syntax.string, |
58 |
multivalue=False, |
59 |
include_in_default_search=True, |
60 |
options=[], |
61 |
required=True, |
62 |
may_change=True, |
63 |
identifies=True |
64 |
), |
65 |
'filename': univention.admin.property( |
66 |
short_description=_('UDM mapping file name'), |
67 |
long_description='', |
68 |
syntax=univention.admin.syntax.BaseFilename, |
69 |
multivalue=False, |
70 |
options=[], |
71 |
required=True, |
72 |
may_change=True, |
73 |
default='', |
74 |
identifies=False |
75 |
), |
76 |
'data': univention.admin.property( |
77 |
short_description=_('UDM mapping data'), |
78 |
long_description='', |
79 |
syntax=univention.admin.syntax.Base64Bzip2Text, |
80 |
multivalue=False, |
81 |
options=[], |
82 |
required=True, |
83 |
may_change=True, |
84 |
identifies=False |
85 |
), |
86 |
'active': univention.admin.property( |
87 |
short_description=_('Active'), |
88 |
long_description='', |
89 |
syntax=univention.admin.syntax.TrueFalseUp, |
90 |
default='FALSE', |
91 |
multivalue=False, |
92 |
options=[], |
93 |
required=False, |
94 |
may_change=True, |
95 |
identifies=False |
96 |
), |
97 |
'appidentifier': univention.admin.property( |
98 |
short_description=_('App identifier'), |
99 |
long_description='', |
100 |
syntax=univention.admin.syntax.TextArea, |
101 |
multivalue=True, |
102 |
options=[], |
103 |
required=False, |
104 |
may_change=True, |
105 |
identifies=False |
106 |
), |
107 |
'package': univention.admin.property( |
108 |
short_description=_('Software package'), |
109 |
long_description='', |
110 |
syntax=univention.admin.syntax.string, |
111 |
multivalue=False, |
112 |
options=[], |
113 |
required=False, |
114 |
may_change=True, |
115 |
identifies=False |
116 |
), |
117 |
'packageversion': univention.admin.property( |
118 |
short_description=_('Software package version'), |
119 |
long_description='', |
120 |
syntax=univention.admin.syntax.DebianPackageVersion, |
121 |
multivalue=False, |
122 |
options=[], |
123 |
required=False, |
124 |
may_change=True, |
125 |
identifies=False |
126 |
), |
127 |
'ucsversionstart': univention.admin.property( |
128 |
short_description=_('Minimal UCS version'), |
129 |
long_description='', |
130 |
syntax=univention.admin.syntax.UCSVersion, |
131 |
multivalue=False, |
132 |
options=[], |
133 |
required=False, |
134 |
may_change=True, |
135 |
identifies=False |
136 |
), |
137 |
'ucsversionend': univention.admin.property( |
138 |
short_description=_('Maximal UCS version'), |
139 |
long_description='', |
140 |
syntax=univention.admin.syntax.UCSVersion, |
141 |
multivalue=False, |
142 |
options=[], |
143 |
required=False, |
144 |
may_change=True, |
145 |
identifies=False |
146 |
), |
147 |
'messagecatalog': univention.admin.property( |
148 |
short_description=_('GNU message catalog for translations'), |
149 |
long_description='GNU message catalog (syntax: <language tag> <Base64 encoded GNU message catalog>)', |
150 |
syntax=univention.admin.syntax.Localesubdirname_and_GNUMessageCatalog, |
151 |
multivalue=True, |
152 |
include_in_default_search=False, |
153 |
options=[], |
154 |
required=False, |
155 |
may_change=True, |
156 |
identifies=False, |
157 |
), |
158 |
} |
159 |
|
160 |
layout = [ |
161 |
Tab(_('General'), _('Basic values'), layout=[ |
162 |
Group(_('General UDM mapping settings'), layout=[ |
163 |
["name"], |
164 |
["filename"], |
165 |
["data"], |
166 |
["messagecatalog"], |
167 |
]), |
168 |
Group(_('Metadata'), layout=[ |
169 |
["package"], |
170 |
["packageversion"], |
171 |
["appidentifier"], |
172 |
]), |
173 |
Group(_('UCS Version Dependencies'), layout=[ |
174 |
["ucsversionstart"], |
175 |
["ucsversionend"], |
176 |
]), |
177 |
Group(_('Activated'), layout=[ |
178 |
["active"], |
179 |
]), |
180 |
]), |
181 |
] |
182 |
|
183 |
mapping = univention.admin.mapping.mapping() |
184 |
mapping.register('name', 'cn', None, univention.admin.mapping.ListToString) |
185 |
mapping.register('filename', 'univentionUDMMappingFilename', None, univention.admin.mapping.ListToString) |
186 |
mapping.register('data', 'univentionUDMMappingData', univention.admin.mapping.mapBase64, univention.admin.mapping.unmapBase64) |
187 |
mapping.register('active', 'univentionUDMMappingActive', None, univention.admin.mapping.ListToString) |
188 |
mapping.register('appidentifier', 'univentionAppIdentifier') |
189 |
mapping.register('package', 'univentionOwnedByPackage', None, univention.admin.mapping.ListToString) |
190 |
mapping.register('packageversion', 'univentionOwnedByPackageVersion', None, univention.admin.mapping.ListToString) |
191 |
mapping.register('ucsversionstart', 'univentionUCSVersionStart', None, univention.admin.mapping.ListToString) |
192 |
mapping.register('ucsversionend', 'univentionUCSVersionEnd', None, univention.admin.mapping.ListToString) |
193 |
# messagecatalog is handled via object._post_map and object._post_unmap defined below |
194 |
|
195 |
|
196 |
class object(univention.admin.handlers.simpleLdap): |
197 |
module = module |
198 |
|
199 |
def _ldap_addlist(self): |
200 |
ocs = ['top', 'univentionObjectMetadata', OC] |
201 |
|
202 |
return [ |
203 |
('objectClass', ocs), |
204 |
] |
205 |
|
206 |
def _ldap_pre_modify(self): |
207 |
diff_keys = [key for key in self.info.keys() if self.info.get(key) != self.oldinfo.get(key) and key not in ('active', 'appidentifier')] |
208 |
if not diff_keys: # check for trivial change |
209 |
return |
210 |
if not self.hasChanged('package'): |
211 |
old_version = self.oldinfo.get('packageversion', '0') |
212 |
if not apt.apt_pkg.version_compare(self['packageversion'], old_version) > -1: |
213 |
raise univention.admin.uexceptions.valueInvalidSyntax(_('packageversion: Version must not be lower than the current one.')) |
214 |
|
215 |
def _post_unmap(self, info, values): |
216 |
info['messagecatalog'] = [] |
217 |
messagecatalog_ldap_attribute = "univentionMessageCatalog" |
218 |
messagecatalog_ldap_attribute_and_tag_prefix = "%s;entry-lang-" % (messagecatalog_ldap_attribute,) |
219 |
for ldap_attribute, value_list in values.items(): |
220 |
if ldap_attribute.startswith(messagecatalog_ldap_attribute_and_tag_prefix): |
221 |
language_tag = ldap_attribute.split(messagecatalog_ldap_attribute_and_tag_prefix, 1)[1] |
222 |
mo_data_base64 = univention.admin.mapping.unmapBase64(value_list) |
223 |
info['messagecatalog'].append((language_tag, mo_data_base64)) |
224 |
return info |
225 |
|
226 |
def _post_map(self, modlist, diff): |
227 |
messagecatalog_ldap_attribute = "univentionMessageCatalog" |
228 |
messagecatalog_ldap_attribute_and_tag_prefix = "%s;entry-lang-" % (messagecatalog_ldap_attribute,) |
229 |
for property_name, old_value, new_value in diff: |
230 |
if property_name == 'messagecatalog': |
231 |
old_dict = dict(old_value) |
232 |
new_dict = dict(new_value) |
233 |
for language_tag, old_mo_data_base64 in old_dict.items(): |
234 |
ldap_attribute = ''.join((messagecatalog_ldap_attribute_and_tag_prefix, language_tag)) |
235 |
new_mo_data_base64 = new_dict.get(language_tag) |
236 |
if not new_mo_data_base64: # property value has been removed |
237 |
old_mo_data_binary = univention.admin.mapping.mapBase64(old_mo_data_base64) |
238 |
modlist.append((ldap_attribute, old_mo_data_binary, None)) |
239 |
else: |
240 |
if new_mo_data_base64 != old_mo_data_base64: |
241 |
old_mo_data_binary = univention.admin.mapping.mapBase64(old_mo_data_base64) |
242 |
new_mo_data_binary = univention.admin.mapping.mapBase64(new_mo_data_base64) |
243 |
modlist.append((ldap_attribute, old_mo_data_binary, new_mo_data_binary)) |
244 |
for language_tag, new_mo_data_base64 in new_dict.items(): |
245 |
ldap_attribute = ''.join((messagecatalog_ldap_attribute_and_tag_prefix, language_tag)) |
246 |
if not old_dict.get(language_tag): # property value has been added |
247 |
new_mo_data_binary = univention.admin.mapping.mapBase64(new_mo_data_base64) |
248 |
modlist.append((ldap_attribute, None, new_mo_data_binary)) |
249 |
break |
250 |
return modlist |
251 |
|
252 |
|
253 |
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=False, required=False, timeout=-1, sizelimit=0): |
254 |
filter = univention.admin.filter.conjunction('&', [ |
255 |
univention.admin.filter.expression('objectClass', OC), |
256 |
]) |
257 |
|
258 |
if filter_s: |
259 |
filter_p = univention.admin.filter.parse(filter_s) |
260 |
univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping) |
261 |
filter.expressions.append(filter_p) |
262 |
|
263 |
res = [] |
264 |
for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit): |
265 |
res.append(object(co, lo, None, dn, attributes=attrs)) |
266 |
return res |
267 |
|
268 |
|
269 |
def identify(dn, attr, canonical=0): |
270 |
return OC in attr.get('objectClass', []) |