View | Details | Raw Unified | Return to bug 33223 | 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/admin/handlers/__init__.py (-69 / +28 lines)
 Lines 64-69   s4connector_search = False Link Here 
64
# FIXME: What is the use of the following line?
64
# FIXME: What is the use of the following line?
65
# __path__.append("users")
65
# __path__.append("users")
66
66
67
67
# manages properties
68
# manages properties
68
class base(object):
69
class base(object):
69
	def __init__(self, co, lo, position, dn='', superordinate = None ):
70
	def __init__(self, co, lo, position, dn='', superordinate = None ):
 Lines 299-305   class base(object): Link Here 
299
		return self.descriptions.keys()
300
		return self.descriptions.keys()
300
301
301
	def items(self):
302
	def items(self):
302
303
		# this returns emtpy strings resp. empty lists for attributes not set
303
		# this returns emtpy strings resp. empty lists for attributes not set
304
		r=[]
304
		r=[]
305
		for key in self.keys():
305
		for key in self.keys():
 Lines 456-462   class base(object): Link Here 
456
456
457
457
458
class simpleLdap(base):
458
class simpleLdap(base):
459
460
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
459
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
461
		global s4connector_present
460
		global s4connector_present
462
		global s4connector_search
461
		global s4connector_search
 Lines 528-534   class simpleLdap(base): Link Here 
528
	def description(self):
527
	def description(self):
529
		if self.dn:
528
		if self.dn:
530
			rdn = self.lo.explodeDn(self.dn)[0]
529
			rdn = self.lo.explodeDn(self.dn)[0]
531
			return rdn[rdn.find('=')+1:]
530
			return rdn[rdn.find('=') + 1:]
532
		else:
531
		else:
533
			return 'none'
532
			return 'none'
534
533
 Lines 546-579   class simpleLdap(base): Link Here 
546
		self.exceptions=[]
545
		self.exceptions=[]
547
546
548
		# remove all properties which do not belong to chosen options
547
		# remove all properties which do not belong to chosen options
549
550
		chosen_options = None
551
		descriptions = None
552
553
		try:
548
		try:
554
			# these might not be set by an inheriting module
549
			# these might not be set by an inheriting module
555
			chosen_options = self.options
550
			chosen_options = self.options
556
			descriptions = self.descriptions
551
			descriptions = self.descriptions
557
		except:
552
		except:
558
			pass
553
			chosen_options = None
554
			descriptions = None
559
555
560
		if chosen_options and descriptions:
556
		if chosen_options and descriptions:
561
			for desc in descriptions:
557
			for desc in descriptions:
562
				propoptions = descriptions[desc].options
558
				propoptions = descriptions[desc].options
563
559
564
				if (propoptions==[]):
560
				if not propoptions:
565
					# property applies to all options
561
					# property applies to all options
566
					continue
562
					continue
567
563
568
				shortcut = False
564
				if set(propoptions) & set(chosen_options):
569
565
					# this property applies to one of the chosen options,
570
				for i in propoptions:
566
					# jump to next option
571
					if i in chosen_options:
572
						# this property applies to one of the chosen options,
573
						# jump to next option
574
						shortcut = True
575
						continue
576
				if shortcut:
577
					continue
567
					continue
578
568
579
				# if we've come here, we found a property that does not apply
569
				# if we've come here, we found a property that does not apply
 Lines 594-600   class simpleLdap(base): Link Here 
594
				ml.append(('objectClass', self.oldattr.get('objectClass', []), self.oldattr.get('objectClass', [])+['univentionPolicyReference']))
584
				ml.append(('objectClass', self.oldattr.get('objectClass', []), self.oldattr.get('objectClass', [])+['univentionPolicyReference']))
595
			ml.append(('univentionPolicyReference', self.oldpolicies, self.policies))
585
			ml.append(('univentionPolicyReference', self.oldpolicies, self.policies))
596
586
597
598
		return ml
587
		return ml
599
588
600
	def _create(self):
589
	def _create(self):
 Lines 719-725   class simpleLdap(base): Link Here 
719
		self.save()
708
		self.save()
720
		return self.dn
709
		return self.dn
721
710
722
#+++# MODIFY #+++#
711
	#+++# MODIFY #+++#
723
	def _modify(self, modify_childs=1, ignore_license=0):
712
	def _modify(self, modify_childs=1, ignore_license=0):
724
		self.exceptions=[]
713
		self.exceptions=[]
725
714
 Lines 744-750   class simpleLdap(base): Link Here 
744
		# iterate over all properties and call checkLdap() of corresponding syntax
733
		# iterate over all properties and call checkLdap() of corresponding syntax
745
		self._call_checkLdap_on_all_property_syntaxes()
734
		self._call_checkLdap_on_all_property_syntaxes()
746
735
747
#+++# MODLIST #+++#
736
		#+++# MODLIST #+++#
748
		ml=self._ldap_modlist()
737
		ml=self._ldap_modlist()
749
		# custom attributes
738
		# custom attributes
750
		m=univention.admin.modules.get(self.module)
739
		m=univention.admin.modules.get(self.module)
 Lines 781-787   class simpleLdap(base): Link Here 
781
							ml.remove(i)
770
							ml.remove(i)
782
						ml.extend( addlist )
771
						ml.extend( addlist )
783
772
784
785
					else:
773
					else:
786
						if deleteObjectClass == '1' and not self.info.has_key(pname):
774
						if deleteObjectClass == '1' and not self.info.has_key(pname):
787
							# value is empty, should delete objectClass and Values
775
							# value is empty, should delete objectClass and Values
 Lines 829-835   class simpleLdap(base): Link Here 
829
					ml.append( ('objectClass', self.oldattr.get('objectClass'), current_ocs+[prop.objClass]) )
817
					ml.append( ('objectClass', self.oldattr.get('objectClass'), current_ocs+[prop.objClass]) )
830
818
831
				else:
819
				else:
832
833
					if prop.syntax == 'boolean' and self.info.has_key(prop.name) and self.info[prop.name] == '0':
820
					if prop.syntax == 'boolean' and self.info.has_key(prop.name) and self.info[prop.name] == '0':
834
						# syntax is boolean and value == 0 ==> remove
821
						# syntax is boolean and value == 0 ==> remove
835
						dellist = []
822
						dellist = []
 Lines 1009-1016   class simpleLdap(base): Link Here 
1009
			self.policyObjects[policy_type]=univention.admin.objects.get(policy_module, None, self.lo, policy_position)
996
			self.policyObjects[policy_type]=univention.admin.objects.get(policy_module, None, self.lo, policy_position)
1010
			self.policyObjects[policy_type].copyIdentifier(self)
997
			self.policyObjects[policy_type].copyIdentifier(self)
1011
			self._init_ldap_search( self.policyObjects[ policy_type ] )
998
			self._init_ldap_search( self.policyObjects[ policy_type ] )
1012
		else:
1013
			pass
1014
999
1015
		return self.policyObjects[policy_type]
1000
		return self.policyObjects[policy_type]
1016
1001
 Lines 1122-1128   class simpleComputer( simpleLdap ): Link Here 
1122
		zoneName.reverse( )
1107
		zoneName.reverse( )
1123
		relativeDomainName = relativeDomainName.split( '.' )
1108
		relativeDomainName = relativeDomainName.split( '.' )
1124
		relativeDomainName.reverse( )
1109
		relativeDomainName.reverse( )
1125
		return '%s.%s' % ( string.join( zoneName, '.' ) , string.join( relativeDomainName, '.' ) )
1110
		return '.'.join(zoneName + relativeDomainName)
1126
1111
1127
	def __ip_from_ptr_ipv6( self, zoneName, relativeDomainName ):
1112
	def __ip_from_ptr_ipv6( self, zoneName, relativeDomainName ):
1128
		fullName = relativeDomainName + '.' + zoneName.replace('.ip6.arpa', '')
1113
		fullName = relativeDomainName + '.' + zoneName.replace('.ip6.arpa', '')
 Lines 1408-1420   class simpleComputer( simpleLdap ): Link Here 
1408
				object[ 'host' ] = object[ 'host' ].replace( old_name, new_name )
1393
				object[ 'host' ] = object[ 'host' ].replace( old_name, new_name )
1409
				object.modify( )
1394
				object.modify( )
1410
1395
1411
1412
	def __remove_from_dhcp_object( self, position = None, name = None, oldname = None, mac = None, ip = None ):
1396
	def __remove_from_dhcp_object( self, position = None, name = None, oldname = None, mac = None, ip = None ):
1413
		# if we got the mac addres, then we remove the object
1397
		# if we got the mac addres, then we remove the object
1414
		# if we only got the ip addres, we remove the ip address
1398
		# if we only got the ip addres, we remove the ip address
1415
1399
1416
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'we should remove a dhcp object: position="%s", name="%s", oldname="%s", mac="%s", ip="%s"' % ( position, name, oldname, mac, ip ) )
1400
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'we should remove a dhcp object: position="%s", name="%s", oldname="%s", mac="%s", ip="%s"' % ( position, name, oldname, mac, ip ) )
1417
		
1401
1418
		dn = None
1402
		dn = None
1419
1403
1420
		tmppos = univention.admin.uldap.position( self.position.getDomain( ) )
1404
		tmppos = univention.admin.uldap.position( self.position.getDomain( ) )
 Lines 1494-1504   class simpleComputer( simpleLdap ): Link Here 
1494
					for dn2, attributes2 in self.lo.search(scope='domain', attr=[ 'zoneName' ], filter='(&(relativeDomainName=%s)(objectClass=dNSZone))' %  name, unique=0 ):
1478
					for dn2, attributes2 in self.lo.search(scope='domain', attr=[ 'zoneName' ], filter='(&(relativeDomainName=%s)(objectClass=dNSZone))' %  name, unique=0 ):
1495
						self.lo.modify( dn, [('pTRRecord', '%s.%s.' % (name, attributes2['zoneName'][0]), '')] )
1479
						self.lo.modify( dn, [('pTRRecord', '%s.%s.' % (name, attributes2['zoneName'][0]), '')] )
1496
1480
1497
				zone = univention.admin.handlers.dns.reverse_zone.object( self.co, self.lo, self.position, zoneDN) 
1481
				zone = univention.admin.handlers.dns.reverse_zone.object( self.co, self.lo, self.position, zoneDN)
1498
				zone.open()
1482
				zone.open()
1499
				zone.modify()
1483
				zone.modify()
1500
1484
1501
1502
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'we should remove a dns reverse object: dnsEntryZoneReverse="%s", name="%s", ip="%s"' % ( dnsEntryZoneReverse, name, ip ) )
1485
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'we should remove a dns reverse object: dnsEntryZoneReverse="%s", name="%s", ip="%s"' % ( dnsEntryZoneReverse, name, ip ) )
1503
		if dnsEntryZoneReverse:
1486
		if dnsEntryZoneReverse:
1504
			rdn = self.calc_dns_reverse_entry_name( ip, dnsEntryZoneReverse )
1487
			rdn = self.calc_dns_reverse_entry_name( ip, dnsEntryZoneReverse )
 Lines 1519-1525   class simpleComputer( simpleLdap ): Link Here 
1519
						modify(rdn, zone)
1502
						modify(rdn, zone)
1520
					except univention.admin.uexceptions.noObject:
1503
					except univention.admin.uexceptions.noObject:
1521
						pass
1504
						pass
1522
			pass
1505
1523
	def __add_dns_reverse_object( self, name, zoneDn, ip ):
1506
	def __add_dns_reverse_object( self, name, zoneDn, ip ):
1524
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'we should create a dns reverse object: zoneDn="%s", name="%s", ip="%s"' % ( zoneDn, name, ip ) )
1507
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'we should create a dns reverse object: zoneDn="%s", name="%s", ip="%s"' % ( zoneDn, name, ip ) )
1525
		if name and zoneDn and ip:
1508
		if name and zoneDn and ip:
 Lines 1644-1651   class simpleComputer( simpleLdap ): Link Here 
1644
		for dn, attributes in self.lo.search(base=zoneDN, scope='domain', attr=['pTRRecord'], filter=search_filter):
1627
		for dn, attributes in self.lo.search(base=zoneDN, scope='domain', attr=['pTRRecord'], filter=search_filter):
1645
			self.lo.modify(dn, [('pTRRecord', '', ptrrecord)])
1628
			self.lo.modify(dn, [('pTRRecord', '', ptrrecord)])
1646
1629
1647
1648
1649
	def __remove_related_ptrrecords(self, zoneDN, ip):
1630
	def __remove_related_ptrrecords(self, zoneDN, ip):
1650
		ptrrecord = '%s.%s.' % (self.info['name'], zoneDN.split('=')[1].split(',')[0])
1631
		ptrrecord = '%s.%s.' % (self.info['name'], zoneDN.split('=')[1].split(',')[0])
1651
		ip_split = ip.split('.')
1632
		ip_split = ip.split('.')
 Lines 1655-1661   class simpleComputer( simpleLdap ): Link Here 
1655
		for dn, attributes in self.lo.search(base=zoneDN, scope='domain', attr=['pTRRecord'], filter=search_filter):
1636
		for dn, attributes in self.lo.search(base=zoneDN, scope='domain', attr=['pTRRecord'], filter=search_filter):
1656
			if ptrrecord in attributes['pTRRecord']:
