View | Details | Raw Unified | Return to bug 33224 | Differences between
and this patch

Collapse All | Expand All

(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-3 / +1 lines)
 Lines 476-482   def _doit(arglist): Link Here 
476
		elif opt == '--logfile':
476
		elif opt == '--logfile':
477
			logfile=val
477
			logfile=val
478
		elif opt == '--policies':
478
		elif opt == '--policies':
479
			policies = True
479
			list_policies = True
480
			if val=="1":
480
			if val=="1":
481
				policies_with_DN = True
481
				policies_with_DN = True
482
			else:
482
			else:
483
- 
484
--
485
.../modules/univention/admincli/admin.py                                | 2 +-
483
.../modules/univention/admincli/admin.py                                | 2 +-
486
1 file changed, 1 insertion(+), 1 deletion(-)
484
1 file changed, 1 insertion(+), 1 deletion(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-3 / +1 lines)
 Lines 934-940   def _doit(arglist): Link Here 
934
				out.append("need new position for moving object")
934
				out.append("need new position for moving object")
935
			else:
935
			else:
936
				res = ''
936
				res = ''
937
				try: # check if goal-position exists
937
				try:  # check if global-position exists
938
					res = lo.get(position_dn)
938
					res = lo.get(position_dn)
939
				except:
939
				except:
940
					pass
940
					pass
941
- 
942
--
943
.../modules/univention/admincli/admin.py           | 31 +++++++++++++++++-----
941
.../modules/univention/admincli/admin.py           | 31 +++++++++++++++++-----
944
1 file changed, 24 insertions(+), 7 deletions(-)
942
1 file changed, 24 insertions(+), 7 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-9 / +24 lines)
 Lines 95-101   def usage(): Link Here 
95
	out.append('  --%-30s %s' % ('bindpwd', 'bind password'))
95
	out.append('  --%-30s %s' % ('bindpwd', 'bind password'))
96
	out.append('  --%-30s %s' % ('bindpwdfile', 'file containing bind password'))
96
	out.append('  --%-30s %s' % ('bindpwdfile', 'file containing bind password'))
97
	out.append('  --%-30s %s' % ('dn', 'Edit object with DN'))
97
	out.append('  --%-30s %s' % ('dn', 'Edit object with DN'))
98
	out.append('  --%-30s %s' % ('arg', 'Edit object with ARG'))
99
	out.append('  --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar'))
98
	out.append('  --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar'))
100
	out.append('  --%-30s %s' % ('append', 'Append value to variable, e.g. foo=bar'))
99
	out.append('  --%-30s %s' % ('append', 'Append value to variable, e.g. foo=bar'))
101
	out.append('  --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar'))
100
	out.append('  --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar'))
 Lines 113-119   def usage(): Link Here 
113
	out.append('  --%-30s %s' % ('bindpwdfile', 'file containing bind password'))
112
	out.append('  --%-30s %s' % ('bindpwdfile', 'file containing bind password'))
114
	out.append('  --%-30s %s' % ('dn', 'Remove object with DN'))
113
	out.append('  --%-30s %s' % ('dn', 'Remove object with DN'))
115
	out.append('  --%-30s %s' % ('superordinate', 'Use superordinate module'))
114
	out.append('  --%-30s %s' % ('superordinate', 'Use superordinate module'))
116
	out.append('  --%-30s %s' % ('arg', 'Remove object with ARG'))
117
	out.append('  --%-30s %s' % ('filter', 'Lookup filter e.g. foo=bar'))
115
	out.append('  --%-30s %s' % ('filter', 'Lookup filter e.g. foo=bar'))
118
	out.append('  --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)'))
116
	out.append('  --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)'))
119
	out.append('  --%-30s %s' % ('remove_referring', 'remove referring objects'))
117
	out.append('  --%-30s %s' % ('remove_referring', 'remove referring objects'))
 Lines 435-441   def _doit(arglist): Link Here 
435
	remove_referring=0
433
	remove_referring=0
436
	recursive=1
434
	recursive=1
437
	# parse options
435
	# parse options
438
	longopts=['position=', 'dn=', 'arg=', 'set=', 'append=', 'remove=', 'superordinate=', 'option=', 'append-option=', 'filter=', 'tls=', 'ignore_exists', 'logfile=', 'policies=', 'binddn=', 'bindpwd=', 'bindpwdfile=', 'customattribute=', 'customattribute-remove=','policy-reference=','policy-dereference=','remove_referring','recursive']
436
	longopts = [
437
		'position=',
438
		'dn=',
439
		'set=',
440
		'append=',
441
		'remove=',
442
		'superordinate=',
443
		'option=',
444
		'append-option=',
445
		'filter=',
446
		'tls=',
447
		'ignore_exists',
448
		'logfile=',
449
		'policies=',
450
		'binddn=',
451
		'bindpwd=',
452
		'bindpwdfile=',
453
		'customattribute=',
454
		'customattribute-remove=',
455
		'policy-reference=',
456
		'policy-dereference=',
457
		'remove_referring',
458
		'recursive'
459
	]
439
	try:
460
	try:
440
		opts, args=getopt.getopt(arglist[3:], '', longopts)
461
		opts, args=getopt.getopt(arglist[3:], '', longopts)
441
	except getopt.error, msg:
462
	except getopt.error, msg:
 Lines 450-456   def _doit(arglist): Link Here 
450
471
451
	position_dn=''
472
	position_dn=''
452
	dn=''
473
	dn=''
453
	arg=None
454
	binddn=None
474
	binddn=None
455
	bindpwd=None
475
	bindpwd=None
456
	list_policies=False
476
	list_policies=False
 Lines 494-501   def _doit(arglist): Link Here 
494
				return out + ['OPERATION FAILED']
514
				return out + ['OPERATION FAILED']
495
		elif opt == '--dn':
515
		elif opt == '--dn':
496
			dn = _2utf8( val )
516
			dn = _2utf8( val )
497
		elif opt == '--arg':
498
			arg=val
499
		elif opt == '--tls':
517
		elif opt == '--tls':
500
			tls=val
518
			tls=val
501
		elif opt == '--ignore_exists':
519
		elif opt == '--ignore_exists':
 Lines 1121-1127   def _doit(arglist): Link Here 
1121
		try:
1139
		try:
1122
			for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter):
1140
			for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter):
1123
				out.append( 'DN: %s' % _2utf8( univention.admin.objects.dn (object ) ) )
1141
				out.append( 'DN: %s' % _2utf8( univention.admin.objects.dn (object ) ) )
1124
				out.append( 'ARG: %s' % univention.admin.objects.arg( object ) )
1125
1142
1126
				if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'):
1143
				if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'):
1127
					object.open()
1144
					object.open()
1128
- 
1129
--
1130
.../modules/univention/admincli/admin.py           | 132 ---------------------
1145
.../modules/univention/admincli/admin.py           | 132 ---------------------
1131
1 file changed, 132 deletions(-)
1146
1 file changed, 132 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-134 lines)
 Lines 85-91   def usage(): Link Here 
85
	out.append('  --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar'))
85
	out.append('  --%-30s %s' % ('set', 'Set variable to value, e.g. foo=bar'))
86
	out.append('  --%-30s %s' % ('superordinate', 'Use superordinate module'))
86
	out.append('  --%-30s %s' % ('superordinate', 'Use superordinate module'))
87
	out.append('  --%-30s %s' % ('option', 'Use only given module options'))
87
	out.append('  --%-30s %s' % ('option', 'Use only given module options'))
88
	out.append('  --%-30s %s' % ('customattribute', 'Set custom attribute foo=bar'))
89
	out.append('  --%-30s %s' % ('policy-reference', 'Reference to policy given by DN'))
88
	out.append('  --%-30s %s' % ('policy-reference', 'Reference to policy given by DN'))
90
	out.append('  --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)'))
89
	out.append('  --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)'))
91
	out.append('  --%-30s   ' % ('ignore_exists'))
90
	out.append('  --%-30s   ' % ('ignore_exists'))
 Lines 100-107   def usage(): Link Here 
100
	out.append('  --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar'))
99
	out.append('  --%-30s %s' % ('remove', 'Remove value from variable, e.g. foo=bar'))
101
	out.append('  --%-30s %s' % ('option', 'Use only given module options'))
100
	out.append('  --%-30s %s' % ('option', 'Use only given module options'))
102
	out.append('  --%-30s %s' % ('append-option', 'Append the module options'))
101
	out.append('  --%-30s %s' % ('append-option', 'Append the module options'))
103
	out.append('  --%-30s %s' % ('customattribute', 'Set custom attribute foo=bar'))
104
	out.append('  --%-30s %s' % ('customattribute-remove', 'Remove custom attribute'))
105
	out.append('  --%-30s %s' % ('policy-reference', 'Reference to policy given by DN'))
102
	out.append('  --%-30s %s' % ('policy-reference', 'Reference to policy given by DN'))
106
	out.append('  --%-30s %s' % ('policy-dereference', 'Remove reference to policy given by DN'))
103
	out.append('  --%-30s %s' % ('policy-dereference', 'Remove reference to policy given by DN'))
107
	out.append('  --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)'))
104
	out.append('  --%-30s %s' % ('tls', '0 (no); 1 (try); 2 (must)'))
 Lines 450-457   def _doit(arglist): Link Here 
450
		'binddn=',
447
		'binddn=',
451
		'bindpwd=',
448
		'bindpwd=',
452
		'bindpwdfile=',
449
		'bindpwdfile=',
453
		'customattribute=',
454
		'customattribute-remove=',
455
		'policy-reference=',
450
		'policy-reference=',
456
		'policy-dereference=',
451
		'policy-dereference=',
457
		'remove_referring',
452
		'remove_referring',
 Lines 486-493   def _doit(arglist): Link Here 
486
	input={}
481
	input={}
487
	append={}
482
	append={}
488
	remove={}
483
	remove={}
489
	customattribute={}
490
	customattribute_remove=[]
491
	policy_reference=[]
484
	policy_reference=[]
492
	policy_dereference=[]
485
	policy_dereference=[]
493
	for opt, val in opts:
486
	for opt, val in opts:
 Lines 526-546   def _doit(arglist): Link Here 
526
			parsed_append_options.append(val)
519
			parsed_append_options.append(val)
527
		elif opt == '--filter':
520
		elif opt == '--filter':
528
			filter=val
521
			filter=val
529
		elif opt == '--customattribute':
530
			pos=val.find('=')
531
			name=val[:pos]
532
			value= _2utf8( val[ pos + 1 : ] )
533
			if not customattribute.has_key(name):
534
				customattribute[name]=[]
535
			customattribute[name].append(value)
536
		elif opt == '--customattribute-remove':
537
			pos=val.find('=')
538
			if pos == -1:
539
				customattribute_remove.append((val,None))
540
			else:
541
				name=val[:pos]
542
				value = _2utf8( val[ pos + 1 : ] )
543
				customattribute_remove.append((name,value))
544
		elif opt == '--policy-reference':
522
		elif opt == '--policy-reference':
545
			policy_reference.append(val)
523
			policy_reference.append(val)
546
		elif opt == '--policy-dereference':
524
		elif opt == '--policy-dereference':
 Lines 725-777   def _doit(arglist): Link Here 
725
			recursive=1
703
			recursive=1
726
704
727
705
728
	extraOC=[]
729
	extraAttributes=[]
730
	customattributes_set =[]
731
	if hasattr(module, 'ldap_extra_objectclasses') and action in ['modify','edit','create','new']:
732
		for oc, pname, syntax, ldapMapping, deleteValues, deleteObjectClass in module.ldap_extra_objectclasses:
733
			if customattribute.has_key(module.property_descriptions[pname].short_description):
734
				customattributes_set.append(module.property_descriptions[pname].short_description)
735
				extraOC.append(oc);
736
				# check multivalue
737
				if module.property_descriptions[pname].multivalue:
738
					if action in ['create','new'] or not dn or dn == '':
739
						values_found=[]
740
					else:
741
						values_found=lo.search(base=dn, attr=[ldapMapping])
742
					for i in customattribute[module.property_descriptions[pname].short_description]:
743
						value_already_set=0
744
						for tmp,val in values_found:
745
							if val.has_key(ldapMapping):
746
								if i in val[ldapMapping]:
747
									value_already_set=1
748
						if value_already_set:
749
							out.append('WARNING: customattribute %s is already set to %s'%(module.property_descriptions[pname].short_description,i))
750
						else:
751
							extraAttributes.append((ldapMapping,'',[i]))
752
				else:
753
					if len(customattribute[module.property_descriptions[pname].short_description])>1:
754
						out.append('WARNING: cannot set singlevalue customattribute "%s" with more than one entry'%module.property_descriptions[pname].short_description)
755
					else:
756
						replaced=0
757
						if action in ['create','new'] or not dn or dn == '':
758
							values_found=[]
759
						else:
760
							values_found=lo.search(base=dn, attr=[ldapMapping])
761
						for tmp,val in values_found:
762
							if val.has_key(ldapMapping):
763
								extraAttributes.append((ldapMapping,val[ldapMapping][0],[customattribute[module.property_descriptions[pname].short_description][0]]))
764
								replaced = 1
765
								if len(val[ldapMapping]) > 1:
766
									out.append("WARNING: singlevalue customattribute %s has more than one value set, replace first"%customattribute[module.property_descriptions[pname].short_description])
767
						if not replaced:
768
							extraAttributes.append((ldapMapping,'',[customattribute[module.property_descriptions[pname].short_description][0]]))
769
770
	if action in ['modify','edit','create','new']:
706
	if action in ['modify','edit','create','new']:
771
		for i in customattribute.keys():
772
			if not i in customattributes_set:
773
				out.append("WARNING: customattribute %s not found, value not set"%i)
774
775
		if policy_reference:
707
		if policy_reference:
776
			for el in policy_reference:
708
			for el in policy_reference:
777
				oc = lo.get(el,['objectClass'])
709
				oc = lo.get(el,['objectClass'])
 Lines 885-908   def _doit(arglist): Link Here 
885
				out.append('E: circular group dependency detected: %s' % e)
817
				out.append('E: circular group dependency detected: %s' % e)
886
				return out + ["OPERATION FAILED"]
818
				return out + ["OPERATION FAILED"]
887
819
888
			if extraOC or extraAttributes:
889
				if extraOC:
890
					oc=lo.search(base=dn, scope='base', attr=['objectClass'])
891
892
					noc=[]
893
					for i in range(len(oc[0][1]['objectClass'])):
894
						noc.append(oc[0][1]['objectClass'][i])
895
896
					for i in range(len(extraOC)):
897
						if extraOC[i] not in noc:
898
							noc.append(extraOC[i])
899
900
					if oc != noc:
901
						extraAttributes.append(('objectClass',oc,noc))
902
903
				if extraAttributes:
904
					lo.modify(dn,extraAttributes)
905
906
			if policy_reference:
820
			if policy_reference:
907
				lo.modify(dn,[('objectClass','','univentionPolicyReference')])
821
				lo.modify(dn,[('objectClass','','univentionPolicyReference')])
908
				modlist=[]
822
				modlist=[]
 Lines 1010-1061   def _doit(arglist): Link Here 
1010
						out.append('E: Invalid Syntax: %s' % e)
924
						out.append('E: Invalid Syntax: %s' % e)
1011
						return out + ["OPERATION FAILED"]
925
						return out + ["OPERATION FAILED"]
1012
926
1013
			if extraOC or extraAttributes:
1014
				if extraOC:
1015
					oc=lo.search(base=dn, scope='base', attr=['objectClass'])
1016
1017
					noc=[]
1018
					for i in range(len(oc[0][1]['objectClass'])):
1019
						noc.append(oc[0][1]['objectClass'][i])
1020
1021
					for i in range(len(extraOC)):
1022
						if not extraOC[i] in noc:
1023
							noc.append(extraOC[i])
1024
1025
					if noc != oc[0][1]['objectClass']:
1026
						extraAttributes.append(('objectClass',oc[0][1]['objectClass'],noc))
1027
				if extraAttributes:
1028
					try:
1029
						lo.modify(dn,extraAttributes)
1030
						object_modified+=1
1031
					except univention.admin.uexceptions.ldapError, msg:
1032
						out.append("ldap Error: %s"%msg)
1033
1034
			if customattribute_remove:
1035
				extraAttributes=[]
1036
				removed_attributes=[]
1037
				if hasattr(module, 'ldap_extra_objectclasses'):
1038
					for oc, pname, syntax, ldapMapping, deleteValues, deleteObjectClass in module.ldap_extra_objectclasses:
1039
						for index in range(0,len(customattribute_remove)):
1040
							if customattribute_remove[index][0] == module.property_descriptions[pname].short_description:
1041
								for tmp,val in lo.search(base=dn, attr=[ldapMapping]):
1042
									if val.has_key(ldapMapping):
1043
										for i in range(0, len(val[ldapMapping])):
1044
											if (not customattribute_remove[index][1]) or customattribute_remove[index][1] == val[ldapMapping][i]:
1045
												extraAttributes.append((ldapMapping,val[ldapMapping][i],''))
1046
												removed_attributes.append(module.property_descriptions[pname].short_description)
1047
									else:
1048
										out.append("customattribute %s not set"%module.property_descriptions[pname].short_description)
1049
										removed_attributes.append(module.property_descriptions[pname].short_description)
1050
1051
				if extraAttributes:
1052
					lo.modify(dn,extraAttributes)
1053
					object_modified+=1
1054
1055
				for n,v in customattribute_remove:
1056
					if not n in removed_attributes:
1057
						out.append("WARNING: customattribute %s not found"%n)
1058
1059
			if policy_reference:
927
			if policy_reference:
1060
				if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']:
928
				if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']:
1061
					lo.modify(dn,[('objectClass','','univentionPolicyReference')])
929
					lo.modify(dn,[('objectClass','','univentionPolicyReference')])
1062
- 
1063
--
1064
.../modules/univention/admincli/admin.py           | 582 +++++++++++----------
930
.../modules/univention/admincli/admin.py           | 582 +++++++++++----------
1065
.../univention-cli-server                          |   9 +-
931
.../univention-cli-server                          |   9 +-
1066
2 files changed, 300 insertions(+), 291 deletions(-)
932
2 files changed, 300 insertions(+), 291 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-290 / +292 lines)
 Lines 30-36    Link Here 
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:[{},{}]}
 Lines 243-250   def _2utf8( text ): Link Here 
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
 Lines 406-431   def doit(arglist): Link Here 
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
 Lines 455-468   def _doit(arglist): Link Here 
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=''
 Lines 503-510   def _doit(arglist): Link Here 
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':
 Lines 527-533   def _doit(arglist): Link Here 
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()
 Lines 553-560   def _doit(arglist): Link Here 
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:
 Lines 568-579   def _doit(arglist): Link Here 
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
 Lines 581-588   def _doit(arglist): Link Here 
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
 Lines 593-612   def _doit(arglist): Link Here 
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)
 Lines 617-637   def _doit(arglist): Link Here 
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:
 Lines 655-661   def _doit(arglist): Link Here 
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]
 Lines 673-679   def _doit(arglist): Link Here 
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('=')
 Lines 696-702   def _doit(arglist): Link Here 
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':
 Lines 704-752   def _doit(arglist): Link Here 
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
 Lines 755-821   def _doit(arglist): Link Here 
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')])
 Lines 826-869   def _doit(arglist): Link Here 
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
 Lines 871-898   def _doit(arglist): Link Here 
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
 Lines 903-928   def _doit(arglist): Link Here 
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']:
 Lines 934-940   def _doit(arglist): Link Here 
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:
 Lines 949-964   def _doit(arglist): Link Here 
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:
 Lines 968-982   def _doit(arglist): Link Here 
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)
 Lines 985-1051   def _doit(arglist): Link Here 
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
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server (-3 / +8 lines)
 Lines 48-53   try: Link Here 
48
	licenseImportError = False
48
	licenseImportError = False
49
except ImportError:
49
except ImportError:
50
	licenseImportError = True
50
	licenseImportError = True
51
try:
52
	from cStringIO import StringIO
53
except ImportError:
54
	from StringIO import StringIO
51
55
52
logfile = ''
56
logfile = ''
53
57
 Lines 219-225   def doit(sarglist, conn): Link Here 
219
		if cmdfile in ('univention-admin', 'univention-directory-manager', 'udm'):
223
		if cmdfile in ('univention-admin', 'univention-directory-manager', 'udm'):
220
			ud.debug(ud.ADMIN, ud.PROCESS, 'daemon [%s] [%s] Calling univention-directory-manager' % (os.getppid(), os.getpid()))
224
			ud.debug(ud.ADMIN, ud.PROCESS, 'daemon [%s] [%s] Calling univention-directory-manager' % (os.getppid(), os.getpid()))
221
			ud.debug(ud.ADMIN, ud.ALL, 'daemon [%s] [%s] arglist: %s' % (os.getppid(), os.getpid(), arglist))
225
			ud.debug(ud.ADMIN, ud.ALL, 'daemon [%s] [%s] arglist: %s' % (os.getppid(), os.getpid(), arglist))
222
			output = univention.admincli.admin.doit(arglist)
226
			stream = StringIO()
227
			univention.admincli.admin.doit(arglist, stream)
228
			value = stream.getvalue()
229
			output = value.splitlines()
223
		elif cmdfile == 'univention-passwd':
230
		elif cmdfile == 'univention-passwd':
224
			ud.debug(ud.ADMIN, ud.PROCESS, 'daemon [%s] [%s] Calling univention-passwd' % (os.getppid(), os.getpid()))
231
			ud.debug(ud.ADMIN, ud.PROCESS, 'daemon [%s] [%s] Calling univention-passwd' % (os.getppid(), os.getpid()))
225
			ud.debug(ud.ADMIN, ud.ALL, 'daemon [%s] [%s] arglist: %s' % (os.getppid(), os.getpid(), arglist))
232
			ud.debug(ud.ADMIN, ud.ALL, 'daemon [%s] [%s] arglist: %s' % (os.getppid(), os.getpid(), arglist))
