Example #1
0
def execute(*args, **kw):
    from pykolab import wap_client

    wap_client.authenticate(username=conf.get("ldap", "bind_dn"), password=conf.get("ldap", "bind_pw"))

    users = wap_client.users_list()
    print '\n'.join(users['list'].keys())
Example #2
0
def purge_resources():
    wap_client.authenticate(conf.get("ldap", "bind_dn"), conf.get("ldap", "bind_pw"), conf.get('kolab', 'primary_domain'))

    resources = wap_client.resources_list()

    for resource in resources['list']:
        wap_client.resource_delete({'id': resource})
Example #3
0
def purge_users():
    wap_client.authenticate(conf.get("ldap", "bind_dn"), conf.get("ldap", "bind_pw"))

    users = wap_client.users_list()
    for user in users['list']:
        wap_client.user_delete({'id': user})

    from tests.functional.purge_imap import purge_imap
    purge_imap()
Example #4
0
def purge_users():
    wap_client.authenticate(conf.get("ldap", "bind_dn"), conf.get("ldap", "bind_pw"))

    users = wap_client.users_list()
    for user in users['list']:
        wap_client.user_delete({'id': user})

    from tests.functional.purge_imap import purge_imap
    purge_imap()
Example #5
0
def execute(*args, **kw):
    from pykolab import wap_client
    # Create the authentication object.
    # TODO: Binds with superuser credentials!
    wap_client.authenticate()
    user_types = wap_client.user_types_list()

    for user_type in user_types['list']:
        type = user_types['list'][user_type]
        print "%-15s - %s" % (type['key'], type['description'])
Example #6
0
def execute(*args, **kw):
    from pykolab import wap_client
    # Create the authentication object.
    # TODO: Binds with superuser credentials!
    wap_client.authenticate()
    user_types = wap_client.user_types_list()

    for user_type in user_types['list']:
        type = user_types['list'][user_type]
        print "%-15s - %s" % (type['key'], type['description'])
Example #7
0
def user_add(givenname, sn, preferredlanguage='en_US', **kw):
    if givenname == None:
        raise Exception

    if givenname == '':
        raise Exception

    if sn == None:
        raise Exception

    if sn == '':
        raise Exception

    user_details = {
            'givenname': givenname,
            'sn': sn,
            'preferredlanguage': preferredlanguage,
            'ou': 'ou=People,dc=example,dc=org',
            'userpassword': '******'
        }

    user_details.update(kw)

    login = conf.get('ldap', 'bind_dn')
    password = conf.get('ldap', 'bind_pw')
    domain = conf.get('kolab', 'primary_domain')

    user_type_id = 0

    result = wap_client.authenticate(login, password, domain)

    user_types = wap_client.user_types_list()

    for key in user_types['list'].keys():
        if user_types['list'][key]['key'] == 'kolab':
            user_type_id = key

    user_type_info = user_types['list'][user_type_id]['attributes']

    params = {
            'user_type_id': user_type_id,
        }

    for attribute in user_type_info['form_fields'].keys():
        attr_details = user_type_info['form_fields'][attribute]

        if isinstance(attr_details, dict):
            if not attr_details.has_key('optional') or attr_details['optional'] == False or user_details.has_key(attribute):
                params[attribute] = user_details[attribute]
        elif isinstance(attr_details, list):
            params[attribute] = user_details[attribute]

    fvg_params = params
    fvg_params['object_type'] = 'user'
    fvg_params['type_id'] = user_type_id
    fvg_params['attributes'] = [attr for attr in user_type_info['auto_form_fields'].keys() if not attr in params.keys()]

    result = wap_client.user_add(params)
def execute(*args, **kw):
    from pykolab import wap_client
    # Create the authentication object.
    # TODO: Binds with superuser credentials!
    wap_client.authenticate()
    system_capabilities = wap_client.system_capabilities()

    if system_capabilities['count'] < 1:
        print "No system capabilities"
        sys.exit(1)

    for domain in system_capabilities['list'].keys():
        print "Domain capabilities for %s" % (domain)

        domain_capabilities = system_capabilities['list'][domain]

        for service in domain_capabilities['actions'].keys():
            print "  %-15s - %r" % (service, domain_capabilities['actions'][service]['type'])