1637
			if ptrrecord in attributes['pTRRecord']:
1657
				self.lo.modify(dn, [('pTRRecord', ptrrecord, '')])
1638
				self.lo.modify(dn, [('pTRRecord', ptrrecord, '')])
1658
		
1659
1639
1660
	def check_common_name_length(self):
1640
	def check_common_name_length(self):
1661
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'check_common_name_length with self["ip"] = %r and self["dnsEntryZoneForward"] = %r' % (self['ip'], self['dnsEntryZoneForward'], ))
1641
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'check_common_name_length with self["ip"] = %r and self["dnsEntryZoneForward"] = %r' % (self['ip'], self['dnsEntryZoneForward'], ))
 Lines 1779-1785   class simpleComputer( simpleLdap ): Link Here 
1779
					else:
1759
					else:
1780
						self.lo.modify( dn, [ ( 'aRecord', '' ,  ip ) ] )
1760
						self.lo.modify( dn, [ ( 'aRecord', '' ,  ip ) ] )
1781
1761
1782
1783
	def __add_dns_alias_object( self, name, dnsForwardZone, dnsAliasZoneContainer, alias ):
1762
	def __add_dns_alias_object( self, name, dnsForwardZone, dnsAliasZoneContainer, alias ):
1784
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'add a dns alias object: name="%s", dnsForwardZone="%s", dnsAliasZoneContainer="%s", alias="%s"' % ( name, dnsForwardZone, dnsAliasZoneContainer, alias ) )
1763
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'add a dns alias object: name="%s", dnsForwardZone="%s", dnsAliasZoneContainer="%s", alias="%s"' % ( name, dnsForwardZone, dnsAliasZoneContainer, alias ) )
1785
		if name and dnsForwardZone and dnsAliasZoneContainer and alias:
1764
		if name and dnsForwardZone and dnsAliasZoneContainer and alias:
 Lines 1798-1804   class simpleComputer( simpleLdap ): Link Here 
1798
			else:
1777
			else:
1799
				# thow exeption, cNAMERecord is single value
1778
				# thow exeption, cNAMERecord is single value
1800
				raise univention.admin.uexceptions.dnsAliasAlreadyUsed, _('DNS alias is already in use.')
1779
				raise univention.admin.uexceptions.dnsAliasAlreadyUsed, _('DNS alias is already in use.')
1801
		pass
1802
1780
1803
	def __remove_dns_alias_object( self, name, dnsForwardZone, dnsAliasZoneContainer, alias = None ):
1781
	def __remove_dns_alias_object( self, name, dnsForwardZone, dnsAliasZoneContainer, alias = None ):
1804
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'remove a dns alias object: name="%s", dnsForwardZone="%s", dnsAliasZoneContainer="%s", alias="%s"' % ( name, dnsForwardZone, dnsAliasZoneContainer, alias ) )
1782
		univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'remove a dns alias object: name="%s", dnsForwardZone="%s", dnsAliasZoneContainer="%s", alias="%s"' % ( name, dnsForwardZone, dnsAliasZoneContainer, alias ) )
 Lines 1845-1853   class simpleComputer( simpleLdap ): Link Here 
1845
					pass
1823
					pass
1846
1824
1847
	def _ldap_post_modify( self ):
1825
	def _ldap_post_modify( self ):
1848
1826
		self.__multiip |= len(self['mac']) > 1 or len(self['ip']) > 1
1849
		if len ( self[ 'mac' ] ) > 1 or len( self[ 'ip' ] ) > 1:
1850
			self.__multiip = True
1851
1827
1852
		for entry in self.__changes[ 'dhcpEntryZone' ][ 'remove' ]:
1828
		for entry in self.__changes[ 'dhcpEntryZone' ][ 'remove' ]:
1853
			univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'simpleComputer: dhcp check: removed: %s' % entry )
1829
			univention.debug.debug( univention.debug.ADMIN, univention.debug.INFO, 'simpleComputer: dhcp check: removed: %s' % entry )
 Lines 1900-1906   class simpleComputer( simpleLdap ): Link Here 
1900
			else:
1876
			else:
1901
				self.__add_dns_reverse_object( self[ 'name' ], dn, ip )
1877
				self.__add_dns_reverse_object( self[ 'name' ], dn, ip )
1902
1878
1903
1904
		for entry in self.__changes[ 'dnsEntryZoneAlias' ][ 'remove' ]:
1879
		for entry in self.__changes[ 'dnsEntryZoneAlias' ][ 'remove' ]:
1905
			dnsForwardZone, dnsAliasZoneContainer, alias = entry
1880
			dnsForwardZone, dnsAliasZoneContainer, alias = entry
1906
			if not alias:
1881
			if not alias:
 Lines 1963-1969   class simpleComputer( simpleLdap ): Link Here 
1963
			self.__update_groups_after_namechange()
1938
			self.__update_groups_after_namechange()
1964
			self.__rename_dhcp_object( position = None, old_name = self.__changes[ 'name' ][ 0 ], new_name = self.__changes[ 'name' ][ 1 ] )
1939
			self.__rename_dhcp_object( position = None, old_name = self.__changes[ 'name' ][ 0 ], new_name = self.__changes[ 'name' ][ 1 ] )
1965
			self.__rename_dns_object( position = None, old_name = self.__changes[ 'name' ][ 0 ], new_name = self.__changes[ 'name' ][ 1 ] )
1940
			self.__rename_dns_object( position = None, old_name = self.__changes[ 'name' ][ 0 ], new_name = self.__changes[ 'name' ][ 1 ] )
1966
			pass
1967
1941
1968
		if self.ipRequest == 1 and self[ 'ip' ]:
1942
		if self.ipRequest == 1 and self[ 'ip' ]:
1969
			for ipAddress in self[ 'ip' ]:
1943
			for ipAddress in self[ 'ip' ]:
 Lines 1981-1997   class simpleComputer( simpleLdap ): Link Here 
1981
1955
1982
	def __remove_associated_domain( self, entry ):
1956
	def __remove_associated_domain( self, entry ):
1983
		dn, ip = self.__split_dns_line( entry )
1957
		dn, ip = self.__split_dns_line( entry )
1984
		domain = string.join(ldap.explode_rdn(dn)[0].split('=')[1:], '=')
1958
		domain = ldap.explode_rdn(dn)[0].split('=', 1)[1]
1985
		if self.info.get('domain', None) == domain:
1959
		if self.info.get('domain', None) == domain:
1986
			self.info['domain'] = None
1960
			self.info['domain'] = None
1987
1961
1988
	def __set_associated_domain( self, entry ):
1962
	def __set_associated_domain( self, entry ):
1989
		dn, ip = self.__split_dns_line( entry )
1963
		dn, ip = self.__split_dns_line( entry )
1990
		domain = string.join(ldap.explode_rdn(dn)[0].split('=')[1:], '=')
1964
		domain = ldap.explode_rdn(dn)[0].split('=', 1)[1]
1991
		if not self.info.get('domain', None):
1965
		if not self.info.get('domain', None):
1992
			self.info['domain'] = domain
1966
			self.info['domain'] = domain
1993
1967
1994
1995
	def _ldap_modlist( self ):
1968
	def _ldap_modlist( self ):
1996
		self.__changes =  {	'mac': {'remove': [ ], 'add': [ ]}, 'ip': {'remove': [ ], 'add': [ ]}, 'name': None,
1969
		self.__changes =  {	'mac': {'remove': [ ], 'add': [ ]}, 'ip': {'remove': [ ], 'add': [ ]}, 'name': None,
1997
							'dnsEntryZoneForward': { 'remove': [ ], 'add': [ ] },
1970
							'dnsEntryZoneForward': { 'remove': [ ], 'add': [ ] },
 Lines 2029-2041   class simpleComputer( simpleLdap ): Link Here 
2029
		newAaaaRecord = []
2002
		newAaaaRecord = []
2030
		if oldAddresses != newAddresses:
2003
		if oldAddresses != newAddresses:
2031
			if oldAddresses:
2004
			if oldAddresses:
2032
			    for address in oldAddresses:
2005
				for address in oldAddresses:
2033
					if ':' in address: # IPv6
2006
					if ':' in address: # IPv6
2034
						oldAaaaRecord.append(address)
2007
						oldAaaaRecord.append(address)
2035
					else:
2008
					else:
2036
						oldARecord.append(address)
2009
						oldARecord.append(address)
2037
			if newAddresses:
2010
			if newAddresses:
2038
			    for address in newAddresses:
2011
				for address in newAddresses:
2039
					if ':' in address: # IPv6
2012
					if ':' in address: # IPv6
2040
						newAaaaRecord.append(ipaddr.IPv6Address(address).exploded)
2013
						newAaaaRecord.append(ipaddr.IPv6Address(address).exploded)
2041
					else:
2014
					else:
 Lines 2075-2093   class simpleComputer( simpleLdap ): Link Here 
2075
						continue
2048
						continue
2076
					self.__changes[ 'ip' ][ 'remove' ].append( ipAddress )
2049
					self.__changes[ 'ip' ][ 'remove' ].append( ipAddress )
2077
2050
2078
2079
		if self.hasChanged( 'name' ):
2051
		if self.hasChanged( 'name' ):
2080
			ml.append( ( 'sn', self.oldattr.get( 'sn', [ None ] )[ 0 ], self[ 'name' ] ) )
2052
			ml.append( ( 'sn', self.oldattr.get( 'sn', [ None ] )[ 0 ], self[ 'name' ] ) )
2081
			self.__changes[ 'name' ] = ( self.oldattr.get( 'sn', [ None ] )[ 0 ], self[ 'name' ] )
2053
			self.__changes[ 'name' ] = ( self.oldattr.get( 'sn', [ None ] )[ 0 ], self[ 'name' ] )
2082
2054
2083
		if self.hasChanged('ip') or self.hasChanged('mac'):
2055
		if self.hasChanged('ip') or self.hasChanged('mac'):
2084
2085
			if len(self.info.get('ip', [])) == 1 and len(self.info.get('mac', [])) == 1 and len(self.info.get('dhcpEntryZone', [])):
2056
			if len(self.info.get('ip', [])) == 1 and len(self.info.get('mac', [])) == 1 and len(self.info.get('dhcpEntryZone', [])):
2086
				# In this special case, we assume the mapping between ip/mac address to be
2057
				# In this special case, we assume the mapping between ip/mac address to be
2087
				# unique. The dhcp entry needs to contain the mac address (as sepcified by
2058
				# unique. The dhcp entry needs to contain the mac address (as sepcified by
2088
				# the ldap search for dhcp entries), the ip address may not correspond to 
2059
				# the ldap search for dhcp entries), the ip address may not correspond to
2089
				# the ip address associated with the computer ldap object, but this would 
2060
				# the ip address associated with the computer ldap object, but this would
2090
				# be erroneous anyway. We therefore update the dhcp entry to correspond to 
2061
				# be erroneous anyway. We therefore update the dhcp entry to correspond to
2091
				# the current ip and mac address. (Bug #20315)
2062
				# the current ip and mac address. (Bug #20315)
2092
				dn, ip, mac = self.__split_dhcp_line( self.info['dhcpEntryZone'][0] )
2063
				dn, ip, mac = self.__split_dhcp_line( self.info['dhcpEntryZone'][0] )
2093
2064
 Lines 2171-2182   class simpleComputer( simpleLdap ): Link Here 
2171
				else:
2142
				else:
2172
					raise univention.admin.uexceptions.invalidDNSAliasEntry, _('The DNS alias entry for this host should contain the zone name, the alias zone container LDAP-DN and the alias.')
2143
					raise univention.admin.uexceptions.invalidDNSAliasEntry, _('The DNS alias entry for this host should contain the zone name, the alias zone container LDAP-DN and the alias.')
2173
2144
2174
		if len ( self[ 'mac' ] ) < 2 and len( self[ 'ip' ] ) < 2:
2145
		self.__multiip = len(self['mac']) > 1 or len(self['ip']) > 1
2175
			self.__multiip = False
2176
		else:
2177
			self.__multiip = True
2178
2146
2179
		ml = ml + super( simpleComputer, self )._ldap_modlist( )
2147
		ml += super(simpleComputer, self)._ldap_modlist()
2180
2148
2181
		return ml
2149
		return ml
2182
2150
 Lines 2191-2196   class simpleComputer( simpleLdap ): Link Here 
2191
			subnet=ldap.explode_dn(reverseDN, 1)[0].replace('.in-addr.arpa','').split('.')
2159
			subnet=ldap.explode_dn(reverseDN, 1)[0].replace('.in-addr.arpa','').split('.')
2192
			ip=sip.split('.')
2160
			ip=sip.split('.')
2193
			return self.calc_dns_reverse_entry_name_do(4, subnet, ip)
2161
			return self.calc_dns_reverse_entry_name_do(4, subnet, ip)
2162
2194
	def calc_dns_reverse_entry_name_do(self, maxLength, zoneNet, ip):
2163
	def calc_dns_reverse_entry_name_do(self, maxLength, zoneNet, ip):
2195
		zoneNet.reverse()
2164
		zoneNet.reverse()
2196
		if not ip[:len(zoneNet)] == zoneNet:
2165
		if not ip[:len(zoneNet)] == zoneNet:
 Lines 2222-2228   class simpleComputer( simpleLdap ): Link Here 
2222
			else:
2191
			else:
2223
				self.__modify_dhcp_object( dn, self[ 'name' ], ip, mac )
2192
				self.__modify_dhcp_object( dn, self[ 'name' ], ip, mac )
2224
2193
2225
2226
		for entry in self.__changes[ 'dnsEntryZoneForward' ][ 'remove' ]:
2194
		for entry in self.__changes[ 'dnsEntryZoneForward' ][ 'remove' ]:
2227
			dn, ip = self.__split_dns_line( entry )
2195
			dn, ip = self.__split_dns_line( entry )
2228
			if not ip and not self.__multiip:
2196
			if not ip and not self.__multiip:
 Lines 2314-2320   class simpleComputer( simpleLdap ): Link Here 
2314
			groupObject = univention.admin.objects.get(univention.admin.modules.get('groups/group'), self.co, self.lo, self.position, group)
2282
			groupObject = univention.admin.objects.get(univention.admin.modules.get('groups/group'), self.co, self.lo, self.position, group)
2315
			groupObject.fast_member_remove( [ self.dn ], self.oldattr.get('uid',[]), ignore_license=1 )
2283
			groupObject.fast_member_remove( [ self.dn ], self.oldattr.get('uid',[]), ignore_license=1 )
2316
2284
2317
2318
	def __update_groups_after_namechange(self):
2285
	def __update_groups_after_namechange(self):
2319
		oldname = self.oldinfo.get('name')
2286
		oldname = self.oldinfo.get('name')
2320
		newname = self.info.get('name')
2287
		newname = self.info.get('name')
 Lines 2356-2362   class simpleComputer( simpleLdap ): Link Here 
2356
2323
2357
			self.lo.modify(group, [('uniqueMember', oldUniqueMembers, newUniqueMembers), ('memberUid', oldMemberUids, newMemberUids)])
2324
			self.lo.modify(group, [('uniqueMember', oldUniqueMembers, newUniqueMembers), ('memberUid', oldMemberUids, newMemberUids)])
2358
2325
2359
2360
	def update_groups(self):
2326
	def update_groups(self):
2361
		if not self.hasChanged('groups') and \
2327
		if not self.hasChanged('groups') and \
2362
			   not ('oldPrimaryGroupDn' in self.__dict__ and self.oldPrimaryGroupDn) and \
2328
			   not ('oldPrimaryGroupDn' in self.__dict__ and self.oldPrimaryGroupDn) and \
 Lines 2400-2406   class simpleComputer( simpleLdap ): Link Here 
2400
				groupObject['hosts'].remove(self.dn)
2366
				groupObject['hosts'].remove(self.dn)
2401
				groupObject.modify(ignore_license=1)
2367
				groupObject.modify(ignore_license=1)
2402
2368
2403
2404
	def primary_group(self):
2369
	def primary_group(self):
2405
		if not self.hasChanged('primaryGroup'):
2370
		if not self.hasChanged('primaryGroup'):
2406
			return
2371
			return
 Lines 2545-2553   class simpleComputer( simpleLdap ): Link Here 
2545
							self.__saved_dhcp_entry = network_object['dhcpEntryZone']
2510
							self.__saved_dhcp_entry = network_object['dhcpEntryZone']
2546
2511
2547
					self.old_network=value
2512
					self.old_network=value
2548
				else:
2549
					pass
2550
2551
2513
2552
		elif key == 'ip':
2514
		elif key == 'ip':
2553
			self.ip_freshly_set = True
2515
			self.ip_freshly_set = True
 Lines 2581-2588   class simpleComputer( simpleLdap ): Link Here 
2581
		if raise_after:
2543
		if raise_after:
2582
			raise raise_after
2544
			raise raise_after
2583
2545
2584
class simpleLdapSub(simpleLdap):
2585
2546
2547
class simpleLdapSub(simpleLdap):
2586
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
2548
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
2587
		base.__init__(self, co, lo, position, dn, superordinate )
2549
		base.__init__(self, co, lo, position, dn, superordinate )
2588
2550
 Lines 2601-2609   class simpleLdapSub(simpleLdap): Link Here 
2601
		if hasattr(self,"_ldap_post_remove"):
2563
		if hasattr(self,"_ldap_post_remove"):
2602
			self._ldap_post_remove()
2564
			self._ldap_post_remove()
2603
2565
2566
2604
class simplePolicy(simpleLdap):
2567
class simplePolicy(simpleLdap):
2605
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
2568
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
2606
2607
		self.resultmode=0
2569
		self.resultmode=0
2608
		self.dn=dn
2570
		self.dn=dn
2609
2571
 Lines 2786-2792   class simplePolicy(simpleLdap): Link Here 
2786
		self.policy_result()
2748
		self.policy_result()
2787
2749
2788
		if self.polinfo.has_key(key):
2750
		if self.polinfo.has_key(key):
2789
2790
			if self.polinfo[key] != newvalue or self.polinfo_more[key]['policy'] == self.cloned or ( self.info.has_key( key ) and self.info[ key ] != newvalue ):
2751
			if self.polinfo[key] != newvalue or self.polinfo_more[key]['policy'] == self.cloned or ( self.info.has_key( key ) and self.info[ key ] != newvalue ):
2791
				if self.polinfo_more[key]['fixed'] and self.polinfo_more[key]['policy'] != self.cloned:
2752
				if self.polinfo_more[key]['fixed'] and self.polinfo_more[key]['policy'] != self.cloned:
2792
					raise univention.admin.uexceptions.policyFixedAttribute, key
2753
					raise univention.admin.uexceptions.policyFixedAttribute, key
 Lines 2795-2803   class simplePolicy(simpleLdap): Link Here 
2795
				if self.hasChanged(key):
2756
				if self.hasChanged(key):
2796
					univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'polinfo: key:%s hasChanged' % (key) )
2757
					univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'polinfo: key:%s hasChanged' % (key) )