226
- 
227
--
228
.../modules/univention/admincli/admin.py                             | 5 +++++
233
.../modules/univention/admincli/admin.py                             | 5 +++++
229
1 file changed, 5 insertions(+)
234
1 file changed, 5 insertions(+)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-2 / +5 lines)
 Lines 1141-1143   def _doit(arglist, out=sys.stdout): Link Here 
1141
		print >> out, "Unknown or no action defined"
1141
		print >> out, "Unknown or no action defined"
1142
		print >> out, ''
1142
		print >> out, ''
1143
		raise Failed()
1143
		raise Failed()
1144
- 
1144
1145
--
1145
1146
if __name__ == '__main__':
1147
	import sys
1148
	doit(sys.argv, sys.stdout)
1146
.../modules/univention/admincli/admin.py                  | 15 +++++++++------
1149
.../modules/univention/admincli/admin.py                  | 15 +++++++++------
1147
1 file changed, 9 insertions(+), 6 deletions(-)
1150
1 file changed, 9 insertions(+), 6 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-8 / +9 lines)
 Lines 267-274   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
267
					else:
267
					else:
268
						val=[]
268
						val=[]
269
						for j in test_val:
269
						for j in test_val:
270
							if j and j.rstrip().lstrip():
270
							j = j.strip()
271
								val.append(j.rstrip().lstrip())
271
							if j:
272
								val.append(j)
272
273
273
					if not object.has_key(key):
274
					if not object.has_key(key):
274
						object[key]=[]
275
						object[key]=[]
 Lines 303-310   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
303
							val=[]
304
							val=[]
304
							print >> out, 'test_val=%s' % (test_val,)
305
							print >> out, 'test_val=%s' % (test_val,)
305
							for j in test_val:
306
							for j in test_val:
306
								if j and j.rstrip().lstrip():
307
								j = j.strip()
307
									val.append(j.rstrip().lstrip())
308
								if j:
309
									val.append(j)
308
310
309
							for j in range(0,len(val)):
311
							for j in range(0,len(val)):
310
								val[j]='"%s"' % val[j]
312
								val[j]='"%s"' % val[j]
 Lines 355-362   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
355
						else:
357
						else:
356
							val=[]
358
							val=[]
357
							for j in test_val:
359
							for j in test_val:
358
								if j and j.rstrip().lstrip():
360
								j = j.strip()
359
									val.append(j.rstrip().lstrip())
361
								if j:
362
									val.append(j)
360
				else:
363
				else:
361
					val=value.split(' ')
364
					val=value.split(' ')
362
				if module.property_descriptions[key].multivalue:
365
				if module.property_descriptions[key].multivalue:
363
- 
364
--
365
.../univention-cli-server                                     | 11 +++--------
366
.../univention-cli-server                                     | 11 +++--------
366
1 file changed, 3 insertions(+), 8 deletions(-)
367
1 file changed, 3 insertions(+), 8 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server (-10 / +3 lines)
 Lines 60-74   class MyRequestHandler(SocketServer.BaseRequestHandler): Link Here 
60
	def handle(self):
60
	def handle(self):
61
		ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] new connection [%s]' % (os.getppid(), os.getpid()))
61
		ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] new connection [%s]' % (os.getppid(), os.getpid()))
62
		sarglist = ''
62
		sarglist = ''
63
		while True:
63
		while not sarglist.endswith('\0'):
64
			buf = self.request.recv(1024)
64
			buf = self.request.recv(1024)
65
			if buf[-1] == '\0':
65
			sarglist += buf
66
				buf = buf[:-1]
66
		doit(sarglist.rstrip('\0'), self.request)
67
				sarglist += buf
68
				break
69
			else:
70
				sarglist += buf
71
		doit(sarglist, self.request)
72
		ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] connection closed [%s]' % (os.getppid(), os.getpid()))
67
		ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] connection closed [%s]' % (os.getppid(), os.getpid()))
73
68
74
	def finish(self):
69
	def finish(self):
75
- 
76
--
77
.../modules/univention/admincli/admin.py                       |  9 +++------
70
.../modules/univention/admincli/admin.py                       |  9 +++------
78
.../univention-directory-manager-modules/univention-cli-server | 10 +++++-----
71
.../univention-directory-manager-modules/univention-cli-server | 10 +++++-----
79
2 files changed, 8 insertions(+), 11 deletions(-)
72
2 files changed, 8 insertions(+), 11 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-6 / +3 lines)
 Lines 542-554   def _doit(arglist, out=sys.stdout): Link Here 
542
542
543
	baseDN=configRegistry['ldap/base']
543
	baseDN=configRegistry['ldap/base']
544
544
545
	if configRegistry.has_key('directory/manager/cmd/debug/level'):
545
	debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0))
546
		debug_level=configRegistry['directory/manager/cmd/debug/level']
547
	else:
548
		debug_level=0
549
546
550
	univention.debug.set_level(univention.debug.LDAP, int(debug_level))
547
	univention.debug.set_level(univention.debug.LDAP, debug_level)
551
	univention.debug.set_level(univention.debug.ADMIN, int(debug_level))
548
	univention.debug.set_level(univention.debug.ADMIN, debug_level)
552
549
553
	if binddn and bindpwd:
550
	if binddn and bindpwd:
554
		univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using %s account" % binddn)
551
		univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using %s account" % binddn)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server (-7 / +5 lines)
 Lines 114-121   def server_main(): Link Here 
114
114
115
	configRegistry = ConfigRegistry()
115
	configRegistry = ConfigRegistry()
116
	configRegistry.load()
116
	configRegistry.load()
117
	debug_level = configRegistry.get('directory/manager/cmd/debug/level', 1)
117
	debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 1))
118
	ud.set_level(ud.ADMIN, int(debug_level))
118
	ud.set_level(ud.ADMIN, debug_level)
119
	ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] forked to background' % os.getpid())
119
	ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] forked to background' % os.getpid())
120
120
121
	try:
121
	try:
 Lines 128-136   def server_main(): Link Here 
128
		else:
128
		else:
129
			print >> sys.stderr, 'E: socket directory exists (%s)' % socket_dir
129
			print >> sys.stderr, 'E: socket directory exists (%s)' % socket_dir
130
130
131
	timeout = configRegistry.get('directory/manager/cmd/timeout')
131
	timeout = float(configRegistry.get('directory/manager/cmd/timeout'))
132
	if timeout:
132
	if timeout:
133
		if int(timeout) > 2147483647:
133
		if timeout > 2147483647:
134
			timeout = 2147483647
134
			timeout = 2147483647
135
	else:
135
	else:
136
		timeout = 300
136
		timeout = 300
 Lines 154-160   def server_main(): Link Here 
154
154
155
	try:
155
	try:
156
		while True:
156
		while True:
157
			rlist, _wlist, _xlist = select([sock], [], [], float(timeout))
157
			rlist, _wlist, _xlist = select([sock], [], [], timeout)
158
			for handler in rlist:
158
			for handler in rlist:
159
				handler.handle_request()
159
				handler.handle_request()
160
			if not rlist:
160
			if not rlist:
161
- 
162
--
163
.../univention-directory-manager-modules/univention-cli-server          | 2 +-
161
.../univention-directory-manager-modules/univention-cli-server          | 2 +-
164
1 file changed, 1 insertion(+), 1 deletion(-)
162
1 file changed, 1 insertion(+), 1 deletion(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server (-3 / +1 lines)
 Lines 91-97   def server_main(): Link Here 
91
91
92
	socket_dir = '/tmp/admincli_%s/' % os.getuid()
92
	socket_dir = '/tmp/admincli_%s/' % os.getuid()
93
	socket_filename = 'sock'
93
	socket_filename = 'sock'
94
	socket_path = (socket_dir+socket_filename)
94
	socket_path = os.path.join(socket_dir, socket_filename)
95
95
96
	ud.init(logfile, ud.FLUSH, ud.NO_FUNCTION)
96
	ud.init(logfile, ud.FLUSH, ud.NO_FUNCTION)
97
97
98
- 
99
--
100
.../modules/univention/admincli/admin.py                          | 8 ++------
98
.../modules/univention/admincli/admin.py                          | 8 ++------
101
1 file changed, 2 insertions(+), 6 deletions(-)
99
1 file changed, 2 insertions(+), 6 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-8 / +2 lines)
 Lines 250-261   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
250
		for key, value in append.items():
250
		for key, value in append.items():
251
			if module.property_descriptions[key].syntax.name == 'file':
251
			if module.property_descriptions[key].syntax.name == 'file':
252
				if os.path.exists(value):
252
				if os.path.exists(value):
253
					fh = open(value, 'r')
253
					with open(value, 'r') as fh:
254
					content=''
254
						object[key] = fh.read()
255
					for line in fh.readlines():
256
						content += line
257
					object[key] = content
258
					fh.close()
259
				else:
255
				else:
260
					print >> out, 'WARNING: file not found: %s' % value
256
					print >> out, 'WARNING: file not found: %s' % value
261
257
262
- 
263
--
264
.../modules/univention/admincli/admin.py                       | 10 +++++-----
258
.../modules/univention/admincli/admin.py                       | 10 +++++-----
265
1 file changed, 5 insertions(+), 5 deletions(-)
259
1 file changed, 5 insertions(+), 5 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-7 / +5 lines)
 Lines 315-324   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
315
					object[key]=[]
315
					object[key]=[]
316
316
317
			else:
317
			else:
318
				if type(object[key]) is str:
318
				if isinstance(object[key], basestring):
319
					object[key] = [ object[key] ]
319
					object[key] = [ object[key] ]
320
				vallist = value
320
				vallist = value
321
				if type(value) is str:
321
				if isinstance(value, basestring):
322
					vallist = [ value ]
322
					vallist = [ value ]
323
323
324
				for val in vallist:
324
				for val in vallist:
 Lines 345-351   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
345
					print >> out, 'WARNING: file not found: %s' % value
345
					print >> out, 'WARNING: file not found: %s' % value
346
346
347
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
347
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
348
				if type(value) == type([]):
348
				if isinstance(value, list):
349
					for i in range(0,len(value)):
349
					for i in range(0,len(value)):
350
						test_val=value[i].split('"')
350
						test_val=value[i].split('"')
351
						if test_val[0] and test_val[0] == value[i]:
351
						if test_val[0] and test_val[0] == value[i]:
 Lines 458-464   def _doit(arglist, out=sys.stdout): Link Here 
458
		print >> out, msg
458
		print >> out, msg
459
		raise Failed()
459
		raise Failed()
460
460
461
	if not args == [] and type(args) == type([]):
461
	if args and isinstance(args, list):
462
		print >> out, "WARNING: the following arguments are ignored: %s" % (
462
		print >> out, "WARNING: the following arguments are ignored: %s" % (
463
			" ".join(('"%s"' % _ for _ in args)),
463
			" ".join(('"%s"' % _ for _ in args)),
464
		)
464
		)
 Lines 807-813   def _doit(arglist, out=sys.stdout): Link Here 
807
				for i in module.property_descriptions:
807
				for i in module.property_descriptions:
808
					property=module.property_descriptions.get(i)
808
					property=module.property_descriptions.get(i)
809
					if property.required:
809
					if property.required:
810
						if not object.has_key(i) or (not object[i] or (type(object[i]) == list and object[i]==[''])):
810
						if not object.has_key(i) or (not object[i] or (isinstance(object[i], list) and object[i]==[''])):
811
							print >> out, i
811
							print >> out, i
812
				raise Failed()
812
				raise Failed()
813
			except univention.admin.uexceptions.noObject, e:
813
			except univention.admin.uexceptions.noObject, e:
814
- 
815
--
816
.../modules/univention/admincli/admin.py                                | 2 +-
814
.../modules/univention/admincli/admin.py                                | 2 +-
817
1 file changed, 1 insertion(+), 1 deletion(-)
815
1 file changed, 1 insertion(+), 1 deletion(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-3 / +1 lines)
 Lines 242-248   def module_information(module, identifies_only=0): Link Here 
242
def _2utf8( text ):
242
def _2utf8( text ):
243
	try:
243
	try:
244
		return text.encode( 'utf-8' )
244
		return text.encode( 'utf-8' )
245
	except:
245
	except UnicodeError:
246
		return text.decode( 'iso-8859-1' )
246
		return text.decode( 'iso-8859-1' )
247
247
248
def object_input(module, object, input, append=None, remove=None, out=sys.stdout):
248
def object_input(module, object, input, append=None, remove=None, out=sys.stdout):
249
- 
250
--
251
.../modules/univention/admincli/admin.py                              | 4 +---
249
.../modules/univention/admincli/admin.py                              | 4 +---
252
1 file changed, 1 insertion(+), 3 deletions(-)
250
1 file changed, 1 insertion(+), 3 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-5 / +1 lines)
 Lines 373-381   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
373
373
374
def list_available_modules(out=sys.stdout):
374
def list_available_modules(out=sys.stdout):
375
	print >> out, "Available Modules are:"
375
	print >> out, "Available Modules are:"
376
	avail_modules = []
376
	avail_modules = univention.admin.modules.modules.keys()
377
	for mod in univention.admin.modules.modules.keys():
378
		avail_modules.append(mod)
379
	avail_modules.sort()
377
	avail_modules.sort()
380
	for mod in avail_modules:
378
	for mod in avail_modules:
381
		print >> out, "  %s" % mod
379
		print >> out, "  %s" % mod
382
- 
383
--
384
.../modules/univention/admincli/admin.py           | 22 +++++++++++-----------
380
.../modules/univention/admincli/admin.py           | 22 +++++++++++-----------
385
1 file changed, 11 insertions(+), 11 deletions(-)
381
1 file changed, 11 insertions(+), 11 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-13 / +11 lines)
 Lines 226-232   def module_usage(information, action='', out=sys.stdout): Link Here 
226
226
227
def module_information(module, identifies_only=0):
227
def module_information(module, identifies_only=0):
228
	information={module:[{},{}]}
228
	information={module:[{},{}]}
229
	if 'superordinate' in dir(module) and module.superordinate:
229
	if getattr(module, 'superordinate', None):
230
		superordinate=univention.admin.modules.get(module.superordinate)
230
		superordinate=univention.admin.modules.get(module.superordinate)
231
		information.update(module_information(superordinate, identifies_only=1))
231
		information.update(module_information(superordinate, identifies_only=1))
232
232
 Lines 715-721   def _doit(arglist, out=sys.stdout): Link Here 
715
715
716
#+++# ACTION CREATE #+++#
716
#+++# ACTION CREATE #+++#
717
	if action == 'create' or action == 'new':
717
	if action == 'create' or action == 'new':
718
			if hasattr(module,'operations') and module.operations:
718
			if getattr(module, 'operations', None):
719
				if not 'add' in module.operations:
719
				if not 'add' in module.operations:
720
					print >> out, 'Create %s not allowed' % module_name
720
					print >> out, 'Create %s not allowed' % module_name
721
					raise Failed()
721
					raise Failed()
 Lines 730-736   def _doit(arglist, out=sys.stdout): Link Here 
730
				object.options=parsed_options
730
				object.options=parsed_options
731
731
732
			object.open()
732
			object.open()
733
			if hasattr(object,'	open_warning') and object.open_warning:
733
			if getattr(object, 'open_warning', None):
734
				print >> out, 'WARNING:%s' % object.open_warning
734
				print >> out, 'WARNING:%s' % object.open_warning
735
			exists=0
735
			exists=0
736
			try:
736
			try:
 Lines 840-846   def _doit(arglist, out=sys.stdout): Link Here 
840
840
841
		object_modified = 0
841
		object_modified = 0
842
842
843
		if hasattr(module,'operations') and module.operations:
843
		if getattr(module, 'operations', None):
844
			if not 'edit' in module.operations:
844
			if not 'edit' in module.operations:
845
				print >> out, 'Modify %s not allowed' % module_name
845
				print >> out, 'Modify %s not allowed' % module_name
846
				raise Failed()
846
				raise Failed()
 Lines 852-862   def _doit(arglist, out=sys.stdout): Link Here 
852
			raise Failed()
852
			raise Failed()
853
853
854
		object.open()
854
		object.open()
855
		if hasattr(object,'open_warning') and object.open_warning:
855
		if getattr(object, 'open_warning', None):
856
			print >> out, 'WARNING:%s' % object.open_warning
856
			print >> out, 'WARNING:%s' % object.open_warning
857
857
858
		if action == 'move':
858
		if action == 'move':
859
			if hasattr(module,'operations') and module.operations:
859
			if getattr(module, 'operations', None):
860
				if not 'move' in module.operations:
860
				if not 'move' in module.operations:
861
					print >> out, 'Move %s not allowed' % module_name
861
					print >> out, 'Move %s not allowed' % module_name
862
					raise Failed()
862
					raise Failed()
 Lines 953-959   def _doit(arglist, out=sys.stdout): Link Here 
953
953
954
	elif action == 'remove' or action == 'delete':
954
	elif action == 'remove' or action == 'delete':
955
955
956
		if hasattr(module,'operations') and module.operations:
956
		if getattr(module, 'operations', None):
957
			if not 'remove' in module.operations:
957
			if not 'remove' in module.operations:
958
				print >> out, 'Remove %s not allowed' % module_name
958
				print >> out, 'Remove %s not allowed' % module_name
959
				raise Failed()
959
				raise Failed()
 Lines 973-979   def _doit(arglist, out=sys.stdout): Link Here 
973
			raise Failed()
973
			raise Failed()
974
974
975
		object.open()
975
		object.open()
976
		if hasattr(object,'open_warning') and object.open_warning:
976
		if getattr(object, 'open_warning', None):
977
			print >> out, 'WARNING:%s' % object.open_warning
977
			print >> out, 'WARNING:%s' % object.open_warning
978
978
979
		if remove_referring and univention.admin.objects.wantsCleanup(object):
979
		if remove_referring and univention.admin.objects.wantsCleanup(object):
 Lines 995-1001   def _doit(arglist, out=sys.stdout): Link Here 
995
995
996
	elif action == 'list' or action == 'lookup':
996
	elif action == 'list' or action == 'lookup':
997
997
998
		if hasattr(module,'operations') and module.operations:
998
		if getattr(module, 'operations', None):
999
			if not 'search' in module.operations:
999
			if not 'search' in module.operations:
1000
				print >> out, 'Search %s not allowed' % module_name
1000
				print >> out, 'Search %s not allowed' % module_name
1001
				raise Failed()
1001
				raise Failed()
 Lines 1006-1014   def _doit(arglist, out=sys.stdout): Link Here 
1006
			for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter):
1006
			for object in univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter):
1007
				print >> out, 'DN: %s' % _2utf8(univention.admin.objects.dn(object))
1007
				print >> out, 'DN: %s' % _2utf8(univention.admin.objects.dn(object))
1008
1008
1009
				if (hasattr(module,'virtual') and not module.virtual) or not hasattr(module,'virtual'):
1009
				if not getattr(module, 'virtual', None):
1010
					object.open()
1010
					object.open()
1011
					if hasattr(object,'open_warning') and object.open_warning:
1011
					if getattr(object, 'open_warning', None):
1012
						print >> out, 'WARNING: %s' % object.open_warning
1012
						print >> out, 'WARNING: %s' % object.open_warning
1013
					for key, value in object.items():
1013
					for key, value in object.items():
1014
						s=module.property_descriptions[key].syntax
1014
						s=module.property_descriptions[key].syntax
1015
- 
1016
--
1017
.../modules/univention/admincli/admin.py                   | 14 +++++++-------
1015
.../modules/univention/admincli/admin.py                   | 14 +++++++-------
1018
1 file changed, 7 insertions(+), 7 deletions(-)
1016
1 file changed, 7 insertions(+), 7 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-9 / +7 lines)
 Lines 529-535   def _doit(arglist, out=sys.stdout): Link Here 
529
	configRegistry=univention.config_registry.ConfigRegistry()
529
	configRegistry=univention.config_registry.ConfigRegistry()
530
	configRegistry.load()
530
	configRegistry.load()
531
531
532
	if configRegistry.has_key('ldap/master') and configRegistry['ldap/master']:
532
	if configRegistry.get('ldap/master'):
533
		co=univention.admin.config.config(configRegistry['ldap/master'])
533
		co=univention.admin.config.config(configRegistry['ldap/master'])
534
	else:
534
	else:
535
		co=univention.admin.config.config()
535
		co=univention.admin.config.config()
 Lines 641-647   def _doit(arglist, out=sys.stdout): Link Here 
641
641
642
			was_set=0
642
			was_set=0
643
			for mod, (properties,options) in information.items():
643
			for mod, (properties,options) in information.items():
644
				if properties.has_key(name):
644
				if name in properties:
645
					if properties[name].multivalue:
645
					if properties[name].multivalue:
646
						if not input.has_key(name):
646
						if not input.has_key(name):
647
							input[name]=[]
647
							input[name]=[]
 Lines 661-667   def _doit(arglist, out=sys.stdout): Link Here 
661
			value = _2utf8( val[ pos + 1 : ] )
661
			value = _2utf8( val[ pos + 1 : ] )
662
			was_set=0
662
			was_set=0
663
			for mod, (properties,options) in information.items():
663
			for mod, (properties,options) in information.items():
664
				if properties.has_key(name):
664
				if name in properties:
665
					if properties[name].multivalue:
665
					if properties[name].multivalue:
666
						if not append.has_key(name):
666
						if not append.has_key(name):
667
							append[name]=[]
667
							append[name]=[]
 Lines 684-690   def _doit(arglist, out=sys.stdout): Link Here 
684
				value = _2utf8( val[ pos + 1 : ] )
684
				value = _2utf8( val[ pos + 1 : ] )
685
			was_set=0
685
			was_set=0
686
			for mod, (properties,options) in information.items():
686
			for mod, (properties,options) in information.items():
687
				if properties.has_key(name):
687
				if name in properties:
688
					if properties[name].multivalue:
688
					if properties[name].multivalue:
689
						if not remove.has_key(name):
689
						if not remove.has_key(name):
690
							remove[name]=[]
