|
30 |
# /usr/share/common-licenses/AGPL-3; if not, see |
30 |
# /usr/share/common-licenses/AGPL-3; if not, see |
31 |
# <http://www.gnu.org/licenses/>. |
31 |
# <http://www.gnu.org/licenses/>. |
32 |
|
32 |
|
33 |
|
33 |
from textwrap import dedent |
|
|
34 |
import sys |
34 |
import getopt |
35 |
import getopt |
35 |
import re |
36 |
import re |
36 |
import string |
37 |
import string |
Lines 54-146
univention.admin.modules.update()
|
Link Here
|
---|
|
54 |
# update choices-lists which are defined in LDAP |
55 |
# update choices-lists which are defined in LDAP |
55 |
univention.admin.syntax.update_choices() |
56 |
univention.admin.syntax.update_choices() |
56 |
|
57 |
|
57 |
# usage information |
58 |
|
58 |
def usage(): |
59 |
class Failed(Exception): |
59 |
out=[] |
60 |
def __str__(self): |
60 |
out.append('univention-directory-manager: command line interface for managing UCS') |
61 |
return "OPERATION FAILED" |
61 |
out.append('copyright (c) 2001-@%@copyright_lastyear@%@ Univention GmbH, Germany') |
62 |
|
62 |
out.append('') |
63 |
|
63 |
out.append('Syntax:') |
64 |
def usage(out=sys.stdout): |
64 |
out.append(' univention-directory-manager module action [options]') |
65 |
print >> out, dedent("""\ |
65 |
out.append(' univention-directory-manager [--help] [--version]') |
66 |
%(prog)s command line interface for managing UCS |
66 |
out.append('') |
67 |
copyright (c) 2001-%(year)s Univention GmbH, Germany |
67 |
out.append('actions:') |
68 |
|
68 |
out.append(' %-32s %s' % ('create:', 'Create a new object')) |
69 |
Syntax: |
69 |
out.append(' %-32s %s' % ('modify:', 'Modify an existing object')) |
70 |
%(prog)s module action [options] |
70 |
out.append(' %-32s %s' % ('remove:', 'Remove an existing object')) |
71 |
%(prog)s [--help] [--version] |
71 |
out.append(' %-32s %s' % ('list:', 'List objects')) |
72 |
|
72 |
out.append(' %-32s %s' % ('move:', 'Move object in directory tree')) |
73 |
actions: |
73 |
out.append('') |
74 |
create: Create a new object |
74 |
out.append(' %-32s %s' % ('-h | --help | -?:', 'print this usage message')) |
75 |
modify: Modify an existing object |
75 |
out.append(' %-32s %s' % ('--version:', 'print version information')) |
76 |
remove: Remove an existing object |
76 |
out.append('') |
77 |
list: List objects |
77 |
out.append('general options:') |
78 |
move: Move object in directory tree |
78 |
out.append(' --%-30s %s' % ('logfile', 'path and name of the logfile to be used')) |
79 |
|
79 |
out.append('') |
80 |
-h | --help | -?: Print this usage message |
80 |
out.append('create options:') |
81 |
--version: Print version information |
81 |
out.append(' --%-30s %s' % ('binddn', 'bind DN')) |
82 |
|
82 |
out.append(' --%-30s %s' % ('bindpwd', 'bind password')) |
83 |
general options: |
83 |
out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) |
84 |
--logfile Path and name of the logfile to be used |
84 |
out.append(' --%-30s %s' % ('position', 'Set position in tree')) |
85 |
--binddn Bind DN |
85 |
out.append(' --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar')) |
86 |
--bindpwd Bind password |
86 |
out.append(' --%-30s %s' % ('superordinate', 'Use superordinate module')) |
87 |
--bindpwdfile file containing bind password |
87 |
out.append(' --%-30s %s' % ('option', 'Use only given module options')) |
88 |
--tls 0 (no); 1 (try); 2 (must) |
88 |
out.append(' --%-30s %s' % ('policy-reference', 'Reference to policy given by DN')) |
89 |
|
89 |
out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) |
90 |
create options: |
90 |
out.append(' --%-30s ' % ('ignore_exists')) |
91 |
--position Set position in tree |
91 |
out.append('') |
92 |
--set Set variable to value, e.g. foo=bar |
92 |
out.append('modify options:') |
93 |
--superordinate Use superordinate module |
93 |
out.append(' --%-30s %s' % ('binddn', 'bind DN')) |
94 |
--option Use only given module options |
94 |
out.append(' --%-30s %s' % ('bindpwd', 'bind password')) |
95 |
--policy-reference Reference to policy given by DN |
95 |
out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) |
96 |
--ignore_exists |
96 |
out.append(' --%-30s %s' % ('dn', 'Edit object with DN')) |
97 |
|
97 |
out.append(' --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar')) |
98 |
modify options: |
98 |
out.append(' --%-30s %s' % ('append', 'Append value to variable, e.g. foo=bar')) |
99 |
--dn Edit object with DN |
99 |
out.append(' --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar')) |
100 |
--set Set variable to value, e.g. foo=bar |
100 |
out.append(' --%-30s %s' % ('option', 'Use only given module options')) |
101 |
--append Append value to variable, e.g. foo=bar |
101 |
out.append(' --%-30s %s' % ('append-option', 'Append the module options')) |
102 |
--remove Remove value from variable, e.g. foo=bar |
102 |
out.append(' --%-30s %s' % ('policy-reference', 'Reference to policy given by DN')) |
103 |
--option Use only given module options |
103 |
out.append(' --%-30s %s' % ('policy-dereference', 'Remove reference to policy given by DN')) |
104 |
--append-option Append the module options |
104 |
out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) |
105 |
--policy-reference Reference to policy given by DN |
105 |
out.append('') |
106 |
--policy-dereference Remove reference to policy given by DN |
106 |
out.append('remove options:') |
107 |
|
107 |
out.append(' --%-30s %s' % ('binddn', 'bind DN')) |
108 |
remove options: |
108 |
out.append(' --%-30s %s' % ('bindpwd', 'bind password')) |
109 |
--dn Remove object with DN |
109 |
out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) |
110 |
--superordinate Use superordinate module |
110 |
out.append(' --%-30s %s' % ('dn', 'Remove object with DN')) |
111 |
--filter Lookup filter e.g. foo=bar |
111 |
out.append(' --%-30s %s' % ('superordinate', 'Use superordinate module')) |
112 |
--remove_referring Remove referring objects |
112 |
out.append(' --%-30s %s' % ('filter', 'Lookup filter e.g. foo=bar')) |
113 |
|
113 |
out.append(' --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)')) |
114 |
list options: |
114 |
out.append(' --%-30s %s' % ('remove_referring', 'remove referring objects')) |
115 |
--filter Lookup filter e.g. foo=bar |
115 |
out.append('') |
116 |
--policies List policy-based settings: |
116 |
out.append('list options:') |
117 |
0:short, 1:long (with policy-DN) |
117 |
out.append(' --%-30s %s' % ('filter', 'Lookup filter e.g. foo=bar')) |
118 |
|
118 |
out.append(' --%-30s %s' % ('policies', 'List policy-based settings:')) |
119 |
move options: |
119 |
out.append(' %-30s %s' % ('', '0:short, 1:long (with policy-DN)')) |
120 |
--dn Move object with DN |
120 |
out.append('') |
121 |
--position Move to position in tree |
121 |
out.append('move options:') |
122 |
|
122 |
out.append(' --%-30s %s' % ('binddn', 'bind DN')) |
123 |
Description: |
123 |
out.append(' --%-30s %s' % ('bindpwd', 'bind password')) |
124 |
%(prog)s is a tool to handle the configuration for UCS |
124 |
out.append(' --%-30s %s' % ('bindpwdfile', 'file containing bind password')) |
125 |
on command line level. |
125 |
out.append(' --%-30s %s' % ('dn', 'Move object with DN')) |
126 |
Use "%(prog)s modules" for a list of available modules. |
126 |
out.append(' --%-30s %s' % ('position', 'Move to position in tree')) |
127 |
""") % { |
127 |
out.append('') |
128 |
"prog": "univention-directory-manager", |
128 |
out.append('Description:') |
129 |
"year": "@%@copyright_lastyear@%@", |
129 |
out.append(' univention-directory-manager is a tool to handle the configuration for UCS') |
130 |
} |
130 |
out.append(' on command line level.') |
131 |
|
131 |
out.append(' Use "univention-directory-manager modules" for a list of available modules.') |
132 |
|
132 |
out.append('') |
133 |
def version(out=sys.stdout): |
133 |
return out |
134 |
print >> out, 'univention-directory-manager @%@package_version@%@' |
134 |
|
135 |
|
135 |
def version(): |
136 |
|
136 |
o=[] |
137 |
def _print_property(module, action, name, out=sys.stdout): |
137 |
o.append('univention-directory-manager @%@package_version@%@') |
|
|
138 |
return o |
139 |
|
140 |
def _print_property( module, action, name, output ): |
141 |
property = module.property_descriptions.get( name ) |
138 |
property = module.property_descriptions.get( name ) |
142 |
if property is None: |
139 |
if property is None: |
143 |
output.append( 'E: unknown property %s of module %s' % ( name, univention.admin.modules.name( module ) ) ) |
140 |
print >> out, 'E: unknown property %s of module %s' % ( |
|
|
141 |
name, |
142 |
univention.admin.modules.name(module), |
143 |
) |
144 |
return |
144 |
return |
145 |
|
145 |
|
146 |
required = { |
146 |
required = { |
Lines 181-212
def _print_property( module, action, name, output ):
|
Link Here
|
---|
|
181 |
flags += ',' |
181 |
flags += ',' |
182 |
flags += '[]' |
182 |
flags += '[]' |
183 |
if flags: |
183 |
if flags: |
184 |
flags = '(' + flags + ')' |
184 |
name += ' (%s)' % (flags,) |
|
|
185 |
|
186 |
print >> out, ' %-40s %s' % ( |
187 |
name, |
188 |
property.short_description |
189 |
) |
185 |
|
190 |
|
186 |
output.append( ' %-40s %s' % ( name + ' ' + flags, property.short_description ) ) |
|
|
187 |
|
191 |
|
188 |
def module_usage(information, action=''): |
192 |
def module_usage(information, action='', out=sys.stdout): |
189 |
out=[] |
|
|
190 |
for module, l in information.items(): |
193 |
for module, l in information.items(): |
191 |
properties, options = l |
194 |
properties, options = l |
192 |
|
195 |
|
193 |
if options: |
196 |
if options: |
194 |
out.append('') |
197 |
print >> out, '' |
195 |
out.append('%s options:' % module.module) |
198 |
print >> out, '%s options:' % module.module |
196 |
for name, option in options.items(): |
199 |
for name, option in options.items(): |
197 |
out.append(' %-32s %s' % (name, option.short_description)) |
200 |
print >> out, ' %-32s %s' % (name, option.short_description) |
198 |
|
201 |
|
199 |
out.append('') |
202 |
print >> out, '' |
200 |
out.append('%s variables:' % module.module) |
203 |
print >> out, '%s variables:' % module.module |
201 |
|
204 |
|
202 |
if not hasattr(module,"layout"): |
205 |
if not hasattr(module,"layout"): |
203 |
continue |
206 |
continue |
204 |
for moduletab in module.layout: |
207 |
for moduletab in module.layout: |
205 |
out.append(' %s:' % (moduletab.label)) |
208 |
print >> out, ' %s:' % (moduletab.label) |
206 |
|
209 |
|
207 |
for row in moduletab.layout: |
210 |
for row in moduletab.layout: |
208 |
if isinstance( row, Group ): |
211 |
if isinstance( row, Group ): |
209 |
out.append( ' %s' % row.label ) |
212 |
print >> out, ' %s' % row.label |
210 |
for row in row.layout: |
213 |
for row in row.layout: |
211 |
if isinstance( row, basestring ): |
214 |
if isinstance( row, basestring ): |
212 |
_print_property( module, action, row, out ) |
215 |
_print_property( module, action, row, out ) |
Lines 220-226
def module_usage(information, action=''):
|
Link Here
|
---|
|
220 |
for item in row: |
223 |
for item in row: |
221 |
_print_property( module, action, item, out ) |
224 |
_print_property( module, action, item, out ) |
222 |
|
225 |
|
223 |
return out |
|
|
224 |
|
226 |
|
225 |
def module_information(module, identifies_only=0): |
227 |
def module_information(module, identifies_only=0): |
226 |
information={module:[{},{}]} |
228 |
information={module:[{},{}]} |
|
243 |
except: |
245 |
except: |
244 |
return text.decode( 'iso-8859-1' ) |
246 |
return text.decode( 'iso-8859-1' ) |
245 |
|
247 |
|
246 |
def object_input(module, object, input, append=None, remove=None): |
248 |
def object_input(module, object, input, append=None, remove=None, out=sys.stdout): |
247 |
out=[] |
|
|
248 |
if append: |
249 |
if append: |
249 |
for key, value in append.items(): |
250 |
for key, value in append.items(): |
250 |
if module.property_descriptions[key].syntax.name == 'file': |
251 |
if module.property_descriptions[key].syntax.name == 'file': |
Lines 256-262
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
256 |
object[key] = content |
257 |
object[key] = content |
257 |
fh.close() |
258 |
fh.close() |
258 |
else: |
259 |
else: |
259 |
out.append('WARNING: file not found: %s' % value) |
260 |
print >> out, 'WARNING: file not found: %s' % value |
260 |
|
261 |
|
261 |
elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): |
262 |
elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): |
262 |
for i in range(0,len(value)): |
263 |
for i in range(0,len(value)): |
Lines 272-278
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
272 |
if not object.has_key(key): |
273 |
if not object.has_key(key): |
273 |
object[key]=[] |
274 |
object[key]=[] |
274 |
if val in object[key]: |
275 |
if val in object[key]: |
275 |
out.append('WARNING: cannot append %s to %s, value exists'%(val,key)) |
276 |
print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key) |
276 |
elif object[key] == [''] or object[key] == []: |
277 |
elif object[key] == [''] or object[key] == []: |
277 |
object[key]=[val] |
278 |
object[key]=[val] |
278 |
else: |
279 |
else: |
Lines 280-286
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
280 |
else: |
281 |
else: |
281 |
for val in value: |
282 |
for val in value: |
282 |
if val in object[key]: |
283 |
if val in object[key]: |
283 |
out.append('WARNING: cannot append %s to %s, value exists'%(val,key)) |
284 |
print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key) |
284 |
elif object[key] == [''] or object[key] == []: |
285 |
elif object[key] == [''] or object[key] == []: |
285 |
object[key]=[val] |
286 |
object[key]=[val] |
286 |
else: |
287 |
else: |
Lines 289-295
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
289 |
tmp.append(val) |
290 |
tmp.append(val) |
290 |
object[key] = list(tmp) |
291 |
object[key] = list(tmp) |
291 |
except univention.admin.uexceptions.valueInvalidSyntax, errmsg: |
292 |
except univention.admin.uexceptions.valueInvalidSyntax, errmsg: |
292 |
out.append('E: Invalid Syntax: %s' % str(errmsg)) |
293 |
print >> out, 'E: Invalid Syntax: %s' % (errmsg,) |
293 |
if remove: |
294 |
if remove: |
294 |
for key, value in remove.items(): |
295 |
for key, value in remove.items(): |
295 |
if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): |
296 |
if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): |
Lines 300-306
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
300 |
val=value[i].split(' ') |
301 |
val=value[i].split(' ') |
301 |
else: |
302 |
else: |
302 |
val=[] |
303 |
val=[] |
303 |
out.append('test_val=%s' % test_val) |
304 |
print >> out, 'test_val=%s' % (test_val,) |
304 |
for j in test_val: |
305 |
for j in test_val: |
305 |
if j and j.rstrip().lstrip(): |
306 |
if j and j.rstrip().lstrip(): |
306 |
val.append(j.rstrip().lstrip()) |
307 |
val.append(j.rstrip().lstrip()) |
Lines 311-317
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
311 |
if val and val in object[key]: |
312 |
if val and val in object[key]: |
312 |
object[key].remove(val) |
313 |
object[key].remove(val) |
313 |
else: |
314 |
else: |
314 |
out.append("WARNING: cannot remove %s from %s, value does not exist"%(val,key)) |
315 |
print >> out, "WARNING: cannot remove %s from %s, value does not exist" % (val, key) |
315 |
else: |
316 |
else: |
316 |
object[key]=[] |
317 |
object[key]=[] |
317 |
|
318 |
|
Lines 326-332
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
326 |
if val in object[key]: |
327 |
if val in object[key]: |
327 |
object[key].remove(val) |
328 |
object[key].remove(val) |
328 |
else: |
329 |
else: |
329 |
out.append("WARNING: cannot remove %s from %s, value does not exist"%(val,key)) |
330 |
print >> out, "WARNING: cannot remove %s from %s, value does not exist" % (val, key) |
330 |
if input: |
331 |
if input: |
331 |
for key, value in input.items(): |
332 |
for key, value in input.items(): |
332 |
if module.property_descriptions[key].syntax.name == 'binaryfile': |
333 |
if module.property_descriptions[key].syntax.name == 'binaryfile': |
Lines 343-349
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
343 |
object[key]= content |
344 |
object[key]= content |
344 |
fh.close() |
345 |
fh.close() |
345 |
else: |
346 |
else: |
346 |
out.append('WARNING: file not found: %s' % value) |
347 |
print >> out, 'WARNING: file not found: %s' % value |
347 |
|
348 |
|
348 |
elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): |
349 |
elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ): |
349 |
if type(value) == type([]): |
350 |
if type(value) == type([]): |
Lines 366-391
def object_input(module, object, input, append=None, remove=None):
|
Link Here
|
---|
|
366 |
try: |
367 |
try: |
367 |
object[key]=value |
368 |
object[key]=value |
368 |
except univention.admin.uexceptions.ipOverridesNetwork, e: |
369 |
except univention.admin.uexceptions.ipOverridesNetwork, e: |
369 |
out.append('WARNING: %s' % e.message) |
370 |
print >> out, 'WARNING: %s' % e.message |
370 |
except univention.admin.uexceptions.valueMayNotChange, e: |
371 |
except univention.admin.uexceptions.valueMayNotChange, e: |
371 |
raise univention.admin.uexceptions.valueMayNotChange, "%s: %s"%(e.message, key) |
372 |
raise univention.admin.uexceptions.valueMayNotChange, "%s: %s"%(e.message, key) |
372 |
return out |
|
|
373 |
|
373 |
|
374 |
def list_available_modules(o=[]): |
|
|
375 |
|
374 |
|
376 |
o.append("Available Modules are:") |
375 |
def list_available_modules(out=sys.stdout): |
|
|
376 |
print >> out, "Available Modules are:" |
377 |
avail_modules = [] |
377 |
avail_modules = [] |
378 |
for mod in univention.admin.modules.modules.keys(): |
378 |
for mod in univention.admin.modules.modules.keys(): |
379 |
avail_modules.append(mod) |
379 |
avail_modules.append(mod) |
380 |
avail_modules.sort() |
380 |
avail_modules.sort() |
381 |
for mod in avail_modules: |
381 |
for mod in avail_modules: |
382 |
o.append(" %s"%mod) |
382 |
print >> out, " %s" % mod |
383 |
return o |
|
|
384 |
|
383 |
|
385 |
def doit(arglist): |
384 |
|
386 |
out=[] |
385 |
def doit(arglist, out=sys.stdout): |
387 |
try: |
386 |
try: |
388 |
out=_doit(arglist) |
387 |
_doit(arglist, out) |
389 |
except univention.admin.uexceptions.base, e: |
388 |
except univention.admin.uexceptions.base, e: |
390 |
univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, traceback.format_exc()) |
389 |
univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, traceback.format_exc()) |
391 |
|
390 |
|
|
406 |
msg[0] = '%s:' % msg[0].strip(':.') |
405 |
msg[0] = '%s:' % msg[0].strip(':.') |
407 |
|
406 |
|
408 |
# append to the output |
407 |
# append to the output |
409 |
out.append(' '.join(msg)) |
408 |
print >> out, ' '.join(msg) |
410 |
return out + ["OPERATION FAILED"] |
409 |
print >> out, Failed() |
411 |
return out |
410 |
except Failed as ex: |
|
|
411 |
print >> out, ex |
412 |
|
412 |
|
413 |
def _doit(arglist): |
|
|
414 |
|
413 |
|
415 |
out=[] |
414 |
def _doit(arglist, out=sys.stdout): |
416 |
# parse module and action |
415 |
# parse module and action |
|
|
416 |
if set(arglist) & set(('-h', '--help', '-?')): |
417 |
return usage(out=out) |
418 |
|
419 |
if '--version' in arglist: |
420 |
return version(out=out) |
421 |
|
417 |
if len(arglist) < 2: |
422 |
if len(arglist) < 2: |
418 |
return usage() + ["OPERATION FAILED"] |
423 |
usage(out=out) |
|
|
424 |
raise Failed() |
419 |
|
425 |
|
420 |
module_name=arglist[1] |
426 |
module_name=arglist[1] |
421 |
if module_name in ['-h', '--help', '-?']: |
|
|
422 |
return usage() |
423 |
|
424 |
if module_name == '--version': |
425 |
return version() |
426 |
|
427 |
|
427 |
if module_name == 'modules': |
428 |
if module_name == 'modules': |
428 |
return list_available_modules() |
429 |
return list_available_modules(out=out) |
429 |
|
430 |
|
430 |
remove_referring=0 |
431 |
remove_referring=0 |
431 |
recursive=1 |
432 |
recursive=1 |
|
455 |
try: |
456 |
try: |
456 |
opts, args=getopt.getopt(arglist[3:], '', longopts) |
457 |
opts, args=getopt.getopt(arglist[3:], '', longopts) |
457 |
except getopt.error, msg: |
458 |
except getopt.error, msg: |
458 |
out.append(str(msg)) |
459 |
print >> out, msg |
459 |
return out + ["OPERATION FAILED"] |
460 |
raise Failed() |
460 |
|
461 |
|
461 |
if not args == [] and type(args) == type([]): |
462 |
if not args == [] and type(args) == type([]): |
462 |
msg = "WARNING: the following arguments are ignored:" |
463 |
print >> out, "WARNING: the following arguments are ignored: %s" % ( |
463 |
for argument in args: |
464 |
" ".join(('"%s"' % _ for _ in args)), |
464 |
msg = '%s "%s"' % (msg, argument) |
465 |
) |
465 |
out.append(msg) |
|
|
466 |
|
466 |
|
467 |
position_dn='' |
467 |
position_dn='' |
468 |
dn='' |
468 |
dn='' |
|
503 |
with open(val) as fp: |
503 |
with open(val) as fp: |
504 |
bindpwd=fp.read().strip() |
504 |
bindpwd=fp.read().strip() |
505 |
except IOError as e: |
505 |
except IOError as e: |
506 |
out.append( 'E: could not read bindpwd from file (%s)' % str(e) ) |
506 |
print >> out, 'E: could not read bindpwd from file (%s)' % (e,) |
507 |
return out + ['OPERATION FAILED'] |
507 |
raise Failed() |
508 |
elif opt == '--dn': |
508 |
elif opt == '--dn': |
509 |
dn = _2utf8( val ) |
509 |
dn = _2utf8( val ) |
510 |
elif opt == '--tls': |
510 |
elif opt == '--tls': |
|
527 |
if logfile: |
527 |
if logfile: |
528 |
univention.debug.init(logfile, 1, 0) |
528 |
univention.debug.init(logfile, 1, 0) |
529 |
else: |
529 |
else: |
530 |
out.append("WARNING: no logfile specified") |
530 |
print >> out, "WARNING: no logfile specified" |
531 |
|
531 |
|
532 |
configRegistry=univention.config_registry.ConfigRegistry() |
532 |
configRegistry=univention.config_registry.ConfigRegistry() |
533 |
configRegistry.load() |
533 |
configRegistry.load() |
|
553 |
lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, start_tls=tls, bindpw=bindpwd) |
553 |
lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, start_tls=tls, bindpw=bindpwd) |
554 |
except Exception, e: |
554 |
except Exception, e: |
555 |
univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) |
555 |
univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) |
556 |
out.append('authentication error: %s' % str(e)) |
556 |
print >> out, 'authentication error: %s' % (e,) |
557 |
return out + ["OPERATION FAILED"] |
557 |
raise Failed() |
558 |
policyOptions.extend(['-D', binddn, '-w', bindpwd]) ## FIXME not so nice |
558 |
policyOptions.extend(['-D', binddn, '-w', bindpwd]) ## FIXME not so nice |
559 |
|
559 |
|
560 |
else: |
560 |
else: |
|
568 |
secretFileName='/etc/machine.secret' |
568 |
secretFileName='/etc/machine.secret' |
569 |
binddn=configRegistry['ldap/hostdn'] |
569 |
binddn=configRegistry['ldap/hostdn'] |
570 |
policyOptions.extend(['-D', binddn, '-y', secretFileName]) |
570 |
policyOptions.extend(['-D', binddn, '-y', secretFileName]) |
|
|
571 |
else: |
572 |
print >> out, "E: Missing LDAP credentials" |
573 |
raise Failed() |
571 |
|
574 |
|
572 |
try: |
575 |
try: |
573 |
secretFile=open(secretFileName,'r') |
576 |
secretFile=open(secretFileName,'r') |
574 |
except IOError: |
577 |
except IOError: |
575 |
out.append('E: Permission denied, try --binddn and --bindpwd') |
578 |
print >> out, 'E: Permission denied, try --binddn and --bindpwd' |
576 |
return out + ["OPERATION FAILED"] |
579 |
raise Failed() |
577 |
pwdLine=secretFile.readline() |
580 |
pwdLine=secretFile.readline() |
578 |
pwd=re.sub('\n','',pwdLine) |
581 |
pwd=re.sub('\n','',pwdLine) |
579 |
|
582 |
|
|
581 |
lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, bindpw=pwd, start_tls=tls) |
584 |
lo=univention.admin.uldap.access(host=configRegistry['ldap/master'], port=int(configRegistry.get('ldap/master/port', '7389')), base=baseDN, binddn=binddn, bindpw=pwd, start_tls=tls) |
582 |
except Exception, e: |
585 |
except Exception, e: |
583 |
univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) |
586 |
univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e)) |
584 |
out.append('authentication error: %s' % str(e)) |
587 |
print >> out, 'authentication error: %s' % (e,) |
585 |
return out + ["OPERATION FAILED"] |
588 |
raise Failed() |
586 |
|
589 |
|
587 |
if not position_dn and superordinate_dn: |
590 |
if not position_dn and superordinate_dn: |
588 |
position_dn=superordinate_dn |
591 |
position_dn=superordinate_dn |
|
593 |
position=univention.admin.uldap.position(baseDN) |
596 |
position=univention.admin.uldap.position(baseDN) |
594 |
position.setDn(position_dn) |
597 |
position.setDn(position_dn) |
595 |
except univention.admin.uexceptions.noObject: |
598 |
except univention.admin.uexceptions.noObject: |
596 |
out.append('E: Invalid position') |
599 |
print >> out, 'E: Invalid position' |
597 |
return out + ["OPERATION FAILED"] |
600 |
raise Failed() |
598 |
|
601 |
|
599 |
try: |
602 |
try: |
600 |
module=univention.admin.modules.get(module_name) |
603 |
module=univention.admin.modules.get(module_name) |
601 |
except: |
604 |
except: |
602 |
out.append("failed to get module %s."%module_name) |
605 |
print >> out, "failed to get module %s." % module_name |
603 |
out.append("") |
606 |
print >> out, "" |
604 |
return list_available_modules(out) + ["OPERATION FAILED"] |
607 |
list_available_modules(out) |
|
|
608 |
raise Failed() |
605 |
|
609 |
|
606 |
if not module: |
610 |
if not module: |
607 |
out.append("unknown module %s." % module_name) |
611 |
print >> out, "unknown module %s." % module_name |
608 |
out.append("") |
612 |
print >> out, "" |
609 |
return list_available_modules(out) + ["OPERATION FAILED"] |
613 |
list_available_modules(out) |
|
|
614 |
raise Failed() |
610 |
|
615 |
|
611 |
# initialise modules |
616 |
# initialise modules |
612 |
univention.admin.modules.init(lo,position,module) |
617 |
univention.admin.modules.init(lo,position,module) |
|
617 |
try: |
622 |
try: |
618 |
superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn) |
623 |
superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn) |
619 |
except univention.admin.uexceptions.insufficientInformation, e: |
624 |
except univention.admin.uexceptions.insufficientInformation, e: |
620 |
out.append('Insufficient Information: %s' % str(e)) |
625 |
print >> out, 'Insufficient Information: %s' % (e,) |
621 |
return out + ["OPERATION FAILED"] |
626 |
raise Failed() |
622 |
else: |
627 |
else: |
623 |
superordinate=None |
628 |
superordinate=None |
624 |
|
629 |
|
625 |
|
630 |
|
626 |
if len(arglist) == 2: |
631 |
if len(arglist) == 2: |
627 |
out = usage() + module_usage(information) |
632 |
module_usage(information, out=out) |
628 |
return out + ["OPERATION FAILED"] |
633 |
raise Failed() |
629 |
|
634 |
|
630 |
action=arglist[2] |
635 |
action=arglist[2] |
631 |
|
636 |
|
632 |
if len(arglist) == 3 and action != 'list': |
637 |
if len(arglist) == 3 and action != 'list': |
633 |
out = usage() + module_usage(information, action) |
638 |
module_usage(information, action, out=out) |
634 |
return out + ["OPERATION FAILED"] |
639 |
raise Failed() |
635 |
|
640 |
|
636 |
|
641 |
|
637 |
for opt, val in opts: |
642 |
for opt, val in opts: |
|
655 |
was_set=1 |
660 |
was_set=1 |
656 |
|
661 |
|
657 |
if not was_set: |
662 |
if not was_set: |
658 |
out.append("WARNING: No attribute with name '%s' in this module, value not set."%name) |
663 |
print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name |
659 |
elif opt == '--append': |
664 |
elif opt == '--append': |
660 |
pos=val.find('=') |
665 |
pos=val.find('=') |
661 |
name=val[:pos] |
666 |
name=val[:pos] |
|
673 |
append[name]=value |
678 |
append[name]=value |
674 |
was_set=1 |
679 |
was_set=1 |
675 |
if not was_set: |
680 |
if not was_set: |
676 |
out.append("WARNING: No attribute with name %s in this module, value not appended."%name) |
681 |
print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name |
677 |
|
682 |
|
678 |
elif opt == '--remove': |
683 |
elif opt == '--remove': |
679 |
pos=val.find('=') |
684 |
pos=val.find('=') |
|
696 |
remove[name]=value |
701 |
remove[name]=value |
697 |
was_set=1 |
702 |
was_set=1 |
698 |
if not was_set: |
703 |
if not was_set: |
699 |
out.append("WARNING: No attribute with name %s in this module, value not removed."%name) |
704 |
print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name |
700 |
elif opt == '--remove_referring': |
705 |
elif opt == '--remove_referring': |
701 |
remove_referring=1 |
706 |
remove_referring=1 |
702 |
elif opt == '--recursive': |
707 |
elif opt == '--recursive': |
|
704 |
|
709 |
|
705 |
|
710 |
|
706 |
if action in ['modify','edit','create','new']: |
711 |
if action in ['modify','edit','create','new']: |
707 |
if policy_reference: |
|
|
708 |
for el in policy_reference: |
712 |
for el in policy_reference: |
709 |
oc = lo.get(el,['objectClass']) |
713 |
oc = lo.get(el, ['objectClass']) |
710 |
if not oc: |
714 |
if not oc: |
711 |
out.append("Object to be referenced does not exist:"+el) |
715 |
print >> out, "Object to be referenced does not exist: %s" % (el,) |
712 |
return out + ["OPERATION FAILED"] |
716 |
raise Failed() |
713 |
if not 'univentionPolicy' in oc['objectClass']: |
717 |
if not 'univentionPolicy' in oc['objectClass']: |
714 |
out.append("Object to be referenced is no valid Policy:"+el) |
718 |
print >> out, "Object to be referenced is no valid Policy: %s" % (el,) |
715 |
return out + ["OPERATION FAILED"] |
719 |
raise Failed() |
716 |
|
720 |
|
717 |
|
721 |
|
718 |
#+++# ACTION CREATE #+++# |
722 |
#+++# ACTION CREATE #+++# |
719 |
if action == 'create' or action == 'new': |
723 |
if action == 'create' or action == 'new': |
720 |
if hasattr(module,'operations') and module.operations: |
724 |
if hasattr(module,'operations') and module.operations: |
721 |
if not 'add' in module.operations: |
725 |
if not 'add' in module.operations: |
722 |
out.append('Create %s not allowed' % module_name) |
726 |
print >> out, 'Create %s not allowed' % module_name |
723 |
return out + ["OPERATION FAILED"] |
727 |
raise Failed() |
724 |
try: |
728 |
try: |
725 |
object=module.object(co, lo, position=position, superordinate=superordinate) |
729 |
object=module.object(co, lo, position=position, superordinate=superordinate) |
726 |
except univention.admin.uexceptions.insufficientInformation: |
730 |
except univention.admin.uexceptions.insufficientInformation: |
727 |
out.append('E: Insufficient information') |
731 |
print >> out, 'E: Insufficient information' |
728 |
out.append('Superordinate object is missing') |
732 |
print >> out, 'Superordinate object is missing' |
729 |
return out + ["OPERATION FAILED"] |
733 |
raise Failed() |
730 |
|
734 |
|
731 |
if parsed_options: |
735 |
if parsed_options: |
732 |
object.options=parsed_options |
736 |
object.options=parsed_options |
733 |
|
737 |
|
734 |
object.open() |
738 |
object.open() |
735 |
if hasattr(object,' open_warning') and object.open_warning: |
739 |
if hasattr(object,' open_warning') and object.open_warning: |
736 |
out.append('WAR NING:%s'%object.open_warning) |
740 |
print >> out, 'WARNING:%s' % object.open_warning |
737 |
exists=0 |
741 |
exists=0 |
738 |
try: |
742 |
try: |
739 |
out.extend(object_input(module, object, input, append=append)) |
743 |
object_input(module, object, input, append=append, out=out) |
740 |
except univention.admin.uexceptions.nextFreeIp: |
744 |
except univention.admin.uexceptions.nextFreeIp: |
741 |
if not ignore_exists: |
745 |
if not ignore_exists: |
742 |
out.append('E: No free IP address found') |
746 |
print >> out, 'E: No free IP address found' |
743 |
return out + ['OPERATION FAILED'] |
747 |
raise Failed() |
744 |
except univention.admin.uexceptions.valueInvalidSyntax, err: |
748 |
except univention.admin.uexceptions.valueInvalidSyntax, err: |
745 |
out.append('E: Invalid Syntax: %s' % err) |
749 |
print >> out, 'E: Invalid Syntax: %s' % err |
746 |
return out + ["OPERATION FAILED"] |
750 |
raise Failed() |
747 |
except Exception, err: |
751 |
except Exception, err: |
748 |
out.append('E: Option %s is not valid' %err) |
752 |
print >> out, 'E: Option %s is not valid' % err |
749 |
return out + ['OPERATION FAILED'] |
753 |
raise Failed() |
750 |
|
754 |
|
751 |
exists=0 |
755 |
exists=0 |
752 |
exists_msg=None |
756 |
exists_msg=None |
|
755 |
except univention.admin.uexceptions.objectExists, dn: |
759 |
except univention.admin.uexceptions.objectExists, dn: |
756 |
exists_msg = dn |
760 |
exists_msg = dn |
757 |
if not ignore_exists: |
761 |
if not ignore_exists: |
758 |
out.append('E: Object exists: %s' % exists_msg) |
762 |
print >> out, 'E: Object exists: %s' % exists_msg |
759 |
return out + ["OPERATION FAILED"] |
763 |
raise Failed() |
760 |
else: |
764 |
else: |
761 |
exists=1 |
765 |
exists=1 |
762 |
except univention.admin.uexceptions.uidAlreadyUsed, user: |
766 |
except univention.admin.uexceptions.uidAlreadyUsed, user: |
763 |
exists_msg = '(uid) %s' % user |
767 |
exists_msg = '(uid) %s' % user |
764 |
if not ignore_exists: |
768 |
if not ignore_exists: |
765 |
out.append('E: Object exists: %s' % exists_msg) |
769 |
print >> out, 'E: Object exists: %s' % exists_msg |
766 |
return out + ["OPERATION FAILED"] |
770 |
raise Failed() |
767 |
else: |
771 |
else: |
768 |
exists=1 |
772 |
exists=1 |
769 |
except univention.admin.uexceptions.groupNameAlreadyUsed, group: |
773 |
except univention.admin.uexceptions.groupNameAlreadyUsed, group: |
770 |
exists_msg = '(group) %s' % group |
774 |
exists_msg = '(group) %s' % group |
771 |
if not ignore_exists: |
775 |
if not ignore_exists: |
772 |
out.append('E: Object exists: %s' % exists_msg) |
776 |
print >> out, 'E: Object exists: %s' % exists_msg |
773 |
return out + ["OPERATION FAILED"] |
777 |
raise Failed() |
774 |
else: |
778 |
else: |
775 |
exists=1 |
779 |
exists=1 |
776 |
except univention.admin.uexceptions.dhcpServerAlreadyUsed, name: |
780 |
except univention.admin.uexceptions.dhcpServerAlreadyUsed, name: |
777 |
exists_msg = '(dhcpserver) %s' % name |
781 |
exists_msg = '(dhcpserver) %s' % name |
778 |
if not ignore_exists: |
782 |
if not ignore_exists: |
779 |
out.append('E: Object exists: %s' % exists_msg) |
783 |
print >> out, 'E: Object exists: %s' % exists_msg |
780 |
return out + ["OPERATION FAILED"] |
784 |
raise Failed() |
781 |
else: |
785 |
else: |
782 |
exists=1 |
786 |
exists=1 |
783 |
except univention.admin.uexceptions.macAlreadyUsed, mac: |
787 |
except univention.admin.uexceptions.macAlreadyUsed, mac: |
784 |
exists_msg = '(mac) %s' % mac |
788 |
exists_msg = '(mac) %s' % mac |
785 |
if not ignore_exists: |
789 |
if not ignore_exists: |
786 |
out.append('E: Object exists: %s' % exists_msg) |
790 |
print >> out, 'E: Object exists: %s' % exists_msg |
787 |
return out + ["OPERATION FAILED"] |
791 |
raise Failed() |
788 |
else: |
792 |
else: |
789 |
exists=1 |
793 |
exists=1 |
790 |
except univention.admin.uexceptions.noLock, e: |
794 |
except univention.admin.uexceptions.noLock, e: |
791 |
exists_msg = '(nolock) %s' % str(e) |
795 |
exists_msg = '(nolock) %s' % str(e) |
792 |
if not ignore_exists: |
796 |
if not ignore_exists: |
793 |
out.append('E: Object exists: %s' % exists_msg) |
797 |
print >> out, 'E: Object exists: %s' % exists_msg |
794 |
return out + ["OPERATION FAILED"] |
798 |
raise Failed() |
795 |
else: |
799 |
else: |
796 |
exists=1 |
800 |
exists=1 |
797 |
except univention.admin.uexceptions.invalidDhcpEntry: |
801 |
except univention.admin.uexceptions.invalidDhcpEntry: |
798 |
out.append('E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.') |
802 |
print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' |
799 |
return out + ["OPERATION FAILED"] |
803 |
raise Failed() |
800 |
except univention.admin.uexceptions.invalidOptions, e: |
804 |
except univention.admin.uexceptions.invalidOptions, e: |
801 |
if not ignore_exists: |
805 |
if not ignore_exists: |
802 |
out.append('E: invalid Options: %s' % e) |
806 |
print >> out, 'E: invalid Options: %s' % e |
803 |
return out + ["OPERATION FAILED"] |
807 |
raise Failed() |
804 |
except univention.admin.uexceptions.insufficientInformation: |
808 |
except univention.admin.uexceptions.insufficientInformation: |
805 |
out.append('E: Insufficient information') |
809 |
print >> out, 'E: Insufficient information' |
806 |
out.append('The following parameters are missing:') |
810 |
print >> out, 'The following parameters are missing:' |
807 |
for i in module.property_descriptions: |
811 |
for i in module.property_descriptions: |
808 |
property=module.property_descriptions.get(i) |
812 |
property=module.property_descriptions.get(i) |
809 |
if property.required: |
813 |
if property.required: |
810 |
if not object.has_key(i) or (not object[i] or (type(object[i]) == list and object[i]==[''])): |
814 |
if not object.has_key(i) or (not object[i] or (type(object[i]) == list and object[i]==[''])): |
811 |
out.append(i) |
815 |
print >> out, i |
812 |
return out + ["OPERATION FAILED"] |
816 |
raise Failed() |
813 |
except univention.admin.uexceptions.noObject, e: |
817 |
except univention.admin.uexceptions.noObject, e: |
814 |
out.append('E: object not found: %s' % e) |
818 |
print >> out, 'E: object not found: %s' % e |
815 |
return out + ["OPERATION FAILED"] |
819 |
raise Failed() |
816 |
except univention.admin.uexceptions.circularGroupDependency, e: |
820 |
except univention.admin.uexceptions.circularGroupDependency, e: |
817 |
out.append('E: circular group dependency detected: %s' % e) |
821 |
print >> out, 'E: circular group dependency detected: %s' % e |
818 |
return out + ["OPERATION FAILED"] |
822 |
raise Failed() |
819 |
|
823 |
|
820 |
if policy_reference: |
824 |
if policy_reference: |
821 |
lo.modify(dn,[('objectClass','','univentionPolicyReference')]) |
825 |
lo.modify(dn,[('objectClass','','univentionPolicyReference')]) |
|
826 |
|
830 |
|
827 |
if exists == 1: |
831 |
if exists == 1: |
828 |
if exists_msg: |
832 |
if exists_msg: |
829 |
out.append('Object exists: %s' % exists_msg) |
833 |
print >> out, 'Object exists: %s' % exists_msg |
830 |
else: |
834 |
else: |
831 |
out.append('Object exists') |
835 |
print >> out, 'Object exists' |
832 |
else: |
836 |
else: |
833 |
if not dn: |
837 |
if not dn: |
834 |
dn=object.dn |
838 |
dn=object.dn |
835 |
out.append('Object created: %s' % _2utf8( dn ) ) |
839 |
print >> out, 'Object created: %s' % _2utf8(dn) |
836 |
|
840 |
|
837 |
#+++# ACTION MODIFY #+++# |
841 |
#+++# ACTION MODIFY #+++# |
838 |
elif action == 'modify' or action == 'edit' or action == 'move': |
842 |
elif action == 'modify' or action == 'edit' or action == 'move': |
839 |
if not dn: |
843 |
if not dn: |
840 |
out.append('E: DN is missing') |
844 |
print >> out, 'E: DN is missing' |
841 |
return out + ["OPERATION FAILED"] |
845 |
raise Failed() |
842 |
|
846 |
|
843 |
object_modified = 0 |
847 |
object_modified = 0 |
844 |
|
848 |
|
845 |
if hasattr(module,'operations') and module.operations: |
849 |
if hasattr(module,'operations') and module.operations: |
846 |
if not 'edit' in module.operations: |
850 |
if not 'edit' in module.operations: |
847 |
out.append('Modify %s not allowed' % module_name) |
851 |
print >> out, 'Modify %s not allowed' % module_name |
848 |
return out + ["OPERATION FAILED"] |
852 |
raise Failed() |
849 |
|
853 |
|
850 |
try: |
854 |
try: |
851 |
object=univention.admin.objects.get(module, co, lo, position='', dn=dn) |
855 |
object=univention.admin.objects.get(module, co, lo, position='', dn=dn) |
852 |
except univention.admin.uexceptions.noObject: |
856 |
except univention.admin.uexceptions.noObject: |
853 |
out.append('E: object not found') |
857 |
print >> out, 'E: object not found' |
854 |
return out + ["OPERATION FAILED"] |
858 |
raise Failed() |
855 |
|
859 |
|
856 |
object.open() |
860 |
object.open() |
857 |
if hasattr(object,'open_warning') and object.open_warning: |
861 |
if hasattr(object,'open_warning') and object.open_warning: |
858 |
out.append('WARNING:%s'%object.open_warning) |
862 |
print >> out, 'WARNING:%s' % object.open_warning |
859 |
|
863 |
|
860 |
if action == 'move': |
864 |
if action == 'move': |
861 |
if hasattr(module,'operations') and module.operations: |
865 |
if hasattr(module,'operations') and module.operations: |
862 |
if not 'move' in module.operations: |
866 |
if not 'move' in module.operations: |
863 |
out.append('Move %s not allowed' % module_name) |
867 |
print >> out, 'Move %s not allowed' % module_name |
864 |
return out + ["OPERATION FAILED"] |
868 |
raise Failed() |
865 |
if not position_dn: |
869 |
if not position_dn: |
866 |
out.append("need new position for moving object") |
870 |
print >> out, "need new position for moving object" |
867 |
else: |
871 |
else: |
868 |
res = '' |
872 |
res = '' |
869 |
try: # check if global-position exists |
873 |
try: # check if global-position exists |
|
871 |
except: |
875 |
except: |
872 |
pass |
876 |
pass |
873 |
if not res: |
877 |
if not res: |
874 |
out.append("position does not exsist: %s"%position_dn) |
878 |
print >> out, "position does not exsist: %s" % position_dn |
875 |
return out + ["OPERATION FAILED"] |
879 |
raise Failed() |
876 |
rdn = dn[:string.find(dn,',')] |
880 |
rdn = dn[:string.find(dn,',')] |
877 |
newdn="%s,%s" % (rdn,position_dn) |
881 |
newdn="%s,%s" % (rdn,position_dn) |
878 |
try: |
882 |
try: |
879 |
object.move(newdn) |
883 |
object.move(newdn) |
880 |
object_modified+=1 |
884 |
object_modified+=1 |
881 |
except univention.admin.uexceptions.noObject: |
885 |
except univention.admin.uexceptions.noObject: |
882 |
out.append('E: object not found') |
886 |
print >> out, 'E: object not found' |
883 |
return out + ["OPERATION FAILED"] |
887 |
raise Failed() |
884 |
except univention.admin.uexceptions.ldapError, msg: |
888 |
except univention.admin.uexceptions.ldapError, msg: |
885 |
out.append("ldap Error: %s"%msg) |
889 |
print >> out, "ldap Error: %s" % msg |
886 |
return out + ["OPERATION FAILED"] |
890 |
raise Failed() |
887 |
except univention.admin.uexceptions.nextFreeIp: |
891 |
except univention.admin.uexceptions.nextFreeIp: |
888 |
out.append('E: No free IP address found') |
892 |
print >> out, 'E: No free IP address found' |
889 |
return out + ['OPERATION FAILED'] |
893 |
raise Failed() |
890 |
except univention.admin.uexceptions.valueInvalidSyntax, err: |
894 |
except univention.admin.uexceptions.valueInvalidSyntax, err: |
891 |
out.append('E: Invalid Syntax: %s' % err) |
895 |
print >> out, 'E: Invalid Syntax: %s' % err |
892 |
return out + ["OPERATION FAILED"] |
896 |
raise Failed() |
893 |
except univention.admin.uexceptions.invalidOperation, msg: |
897 |
except univention.admin.uexceptions.invalidOperation, msg: |
894 |
out.append(str(msg)) |
898 |
print >> out, str(msg) |
895 |
return out + ["OPERATION FAILED"] |
899 |
raise Failed() |
896 |
|
900 |
|
897 |
else: # modify |
901 |
else: # modify |
898 |
|
902 |
|
|
903 |
for option in parsed_append_options: |
907 |
for option in parsed_append_options: |
904 |
object.options.append(option) |
908 |
object.options.append(option) |
905 |
try: |
909 |
try: |
906 |
out.extend(object_input(module, object, input, append, remove)) |
910 |
object_input(module, object, input, append, remove, out=out) |
907 |
except univention.admin.uexceptions.valueMayNotChange,e: |
911 |
except univention.admin.uexceptions.valueMayNotChange,e: |
908 |
out.append(unicode(e[0])) |
912 |
print >> out, unicode(e[0]) |
909 |
return out + ["OPERATION FAILED"] |
913 |
raise Failed() |
910 |
if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options: |
914 |
if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options: |
911 |
try: |
915 |
try: |
912 |
dn=object.modify() |
916 |
dn=object.modify() |
913 |
object_modified+=1 |
917 |
object_modified+=1 |
914 |
except univention.admin.uexceptions.noObject: |
918 |
except univention.admin.uexceptions.noObject: |
915 |
out.append('E: object not found') |
919 |
print >> out, 'E: object not found' |
916 |
return out + ["OPERATION FAILED"] |
920 |
raise Failed() |
917 |
except univention.admin.uexceptions.invalidDhcpEntry: |
921 |
except univention.admin.uexceptions.invalidDhcpEntry: |
918 |
out.append('E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.') |
922 |
print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.' |
919 |
return out + ["OPERATION FAILED"] |
923 |
raise Failed() |
920 |
except univention.admin.uexceptions.circularGroupDependency, e: |
924 |
except univention.admin.uexceptions.circularGroupDependency, e: |
921 |
out.append('E: circular group dependency detected: %s' % e) |
925 |
print >> out, 'E: circular group dependency detected: %s' % e |
922 |
return out + ["OPERATION FAILED"] |
926 |
raise Failed() |
923 |
except univention.admin.uexceptions.valueInvalidSyntax, e: |
927 |
except univention.admin.uexceptions.valueInvalidSyntax, e: |
924 |
out.append('E: Invalid Syntax: %s' % e) |
928 |
print >> out, 'E: Invalid Syntax: %s' % e |
925 |
return out + ["OPERATION FAILED"] |
929 |
raise Failed() |
926 |
|
930 |
|
927 |
if policy_reference: |
931 |
if policy_reference: |
928 |
if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']: |
932 |
if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']: |
|
934 |
upr['univentionPolicyReference'] = [] |
938 |
upr['univentionPolicyReference'] = [] |
935 |
for el in policy_reference: |
939 |
for el in policy_reference: |
936 |
if val in upr['univentionPolicyReference']: |
940 |
if val in upr['univentionPolicyReference']: |
937 |
out.append('WARNING: cannot append %s to univentionPolicyReference, value exists' % val) |
941 |
print >> out, 'WARNING: cannot append %s to univentionPolicyReference, value exists' % val |
938 |
else: |
942 |
else: |
939 |
modlist.append(('univentionPolicyReference','',el)) |
943 |
modlist.append(('univentionPolicyReference','',el)) |
940 |
if modlist: |
944 |
if modlist: |
|
949 |
object_modified+=1 |
953 |
object_modified+=1 |
950 |
|
954 |
|
951 |
if object_modified > 0: |
955 |
if object_modified > 0: |
952 |
out.append( 'Object modified: %s'% _2utf8( dn ) ) |
956 |
print >> out, 'Object modified: %s' % _2utf8(dn) |
953 |
else: |
957 |
else: |
954 |
out.append( 'No modification: %s'% _2utf8( dn ) ) |
958 |
print >> out, 'No modification: %s' % _2utf8(dn) |
955 |
|
959 |
|
956 |
elif action == 'remove' or action == 'delete': |
960 |
elif action == 'remove' or action == 'delete': |
957 |
|
961 |
|
958 |
if hasattr(module,'operations') and module.operations: |
962 |
if hasattr(module,'operations') and module.operations: |
959 |
if not 'remove' in module.operations: |
963 |
if not 'remove' in module.operations: |
960 |
out.append('Remove %s not allowed' % module_name) |
964 |
print >> out, 'Remove %s not allowed' % module_name |
961 |
return out + ["OPERATION FAILED"] |
965 |
raise Failed() |
962 |
|
966 |
|
963 |
try: |
967 |
try: |
964 |
if dn and filter: |
968 |
if dn and filter: |
|
968 |
elif filter: |
972 |
elif filter: |
969 |
object=univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter, required=1, unique=1)[0] |
973 |
object=univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter, required=1, unique=1)[0] |
970 |
else: |
974 |
else: |
971 |
out.append('E: dn or filter needed') |
975 |
print >> out, 'E: dn or filter needed' |
972 |
return out + ["OPERATION FAILED"] |
976 |
raise Failed() |
973 |
except (univention.admin.uexceptions.noObject, IndexError): |
977 |
except (univention.admin.uexceptions.noObject, IndexError): |
974 |
out.append('E: object not found') |
978 |
print >> out, 'E: object not found' |
975 |
return out + ["OPERATION FAILED"] |
979 |
raise Failed() |
976 |
|
980 |
|
977 |
object.open() |
981 |
object.open() |
978 |
if hasattr(object,'open_warning') and object.open_warning: |
982 |
if hasattr(object,'open_warning') and object.open_warning: |
979 |
out.append('WARNING:%s'%object.open_warning) |
983 |
print >> out, 'WARNING:%s' % object.open_warning |
980 |
|
984 |
|
981 |
if remove_referring and univention.admin.objects.wantsCleanup(object): |
985 |
if remove_referring and univention.admin.objects.wantsCleanup(object): |
982 |
univention.admin.objects.performCleanup(object) |
986 |
univention.admin.objects.performCleanup(object) |
|
985 |
try: |
989 |
try: |
986 |
object.remove(recursive) |
990 |
object.remove(recursive) |
987 |
except univention.admin.uexceptions.ldapError,msg: |
991 |
except univention.admin.uexceptions.ldapError,msg: |
988 |
out.append(str(msg)) |
992 |
print >> out, str(msg) |
989 |
return out + ["OPERATION FAILED"] |
993 |
raise Failed() |
990 |
else: |
994 |
else: |
991 |
try: |
995 |
try: |
992 |
object.remove() |
996 |
object.remove() |
993 |
except univention.admin.uexceptions.primaryGroupUsed: |
997 |
except univention.admin.uexceptions.primaryGroupUsed: |
994 |
out.append('E: object in use') |
998 |
print >> out, 'E: object in use' |
995 |
return out + ["OPERATION FAILED"] |
999 |
raise Failed() |
996 |
out.append( 'Object removed: %s'% _2utf8( dn ) ) |
1000 |
print >> out, 'Object removed: %s' % _2utf8(dn) |
997 |
|
1001 |
|
998 |
elif action == 'list' or action == 'lookup': |
1002 |
elif action == 'list' or action == 'lookup': |
999 |
|
1003 |
|
1000 |
if hasattr(module,'operations') and module.operations: |
1004 |
if hasattr(module,'operations') and module.operations: |
1001 |
if not 'search' in module.operations: |
1005 |
if not 'search' in module.operations: |
1002 |
out.append('Search %s not allowed' % module_name) |
1006 |
print >> out, 'Search %s not allowed' % module_name |
1003 |
return out + ["OPERATION FAILED"] |
1007 |
raise Failed() |
1004 |
|
1008 |
|
1005 |
out.append( _2utf8( filter ) ) |
1009 |
print >> out, _2utf8(filter) |
1006 |
|
1010 |
|
1007 |
try: |
1011 |
try: |
1008 |
for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter): |
1012 |
for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter): |
1009 |
out.append( 'DN: %s' % _2utf8( univention.admin.objects.dn (object ) ) ) |
1013 |
print >> out, 'DN: %s' % _2utf8(univention.admin.objects.dn(object)) |
1010 |
|
1014 |
|
1011 |
if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'): |
1015 |
if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'): |
1012 |
object.open() |
1016 |
object.open() |
1013 |
if hasattr(object,'open_warning') and object.open_warning: |
1017 |
if hasattr(object,'open_warning') and object.open_warning: |
1014 |
out.append('WARNING: %s'%object.open_warning) |
1018 |
print >> out, 'WARNING: %s' % object.open_warning |
1015 |
for key, value in object.items(): |
1019 |
for key, value in object.items(): |
1016 |
s=module.property_descriptions[key].syntax |
1020 |
s=module.property_descriptions[key].syntax |
1017 |
if module.property_descriptions[key].multivalue: |
1021 |
if module.property_descriptions[key].multivalue: |
1018 |
for v in value: |
1022 |
for v in value: |
1019 |
if s.tostring(v): |
1023 |
if s.tostring(v): |
1020 |
out.append(' %s: %s' % ( _2utf8( key ), _2utf8( s.tostring( v ) ) ) ) |
1024 |
print >> out, ' %s: %s' % (_2utf8(key), _2utf8(s.tostring(v))) |
1021 |
else: |
1025 |
else: |
1022 |
out.append(' %s: %s' % ( _2utf8( key ), None ) ) |
1026 |
print >> out, ' %s: %s' % (_2utf8(key), None) |
1023 |
else: |
1027 |
else: |
1024 |
if s.tostring(value): |
1028 |
if s.tostring(value): |
1025 |
out.append(' %s: %s' % ( _2utf8( key ), _2utf8( s.tostring( value ) ) ) ) |
1029 |
print >> out, ' %s: %s' % (_2utf8(key), _2utf8(s.tostring(value))) |
1026 |
else: |
1030 |
else: |
1027 |
out.append(' %s: %s' % ( _2utf8( key ), None ) ) |
1031 |
print >> out, ' %s: %s' % (_2utf8(key), None) |
1028 |
|
1032 |
|
1029 |
if 'univentionPolicyReference' in lo.get(univention.admin.objects.dn(object),['objectClass'])['objectClass']: |
1033 |
if 'univentionPolicyReference' in lo.get(univention.admin.objects.dn(object),['objectClass'])['objectClass']: |
1030 |
references = lo.get( _2utf8(univention.admin.objects.dn( object ) ), |
1034 |
references = lo.get( _2utf8(univention.admin.objects.dn( object ) ), |
1031 |
[ 'univentionPolicyReference' ] ) |
1035 |
[ 'univentionPolicyReference' ] ) |
1032 |
if references: |
1036 |
if references: |
1033 |
for el in references['univentionPolicyReference']: |
1037 |
for el in references['univentionPolicyReference']: |
1034 |
out.append(' %s: %s' % ( 'univentionPolicyReference', |
1038 |
print >> out, ' %s: %s' % ( |
1035 |
_2utf8( s.tostring( el ) ) ) ) |
1039 |
'univentionPolicyReference', |
|
|
1040 |
_2utf8(s.tostring(el)) |
1041 |
) |
1036 |
|
1042 |
|
1037 |
if list_policies: |
1043 |
if list_policies: |
1038 |
utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) ) |
1044 |
utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) ) |
1039 |
p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_objectdn], stdout=subprocess.PIPE) |
1045 |
p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_objectdn], stdout=subprocess.PIPE) |
1040 |
policyResults = p1.communicate()[0].split('\n') |
1046 |
policyResults = p1.communicate()[0].split('\n') |
1041 |
|
1047 |
|
1042 |
out.append(" Policy-based Settings:") |
1048 |
print >> out, " Policy-based Settings:" |
1043 |
policy='' |
1049 |
policy='' |
1044 |
value=[] |
1050 |
value=[] |
1045 |
client={} |
1051 |
client={} |
1046 |
for line in policyResults: |
1052 |
for line in policyResults: |
1047 |
if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): |
1053 |
if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): |
1048 |
out.append(" %s"%line.strip()) |
1054 |
print >> out, " %s" % line.strip() |
1049 |
if policies_with_DN: |
1055 |
if policies_with_DN: |
1050 |
clsplit=string.split(line.strip(), ': ') |
1056 |
clsplit=string.split(line.strip(), ': ') |
1051 |
if clsplit[0] == 'Policy': |
1057 |
if clsplit[0] == 'Policy': |
Lines 1067-1073
def _doit(arglist):
|
Link Here
|
---|
|
1067 |
client[attribute]=[policy, value] |
1073 |
client[attribute]=[policy, value] |
1068 |
value=[] |
1074 |
value=[] |
1069 |
|
1075 |
|
1070 |
out.append('') |
1076 |
print >> out, '' |
1071 |
|
1077 |
|
1072 |
if module_name == 'dhcp/host': |
1078 |
if module_name == 'dhcp/host': |
1073 |
subnet_module=univention.admin.modules.get('dhcp/subnet') |
1079 |
subnet_module=univention.admin.modules.get('dhcp/subnet') |
Lines 1077-1089
def _doit(arglist):
|
Link Here
|
---|
|
1077 |
utf8_subnet_dn = _2utf8( subnet.dn ) |
1083 |
utf8_subnet_dn = _2utf8( subnet.dn ) |
1078 |
p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_subnet_dn], stdout=subprocess.PIPE) |
1084 |
p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_subnet_dn], stdout=subprocess.PIPE) |
1079 |
policyResults = p1.communicate()[0].split('\n') |
1085 |
policyResults = p1.communicate()[0].split('\n') |
1080 |
out.append(" Subnet-based Settings:") |
1086 |
print >> out, " Subnet-based Settings:" |
1081 |
ddict={} |
1087 |
ddict={} |
1082 |
policy='' |
1088 |
policy='' |
1083 |
value=[] |
1089 |
value=[] |
1084 |
for line in policyResults: |
1090 |
for line in policyResults: |
1085 |
if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): |
1091 |
if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "): |
1086 |
out.append(" %s"%line.strip()) |
1092 |
print >> out, " %s" % line.strip() |
1087 |
if policies_with_DN: |
1093 |
if policies_with_DN: |
1088 |
subsplit=string.split(line.strip(), ': ') |
1094 |
subsplit=string.split(line.strip(), ': ') |
1089 |
if subsplit[0] == 'Policy': |
1095 |
if subsplit[0] == 'Policy': |
Lines 1101-1113
def _doit(arglist):
|
Link Here
|
---|
|
1101 |
ddict[subsplit[0]] = [] |
1107 |
ddict[subsplit[0]] = [] |
1102 |
ddict[subsplit[0]].append(subsplit[1]) |
1108 |
ddict[subsplit[0]].append(subsplit[1]) |
1103 |
|
1109 |
|
1104 |
out.append('') |
1110 |
print >> out, '' |
1105 |
|
1111 |
|
1106 |
if policies_with_DN: |
1112 |
if policies_with_DN: |
1107 |
ddict[attribute]=[policy, value] |
1113 |
ddict[attribute]=[policy, value] |
1108 |
value=[] |
|
|
1109 |
|
1114 |
|
1110 |
out.append(" Merged Settings:") |
1115 |
print >> out, " Merged Settings:" |
1111 |
|
1116 |
|
1112 |
for key in ddict.keys(): |
1117 |
for key in ddict.keys(): |
1113 |
if not client.has_key(key): |
1118 |
if not client.has_key(key): |
Lines 1115-1141
def _doit(arglist):
|
Link Here
|
---|
|
1115 |
|
1120 |
|
1116 |
if policies_with_DN: |
1121 |
if policies_with_DN: |
1117 |
for key in client.keys(): |
1122 |
for key in client.keys(): |
1118 |
out.append(" Policy: "+client[key][0]) |
1123 |
print >> out, " Policy: " + client[key][0] |
1119 |
out.append(" Attribute: "+key) |
1124 |
print >> out, " Attribute: " + key |
1120 |
for i in range(0, len(client[key][1])): |
1125 |
for i in range(0, len(client[key][1])): |
1121 |
out.append(" Value: "+client[key][1][i]) |
1126 |
print >> out, " Value: " + client[key][1][i] |
1122 |
else: |
1127 |
else: |
1123 |
for key in client.keys(): |
1128 |
for key in client.keys(): |
1124 |
for i in range(0, len(client[key])): |
1129 |
for i in range(0, len(client[key])): |
1125 |
out.append(" %s=%s" % (key, client[key][i])) |
1130 |
print >> out, " %s=%s" % (key, client[key][i]) |
1126 |
out.append('') |
1131 |
print >> out, '' |
1127 |
|
1132 |
|
1128 |
out.append('') |
1133 |
print >> out, '' |
1129 |
except univention.admin.uexceptions.ldapError, errmsg: |
1134 |
except univention.admin.uexceptions.ldapError, errmsg: |
1130 |
out.append('%s' %str(errmsg)) |
1135 |
print >> out, '%s' % (errmsg,) |
1131 |
return out + ["OPERATION FAILED"] |
1136 |
raise Failed() |
1132 |
except univention.admin.uexceptions.valueInvalidSyntax, errmsg: |
1137 |
except univention.admin.uexceptions.valueInvalidSyntax, errmsg: |
1133 |
out.append('%s' %str(errmsg.message)) |
1138 |
print >> out, '%s' % (errmsg.message,) |
1134 |
return out + ["OPERATION FAILED"] |
1139 |
raise Failed() |
1135 |
else: |
1140 |
else: |
1136 |
out.append("Unknown or no action defined") |
1141 |
print >> out, "Unknown or no action defined" |
1137 |
out.append('') |
1142 |
print >> out, '' |
1138 |
usage() |
1143 |
raise Failed() |
1139 |
return out + ["OPERATION FAILED"] |
|
|
1140 |
|
1141 |
return out # nearly the only successfull return |