2797
					self.changes=1
2758
					self.changes=1
2798
				return
2759
			return
2799
			else:
2800
				return
2801
2760
2802
		# this object did not exist before
2761
		# this object did not exist before
2803
		if not self.oldinfo:
2762
		if not self.oldinfo:
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/__common.py (-34 / +94 lines)
 Lines 30-84    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
import copy
33
import sys
34
35
import univention.admin.localization
34
import univention.admin.localization
36
from univention.admin.layout import Tab, Group
35
from univention.admin.layout import Tab
36
from univention.admin.handlers import simpleLdap
37
37
38
translation = univention.admin.localization.translation( 'univention.admin.handlers.dhcp' )
38
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
39
_ = translation.translate
39
_ = translation.translate
40
40
41
42
_options = {
43
	'options': univention.admin.option(
44
		short_description=_('Allow custom DHCP options'),
45
		long_description=_("Allow adding custom DHCP options. Experts only!"),
46
		default=False,
47
		editable=True,
48
		objectClasses=['dhcpOptions'],
49
	),
50
}
51
52
41
_properties = {
53
_properties = {
42
	'option': univention.admin.property(
54
	'option': univention.admin.property(
43
		short_description = _( 'DHCP options' ),
55
		short_description=_('DHCP options'),
44
		long_description = _( 'Defines DHCP options for the subnet.' ),
56
		long_description=_('Defines additional DHCP options.'),
45
		syntax = univention.admin.syntax.string,
57
		syntax=univention.admin.syntax.string,
46
		multivalue = True,
58
		multivalue=True,
47
		options = [],
59
		options=["options"],
48
		required = 0,
60
		required=False,
49
		may_change = True,
61
		may_change=True,
50
		identifies = 0
62
		identifies=False,
51
		),
63
	),
52
}
64
}
53
65
54
# def optionMap( value ):
55
# 	return map( lambda x: ' '.join( x ), value )
56
66
57
# def optionUnmap( value ):
67
def rangeMap(value):
58
# 	return map( lambda x: x.split( ' ', 1 ), value )
68
	return map(lambda x: ' '.join(x), value)
69
70
71
def rangeUnmap(value):
72
	return map(lambda x: x.split(), value)
73
59
74
60
_mappings = (
75
_mappings = (
61
	# ( 'option', 'dhcpOption', optionMap, optionUnmap ),
76
	('option', 'dhcpOption', None, None),
62
	( 'option', 'dhcpOption', None, univention.admin.mapping.ListToString ),
77
)
63
	)
78
64
79
65
def add_dhcp_options( properties, mapping, layout ):
80
def add_dhcp_options(module_name):
66
	global _properties, _mappings
81
	module = sys.modules[module_name]
67
82
68
	for name, prop in _properties.items():
83
	options = getattr(module, "options")
69
		properties[ name ] = prop
84
	options.update(_options)
70
85
86
	properties = getattr(module, "property_descriptions")
87
	properties.update(_properties)
88
89
	mapping = getattr(module, "mapping")
71
	for item in _mappings:
90
	for item in _mappings:
72
		mapping.register( *item )
91
		mapping.register(*item)
92
93
	layout = getattr(module, "layout")
94
	layout.append(Tab(
95
		_('DHCP options'),
96
		_('Custom DHCP options'),
97
		advanced=True,
98
		layout=['option']
99
	))
100
101
102
class SimpleDhcp(simpleLdap):
103
	@classmethod