690
							remove[name]=[]
 Lines 805-811   def _doit(arglist, out=sys.stdout): Link Here 
805
				for i in module.property_descriptions:
805
				for i in module.property_descriptions:
806
					property=module.property_descriptions.get(i)
806
					property=module.property_descriptions.get(i)
807
					if property.required:
807
					if property.required:
808
						if not object.has_key(i) or (not object[i] or (isinstance(object[i], list) and object[i]==[''])):
808
						if i not in object or (not object[i] or (isinstance(object[i], list) and object[i]==[''])):
809
							print >> out, i
809
							print >> out, i
810
				raise Failed()
810
				raise Failed()
811
			except univention.admin.uexceptions.noObject, e:
811
			except univention.admin.uexceptions.noObject, e:
 Lines 928-934   def _doit(arglist, out=sys.stdout): Link Here 
928
					object_modified+=1
928
					object_modified+=1
929
				modlist=[]
929
				modlist=[]
930
				upr = lo.search(base=dn, scope='base', attr=['univentionPolicyReference'])[0][1]
930
				upr = lo.search(base=dn, scope='base', attr=['univentionPolicyReference'])[0][1]
931
				if not upr.has_key('univentionPolicyReference'):
931
				if 'univentionPolicyReference' not in upr:
932
					upr['univentionPolicyReference'] = []
932
					upr['univentionPolicyReference'] = []
933
				for el in policy_reference:
933
				for el in policy_reference:
934
					if val in upr['univentionPolicyReference']:
934
					if val in upr['univentionPolicyReference']:
 Lines 1109-1115   def _doit(arglist, out=sys.stdout): Link Here 
1109
									print >> out, "  Merged Settings:"
1109
									print >> out, "  Merged Settings:"
1110
1110
1111
									for key in ddict.keys():
1111
									for key in ddict.keys():
1112
										if not client.has_key(key):
1112
										if key not in client:
1113
											client[key]=ddict[key]
1113
											client[key]=ddict[key]
1114
1114
1115
									if policies_with_DN:
1115
									if policies_with_DN:
1116
- 
1117
--
1118
.../modules/univention/admincli/admin.py             | 20 ++++++--------------
1116
.../modules/univention/admincli/admin.py             | 20 ++++++--------------
1119
1 file changed, 6 insertions(+), 14 deletions(-)
1117
1 file changed, 6 insertions(+), 14 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-16 / +6 lines)
 Lines 639-665   def _doit(arglist, out=sys.stdout): Link Here 
639
			name=val[:pos]
639
			name=val[:pos]
640
			value = _2utf8( val[ pos + 1 : ] )
640
			value = _2utf8( val[ pos + 1 : ] )
641
641
642
			was_set=0
643
			for mod, (properties,options) in information.items():
642
			for mod, (properties,options) in information.items():
644
				if name in properties:
643
				if name in properties:
645
					if properties[name].multivalue:
644
					if properties[name].multivalue:
646
						if not input.has_key(name):
645
						if not input.has_key(name):
647
							input[name]=[]
646
							input[name]=[]
648
							was_set=1
649
						if value:
647
						if value:
650
							input[name].append(value)
648
							input[name].append(value)
651
							was_set=1
652
					else:
649
					else:
653
						input[name]=value
650
						input[name]=value
654
						was_set=1
651
					break
655
652
			else:
656
			if not was_set:
657
				print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name
653
				print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name
658
		elif opt == '--append':
654
		elif opt == '--append':
659
			pos=val.find('=')
655
			pos=val.find('=')
660
			name=val[:pos]
656
			name=val[:pos]
661
			value = _2utf8( val[ pos + 1 : ] )
657
			value = _2utf8( val[ pos + 1 : ] )
662
			was_set=0
663
			for mod, (properties,options) in information.items():
658
			for mod, (properties,options) in information.items():
664
				if name in properties:
659
				if name in properties:
665
					if properties[name].multivalue:
660
					if properties[name].multivalue:
 Lines 667-677   def _doit(arglist, out=sys.stdout): Link Here 
667
							append[name]=[]
662
							append[name]=[]
668
						if value:
663
						if value:
669
							append[name].append(value)
664
							append[name].append(value)
670
							was_set=1
671
					else:
665
					else:
672
						append[name]=value
666
						append[name]=value
673
						was_set=1
667
					break
674
			if not was_set:
668
			else:
675
				print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name
669
				print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name
676
670
677
		elif opt == '--remove':
671
		elif opt == '--remove':
 Lines 682-688   def _doit(arglist, out=sys.stdout): Link Here 
682
			else:
676
			else:
683
				name=val[:pos]
677
				name=val[:pos]
684
				value = _2utf8( val[ pos + 1 : ] )
678
				value = _2utf8( val[ pos + 1 : ] )
685
			was_set=0
686
			for mod, (properties,options) in information.items():
679
			for mod, (properties,options) in information.items():
687
				if name in properties:
680
				if name in properties:
688
					if properties[name].multivalue:
681
					if properties[name].multivalue:
 Lines 690-700   def _doit(arglist, out=sys.stdout): Link Here 
690
							remove[name]=[]
683
							remove[name]=[]
691
						if value:
684
						if value:
692
							remove[name].append(value)
685
							remove[name].append(value)
693
							was_set=1
694
					else:
686
					else:
695
						remove[name]=value
687
						remove[name]=value
696
						was_set=1
688
					break
697
			if not was_set:
689
			else:
698
				print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name
690
				print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name
699
		elif opt == '--remove_referring':
691
		elif opt == '--remove_referring':
700
			remove_referring=1
692
			remove_referring=1
701
- 
702
--
703
.../modules/univention/admincli/admin.py                  | 15 ++++++---------
693
.../modules/univention/admincli/admin.py                  | 15 ++++++---------
704
1 file changed, 6 insertions(+), 9 deletions(-)
694
1 file changed, 6 insertions(+), 9 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-11 / +6 lines)
 Lines 642-651   def _doit(arglist, out=sys.stdout): Link Here 
642
			for mod, (properties,options) in information.items():
642
			for mod, (properties,options) in information.items():
643
				if name in properties:
643
				if name in properties:
644
					if properties[name].multivalue:
644
					if properties[name].multivalue:
645
						if not input.has_key(name):
645
						values = input.setdefault(name, [])
646
							input[name]=[]
647
						if value:
646
						if value:
648
							input[name].append(value)
647
							values.append(value)
649
					else:
648
					else:
650
						input[name]=value
649
						input[name]=value
651
					break
650
					break
 Lines 658-667   def _doit(arglist, out=sys.stdout): Link Here 
658
			for mod, (properties,options) in information.items():
657
			for mod, (properties,options) in information.items():
659
				if name in properties:
658
				if name in properties:
660
					if properties[name].multivalue:
659
					if properties[name].multivalue:
661
						if not append.has_key(name):
660
						values = append.setdefault(name, [])
662
							append[name]=[]
663
						if value:
661
						if value:
664
							append[name].append(value)
662
							values.append(value)
665
					else:
663
					else:
666
						append[name]=value
664
						append[name]=value
667
					break
665
					break
 Lines 679-688   def _doit(arglist, out=sys.stdout): Link Here 
679
			for mod, (properties,options) in information.items():
677
			for mod, (properties,options) in information.items():
680
				if name in properties:
678
				if name in properties:
681
					if properties[name].multivalue:
679
					if properties[name].multivalue:
682
						if not remove.has_key(name):
680
						values = remove.setdefault(name, [])
683
							remove[name]=[]
684
						if value:
681
						if value:
685
							remove[name].append(value)
682
							values.append(value)
686
					else:
683
					else:
687
						remove[name]=value
684
						remove[name]=value
688
					break
685
					break
689
- 
690
--
691
.../modules/univention/admincli/admin.py           | 58 +++++++++++-----------
686
.../modules/univention/admincli/admin.py           | 58 +++++++++++-----------
692
1 file changed, 29 insertions(+), 29 deletions(-)
687
1 file changed, 29 insertions(+), 29 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-31 / +29 lines)
 Lines 256-265   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
256
					print >> out, 'WARNING: file not found: %s' % value
256
					print >> out, 'WARNING: file not found: %s' % value
257
257
258
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
258
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
259
				for i in range(0,len(value)):
259
				for i in value:
260
					test_val=value[i].split('"')
260
					test_val = i.split('"')
261
					if test_val[0] and test_val[0] == value[i]:
261
					if test_val[0] and test_val[0] == i:
262
						val=value[i].split(' ')
262
						val = i.split(' ')
263
					else:
263
					else:
264
						val=[]
264
						val=[]
265
						for j in test_val:
265
						for j in test_val:
 Lines 267-289   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
267
							if j:
267
							if j:
268
								val.append(j)
268
								val.append(j)
269
269
270
					if not object.has_key(key):
270
					values = object.setdefault(key, [])
271
						object[key]=[]
271
					if val in values:
272
					if val in object[key]:
273
						print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key)
272
						print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key)
274
					elif object[key] == [''] or object[key] == []:
273
					elif values == [''] or values == []:
275
						object[key]=[val]
274
						values[:] = [val]
276
					else:
275
					else:
277
						object[key].append(val)
276
						values.append(val)
278
			else:
277
			else:
279
				for val in value:
278
				for val in value:
280
					if val in object[key]:
279
					values = object[key]
280
					if val in values:
281
						print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key)
281
						print >> out, 'WARNING: cannot append %s to %s, value exists' % (val, key)
282
					elif object[key] == [''] or object[key] == []:
282
					elif values == [''] or values == []:
283
						object[key]=[val]
283
						values[:] = [val]
284
					else:
284
					else:
285
						try:
285
						try:
286
							tmp = list(object[key])
286
							tmp = list(values)
287
							tmp.append(val)
287
							tmp.append(val)
288
							object[key] = list(tmp)
288
							object[key] = list(tmp)
289
						except univention.admin.uexceptions.valueInvalidSyntax, errmsg:
289
						except univention.admin.uexceptions.valueInvalidSyntax, errmsg:
 Lines 292-301   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
292
		for key, value in remove.items():
292
		for key, value in remove.items():
293
			if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
293
			if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
294
				if value:
294
				if value:
295
					for i in range(0,len(value)):
295
					for i in value:
296
						test_val=value[i].split('"')
296
						test_val = i.split('"')
297
						if test_val[0] and test_val[0] == value[i]:
297
						if test_val[0] and test_val[0] == i:
298
							val=value[i].split(' ')
298
							val = i.split(' ')
299
						else:
299
						else:
300
							val=[]
300
							val=[]
301
							print >> out, 'test_val=%s' % (test_val,)
301
							print >> out, 'test_val=%s' % (test_val,)
 Lines 346-353   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
346
346
347
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
347
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
348
				if isinstance(value, list):
348
				if isinstance(value, list):
349
					for i in range(0,len(value)):
349
					for i in value:
350
						test_val=value[i].split('"')
350
						test_val = i.split('"')
351
						if test_val[0] and test_val[0] == value[i]:
351
						if test_val[0] and test_val[0] == value[i]:
352
							val=value[i].split(' ')
352
							val=value[i].split(' ')
353
						else:
353
						else:
 Lines 1097-1116   def _doit(arglist, out=sys.stdout): Link Here 
1097
1097
1098
									print >> out, "  Merged Settings:"
1098
									print >> out, "  Merged Settings:"
1099
1099
1100
									for key in ddict.keys():
1100
									for key, values in ddict.items():
1101
										if key not in client:
1101
										if key not in client:
1102
											client[key]=ddict[key]
1102
											client[key] = values
1103
1103
1104
									if policies_with_DN:
1104
									if policies_with_DN:
1105
										for key in client.keys():
1105
										for key, (policy, values) in client.items():
1106
											print >> out, "    Policy: " + client[key][0]
1106
											print >> out, "    Policy: " + policy
1107
											print >> out, "    Attribute: " + key
1107
											print >> out, "    Attribute: " + key
1108
											for i in range(0, len(client[key][1])):
1108
											for value in values:
1109
												print >> out, "    Value: " + client[key][1][i]
1109
												print >> out, "    Value: " + value
1110
									else:
1110
									else:
1111
										for key in client.keys():
1111
										for key, values in client.items():
1112
											for i in range(0, len(client[key])):
1112
											for value in values:
1113
												print >> out, "    %s=%s" % (key, client[key][i])
1113
												print >> out, "    %s=%s" % (key, value)
1114
									print >> out, ''
1114
									print >> out, ''
1115
1115
1116
				print >> out, ''
1116
				print >> out, ''
1117
- 
1118
--
1119
.../modules/univention/admincli/admin.py                    | 13 ++++---------
1117
.../modules/univention/admincli/admin.py                    | 13 ++++---------
1120
1 file changed, 4 insertions(+), 9 deletions(-)
1118
1 file changed, 4 insertions(+), 9 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-11 / +4 lines)
 Lines 304-311   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
304
								if j:
304
								if j:
305
									val.append(j)
305
									val.append(j)
306
306
307
							for j in range(0,len(val)):
307
							val = ['"%s"' % _ for _ in val]
308
								val[j]='"%s"' % val[j]
309
308
310
						if val and val in object[key]:
309
						if val and val in object[key]:
311
							object[key].remove(val)
310
							object[key].remove(val)
 Lines 395-401   def doit(arglist, out=sys.stdout): Link Here 
395
				msg.extend(e.args)
394
				msg.extend(e.args)
396
395
397
		# strip elements and make sure that a ':' is printed iff further information follows
396
		# strip elements and make sure that a ':' is printed iff further information follows
398
		msg = [i.strip() for i in msg]
397
		msg = [_.strip() for _ in msg]
399
		if len(msg) == 1:
398
		if len(msg) == 1:
400
			msg[0] = '%s.' % msg[0].strip(':.')
399
			msg[0] = '%s.' % msg[0].strip(':.')
401
		elif len(msg) > 1:
400
		elif len(msg) > 1:
 Lines 806-814   def _doit(arglist, out=sys.stdout): Link Here 
806
805
807
			if policy_reference:
806
			if policy_reference:
808
				lo.modify(dn,[('objectClass','','univentionPolicyReference')])
807
				lo.modify(dn,[('objectClass','','univentionPolicyReference')])
809
				modlist=[]
808
				modlist = [('univentionPolicyReference', '', el) for el in policy_reference]
810
				for el in policy_reference:
811
					modlist.append(('univentionPolicyReference','',el))
812
				lo.modify(dn,modlist)
809
				lo.modify(dn,modlist)
813
810
814
			if exists == 1:
811
			if exists == 1:
 Lines 929-937   def _doit(arglist, out=sys.stdout): Link Here 
929
					object_modified+=1
926
					object_modified+=1
930
927
931
			if policy_dereference:
928
			if policy_dereference:
932
				modlist=[]
929
				modlist = [('univentionPolicyReference', el, '') for el in policy_dereference]
933
				for el in policy_dereference:
934
					modlist.append(('univentionPolicyReference',el,''))
935
				lo.modify(dn,modlist)
930
				lo.modify(dn,modlist)
936
				object_modified+=1
931
				object_modified+=1
937
932
938
- 
939
--
940
.../modules/univention/admincli/admin.py           | 35 ++++++----------------
933
.../modules/univention/admincli/admin.py           | 35 ++++++----------------
941
1 file changed, 9 insertions(+), 26 deletions(-)
934
1 file changed, 9 insertions(+), 26 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-28 / +9 lines)
 Lines 224-234   def module_usage(information, action='', out=sys.stdout): Link Here 
224
						_print_property( module, action, item, out )
224
						_print_property( module, action, item, out )
225
225
226
226
227
def module_information(module, identifies_only=0):
227
def module_information(module, identifies_only=False):
228
	information={module:[{},{}]}
228
	information={module:[{},{}]}
229
	if getattr(module, 'superordinate', None):
229
	if getattr(module, 'superordinate', None):
230
		superordinate=univention.admin.modules.get(module.superordinate)
230
		superordinate=univention.admin.modules.get(module.superordinate)
231
		information.update(module_information(superordinate, identifies_only=1))
231
		information.update(module_information(superordinate, identifies_only=True))
232
232
233
	if not identifies_only:
233
	if not identifies_only:
234
		for name, property in module.property_descriptions.items():
234
		for name, property in module.property_descriptions.items():
 Lines 424-431   def _doit(arglist, out=sys.stdout): Link Here 
424
	if module_name == 'modules':
424
	if module_name == 'modules':
425
		return list_available_modules(out=out)
425
		return list_available_modules(out=out)
426
426
427
	remove_referring=0
427
	remove_referring = False
428
	recursive=1
428
	recursive = True  # BUG: if this is the default, there's no way to disable it
429
	# parse options
429
	# parse options
430
	longopts = [
430
	longopts = [
431
		'position=',
431
		'position=',
 Lines 469-475   def _doit(arglist, out=sys.stdout): Link Here 
469
	policyOptions=[]
469
	policyOptions=[]
470
	logfile='/var/log/univention/directory-manager-cmd.log'
470
	logfile='/var/log/univention/directory-manager-cmd.log'
471
	tls=2
471
	tls=2
472
	ignore_exists=0
472
	ignore_exists = False
473
	superordinate_dn=''
473
	superordinate_dn=''
474
	parsed_append_options=[]
474
	parsed_append_options=[]
475
	parsed_options=[]
475
	parsed_options=[]
 Lines 506-512   def _doit(arglist, out=sys.stdout): Link Here 
506
		elif opt == '--tls':
506
		elif opt == '--tls':
507
			tls=val
507
			tls=val
508
		elif opt == '--ignore_exists':
508
		elif opt == '--ignore_exists':
509
			ignore_exists=1
509
			ignore_exists = True
510
		elif opt == '--superordinate':
510
		elif opt == '--superordinate':
511
			superordinate_dn=val
511
			superordinate_dn=val
512
		elif opt == '--option':
512
		elif opt == '--option':
 Lines 685-693   def _doit(arglist, out=sys.stdout): Link Here 
685
			else:
685
			else:
686
				print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name
686
				print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name
687
		elif opt == '--remove_referring':
687
		elif opt == '--remove_referring':
688
			remove_referring=1
688
			remove_referring = True
689
		elif opt == '--recursive':
689
		elif opt == '--recursive':
690
			recursive=1
690
			recursive = True
691
691
692
692
693
	if action in ['modify','edit','create','new']:
693
	if action in ['modify','edit','create','new']:
 Lines 720-726   def _doit(arglist, out=sys.stdout): Link Here 
720
			object.open()
720
			object.open()
721
			if getattr(object, 'open_warning', None):
721
			if getattr(object, 'open_warning', None):
722
				print >> out, 'WARNING:%s' % object.open_warning
722
				print >> out, 'WARNING:%s' % object.open_warning
723
			exists=0
724
			try:
723
			try:
725
				object_input(module, object, input, append=append, out=out)
724
				object_input(module, object, input, append=append, out=out)
726
			except univention.admin.uexceptions.nextFreeIp:
725
			except univention.admin.uexceptions.nextFreeIp:
 Lines 734-740   def _doit(arglist, out=sys.stdout): Link Here 
734
				print >> out, 'E: Option %s is not valid' % err
733
				print >> out, 'E: Option %s is not valid' % err
735
				raise Failed()
734
				raise Failed()
736
735
737
			exists=0
738
			exists_msg=None
736
			exists_msg=None
739
			try:
737
			try:
740
				dn=object.create()
738
				dn=object.create()
 Lines 743-785   def _doit(arglist, out=sys.stdout): Link Here 
743
				if not ignore_exists:
741
				if not ignore_exists:
744
					print >> out, 'E: Object exists: %s' % exists_msg
742
					print >> out, 'E: Object exists: %s' % exists_msg
745
					raise Failed()
743
					raise Failed()
746
				else:
747
					exists=1
748
			except univention.admin.uexceptions.uidAlreadyUsed, user:
744
			except univention.admin.uexceptions.uidAlreadyUsed, user:
749
				exists_msg = '(uid) %s' % user
745
				exists_msg = '(uid) %s' % user
750
				if not ignore_exists:
746
				if not ignore_exists:
751
					print >> out, 'E: Object exists: %s' % exists_msg
747
					print >> out, 'E: Object exists: %s' % exists_msg
752
					raise Failed()
748
					raise Failed()
753
				else:
754
					exists=1
755
			except univention.admin.uexceptions.groupNameAlreadyUsed, group:
749
			except univention.admin.uexceptions.groupNameAlreadyUsed, group:
756
				exists_msg = '(group) %s' % group
750
				exists_msg = '(group) %s' % group
757
				if not ignore_exists:
751
				if not ignore_exists:
758
					print >> out, 'E: Object exists: %s' % exists_msg
752
					print >> out, 'E: Object exists: %s' % exists_msg
759
					raise Failed()
753
					raise Failed()
760
				else:
761
					exists=1
762
			except univention.admin.uexceptions.dhcpServerAlreadyUsed, name:
754
			except univention.admin.uexceptions.dhcpServerAlreadyUsed, name:
763
				exists_msg = '(dhcpserver) %s' % name
755
				exists_msg = '(dhcpserver) %s' % name
764
				if not ignore_exists:
756
				if not ignore_exists:
765
					print >> out, 'E: Object exists: %s' % exists_msg
757
					print >> out, 'E: Object exists: %s' % exists_msg
766
					raise Failed()
758
					raise Failed()
767
				else:
768
					exists=1
769
			except univention.admin.uexceptions.macAlreadyUsed, mac:
759
			except univention.admin.uexceptions.macAlreadyUsed, mac:
770
				exists_msg = '(mac) %s' % mac
760
				exists_msg = '(mac) %s' % mac
771
				if not ignore_exists:
761
				if not ignore_exists:
772
					print >> out, 'E: Object exists: %s' % exists_msg
762
					print >> out, 'E: Object exists: %s' % exists_msg
773
					raise Failed()
763
					raise Failed()
774
				else:
775
					exists=1
776
			except univention.admin.uexceptions.noLock, e:
764
			except univention.admin.uexceptions.noLock, e:
777
				exists_msg = '(nolock) %s' % str(e)
765
				exists_msg = '(nolock) %s' % str(e)
778
				if not ignore_exists:
766
				if not ignore_exists:
779
					print >> out, 'E: Object exists: %s' % exists_msg
767
					print >> out, 'E: Object exists: %s' % exists_msg
780
					raise Failed()
768
					raise Failed()
781
				else:
782
					exists=1
783
			except univention.admin.uexceptions.invalidDhcpEntry:
769
			except univention.admin.uexceptions.invalidDhcpEntry:
784
				print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
770
				print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
785
				raise Failed()
771
				raise Failed()
 Lines 808-818   def _doit(arglist, out=sys.stdout): Link Here 
808
				modlist = [('univentionPolicyReference', '', el) for el in policy_reference]
794
				modlist = [('univentionPolicyReference', '', el) for el in policy_reference]
809
				lo.modify(dn,modlist)
795
				lo.modify(dn,modlist)
810
796
811
			if exists == 1:
797
			if exists_msg:
812
				if exists_msg:
813
					print >> out, 'Object exists: %s' % exists_msg
798
					print >> out, 'Object exists: %s' % exists_msg
814
				else:
815
					print >> out, 'Object exists'
816
			else:
799
			else:
817
				if not dn:
800
				if not dn:
818
					dn=object.dn
801
					dn=object.dn
819
- 
820
--
821
.../modules/univention/admincli/admin.py           | 98 +++++++++-------------
802
.../modules/univention/admincli/admin.py           | 98 +++++++++-------------
822
1 file changed, 40 insertions(+), 58 deletions(-)
803
1 file changed, 40 insertions(+), 58 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-60 / +40 lines)
 Lines 407-412   def doit(arglist, out=sys.stdout): Link Here 
407
		print >> out, ex
407
		print >> out, ex
408
408
409
409
410
def get_policy(dn, out=sys.stdout, policyOptions=None, policies_with_DN=False):
411
	cmd = ['univention_policy_result']
412
	if policyOptions:
413
		cmd.extend(policyOptions)
414
	cmd.append(dn)
415
416
	policy = attribute = ''
417
	value = []
418
	client = {}
419
420
	proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
421
	for line in proc.stdout:
422
		line = line.strip()
423
		if not line or line.startswith("DN: ") or line.startswith("POLICY "):
424
			continue
425
426
		print >> out, "    %s" % line
427
		if policies_with_DN:
428
			key, val = line.split(': ', 1)
429
			if key == 'Policy':
430
				if attribute and policy:
431
					client[attribute] = [policy, value]
432
					value = []
433
				policy = val
434
			elif key == 'Attribute':
435
				attribute = val
436
			elif key == 'Value':
437
				value.append(val)
438
		else:
439
			key, val = line.split('=', 1)
440
			client.setdefault(key, []).append(val)
441
	proc.wait()
442
	if policies_with_DN and attribute and policy:
443
		client[attribute] = [policy, value]
444
445
	return client
446
447
410
def _doit(arglist, out=sys.stdout):
448
def _doit(arglist, out=sys.stdout):
411
	# parse module and action
449
	# parse module and action
412
	if set(arglist) & set(('-h', '--help', '-?')):
450
	if set(arglist) & set(('-h', '--help', '-?')):
 Lines 1003-1039   def _doit(arglist, out=sys.stdout): Link Here 
1003
1041
1004
				if list_policies:
1042
				if list_policies:
1005
					utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) )
