Example #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
Example #2
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
Example #3
0
    def run(self):
        print "pre install"
        _install.run(self)

        #script link
        source = "%s/uwsas/uwsa.py" % self.install_lib
        link = "/usr/local/bin/uwsa"
        if not files.exists(link):
            files.symlink(source,link)
        files.chmod(link, u="rx",g="rx",o="rx")

        #validate v0.3.1 old path
        if files.exists("/usr/local/lib/uwsa") and \
            inputs.get_input_yesno(t("The old uwsa path exists. Do you want to move its content to new destination?")):
            cmd_list = [
                "bash -c 'mkdir -p /var/lib/uwsa'",
                "bash -c 'cp -fr /usr/local/lib/uwsa/* /var/lib/uwsa/'",
            ]
            completed, pinfo = core.exec_cmd_list(cmd_list)
            if completed:
                cmd_list = [
                    "bash -c 'mv /usr/local/lib/uwsa /usr/local/lib/uwsa_to_delete'",
                ]
                completed, pinfo = core.exec_cmd_list(cmd_list)
            files.replace_in('/etc/uwsa/uwsa.conf','/usr/local/lib/uwsa','/var/lib/uwsa')

        #validate v0.4 remove mysql_xxx in conf

        all_conf = files.ls("/var/lib/uwsa/site/*")
        for f in all_conf:
            if files.is_file(f):
                files.replace_in(f,'mysql_schema','schema')
                files.replace_in(f,'mysql_user','user')
                files.replace_in(f,'mysql_pass','pass')

        #install prereque
        dependencies = "python-ldap python-iniparse python-mysqldb"
        print t("Will install"), dependencies
        cmd_list = [
            'apt-get update',
            "bash -c 'DEBIAN_FRONTEND=noninteractive apt-get install -y %s'" % dependencies,
        ]
        completed, pinfo = core.exec_cmd_list(cmd_list)
        if not completed:
            raise Exception(t("Cannot install uwsa dependencies! %s" % dependencies))

        print t("post install DONE!")
Example #4
0
    def fix_ses_close(self, element):

        if not files.exists(element['name']):
            files.append(element['name'], "#! /bin/sh")
Example #5
0
 def check_ses_close(self, element):
     is_ok = True
     is_ok &= files.exists(element['name'])
     return is_ok
Example #6
0
 def is_conf_exists(self, site_name):
     safe_site_name = self.get_safe_name(site_name)
     conf_path = "%s/%s" % (CONF_MAP('site','conf_path'), safe_site_name)
     return files.exists(conf_path)
Example #7
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)
Example #8
0
 def fix_user_allow(self, element):
     if not files.exists(element['name']):
         files.create(element['name'], '')