104
	def lookup(cls, co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
105
		filter_str = unicode(cls.lookup_filter(filter_s))
106
		res = [
107
			cls(co, lo, None, dn=dn, superordinate=superordinate, attributes=attrs)
108
			for dn, attrs in lo.search(filter_str, base, scope, [], unique, required, timeout, sizelimit)
109
		]
110
		return res
111
112
113
class DhcpOptions(SimpleDhcp):
114
	def setup_options(self, options):
115
		self.options = []
116
		self._define_options(options)
117
118
	def open(self):
119
		super(DhcpOptions, self).open()
120
		try:
121
			ocs = self.oldattr['objectClass']
122
			if "dhcpOptions" in ocs:
123
				self.options.append("options")
124
		except LookupError:
125
			pass
126
		self.old_options = list(self.options)
127
128
	def _ldap_modlist(self):
129
		if "options" not in self.options:
130
			del self.info.get('option', [])[:]
73
131
74
	# currently not visible
132
		mod_list = super(DhcpOptions, self)._ldap_modlist()
75
	#layout.append( Tab( _( 'Advanced' ), _( 'Advanced DHCP options' ), layout = [ 'option' ] ) )
76
133
77
def add_dhcp_objectclass( self, ml ):
134
		old_ocs = self.oldattr.get('objectClass', [])
78
	oldOCs = self.oldattr.get( 'objectClass', [] )
135
		if self.info.get('option', []):
79
	newOCs = copy.copy( oldOCs )
136
			if 'dhcpOptions' not in old_ocs:
80
	if self.info.get( 'option', [] ) and not 'dhcpOptions' in oldOCs:
137
				new_ocs = old_ocs + ['dhcpOptions']
81
		newOCs.append( 'dhcpOptions' )
138
				mod_list.append(('objectClass', old_ocs, new_ocs))
82
		ml.append( ( 'objectClass', oldOCs, newOCs ) )
139
		elif "options" not in self.options and 'dhcpOptions' in old_ocs:
140
			new_ocs = list(old_ocs)
141
			new_ocs.remove("dhcpOptions")
142
			mod_list.append(('objectClass', old_ocs, new_ocs))
83
143
84
	return ml
144
		return mod_list
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/dhcp.py (-55 / +64 lines)
 Lines 44-121   import univention.admin.handlers.dhcp.sharedsubnet Link Here 
44
import univention.admin.handlers.dhcp.subnet
44
import univention.admin.handlers.dhcp.subnet
45
45
46
46
47
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
47
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
48
_=translation.translate
48
_ = translation.translate
49
49
50
50
51
module='dhcp/dhcp'
51
module = 'dhcp/dhcp'
52
52
53
childs=0
53
childs = 0
54
short_description=_('DHCP')
54
short_description = _('DHCP')
55
long_description=''
55
long_description = ''
56
operations=['search']
56
operations = ['search']
57
usewizard=1
57
usewizard = 1
58
wizardmenustring=_("DHCP")
58
wizardmenustring = _("DHCP")
59
wizarddescription=_("Add, edit and delete DHCP objects")
59
wizarddescription = _("Add, edit and delete DHCP objects")
60
wizardoperations={"add":[_("Add"), _("Add DHCP object")],"find":[_("Search"), _("Search DHCP object(s)")]}
60
wizardoperations = {
61
wizardpath="univentionDhcpObject"
61
	"add": [_("Add"), _("Add DHCP object")],
62
wizardsuperordinates = ( 'None', 'dhcp/service', 'dhcp/shared' )
62
	"find": [_("Search"), _("Search DHCP object(s)")],
63
}
64
wizardpath = "univentionDhcpObject"
65
wizardsuperordinates = ('None', 'dhcp/service', 'dhcp/shared')
63
wizardtypesforsuper = {
66
wizardtypesforsuper = {
64
	'None' : ( 'dhcp/service', ),
67
	'None': ('dhcp/service',),
65
	'dhcp/service' : ( 'dhcp/host', 'dhcp/server', 'dhcp/shared', 'dhcp/subnet' ),
68
	'dhcp/service': ('dhcp/host', 'dhcp/server', 'dhcp/shared', 'dhcp/subnet'),
66
	'dhcp/shared' : ( 'dhcp/sharedsubnet', )
69
	'dhcp/shared': ('dhcp/sharedsubnet',)
67
	}
70
}
68
71
69
childmodules=["dhcp/host","dhcp/pool","dhcp/server","dhcp/service","dhcp/shared","dhcp/sharedsubnet","dhcp/subnet"]
72
childmodules = [
70
virtual=1
73
	"dhcp/host",
71
options={
74
	"dhcp/pool",
75
	"dhcp/server",
76
	"dhcp/service",
77
	"dhcp/shared",
78
	"dhcp/sharedsubnet",
79
	"dhcp/subnet",
80
]
81
virtual = 1
82
83
options = {
72
}
84
}
73
property_descriptions={
85
86
property_descriptions = {
74
	'name': univention.admin.property(
87
	'name': univention.admin.property(
75
			short_description=_('Name'),
88
		short_description=_('Name'),
76
			long_description='',
89
		long_description='',
77
			syntax=univention.admin.syntax.string,
90
		syntax=univention.admin.syntax.string,
78
			multivalue=0,
91
		multivalue=False,
79
			include_in_default_search=1,
92
		include_in_default_search=True,
80
			options=[],
93
		options=[],
81
			required=1,
94
		required=True,
82
			may_change=1,
95
		may_change=True,
83
			identifies=1
96
		identifies=True
84
		)
97
	)
85
}
98
}
86
99
87
layout = [ Tab( _( 'General' ), _( 'Basic settings' ), layout = [ "name" ] ) ]
100
layout = [Tab(_('General'), _('Basic settings'), layout=["name"])]
88
101
89
mapping=univention.admin.mapping.mapping()
102
mapping = univention.admin.mapping.mapping()
90
103
91
104
92
class object(univention.admin.handlers.simpleLdap):
105
class object(univention.admin.handlers.simpleLdap):
93
	module=module
106
	module = module
94
107
95
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
108
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
96
		global mapping
109
		self.mapping = mapping
97
		global property_descriptions
110
		self.descriptions = property_descriptions
98
111
99
		self.mapping=mapping
112
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
100
		self.descriptions=property_descriptions
101
102
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
103
113
104
114
105
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
115
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
106
	ret=[]
116
	ret = []
107
	if superordinate:
117
	if superordinate:
108
		ret+=  univention.admin.handlers.dhcp.host.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
118
		ret += univention.admin.handlers.dhcp.host.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
109
		ret+= univention.admin.handlers.dhcp.pool.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
119
		ret += univention.admin.handlers.dhcp.pool.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
110
		ret+=univention.admin.handlers.dhcp.server.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
120
		ret += univention.admin.handlers.dhcp.server.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
111
		ret+= univention.admin.handlers.dhcp.shared.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
121
		ret += univention.admin.handlers.dhcp.shared.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
112
		ret+= univention.admin.handlers.dhcp.sharedsubnet.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
122
		ret += univention.admin.handlers.dhcp.sharedsubnet.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
113
		ret+= univention.admin.handlers.dhcp.subnet.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
123
		ret += univention.admin.handlers.dhcp.subnet.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
114
	else:
124
	else:
115
		ret+= univention.admin.handlers.dhcp.service.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
125
		ret += univention.admin.handlers.dhcp.service.lookup(co, lo, filter_s, base, superordinate, scope, unique, required, timeout, sizelimit)
116
	return ret
126
	return ret
117
127
128
118
def identify(dn, attr, canonical=0):
129
def identify(dn, attr, canonical=0):
119
	pass
130
	pass
120
121
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/host.py (-75 / +85 lines)
 Lines 34-160   from univention.admin.layout import Tab, Group Link Here 
34
import univention.admin.filter
34
import univention.admin.filter
35
import univention.admin.handlers
35
import univention.admin.handlers
36
import univention.admin.localization
36
import univention.admin.localization
37
import univention.debug
37
import univention.debug as ud
38
38
39
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
39
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
40
_=translation.translate
40
_ = translation.translate
41
41
42
module='dhcp/host'
42
module = 'dhcp/host'
43
operations=['add','edit','remove','search']
43
operations = ['add', 'edit', 'remove', 'search']
44
superordinate='dhcp/service'
44
superordinate = 'dhcp/service'
45
childs=0
45
childs = 0
46
usewizard=1
46
usewizard = 1
47
short_description=_('DHCP: Host')
47
short_description = _('DHCP: Host')
48
long_description=''
48
long_description = ''
49
options={
49
50
options = {
50
}
51
}
51
property_descriptions={
52
53
property_descriptions = {
52
	'host':  univention.admin.property(
54
	'host':  univention.admin.property(
53
			short_description=_('Hostname'),
55
		short_description=_('Hostname'),
54
			long_description='',
56
		long_description='',
55
			syntax=univention.admin.syntax.string,
57
		syntax=univention.admin.syntax.string,
56
			multivalue=0,
58
		multivalue=False,
57
			include_in_default_search=1,
59
		include_in_default_search=True,
58
			options=[],
60
		options=[],
59
			required=1,
61
		required=True,
60
			may_change=1,
62
		may_change=True,
61
			identifies=1
63
		identifies=True
62
		),
64
	),
63
	'hwaddress': univention.admin.property(
65
	'hwaddress': univention.admin.property(
64
			short_description=_('Hardware address'),
66
		short_description=_('Hardware address'),
65
			long_description=_('Currently, only the ethernet and token-ring types are recognized. \
67
		long_description=_(
66
The hardware-address should be a set of hexadecimal octets (numbers from 0 through ff) separated by colons.'),
68
			'Currently, only the ethernet and token-ring types are recognized.'
67
			syntax=univention.admin.syntax.DHCP_HardwareAddress,
69
			'The hardware-address should be a set of hexadecimal octets (numbers from 0 through ff) separated by colons.'),
68
			multivalue=0,
70
		syntax=univention.admin.syntax.DHCP_HardwareAddress,
69
			options=[],
71
		multivalue=False,
70
			required=1,
72
		options=[],
71
			may_change=1,
73
		required=True,
72
			identifies=0
74
		may_change=True,
73
		),
75
		identifies=False
76
	),
74
	'fixedaddress': univention.admin.property(
77
	'fixedaddress': univention.admin.property(
75
			short_description=_('Fixed IP addresses'),
78
		short_description=_('Fixed IP addresses'),
76
			long_description=_('Assign one or more fixed IP addresses. \
79
		long_description=_(
77
Each address should be either an IP address or a domain name that resolves to one or more IP addresses'),
80
			'Assign one or more fixed IP addresses.'
78
			syntax=univention.admin.syntax.string,
81
			'Each address should be either an IP address or a domain name that resolves to one or more IP addresses'),
79
			multivalue=1,
82
		syntax=univention.admin.syntax.string,
80
			options=[],
83
		multivalue=True,
81
			required=0,
84
		options=[],
82
			may_change=1,
85
		required=False,
83
			identifies=0
86
		may_change=True,
84
		),
87
		identifies=False
88
	),
85
}
89
}
86
layout=[
90
87
	Tab( _('General'), _('Basic settings'), layout = [
91
layout = [
88
		Group( _( 'General' ), layout = [
92
	Tab(_('General'), _('Basic settings'), layout=[
93
		Group(_('General'), layout=[
89
			'host',
94
			'host',
90
			'hwaddress',
95
			'hwaddress',
91
			'fixedaddress'
96
			'fixedaddress'
92
		] ),
97
		]),
93
	] )
98
	])
94
]
99
]
95
100
101
96
def unmapHWAddress(old):
102
def unmapHWAddress(old):
97
	univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'host.py: unmapHWAddress: old: %s' % old)
103
	ud.debug(ud.ADMIN, ud.INFO, 'host.py: unmapHWAddress: old: %s' % old)
98
	if not old:
104
	if not old:
99
		return ['', '']
105
		return ['', '']
100
	return old[0].split(' ')
106
	return old[0].split(' ')
101
107
108
102
def mapHWAddress(old):
109
def mapHWAddress(old):
103
	univention.debug.debug(univention.debug.ADMIN, univention.debug.INFO, 'host.py: mapHWAddress: old: %s' % old)
110
	ud.debug(ud.ADMIN, ud.INFO, 'host.py: mapHWAddress: old: %s' % old)
104
	if not old[0]:
111
	if not old[0]:
105
		return ''
112
		return ''
106
	else:
113
	else:
107
		if len (old) > 1:
114
		if len(old) > 1:
108
			return '%s %s' % (old[0], old[1])
115
			return '%s %s' % (old[0], old[1])
109
		else:
116
		else:
110
			return old
117
			return old
111
118
112
mapping=univention.admin.mapping.mapping()
119
120
mapping = univention.admin.mapping.mapping()
113
mapping.register('host', 'cn', None, univention.admin.mapping.ListToString)
121
mapping.register('host', 'cn', None, univention.admin.mapping.ListToString)
114
mapping.register('hwaddress', 'dhcpHWAddress', mapHWAddress, unmapHWAddress)
122
mapping.register('hwaddress', 'dhcpHWAddress', mapHWAddress, unmapHWAddress)
115
mapping.register('fixedaddress', 'univentionDhcpFixedAddress')
123
mapping.register('fixedaddress', 'univentionDhcpFixedAddress')
116
124
117
class object(univention.admin.handlers.simpleLdap):
125
from .__common import add_dhcp_options, DhcpOptions
118
	module=module
126
add_dhcp_options(__name__)
119
127
120
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
121
		global mapping
122
		global property_descriptions
123
128
124
		self.mapping=mapping
129
class object(DhcpOptions):
125
		self.descriptions=property_descriptions
130
	module = module
131
132
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
133
		self.mapping = mapping
134
		self.descriptions = property_descriptions
126
135
127
		if not superordinate:
136
		if not superordinate:
128
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
137
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
129
		if not dn and not position:
138
		if not dn and not position:
130
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
139
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
131
140
132
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
141
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
142
		self.setup_options(options)
133
143
134
	def _ldap_pre_create(self):
144
	def _ldap_pre_create(self):
135
		self.dn='%s=%s,%s' % (mapping.mapName('host'), mapping.mapValue('host', self.info['host']), self.position.getDn())
145
		self.dn = '%s=%s,%s' % (
146
			mapping.mapName('host'),
147
			mapping.mapValue('host', self.info['host']),
148
			self.position.getDn()
149
		)
136
150
137
	def _ldap_addlist(self):
151
	def _ldap_addlist(self):
138
		return [
152
		return [
139
			('objectClass', ['top', 'univentionDhcpHost']),
153
			('objectClass', ['top', 'univentionDhcpHost']),
140
		]
154
		]
141
155
142
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
156
	@staticmethod
157
	def lookup_filter(filter_s=None, lo=None):
158
		filter_obj = univention.admin.filter.conjunction('&', [
159
			univention.admin.filter.expression('objectClass', 'univentionDhcpHost')
160
		])
161
		filter_obj.append_unmapped_filter_string(filter_s, univention.admin.mapping.mapRewrite, mapping)
162
		return filter_obj
143
163
144
	filter=univention.admin.filter.conjunction('&', [
145
	univention.admin.filter.expression('objectClass', 'univentionDhcpHost')
146
	])
147
164
148
	if filter_s:
165
lookup_filter = object.lookup_filter
149
		filter_p=univention.admin.filter.parse(filter_s)
166
lookup = object.lookup
150
		univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping)
151
		filter.expressions.append(filter_p)
152
167
153
	res=[]
154
	for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
155
		res.append((object(co, lo, None, dn=dn, superordinate=superordinate, attributes = attrs )))
156
	return res
157
168
158
def identify(dn, attr):
169
def identify(dn, attr):
159
160
	return 'univentionDhcpHost' in attr.get('objectClass', [])
170
	return 'univentionDhcpHost' in attr.get('objectClass', [])
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/pool.py (-150 / +142 lines)
 Lines 31-37    Link Here 
31
# <http://www.gnu.org/licenses/>.
31
# <http://www.gnu.org/licenses/>.
32
32
33
import copy
33
import copy
34
import string
35
34
36
from univention.admin.layout import Tab, Group
35
from univention.admin.layout import Tab, Group
37
import univention.admin.filter
36
import univention.admin.filter
 Lines 39-249   import univention.admin.handlers Link Here 
39
import univention.admin.localization
38
import univention.admin.localization
40
import univention.admin.uexceptions
39
import univention.admin.uexceptions
41
40
42
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
41
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
43
_=translation.translate
42
_ = translation.translate
44
43
45
module='dhcp/pool'
44
module = 'dhcp/pool'
46
operations=['add','edit','remove','search']
45
operations = ['add', 'edit', 'remove', 'search']
47
superordinate = 'dhcp/subnet'
46
superordinate = 'dhcp/subnet'
48
childs=0
47
childs = 0
49
usewizard=1
48
usewizard = 1
50
short_description=_('DHCP: Pool')
49
short_description = _('DHCP: Pool')
51
long_description=''
50
long_description = ''
52
options={
51
52
options = {
53
}
53
}
54
property_descriptions={
54
55
property_descriptions = {
55
	'name': univention.admin.property(
56
	'name': univention.admin.property(
56
			short_description=_('Name'),
57
		short_description=_('Name'),
57
			long_description='',
58
		long_description=_('A unique name used to identify this pool, e.g. "known" or "guests"'),
58
			syntax=univention.admin.syntax.string,
59
		syntax=univention.admin.syntax.string,
59
			multivalue=0,
60
		multivalue=False,
60
			include_in_default_search=1,
61
		include_in_default_search=True,
61
			options=[],
62
		options=[],
62
			required=1,
63
		required=True,
63
			may_change=0,
64
		may_change=False,
64
			identifies=1
65
		identifies=True
65
		),
66
	),
66
	'range': univention.admin.property(
67
	'range': univention.admin.property(
67
			short_description=_('IP range for dynamic assignment'),
68
		short_description=_('IP range for dynamic assignment'),
68
			long_description='',
69
		long_description='',
69
			syntax=univention.admin.syntax.IPv4_AddressRange,
70
		syntax=univention.admin.syntax.IPv4_AddressRange,
70
			multivalue=1,
71
		multivalue=True,
71
			options=[],
72
		options=[],
72
			required=1,
73
		required=True,
73
			may_change=1,
74
		may_change=True,
74
			identifies=0
75
		identifies=False
75
		),
76
	),
76
	'failover_peer': univention.admin.property(
77
	'failover_peer': univention.admin.property(
77
			short_description=_('Failover peer'),
78
		short_description=_('Failover peer'),
78
			long_description='',
79
		long_description=_('The name of a failover configuration manually configured in /etc/dhcp/local.conf.'),
79
			syntax=univention.admin.syntax.string,
80
		syntax=univention.admin.syntax.string,
80
			multivalue=0,
81
		multivalue=False,
81
			options=[],
82
		options=[],
82
			required=0,
83
		required=False,
83
			may_change=1,
84
		may_change=True,
84
			identifies=0,
85
		identifies=False,
85
		),
86
	),
86
	'known_clients': univention.admin.property(
87
	'known_clients': univention.admin.property(
87
			short_description=_('Allow known clients'),
88
		short_description=_('Give IP to known clients'),
88
			long_description='',
89
		long_description=_('Addresses are allocated for client, which have a host entry matching their MAC address.'),
89
			syntax=univention.admin.syntax.AllowDeny,
90
		syntax=univention.admin.syntax.AllowDeny,
90
			multivalue=0,
91
		multivalue=False,
91
			options=[],
92
		options=[],
92
			required=0,
93
		required=False,
93
			may_change=1,
94
		may_change=True,
94
			identifies=0
95
		identifies=False
95
		),
96
	),
96
	'unknown_clients': univention.admin.property(
97
	'unknown_clients': univention.admin.property(
97
			short_description=_('Allow unknown clients'),
98
		short_description=_('Give IP to unknown clients'),
98
			long_description='',
99
		long_description=_('Addresses are allocated for clients, which do not have a host entry mating their MAC address.'),
99
			syntax=univention.admin.syntax.AllowDeny,
100
		syntax=univention.admin.syntax.AllowDeny,
100
			multivalue=0,
101
		multivalue=False,
101
			options=[],
102
		options=[],
102
			required=0,
103
		required=False,
103
			may_change=1,
104
		may_change=True,
104
			identifies=0
105
		identifies=False
105
		),
106
	),
106
	'dynamic_bootp_clients': univention.admin.property(
107
	'dynamic_bootp_clients': univention.admin.property(
107
			short_description=_('Allow dynamic BOOTP clients'),
108
		short_description=_('Give IP to dynamic BOOTP clients'),
108
			long_description='',
109
		long_description=_(
109
			syntax=univention.admin.syntax.AllowDeny,
110
			'Give addresses to clients using the legacy BOOTP protocol.'
110
			multivalue=0,
111
			'Since BOOTP does not support an expiry date or a release mechanism, addresses are allocated indefinitely!'),
111
			options=[],
112
		syntax=univention.admin.syntax.AllowDeny,
112
			required=0,
113
		multivalue=False,
113
			may_change=1,
114
		options=[],
114
			identifies=0
115
		required=False,
115
		),
116
		may_change=True,
117
		identifies=False
118
	),
116
	'all_clients': univention.admin.property(
119
	'all_clients': univention.admin.property(
117
			short_description=_('All clients'),
120
		short_description=_('Give IP from this pool'),
118
			long_description='',
121
		long_description=_('Give addresses from this pool at all or not.'),
119
			syntax=univention.admin.syntax.AllowDeny,
122
		syntax=univention.admin.syntax.AllowDeny,
120
			multivalue=0,
123
		multivalue=False,
121
			options=[],
124
		options=[],
122
			required=0,
125
		required=False,
123
			may_change=1,
126
		may_change=True,
124
			identifies=0
127
		identifies=False
125
		),
128
	),
126
}
129
}
127
130
128
options={
131
options = {
129
}
132
}
130
133
131
layout = [
134
layout = [
132
	Tab(_('General'), _('Basic settings'), layout = [
135
	Tab(_('General'), _('Basic settings'), layout=[
133
		Group( _( 'General' ), layout = [
136
		Group(_('General'), layout=[
134
			'name',
137
			'name',
135
			'range'
138
			'range'
136
		] ),
139
		]),
137
	] ),
140
	]),
138
	Tab( _( 'Advanced' ), _('Advanced DHCP pool options'), advanced = True, layout = [
141
	Tab(_('Advanced'), _('Advanced DHCP pool options'), advanced=True, layout=[
139
		'failover_peer',
142
		'failover_peer',
140
		[ 'known_clients', 'unknown_clients' ],
143
		['known_clients', 'unknown_clients'],
141
		[ 'dynamic_bootp_clients', 'all_clients' ]
144
		['dynamic_bootp_clients', 'all_clients']
142
	] )
145
	])
143
]
146
]
144
147
145
def rangeMap( value ):
146
	return map( lambda x: ' '.join( x ), value )
147
148
148
def rangeUnmap( value ):
149
from .__common import rangeMap, rangeUnmap, add_dhcp_options, DhcpOptions
149
	return map( lambda x: x.split( ' ' ), value )
150
150
151
mapping=univention.admin.mapping.mapping()
151
mapping = univention.admin.mapping.mapping()
152
mapping.register('name', 'cn', None, univention.admin.mapping.ListToString)
152
mapping.register('name', 'cn', None, univention.admin.mapping.ListToString)
153
mapping.register('range', 'dhcpRange', rangeMap, rangeUnmap)
153
mapping.register('range', 'dhcpRange', rangeMap, rangeUnmap)
154
mapping.register('failover_peer', 'univentionDhcpFailoverPeer', None, univention.admin.mapping.ListToString)
154
mapping.register('failover_peer', 'univentionDhcpFailoverPeer', None, univention.admin.mapping.ListToString)
155
155
156
class object(univention.admin.handlers.simpleLdap):
156
add_dhcp_options(__name__)
157
	module=module
158
157
159
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
160
		global mapping
161
		global property_descriptions
162
158
163
		self.mapping=mapping
159
class object(DhcpOptions):
164
		self.descriptions=property_descriptions
160
	module = module
161
162
	permits_udm2dhcp = {
163
		'known_clients': "known clients",
164
		'unknown_clients': "unknown clients",
165
		'dynamic_bootp_clients': "dynamic bootp clients",
166
		'all_clients': "all clients",
167
	}
168
	permits_dhcp2udm = dict((value, key) for (key, value) in permits_udm2dhcp.items())
169
170
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
171
		self.mapping = mapping
172
		self.descriptions = property_descriptions
165
173
166
		if not superordinate:
174
		if not superordinate:
167
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
175
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
168
		if not dn and not position:
176
		if not dn and not position:
169
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
177
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
170
178
171
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
179
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
180
		self.setup_options(options)
172
181
173
	def open(self):
182
	def open(self):
174
183
		super(object, self).open()
175
		univention.admin.handlers.simpleLdap.open(self)
176
184
177
		for i in self.oldattr.get('dhcpPermitList', []):
185
		for i in self.oldattr.get('dhcpPermitList', []):
178
			pos=i.find(' ')
186
			permit, name = i.split(' ', 1)
179
			permit=i[:pos]
187
			prop = self.permits_dhcp2udm[name]
180
			name=i[pos+1:]
188
			self[prop] = permit
181
			if name == 'known clients':
182
				self['known_clients']=permit
183
			elif name == 'unknown clients':
184
				self['unknown_clients']=permit
185
			elif name == 'dynamic bootp clients':
186
				self['dynamic_bootp_clients']=permit
187
			elif name == 'all clients':
188
				self['all_clients']=permit
189
189
190
		self.save()
190
		self.save()
191
191
192
193
	def _ldap_pre_create(self):
192
	def _ldap_pre_create(self):
194
		self.dn='%s=%s,%s' % (mapping.mapName('name'), mapping.mapValue('name', self.info['name']), self.position.getDn())
193
		self.dn = '%s=%s,%s' % (
194
			mapping.mapName('name'),
195
			mapping.mapValue('name', self.info['name']),
196
			self.position.getDn()
197
		)
195
198
196
	def _ldap_addlist(self):
199
	def _ldap_addlist(self):
197
		return [
200
		return [
198
			('objectClass', ['top', 'univentionDhcpPool']),
201
			('objectClass', ['top', 'univentionDhcpPool']),
199
		]
202
		]
200
	
203
201
	def _ldap_modlist(self):
204
	def _ldap_modlist(self):
202
		ml=univention.admin.handlers.simpleLdap._ldap_modlist(self)
205
		ml = super(object, self)._ldap_modlist()
203
		if self.hasChanged(['known_clients', 'unknown_clients', 'dynamic_bootp_clients', 'all_clients']):
206
		if self.hasChanged(self.permits_udm2dhcp.keys()):
204
			old=self.oldattr.get('dhcpPermitList', [])
207
			old = self.oldattr.get('dhcpPermitList', [])
205
			new=copy.deepcopy(old)
208
			new = copy.deepcopy(old)
206
209
			for prop, value in self.permits_udm2dhcp.items():
207
			if self.oldinfo.has_key('known_clients') and self.oldinfo['known_clients']:
210
				try:
208
				new.remove(self.oldinfo['known_clients']+' known clients')
211
					permit = self.oldinfo[prop]
209
			if self.info.has_key('known_clients') and self.info['known_clients']:
212
					new.remove("%s %s" % (permit, value))
210
				new.append(self.info['known_clients']+' known clients')
213
				except LookupError:
211
				
214
					pass
212
			if self.oldinfo.has_key('unknown_clients') and self.oldinfo['unknown_clients']:
215
				try:
213
				new.remove(self.oldinfo['unknown_clients']+' unknown clients')
216
					permit = self.info[prop]
214
			if self.info.has_key('unknown_clients') and self.info['unknown_clients']:
217
					new.append("%s %s" % (permit, value))
215
				new.append(self.info['unknown_clients']+' unknown clients')
218
				except LookupError:
216
219
					pass
217
			if self.oldinfo.has_key('dynamic_bootp_clients') and self.oldinfo['dynamic_bootp_clients']:
218
				new.remove(self.oldinfo['dynamic_bootp_clients']+' dynamic bootp clients')
219
			if self.info.has_key('dynamic_bootp_clients') and self.info['dynamic_bootp_clients']:
220
				new.append(self.info['dynamic_bootp_clients']+' dynamic bootp clients')
221
			
222
			if self.oldinfo.has_key('all_clients') and self.oldinfo['all_clients']:
223
				new.remove(self.oldinfo['all_clients']+' all clients')
224
			if self.info.has_key('all_clients') and self.info['all_clients']:
225
				new.append(self.info['all_clients']+' all clients')
226
				
227
			ml.append(('dhcpPermitList', old, new))
220
			ml.append(('dhcpPermitList', old, new))
221
228
		if self.info.get('failover_peer', None) and not self.info.get('dynamic_bootp_clients', None) == 'deny':
222
		if self.info.get('failover_peer', None) and not self.info.get('dynamic_bootp_clients', None) == 'deny':
229
			raise univention.admin.uexceptions.bootpXORFailover
223
			raise univention.admin.uexceptions.bootpXORFailover
224
230
		return ml
225
		return ml
231
226
232
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
227
	@staticmethod
228
	def lookup_filter(filter_s=None, lo=None):
229
		filter_obj = univention.admin.filter.conjunction('&', [
230
			univention.admin.filter.expression('objectClass', 'univentionDhcpPool')
231
		])
232
		filter_obj.append_unmapped_filter_string(filter_s, univention.admin.mapping.mapRewrite, mapping)
233
		return filter_obj
233
234
234
	filter=univention.admin.filter.conjunction('&', [
235
	univention.admin.filter.expression('objectClass', 'univentionDhcpPool')
236
	])
237
235
238
	if filter_s:
236
lookup_filter = object.lookup_filter
239
		filter_p=univention.admin.filter.parse(filter_s)
237
lookup = object.lookup
240
		univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping)