1043
					utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) )
1006
					p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_objectdn], stdout=subprocess.PIPE)
1007
					policyResults = p1.communicate()[0].split('\n')
1008
1009
					print >> out, "  Policy-based Settings:"
1044
					print >> out, "  Policy-based Settings:"
1010
					policy=''
1045
					client = get_policy(utf8_objectdn, out, policyOptions, policies_with_DN)
1011
					value=[]
1012
					client={}
1013
					for line in policyResults:
1014
						if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "):
1015
							print >> out, "    %s" % line.strip()
1016
							if policies_with_DN:
1017
								clsplit=string.split(line.strip(), ': ')
1018
								if clsplit[0] == 'Policy':
1019
									if policy:
1020
										client[attribute]=[policy, value]
1021
										value=[]
1022
									policy=clsplit[1]
1023
								elif clsplit[0] == 'Attribute':
1024
									attribute=clsplit[1]
1025
								elif clsplit[0] == 'Value':
1026
									value.append(clsplit[1])
1027
							else:
1028
								clsplit=string.split(line.strip(), '=')
1029
								if not client.has_key(clsplit[0]):
1030
									client[clsplit[0]] = []
1031
								client[clsplit[0]].append(clsplit[1])
1032
1033
					if policies_with_DN:
1034
						client[attribute]=[policy, value]
1035
						value=[]
1036
1037
					print >> out, ''
1046
					print >> out, ''
1038
1047
1039
					if module_name == 'dhcp/host':
1048
					if module_name == 'dhcp/host':
 Lines 1042-1078   def _doit(arglist, out=sys.stdout): Link Here 
1042
1051
1043
								if univention.admin.ipaddress.ip_is_in_network(subnet['subnet'], subnet['subnetmask'], object['fixedaddress'][0]):
1052
								if univention.admin.ipaddress.ip_is_in_network(subnet['subnet'], subnet['subnetmask'], object['fixedaddress'][0]):
1044
									utf8_subnet_dn = _2utf8( subnet.dn )
1053
									utf8_subnet_dn = _2utf8( subnet.dn )
1045
									p1 = subprocess.Popen(['univention_policy_result'] + policyOptions + [utf8_subnet_dn], stdout=subprocess.PIPE)
1046
									policyResults = p1.communicate()[0].split('\n')
1047
									print >> out, "  Subnet-based Settings:"
1054
									print >> out, "  Subnet-based Settings:"
1048
									ddict={}
1055
									ddict = get_policy(utf8_subnet_dn, out, policyOptions, policies_with_DN)
1049
									policy=''
1050
									value=[]
1051
									for line in policyResults:
1052
										if not (line.strip() == "" or line.strip()[:4]=="DN: " or line.strip()[:7]=="POLICY "):
1053
											print >> out, "    %s" % line.strip()
1054
											if policies_with_DN:
1055
												subsplit=string.split(line.strip(), ': ')
1056
												if subsplit[0] == 'Policy':
1057
													if policy:
1058
														ddict[attribute]=[policy, value]
1059
														value=[]
1060
													policy=subsplit[1]
1061
												elif subsplit[0] == 'Attribute':
1062
													attribute=subsplit[1]
1063
												elif subsplit[0] == 'Value':
1064
													value.append(subsplit[1])
1065
											else:
1066
												subsplit=string.split(line.strip(), '=')
1067
												if not ddict.has_key(subsplit[0]):
1068
													ddict[subsplit[0]] = []
1069
												ddict[subsplit[0]].append(subsplit[1])
1070
1071
									print >> out, ''
1056
									print >> out, ''
1072
1057
1073
									if policies_with_DN:
1074
										ddict[attribute]=[policy, value]
1075
1076
									print >> out, "  Merged Settings:"
1058
									print >> out, "  Merged Settings:"
1077
1059
1078
									for key, values in ddict.items():
1060
									for key, values in ddict.items():
1079
- 
1080
--
1081
.../modules/univention/admincli/admin.py                                | 2 +-
1061
.../modules/univention/admincli/admin.py                                | 2 +-
1082
1 file changed, 1 insertion(+), 1 deletion(-)
1062
1 file changed, 1 insertion(+), 1 deletion(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-3 / +1 lines)
 Lines 46-52   import univention.admin.uexceptions Link Here 
46
import univention.admin.uldap
46
import univention.admin.uldap
47
import univention.admin.modules
47
import univention.admin.modules
48
import univention.admin.objects
48
import univention.admin.objects
49
from univention.admin.layout import Tab, Group
49
from univention.admin.layout import Group
50
import univention.config_registry
50
import univention.config_registry
51
import univention.admin.ipaddress
51
import univention.admin.ipaddress
52
52
53
- 
54
--
55
.../modules/univention/admincli/admin.py           | 100 ++++++++++-----------
53
.../modules/univention/admincli/admin.py           | 100 ++++++++++-----------
56
1 file changed, 50 insertions(+), 50 deletions(-)
54
1 file changed, 50 insertions(+), 50 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-52 / +50 lines)
 Lines 40-53   import os Link Here 
40
import subprocess
40
import subprocess
41
import traceback
41
import traceback
42
42
43
import univention.debug
43
import univention.debug as ud
44
44
45
import univention.admin.uexceptions
45
import univention.admin.uexceptions as uex
46
import univention.admin.uldap
46
import univention.admin.uldap
47
import univention.admin.modules
47
import univention.admin.modules
48
import univention.admin.objects
48
import univention.admin.objects
49
from univention.admin.layout import Group
49
from univention.admin.layout import Group
50
import univention.config_registry
50
from univention.config_registry import ConfigRegistry
51
import univention.admin.ipaddress
51
import univention.admin.ipaddress
52
52
53
univention.admin.modules.update()
53
univention.admin.modules.update()
 Lines 286-292   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
286
							tmp = list(values)
286
							tmp = list(values)
287
							tmp.append(val)
287
							tmp.append(val)
288
							object[key] = list(tmp)
288
							object[key] = list(tmp)
289
						except univention.admin.uexceptions.valueInvalidSyntax, errmsg:
289
						except uex.valueInvalidSyntax, errmsg:
290
							print >> out, 'E: Invalid Syntax: %s' % (errmsg,)
290
							print >> out, 'E: Invalid Syntax: %s' % (errmsg,)
291
	if remove:
291
	if remove:
292
		for key, value in remove.items():
292
		for key, value in remove.items():
 Lines 364-373   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
364
			else:
364
			else:
365
				try:
365
				try:
366
					object[key]=value
366
					object[key]=value
367
				except univention.admin.uexceptions.ipOverridesNetwork, e:
367
				except uex.ipOverridesNetwork, e:
368
					print >> out, 'WARNING: %s' % e.message
368
					print >> out, 'WARNING: %s' % e.message
369
				except univention.admin.uexceptions.valueMayNotChange, e:
369
				except uex.valueMayNotChange, e:
370
					raise univention.admin.uexceptions.valueMayNotChange, "%s: %s"%(e.message, key)
370
					raise uex.valueMayNotChange, "%s: %s"%(e.message, key)
371
371
372
372
373
def list_available_modules(out=sys.stdout):
373
def list_available_modules(out=sys.stdout):
 Lines 381-388   def list_available_modules(out=sys.stdout): Link Here 
381
def doit(arglist, out=sys.stdout):
381
def doit(arglist, out=sys.stdout):
382
	try:
382
	try:
383
		_doit(arglist, out)
383
		_doit(arglist, out)
384
	except univention.admin.uexceptions.base, e:
384
	except uex.base, e:
385
		univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, traceback.format_exc())
385
		ud.debug(ud.ADMIN, ud.WARN, traceback.format_exc())
386
386
387
		# collect error information
387
		# collect error information
388
		msg = []
388
		msg = []
 Lines 559-569   def _doit(arglist, out=sys.stdout): Link Here 
559
			policy_dereference.append(val)
559
			policy_dereference.append(val)
560
560
561
	if logfile:
561
	if logfile:
562
		univention.debug.init(logfile, 1, 0)
562
		ud.init(logfile, 1, 0)
563
	else:
563
	else:
564
		print >> out, "WARNING: no logfile specified"
564
		print >> out, "WARNING: no logfile specified"
565
565
566
	configRegistry=univention.config_registry.ConfigRegistry()
566
	configRegistry = ConfigRegistry()
567
	configRegistry.load()
567
	configRegistry.load()
568
568
569
	if configRegistry.get('ldap/master'):
569
	if configRegistry.get('ldap/master'):
 Lines 575-601   def _doit(arglist, out=sys.stdout): Link Here 
575
575
576
	debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0))
576
	debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0))
577
577
578
	univention.debug.set_level(univention.debug.LDAP, debug_level)
578
	ud.set_level(ud.LDAP, debug_level)
579
	univention.debug.set_level(univention.debug.ADMIN, debug_level)
579
	ud.set_level(ud.ADMIN, debug_level)
580
580
581
	if binddn and bindpwd:
581
	if binddn and bindpwd:
582
		univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using %s account" % binddn)
582
		ud.debug(ud.ADMIN, ud.INFO, "using %s account" % binddn)
583
		try:
583
		try:
584
			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)
584
			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)
585
		except Exception, e:
585
		except Exception, e:
586
			univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e))
586
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
587
			print >> out, 'authentication error: %s' % (e,)
587
			print >> out, 'authentication error: %s' % (e,)
588
			raise Failed()
588
			raise Failed()
589
		policyOptions.extend(['-D', binddn, '-w', bindpwd])	## FIXME not so nice
589
		policyOptions.extend(['-D', binddn, '-w', bindpwd])	## FIXME not so nice
590
590
591
	else:
591
	else:
592
		if os.path.exists('/etc/ldap.secret'):
592
		if os.path.exists('/etc/ldap.secret'):
593
			univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using cn=admin,%s account" % baseDN)
593
			ud.debug(ud.ADMIN, ud.INFO, "using cn=admin,%s account" % baseDN)
594
			secretFileName='/etc/ldap.secret'
594
			secretFileName='/etc/ldap.secret'
595
			binddn='cn=admin,'+baseDN
595
			binddn='cn=admin,'+baseDN
596
			policyOptions.extend(['-D', binddn, '-y', secretFileName])
596
			policyOptions.extend(['-D', binddn, '-y', secretFileName])
597
		elif os.path.exists('/etc/machine.secret'):
597
		elif os.path.exists('/etc/machine.secret'):
598
			univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, "using %s account" % configRegistry['ldap/hostdn'])
598
			ud.debug(ud.ADMIN, ud.INFO, "using %s account" % configRegistry['ldap/hostdn'])
599
			secretFileName='/etc/machine.secret'
599
			secretFileName='/etc/machine.secret'
600
			binddn=configRegistry['ldap/hostdn']
600
			binddn=configRegistry['ldap/hostdn']
601
			policyOptions.extend(['-D', binddn, '-y', secretFileName])
601
			policyOptions.extend(['-D', binddn, '-y', secretFileName])
 Lines 614-620   def _doit(arglist, out=sys.stdout): Link Here 
614
		try:
614
		try:
615
			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)
615
			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)
616
		except Exception, e:
616
		except Exception, e:
617
			univention.debug.debug(univention.debug.ADMIN, univention.debug.WARN, 'authentication error: %s' % str(e))
617
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
618
			print >> out, 'authentication error: %s' % (e,)
618
			print >> out, 'authentication error: %s' % (e,)
619
			raise Failed()
619
			raise Failed()
620
620
 Lines 626-632   def _doit(arglist, out=sys.stdout): Link Here 
626
	try:
626
	try:
627
		position=univention.admin.uldap.position(baseDN)
627
		position=univention.admin.uldap.position(baseDN)
628
		position.setDn(position_dn)
628
		position.setDn(position_dn)
629
	except univention.admin.uexceptions.noObject:
629
	except uex.noObject:
630
		print >> out, 'E: Invalid position'
630
		print >> out, 'E: Invalid position'
631
		raise Failed()
631
		raise Failed()
632
632
 Lines 652-658   def _doit(arglist, out=sys.stdout): Link Here 
652
	if superordinate_dn and univention.admin.modules.superordinate(module):
652
	if superordinate_dn and univention.admin.modules.superordinate(module):
653
		try:
653
		try:
654
			superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn)
654
			superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn)
655
		except univention.admin.uexceptions.insufficientInformation, e:
655
		except uex.insufficientInformation, e:
656
			print >> out, 'Insufficient Information: %s' % (e,)
656
			print >> out, 'Insufficient Information: %s' % (e,)
657
			raise Failed()
657
			raise Failed()
658
	else:
658
	else:
 Lines 747-753   def _doit(arglist, out=sys.stdout): Link Here 
747
					raise Failed()
747
					raise Failed()
748
			try:
748
			try:
749
				object=module.object(co, lo, position=position, superordinate=superordinate)
749
				object=module.object(co, lo, position=position, superordinate=superordinate)
750
			except univention.admin.uexceptions.insufficientInformation:
750
			except uex.insufficientInformation:
751
				print >> out, 'E: Insufficient information'
751
				print >> out, 'E: Insufficient information'
752
				print >> out, 'Superordinate object is missing'
752
				print >> out, 'Superordinate object is missing'
753
				raise Failed()
753
				raise Failed()
 Lines 760-770   def _doit(arglist, out=sys.stdout): Link Here 
760
				print >> out, 'WARNING:%s' % object.open_warning
760
				print >> out, 'WARNING:%s' % object.open_warning
761
			try:
761
			try:
762
				object_input(module, object, input, append=append, out=out)
762
				object_input(module, object, input, append=append, out=out)
763
			except univention.admin.uexceptions.nextFreeIp:
763
			except uex.nextFreeIp:
764
				if not ignore_exists:
764
				if not ignore_exists:
765
					print >> out, 'E: No free IP address found'
765
					print >> out, 'E: No free IP address found'
766
					raise Failed()
766
					raise Failed()
767
			except univention.admin.uexceptions.valueInvalidSyntax, err:
767
			except uex.valueInvalidSyntax, err:
768
				print >> out, 'E: Invalid Syntax: %s' % err
768
				print >> out, 'E: Invalid Syntax: %s' % err
769
				raise Failed()
769
				raise Failed()
770
			except Exception, err:
770
			except Exception, err:
 Lines 774-817   def _doit(arglist, out=sys.stdout): Link Here 
774
			exists_msg=None
774
			exists_msg=None
775
			try:
775
			try:
776
				dn=object.create()
776
				dn=object.create()
777
			except univention.admin.uexceptions.objectExists, dn:
777
			except uex.objectExists, dn:
778
				exists_msg = dn
778
				exists_msg = dn
779
				if not ignore_exists:
779
				if not ignore_exists:
780
					print >> out, 'E: Object exists: %s' % exists_msg
780
					print >> out, 'E: Object exists: %s' % exists_msg
781
					raise Failed()
781
					raise Failed()
782
			except univention.admin.uexceptions.uidAlreadyUsed, user:
782
			except uex.uidAlreadyUsed, user:
783
				exists_msg = '(uid) %s' % user
783
				exists_msg = '(uid) %s' % user
784
				if not ignore_exists:
784
				if not ignore_exists:
785
					print >> out, 'E: Object exists: %s' % exists_msg
785
					print >> out, 'E: Object exists: %s' % exists_msg
786
					raise Failed()
786
					raise Failed()
787
			except univention.admin.uexceptions.groupNameAlreadyUsed, group:
787
			except uex.groupNameAlreadyUsed, group:
788
				exists_msg = '(group) %s' % group
788
				exists_msg = '(group) %s' % group
789
				if not ignore_exists:
789
				if not ignore_exists:
790
					print >> out, 'E: Object exists: %s' % exists_msg
790
					print >> out, 'E: Object exists: %s' % exists_msg
791
					raise Failed()
791
					raise Failed()
792
			except univention.admin.uexceptions.dhcpServerAlreadyUsed, name:
792
			except uex.dhcpServerAlreadyUsed, name:
793
				exists_msg = '(dhcpserver) %s' % name
793
				exists_msg = '(dhcpserver) %s' % name
794
				if not ignore_exists:
794
				if not ignore_exists:
795
					print >> out, 'E: Object exists: %s' % exists_msg
795
					print >> out, 'E: Object exists: %s' % exists_msg
796
					raise Failed()
796
					raise Failed()
797
			except univention.admin.uexceptions.macAlreadyUsed, mac:
797
			except uex.macAlreadyUsed, mac:
798
				exists_msg = '(mac) %s' % mac
798
				exists_msg = '(mac) %s' % mac
799
				if not ignore_exists:
799
				if not ignore_exists:
800
					print >> out, 'E: Object exists: %s' % exists_msg
800
					print >> out, 'E: Object exists: %s' % exists_msg
801
					raise Failed()
801
					raise Failed()
802
			except univention.admin.uexceptions.noLock, e:
802
			except uex.noLock, e:
803
				exists_msg = '(nolock) %s' % str(e)
803
				exists_msg = '(nolock) %s' % str(e)
804
				if not ignore_exists:
804
				if not ignore_exists:
805
					print >> out, 'E: Object exists: %s' % exists_msg
805
					print >> out, 'E: Object exists: %s' % exists_msg
806
					raise Failed()
806
					raise Failed()
807
			except univention.admin.uexceptions.invalidDhcpEntry:
807
			except uex.invalidDhcpEntry:
808
				print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
808
				print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
809
				raise Failed()
809
				raise Failed()
810
			except univention.admin.uexceptions.invalidOptions, e:
810
			except uex.invalidOptions, e:
811
				if not ignore_exists:
811
				if not ignore_exists:
812
					print >> out, 'E: invalid Options: %s' % e
812
					print >> out, 'E: invalid Options: %s' % e
813
					raise Failed()
813
					raise Failed()
814
			except univention.admin.uexceptions.insufficientInformation:
814
			except uex.insufficientInformation:
815
				print >> out, 'E: Insufficient information'
815
				print >> out, 'E: Insufficient information'
816
				print >> out, 'The following parameters are missing:'
816
				print >> out, 'The following parameters are missing:'
817
				for i in module.property_descriptions:
817
				for i in module.property_descriptions:
 Lines 820-829   def _doit(arglist, out=sys.stdout): Link Here 
820
						if i not in object or (not object[i] or (isinstance(object[i], list) and object[i]==[''])):
820
						if i not in object or (not object[i] or (isinstance(object[i], list) and object[i]==[''])):
821
							print >> out, i
821
							print >> out, i
822
				raise Failed()
822
				raise Failed()
823
			except univention.admin.uexceptions.noObject, e:
823
			except uex.noObject, e:
824
				print >> out, 'E: object not found: %s' % e
824
				print >> out, 'E: object not found: %s' % e
825
				raise Failed()
825
				raise Failed()
826
			except univention.admin.uexceptions.circularGroupDependency, e:
