示例#1
0
def create_extended_option(option, app, lo, pos):
    attrs = {}
    option_position = '%s,%s' % (option.position, ucr_get('ldap/base'))
    create_recursive_container(option_position, lo, pos)
    pos.setDn(option_position)
    attrs['name'] = option.name
    attrs['shortDescription'] = option.description
    if option.long_description:
        attrs['longDescription'] = option.long_description
    if option.description_de:
        attrs['translationShortDescription'] = [('de_DE',
                                                 option.description_de)]
    if option.long_description_de:
        attrs['translationLongDescription'] = [('de_DE',
                                                option.long_description_de)]
    attrs['default'] = option.default
    attrs['editable'] = option.editable
    attrs['module'] = option.module
    attrs['objectClass'] = option.object_class
    attrs['isApp'] = '1'
    attribute_logger.debug('Creating DN: %s' % option.dn)
    if not create_object_if_not_exists('settings/extended_options', lo, pos, **
                                       attrs):
        attribute_logger.debug('... already exists. Overwriting!')
        modify_object('settings/extended_options', lo, pos, option.dn, **attrs)
示例#2
0
def create_extended_attribute(attribute, app, layout_position, lo, pos):
    attrs = {}
    attribute_position = '%s,%s' % (attribute.position, ucr_get('ldap/base'))
    create_recursive_container(attribute_position, lo, pos)
    pos.setDn(attribute_position)
    attrs['name'] = attribute.name
    attrs['shortDescription'] = attribute.description
    if attribute.long_description:
        attrs['longDescription'] = attribute.long_description
    if attribute.description_de:
        attrs['translationShortDescription'] = [('de_DE',
                                                 attribute.description_de)]
    if attribute.long_description_de:
        attrs['translationLongDescription'] = [('de_DE',
                                                attribute.long_description_de)]
    attrs['syntax'] = attribute._udm_syntax or attribute.syntax
    attrs['multivalue'] = not attribute.single_value
    if attribute.default:
        attrs['default'] = attribute.default
    attrs['tabPosition'] = str(layout_position)
    attrs['tabName'] = 'Apps'
    attrs['groupName'] = app.name
    attrs['ldapMapping'] = attribute.name
    attrs['objectClass'] = attribute.belongs_to
    attrs['module'] = attribute.module
    attrs['deleteObjectClass'] = True
    attrs['mayChange'] = True
    attrs['fullWidth'] = attribute._full_width
    attribute_logger.debug('Creating DN: %s' % attribute.dn)
    if not create_object_if_not_exists('settings/extended_attribute', lo, pos,
                                       **attrs):
        attribute_logger.debug('... already exists. Overwriting!')
        modify_object('settings/extended_attribute', lo, pos, attribute.dn,
                      **attrs)
示例#3
0
def create_extended_attribute(attribute, app, layout_position, lo, pos):
    attrs = {}
    attribute_position = '%s,%s' % (attribute.position, ucr_get('ldap/base'))
    create_recursive_container(attribute_position, lo, pos)
    pos.setDn(attribute_position)
    attrs['name'] = attribute.name
    attrs['shortDescription'] = attribute.description
    if attribute.long_description:
        attrs['longDescription'] = attribute.long_description
    if attribute.description_de:
        attrs['translationShortDescription'] = [('de_DE',
                                                 attribute.description_de)]
    if attribute.long_description_de:
        attrs['translationLongDescription'] = [('de_DE',
                                                attribute.long_description_de)]
    attrs['syntax'] = attribute.udm_syntax
    attrs['multivalue'] = str(int(not attribute.single_value))
    if attribute.default:
        attrs['default'] = attribute.default
    attrs['tabPosition'] = attribute.tab_position or str(layout_position)
    attrs['tabName'] = attribute.tab_name
    if attribute.tab_name_de:
        attrs['translationTabName'] = [('de_DE', attribute.tab_name_de)]
    attrs['groupName'] = attribute.group_name or app.name
    if attribute.group_name_de:
        attrs['translationGroupName'] = [('de_DE', attribute.group_name_de)]
    attrs['ldapMapping'] = attribute.ldap_mapping
    attrs['objectClass'] = attribute.belongs_to
    attrs['module'] = attribute.module
    attrs['deleteObjectClass'] = attribute.delete_object_class
    attrs['mayChange'] = attribute.may_change
    attrs['fullWidth'] = attribute.full_width
    attrs['hook'] = attribute.hook
    attrs['disableUDMWeb'] = attribute.disable_web
    attrs['groupPosition'] = attribute.group_position
    attrs['tabAdvanced'] = attribute.advanced
    attrs['overwriteTab'] = attribute.overwrite_tab
    attrs['overwritePosition'] = attribute.overwrite_position
    attrs['valueRequired'] = attribute.required
    attrs['notEditable'] = attribute.not_editable
    attrs['doNotSearch'] = attribute.dont_search
    attrs['copyable'] = attribute.copyable
    attrs['options'] = attribute.options
    attrs['CLIName'] = attribute.cli_name
    attrs = dict(
        (key, value) for key, value in attrs.items() if value is not None)
    attribute_logger.debug('Creating DN: %s' % attribute.dn)
    if not create_object_if_not_exists('settings/extended_attribute', lo, pos,
                                       **attrs):
        attribute_logger.debug('... already exists. Overwriting!')
        modify_object('settings/extended_attribute', lo, pos, attribute.dn,
                      **attrs)