241
		filter.expressions.append(filter_p)
242
238
243
	res=[]
244
	for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
245
		res.append((object(co, lo, None, dn=dn, superordinate=superordinate, attributes = attrs )))
246
	return res
247
239
248
def identify(dn, attr):
240
def identify(dn, attr):
249
	return 'univentionDhcpPool' in attr.get('objectClass', [])
241
	return 'univentionDhcpPool' in attr.get('objectClass', [])
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/server.py (-56 / +61 lines)
 Lines 35-105   import univention.admin.filter Link Here 
35
import univention.admin.handlers
35
import univention.admin.handlers
36
import univention.admin.localization
36
import univention.admin.localization
37
37
38
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
38
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
39
_=translation.translate
39
_ = translation.translate
40
40
41
module='dhcp/server'
41
module = 'dhcp/server'
42
operations=['add','edit','remove','search']
42
operations = ['add', 'edit', 'remove', 'search']
43
superordinate='dhcp/service'
43
superordinate = 'dhcp/service'
44
childs=0
44
childs = 0
45
usewizard=1
45
usewizard = 1
46
short_description=_('DHCP: Server')
46
short_description = _('DHCP: Server')
47
long_description=''
47
long_description = ''
48
options={
48
49
options = {
49
}
50
}
50
51
51
property_descriptions={
52
property_descriptions = {
52
	'server': univention.admin.property(
53
	'server': univention.admin.property(
53
			short_description=_('Server name'),
54
		short_description=_('Server name'),
54
			long_description='',
55
		long_description='',
55
			syntax=univention.admin.syntax.string,
56
		syntax=univention.admin.syntax.string,
56
			multivalue=0,
57
		multivalue=False,
57
			include_in_default_search=1,
58
		include_in_default_search=True,
58
			options=[],
59
		options=[],
59
			required=1,
60
		required=True,
60
			may_change=1,
61
		may_change=True,
61
			identifies=1
62
		identifies=True
62
		),
63
	),
63
}
64
}
64
65
65
layout = [
66
layout = [
66
	Tab( _( 'General' ), _('General settings'), layout = [
67
	Tab(_('General'), _('General settings'), layout=[
67
		Group( _( 'General' ), layout = [
68
		Group(_('General'), layout=[
68
			'server'
69
			'server'
69
		] ),
70
		]),
70
	] )
71
	])
71
]
72
]
72
73
73
mapping=univention.admin.mapping.mapping()
74
mapping = univention.admin.mapping.mapping()
74
mapping.register('server', 'cn', None, univention.admin.mapping.ListToString)
75
mapping.register('server', 'cn', None, univention.admin.mapping.ListToString)
75
76
76
from .__common import add_dhcp_options
77
from .__common import add_dhcp_options
78
add_dhcp_options(__name__)
77
79
78
add_dhcp_options( property_descriptions, mapping, layout )
79
80
80
class object(univention.admin.handlers.simpleLdap):
81
class object(univention.admin.handlers.simpleLdap):
81
	module=module