826
			except uex.circularGroupDependency, e:
827
				print >> out, 'E: circular group dependency detected: %s' % e
827
				print >> out, 'E: circular group dependency detected: %s' % e
828
				raise Failed()
828
				raise Failed()
829
829
 Lines 854-860   def _doit(arglist, out=sys.stdout): Link Here 
854
854
855
		try:
855
		try:
856
			object=univention.admin.objects.get(module, co, lo, position='', dn=dn)
856
			object=univention.admin.objects.get(module, co, lo, position='', dn=dn)
857
		except univention.admin.uexceptions.noObject:
857
		except uex.noObject:
858
			print >> out, 'E: object not found'
858
			print >> out, 'E: object not found'
859
			raise Failed()
859
			raise Failed()
860
860
 Lines 883-901   def _doit(arglist, out=sys.stdout): Link Here 
883
				try:
883
				try:
884
					object.move(newdn)
884
					object.move(newdn)
885
					object_modified+=1
885
					object_modified+=1
886
				except univention.admin.uexceptions.noObject:
886
				except uex.noObject:
887
					print >> out, 'E: object not found'
887
					print >> out, 'E: object not found'
888
					raise Failed()
888
					raise Failed()
889
				except univention.admin.uexceptions.ldapError, msg:
889
				except uex.ldapError, msg:
890
					print >> out, "ldap Error: %s" % msg
890
					print >> out, "ldap Error: %s" % msg
891
					raise Failed()
891
					raise Failed()
892
				except univention.admin.uexceptions.nextFreeIp:
892
				except uex.nextFreeIp:
893
					print >> out, 'E: No free IP address found'
893
					print >> out, 'E: No free IP address found'
894
					raise Failed()
894
					raise Failed()
895
				except univention.admin.uexceptions.valueInvalidSyntax, err:
895
				except uex.valueInvalidSyntax, err:
896
					print >> out, 'E: Invalid Syntax: %s' % err
896
					print >> out, 'E: Invalid Syntax: %s' % err
897
					raise Failed()
897
					raise Failed()
898
				except univention.admin.uexceptions.invalidOperation, msg:
898
				except uex.invalidOperation, msg:
899
					print >> out, str(msg)
899
					print >> out, str(msg)
900
					raise Failed()
900
					raise Failed()
901
901
 Lines 909-931   def _doit(arglist, out=sys.stdout): Link Here 
909
						object.options.append(option)
909
						object.options.append(option)
910
				try:
910
				try:
911
					object_input(module, object, input, append, remove, out=out)
911
					object_input(module, object, input, append, remove, out=out)
912
				except univention.admin.uexceptions.valueMayNotChange,e:
912
				except uex.valueMayNotChange,e:
913
					print >> out, unicode(e[0])
913
					print >> out, unicode(e[0])
914
					raise Failed()
914
					raise Failed()
915
				if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options:
915
				if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options:
916
					try:
916
					try:
917
						dn=object.modify()
917
						dn=object.modify()
918
						object_modified+=1
918
						object_modified+=1
919
					except univention.admin.uexceptions.noObject:
919
					except uex.noObject:
920
						print >> out, 'E: object not found'
920
						print >> out, 'E: object not found'
921
						raise Failed()
921
						raise Failed()
922
					except univention.admin.uexceptions.invalidDhcpEntry:
922
					except uex.invalidDhcpEntry:
923
						print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
923
						print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
924
						raise Failed()
924
						raise Failed()
925
					except univention.admin.uexceptions.circularGroupDependency, e:
925
					except uex.circularGroupDependency, e:
926
						print >> out, 'E: circular group dependency detected: %s' % e
926
						print >> out, 'E: circular group dependency detected: %s' % e
927
						raise Failed()
927
						raise Failed()
928
					except univention.admin.uexceptions.valueInvalidSyntax, e:
928
					except uex.valueInvalidSyntax, e:
929
						print >> out, 'E: Invalid Syntax: %s' % e
929
						print >> out, 'E: Invalid Syntax: %s' % e
930
						raise Failed()
930
						raise Failed()
931
931
 Lines 973-979   def _doit(arglist, out=sys.stdout): Link Here 
973
			else:
973
			else:
974
				print >> out, 'E: dn or filter needed'
974
				print >> out, 'E: dn or filter needed'
975
				raise Failed()
975
				raise Failed()
976
		except (univention.admin.uexceptions.noObject, IndexError):
976
		except (uex.noObject, IndexError):
977
			print >> out, 'E: object not found'
977
			print >> out, 'E: object not found'
978
			raise Failed()
978
			raise Failed()
979
979
 Lines 987-999   def _doit(arglist, out=sys.stdout): Link Here 
987
		if recursive:
987
		if recursive:
988
			try:
988
			try:
989
				object.remove(recursive)
989
				object.remove(recursive)
990
			except univention.admin.uexceptions.ldapError,msg:
990
			except uex.ldapError,msg:
991
				print >> out, str(msg)
991
				print >> out, str(msg)
992
				raise Failed()
992
				raise Failed()
993
		else:
993
		else:
994
			try:
994
			try:
995
				object.remove()
995
				object.remove()
996
			except univention.admin.uexceptions.primaryGroupUsed:
996
			except uex.primaryGroupUsed:
997
				print >> out, 'E: object in use'
997
				print >> out, 'E: object in use'
998
				raise Failed()
998
				raise Failed()
999
		print >> out, 'Object removed: %s' % _2utf8(dn)
999
		print >> out, 'Object removed: %s' % _2utf8(dn)
 Lines 1074-1083   def _doit(arglist, out=sys.stdout): Link Here 
1074
									print >> out, ''
1074
									print >> out, ''
1075
1075
1076
				print >> out, ''
1076
				print >> out, ''
1077
		except univention.admin.uexceptions.ldapError, errmsg:
1077
		except uex.ldapError, errmsg:
1078
			print >> out, '%s' % (errmsg,)
1078
			print >> out, '%s' % (errmsg,)
1079
			raise Failed()
1079
			raise Failed()
1080
		except univention.admin.uexceptions.valueInvalidSyntax, errmsg:
1080
		except uex.valueInvalidSyntax, errmsg:
1081
			print >> out, '%s' % (errmsg.message,)
1081
			print >> out, '%s' % (errmsg.message,)
1082
			raise Failed()
1082
			raise Failed()
1083
	else:
1083
	else:
1084
- 
1085
--
1086
.../modules/univention/admincli/admin.py                                | 2 +-
1084
.../modules/univention/admincli/admin.py                                | 2 +-
1087
1 file changed, 1 insertion(+), 1 deletion(-)
1085
1 file changed, 1 insertion(+), 1 deletion(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-3 / +1 lines)
 Lines 559-565   def _doit(arglist, out=sys.stdout): Link Here 
559
			policy_dereference.append(val)
559
			policy_dereference.append(val)
560
560
561
	if logfile:
561
	if logfile:
562
		ud.init(logfile, 1, 0)
562
		ud.init(logfile, ud.FLUSH, ud.NO_FUNCTION)
563
	else:
563
	else:
564
		print >> out, "WARNING: no logfile specified"
564
		print >> out, "WARNING: no logfile specified"
565
565
566
- 
567
--
568
.../modules/univention/admincli/admin.py           | 25 +++++++++-------------
566
.../modules/univention/admincli/admin.py           | 25 +++++++++-------------
569
1 file changed, 10 insertions(+), 15 deletions(-)
567
1 file changed, 10 insertions(+), 15 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-17 / +10 lines)
 Lines 34-40   from textwrap import dedent Link Here 
34
import sys
34
import sys
35
import getopt
35
import getopt
36
import re
36
import re
37
import string
38
import base64
37
import base64
39
import os
38
import os
40
import subprocess
39
import subprocess
 Lines 672-680   def _doit(arglist, out=sys.stdout): Link Here 
672
671
673
	for opt, val in opts:
672
	for opt, val in opts:
674
		if opt == '--set':
673
		if opt == '--set':
675
			pos=val.find('=')
674
			name, value = val.split('=', 1)
676
			name=val[:pos]
675
			value = _2utf8(value)
677
			value = _2utf8( val[ pos + 1 : ] )
678
676
679
			for mod, (properties,options) in information.items():
677
			for mod, (properties,options) in information.items():
680
				if name in properties:
678
				if name in properties:
 Lines 688-696   def _doit(arglist, out=sys.stdout): Link Here 
688
			else:
686
			else:
689
				print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name
687
				print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name
690
		elif opt == '--append':
688
		elif opt == '--append':
691
			pos=val.find('=')
689
			name, value = val.split('=', 1)
692
			name=val[:pos]
690
			value = _2utf8(value)
693
			value = _2utf8( val[ pos + 1 : ] )
694
			for mod, (properties,options) in information.items():
691
			for mod, (properties,options) in information.items():
695
				if name in properties:
692
				if name in properties:
696
					if properties[name].multivalue:
693
					if properties[name].multivalue:
 Lines 704-716   def _doit(arglist, out=sys.stdout): Link Here 
704
				print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name
701
				print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name
705
702
706
		elif opt == '--remove':
703
		elif opt == '--remove':
707
			pos=val.find('=')
704
			try:
708
			if pos == -1:
705
				name, value = val.split('=', 1)
709
				name=val
706
				value = _2utf8(value)
710
				value=None
707
			except ValueError:
711
			else:
708
				name, value = val, None
712
				name=val[:pos]
713
				value = _2utf8( val[ pos + 1 : ] )
714
			for mod, (properties,options) in information.items():
709
			for mod, (properties,options) in information.items():
715
				if name in properties:
710
				if name in properties:
716
					if properties[name].multivalue:
711
					if properties[name].multivalue:
 Lines 878-884   def _doit(arglist, out=sys.stdout): Link Here 
878
				if not res:
873
				if not res:
879
					print >> out, "position does not exsist: %s" % position_dn
874
					print >> out, "position does not exsist: %s" % position_dn
880
					raise Failed()
875
					raise Failed()
881
				rdn = dn[:string.find(dn,',')]
876
				rdn, _old_base = dn.split(',', 1)
882
				newdn="%s,%s" % (rdn,position_dn)
877
				newdn="%s,%s" % (rdn,position_dn)
883
				try:
878
				try:
884
					object.move(newdn)
879
					object.move(newdn)
885
- 
886
--
887
.../modules/univention/admincli/admin.py                            | 6 +++---
880
.../modules/univention/admincli/admin.py                            | 6 +++---
888
1 file changed, 3 insertions(+), 3 deletions(-)
881
1 file changed, 3 insertions(+), 3 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-5 / +3 lines)
 Lines 723-729   def _doit(arglist, out=sys.stdout): Link Here 
723
			recursive = True
723
			recursive = True
724
724
725
725
726
	if action in ['modify','edit','create','new']:
726
	if action in ('modify', 'edit', 'create', 'new'):
727
			for el in policy_reference:
727
			for el in policy_reference:
728
				oc = lo.get(el, ['objectClass'])
728
				oc = lo.get(el, ['objectClass'])
729
				if not oc:
729
				if not oc:
 Lines 735-741   def _doit(arglist, out=sys.stdout): Link Here 
735
735
736
736
737
#+++# ACTION CREATE #+++#
737
#+++# ACTION CREATE #+++#
738
	if action == 'create' or action == 'new':
738
	if action in ('create', 'new'):
739
			if getattr(module, 'operations', None):
739
			if getattr(module, 'operations', None):
740
				if not 'add' in module.operations:
740
				if not 'add' in module.operations:
741
					print >> out, 'Create %s not allowed' % module_name
741
					print >> out, 'Create %s not allowed' % module_name
 Lines 896-902   def _doit(arglist, out=sys.stdout): Link Here 
896
896
897
		else: # modify
897
		else: # modify
898
898
899
			if (len(input)+len(append)+len(remove)+len(parsed_append_options)+len(parsed_options))>0:
899
			if any((input, append, remove, parsed_append_options, parsed_options)):
900
				if parsed_options:
900
				if parsed_options:
901
					object.options=parsed_options
901
					object.options=parsed_options
902
				if parsed_append_options:
902
				if parsed_append_options:
903
- 
904
--
905
.../modules/univention/admincli/admin.py               | 18 ++++++++----------
903
.../modules/univention/admincli/admin.py               | 18 ++++++++----------
906
1 file changed, 8 insertions(+), 10 deletions(-)
904
1 file changed, 8 insertions(+), 10 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-12 / +8 lines)
 Lines 588-606   def _doit(arglist, out=sys.stdout): Link Here 
588
		policyOptions.extend(['-D', binddn, '-w', bindpwd])	## FIXME not so nice
588
		policyOptions.extend(['-D', binddn, '-w', bindpwd])	## FIXME not so nice
589
589
590
	else:
590
	else:
591
		if os.path.exists('/etc/ldap.secret'):
591
		for binddn, secretFileName in (
592
			ud.debug(ud.ADMIN, ud.INFO, "using cn=admin,%s account" % baseDN)
592
			('cn=admin,' + baseDN, '/etc/ldap.secret'),
593
			secretFileName='/etc/ldap.secret'
593
			(configRegistry['ldap/hostdn'], '/etc/machine.secret'),
594
			binddn='cn=admin,'+baseDN
594
		):
595
			policyOptions.extend(['-D', binddn, '-y', secretFileName])
595
			if os.path.exists(secretFileName):
596
		elif os.path.exists('/etc/machine.secret'):
596
				break
597
			ud.debug(ud.ADMIN, ud.INFO, "using %s account" % configRegistry['ldap/hostdn'])
598
			secretFileName='/etc/machine.secret'
599
			binddn=configRegistry['ldap/hostdn']
600
			policyOptions.extend(['-D', binddn, '-y', secretFileName])
601
		else:
597
		else:
602
			print >> out, "E: Missing LDAP credentials"
598
			print >> out, "E: Missing LDAP credentials"
603
			raise Failed()
599
			raise Failed()
600
		ud.debug(ud.ADMIN, ud.INFO, "using %s account" % binddn)
601
		policyOptions.extend(['-D', binddn, '-y', secretFileName])
604
602
605
		try:
603
		try:
606
			secretFile=open(secretFileName,'r')
604
			secretFile=open(secretFileName,'r')
607
- 
608
--
609
.../modules/univention/admincli/admin.py                   | 14 ++++++++++----
605
.../modules/univention/admincli/admin.py                   | 14 ++++++++++----
610
1 file changed, 10 insertions(+), 4 deletions(-)
606
1 file changed, 10 insertions(+), 4 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-6 / +10 lines)
 Lines 484-490   def _doit(arglist, out=sys.stdout): Link Here 
484
		'policy-reference=',
484
		'policy-reference=',
485
		'policy-dereference=',
485
		'policy-dereference=',
486
		'remove_referring',
486
		'remove_referring',
487
		'recursive'
487
		'recursive',
488
	]
488
	]
489
	try:
489
	try:
490
		opts, args=getopt.getopt(arglist[3:], '', longopts)
490
		opts, args=getopt.getopt(arglist[3:], '', longopts)
 Lines 580-586   def _doit(arglist, out=sys.stdout): Link Here 
580
	if binddn and bindpwd:
580
	if binddn and bindpwd:
581
		ud.debug(ud.ADMIN, ud.INFO, "using %s account" % binddn)
581
		ud.debug(ud.ADMIN, ud.INFO, "using %s account" % binddn)
582
		try:
582
		try:
583
			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)
583
			lo = univention.admin.uldap.access(
584
				host=configRegistry['ldap/master'],
585
				port=int(configRegistry.get('ldap/master/port', 7389)),
586
				base=baseDN,
587
				binddn=binddn,
588
				start_tls=tls,
589
				bindpw=bindpwd
590
			)
584
		except Exception, e:
591
		except Exception, e:
585
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
592
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
586
			print >> out, 'authentication error: %s' % (e,)
593
			print >> out, 'authentication error: %s' % (e,)
 Lines 863-873   def _doit(arglist, out=sys.stdout): Link Here 
863
			if not position_dn:
870
			if not position_dn:
864
				print >> out, "need new position for moving object"
871
				print >> out, "need new position for moving object"
865
			else:
872
			else:
866
				res = ''
867
				try:  # check if global-position exists
873
				try:  # check if global-position exists
868
					res = lo.get(position_dn)
874
					res = lo.get(position_dn)
869
				except:
875
				except:
870
					pass
876
					res = ''
871
				if not res:
877
				if not res:
872
					print >> out, "position does not exsist: %s" % position_dn
878
					print >> out, "position does not exsist: %s" % position_dn
873
					raise Failed()
879
					raise Failed()
874
- 
875
--
876
.../modules/univention/admincli/admin.py                    | 13 +++++--------
880
.../modules/univention/admincli/admin.py                    | 13 +++++--------
877
1 file changed, 5 insertions(+), 8 deletions(-)
881
1 file changed, 5 insertions(+), 8 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-10 / +5 lines)
 Lines 160-166   def _print_property(module, action, name, out=sys.stdout): Link Here 
160
		required[ 'editable' ] = False
160
		required[ 'editable' ] = False
161
161
162
	flags = ''
162
	flags = ''
163
	if action in required and required[ action ]:
163
	if required.get(action):
164
		flags='*'
164
		flags='*'
165
	elif not action in required:
165
	elif not action in required:
166
		if required[ 'create' ]:
166
		if required[ 'create' ]:
 Lines 171-186   def _print_property(module, action, name, out=sys.stdout): Link Here 
171
			flags += 'r'
171
			flags += 'r'
172
		if not required[ 'editable' ]:
172
		if not required[ 'editable' ]:
173
			flags += 'e'
173
			flags += 'e'
174
	flags = [flags] if flags else []
174
	if property.options:
175
	if property.options:
175
		if flags:
176
		flags.extend(property.options)
176
			flags += ','
177
		flags += ','.join(property.options)
178
	if property.multivalue:
177
	if property.multivalue:
179
		if flags:
178
		flags.append('[]')
180
			flags += ','
181
		flags += '[]'
182
	if flags:
179
	if flags:
183
		name += ' (%s)' % (flags,)
180
		name += ' (%s)' % (','.join(flags),)
