Ejemplo n.º 1
0
    def do_check_fix(self, args):
        fix = True if "fix" in args else False
        check = True if "check" in args else False
        silent = True if "silent" in args else False
        failed = []
        fixed = []

        if check or fix:
            for element in self.install_list:
                if not self.checker_lu[element["type"]](element):
                    failed.append(element)
                    if fix:
                        self.fixer_lu[element["type"]](element)
                        fixed.append(element)
                        if not silent:
                            L.info(
                                t("Fixed: the %(type)s %(name)s") % {"type": element["type"], "name": element["name"]}
                            )
                    else:
                        if not silent:
                            L.error(
                                t("Check failed for the %(type)s %(name)s")
                                % {"type": element["type"], "name": element["name"]}
                            )

        return failed, fixed
Ejemplo n.º 2
0
 def search(self, args):
     user_list = args
     user_list.remove('search')
     completed = True
     for user in user_list:
         exists = len(ldap.search(user)) != 0
         if exists:
             L.info(t("The user %s exists") % user)
         else:
             L.info(t("The user %s does not exists") % user)
         completed &= exists
     return completed
Ejemplo n.º 3
0
 def is_member(self, args):
     completed = True
     args.remove('is_member')
     user = args[0]
     group = args[1]
     is_member = ldap.is_member_of(user, group,"")
     if is_member:
         L.info(t("The user %(user)s is member of %(group)s") % {'user':user,'group':group})
     else:
         L.info(t("The user %(user)s is NOT member of %(group)s") % {'user':user,'group':group})
         
     return completed
Ejemplo n.º 4
0
 def is_admin(self, args):
     user_list = args
     user_list.remove('is_admin')
     completed = True
     for user in user_list:
         is_adm = ldap.is_admin(user)
         if is_adm:
             L.info(t("The user %s is admin") % user)
         else:
             L.info(t("The user %s is NOT admin") % user)
         completed &= is_adm
         
     return completed
Ejemplo n.º 5
0
    def do(self, args=[]):
        completed = InstallCommand.do(self,args)

        if inputs.get_input_yesno(t("Do you want to configure centrify/ldap now?")):
            if inputs.get_input_yesno(t("Will this machine use Active Directory?")):
                domain_name = inputs.get_input_string(t("What is the domain name?"), CONF_MAP('ldap','domain'))
                domain_controller = inputs.get_input_string(t("What is the address of the domain controller?"), CONF_MAP('ldap','dc'))
                domain_read_user = inputs.get_input_string(t("What is the ldap reader username?"), CONF_MAP('ldap','ldap_reader'))
                domain_read_pass = inputs.get_password(t("What is the ldap reader password?"),validate=False)
                domain_default_ou = inputs.get_input_string(t("What is the ldap default OU for uwsa?"), CONF_MAP('ldap','uwsa_ou'))

                CONFIG.mod('ldap','enabled', True)
                CONFIG.mod('ldap','domain', domain_name)
                CONFIG.mod('ldap','dc', domain_controller)
                CONFIG.mod('ldap','ldap_reader', domain_read_user)
                CONFIG.mod('ldap','ldap_reader_pass', domain_read_pass)
                CONFIG.mod('ldap','uwsa_ou', domain_default_ou)

                if not CONF_MAP('centrify', 'joined') and inputs.get_input_yesno(t("Do you want to join the Active Directory now?")):
                    domain_admin_user = inputs.get_input_string(t("What is the domain admin username?"))
                    domain_admin_pass = inputs.get_password(t("What is the domain admin password?"),confirm=False, validate=False)
                    cmd_list = [
                        {'command' : 'adjoin -w --force --user %s --password %s %s' % (domain_admin_user, domain_admin_pass, domain_name),
                         'anonymous' : 'adjoin -w --force --user %s --password XXXXXXXXXXXXX %s' % (domain_admin_user, domain_name),
                         'success_code' : [0,8],
                        },
                        'service centrifydc start',
                    ]
                    completed, pinfo = core.exec_cmd_list(cmd_list)
                    L.info(pinfo['stdout'])
                    if not completed:
                        raise Exception(t("Error in installation!"), self.NAME)
                    CONFIG.mod('centrify','joined', "True" )
                CONFIG.save()

        return completed