示例#4
0
def _handler(ucr, changes):
    changed_entries = set()
    for key in changes.keys():
        match = re.match('ucs/web/overview/entries/(admin|service)/([^/]+)/.*',
                         key)
        if match:
            changed_entries.add(match.group(2))
    changed_entries -= set(
        ['umc', 'invalid-certificate-list', 'root-certificate', 'ldap-master'])
    portal_logger.debug('Changed: %r' % changed_entries)
    if not changed_entries:
        return
    lo, pos = get_machine_connection()
    pos.setDn('cn=entry,cn=portals,cn=univention,%s' % ucr.get('ldap/base'))
    hostname = '%s.%s' % (ucr.get('hostname'), ucr.get('domainname'))

    # iterate over all ipv4 and ipv6 addresses and append them to the link
    local_hosts = [hostname]
    interfaces = Interfaces(ucr)
    for idev, iconf in interfaces.all_interfaces:
        # get ipv4 address of device
        if iconf.ipv4_address():
            local_hosts.append(str(iconf.ipv4_address().ip))

        # get ipv6 addresses of device
        for iname in iconf.ipv6_names:
            local_hosts.append('[%s]' % (iconf.ipv6_address(iname).ip, ))

    portal_logger.debug('Local hosts are: %r' % local_hosts)
    attr_entries = {}
    for changed_entry in changed_entries:
        attr_entries[changed_entry] = {}
    for ucr_key in ucr.keys():
        match = re.match('ucs/web/overview/entries/([^/]+)/([^/]+)/(.*)',
                         ucr_key)
        if not match:
            continue
        category = match.group(1)
        cn = match.group(2)
        key = match.group(3)
        value = ucr.get(ucr_key)
        if cn in attr_entries:
            portal_logger.debug('Matched %r -> %r' % (ucr_key, value))
            entry = attr_entries[cn]
            entry['name'] = cn
            if '_links' not in entry:
                links = []
                for host in local_hosts:
                    if host:
                        links.append(_Link(host=host))
                entry['_links'] = links
            if key == 'link':
                for link in entry['_links']:
                    if value.startswith('http'):
                        link.full = value
                    else:
                        link.path = value
            elif key == 'port_http':
                if value:
                    for link in entry['_links'][:]:
                        if link.protocol == 'https':
                            link = copy(link)
                            entry['_links'].append(link)
                        link.protocol = 'http'
                        link.port = value
            elif key == 'port_https':
                if value:
                    for link in entry['_links'][:]:
                        if link.protocol == 'http':
                            link = copy(link)
                            entry['_links'].append(link)
                        link.protocol = 'https'
                        link.port = value
            elif key == 'icon':
                try:
                    if value.startswith('/univention-management-console'):
                        value = '/univention%s' % value[30:]
                    with open('/var/www/%s' % value, 'rb') as fd:
                        entry['icon'] = b64encode(fd.read()).decode('ASCII')
                except EnvironmentError:
                    pass
            elif key == 'label':
                entry.setdefault('displayName', [])
                entry['displayName'].append(('en_US', value))
            elif key == 'label/de':
                entry.setdefault('displayName', [])
                entry['displayName'].append(('de_DE', value))
            elif key == 'label/fr':
                entry.setdefault('displayName', [])
                entry['displayName'].append(('fr_FR', value))
            elif key == 'description':
                entry.setdefault('description', [])
                entry['description'].append(('en_US', value))
            elif key == 'description/de':
                entry.setdefault('description', [])
                entry['description'].append(('de_DE', value))
            elif key == 'description/fr':
                entry.setdefault('description', [])
                entry['description'].append(('fr_FR', value))
            elif key == 'link-target':
                entry['linkTarget'] = value
            elif key == 'background-color':
                entry['backgroundColor'] = value
            else:
                portal_logger.info('Don\'t know how to handle UCR key %s' %
                                   ucr_key)
    for cn, attrs in attr_entries.items():
        dn = 'cn=%s,%s' % (escape_dn_chars(cn), pos.getDn())
        unprocessed_links = attrs.pop('_links', [])
        my_links = set()
        no_ports = all(not link.port for link in unprocessed_links)
        for link in unprocessed_links:
            if no_ports:
                if link.protocol == 'http':
                    link.port = '80'
                elif link.protocol == 'https':
                    link.port = '443'
            if link:
                my_links.add(('en_US', str(link)))
            if not link.protocol:
                link.protocol = 'http'
                if link:
                    my_links.add(('en_US', str(link)))
                link.protocol = 'https'
                if link:
                    my_links.add(('en_US', str(link)))
        my_links = list(my_links)
        portal_logger.debug('Processing %s' % dn)
        portal_logger.debug('Attrs: %r' % attrs)
        portal_logger.debug('Links: %r' % my_links)
        try:
            obj = init_object('portals/entry', lo, pos, dn)
        except AttributeError:
            portal_logger.error(
                'The handler is not ready yet. Portal modules are not installed. You may have to set the variables again.'
            )
            return
        except udm_errors.noObject:
            portal_logger.debug('DN not found...')
            if my_links:
                portal_logger.debug('... creating')
                attrs['link'] = my_links
                attrs['activated'] = True
                try:
                    create_object_if_not_exists('portals/entry', lo, pos,
                                                **attrs)
                except udm_errors.insufficientInformation as exc:
                    portal_logger.info('Cannot create: %s' % exc)
                try:
                    category_pos = position(ucr.get('ldap/base'))
                    category_pos.setDn('cn=category,cn=portals,cn=univention')
                    category_dn = 'cn=domain-%s,%s' % (
                        escape_dn_chars(category),
                        category_pos.getDn(),
                    )
                    portal_logger.debug('Adding entry to %s' % (category_dn, ))
                    obj = init_object('portals/category', lo, category_pos,
                                      category_dn)
                    entries = obj['entries']
                    entries.append(dn)
                    modify_object('portals/category',
                                  lo,
                                  category_pos,
                                  category_dn,
                                  entries=entries)
                except udm_errors.noObject:
                    portal_logger.debug('DN not found...')
            continue
        links = obj['link']
        portal_logger.debug('Existing links: %r' % links)
        links = [
            _link for _link in links
            if urlsplit(_link[1]).hostname not in local_hosts
        ]
        links.extend(my_links)
        portal_logger.debug('New links: %r' % links)
        if not links:
            portal_logger.debug('Removing DN')
            remove_object_if_exists('portals/entry', lo, pos, dn)
        else:
            portal_logger.debug('Modifying DN')
            attrs['link'] = links
            modify_object('portals/entry', lo, pos, dn, **attrs)