184
181
185
	print >> out, '		%-40s %s' % (
182
	print >> out, '		%-40s %s' % (
186
		name,
183
		name,
187
- 
188
--
189
.../modules/univention/admincli/admin.py           | 533 +++++++++++----------
184
.../modules/univention/admincli/admin.py           | 533 +++++++++++----------
190
.../univention-cli-server                          |   8 +-
185
.../univention-cli-server                          |   8 +-
191
2 files changed, 275 insertions(+), 266 deletions(-)
186
2 files changed, 275 insertions(+), 266 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-263 / +270 lines)
 Lines 49-54   from univention.admin.layout import Group Link Here 
49
from univention.config_registry import ConfigRegistry
49
from univention.config_registry import ConfigRegistry
50
import univention.admin.ipaddress
50
import univention.admin.ipaddress
51
51
52
52
univention.admin.modules.update()
53
univention.admin.modules.update()
53
54
54
# update choices-lists which are defined in LDAP
55
# update choices-lists which are defined in LDAP
 Lines 134-140   def version(out=sys.stdout): Link Here 
134
135
135
136
136
def _print_property(module, action, name, out=sys.stdout):
137
def _print_property(module, action, name, out=sys.stdout):
137
	property = module.property_descriptions.get( name )
138
	property = module.property_descriptions.get(name)
138
	if property is None:
139
	if property is None:
139
		print >> out, 'E: unknown property %s of module %s' % (
140
		print >> out, 'E: unknown property %s of module %s' % (
140
			name,
141
			name,
 Lines 143-175   def _print_property(module, action, name, out=sys.stdout): Link Here 
143
		return
144
		return
144
145
145
	required = {
146
	required = {
146
		'create' : False,
147
		'create': False,
147
		'modify' : False,
148
		'modify': False,
148
		'remove' : False,
149
		'remove': False,
149
		'editable': True,
150
		'editable': True,
150
		}
151
	}
151
152
152
	if property.required:
153
	if property.required:
153
		required [ 'create' ] = True
154
		required['create'] = True
154
	if property.identifies:
155
	if property.identifies:
155
		required[ 'modify' ] = True
156
		required['modify'] = True
156
		required[ 'remove' ] = True
157
		required['remove'] = True
157
	if not property.editable:
158
	if not property.editable:
158
		required[ 'modify' ] = False
159
		required['modify'] = False
159
		required[ 'remove' ] = False
160
		required['remove'] = False
160
		required[ 'editable' ] = False
161
		required['editable'] = False
161
162
162
	flags = ''
163
	flags = ''
163
	if required.get(action):
164
	if required.get(action):
164
		flags='*'
165
		flags = '*'
165
	elif not action in required:
166
	elif not action in required:
166
		if required[ 'create' ]:
167
		if required['create']:
167
			flags += 'c'
168
			flags += 'c'
168
		if required[ 'modify' ]:
169
		if required['modify']:
169
			flags += 'm'
170
			flags += 'm'
170
		if required[ 'remove' ]:
171
		if required['remove']:
171
			flags += 'r'
172
			flags += 'r'
172
		if not required[ 'editable' ]:
173
		if not required['editable']:
173
			flags += 'e'
174
			flags += 'e'
174
	flags = [flags] if flags else []
175
	flags = [flags] if flags else []
175
	if property.options:
176
	if property.options:
 Lines 198-245   def module_usage(information, action='', out=sys.stdout): Link Here 
198
		print >> out, ''
199
		print >> out, ''
199
		print >> out, '%s variables:' % module.module
200
		print >> out, '%s variables:' % module.module
200
201
201
		if not hasattr(module,"layout"):
202
		if not hasattr(module, "layout"):
202
			continue
203
			continue
203
		for moduletab in module.layout:
204
		for moduletab in module.layout:
204
			print >> out, '  %s:' % (moduletab.label)
205
			print >> out, '  %s:' % (moduletab.label)
205
206
206
			for row in moduletab.layout:
207
			for row in moduletab.layout:
207
				if isinstance( row, Group ):
208
				if isinstance(row, Group):
208
					print >> out, '	%s' % row.label
209
					print >> out, '	%s' % row.label
209
					for row in row.layout:
210
					for row in row.layout:
210
						if isinstance( row, basestring ):
211
						if isinstance(row, basestring):
211
							_print_property( module, action, row, out )
212
							_print_property(module, action, row, out)
212
							continue
213
							continue
213
						for item in row:
214
						for item in row:
214
							_print_property( module, action, item, out )
215
							_print_property(module, action, item, out)
215
				else:
216
				else:
216
					if isinstance( row, basestring ):
217
					if isinstance(row, basestring):
217
						_print_property( module, action, row, out )
218
						_print_property(module, action, row, out)
218
						continue
219
						continue
219
					for item in row:
220
					for item in row:
220
						_print_property( module, action, item, out )
221
						_print_property(module, action, item, out)
221
222
222
223
223
def module_information(module, identifies_only=False):
224
def module_information(module, identifies_only=False):
224
	information={module:[{},{}]}
225
	information = {
226
		module: [{}, {}],
227
	}
225
	if getattr(module, 'superordinate', None):
228
	if getattr(module, 'superordinate', None):
226
		superordinate=univention.admin.modules.get(module.superordinate)
229
		superordinate = univention.admin.modules.get(module.superordinate)
227
		information.update(module_information(superordinate, identifies_only=True))
230
		information.update(module_information(superordinate, identifies_only=True))
228
231
229
	if not identifies_only:
232
	if not identifies_only:
230
		for name, property in module.property_descriptions.items():
233
		for name, property in module.property_descriptions.items():
231
			information[module][0][name]=property
234
			information[module][0][name] = property
232
		if hasattr(module,'options'):
235
		if hasattr(module, 'options'):
233
			for name, option in module.options.items():
236
			for name, option in module.options.items():
234
				information[module][1][name]=option
237
				information[module][1][name] = option
235
238
236
	return information
239
	return information
237
240
238
def _2utf8( text ):
241
242
def _2utf8(text):
239
	try:
243
	try:
240
		return text.encode( 'utf-8' )
244
		return text.encode('utf-8')
241
	except UnicodeError:
245
	except UnicodeError:
242
		return text.decode( 'iso-8859-1' )
246
		return text.decode('iso-8859-1')
247
243
248
244
def object_input(module, object, input, append=None, remove=None, out=sys.stdout):
249
def object_input(module, object, input, append=None, remove=None, out=sys.stdout):
245
	if append:
250
	if append:
 Lines 251-263   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
251
				else:
256
				else:
252
					print >> out, 'WARNING: file not found: %s' % value
257
					print >> out, 'WARNING: file not found: %s' % value
253
258
254
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
259
			elif univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
255
				for i in value:
260
				for i in value:
256
					test_val = i.split('"')
261
					test_val = i.split('"')
257
					if test_val[0] and test_val[0] == i:
262
					if test_val[0] and test_val[0] == i:
258
						val = i.split(' ')
263
						val = i.split(' ')
259
					else:
264
					else:
260
						val=[]
265
						val = []
261
						for j in test_val:
266
						for j in test_val:
262
							j = j.strip()
267
							j = j.strip()
263
							if j:
268
							if j:
 Lines 286-299   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
286
							print >> out, 'E: Invalid Syntax: %s' % (errmsg,)
291
							print >> out, 'E: Invalid Syntax: %s' % (errmsg,)
287
	if remove:
292
	if remove:
288
		for key, value in remove.items():
293
		for key, value in remove.items():
289
			if univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
294
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
290
				if value:
295
				if value:
291
					for i in value:
296
					for i in value:
292
						test_val = i.split('"')
297
						test_val = i.split('"')
293
						if test_val[0] and test_val[0] == i:
298
						if test_val[0] and test_val[0] == i:
294
							val = i.split(' ')
299
							val = i.split(' ')
295
						else:
300
						else:
296
							val=[]
301
							val = []
297
							print >> out, 'test_val=%s' % (test_val,)
302
							print >> out, 'test_val=%s' % (test_val,)
298
							for j in test_val:
303
							for j in test_val:
299
								j = j.strip()
304
								j = j.strip()
 Lines 307-320   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
307
						else:
312
						else:
308
							print >> out, "WARNING: cannot remove %s from %s, value does not exist" % (val, key)
313
							print >> out, "WARNING: cannot remove %s from %s, value does not exist" % (val, key)
309
				else:
314
				else:
310
					object[key]=[]
315
					object[key] = []
311
316
312
			else:
317
			else:
313
				if isinstance(object[key], basestring):
318
				if isinstance(object[key], basestring):
314
					object[key] = [ object[key] ]
319
					object[key] = [object[key]]
315
				vallist = value
320
				vallist = value
316
				if isinstance(value, basestring):
321
				if isinstance(value, basestring):
317
					vallist = [ value ]
322
					vallist = [value]
318
323
319
				for val in vallist:
324
				for val in vallist:
320
					if val in object[key]:
325
					if val in object[key]:
 Lines 325-369   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
325
		for key, value in input.items():
330
		for key, value in input.items():
326
			if module.property_descriptions[key].syntax.name == 'binaryfile':
331
			if module.property_descriptions[key].syntax.name == 'binaryfile':
327
				if value == '':
332
				if value == '':
328
					object[key]=value
333
					object[key] = value
329
				elif os.path.exists(value):
334
				elif os.path.exists(value):
330
					fh = open(value, 'r')
335
					fh = open(value, 'r')
331
					content=fh.read()
336
					content = fh.read()
332
					if "----BEGIN CERTIFICATE-----" in content:
337
					if "----BEGIN CERTIFICATE-----" in content:
333
						content = content.replace('----BEGIN CERTIFICATE-----','')
338
						content = content.replace('----BEGIN CERTIFICATE-----', '')
334
						content = content.replace('----END CERTIFICATE-----','')
339
						content = content.replace('----END CERTIFICATE-----', '')
335
						object[key]=base64.decodestring(content)
340
						object[key] = base64.decodestring(content)
336
					else:
341
					else:
337
						object[key]= content
342
						object[key] = content
338
					fh.close()
343
					fh.close()
339
				else:
344
				else:
340
					print >> out, 'WARNING: file not found: %s' % value
345
					print >> out, 'WARNING: file not found: %s' % value
341
346
342
			elif univention.admin.syntax.is_syntax( module.property_descriptions[key].syntax, univention.admin.syntax.complex ):
347
			elif univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
343
				if isinstance(value, list):
348
				if isinstance(value, list):
344
					for i in value:
349
					for i in value:
345
						test_val = i.split('"')
350
						test_val = i.split('"')
346
						if test_val[0] and test_val[0] == value[i]:
351
						if test_val[0] and test_val[0] == value[i]:
347
							val=value[i].split(' ')
352
							val = value[i].split(' ')
348
						else:
353
						else:
349
							val=[]
354
							val = []
350
							for j in test_val:
355
							for j in test_val:
351
								j = j.strip()
356
								j = j.strip()
352
								if j:
357
								if j:
353
									val.append(j)
358
									val.append(j)
354
				else:
359
				else:
355
					val=value.split(' ')
360
					val = value.split(' ')
356
				if module.property_descriptions[key].multivalue:
361
				if module.property_descriptions[key].multivalue:
357
					object[key]=[val]
362
					object[key] = [val]
358
				else:
363
				else:
359
					object[key]=val
364
					object[key] = val
360
			else:
365
			else:
361
				try:
366
				try:
362
					object[key]=value
367
					object[key] = value
363
				except uex.ipOverridesNetwork, e:
368
				except uex.ipOverridesNetwork, e:
364
					print >> out, 'WARNING: %s' % e.message
369
					print >> out, 'WARNING: %s' % e.message
365
				except uex.valueMayNotChange, e:
370
				except uex.valueMayNotChange, e:
366
					raise uex.valueMayNotChange, "%s: %s"%(e.message, key)
371
					raise uex.valueMayNotChange, "%s: %s" % (e.message, key)
367
372
368
373
369
def list_available_modules(out=sys.stdout):
374
def list_available_modules(out=sys.stdout):
 Lines 453-460   def _doit(arglist, out=sys.stdout): Link Here 
453
		usage(out=out)
458
		usage(out=out)
454
		raise Failed()
459
		raise Failed()
455
460
456
	module_name=arglist[1]
461
	module_name = arglist[1]
457
458
	if module_name == 'modules':
462
	if module_name == 'modules':
459
		return list_available_modules(out=out)
463
		return list_available_modules(out=out)
460
464
 Lines 484-490   def _doit(arglist, out=sys.stdout): Link Here 
484
		'recursive',
488
		'recursive',
485
	]
489
	]
486
	try:
490
	try:
487
		opts, args=getopt.getopt(arglist[3:], '', longopts)
491
		opts, args = getopt.getopt(arglist[3:], '', longopts)
488
	except getopt.error, msg:
492
	except getopt.error, msg:
489
		print >> out, msg
493
		print >> out, msg
490
		raise Failed()
494
		raise Failed()
 Lines 494-554   def _doit(arglist, out=sys.stdout): Link Here 
494
			" ".join(('"%s"' % _ for _ in args)),
498
			" ".join(('"%s"' % _ for _ in args)),
495
		)
499
		)
496
500
497
	position_dn=''
501
	position_dn = ''
498
	dn=''
502
	dn = ''
499
	binddn=None
503
	binddn = None
500
	bindpwd=None
504
	bindpwd = None
501
	list_policies=False
505
	list_policies = False
502
	policies_with_DN=False
506
	policies_with_DN = False
503
	policyOptions=[]
507
	policyOptions = []
504
	logfile='/var/log/univention/directory-manager-cmd.log'
508
	logfile = '/var/log/univention/directory-manager-cmd.log'
505
	tls=2
509
	tls = 2
506
	ignore_exists = False
510
	ignore_exists = False
507
	superordinate_dn=''
511
	superordinate_dn = ''
508
	parsed_append_options=[]
512
	parsed_append_options = []
509
	parsed_options=[]
513
	parsed_options = []
510
	filter=''
514
	filter = ''
511
	input={}
515
	input = {}
512
	append={}
516
	append = {}
513
	remove={}
517
	remove = {}
514
	policy_reference=[]
518
	policy_reference = []
515
	policy_dereference=[]
519
	policy_dereference = []
516
	for opt, val in opts:
520
	for opt, val in opts:
517
		if opt == '--position':
521
		if opt == '--position':
518
			position_dn = _2utf8( val )
522
			position_dn = _2utf8(val)
519
		elif opt == '--logfile':
523
		elif opt == '--logfile':
520
			logfile=val
524
			logfile = val
521
		elif opt == '--policies':
525
		elif opt == '--policies':
522
			list_policies = True
526
			list_policies = True
523
			if val=="1":
527
			if val == "1":
524
				policies_with_DN = True
528
				policies_with_DN = True
525
			else:
529
			else:
526
				policyOptions = ['-s']
530
				policyOptions = ['-s']
527
		elif opt == '--binddn':
531
		elif opt == '--binddn':
528
			binddn=val
532
			binddn = val
529
		elif opt == '--bindpwd':
533
		elif opt == '--bindpwd':
530
			bindpwd=val
534
			bindpwd = val
531
		elif opt == '--bindpwdfile':
535
		elif opt == '--bindpwdfile':
532
			try:
536
			try:
533
				with open(val) as fp:
537
				with open(val) as fp:
534
					bindpwd=fp.read().strip()
538
					bindpwd = fp.read().strip()
535
			except IOError as e:
539
			except IOError as e:
536
				print >> out, 'E: could not read bindpwd from file (%s)' % (e,)
540
				print >> out, 'E: could not read bindpwd from file (%s)' % (e,)
537
				raise Failed()
541
				raise Failed()
538
		elif opt == '--dn':
542
		elif opt == '--dn':
539
			dn = _2utf8( val )
543
			dn = _2utf8(val)
540
		elif opt == '--tls':
544
		elif opt == '--tls':
541
			tls=val
545
			tls = val
542
		elif opt == '--ignore_exists':
546
		elif opt == '--ignore_exists':
543
			ignore_exists = True
547
			ignore_exists = True
544
		elif opt == '--superordinate':
548
		elif opt == '--superordinate':
545
			superordinate_dn=val
549
			superordinate_dn = val
546
		elif opt == '--option':
550
		elif opt == '--option':
547
			parsed_options.append(val)
551
			parsed_options.append(val)
548
		elif opt == '--append-option':
552
		elif opt == '--append-option':
549
			parsed_append_options.append(val)
553
			parsed_append_options.append(val)
550
		elif opt == '--filter':
554
		elif opt == '--filter':
551
			filter=val
555
			filter = val
552
		elif opt == '--policy-reference':
556
		elif opt == '--policy-reference':
553
			policy_reference.append(val)
557
			policy_reference.append(val)
554
		elif opt == '--policy-dereference':
558
		elif opt == '--policy-dereference':
 Lines 563-573   def _doit(arglist, out=sys.stdout): Link Here 
563
	configRegistry.load()
567
	configRegistry.load()
564
568
565
	if configRegistry.get('ldap/master'):
569
	if configRegistry.get('ldap/master'):
566
		co=univention.admin.config.config(configRegistry['ldap/master'])
570
		co = univention.admin.config.config(configRegistry['ldap/master'])
567
	else:
571
	else:
568
		co=univention.admin.config.config()
572
		co = univention.admin.config.config()
569
573
570
	baseDN=configRegistry['ldap/base']
574
	baseDN = configRegistry['ldap/base']
571
575
572
	debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0))
576
	debug_level = int(configRegistry.get('directory/manager/cmd/debug/level', 0))
573
577
 Lines 589-595   def _doit(arglist, out=sys.stdout): Link Here 
589
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
593
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
590
			print >> out, 'authentication error: %s' % (e,)
594
			print >> out, 'authentication error: %s' % (e,)
591
			raise Failed()
595
			raise Failed()
592
		policyOptions.extend(['-D', binddn, '-w', bindpwd])	## FIXME not so nice
596
		policyOptions.extend(['-D', binddn, '-w', bindpwd])  # FIXME not so nice
593
597
594
	else:
598
	else:
595
		for binddn, secretFileName in (
599
		for binddn, secretFileName in (
 Lines 605-638   def _doit(arglist, out=sys.stdout): Link Here 
605
		policyOptions.extend(['-D', binddn, '-y', secretFileName])
609
		policyOptions.extend(['-D', binddn, '-y', secretFileName])
606
610
607
		try:
611
		try:
608
			secretFile=open(secretFileName,'r')
612
			secretFile = open(secretFileName, 'r')
609
		except IOError:
613
		except IOError:
610
			print >> out, 'E: Permission denied, try --binddn and --bindpwd'
614
			print >> out, 'E: Permission denied, try --binddn and --bindpwd'
611
			raise Failed()
615
			raise Failed()
612
		pwdLine=secretFile.readline()
616
		pwdLine = secretFile.readline()
613
		pwd=re.sub('\n','',pwdLine)
617
		pwd = re.sub('\n', '', pwdLine)
614
618
615
		try:
619
		try:
616
			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)
620
			lo = univention.admin.uldap.access(
621
				host=configRegistry['ldap/master'],
622
				port=int(configRegistry.get('ldap/master/port', '7389')),
623
				base=baseDN,
624
				binddn=binddn,
625
				bindpw=pwd,
626
				start_tls=tls
627
			)
617
		except Exception, e:
628
		except Exception, e:
618
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
629
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
619
			print >> out, 'authentication error: %s' % (e,)
630
			print >> out, 'authentication error: %s' % (e,)
620
			raise Failed()
631
			raise Failed()
621
632
622
	if not position_dn and superordinate_dn:
633
	if not position_dn and superordinate_dn:
623
		position_dn=superordinate_dn
634
		position_dn = superordinate_dn
624
	elif not position_dn:
635
	elif not position_dn:
625
		position_dn=baseDN
636
		position_dn = baseDN
626
637
627
	try:
638
	try:
628
		position=univention.admin.uldap.position(baseDN)
639
		position = univention.admin.uldap.position(baseDN)
629
		position.setDn(position_dn)
640
		position.setDn(position_dn)
630
	except uex.noObject:
641
	except uex.noObject:
631
		print >> out, 'E: Invalid position'
642
		print >> out, 'E: Invalid position'
632
		raise Failed()
643
		raise Failed()
633
644
634
	try:
645
	try:
635
		module=univention.admin.modules.get(module_name)
646
		module = univention.admin.modules.get(module_name)
636
	except:
647
	except:
637
		print >> out, "failed to get module %s." % module_name
648
		print >> out, "failed to get module %s." % module_name
638
		print >> out, ""
649
		print >> out, ""
 Lines 646-703   def _doit(arglist, out=sys.stdout): Link Here 
646
		raise Failed()
657
		raise Failed()
647
658
648
	# initialise modules
659
	# initialise modules
649
	univention.admin.modules.init(lo,position,module)
660
	univention.admin.modules.init(lo, position, module)
650
661
651
	information=module_information(module)
662
	information = module_information(module)
652
663
653
	if superordinate_dn and univention.admin.modules.superordinate(module):
664
	if superordinate_dn and univention.admin.modules.superordinate(module):
654
		try:
665
		try:
655
			superordinate=univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn)
666
			superordinate = univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn)
656
		except uex.insufficientInformation, e:
667
		except uex.insufficientInformation, e:
657
			print >> out, 'Insufficient Information: %s' % (e,)
668
			print >> out, 'Insufficient Information: %s' % (e,)
658
			raise Failed()
669
			raise Failed()
659
	else:
670
	else:
660
		superordinate=None
671
		superordinate = None
661
662
672
663
	if len(arglist) == 2:
673
	if len(arglist) == 2:
664
		module_usage(information, out=out)
674
		module_usage(information, out=out)
665
		raise Failed()
675
		raise Failed()
666
676
667
	action=arglist[2]
677
	action = arglist[2]
668
678
669
	if len(arglist) == 3 and action != 'list':
679
	if len(arglist) == 3 and action != 'list':
670
		module_usage(information, action, out=out)
680
		module_usage(information, action, out=out)
671
		raise Failed()
681
		raise Failed()
672
682
673
674
	for opt, val in opts:
683
	for opt, val in opts:
675
		if opt == '--set':
684
		if opt == '--set':
676
			name, value = val.split('=', 1)
685
			name, value = val.split('=', 1)
677
			value = _2utf8(value)
686
			value = _2utf8(value)
678
687
			for mod, (properties, options) in information.items():
679
			for mod, (properties,options) in information.items():
680
				if name in properties:
688
				if name in properties:
681
					if properties[name].multivalue:
689
					if properties[name].multivalue:
682
						values = input.setdefault(name, [])
690
						values = input.setdefault(name, [])
683
						if value:
691
						if value:
684
							values.append(value)
692
							values.append(value)
685
					else:
693
					else:
686
						input[name]=value
694
						input[name] = value
687
					break
695
					break
688
			else:
696
			else:
689
				print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name
697
				print >> out, "WARNING: No attribute with name '%s' in this module, value not set." % name
698
690
		elif opt == '--append':
699
		elif opt == '--append':
691
			name, value = val.split('=', 1)
700
			name, value = val.split('=', 1)
692
			value = _2utf8(value)
701
			value = _2utf8(value)
693
			for mod, (properties,options) in information.items():
702
			for mod, (properties, options) in information.items():
694
				if name in properties:
703
				if name in properties:
695
					if properties[name].multivalue:
704
					if properties[name].multivalue:
696
						values = append.setdefault(name, [])
705
						values = append.setdefault(name, [])
697
						if value:
706
						if value:
698
							values.append(value)
707
							values.append(value)
699
					else:
708
					else:
700
						append[name]=value
709
						append[name] = value
701
					break
710
					break
702
			else:
711
			else:
703
				print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name
712
				print >> out, "WARNING: No attribute with name %s in this module, value not appended." % name
 Lines 708-842   def _doit(arglist, out=sys.stdout): Link Here 
708
				value = _2utf8(value)
717
				value = _2utf8(value)
709
			except ValueError:
718
			except ValueError:
710
				name, value = val, None
719
				name, value = val, None
711
			for mod, (properties,options) in information.items():
720
			for mod, (properties, options) in information.items():
712
				if name in properties:
721
				if name in properties:
713
					if properties[name].multivalue:
722
					if properties[name].multivalue:
714
						values = remove.setdefault(name, [])
723
						values = remove.setdefault(name, [])
715
						if value:
724
						if value:
716
							values.append(value)
725
							values.append(value)
717
					else:
726
					else:
718
						remove[name]=value
727
						remove[name] = value
719
					break
728
					break
720
			else:
729
			else:
721
				print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name
730
				print >> out, "WARNING: No attribute with name %s in this module, value not removed." % name
731
722
		elif opt == '--remove_referring':
732
		elif opt == '--remove_referring':
723
			remove_referring = True
733
			remove_referring = True
734
724
		elif opt == '--recursive':
735
		elif opt == '--recursive':
725
			recursive = True
736
			recursive = True
726
737
727
728
	if action in ('modify', 'edit', 'create', 'new'):
738
	if action in ('modify', 'edit', 'create', 'new'):
729
			for el in policy_reference:
739
		for el in policy_reference:
730
				oc = lo.get(el, ['objectClass'])
740
			oc = lo.get(el, ['objectClass'])
731
				if not oc:
741
			if not oc:
732
					print >> out, "Object to be referenced does not exist: %s" % (el,)
742
				print >> out, "Object to be referenced does not exist: %s" % (el,)
733
					raise Failed()
743
				raise Failed()
734
				if not 'univentionPolicy' in oc['objectClass']:
744
			if not 'univentionPolicy' in oc['objectClass']:
735
					print >> out, "Object to be referenced is no valid Policy: %s" % (el,)
745
				print >> out, "Object to be referenced is no valid Policy: %s" % (el,)
736
					raise Failed()
746
				raise Failed()
737
738
747
739
#+++# ACTION CREATE #+++#
748
	#+++# ACTION CREATE #+++#
740
	if action in ('create', 'new'):