Ejemplo n.º 6
0
    def create_wordpress(self):
        if self.conf.get('wordpress','enabled'):
            site_path, root_path, log_path, upload_tmp_path = self.generate_dir()
            wp_tpl_webroot = CONF_MAP('site','wordpress_template_path') + "/webroot"
            wp_tpl_schema = CONF_MAP('site','wordpress_template_path') + "/schema/wordpress_tpl_schema.sql"
            wp_webroot_conf = root_path + "/wp-config.php"
            mysql_user = self.conf.get('mysql','user')
            mysql_pass = self.conf.get('mysql','pass')
            mysql_schema = self.conf.get('mysql','schema')
            site_name = self.conf.get('main','site_name')

            if inputs.get_input_noyes(t("Do you want deploy the default wordpress template under %s?") % root_path):
                if files.exists(wp_tpl_webroot):
                    cmd_list = [
                        "bash -c 'cp -fr %s/* %s/'" % (wp_tpl_webroot, root_path),
                    ]
                    completed, pinfo = core.exec_cmd_list(cmd_list)
                    if not completed:
                        L.error(t("Cannot deploy the template."))
                else:
                    L.info(t("There is no template under %s") % wp_tpl_webroot)
            elif inputs.get_input_yesno(t("Do you want to only deploy default plugins?")):
                if files.exists(wp_tpl_webroot):
                    cmd_list = [
                        "bash -c 'mkdir -p %s/wp-content/plugins'" % root_path,
                        "bash -c 'cp -fr %s/wp-content/plugins/* %s/wp-content/plugins/'" % (wp_tpl_webroot, root_path),
                    ]
                    completed, pinfo = core.exec_cmd_list(cmd_list)
                    if not completed:
                        L.error(t("Cannot deploy plugins."))
                else:
                    L.info(t("There is no template under %s") % wp_tpl_webroot)

            if files.exists(wp_webroot_conf):
                params_dict = {
                        'DB_NAME': mysql_schema,
                        'DB_USER': mysql_user,
                        'DB_PASSWORD': mysql_pass,
                        'DB_HOST':'localhost',
                    }
                for key in params_dict:
                    pattern = "define\(\s*?['\"]%s['\"].*;" % key
                    target = "define('%s', '%s');" % (key, params_dict[key])
                    files.re_replace_in(wp_webroot_conf, pattern, target)
            else:
                L.info(t("There is no wp-config.php under %s") % root_path)

            if files.exists(wp_tpl_schema) and inputs.get_input_noyes(t("Do you want to restore default database?")):
                L.info(t("Restoring default schema %s.") % mysql_schema)
                tmp_file = "/tmp/uwsa_wp_schema_%s" % uuid.uuid4()
                files.cp(wp_tpl_schema, tmp_file)
                files.re_replace_in(tmp_file,'UWSA_SCHEMA_NAME', mysql_schema)
                files.replace_in_php_database(tmp_file,'UWSA_SITE_NAME', site_name)
                cmd_list = [
                    {
                        'command': "bash -c 'mysql -u %s -p%s %s < %s'" % (mysql_user, mysql_pass, mysql_schema, tmp_file),
                        'anonymous': "bash -c 'mysql -u %s -p%s %s < %s'"  % (mysql_user, "XXXXX", mysql_schema, tmp_file),
                    },
                ]

                completed, pinfo = core.exec_cmd_list(cmd_list)
                if not completed:
                    L.error(t("Failed to restore schema %s!") % mysql_schema)
                os.remove(tmp_file)
Ejemplo n.º 7
0
 def do_install(self):
     self.pre_install()
     for element in self.install_list:
         L.info(t("Installing the %(type)s %(name)s") % {"type": element["type"], "name": element["name"]})
         self.install_lu[element["type"]](element)
     return True