|
|
|
1 |
# -*- coding: utf-8 -*- |
2 |
# |
3 |
# Univention Directory Manager Modules |
4 |
# direcory manager module for UCR extensions |
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 = "univentionUCRExtension" |
45 |
|
46 |
module = 'settings/ucr_extension' |
47 |
superordinate = 'settings/cn' |
48 |
childs = 0 |
49 |
operations = ['add', 'edit', 'remove', 'search', 'move'] |
50 |
short_description = _('Settings: UCR Extension') |
51 |
long_description = '' |
52 |
options = {} |
53 |
property_descriptions = { |
54 |
'name': univention.admin.property( |
55 |
short_description=_('UCR 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=_('UCR 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 |
'infodata': univention.admin.property( |
77 |
short_description=_('UCR info 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 |
'variablesinfodata': univention.admin.property( |
87 |
short_description=_('UCR variables info data'), |
88 |
long_description='', |
89 |
syntax=univention.admin.syntax.Base64Bzip2Text, |
90 |
multivalue=False, |
91 |
options=[], |
92 |
required=True, |
93 |
may_change=True, |
94 |
identifies=False |
95 |
), |
96 |
'template': univention.admin.property( |
97 |
short_description=_('UCR temaplates'), |
98 |
long_description='', |
99 |
syntax=univention.admin.syntax.Base64Bzip2Text, |
100 |
multivalue=True, |
101 |
options=[], |
102 |
required=True, |
103 |
may_change=True, |
104 |
identifies=False |
105 |
), |
106 |
'scripts': univention.admin.property( |
107 |
short_description=_('UCR scripts'), |
108 |
long_description='', |
109 |
syntax=univention.admin.syntax.Base64Bzip2Text, |
110 |
multivalue=True, |
111 |
options=[], |
112 |
required=True, |
113 |
may_change=True, |
114 |
identifies=False |
115 |
), |
116 |
'active': univention.admin.property( |
117 |
short_description=_('Active'), |
118 |
long_description='', |
119 |
syntax=univention.admin.syntax.TrueFalseUp, |
120 |
default='FALSE', |
121 |
multivalue=False, |
122 |
options=[], |
123 |
required=False, |
124 |
may_change=True, |
125 |
identifies=False |
126 |
), |
127 |
'servers': univention.admin.property( |
128 |
short_description=_('Servers'), |
129 |
long_description='', |
130 |
syntax=univention.admin.syntax.UCS_Server, |
131 |
multivalue=True, |
132 |
options=[], |
133 |
required=False, |
134 |
may_change=True, |
135 |
identifies=False |
136 |
), |
137 |
'appidentifier': univention.admin.property( |
138 |
short_description=_('App identifier'), |
139 |
long_description='', |
140 |
syntax=univention.admin.syntax.TextArea, |
141 |
multivalue=True, |
142 |
options=[], |
143 |
required=False, |
144 |
may_change=True, |
145 |
identifies=False |
146 |
), |
147 |
'package': univention.admin.property( |
148 |
short_description=_('Software package'), |
149 |
long_description='', |
150 |
syntax=univention.admin.syntax.string, |
151 |
multivalue=False, |
152 |
options=[], |
153 |
required=False, |
154 |
may_change=True, |
155 |
identifies=False |
156 |
), |
157 |
'packageversion': univention.admin.property( |
158 |
short_description=_('Software package version'), |
159 |
long_description='', |
160 |
syntax=univention.admin.syntax.DebianPackageVersion, |
161 |
multivalue=False, |
162 |
options=[], |
163 |
required=False, |
164 |
may_change=True, |
165 |
identifies=False |
166 |
), |
167 |
'ucsversionstart': univention.admin.property( |
168 |
short_description=_('Minimal UCS version'), |
169 |
long_description='', |
170 |
syntax=univention.admin.syntax.UCSVersion, |
171 |
multivalue=False, |
172 |
options=[], |
173 |
required=False, |
174 |
may_change=True, |
175 |
identifies=False |
176 |
), |
177 |
'ucsversionend': univention.admin.property( |
178 |
short_description=_('Maximal UCS version'), |
179 |
long_description='', |
180 |
syntax=univention.admin.syntax.UCSVersion, |
181 |
multivalue=False, |
182 |
options=[], |
183 |
required=False, |
184 |
may_change=True, |
185 |
identifies=False |
186 |
), |
187 |
} |
188 |
|
189 |
layout = [ |
190 |
Tab(_('General'), _('Basic values'), layout=[ |
191 |
Group(_('General UCR extension settings'), layout=[ |
192 |
["name"], |
193 |
["filename"], |
194 |
["data"], |
195 |
["servers"], |
196 |
]), |
197 |
Group(_('Metadata'), layout=[ |
198 |
["package"], |
199 |
["packageversion"], |
200 |
["appidentifier"], |
201 |
]), |
202 |
Group(_('UCS Version Dependencies'), layout=[ |
203 |
["ucsversionstart"], |
204 |
["ucsversionend"], |
205 |
]), |
206 |
Group(_('Activated'), layout=[ |
207 |
["active"], |
208 |
]), |
209 |
]), |
210 |
] |
211 |
|
212 |
mapping = univention.admin.mapping.mapping() |
213 |
mapping.register('name', 'cn', None, univention.admin.mapping.ListToString) |
214 |
mapping.register('filename', 'univentionUCRFilename', None, univention.admin.mapping.ListToString) |
215 |
mapping.register('metadata', 'univentionUCRMetaData', univention.admin.mapping.mapBase64, univention.admin.mapping.unmapBase64) |
216 |
mapping.register('active', 'univentionUCRActive', None, univention.admin.mapping.ListToString) |
217 |
mapping.register('servers', 'univentionUCRServers') |
218 |
mapping.register('appidentifier', 'univentionAppIdentifier') |
219 |
mapping.register('package', 'univentionOwnedByPackage', None, univention.admin.mapping.ListToString) |
220 |
mapping.register('packageversion', 'univentionOwnedByPackageVersion', None, univention.admin.mapping.ListToString) |
221 |
mapping.register('ucsversionstart', 'univentionUCSVersionStart', None, univention.admin.mapping.ListToString) |
222 |
mapping.register('ucsversionend', 'univentionUCSVersionEnd', None, univention.admin.mapping.ListToString) |
223 |
|
224 |
|
225 |
class object(univention.admin.handlers.simpleLdap): |
226 |
module = module |
227 |
|
228 |
def open(self): |
229 |
univention.admin.handlers.simpleLdap.open(self) |
230 |
|
231 |
def _ldap_addlist(self): |
232 |
ocs = ['top', 'univentionObjectMetadata', OC] |
233 |
|
234 |
return [ |
235 |
('objectClass', ocs), |
236 |
] |
237 |
|
238 |
def _ldap_pre_modify(self): |
239 |
diff_keys = [key for key in self.info.keys() if self.info.get(key) != self.oldinfo.get(key) and key not in ('active', 'appidentifier')] |
240 |
if not diff_keys: # check for trivial change |
241 |
return |
242 |
if not self.hasChanged('package'): |
243 |
old_version = self.oldinfo.get('packageversion', '0') |
244 |
if not apt.apt_pkg.version_compare(self['packageversion'], old_version) > -1: |
245 |
raise univention.admin.uexceptions.valueInvalidSyntax(_('packageversion: Version must not be lower than the current one.')) |
246 |
|
247 |
|
248 |
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=False, required=False, timeout=-1, sizelimit=0): |
249 |
|
250 |
filter = univention.admin.filter.conjunction('&', [ |
251 |
univention.admin.filter.expression('objectClass', OC), |
252 |
]) |
253 |
|
254 |
if filter_s: |
255 |
filter_p = univention.admin.filter.parse(filter_s) |
256 |
univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping) |
257 |
filter.expressions.append(filter_p) |
258 |
|
259 |
res = [] |
260 |
for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit): |
261 |
res.append(object(co, lo, None, dn, attributes=attrs)) |
262 |
return res |
263 |
|
264 |
|
265 |
def identify(dn, attr, canonical=0): |
266 |
|
267 |
return OC in attr.get('objectClass', []) |