Example #9
0
def resource_add(type, cn, members=None, owner=None, **kw):
    if type is None or type == '':
        raise Exception

    if cn is None or cn == '':
        raise Exception

    resource_details = {
        'cn': cn,
        'kolabtargetfolder': "shared/Resources/" + cn + "@example.org",
        'uniquemember': members,
        'owner': owner,
        'ou': 'ou=resources,dc=example,dc=org'
    }

    resource_details.update(kw)

    bind_dn = conf.get('ldap', 'bind_dn')
    bind_pw = conf.get('ldap', 'bind_pw')
    domain = conf.get('kolab', 'primary_domain')
    result = wap_client.authenticate(bind_dn, bind_pw, domain)

    type_id = 0
    resource_types = wap_client.resource_types_list()

    for key in resource_types['list'].keys():
        if resource_types['list'][key]['key'] == type:
            type_id = key

    if type_id == 0:
        raise Exception

    resource_type_info = resource_types['list'][type_id]['attributes']

    params = {}

    for attribute in resource_type_info['form_fields'].keys():
        attr_details = resource_type_info['form_fields'][attribute]

        if isinstance(attr_details, dict):
            if 'optional' not in attr_details or attr_details[
                    'optional'] is False or attribute in resource_details:
                params[attribute] = resource_details[attribute]
        elif isinstance(attr_details, list):
            params[attribute] = resource_details[attribute]

    fvg_params = params
    fvg_params['object_type'] = 'resource'
    fvg_params['type_id'] = type_id
    fvg_params['attributes'] = [
        attr for attr in resource_type_info['auto_form_fields'].keys()
        if attr not in params
    ]

    result = wap_client.resource_add(params)
    result['dn'] = "cn=" + result['cn'] + ",ou=Resources,dc=example,dc=org"
    return result
Example #10
0
def user_add(givenname, sn, preferredlanguage='en_US', **kw):
    if givenname is None or givenname == '':
        raise Exception

    if sn is None or sn == '':
        raise Exception

    user_details = {
        'givenname': givenname,
        'sn': sn,
        'preferredlanguage': preferredlanguage,
        'ou': 'ou=People,dc=example,dc=org',
        'userpassword': '******'
    }

    user_details.update(kw)

    login = conf.get('ldap', 'bind_dn')
    password = conf.get('ldap', 'bind_pw')
    domain = conf.get('kolab', 'primary_domain')

    user_type_id = 0

    result = wap_client.authenticate(login, password, domain)

    user_types = wap_client.user_types_list()

    for key in user_types['list'].keys():
        if user_types['list'][key]['key'] == 'kolab':
            user_type_id = key

    user_type_info = user_types['list'][user_type_id]['attributes']

    params = {
        'user_type_id': user_type_id,
    }

    for attribute in user_type_info['form_fields'].keys():
        attr_details = user_type_info['form_fields'][attribute]

        if isinstance(attr_details, dict):
            if 'optional' not in attr_details or attr_details[
                    'optional'] is False or attribute in user_details:
                params[attribute] = user_details[attribute]
        elif isinstance(attr_details, list):
            params[attribute] = user_details[attribute]

    fvg_params = params
    fvg_params['object_type'] = 'user'
    fvg_params['type_id'] = user_type_id
    fvg_params['attributes'] = [
        attr for attr in user_type_info['auto_form_fields'].keys()
        if attr not in params
    ]

    result = wap_client.user_add(params)
Example #11
0
def execute(*args, **kw):
    from pykolab import wap_client
    # Create the authentication object.
    # TODO: Binds with superuser credentials!
    wap_client.authenticate()
    system_capabilities = wap_client.system_capabilities()

    if system_capabilities['count'] < 1:
        print "No system capabilities"
        sys.exit(1)

    for domain in system_capabilities['list'].keys():
        print "Domain capabilities for %s" % (domain)

        domain_capabilities = system_capabilities['list'][domain]

        for service in domain_capabilities['actions'].keys():
            print "  %-15s - %r" % (
                service, domain_capabilities['actions'][service]['type'])
Example #12
0
def execute(*args, **kw):
    from pykolab import wap_client

    # Use uber-administrative privileges
    username = conf.get('ldap', 'bind_dn')
    if username == None:
        log.error(_("Could not find credentials with sufficient permissions" + \
                "to add a domain name space."))

        sys.exit(1)

    wap_client.authenticate(username=username)

    dna = conf.get('ldap', 'domain_name_attribute')

    try:
        domain = conf.cli_args.pop(0)
    except IndexError, errmsg:
        domain = utils.ask_question(_("Domain name"))
Example #13
0
def execute(*args, **kw):
    from pykolab import wap_client

    # Use uber-administrative privileges
    username = conf.get('ldap', 'bind_dn')
    if username == None:
        log.error(_("Could not find credentials with sufficient permissions" + \
                "to add a domain name space."))

        sys.exit(1)

    wap_client.authenticate(username=username)

    dna = conf.get('ldap', 'domain_name_attribute')

    try:
        domain = conf.cli_args.pop(0)
    except IndexError, errmsg:
        domain = utils.ask_question(_("Domain name"))