def _handler(ucr, changes):
	changed_entries = set()
	for key in changes.keys():
		match = re.match('ucs/web/overview/entries/(admin|service)/([^/]+)/.*', key)
		if match:
			changed_entries.add(match.group(2))
	changed_entries -= set(['umc', 'invalid-certificate-list', 'root-certificate', 'ldap-master'])
	portal_logger.debug('Changed: %r' % changed_entries)
	if not changed_entries:
		return
	lo, pos = get_machine_connection()
	pos.setDn('cn=portal,cn=univention,%s' % ucr.get('ldap/base'))
	interfaces = Interfaces(ucr)
	hostname = '%s.%s' % (ucr.get('hostname'), ucr.get('domainname'))
	default_ipv4_address = interfaces.get_default_ipv4_address()
	if default_ipv4_address:
		default_ipv4_address = str(default_ipv4_address.ip)
	default_ipv6_address = interfaces.get_default_ipv6_address()
	if default_ipv6_address:
		default_ipv6_address = str(default_ipv6_address.ip)
	local_hosts = [hostname, default_ipv4_address, default_ipv6_address]
	portal_logger.debug('Local hosts are: %r' % local_hosts)
	attr_entries = {}
	for changed_entry in changed_entries:
		attr_entries[changed_entry] = {}
	for ucr_key in ucr.keys():
		match = re.match('ucs/web/overview/entries/([^/]+)/([^/]+)/(.*)', ucr_key)
		if not match:
			continue
		category = match.group(1)
		cn = match.group(2)
		key = match.group(3)
		value = ucr.get(ucr_key)
		if cn in attr_entries:
			portal_logger.debug('Matched %r -> %r' % (ucr_key, value))
			entry = attr_entries[cn]
			entry['category'] = category
			entry['name'] = cn
			if '_links' not in entry:
				links = []
				for host in local_hosts:
					if host:
						links.append(_Link(host=host))
				entry['_links'] = links
			if key == 'link':
				for link in entry['_links']:
					if value.startswith('http'):
						link.full = value
					else:
						link.path = value
			elif key == 'port_http':
				if value:
					for link in entry['_links'][:]:
						if link.protocol == 'https':
							link = copy(link)
							entry['_links'].append(link)
						link.protocol = 'http'
						link.port = value
			elif key == 'port_https':
				if value:
					for link in entry['_links'][:]:
						if link.protocol == 'http':
							link = copy(link)
							entry['_links'].append(link)
						link.protocol = 'https'
						link.port = value
			elif key == 'icon':
				try:
					if value.startswith('/univention-management-console'):
						value = '/univention%s' % value[30:]
					with open('/var/www/%s' % value) as fd:
						entry['icon'] = b64encode(fd.read())
				except EnvironmentError:
					pass
			elif key == 'label':
				entry.setdefault('displayName', [])
				entry['displayName'].append(('en_US', value))
			elif key == 'label/de':
				entry.setdefault('displayName', [])
				entry['displayName'].append(('de_DE', value))
			elif key == 'label/fr':
				entry.setdefault('displayName', [])
				entry['displayName'].append(('fr_FR', value))
			elif key == 'description':
				entry.setdefault('description', [])
				entry['description'].append(('en_US', value))
			elif key == 'description/de':
				entry.setdefault('description', [])
				entry['description'].append(('de_DE', value))
			elif key == 'description/fr':
				entry.setdefault('description', [])
				entry['description'].append(('fr_FR', value))
			else:
				portal_logger.info('Don\'t know how to handle UCR key %s' % ucr_key)
	for cn, attrs in attr_entries.items():
		dn = 'cn=%s,%s' % (escape_dn_chars(cn), pos.getDn())
		unprocessed_links = attrs.pop('_links', [])
		my_links = set()
		no_ports = all(not link.port for link in unprocessed_links)
		for link in unprocessed_links:
			if no_ports:
				if link.protocol == 'http':
					link.port = '80'
				elif link.protocol == 'https':
					link.port = '443'
			if link:
				my_links.add(str(link))
			if not link.protocol:
				link.protocol = 'http'
				if link:
					my_links.add(str(link))
				link.protocol = 'https'
				if link:
					my_links.add(str(link))
		my_links = list(my_links)
		portal_logger.debug('Processing %s' % dn)
		portal_logger.debug('Attrs: %r' % attrs)
		portal_logger.debug('Links: %r' % my_links)
		try:
			obj = init_object('settings/portal_entry', lo, pos, dn)
		except udm_errors.noObject:
			portal_logger.debug('DN not found...')
			if my_links:
				portal_logger.debug('... creating')
				attrs['link'] = my_links
				attrs['portal'] = ['cn=domain,cn=portal,cn=univention,%s' % ucr_get('ldap/base')]
				attrs['activated'] = True
				attrs['authRestriction'] = 'anonymous'
				try:
					create_object_if_not_exists('settings/portal_entry', lo, pos, **attrs)
				except udm_errors.insufficientInformation as exc:
					portal_logger.info('Cannot create: %s' % exc)
			continue
		links = obj['link']
		portal_logger.debug('Existing links: %r' % links)
		links = [_link for _link in links if urlsplit(_link).hostname not in local_hosts]
		links.extend(my_links)
		portal_logger.debug('New links: %r' % links)
		if not links:
			portal_logger.debug('Removing DN')
			remove_object_if_exists('settings/portal_entry', lo, pos, dn)
		else:
			portal_logger.debug('Modifying DN')
			attrs['link'] = links
			modify_object('settings/portal_entry', lo, pos, dn, **attrs)