82
	module = module
82
83
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
84
		global mapping
85
		global property_descriptions
86
83
87
		self.superordinate=superordinate
84
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
88
		self.mapping=mapping
85
		self.superordinate = superordinate
89
		self.descriptions=property_descriptions
86
		self.mapping = mapping
87
		self.descriptions = property_descriptions
90
88
91
		if not superordinate:
89
		if not superordinate:
92
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
90
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
93
		if not dn and not position:
91
		if not dn and not position:
94
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
92
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
95
93
96
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
94
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
97
95
98
	def _ldap_pre_create(self):
96
	def _ldap_pre_create(self):
99
		self.dn='%s=%s,%s' % (mapping.mapName('server'), mapping.mapValue('server', self.info['server']), self.position.getDn())
97
		self.dn = '%s=%s,%s' % (
98
			mapping.mapName('server'),
99
			mapping.mapValue('server', self.info['server']),
100
			self.position.getDn()
101
		)
100
102
101
	def _ldap_addlist(self):
103
	def _ldap_addlist(self):
102
		searchBase=self.position.getDomain()
104
		searchBase = self.position.getDomain()
103
		if self.lo.searchDn(base=searchBase, filter='(&(objectClass=dhcpServer)(cn=%s))' % (self.info['server'])):
105
		if self.lo.searchDn(base=searchBase, filter='(&(objectClass=dhcpServer)(cn=%s))' % (self.info['server'])):
104
			raise univention.admin.uexceptions.dhcpServerAlreadyUsed, self.info['server']
106
			raise univention.admin.uexceptions.dhcpServerAlreadyUsed, self.info['server']
105
107
 Lines 107-139   class object(univention.admin.handlers.simpleLdap): Link Here 
107
			('objectClass', ['top', 'dhcpServer']),
109
			('objectClass', ['top', 'dhcpServer']),
108
			('dhcpServiceDN', self.superordinate.dn),
110
			('dhcpServiceDN', self.superordinate.dn),
109
		]
111
		]
112
110
	def _ldap_post_move(self, olddn):
113
	def _ldap_post_move(self, olddn):
111
		'''edit dhcpServiceDN'''
114
		'''edit dhcpServiceDN'''
112
		oldServiceDN=self.lo.getAttr(self.dn, 'dhcpServiceDN')
115
		oldServiceDN = self.lo.getAttr(self.dn, 'dhcpServiceDN')
113
		module=univention.admin.modules.identifyOne(self.position.getDn(), self.lo.get(self.position.getDn()))
116
		module = univention.admin.modules.identifyOne(self.position.getDn(), self.lo.get(self.position.getDn()))
114
		object=univention.admin.objects.get(module, None, self.lo, self.position, dn=self.position.getDn())
117
		object = univention.admin.objects.get(module, None, self.lo, self.position, dn=self.position.getDn())
115
		shadow_module, shadow_object=univention.admin.objects.shadow(self.lo, module, object, self.position)
118
		shadow_module, shadow_object = univention.admin.objects.shadow(self.lo, module, object, self.position)
116
		self.lo.modify(self.dn, [('dhcpServiceDN', oldServiceDN[0], shadow_object.dn)])
119
		self.lo.modify(self.dn, [('dhcpServiceDN', oldServiceDN[0], shadow_object.dn)])
117
120
118
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
119
121
120
	filter=univention.admin.filter.conjunction('&', [
122
def lookup_filter(filter_s=None, lo=None):
121
	univention.admin.filter.expression('objectClass', 'dhcpServer')
123
	filter_obj = univention.admin.filter.conjunction('&', [
124
		univention.admin.filter.expression('objectClass', 'dhcpServer')
122
	])
125
	])
126
	filter_obj.append_unmapped_filter_string(filter_s, univention.admin.mapping.mapRewrite, mapping)
127
	return filter_obj
123
128
124
	if superordinate:
125
		filter.expressions.append(univention.admin.filter.expression('dhcpServiceDN', superordinate.dn))
126
129
127
	if filter_s:
130
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
128
		filter_p=univention.admin.filter.parse(filter_s)
131
	filter_obj = lookup_filter(filter_s)
129
		univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping)
132
	if superordinate:
130
		filter.expressions.append(filter_p)
133
		filter_obj.expressions.append(univention.admin.filter.expression('dhcpServiceDN', superordinate.dn))
134
	filter_str = unicode(filter_obj)
131
135
132
	res=[]
136
	res = [
133
	for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
137
		object(co, lo, None, dn=dn, superordinate=superordinate, attributes=attrs)
134
		res.append((object(co, lo, None, dn=dn, superordinate=superordinate, attributes = attrs )))
138
		for dn, attrs in lo.search(filter_str, base, scope, [], unique, required, timeout, sizelimit)
139
	]
135
	return res
140
	return res
136
141
137
def identify(dn, attr):
138
142
143
def identify(dn, attr):
139
	return 'dhcpServer' in attr.get('objectClass', [])
144
	return 'dhcpServer' in attr.get('objectClass', [])
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/service.py (-61 / +56 lines)
 Lines 35-127   import univention.admin.filter Link Here 
35
import univention.admin.handlers
35
import univention.admin.handlers
36
import univention.admin.localization
36
import univention.admin.localization
37
37
38
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
38
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
39
_=translation.translate
39
_ = translation.translate
40
40
41
module='dhcp/service'
41
module = 'dhcp/service'
42
operations=['add','edit','remove','search']
42
operations = ['add', 'edit', 'remove', 'search']
43
childs=1
43
childs = 1
44
usewizard=1
44
usewizard = 1
45
short_description=_('DHCP: Service')
45
short_description = _('DHCP: Service')
46
long_description=''
46
long_description = ''
47
options={
47
48
options = {
48
}
49
}
49
property_descriptions={
50
51
property_descriptions = {
50
	'service': univention.admin.property(
52
	'service': univention.admin.property(
51
			short_description=_('Service name'),
53
		short_description=_('Service name'),
52
			long_description='',
54
		long_description='',
53
			syntax=univention.admin.syntax.string,
55
		syntax=univention.admin.syntax.string,
54
			multivalue=0,
56
		multivalue=False,
55
			include_in_default_search=1,
57
		include_in_default_search=True,
56
			options=[],
58
		options=[],
57
			required=1,
59
		required=True,
58
			may_change=0,
60
		may_change=False,
59
			identifies=1
61
		identifies=True
60
		),
62
	),
61
}
63
}
62
64
63
layout = [
65
layout = [
64
	Tab( _( 'General' ), _( 'Basic settings' ), layout = [
66
	Tab(_('General'), _('Basic settings'), layout=[
65
		Group( _( 'General' ), layout = [
67
		Group(_('General'), layout=[
66
			'service',
68
			'service',
67
		] ),
69
		]),
68
	] ),
70
	]),
69
]
71
]
70
72
71
mapping=univention.admin.mapping.mapping()
73
mapping = univention.admin.mapping.mapping()
72
mapping.register('service', 'cn', None, univention.admin.mapping.ListToString)
74
mapping.register('service', 'cn', None, univention.admin.mapping.ListToString)
73
75
74
from .__common import add_dhcp_options, add_dhcp_objectclass
76
from .__common import add_dhcp_options, DhcpOptions
75
77
add_dhcp_options(__name__)
76
add_dhcp_options( property_descriptions, mapping, layout )
77
78
78
class object(univention.admin.handlers.simpleLdap):
79
	module=module
80
79
81
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
80
class object(DhcpOptions):
82
		global mapping
81
	module = module
83
		global property_descriptions
84
82
85
		self.mapping=mapping
83
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
86
		self.descriptions=property_descriptions
84
		self.mapping = mapping
85
		self.descriptions = property_descriptions
87
86
88
		if not dn and not position:
87
		if not dn and not position:
89
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
88
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
90
89
91
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
90
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
91
		self.setup_options(options)
92
92
93
	def _ldap_pre_create(self):
93
	def _ldap_pre_create(self):
94
		self.dn='%s=%s,%s' % (mapping.mapName('service'), mapping.mapValue('service', self.info['service']), self.position.getDn())
94
		self.dn = '%s=%s,%s' % (
95
			mapping.mapName('service'),
96
			mapping.mapValue('service', self.info['service']),
97
			self.position.getDn()
98
		)
95
99
96
	def _ldap_addlist(self):
100
	def _ldap_addlist(self):
97
		return [
101
		return [
98
			('objectClass', [ 'top', 'univentionDhcpService', 'dhcpOptions' ] ),
102
			('objectClass', ['top', 'univentionDhcpService']),
99
		]
103
		]
100
104
101
	def _ldap_modlist(self):
105
	@staticmethod
102
		ml = univention.admin.handlers.simpleLdap._ldap_modlist( self )
106
	def lookup_filter(filter_s=None, lo=None):
103
107
		filter_obj = univention.admin.filter.conjunction('&', [
104
		return add_dhcp_objectclass( self, ml )
108
			univention.admin.filter.conjunction('|', [
105
109
				univention.admin.filter.expression('objectClass', 'dhcpService'),
106
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
110
				univention.admin.filter.expression('objectClass', 'univentionDhcpService')
107
111
			])
108
	filter=univention.admin.filter.conjunction('&', [
109
		univention.admin.filter.conjunction('|', [
110
			univention.admin.filter.expression('objectClass', 'dhcpService'),
111
			univention.admin.filter.expression('objectClass', 'univentionDhcpService')
112
		])
112
		])
113
	])
113
		filter_obj.append_unmapped_filter_string(filter_s, univention.admin.mapping.mapRewrite, mapping)
114
		return filter_obj
115
114
116
115
	if filter_s:
117
lookup_filter = object.lookup_filter
116
		filter_p=univention.admin.filter.parse(filter_s)
118
lookup = object.lookup
117
		univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping)
118
		filter.expressions.append(filter_p)
119
119
120
	res=[]
121
	for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
122
		res.append((object(co, lo, None, dn=dn, superordinate=superordinate, attributes = attrs )))
123
	return res
124
120
125
def identify(dn, attr):
121
def identify(dn, attr):
126
	return 'dhcpService' in attr.get('objectClass', []) \
122
	return bool(set(('dhcpService', 'univentionDhcpService')) & set(attr.get('objectClass', [])))
127
		or 'univentionDhcpService' in attr.get('objectClass', [])
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/shared.py (-56 / +53 lines)
 Lines 36-126   import univention.admin.handlers Link Here 
