示例#1
0
    def to_dev(self, args):
        completed = False
        args.remove("todev")

        site_name = self.ask_site_name(self.get_next_arg(args))
        if not self.is_conf_exists(site_name):
            completed = True
            print t("Sorry, the site '%s' does not exists.") % site_name
            return completed
        self.load(site_name)

        site_path, root_path, log_path, upload_tmp_path = self.generate_dir()
        errors = False

        if self.conf.get("mysql", "enabled"):
            schema = self.conf.get("mysql", "schema")
            # user = self.conf.get('mysql', 'user')
            # password = self.conf.get('mysql', 'pass')
            if inputs.get_input_yesno(t("The schema '%s' will be converted. Continue?") % schema):
                filename = "/tmp/site_convert_todev_%s" % uuid.uuid4()
                if not (self.dump_bd(filename) and self.schema_todev(filename) and self.restore_bd(filename)):
                    L.error(t("Fail to convert schema"))
                    errors = True
                files.rm(filename)

        if errors and not inputs.get_input_yesno(t("There was some errors. Continue?")):
            completed = False
            return completed

        if inputs.get_input_yesno(t("The files under %s will be converted. Continue??") % root_path):
            site_name = self.conf.get("main", "site_name")
            site_dev_name = self.conf.get("main", "site_dev_name")
            site_name_escape = site_name.replace(".", "\.")
            file_list = self.get_file_list(root_path)
            for f in file_list:
                print t("Converting file %s") % f
                files.re_replace_in(f, site_name_escape, site_dev_name)
                files.re_replace_in(f, "(dev\.)*%s" % site_name_escape, site_dev_name)

        robot = root_path + "/robots.txt"
        prodrobot = root_path + "/robots.txt.prod"

        if files.exists(robot):
            self.show_file(t("------- ROBOTS.TXT --------"), robot)
        if files.exists(prodrobot):
            self.show_file(t("------- ROBOTS.TXT.PROD --------"), prodrobot)

        if files.exists(robot) and inputs.get_input_yesno(
            t("Do you want to backup current robots.txt to robots.txt.prod?")
        ):
            if not files.exists(prodrobot) or (
                files.exists(prodrobot) and inputs.get_input_noyes(t("The robots.txt.prod exists. Overwrite?"))
            ):
                files.cp(robot, prodrobot)
        if inputs.get_input_yesno(t("Do you want create a dev robots.txt that disallow all?")):
            with open(files.get_rel_path("data/dev.robots.txt")) as devbot_tpl:
                files.create(robot, devbot_tpl.read())

        completed = True
        return completed
示例#2
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
示例#3
0
    def do(self, args=[]):
        completed = SiteCreateCommand.do(self,args)
        if not completed:

            if not self.ask_create_name(self.get_next_arg(args)):
                #self.ask_alias_name()
                self.ask_dev_name()
                self.update_client_info()
                self.ask_create_access()
                self.ask_create_mysql(mandatory=True)
                self.ask_allow_override(default='All')
                self.conf.mod('php','enabled', True)
                self.conf.mod('php','php_engine','on')
                mysql_enabled = self.conf.get('mysql','schema') is not None
                self.conf.mod('mysql','enabled', mysql_enabled)
                self.conf.mod('wordpress','enabled', True)
                self.conf.mod('wikimedia','enabled', False)
                self.conf.mod('typo3','enabled', False)
                self.save()
                self.fix_config(overwrite=True)
                try:
                    if inputs.get_input_yesno(t("Do you want to send configuration of %(name)s to %(mail)s?") %
                                                {   'name': self.conf.get('main','site_name'), 
                                                    'mail': CONF_MAP('mail','admin_mail'),
                                                }):
                        self.send_status_mail()
                except Exception:
                    L.exception(t("Problem sending mail in %s") % __file__)
                print self.gen_status_msg()
                completed = True

        return completed
示例#4
0
文件: apache.py 项目: pylanglois/uwsa
def graceful():
    cmd_list = [
        "apache2ctl graceful",
    ]
    completed, pinfo = core.exec_cmd_list(cmd_list)
    if not completed:
        L.error(pinfo['stdout'] + '\n' + pinfo['stderr'])
        raise Exception(t("Error in site.graceful!"))