749
	if action in ('create', 'new'):
741
			if getattr(module, 'operations', None):
750
		if getattr(module, 'operations', None):
742
				if not 'add' in module.operations:
751
			if not 'add' in module.operations:
743
					print >> out, 'Create %s not allowed' % module_name
752
				print >> out, 'Create %s not allowed' % module_name
744
					raise Failed()
745
			try:
746
				object=module.object(co, lo, position=position, superordinate=superordinate)
747
			except uex.insufficientInformation:
748
				print >> out, 'E: Insufficient information'
749
				print >> out, 'Superordinate object is missing'
750
				raise Failed()
753
				raise Failed()
754
		try:
755
			object = module.object(co, lo, position=position, superordinate=superordinate)
756
		except uex.insufficientInformation:
757
			print >> out, 'E: Insufficient information'
758
			print >> out, 'Superordinate object is missing'
759
			raise Failed()
751
760
752
			if parsed_options:
761
		if parsed_options:
753
				object.options=parsed_options
762
			object.options = parsed_options
754
763
755
			object.open()
764
		object.open()
756
			if getattr(object, 'open_warning', None):
765
		if getattr(object, 'open_warning', None):
757
				print >> out, 'WARNING:%s' % object.open_warning
766
			print >> out, 'WARNING:%s' % object.open_warning
758
			try:
767
		try:
759
				object_input(module, object, input, append=append, out=out)
768
			object_input(module, object, input, append=append, out=out)
760
			except uex.nextFreeIp:
769
		except uex.nextFreeIp:
761
				if not ignore_exists:
770
			if not ignore_exists:
762
					print >> out, 'E: No free IP address found'
771
				print >> out, 'E: No free IP address found'
763
					raise Failed()
764
			except uex.valueInvalidSyntax, err:
765
				print >> out, 'E: Invalid Syntax: %s' % err
766
				raise Failed()
767
			except Exception, err:
768
				print >> out, 'E: Option %s is not valid' % err
769
				raise Failed()
772
				raise Failed()
773
		except uex.valueInvalidSyntax, err:
774
			print >> out, 'E: Invalid Syntax: %s' % err
775
			raise Failed()
776
		except Exception, err:
777
			print >> out, 'E: Option %s is not valid' % err
778
			raise Failed()
770
779
771
			exists_msg=None
780
		exists_msg = None
772
			try:
781
		try:
773
				dn=object.create()
782
			dn = object.create()
774
			except uex.objectExists, dn:
783
		except uex.objectExists, dn:
775
				exists_msg = dn
784
			exists_msg = dn
776
				if not ignore_exists:
785
			if not ignore_exists:
777
					print >> out, 'E: Object exists: %s' % exists_msg
786
				print >> out, 'E: Object exists: %s' % exists_msg
778
					raise Failed()
779
			except uex.uidAlreadyUsed, user:
780
				exists_msg = '(uid) %s' % user
781
				if not ignore_exists:
782
					print >> out, 'E: Object exists: %s' % exists_msg
783
					raise Failed()
784
			except uex.groupNameAlreadyUsed, group:
785
				exists_msg = '(group) %s' % group
786
				if not ignore_exists:
787
					print >> out, 'E: Object exists: %s' % exists_msg
788
					raise Failed()
789
			except uex.dhcpServerAlreadyUsed, name:
790
				exists_msg = '(dhcpserver) %s' % name
791
				if not ignore_exists:
792
					print >> out, 'E: Object exists: %s' % exists_msg
793
					raise Failed()
794
			except uex.macAlreadyUsed, mac:
795
				exists_msg = '(mac) %s' % mac
796
				if not ignore_exists:
797
					print >> out, 'E: Object exists: %s' % exists_msg
798
					raise Failed()
799
			except uex.noLock, e:
800
				exists_msg = '(nolock) %s' % str(e)
801
				if not ignore_exists:
802
					print >> out, 'E: Object exists: %s' % exists_msg
803
					raise Failed()
804
			except uex.invalidDhcpEntry:
805
				print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
806
				raise Failed()
787
				raise Failed()
807
			except uex.invalidOptions, e:
788
		except uex.uidAlreadyUsed, user:
808
				if not ignore_exists:
789
			exists_msg = '(uid) %s' % user
809
					print >> out, 'E: invalid Options: %s' % e
790
			if not ignore_exists:
810
					raise Failed()
791
				print >> out, 'E: Object exists: %s' % exists_msg
811
			except uex.insufficientInformation:
812
				print >> out, 'E: Insufficient information'
813
				print >> out, 'The following parameters are missing:'
814
				for i in module.property_descriptions:
815
					property=module.property_descriptions.get(i)
816
					if property.required:
817
						if i not in object or (not object[i] or (isinstance(object[i], list) and object[i]==[''])):
818
							print >> out, i
819
				raise Failed()
792
				raise Failed()
820
			except uex.noObject, e:
793
		except uex.groupNameAlreadyUsed, group:
821
				print >> out, 'E: object not found: %s' % e
794
			exists_msg = '(group) %s' % group
795
			if not ignore_exists:
796
				print >> out, 'E: Object exists: %s' % exists_msg
822
				raise Failed()
797
				raise Failed()
823
			except uex.circularGroupDependency, e:
798
		except uex.dhcpServerAlreadyUsed, name:
824
				print >> out, 'E: circular group dependency detected: %s' % e
799
			exists_msg = '(dhcpserver) %s' % name
800
			if not ignore_exists:
801
				print >> out, 'E: Object exists: %s' % exists_msg
825
				raise Failed()
802
				raise Failed()
803
		except uex.macAlreadyUsed, mac:
804
			exists_msg = '(mac) %s' % mac
805
			if not ignore_exists:
806
				print >> out, 'E: Object exists: %s' % exists_msg
807
				raise Failed()
808
		except uex.noLock, e:
809
			exists_msg = '(nolock) %s' % str(e)
810
			if not ignore_exists:
811
				print >> out, 'E: Object exists: %s' % exists_msg
812
				raise Failed()
813
		except uex.invalidDhcpEntry:
814
			print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
815
			raise Failed()
816
		except uex.invalidOptions, e:
817
			if not ignore_exists:
818
				print >> out, 'E: invalid Options: %s' % e
819
				raise Failed()
820
		except uex.insufficientInformation:
821
			print >> out, 'E: Insufficient information'
822
			print >> out, 'The following parameters are missing:'
823
			for i in module.property_descriptions:
824
				property = module.property_descriptions.get(i)
825
				if property.required:
826
					if i not in object or (not object[i] or (isinstance(object[i], list) and object[i] == [''])):
827
						print >> out, i
828
			raise Failed()
829
		except uex.noObject, e:
830
			print >> out, 'E: object not found: %s' % e
831
			raise Failed()
832
		except uex.circularGroupDependency, e:
833
			print >> out, 'E: circular group dependency detected: %s' % e
834
			raise Failed()
826
835
827
			if policy_reference:
836
		if policy_reference:
828
				lo.modify(dn,[('objectClass','','univentionPolicyReference')])
837
			lo.modify(dn, [('objectClass', '', 'univentionPolicyReference')])
829
				modlist = [('univentionPolicyReference', '', el) for el in policy_reference]
838
			modlist = [('univentionPolicyReference', '', el) for el in policy_reference]
830
				lo.modify(dn,modlist)
839
			lo.modify(dn, modlist)
831
840
832
			if exists_msg:
841
		if exists_msg:
833
					print >> out, 'Object exists: %s' % exists_msg
842
				print >> out, 'Object exists: %s' % exists_msg
834
			else:
843
		else:
835
				if not dn:
844
			if not dn:
836
					dn=object.dn
845
				dn = object.dn
837
				print >> out, 'Object created: %s' % _2utf8(dn)
846
			print >> out, 'Object created: %s' % _2utf8(dn)
838
847
839
#+++# ACTION MODIFY #+++#
848
	#+++# ACTION MODIFY #+++#
840
	elif action == 'modify' or action == 'edit' or action == 'move':
849
	elif action == 'modify' or action == 'edit' or action == 'move':
841
		if not dn:
850
		if not dn:
842
			print >> out, 'E: DN is missing'
851
			print >> out, 'E: DN is missing'
 Lines 850-856   def _doit(arglist, out=sys.stdout): Link Here 
850
				raise Failed()
859
				raise Failed()
851
860
852
		try:
861
		try:
853
			object=univention.admin.objects.get(module, co, lo, position='', dn=dn)
862
			object = univention.admin.objects.get(module, co, lo, position='', dn=dn)
854
		except uex.noObject:
863
		except uex.noObject:
855
			print >> out, 'E: object not found'
864
			print >> out, 'E: object not found'
856
			raise Failed()
865
			raise Failed()
 Lines 875-884   def _doit(arglist, out=sys.stdout): Link Here 
875
					print >> out, "position does not exsist: %s" % position_dn
884
					print >> out, "position does not exsist: %s" % position_dn
876
					raise Failed()
885
					raise Failed()
877
				rdn, _old_base = dn.split(',', 1)
886
				rdn, _old_base = dn.split(',', 1)
878
				newdn="%s,%s" % (rdn,position_dn)
887
				newdn = "%s,%s" % (rdn, position_dn)
879
				try:
888
				try:
880
					object.move(newdn)
889
					object.move(newdn)
881
					object_modified+=1
890
					object_modified += 1
882
				except uex.noObject:
891
				except uex.noObject:
883
					print >> out, 'E: object not found'
892
					print >> out, 'E: object not found'
884
					raise Failed()
893
					raise Failed()
 Lines 895-917   def _doit(arglist, out=sys.stdout): Link Here 
895
					print >> out, str(msg)
904
					print >> out, str(msg)
896
					raise Failed()
905
					raise Failed()
897
906
898
		else: # modify
907
		else:  # modify
899
900
			if any((input, append, remove, parsed_append_options, parsed_options)):
908
			if any((input, append, remove, parsed_append_options, parsed_options)):
901
				if parsed_options:
909
				if parsed_options:
902
					object.options=parsed_options
910
					object.options = parsed_options
903
				if parsed_append_options:
911
				if parsed_append_options:
904
					for option in parsed_append_options:
912
					for option in parsed_append_options:
905
						object.options.append(option)
913
						object.options.append(option)
906
				try:
914
				try:
907
					object_input(module, object, input, append, remove, out=out)
915
					object_input(module, object, input, append, remove, out=out)
908
				except uex.valueMayNotChange,e:
916
				except uex.valueMayNotChange, e:
909
					print >> out, unicode(e[0])
917
					print >> out, unicode(e[0])
910
					raise Failed()
918
					raise Failed()
911
				if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options:
919
				if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options:
912
					try:
920
					try:
913
						dn=object.modify()
921
						dn = object.modify()
914
						object_modified+=1
922
						object_modified += 1
915
					except uex.noObject:
923
					except uex.noObject:
916
						print >> out, 'E: object not found'
924
						print >> out, 'E: object not found'
917
						raise Failed()
925
						raise Failed()
 Lines 926-935   def _doit(arglist, out=sys.stdout): Link Here 
926
						raise Failed()
934
						raise Failed()
927
935
928
			if policy_reference:
936
			if policy_reference:
929
				if 'univentionPolicyReference' not in lo.get(dn,['objectClass'])['objectClass']:
937
				if 'univentionPolicyReference' not in lo.get(dn, ['objectClass'])['objectClass']:
930
					lo.modify(dn,[('objectClass','','univentionPolicyReference')])
938
					lo.modify(dn, [('objectClass', '', 'univentionPolicyReference')])
931
					object_modified+=1
939
					object_modified += 1
932
				modlist=[]
940
				modlist = []
933
				upr = lo.search(base=dn, scope='base', attr=['univentionPolicyReference'])[0][1]
941
				upr = lo.search(base=dn, scope='base', attr=['univentionPolicyReference'])[0][1]
934
				if 'univentionPolicyReference' not in upr:
942
				if 'univentionPolicyReference' not in upr:
935
					upr['univentionPolicyReference'] = []
943
					upr['univentionPolicyReference'] = []
 Lines 937-951   def _doit(arglist, out=sys.stdout): Link Here 
937
					if val in upr['univentionPolicyReference']:
945
					if val in upr['univentionPolicyReference']:
938
						print >> out, 'WARNING: cannot append %s to univentionPolicyReference, value exists' % val
946
						print >> out, 'WARNING: cannot append %s to univentionPolicyReference, value exists' % val
939
					else:
947
					else:
940
						modlist.append(('univentionPolicyReference','',el))
948
						modlist.append(('univentionPolicyReference', '', el))
941
				if modlist:
949
				if modlist:
942
					lo.modify(dn,modlist)
950
					lo.modify(dn, modlist)
943
					object_modified+=1
951
					object_modified += 1
944
952
945
			if policy_dereference:
953
			if policy_dereference:
946
				modlist = [('univentionPolicyReference', el, '') for el in policy_dereference]
954
				modlist = [('univentionPolicyReference', el, '') for el in policy_dereference]
947
				lo.modify(dn,modlist)
955
				lo.modify(dn, modlist)
948
				object_modified+=1
956
				object_modified += 1
949
957
950
		if object_modified > 0:
958
		if object_modified > 0:
951
			print >> out, 'Object modified: %s' % _2utf8(dn)
959
			print >> out, 'Object modified: %s' % _2utf8(dn)
 Lines 953-959   def _doit(arglist, out=sys.stdout): Link Here 
953
			print >> out, 'No modification: %s' % _2utf8(dn)
961
			print >> out, 'No modification: %s' % _2utf8(dn)
954
962
955
	elif action == 'remove' or action == 'delete':
963
	elif action == 'remove' or action == 'delete':
956
957
		if getattr(module, 'operations', None):
964
		if getattr(module, 'operations', None):
958
			if not 'remove' in module.operations:
965
			if not 'remove' in module.operations:
959
				print >> out, 'Remove %s not allowed' % module_name
966
				print >> out, 'Remove %s not allowed' % module_name
 Lines 961-971   def _doit(arglist, out=sys.stdout): Link Here 
961
968
962
		try:
969
		try:
963
			if dn and filter:
970
			if dn and filter:
964
				object=univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0]
971
				object = univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0]
965
			elif dn:
972
			elif dn:
966
				object=univention.admin.modules.lookup(module, co, lo, scope='base', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0]
973
				object = univention.admin.modules.lookup(module, co, lo, scope='base', superordinate=superordinate, base=dn, filter=filter, required=1, unique=1)[0]
967
			elif filter:
974
			elif filter:
968
				object=univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter, required=1, unique=1)[0]
975
				object = univention.admin.modules.lookup(module, co, lo, scope='sub', superordinate=superordinate, base=position.getDn(), filter=filter, required=1, unique=1)[0]
969
			else:
976
			else:
970
				print >> out, 'E: dn or filter needed'
977
				print >> out, 'E: dn or filter needed'
971
				raise Failed()
978
				raise Failed()
 Lines 983-989   def _doit(arglist, out=sys.stdout): Link Here 
983
		if recursive:
990
		if recursive:
984
			try:
991
			try:
985
				object.remove(recursive)
992
				object.remove(recursive)
986
			except uex.ldapError,msg:
993
			except uex.ldapError, msg:
987
				print >> out, str(msg)
994
				print >> out, str(msg)
988
				raise Failed()
995
				raise Failed()
989
		else:
996
		else:
 Lines 995-1001   def _doit(arglist, out=sys.stdout): Link Here 
995
		print >> out, 'Object removed: %s' % _2utf8(dn)
1002
		print >> out, 'Object removed: %s' % _2utf8(dn)
996
1003
997
	elif action == 'list' or action == 'lookup':
1004
	elif action == 'list' or action == 'lookup':
998
999
		if getattr(module, 'operations', None):
1005
		if getattr(module, 'operations', None):
1000
			if not 'search' in module.operations:
1006
			if not 'search' in module.operations:
1001
				print >> out, 'Search %s not allowed' % module_name
1007
				print >> out, 'Search %s not allowed' % module_name
 Lines 1012-1018   def _doit(arglist, out=sys.stdout): Link Here 
1012
					if getattr(object, 'open_warning', None):
1018
					if getattr(object, 'open_warning', None):
1013
						print >> out, 'WARNING: %s' % object.open_warning
1019
						print >> out, 'WARNING: %s' % object.open_warning
1014
					for key, value in object.items():
1020
					for key, value in object.items():
1015
						s=module.property_descriptions[key].syntax
1021
						s = module.property_descriptions[key].syntax
1016
						if module.property_descriptions[key].multivalue:
1022
						if module.property_descriptions[key].multivalue:
1017
							for v in value:
1023
							for v in value:
1018
								if s.tostring(v):
1024
								if s.tostring(v):
 Lines 1025-1033   def _doit(arglist, out=sys.stdout): Link Here 
1025
							else:
1031
							else:
1026
								print >> out, '  %s: %s' % (_2utf8(key), None)
1032
								print >> out, '  %s: %s' % (_2utf8(key), None)
1027
1033
1028
					if 'univentionPolicyReference' in lo.get(univention.admin.objects.dn(object),['objectClass'])['objectClass']:
1034
					if 'univentionPolicyReference' in lo.get(univention.admin.objects.dn(object), ['objectClass'])['objectClass']:
1029
						references = lo.get( _2utf8(univention.admin.objects.dn( object ) ),
1035
						references = lo.get(
1030
										 [ 'univentionPolicyReference' ] )
1036
							_2utf8(univention.admin.objects.dn(object)),
1037
							['univentionPolicyReference']
1038
						)
1031
						if references:
1039
						if references:
1032
							for el in references['univentionPolicyReference']:
1040
							for el in references['univentionPolicyReference']:
1033
								print >> out, '  %s: %s' % (
1041
								print >> out, '  %s: %s' % (
 Lines 1036-1073   def _doit(arglist, out=sys.stdout): Link Here 
1036
								)
1044
								)
1037
1045
1038
				if list_policies:
1046
				if list_policies:
1039
					utf8_objectdn = _2utf8( univention.admin.objects.dn( object ) )
1047
					utf8_objectdn = _2utf8(univention.admin.objects.dn(object))
1040
					print >> out, "  Policy-based Settings:"
1048
					print >> out, "  Policy-based Settings:"
1041
					client = get_policy(utf8_objectdn, out, policyOptions, policies_with_DN)
1049
					client = get_policy(utf8_objectdn, out, policyOptions, policies_with_DN)
1042
					print >> out, ''
1050
					print >> out, ''
1043
1051
1044
					if module_name == 'dhcp/host':
1052
					if module_name == 'dhcp/host':
1045
							subnet_module=univention.admin.modules.get('dhcp/subnet')
1053
						subnet_module = univention.admin.modules.get('dhcp/subnet')
1046
							for subnet in univention.admin.modules.lookup(subnet_module, co, lo, scope='sub', superordinate=superordinate, base='', filter=''):
1054
						for subnet in univention.admin.modules.lookup(subnet_module, co, lo, scope='sub', superordinate=superordinate, base='', filter=''):
1047
1055
							if univention.admin.ipaddress.ip_is_in_network(subnet['subnet'], subnet['subnetmask'], object['fixedaddress'][0]):
1048
								if univention.admin.ipaddress.ip_is_in_network(subnet['subnet'], subnet['subnetmask'], object['fixedaddress'][0]):
1056
								utf8_subnet_dn = _2utf8(subnet.dn)
1049
									utf8_subnet_dn = _2utf8( subnet.dn )
1057
								print >> out, "  Subnet-based Settings:"
1050
									print >> out, "  Subnet-based Settings:"
1058
								ddict = get_policy(utf8_subnet_dn, out, policyOptions, policies_with_DN)
1051
									ddict = get_policy(utf8_subnet_dn, out, policyOptions, policies_with_DN)
1059
								print >> out, ''
1052
									print >> out, ''
1060
1053
1061
								print >> out, "  Merged Settings:"
1054
									print >> out, "  Merged Settings:"
1062
1055
1063
								for key, values in ddict.items():
1056
									for key, values in ddict.items():
1064
									if key not in client:
1057
										if key not in client:
1065
										client[key] = values
1058
											client[key] = values
1066
1059
1067
								if policies_with_DN:
1060
									if policies_with_DN:
1068
									for key, (policy, values) in client.items():
1061
										for key, (policy, values) in client.items():
1069
										print >> out, "    Policy: " + policy
1062
											print >> out, "    Policy: " + policy
1070
										print >> out, "    Attribute: " + key
1063
											print >> out, "    Attribute: " + key
1071
										for value in values:
1064
											for value in values:
1072
											print >> out, "    Value: " + value
1065
												print >> out, "    Value: " + value
1073
								else:
1066
									else:
1074
									for key, values in client.items():
1067
										for key, values in client.items():
1075
										for value in values:
1068
											for value in values:
1076
											print >> out, "    %s=%s" % (key, value)
1069
												print >> out, "    %s=%s" % (key, value)
1077
								print >> out, ''
1070
									print >> out, ''
1071
1078
1072
				print >> out, ''
1079
				print >> out, ''
1073
		except uex.ldapError, errmsg:
1080
		except uex.ldapError, errmsg:
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/univention-cli-server (-5 / +5 lines)
 Lines 55-60   except ImportError: Link Here 
55
55
56
logfile = ''
56
logfile = ''
57
57
58
58
class MyRequestHandler(SocketServer.BaseRequestHandler):
59
class MyRequestHandler(SocketServer.BaseRequestHandler):
59
	"""Handle request on listeneing socket to open new connection."""
60
	"""Handle request on listeneing socket to open new connection."""
60
	def handle(self):
61
	def handle(self):
 Lines 74-83   class ForkingTCPServer(SocketServer.ForkingTCPServer): Link Here 
74
	"""UDM server listening on UNIX socket."""
75
	"""UDM server listening on UNIX socket."""
75
	address_family = socket.AF_UNIX
76
	address_family = socket.AF_UNIX
76
	allow_reuse_address = 1
77
	allow_reuse_address = 1
78
77
	def server_bind(self):
79
	def server_bind(self):
78
		SocketServer.TCPServer.server_bind(self)