36
import univention.admin.ipaddress
36
import univention.admin.ipaddress
37
import univention.admin.localization
37
import univention.admin.localization
38
38
39
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
39
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
40
_=translation.translate
40
_ = translation.translate
41
41
42
module='dhcp/shared'
42
module = 'dhcp/shared'
43
operations=['add','edit','remove','search']
43
operations = ['add', 'edit', 'remove', 'search']
44
superordinate='dhcp/service'
44
superordinate = 'dhcp/service'
45
childs=1
45
childs = 1
46
short_description=_('DHCP: Shared network')
46
short_description = _('DHCP: Shared network')
47
long_description=''
47
long_description = ''
48
options={
48
49
options = {
49
}
50
}
50
property_descriptions={
51
52
property_descriptions = {
51
	'name': univention.admin.property(
53
	'name': univention.admin.property(
52
			short_description=_('Shared network name'),
54
		short_description=_('Shared network name'),
53
			long_description='',
55
		long_description='',
54
			syntax=univention.admin.syntax.uid,
56
		syntax=univention.admin.syntax.uid,
55
			multivalue=0,
57
		multivalue=False,
56
			include_in_default_search=1,
58
		include_in_default_search=True,
57
			options=[],
59
		options=[],
58
			required=1,
60
		required=True,
59
			may_change=0,
61
		may_change=False,
60
			identifies=1
62
		identifies=True
61
		)
63
	)
62
}
63
options={
64
}
64
}
65
65
66
layout = [
66
layout = [
67
	Tab( _( 'General' ), _( 'Basic settings' ), layout = [
67
	Tab(_('General'), _('Basic settings'), layout=[
68
		Group( _( 'General' ), layout = [
68
		Group(_('General'), layout=[
69
			'name'
69
			'name'
70
		] ),
70
		]),
71
	] ),
71
	]),
72
]
72
]
73
73
74
mapping=univention.admin.mapping.mapping()
74
mapping = univention.admin.mapping.mapping()
75
mapping.register('name', 'cn', None, univention.admin.mapping.ListToString)
75
mapping.register('name', 'cn', None, univention.admin.mapping.ListToString)
76
76
77
class object(univention.admin.handlers.simpleLdap):
77
from .__common import add_dhcp_options, DhcpOptions
78
	module=module
78
add_dhcp_options(__name__)
79
79
80
80
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
81
class object(DhcpOptions):
81
		global mapping
82
	module = module
82
		global property_descriptions
83
83
84
		self.mapping=mapping
84
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
85
		self.descriptions=property_descriptions
85
		self.mapping = mapping
86
		self.descriptions = property_descriptions
86
87
87
		if not superordinate:
88
		if not superordinate:
88
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
89
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
89
		if not dn and not position:
90
		if not dn and not position:
90
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
91
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
91
92
92
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
93
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
93
94
		self.setup_options(options)
94
	def open(self):
95
		univention.admin.handlers.simpleLdap.open(self)
96
97
		self.save()
98
95
99
	def _ldap_pre_create(self):
96
	def _ldap_pre_create(self):
100
		self.dn='%s=%s,%s' % (mapping.mapName('name'), mapping.mapValue('name', self.info['name']), self.position.getDn())
97
		self.dn = '%s=%s,%s' % (
98
			mapping.mapName('name'),
99
			mapping.mapValue('name', self.info['name']),
100
			self.position.getDn(),
101
		)
101
102
102
	def _ldap_addlist(self):
103
	def _ldap_addlist(self):
103
		return [
104
		return [
104
			('objectClass', ['top', 'dhcpSharedNetwork'])
105
			('objectClass', ['top', 'dhcpSharedNetwork'])
105
		]
106
		]
106
107
107
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
108
108
109
	filter=univention.admin.filter.conjunction('&', [
109
	@staticmethod
110
	univention.admin.filter.expression('objectClass', 'dhcpSharedNetwork')
110
	def lookup_filter(filter_s=None, lo=None):
111
	])
111
		filter_obj = univention.admin.filter.conjunction('&', [
112
			univention.admin.filter.expression('objectClass', 'dhcpSharedNetwork')
113
		])
114
		filter_obj.append_unmapped_filter_string(filter_s, univention.admin.mapping.mapRewrite, mapping)
115
		return filter_obj
112
116
113
	if filter_s:
114
		filter_p=univention.admin.filter.parse(filter_s)
115
		univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping)
116
		filter.expressions.append(filter_p)
117
117
118
	res=[]
118
lookup_filter = object.lookup_filter
119
	for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
119
lookup = object.lookup
120
		res.append((object(co, lo, None, dn=dn, superordinate=superordinate, attributes = attrs )))
120
121
	return res
122
121
123
def identify(dn, attr):
122
def identify(dn, attr):
124
	
125
	return 'dhcpSharedNetwork' in attr.get('objectClass', [])
123
	return 'dhcpSharedNetwork' in attr.get('objectClass', [])
126
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/sharedsubnet.py (-95 / +82 lines)
 Lines 30-174    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
import string
34
35
from univention.admin.layout import Tab, Group
33
from univention.admin.layout import Tab, Group
36
import univention.admin.filter
34
import univention.admin.filter
37
import univention.admin.handlers
35
import univention.admin.handlers
38
import univention.admin.ipaddress
36
import univention.admin.ipaddress
39
import univention.admin.localization
37
import univention.admin.localization
40
38
41
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
39
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
42
_=translation.translate
40
_ = translation.translate
41
42
module = 'dhcp/sharedsubnet'
43
operations = ['add', 'edit', 'remove', 'search']
44
superordinate = 'dhcp/shared'
45
childs = 1
46
short_description = _('DHCP: Shared subnet')
47
long_description = ''
43
48
44
module='dhcp/sharedsubnet'
49
options = {
45
operations=['add','edit','remove','search']
46
superordinate='dhcp/shared'
47
childs=1
48
short_description=_('DHCP: Shared subnet')
49
long_description=''
50
options={
51
}
50
}
52
property_descriptions={
51
52
property_descriptions = {
53
	'subnet': univention.admin.property(
53
	'subnet': univention.admin.property(
54
			short_description=_('Subnet address'),
54
		short_description=_('Subnet address'),
55
			long_description='',
55
		long_description='',
56
			syntax=univention.admin.syntax.ipv4Address,
56
		syntax=univention.admin.syntax.ipv4Address,
57
			multivalue=0,
57
		multivalue=False,
58
			include_in_default_search=1,
58
		include_in_default_search=True,
59
			options=[],
59
		options=[],
60
			required=1,
60
		required=True,
61
			may_change=0,
61
		may_change=False,
62
			identifies=1
62
		identifies=True
63
		),
63
	),
64
	'subnetmask': univention.admin.property(
64
	'subnetmask': univention.admin.property(
65
			short_description=_('Netmask'),
65
		short_description=_('Netmask'),
66
			long_description='',
66
		long_description='',
67
			syntax=univention.admin.syntax.v4netmask,
67
		syntax=univention.admin.syntax.v4netmask,
68
			multivalue=0,
68
		multivalue=False,
69
			options=[],
69
		options=[],
70
			required=1,
70
		required=True,
71
			may_change=1,
71
		may_change=True,
72
			identifies=0
72
		identifies=False
73
		),
73
	),
74
	'broadcastaddress': univention.admin.property(
74
	'broadcastaddress': univention.admin.property(
75
			short_description=_('Broadcast address'),
75
		short_description=_('Broadcast address'),
76
			long_description='',
76
		long_description='',
77
			syntax=univention.admin.syntax.ipv4Address,
77
		syntax=univention.admin.syntax.ipv4Address,
78
			multivalue=0,
78
		multivalue=False,
79
			options=[],
79
		options=[],
80
			required=0,
80
		required=False,
81
			may_change=1,
81
		may_change=True,
82
			identifies=0
82
		identifies=False
83
		),
83
	),
84
	'range': univention.admin.property(
84
	'range': univention.admin.property(
85
			short_description=_('Dynamic address assignment'),
85
		short_description=_('Dynamic address assignment'),
86
			long_description=_( 'Define a pool of addresses available for dynamic address assignment.'),
86
		long_description=_('Define a pool of addresses available for dynamic address assignment.'),
87
			syntax=univention.admin.syntax.IPv4_AddressRange,
87
		syntax=univention.admin.syntax.IPv4_AddressRange,
88
			multivalue=1,
88
		multivalue=True,
89
			options=[],
89
		options=[],
90
			required=0,
90
		required=False,
91
			may_change=1,
91
		may_change=True,
92
			identifies=0
92
		identifies=False
93
		),
93
	),
94
}
95
96
options={
97
}
94
}
98
95
99
layout = [
96
layout = [
100
	Tab(_('General'), _('Basic settings'), layout = [
97
	Tab(_('General'), _('Basic settings'), layout=[
101
		Group( _( 'General' ), layout = [
98
		Group(_('General'), layout=[
102
			[ 'subnet', 'subnetmask' ],
99
			['subnet', 'subnetmask'],
103
			'broadcastaddress',
100
			'broadcastaddress',
104
			'range'
101
			'range'
105
		] ),
102
		]),
106
	] ),
103
	]),
107
]
104
]
108
105
109
def rangeMap( value ):
110
	return map( lambda x: ' '.join( x ), value ) or None
111
106
112
def rangeUnmap( value ):
107
from .__common import rangeMap, rangeUnmap, add_dhcp_options, DhcpOptions
113
	return map( lambda x: x.split( ' ' ), value )
114
108
115
mapping=univention.admin.mapping.mapping()
109
mapping = univention.admin.mapping.mapping()
116
mapping.register('subnet', 'cn', None, univention.admin.mapping.ListToString)
110
mapping.register('subnet', 'cn', None, univention.admin.mapping.ListToString)
117
mapping.register('range', 'dhcpRange', rangeMap, rangeUnmap)
111
mapping.register('range', 'dhcpRange', rangeMap, rangeUnmap)
118
mapping.register('subnetmask', 'dhcpNetMask', None, univention.admin.mapping.ListToString)
112
mapping.register('subnetmask', 'dhcpNetMask', None, univention.admin.mapping.ListToString)
119
mapping.register('broadcastaddress', 'univentionDhcpBroadcastAddress', None, univention.admin.mapping.ListToString)
113
mapping.register('broadcastaddress', 'univentionDhcpBroadcastAddress', None, univention.admin.mapping.ListToString)
120
114
121
from .__common import add_dhcp_options, add_dhcp_objectclass
115
add_dhcp_options(__name__)
122
123
add_dhcp_options( property_descriptions, mapping, layout )
124
116
125
class object(univention.admin.handlers.simpleLdap):
126
	module=module
127
117
128
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
118
class object(DhcpOptions):
129
		global mapping
119
	module = module
130
		global property_descriptions
131
120
132
		self.superordinate=superordinate
121
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
133
		self.mapping=mapping
122
		self.superordinate = superordinate
134
		self.descriptions=property_descriptions
123
		self.mapping = mapping
124
		self.descriptions = property_descriptions
135
125
136
		if not superordinate:
126
		if not superordinate:
137
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
127
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
138
		if not dn and not position:
128
		if not dn and not position:
139
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
129
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
140
130
141
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
131
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
132
		self.setup_options(options)
142
133
143
	def _ldap_pre_create(self):
134
	def _ldap_pre_create(self):
144
		self.dn='%s=%s,%s' % (mapping.mapName('subnet'), mapping.mapValue('subnet', self.info['subnet']), self.position.getDn())
135
		self.dn = '%s=%s,%s' % (
136
			mapping.mapName('subnet'),
137
			mapping.mapValue('subnet', self.info['subnet']),
138
			self.position.getDn()
139
		)
145
140
146
	def _ldap_addlist(self):
141
	def _ldap_addlist(self):
147
		return [
142
		return [
148
			('objectClass', ['top', 'univentionDhcpSubnet', 'univentionDhcpSharedSubnet', 'dhcpOptions' ]),
143
			('objectClass', ['top', 'univentionDhcpSubnet', 'univentionDhcpSharedSubnet']),
149
		]
144
		]
150
145
151
	def _ldap_modlist(self):
146
	@staticmethod
152
		ml = univention.admin.handlers.simpleLdap._ldap_modlist( self )
147
	def lookup_filter(filter_s=None, lo=None):
153
148
		filter_obj = univention.admin.filter.conjunction('&', [
154
		return add_dhcp_objectclass( self, ml )
149
			univention.admin.filter.expression('objectClass', 'univentionDhcpSubnet'),
155
150
			univention.admin.filter.expression('objectClass', 'univentionDhcpSharedSubnet')
156
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
151
		])
152
		filter_obj.append_unmapped_filter_string(filter_s, univention.admin.mapping.mapRewrite, mapping)
153
		return filter_obj
157
154
158
	filter=univention.admin.filter.conjunction('&', [
159
	univention.admin.filter.expression('objectClass', 'univentionDhcpSubnet'),
160
	univention.admin.filter.expression('objectClass', 'univentionDhcpSharedSubnet')
161
	])
162
155
163
	if filter_s:
156
lookup_filter = object.lookup_filter
164
		filter_p=univention.admin.filter.parse(filter_s)
157
lookup = object.lookup
165
		univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping)
166
		filter.expressions.append(filter_p)
167
158
168
	res=[]
169
	for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
170
		res.append((object(co, lo, None, dn=dn, superordinate=superordinate, attributes = attrs )))
171
	return res
172
159
173
def identify(dn, attr):
160
def identify(dn, attr):
174
	return 'univentionDhcpSubnet' in attr.get('objectClass', []) and 'univentionDhcpSharedSubnet' in attr.get('objectClass', [])
161
	return set(('univentionDhcpSubnet', 'univentionDhcpSharedSubnet')) <= set(attr.get('objectClass', []))