示例#5
0
    def to_prod(self, args):
        completed = False
        args.remove("toprod")

        site_name = self.ask_site_name(self.get_next_arg(args))
        if not self.is_conf_exists(site_name):
            completed = True
            print t("Sorry, the site '%s' does not exists.") % site_name
            return completed
        self.load(site_name)

        site_path, root_path, log_path, upload_tmp_path = self.generate_dir()
        errors = False

        if self.conf.get("mysql", "enabled"):
            schema = self.conf.get("mysql", "schema")
            if inputs.get_input_yesno(t("The schema '%s' will be converted. Continue?") % schema):
                filename = "/tmp/site_convert_toprod_%s" % uuid.uuid4()
                if not (self.dump_bd(filename) and self.schema_toprod(filename) and self.restore_bd(filename)):
                    L.error(t("Fail to convert schema"))
                    errors = True
                files.rm(filename)

        if errors and not inputs.get_input_yesno(t("There was some errors. Continue?")):
            completed = False
            return completed

        if inputs.get_input_yesno(t("The files under %s will be converted. Continue??") % root_path):
            site_name = self.conf.get("main", "site_name")
            site_name_escape = site_name.replace(".", "\.")
            file_list = self.get_file_list(root_path)
            for f in file_list:
                print t("Converting file %s") % f
                files.re_replace_in(f, "(dev\.)*%s" % site_name_escape, site_name)

        robot = root_path + "/robots.txt"
        prodrobot = root_path + "/robots.txt.prod"

        if files.exists(robot):
            self.show_file(t("------- ROBOTS.TXT --------"), robot)
        if files.exists(prodrobot):
            self.show_file(t("------- ROBOTS.TXT.PROD --------"), prodrobot)

        if files.exists(prodrobot) and inputs.get_input_yesno(
            t("The file robots.txt.prod exists. Do you want to replace robots.txt with it?")
        ):
            files.cp(prodrobot, robot)
        if (
            not files.exists(prodrobot)
            and files.exists(robot)
            and inputs.get_input_yesno(
                t("Warning the %s files DOES NOT exists. Answer Yes to DELETE robots.txt") % prodrobot
            )
        ):
            files.rm(robot)

        completed = True
        return completed
示例#6
0
 def run(self, args=[]):
     ret_code = 0
     name = self.get_next_arg(args)
     if name in self.get_registree_names():
         ret_code = self.get(name).run(args[1:])
     else:
         core.CONFIG.mod('core', 'tool_name', "%s" % self.get_log_name())
         L.reset_logger()
         ret_code = self.do(args)
     return ret_code
示例#7
0
文件: site.py 项目: pylanglois/uwsa
 def output_config(self):
     try:
         if inputs.get_input_yesno(t("Do you want to send configuration of %(name)s to %(mail)s?") %
                                     {   'name': self.conf.get('main','site_name'), 
                                         'mail': CONF_MAP('mail','admin_mail'),
                                     }):
             self.send_status_mail()
     except Exception:
         L.exception(t("Problem sending mail in %s") % __file__)
     print self.gen_status_msg()
示例#8
0
def ldap_centrify_refresh(self, ldap_group=None, ldap_user=None):

    cmd_list = ['adflush','adreload','sleep 15','adinfo']

    if ldap_user:
        cmd_list.append('adquery user -A %s' % ldap_user)
    if ldap_group:
        cmd_list.append('adquery group -A %s' % ldap_group)

    completed, pinfo = core.exec_cmd_list(cmd_list)
    if not completed:
        L.error(t("Cannot reload AD after LDAP user/group creation!"))
示例#9
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
示例#10
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
示例#11
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
示例#12
0
    def restore_bd(self, filename):
        schema = self.conf.get("mysql", "schema")
        user = self.conf.get("mysql", "user")
        password = self.conf.get("mysql", "pass")

        cmd_list = [
            {
                "command": "bash -c 'mysql -u %s -p%s %s < %s'" % (user, password, schema, filename),
                "anonymous": "bash -c 'mysql -u %s -p%s %s < %s'" % (user, "XXXXX", schema, filename),
            }
        ]

        completed, pinfo = core.exec_cmd_list(cmd_list)
        if not completed:
            L.error(t("Failed to restore schema %s!") % schema)
        return completed