Example #14
0
def purge_resources():
    bind_dn = conf.get('ldap', 'bind_dn')
    bind_pw = conf.get('ldap', 'bind_pw')
    domain = conf.get('kolab', 'primary_domain')
    result = wap_client.authenticate(bind_dn, bind_pw, domain)

    resources = wap_client.resources_list()

    for resource in resources['list']:
        wap_client.resource_delete({'id': resource})
Example #15
0
def execute(*args, **kw):
    from pykolab import wap_client
    # Create the authentication object.
    # TODO: Binds with superuser credentials!
    wap_client.authenticate()
    domains = wap_client.domains_list()

    dna = conf.get('ldap', 'domain_name_attribute')

    print "%-39s %-40s" % ("Primary Domain Name Space","Secondary Domain Name Space(s)")

    # TODO: Take a hint in --quiet, and otherwise print out a nice table
    # with headers and such.
    if isinstance(domains['list'], dict):
        for domain_dn in domains['list'].keys():
            if isinstance(domains['list'][domain_dn][dna], list):
                print domains['list'][domain_dn][dna][0]
                for domain_alias in domains['list'][domain_dn][dna][1:]:
                    print "%-39s %-40s" % ('', domain_alias)
            else:
                print domains['list'][domain_dn][dna]
Example #16
0
def execute(*args, **kw):
    from pykolab import wap_client
    # Create the authentication object.
    # TODO: Binds with superuser credentials!
    wap_client.authenticate()
    domains = wap_client.domains_list()

    dna = conf.get('ldap', 'domain_name_attribute')

    print "%-39s %-40s" % ("Primary Domain Name Space",
                           "Secondary Domain Name Space(s)")

    # TODO: Take a hint in --quiet, and otherwise print out a nice table
    # with headers and such.
    if isinstance(domains['list'], dict):
        for domain_dn in domains['list'].keys():
            if isinstance(domains['list'][domain_dn][dna], list):
                print domains['list'][domain_dn][dna][0]
                for domain_alias in domains['list'][domain_dn][dna][1:]:
                    print "%-39s %-40s" % ('', domain_alias)
            else:
                print domains['list'][domain_dn][dna]
Example #17
0
def execute(*args, **kw):
    from pykolab import wap_client

    # Use uber-administrative privileges
    username = conf.get('ldap', 'bind_dn')
    if username == None:
        log.error(_("Could not find credentials with sufficient permissions" + \
                "to add a domain name space."))

        sys.exit(1)

    wap_client.authenticate(username=username)
    domains = wap_client.domains_list()

    dna = conf.get('ldap', 'domain_name_attribute')

    if not conf.parent_domain == None:
        parent_found = False
        if isinstance(domains['list'], dict):
            for _domain in domains['list'].keys():
                if parent_found:
                    continue

                if isinstance(domains['list'][_domain][dna], basestring):
                    if conf.parent_domain == domains['list'][_domain][dna]:
                        parent_found = True
                elif isinstance(domains['list'][_domain], list):
                    if conf.parent_domain in domains['list'][_domain][dna]:
                        parent_found = True

        if not parent_found:
            log.error(_("Invalid parent domain"))
            sys.exit(1)

    try:
        domain = conf.cli_args.pop(0)
    except IndexError, errmsg:
        domain = utils.ask_question(_("Domain name"))
Example #18
0
def resource_add(type, cn, members=None, owner=None, **kw):
    if type == None or type == '':
        raise Exception

    if cn == None or cn == '':
        raise Exception

    resource_details = {
        'cn': cn,
        'kolabtargetfolder': "shared/Resources/" + cn + "@example.org",
        'uniquemember': members,
        'owner': owner,
        'ou': 'ou=resources,dc=example,dc=org'
    }

    resource_details.update(kw)

    result = wap_client.authenticate(conf.get('ldap', 'bind_dn'), conf.get('ldap', 'bind_pw'), conf.get('kolab', 'primary_domain'))

    type_id = 0
    resource_types = wap_client.resource_types_list()

    for key in resource_types['list'].keys():
        if resource_types['list'][key]['key'] == type:
            type_id = key

    if type_id == 0:
        raise Exception

    resource_type_info = resource_types['list'][type_id]['attributes']

    params = {}

    for attribute in resource_type_info['form_fields'].keys():
        attr_details = resource_type_info['form_fields'][attribute]

        if isinstance(attr_details, dict):
            if not attr_details.has_key('optional') or attr_details['optional'] == False or resource_details.has_key(attribute):
                params[attribute] = resource_details[attribute]
        elif isinstance(attr_details, list):
            params[attribute] = resource_details[attribute]

    fvg_params = params
    fvg_params['object_type'] = 'resource'
    fvg_params['type_id'] = type_id
    fvg_params['attributes'] = [attr for attr in resource_type_info['auto_form_fields'].keys() if not attr in params.keys()]

    result = wap_client.resource_add(params)
    result['dn'] = "cn=" + result['cn'] + ",ou=Resources,dc=example,dc=org"
    return result
