示例#1
0
文件: ldap.py 项目: pylanglois/uwsa
def create_user(username, useremail, password=None):
    if not password:
        password = inputs.gen_password()

    ldapi = enter_ldap()
    unicode_pass = unicode('"' + password + '"', "iso-8859-1")
    password_value = unicode_pass.encode("utf-16-le")

    add_user = [
        ("objectclass", ["top", "person", "organizationalPerson", "user"]),
        ("uid", username),
        ("sAMAccountName", username),
        ("cn", username),
        ("sn", username),
        ("givenName", username),
        ("userPrincipalName", username + "@" + CONF_MAP("ldap", "domain")),
        ("mail", useremail),
        ("description", "created by uwsa"),
        ("unicodePwd", password_value),
        ("userAccountControl", ["66048"]),
    ]
    user_dn = "cn=%s,%s" % (username, build_dn(CONF_MAP("ldap", "uwsa_ou")))
    ldapi.add_ext_s(user_dn, add_user)

    return password
示例#2
0
    def ask_create_mysql(self, mandatory=False):
        #mysql user name max length = 16
        #mysql schema name max length = 64
        mysql_user = self.conf.get('mysql','user')
        mysql_pass = self.conf.get('mysql','pass')
        mysql_schema = self.conf.get('mysql','schema')
        mysql_apply = False

        if mandatory or inputs.get_input_yesno(t("Do you want to create a MySQL user?")):
            self.ask_mysql_cred()
            mysql_apply = True
            prefix = 'mysql_'
            #username
            max_length = 16
            default = inputs.gen_id(length=(max_length-len(prefix)),prefix=prefix) if mysql_user is None else mysql_user
            username = ""
            while len(username) == 0 or len(username) > max_length or \
                    (mysql.user_exists(username) and not inputs.get_input_yesno(t("The user '%s' exists. Continue?") % username)):
                username = inputs.get_input_string("What is the username?", default)
                if len(username) == 0 or len(username) > max_length:
                    print t("The username length must be less than %s") % max_length
            mysql_user = username
            #password
            max_length = 64
            default = inputs.gen_password(allowed_chars=inputs.PASS_CHARS_MYSQL) if mysql_pass is None else mysql_pass
            password = ""
            while len(password) == 0 or len(password) > max_length:
                password = inputs.get_input_string("What is the password?", default)
                if len(password) == 0 or len(password) > max_length:
                    print t("The password length must be less than %s") % max_length
            mysql_pass = password

        if inputs.get_input_yesno(t("Do you want to create a MySQL schema?")):
            self.ask_mysql_cred()
            mysql_apply = True
            prefix = 'schema_'
            max_length = 64
            default = inputs.gen_id(prefix=prefix) if mysql_schema is None else mysql_schema
            schema = ""
            while len(schema) == 0 or len(schema) > max_length or \
                    (mysql.schema_exists(schema) and not inputs.get_input_yesno(t("The schema '%s' exists. Continue?") % schema)):
                schema = inputs.get_input_string("What is the schema name?", default)
                if len(schema) == 0 or len(schema) > max_length:
                    print t("The schema name length must be less than %s") % max_length
            mysql_schema = schema

        self.conf.mod('mysql','user', mysql_user)
        self.conf.mod('mysql','pass', mysql_pass)
        self.conf.mod('mysql','schema', mysql_schema)
        self.conf.mod('mysql','mysql_apply', mysql_apply)
示例#3
0
文件: unix.py 项目: pylanglois/uwsa
def create_user(username, usermail, password=None):
    if password is None:
        password = inputs.gen_password(inputs.PASS_CHARS_UNIX)

    cmd_list = [
        {
            'command': 'bash -c "useradd -s /bin/bash -U -p $(mkpasswd \"%s\") %s"' % (password, username),
            'anonymous': 'bash -c "useradd -s /bin/bash -U -p $(mkpasswd XXXXXX) %s"' % username,
        }
    ]	

    completed, pinfo = core.exec_cmd_list(cmd_list)
    if not completed:
        L.error(pinfo['stdout'] + '\n' + pinfo['stderr'])
        raise Exception(t("Error in user creation!"))

    return password
示例#4
0
    def ask_create_access(self):
        safe_site_name = self.get_safe_name(self.conf.get('main','site_name'))

        unix_user = self.conf.get('access','unix_user')
        unix_group = self.conf.get('access','unix_group')
        #ldap_user = self.conf.get('access','ldap_user')
        ldap_group = self.conf.get('access','ldap_group')
        ldap_to_apply = False

        if unix_group is None:
            unix_group = safe_site_name + "_unix"

        if ldap_group is None:
            ldap_group = safe_site_name

        #TODO not working for now. Needs debug
        #if CONF_MAP('ldap','enabled') and inputs.get_input_noyes(t("Do you want to create a LDAP user?")):
        #    ldap_user = self.ask_create_user(ldap_user)
        #    self.conf.mod('access','ldap_user', ldap_user)
        #    if ldap_user and not ldap.user_exists(ldap_user):
        #        self.conf.mod('access','ldap_pass', inputs.gen_password())
        #    ldap_to_apply = True

        if CONF_MAP('ldap','enabled') and inputs.get_input_yesno(t("Do you want to create a LDAP group?")):
            self.conf.mod('access','ldap_group', self.ask_create_group(ldap_group))
            ldap_to_apply = True

        if CONF_MAP('unix','enabled') and inputs.get_input_yesno(t("Do you want to create a UNIX user?")):
            unix_user = self.ask_create_user(unix_user)
            self.conf.mod('access','unix_user', unix_user)
            if unix_user and not unix.user_exists(unix_user):
                self.conf.mod('access','unix_pass', inputs.gen_password(allowed_chars=inputs.PASS_CHARS_UNIX))

        if CONF_MAP('unix','enabled') and inputs.get_input_yesno(t("Do you want to create a UNIX group?")):
            self.conf.mod('access','unix_group', self.ask_create_group(unix_group))

        self.conf.mod('access','ldap_to_apply',ldap_to_apply)