示例#13
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
示例#14
0
    def dump_bd(self, filename):
        schema = self.conf.get("mysql", "schema")
        user = self.conf.get("mysql", "user")
        password = self.conf.get("mysql", "pass")

        cmd_list = [
            {
                "command": "bash -c 'mysqldump -u%s -p%s --single-transaction --routines --triggers %s > %s'"
                % (user, password, schema, filename),
                "anonymous": "bash -c 'mysqldump -u%s -p%s --single-transaction --routines --triggers %s > %s'"
                % (user, "XXXXX", schema, filename),
            }
        ]

        completed, pinfo = core.exec_cmd_list(cmd_list)
        if not completed:
            L.error(t("Failed to dump schema %s!") % schema)
        return completed
示例#15
0
文件: site.py 项目: pylanglois/uwsa
    def try_acl_activation(self):
        unix_group = self.conf.get('access','unix_group')
        ldap_group = self.conf.get('access','ldap_group')
        cmd_list = []

        if unix_group:
            #unix_acl = self.generate_acl(unix_group)
            cron_fullpath = "/etc/cron.acl/%s" % self.get_safe_name(unix_group)
            cmd_list.append(cron_fullpath)

        if ldap_group:
            #ldap_acl = self.generate_acl(ldap_group)
            cron_fullpath = "/etc/cron.acl/%s" % self.get_safe_name(ldap_group)
            cmd_list.append(cron_fullpath)

        if len(cmd_list) > 0:
            completed, pinfo = core.exec_cmd_list(cmd_list)
            if not completed:
                L.error(t("ACL not applied properly, probably because centrify is not updated. "
                          "You will need to apply them manually or wait the auto apply..."))
示例#16
0
    def fix_path(self, args):
        completed = False
        args.remove("fixpath")

        old_path = self.get_next_path(args)
        args.remove(old_path)
        site_name = self.ask_site_name(self.get_next_arg(args))

        if not self.is_conf_exists(site_name):
            completed = True
            print t("Sorry, the site '%s' does not exists.") % site_name
            return completed
        self.load(site_name)

        site_path, root_path, log_path, upload_tmp_path = self.generate_dir()
        errors = False

        if self.conf.get("mysql", "enabled"):
            schema = self.conf.get("mysql", "schema")
            if inputs.get_input_yesno(t("The paths in schema '%s' will be converted. Continue?") % schema):
                filename = "/tmp/site_convert_fixpath_%s" % uuid.uuid4()
                if not (
                    self.dump_bd(filename)
                    and self.schema_fix_webroot_path(filename, old_path_name=old_path)
                    and self.restore_bd(filename)
                ):
                    L.error(t("Fail to convert schema"))
                    errors = True
                files.rm(filename)

        if errors and not inputs.get_input_yesno(t("There was some errors. Continue?")):
            completed = False
            return completed

        if inputs.get_input_yesno(t("The files under %s will be converted. Continue??") % root_path):
            file_list = self.get_file_list(root_path)
            for f in file_list:
                print t("Converting file %s") % f
                files.re_replace_in(f, old_path, root_path)
示例#17
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
示例#18
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
示例#19
0
        if (
            not is_admin
            and unix.is_notunix_user(pam_user)
            and CONF_MAP("ldap", "enabled")
            and CONF_MAP("centrify", "pam_allow_workaround")
        ):
            is_allowed_to_login = False
            with open("/etc/centrifydc/groups.allow", "r") as f:
                for group in f:
                    group = group.strip()
                    if group:
                        print pam_user, group, ldap.is_member_of(pam_user, group, "")
                        is_allowed_to_login |= ldap.is_member_of(pam_user, group, "")
            if not is_allowed_to_login:
                L.error(t("%s is not allowed here! Bye!") % pam_user)
                exit(1)

        if not is_admin:
            cmd_list = [
                "mkdir -p /home/%(user)s" % {"user": pam_user},
                "chown root:%(user)s /home/%(user)s" % {"user": pam_user},
                "chmod g+rx /home/%(user)s" % {"user": pam_user},
                "run-parts --report  %s" % CONF_MAP("libpam_script", "auto_mount_dir"),
            ]

            completed, pinfo = core.exec_cmd_list(cmd_list)
            # if not completed:
            #    L.error(t("Chrooting is NOT working! %s") % pinfo)
        else:
            print t("Hi!")
示例#20
0
文件: site.py 项目: pylanglois/uwsa
    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)