Example #19
0
    def setup_class(self, *args, **kw):
        self.config = RawConfigParser()
        self.config.read(conf.config_file)

        from tests.functional.purge_users import purge_users
        purge_users()

        self.user = {
                'local': 'john.doe',
                'domain': 'example.org'
            }

        self.login = conf.get('ldap', 'bind_dn')
        self.password = conf.get('ldap', 'bind_pw')
        self.domain = conf.get('kolab', 'primary_domain')

        result = wap_client.authenticate(self.login, self.password, self.domain)
Example #20
0
    def setup_class(self, *args, **kw):
        self.config = RawConfigParser()
        self.config.read(conf.config_file)

        from tests.functional.purge_users import purge_users
        purge_users()

        self.user = {
                'local': 'john.doe',
                'domain': 'example.org'
            }

        self.login = conf.get('ldap', 'bind_dn')
        self.password = conf.get('ldap', 'bind_pw')
        self.domain = conf.get('kolab', 'primary_domain')

        result = wap_client.authenticate(self.login, self.password, self.domain)
    def test_001_list_options_user_preferredlanguage(self):
        conf = pykolab.getConf()
        conf.finalize_conf(fatal=False)

        self.login = conf.get('ldap', 'bind_dn')
        self.password = conf.get('ldap', 'bind_pw')
        self.domain = conf.get('kolab', 'primary_domain')

        result = wap_client.authenticate(self.login, self.password, self.domain)

        attribute_values = wap_client.form_value_select_options(
                'user',
                1,
                'preferredlanguage'
            )

        self.assertTrue(attribute_values['preferredlanguage'].has_key('default'))
        self.assertTrue(attribute_values['preferredlanguage'].has_key('list'))
        self.assertTrue(len(attribute_values['preferredlanguage']['list']) > 1)
        self.assertTrue(attribute_values['preferredlanguage']['default'] in attribute_values['preferredlanguage']['list'])
Example #22
0
 def test_001_authenticate(self):
     result = wap_client.authenticate(self.login, self.password, self.domain)
Example #23
0
def __init__():
    commands.register('user_info',
                      execute,
                      description="Display user information.")


def execute(*args, **kw):
    from pykolab import wap_client

    try:
        user = conf.cli_args.pop(0)
    except IndexError, errmsg:
        user = utils.ask_question(_("Email address"))

    result = wap_client.authenticate(username=conf.get("ldap", "bind_dn"),
                                     password=conf.get("ldap", "bind_pw"))

    if len(user.split('@')) > 1:
        wap_client.system_select_domain(user.split('@')[1])

    user_info = wap_client.user_find({'mail': user})

    if user_info == None or not user_info:
        print >> sys.stderr, _("No such user %s") % (user)
        sys.exit(0)

    unic_attrs = ['displayname', 'givenname', 'cn', 'sn', 'ou', 'entrydn']

    for (k, v) in user_info.iteritems():
        if k in unic_attrs:
            print "%s: %s" % (k, v)
Example #24
0
def execute(*args, **kw):
    from pykolab import wap_client
    # Create the authentication object.
    # TODO: Binds with superuser credentials!
    wap_client.authenticate()
    wap_client.user_add()
Example #25
0
from pykolab import utils
from pykolab.translate import _

log = pykolab.getLogger('pykolab.cli')
conf = pykolab.getConf()

def __init__():
    commands.register('user_info', execute, description="Display user information.")

def execute(*args, **kw):
    from pykolab import wap_client

    try:
        user = conf.cli_args.pop(0)
    except IndexError, errmsg:
        user = utils.ask_question(_("Email address"))

    result = wap_client.authenticate(username=conf.get("ldap", "bind_dn"), password=conf.get("ldap", "bind_pw"))

    if len(user.split('@')) > 1:
        wap_client.system_select_domain(user.split('@')[1])

    user_info = wap_client.user_find({'mail':user})

    if user_info == None or not user_info:
        print >> sys.stderr, _("No such user %s") % (user)
        sys.exit(0)

    for (k,v) in user_info.iteritems():
        print "%s: %r" % (k,v)
Example #26
0
 def test_001_authenticate(self):
     result = wap_client.authenticate(self.login, self.password,
                                      self.domain)