(-)a/branches/ucs-3.2/ucs-3.2-0/management/univention-directory-manager-modules/modules/univention/admin/handlers/dhcp/subnet.py (-106 / +94 lines)
 Lines 30-175    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
import string
34
35
from univention.admin.layout import Tab, Group
33
from univention.admin.layout import Tab, Group
36
import univention.admin.filter
34
import univention.admin.filter
37
import univention.admin.handlers
35
import univention.admin.handlers
38
import univention.admin.ipaddress
36
import univention.admin.ipaddress
39
import univention.admin.localization
37
import univention.admin.localization
40
38
41
translation=univention.admin.localization.translation('univention.admin.handlers.dhcp')
39
translation = univention.admin.localization.translation('univention.admin.handlers.dhcp')
42
_=translation.translate
40
_ = translation.translate
43
41
44
module='dhcp/subnet'
42
module = 'dhcp/subnet'
45
operations=['add','edit','remove','search']
43
operations = ['add', 'edit', 'remove', 'search']
46
superordinate='dhcp/service'
44
superordinate = 'dhcp/service'
47
childs=1
45
childs = 1
48
usewizard=1
46
usewizard = 1
49
short_description=_('DHCP: Subnet')
47
short_description = _('DHCP: Subnet')
50
long_description=''
48
long_description = ''
51
options={
49
50
options = {
52
}
51
}
53
property_descriptions={
52
53
property_descriptions = {
54
	'subnet': univention.admin.property(
54
	'subnet': univention.admin.property(
55
			short_description=_('Subnet address'),
55
		short_description=_('Subnet address'),
56
			long_description='',
56
		long_description='',
57
			syntax=univention.admin.syntax.ipv4Address,
57
		syntax=univention.admin.syntax.ipv4Address,
58
			multivalue=0,
58
		multivalue=False,
59
			include_in_default_search=1,
59
		include_in_default_search=True,
60
			options=[],
60
		options=[],
61
			required=1,
61
		required=True,
62
			may_change=0,
62
		may_change=False,
63
			identifies=1
63
		identifies=True
64
		),
64
	),
65
	'subnetmask': univention.admin.property(
65
	'subnetmask': univention.admin.property(
66
			short_description=_('Netmask'),
66
		short_description=_('Netmask'),
67
			long_description='',
67
		long_description='',
68
			syntax=univention.admin.syntax.v4netmask,
68
		syntax=univention.admin.syntax.v4netmask,
69
			multivalue=0,
69
		multivalue=False,
70
			options=[],
70
		options=[],
71
			required=1,
71
		required=True,
72
			may_change=1,
72
		may_change=True,
73
			identifies=0
73
		identifies=False
74
		),
74
	),
75
	'broadcastaddress': univention.admin.property(
75
	'broadcastaddress': univention.admin.property(
76
			short_description=_('Broadcast address'),
76
		short_description=_('Broadcast address'),
77
			long_description='',
77
		long_description='',
78
			syntax=univention.admin.syntax.ipv4Address,
78
		syntax=univention.admin.syntax.ipv4Address,
79
			multivalue=0,
79
		multivalue=False,
80
			options=[],
80
		options=[],
81
			required=0,
81
		required=False,
82
			may_change=1,
82
		may_change=True,
83
			identifies=0
83
		identifies=False
84
		),
84
	),
85
	'range': univention.admin.property(
85
	'range': univention.admin.property(
86
			short_description=_('Dynamic address assignment'),
86
		short_description=_('Dynamic address assignment'),
87
			long_description=_( 'Define a pool of addresses available for dynamic address assignment.' ),
87
		long_description=_('Define a pool of addresses available for dynamic address assignment.'),
88
			syntax=univention.admin.syntax.IPv4_AddressRange,
88
		syntax=univention.admin.syntax.IPv4_AddressRange,
89
			multivalue=1,
89
		multivalue=True,
90
			options=[],
90
		options=[],
91
			required=0,
91
		required=False,
92
			may_change=1,
92
		may_change=True,
93
			identifies=0
93
		identifies=False
94
		),
94
	),
95
}
96
97
options={
98
}
95
}
99
96
100
layout = [
97
layout = [
101
	Tab( _( 'General' ), _('Basic settings'), layout = [
98
	Tab(_('General'), _('Basic settings'), layout=[
102
		Group( _( 'General' ), layout = [
99
		Group(_('General'), layout=[
103
			[ 'subnet', 'subnetmask' ],
100
			['subnet', 'subnetmask'],
104
			'broadcastaddress',
101
			'broadcastaddress',
105
			'range'
102
			'range'
106
		] ),
103
		]),
107
	] ),
104
	]),
108
]
105
]
109
106
110
def rangeMap( value ):
107
from .__common import rangeUnmap, add_dhcp_options, DhcpOptions
111
	return map( lambda x: ' '.join( x ), value )
112
108
113
def rangeUnmap( value ):
109
mapping = univention.admin.mapping.mapping()
114
	return map( lambda x: x.split(), value )
115
116
mapping=univention.admin.mapping.mapping()
117
mapping.register('subnet', 'cn', None, univention.admin.mapping.ListToString)
110
mapping.register('subnet', 'cn', None, univention.admin.mapping.ListToString)
118
mapping.register('subnetmask', 'dhcpNetMask', None, univention.admin.mapping.ListToString)
111
mapping.register('subnetmask', 'dhcpNetMask', None, univention.admin.mapping.ListToString)
119
mapping.register('broadcastaddress', 'univentionDhcpBroadcastAddress', None, univention.admin.mapping.ListToString)
112
mapping.register('broadcastaddress', 'univentionDhcpBroadcastAddress', None, univention.admin.mapping.ListToString)
120
113
121
from .__common import add_dhcp_options, add_dhcp_objectclass
114
add_dhcp_options(__name__)
122
123
add_dhcp_options( property_descriptions, mapping, layout )
124
115
125
class object(univention.admin.handlers.simpleLdap):
126
	module=module
127
116
128
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes = [] ):
117
class object(DhcpOptions):
129
		global mapping
118
	module = module
130
		global property_descriptions
131
119
132
		self.superordinate=superordinate
120
	def __init__(self, co, lo, position, dn='', superordinate=None, attributes=[]):
133
		self.mapping=mapping
121
		self.superordinate = superordinate
134
		self.descriptions=property_descriptions
122
		self.mapping = mapping
123
		self.descriptions = property_descriptions
135
124
136
		if not superordinate:
125
		if not superordinate:
137
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
126
			raise univention.admin.uexceptions.insufficientInformation, 'superordinate object not present'
138
		if not dn and not position:
127
		if not dn and not position:
139
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
128
			raise univention.admin.uexceptions.insufficientInformation, 'neither dn nor position present'
140
129
141
		univention.admin.handlers.simpleLdap.__init__(self, co, lo, position, dn, superordinate, attributes = attributes )
130
		super(object, self).__init__(co, lo, position, dn, superordinate, attributes=attributes)
142
131
		self.setup_options(options)
143
132
144
	def open(self):
133
	def open(self):
145
		univention.admin.handlers.simpleLdap.open(self)
134
		super(object, self).open()
146
		self.info['range'] = rangeUnmap( self.oldattr.get('dhcpRange', []) )
135
		self.info['range'] = self.oldinfo['range'] = rangeUnmap(self.oldattr.get('dhcpRange', []))
147
		self.oldinfo['range'] = rangeUnmap( self.oldattr.get('dhcpRange', []) )
148
149
136
150
	def _ldap_pre_create(self):
137
	def _ldap_pre_create(self):
151
		self.dn='%s=%s,%s' % (mapping.mapName('subnet'), mapping.mapValue('subnet', self.info['subnet']), self.position.getDn())
138
		self.dn = '%s=%s,%s' % (
139
			mapping.mapName('subnet'),
140
			mapping.mapValue('subnet', self.info['subnet']),
141
			self.position.getDn()
142
		)
152
143
153
	def _ldap_addlist(self):
144
	def _ldap_addlist(self):
154
		return [
145
		return [
155
			( 'objectClass', [ 'top', 'univentionDhcpSubnet' ] ),
146
			('objectClass', ['top', 'univentionDhcpSubnet']),
156
		]
147
		]
157
148
158
	def _ldap_modlist(self):
149
	def _ldap_modlist(self):
159
150
		ml = super(object, self)._ldap_modlist()
160
		ml=univention.admin.handlers.simpleLdap._ldap_modlist(self)
161
151
162
		if self.hasChanged('range'):
152
		if self.hasChanged('range'):
163
			dhcpRange=[]
153
			dhcpRange = []
164
			for i in self['range']:
154
			for i in self['range']:
165
				for j in self['range']:
155
				for j in self['range']:
166
					if i != j and univention.admin.ipaddress.is_range_overlapping(i, j):
156
					if i != j and univention.admin.ipaddress.is_range_overlapping(i, j):
167
						raise univention.admin.uexceptions.rangesOverlapping, '%s-%s; %s-%s' % (i[0], i[1], j[0], j[1])
157
						raise univention.admin.uexceptions.rangesOverlapping, '%s-%s; %s-%s' % (i[0], i[1], j[0], j[1])
168
158
169
				ip_in_network=1
159
				ip_in_network = True
170
				for j in i:
160
				for j in i:
171
					if not univention.admin.ipaddress.ip_is_in_network(self['subnet'], self['subnetmask'], j):
161
					if not univention.admin.ipaddress.ip_is_in_network(self['subnet'], self['subnetmask'], j):
172
						ip_in_network=0
162
						ip_in_network = False
173
163
174
					if univention.admin.ipaddress.ip_is_network_address(self['subnet'], self['subnetmask'], j):
164
					if univention.admin.ipaddress.ip_is_network_address(self['subnet'], self['subnetmask'], j):
175
						raise univention.admin.uexceptions.rangeInNetworkAddress, '%s-%s' % (i[0], i[1])
165
						raise univention.admin.uexceptions.rangeInNetworkAddress, '%s-%s' % (i[0], i[1])
 Lines 178-209   class object(univention.admin.handlers.simpleLdap): Link Here 
178
						raise univention.admin.uexceptions.rangeInBroadcastAddress, '%s-%s' % (i[0], i[1])
168
						raise univention.admin.uexceptions.rangeInBroadcastAddress, '%s-%s' % (i[0], i[1])
179
169
180
				if ip_in_network:
170
				if ip_in_network:
181
					dhcpRange.append(string.join(i, ' '))
171
					dhcpRange.append(' '.join(i))
182
				else:
172
				else:
183
					raise univention.admin.uexceptions.rangeNotInNetwork, '%s-%s' % (i[0], i[1])
173
					raise univention.admin.uexceptions.rangeNotInNetwork, '%s-%s' % (i[0], i[1])
184
			#univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'old Range: %s' % self.oldinfo['range'])
174
			#univention.debug.debug(univention.debug.ADMIN, univention.debug.ERROR, 'old Range: %s' % self.oldinfo['range'])
185
			if '' in dhcpRange:
175
			if '' in dhcpRange:
186
				dhcpRange.remove('')
176
				dhcpRange.remove('')
187
			ml.append(('dhcpRange', self.oldattr.get('dhcpRange', []), dhcpRange))
177
			ml.append(('dhcpRange', self.oldattr.get('dhcpRange', []), dhcpRange))
188
		return add_dhcp_objectclass( self, ml )
189
178
190
def lookup(co, lo, filter_s, base='', superordinate=None, scope='sub', unique=0, required=0, timeout=-1, sizelimit=0):
179
		return ml
180
181
	@staticmethod
182
	def lookup_filter(filter_s=None, lo=None):
183
		filter_obj = univention.admin.filter.conjunction('&', [
184
			univention.admin.filter.expression('objectClass', 'univentionDhcpSubnet'),
185
			univention.admin.filter.conjunction('!', [univention.admin.filter.expression('objectClass', 'univentionDhcpSharedSubnet')])
186
		])
187
		filter_obj.append_unmapped_filter_string(filter_s, univention.admin.mapping.mapRewrite, mapping)
188
		return filter_obj
191
189
192
	filter=univention.admin.filter.conjunction('&', [
193
	univention.admin.filter.expression('objectClass', 'univentionDhcpSubnet'),
194
	univention.admin.filter.conjunction('!', [univention.admin.filter.expression('objectClass', 'univentionDhcpSharedSubnet')])
195
	])
196
190
197
	if filter_s:
191
lookup_filter = object.lookup_filter
198
		filter_p=univention.admin.filter.parse(filter_s)
192
lookup = object.lookup
199
		univention.admin.filter.walk(filter_p, univention.admin.mapping.mapRewrite, arg=mapping)
200
		filter.expressions.append(filter_p)
201
193
202
	res=[]
203
	for dn, attrs in lo.search(unicode(filter), base, scope, [], unique, required, timeout, sizelimit):
204
		res.append((object(co, lo, None, dn=dn, superordinate=superordinate, attributes = attrs )))
205
	return res
206
194
207
def identify(dn, attr):
195
def identify(dn, attr):
208
	
196
	ocs = set(attr.get('objectClass', []))
209
	return 'univentionDhcpSubnet' in attr.get('objectClass', []) and not 'univentionDhcpSharedSubnet' in attr.get('objectClass', [])
197
	return 'univentionDhcpSubnet' in ocs and not 'univentionDhcpSharedSubnet' in ocs

Return to bug 33223