80
		SocketServer.TCPServer.server_bind(self)
79
		_host, port = self.socket.getsockname()[:2]
81
		_host, port = self.socket.getsockname()[:2]
80
		self.server_name = 'localhost' #socket.getfqdn(host)
82
		self.server_name = 'localhost'  # socket.getfqdn(host)
81
		self.server_port = port
83
		self.server_port = port
82
84
83
85
 Lines 104-110   def server_main(): Link Here 
104
				os.kill(pid, signal.SIGCONT)
106
				os.kill(pid, signal.SIGCONT)
105
		except (ValueError, OSError):
107
		except (ValueError, OSError):
106
			pid = 0
108
			pid = 0
107
		if not pid: # no pid found or no server running
109
		if not pid:  # no pid found or no server running
108
			os.unlink(socket_path)
110
			os.unlink(socket_path)
109
			os.unlink(runfilename)
111
			os.unlink(runfilename)
110
			os.rmdir(socket_dir)
112
			os.rmdir(socket_dir)
 Lines 160-166   def server_main(): Link Here 
160
			if not rlist:
162
			if not rlist:
161
				ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] stopped after %s seconds idle' % (os.getpid(), timeout))
163
				ud.debug(ud.ADMIN, ud.INFO, 'daemon [%s] stopped after %s seconds idle' % (os.getpid(), timeout))
162
				sys.exit(0)
164
				sys.exit(0)
163
164
	finally:
165
	finally:
165
		os.unlink(socket_path)
166
		os.unlink(socket_path)
166
		os.unlink(runfilename)
167
		os.unlink(runfilename)
 Lines 259-263   def main(): Link Here 
259
	else:  # parent
260
	else:  # parent
260
		os.waitpid(pid, os.P_NOWAIT)
261
		os.waitpid(pid, os.P_NOWAIT)
261
262
263
262
if __name__ == "__main__":
264
if __name__ == "__main__":
263
	main()
265
	main()
264
- 
265
--
266
.../modules/univention/admincli/admin.py           | 108 ++++++++++-----------
266
.../modules/univention/admincli/admin.py           | 108 ++++++++++-----------
267
1 file changed, 54 insertions(+), 54 deletions(-)
267
1 file changed, 54 insertions(+), 54 deletions(-)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-56 / +54 lines)
 Lines 287-294   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
287
							tmp = list(values)
287
							tmp = list(values)
288
							tmp.append(val)
288
							tmp.append(val)
289
							object[key] = list(tmp)
289
							object[key] = list(tmp)
290
						except uex.valueInvalidSyntax, errmsg:
290
						except uex.valueInvalidSyntax, ex:
291
							print >> out, 'E: Invalid Syntax: %s' % (errmsg,)
291
							print >> out, 'E: Invalid Syntax: %s' % (ex,)
292
	if remove:
292
	if remove:
293
		for key, value in remove.items():
293
		for key, value in remove.items():
294
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
294
			if univention.admin.syntax.is_syntax(module.property_descriptions[key].syntax, univention.admin.syntax.complex):
 Lines 365-374   def object_input(module, object, input, append=None, remove=None, out=sys.stdout Link Here 
365
			else:
365
			else:
366
				try:
366
				try:
367
					object[key] = value
367
					object[key] = value
368
				except uex.ipOverridesNetwork, e:
368
				except uex.ipOverridesNetwork, ex:
369
					print >> out, 'WARNING: %s' % e.message
369
					print >> out, 'WARNING: %s' % ex.message
370
				except uex.valueMayNotChange, e:
370
				except uex.valueMayNotChange, ex:
371
					raise uex.valueMayNotChange, "%s: %s" % (e.message, key)
371
					raise uex.valueMayNotChange, "%s: %s" % (ex.message, key)
372
372
373
373
374
def list_available_modules(out=sys.stdout):
374
def list_available_modules(out=sys.stdout):
 Lines 382-398   def list_available_modules(out=sys.stdout): Link Here 
382
def doit(arglist, out=sys.stdout):
382
def doit(arglist, out=sys.stdout):
383
	try:
383
	try:
384
		_doit(arglist, out)
384
		_doit(arglist, out)
385
	except uex.base, e:
385
	except uex.base, ex:
386
		ud.debug(ud.ADMIN, ud.WARN, traceback.format_exc())
386
		ud.debug(ud.ADMIN, ud.WARN, traceback.format_exc())
387
387
388
		# collect error information
388
		# collect error information
389
		msg = []
389
		msg = []
390
		if getattr(e, 'message', None):
390
		if getattr(ex, 'message', None):
391
			msg.append(e.message)
391
			msg.append(ex.message)
392
		if getattr(e, 'args', None):
392
		if getattr(ex, 'args', None):
393
			#avoid duplicate messages
393
			#avoid duplicate messages
394
			if not len(msg) or len(e.args) > 1 or e.args[0] != msg[0]:
394
			if not len(msg) or len(ex.args) > 1 or ex.args[0] != msg[0]:
395
				msg.extend(e.args)
395
				msg.extend(ex.args)
396
396
397
		# strip elements and make sure that a ':' is printed iff further information follows
397
		# strip elements and make sure that a ':' is printed iff further information follows
398
		msg = [_.strip() for _ in msg]
398
		msg = [_.strip() for _ in msg]
 Lines 489-496   def _doit(arglist, out=sys.stdout): Link Here 
489
	]
489
	]
490
	try:
490
	try:
491
		opts, args = getopt.getopt(arglist[3:], '', longopts)
491
		opts, args = getopt.getopt(arglist[3:], '', longopts)
492
	except getopt.error, msg:
492
	except getopt.error, ex:
493
		print >> out, msg
493
		print >> out, ex
494
		raise Failed()
494
		raise Failed()
495
495
496
	if args and isinstance(args, list):
496
	if args and isinstance(args, list):
 Lines 536-543   def _doit(arglist, out=sys.stdout): Link Here 
536
			try:
536
			try:
537
				with open(val) as fp:
537
				with open(val) as fp:
538
					bindpwd = fp.read().strip()
538
					bindpwd = fp.read().strip()
539
			except IOError as e:
539
			except IOError as ex:
540
				print >> out, 'E: could not read bindpwd from file (%s)' % (e,)
540
				print >> out, 'E: could not read bindpwd from file (%s)' % (ex,)
541
				raise Failed()
541
				raise Failed()
542
		elif opt == '--dn':
542
		elif opt == '--dn':
543
			dn = _2utf8(val)
543
			dn = _2utf8(val)
 Lines 589-597   def _doit(arglist, out=sys.stdout): Link Here 
589
				start_tls=tls,
589
				start_tls=tls,
590
				bindpw=bindpwd
590
				bindpw=bindpwd
591
			)
591
			)
592
		except Exception, e:
592
		except Exception, ex:
593
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
593
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % (ex,))
594
			print >> out, 'authentication error: %s' % (e,)
594
			print >> out, 'authentication error: %s' % (ex,)
595
			raise Failed()
595
			raise Failed()
596
		policyOptions.extend(['-D', binddn, '-w', bindpwd])  # FIXME not so nice
596
		policyOptions.extend(['-D', binddn, '-w', bindpwd])  # FIXME not so nice
597
597
 Lines 625-633   def _doit(arglist, out=sys.stdout): Link Here 
625
				bindpw=pwd,
625
				bindpw=pwd,
626
				start_tls=tls
626
				start_tls=tls
627
			)
627
			)
628
		except Exception, e:
628
		except Exception, ex:
629
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % str(e))
629
			ud.debug(ud.ADMIN, ud.WARN, 'authentication error: %s' % (ex,))
630
			print >> out, 'authentication error: %s' % (e,)
630
			print >> out, 'authentication error: %s' % (ex,)
631
			raise Failed()
631
			raise Failed()
632
632
633
	if not position_dn and superordinate_dn:
633
	if not position_dn and superordinate_dn:
 Lines 664-671   def _doit(arglist, out=sys.stdout): Link Here 
664
	if superordinate_dn and univention.admin.modules.superordinate(module):
664
	if superordinate_dn and univention.admin.modules.superordinate(module):
665
		try:
665
		try:
666
			superordinate = univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn)
666
			superordinate = univention.admin.objects.get(univention.admin.modules.superordinate(module), co, lo, '', dn=superordinate_dn)
667
		except uex.insufficientInformation, e:
667
		except uex.insufficientInformation, ex:
668
			print >> out, 'Insufficient Information: %s' % (e,)
668
			print >> out, 'Insufficient Information: %s' % (ex,)
669
			raise Failed()
669
			raise Failed()
670
	else:
670
	else:
671
		superordinate = None
671
		superordinate = None
 Lines 770-780   def _doit(arglist, out=sys.stdout): Link Here 
770
			if not ignore_exists:
770
			if not ignore_exists:
771
				print >> out, 'E: No free IP address found'
771
				print >> out, 'E: No free IP address found'
772
				raise Failed()
772
				raise Failed()
773
		except uex.valueInvalidSyntax, err:
773
		except uex.valueInvalidSyntax, ex:
774
			print >> out, 'E: Invalid Syntax: %s' % err
774
			print >> out, 'E: Invalid Syntax: %s' % ex
775
			raise Failed()
775
			raise Failed()
776
		except Exception, err:
776
		except Exception, ex:
777
			print >> out, 'E: Option %s is not valid' % err
777
			print >> out, 'E: Option %s is not valid' % ex
778
			raise Failed()
778
			raise Failed()
779
779
780
		exists_msg = None
780
		exists_msg = None
 Lines 805-821   def _doit(arglist, out=sys.stdout): Link Here 
805
			if not ignore_exists:
805
			if not ignore_exists:
806
				print >> out, 'E: Object exists: %s' % exists_msg
806
				print >> out, 'E: Object exists: %s' % exists_msg
807
				raise Failed()
807
				raise Failed()
808
		except uex.noLock, e:
808
		except uex.noLock, ex:
809
			exists_msg = '(nolock) %s' % str(e)
809
			exists_msg = '(nolock) %s' % (ex,)
810
			if not ignore_exists:
810
			if not ignore_exists:
811
				print >> out, 'E: Object exists: %s' % exists_msg
811
				print >> out, 'E: Object exists: %s' % exists_msg
812
				raise Failed()
812
				raise Failed()
813
		except uex.invalidDhcpEntry:
813
		except uex.invalidDhcpEntry:
814
			print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
814
			print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
815
			raise Failed()
815
			raise Failed()
816
		except uex.invalidOptions, e:
816
		except uex.invalidOptions, ex:
817
			if not ignore_exists:
817
			if not ignore_exists:
818
				print >> out, 'E: invalid Options: %s' % e
818
				print >> out, 'E: invalid Options: %s' % ex
819
				raise Failed()
819
				raise Failed()
820
		except uex.insufficientInformation:
820
		except uex.insufficientInformation:
821
			print >> out, 'E: Insufficient information'
821
			print >> out, 'E: Insufficient information'
 Lines 826-836   def _doit(arglist, out=sys.stdout): Link Here 
826
					if i not in object or (not object[i] or (isinstance(object[i], list) and object[i] == [''])):
826
					if i not in object or (not object[i] or (isinstance(object[i], list) and object[i] == [''])):
827
						print >> out, i
827
						print >> out, i
828
			raise Failed()
828
			raise Failed()
829
		except uex.noObject, e:
829
		except uex.noObject, ex:
830
			print >> out, 'E: object not found: %s' % e
830
			print >> out, 'E: object not found: %s' % ex
831
			raise Failed()
831
			raise Failed()
832
		except uex.circularGroupDependency, e:
832
		except uex.circularGroupDependency, ex:
833
			print >> out, 'E: circular group dependency detected: %s' % e
833
			print >> out, 'E: circular group dependency detected: %s' % ex
834
			raise Failed()
834
			raise Failed()
835
835
836
		if policy_reference:
836
		if policy_reference:
 Lines 891-907   def _doit(arglist, out=sys.stdout): Link Here 
891
				except uex.noObject:
891
				except uex.noObject:
892
					print >> out, 'E: object not found'
892
					print >> out, 'E: object not found'
893
					raise Failed()
893
					raise Failed()
894
				except uex.ldapError, msg:
894
				except uex.ldapError, ex:
895
					print >> out, "ldap Error: %s" % msg
895
					print >> out, "ldap Error: %s" % ex
896
					raise Failed()
896
					raise Failed()
897
				except uex.nextFreeIp:
897
				except uex.nextFreeIp:
898
					print >> out, 'E: No free IP address found'
898
					print >> out, 'E: No free IP address found'
899
					raise Failed()
899
					raise Failed()
900
				except uex.valueInvalidSyntax, err:
900
				except uex.valueInvalidSyntax, ex:
901
					print >> out, 'E: Invalid Syntax: %s' % err
901
					print >> out, 'E: Invalid Syntax: %s' % ex
902
					raise Failed()
902
					raise Failed()
903
				except uex.invalidOperation, msg:
903
				except uex.invalidOperation, ex:
904
					print >> out, str(msg)
904
					print >> out, ex
905
					raise Failed()
905
					raise Failed()
906
906
907
		else:  # modify
907
		else:  # modify
 Lines 913-920   def _doit(arglist, out=sys.stdout): Link Here 
913
						object.options.append(option)
913
						object.options.append(option)
914
				try:
914
				try:
915
					object_input(module, object, input, append, remove, out=out)
915
					object_input(module, object, input, append, remove, out=out)
916
				except uex.valueMayNotChange, e:
916
				except uex.valueMayNotChange, ex:
917
					print >> out, unicode(e[0])
917
					print >> out, unicode(ex[0])
918
					raise Failed()
918
					raise Failed()
919
				if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options:
919
				if object.hasChanged(input.keys()) or object.hasChanged(append.keys()) or object.hasChanged(remove.keys()) or parsed_append_options or parsed_options:
920
					try:
920
					try:
 Lines 926-936   def _doit(arglist, out=sys.stdout): Link Here 
926
					except uex.invalidDhcpEntry:
926
					except uex.invalidDhcpEntry:
927
						print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
927
						print >> out, 'E: The DHCP entry for this host should contain the zone dn, the ip address and the mac address.'
928
						raise Failed()
928
						raise Failed()
929
					except uex.circularGroupDependency, e:
929
					except uex.circularGroupDependency, ex:
930
						print >> out, 'E: circular group dependency detected: %s' % e
930
						print >> out, 'E: circular group dependency detected: %s' % ex
931
						raise Failed()
931
						raise Failed()
932
					except uex.valueInvalidSyntax, e:
932
					except uex.valueInvalidSyntax, ex:
933
						print >> out, 'E: Invalid Syntax: %s' % e
933
						print >> out, 'E: Invalid Syntax: %s' % ex
934
						raise Failed()
934
						raise Failed()
935
935
936
			if policy_reference:
936
			if policy_reference:
 Lines 990-997   def _doit(arglist, out=sys.stdout): Link Here 
990
		if recursive:
990
		if recursive:
991
			try:
991
			try:
992
				object.remove(recursive)
992
				object.remove(recursive)
993
			except uex.ldapError, msg:
993
			except uex.ldapError, ex:
994
				print >> out, str(msg)
994
				print >> out, ex
995
				raise Failed()
995
				raise Failed()
996
		else:
996
		else:
997
			try:
997
			try:
 Lines 1077-1087   def _doit(arglist, out=sys.stdout): Link Here 
1077
								print >> out, ''
1077
								print >> out, ''
1078
1078
1079
				print >> out, ''
1079
				print >> out, ''
1080
		except uex.ldapError, errmsg:
1080
		except uex.ldapError, ex:
1081
			print >> out, '%s' % (errmsg,)
1081
			print >> out, ex
1082
			raise Failed()
1082
			raise Failed()
1083
		except uex.valueInvalidSyntax, errmsg:
1083
		except uex.valueInvalidSyntax, ex:
1084
			print >> out, '%s' % (errmsg.message,)
1084
			print >> out, ex.message
1085
			raise Failed()
1085
			raise Failed()
1086
	else:
1086
	else:
1087
		print >> out, "Unknown or no action defined"
1087
		print >> out, "Unknown or no action defined"
1088
- 
1089
--
1090
.../modules/univention/admincli/admin.py           | 148 +++++++++++++++++++++
1088
.../modules/univention/admincli/admin.py           | 148 +++++++++++++++++++++
1091
1 file changed, 148 insertions(+)
1089
1 file changed, 148 insertions(+)
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admincli/admin.py (-1 / +148 lines)
 Lines 32-37    Link Here 
32
32
33
from textwrap import dedent
33
from textwrap import dedent
34
import sys
34
import sys
35
from argparse import ArgumentParser
35
import getopt
36
import getopt
36
import re
37
import re
37
import base64
38
import base64
 Lines 56-61   univention.admin.modules.update() Link Here 
56
univention.admin.syntax.update_choices()
57
univention.admin.syntax.update_choices()
57
58
58
59
60
def parse_commandline():
61
	usage = dedent("""\
62
	%(prog)s module action [arguments]
63
	%(prog)s [--help] [--version]
64
	""")
65
	description = dedent("""\
66
	univention-directory-manager is a tool to handle the configuration for UCS
67
	on command line level.
68
	Use "univention-directory-manager modules" for a list of available modules.
69
	""")
70
	version = "%(prog)s @%@package_version@%@"
71
	parser = ArgumentParser(
72
		usage=usage,
73
		description=description,
74
		prog="univention-directory-manager")
75
	parser.add_argument("-?", action="help")
76
	parser.add_argument("--version", action="version", version=version)
77
78
	general_opt = parser.add_argument_group("General options")
79
	general_opt.add_argument(
80
		"--logfile",
81
		dest="logfile",
82
		default='/var/log/univention/directory-manager-cmd.log',
83
		help="path and name of the logfile to be used")
84
	general_opt.add_argument(
85
		"--binddn",
86
		dest="binddn",
87
		help="bind DN")
88
	general_opt.add_argument(
89
		"--bindpwd",
90
		dest="bindpwd",
91
		help="bind password")
92
	general_opt.add_argument(
93
		"--bindpwdfile",
94
		dest="bindpwdfile",
95
		help="file containing bind password")
96
	general_opt.add_argument(
97
		"--tls",
98
		dest="tls", type=int,
99
		default=2, choices=range(3),
100
		help="0 (no); 1 (try); 2 (must)")
101
102
	subparsers = parser.add_subparsers(
103
			title="sub-commands",
104
			description="valid subcommands",
105
			help="additional help")
106
107
	create_opt = subparsers.add_parser("modules", help="List available modules")
108
109
	create_opt = subparsers.add_parser("create", help="Create a new object")
110
	create_opt.add_argument(
111
		"--position",
112
		dest="position",
113
		help="Set position in tree")
114
	create_opt.add_argument(
115
		"--set",
116
		action="append", dest="set", required=True,
117
		help="Set variable to value, e.g. foo=bar")
118
	create_opt.add_argument(
119
		"--superordinate",
120
		dest="superordinate",
121
		help="Use superordinate module")
122
	create_opt.add_argument(
123
		"--option",
124
		action="append", dest="option",
125
		help="Use only given module options")
126
	create_opt.add_argument(
127
		"--policy-reference",
128
		action="append", dest="policy_reference",
129
		help="Reference to policy given by DN")
130
	create_opt.add_argument(
131
		"--ignore_exists",
132
		action="store_true", dest="ignore_exists",
133
		help="Ignore already existing object")
134
135
	modify_opt = subparsers.add_parser("modify", help="Modify an existing object")
136
	modify_opt.add_argument(
137
		"--dn",
138
		dest="dn", required=True,
139
		help="Edit object with DN")
140
	modify_opt.add_argument(
141
		"--set",
142
		action="append", dest="set",
143
		help="Set variable to value, e.g. foo=bar")
144
	modify_opt.add_argument(
145
		"--append",
146
		action="append", dest="append",
147
		help="Append value to variable, e.g. foo=bar")
148
	modify_opt.add_argument(
149
		"--remove",
150
		action="append", dest="remove",
151
		help="Remove value from variable, e.g. foo=bar")
152
	modify_opt.add_argument(
153
		"--option",
154
		action="append", dest="option",
155
		help="Append the module options")
156
	modify_opt.add_argument(
157
		"--policy-reference",
158
		action="append", dest="policy_reference",
159
		help="Reference to policy given by DN")
160
	modify_opt.add_argument(
161
		"--policy-dereference",
162
		action="append", dest="policy_dereference",
163
		help="Remove reference to policy given by DN")
164
165
	remove_opt = subparsers.add_parser("remove", help="Remove an existing object")
166
	remove_opt.add_argument(
167
		"--dn",
168
		dest="dn",
169
		help="Remove object with DN")
170
	remove_opt.add_argument(
171
		"--superordinate",
172
		dest="superordinate",
173
		help="Use superordinate module")
174
	remove_opt.add_argument(
175
		"--filter",
176
		dest="filter",
177
		help="Lookup filter e.g. foo=bar")
178
	remove_opt.add_argument(
179
		"--remove_referring",
180
		action="store_true", dest="remove_referring",
181
		help="Remove referring objects")
182
183
	list_opt = subparsers.add_parser("list", help="List objects")
184
	list_opt.add_argument(
185
		"--filter",
186
		dest="filter",
187
		help="Lookup filter e.g. foo=bar")
188
	list_opt.add_argument(
189
		"--policies",
190
		dest="policies", type=int, choices=range(2),
191
		help="List policy-based settings: 0:short, 1:long (with policy-DN)")
192
193
	move_opt = subparsers.add_parser("move", help="Move object in directory tree")
194
	move_opt.add_argument(
195
		"--dn",
196
		dest="dn", required=True,
197
		help="Move object with DN")
198
	move_opt.add_argument(
199
		"--position",
200
		dest="position", required=True,
201
		help="Move to position in tree")
202
203
	args = parser.parse_args()
204
	return args
205
206
59
class Failed(Exception):
207
class Failed(Exception):
60
	def __str__(self):
208
	def __str__(self):
61
		return "OPERATION FAILED"
209
		return "OPERATION FAILED"
62
- 

Return to bug 33224