コード例 #1
0
	def _get_machine_connection(self):
		try:
			return get_machine_connection()
		except IOError:
			raise ConnectionFailedSecretFile()
		except ldap.INVALID_CREDENTIALS:
			raise ConnectionFailedInvalidMachineCredentials()
		except ldap.CONNECT_ERROR as exc:
			raise ConnectionFailedConnectError(exc)
		except ldap.SERVER_DOWN:
			raise ConnectionFailedServerDown()
コード例 #2
0
def find_hosts_for_master_packages():
	from univention.appcenter.udm import get_machine_connection, search_objects
	lo, pos = get_machine_connection()
	hosts = []
	for host in search_objects('computers/domaincontroller_master', lo, pos):
		hosts.append((host.info.get('fqdn'), True))
	for host in search_objects('computers/domaincontroller_backup', lo, pos):
		hosts.append((host.info.get('fqdn'), False))
	try:
		local_fqdn = '%s.%s' % (ucr_get('hostname'), ucr_get('domainname'))
		local_is_master = ucr_get('server/role') == 'domaincontroller_master'
		hosts.remove((local_fqdn, local_is_master))
	except ValueError:
		# not in list
		pass
	return hosts
コード例 #3
0
 def _list(self, pattern):
     ret = []
     lo, pos = get_machine_connection()
     for app in self.get_apps():
         versions = []
         installations = {}
         if pattern:
             if not fnmatch(app.id, pattern):
                 continue
         app = Apps().find(app.id, latest=True)
         for _app in Apps().get_all_apps_with_id(app.id):
             ldap_obj = get_app_ldap_object(_app, lo, pos)
             servers = ldap_obj.installed_on_servers()
             versions.append(_app.version)
             installations[_app.version] = servers
         ret.append((app, versions, installations))
     return ret
コード例 #4
0
def resolve_dependencies(apps, action):
	from univention.appcenter.app_cache import Apps
	from univention.appcenter.udm import get_machine_connection
	lo, pos = get_machine_connection()
	utils_logger.info('Resolving dependencies for %s' % ', '.join(app.id for app in apps))
	apps_with_their_dependencies = []
	depends = {}
	checked = []
	apps = apps[:]
	if action == 'remove':
		# special case: do not resolve dependencies as
		# we are going to uninstall the app
		# do not removed dependant apps either: the admin may want to keep them
		# => will get an error afterwards
		# BUT: reorder the apps if needed
		original_app_ids = [_app.id for _app in apps]
		for app in apps:
			checked.append(app)
			depends[app.id] = []
			for app_id in app.required_apps:
				if app_id not in original_app_ids:
					continue
				depends[app.id].append(app_id)
			for app_id in app.required_apps_in_domain:
				if app_id not in original_app_ids:
					continue
				depends[app.id].append(app_id)
		apps = []
	while apps:
		app = apps.pop()
		if app in checked:
			continue
		checked.insert(0, app)
		dependencies = depends[app.id] = []
		for app_id in app.required_apps:
			required_app = Apps().find(app_id)
			if required_app is None:
				utils_logger.warn('Could not find required App %s' % app_id)
				continue
			if not required_app.is_installed():
				utils_logger.info('Adding %s to the list of Apps' % required_app.id)
				apps.append(required_app)
				dependencies.append(app_id)
		for app_id in app.required_apps_in_domain:
			required_app = Apps().find(app_id)
			if required_app is None:
				utils_logger.warn('Could not find required App %s' % app_id)
				continue
			if required_app.is_installed():
				continue
			if lo.search('(&(univentionObjectType=appcenter/app)(univentionAppInstalledOnServer=*)(univentionAppID=%s_*))' % required_app.id):
				continue
			utils_logger.info('Adding %s to the list of Apps' % required_app.id)
			apps.append(required_app)
			dependencies.append(app_id)
	max_loop = len(checked) ** 2
	i = 0
	while checked:
		app = checked.pop(0)
		if not depends[app.id]:
			apps_with_their_dependencies.append(app)
			for app_id, required_apps in depends.items():
				try:
					required_apps.remove(app.id)
				except ValueError:
					pass
		else:
			checked.append(app)
		i += 1
		if i > max_loop:
			# this should never happen unless we release apps with dependency cycles
			raise RuntimeError('Cannot resolve dependency cycle!')
	if action == 'remove':
		# another special case:
		# we need to reverse the order: the app with the dependencies needs to be
		# removed first
		apps_with_their_dependencies.reverse()
	return apps_with_their_dependencies
コード例 #5
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)
コード例 #6
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=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)
コード例 #7
0
        "Congratulations, the Self Service Modules have been installed!")
    test.click_button("Continue")
    test.wait_until_all_standby_animations_disappeared()
    test.wait_for_text("Self Service modules allow users to take care")
    test.save_screenshot("app_installed")

    # Erfolgreich?
    test.wait_for_text("Manage local installation")
    subprocess.call(['univention-check-join-status'])
    ucr_load()
    for key, value in [('appcenter/installed', 'ME'),
                       ('appcenter/apps/self-service/status', 'installed'),
                       ('appcenter/apps/self-service/version', '4.0')]:
        if ucr_get(key) != value:
            raise ValueError('%s: %r' % (key, ucr_get(key)))
    lo, pos = get_machine_connection()
    app_obj = search_objects('appcenter/app', lo, pos)[0]
    app_obj.dn == 'univentionAppID=self-service_4.0,cn=self-service,cn=apps,cn=univention,%s' % ucr_get(
        'ldap/base')

    # Können Apps mit NotifyVendor=Yes installiert werden (sollte nicht so sein) ?
    test.click_button("Back to overview")
    test.click_element(
        '//div[contains(concat(" ", normalize-space(@class), " "), " umcGalleryWrapperItem ")][@moduleid="nextcloud"]'
    )
    test.wait_for_text("Nextcloud brings together universal access")
    test.click_button("Install")
    test.wait_for_text("License Agreement")
    test.click_button("Accept license")
    test.wait_for_text("Install Information")
    test.click_element(