%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/clwpos/hooks/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/clwpos/hooks/wpos_modify_user_hook.py

# coding=utf-8
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

from __future__ import absolute_import, print_function

import os
import subprocess
import sys

from clcommon.clpwd import drop_privileges
from clcommon.public_hooks.lib import ModifyUserHook
from clwpos.cl_wpos_exceptions import WposError
from clwpos.optimization_modules import OBJECT_CACHE_MODULE
from clwpos.user.config import UserConfig
from clwpos.utils import WposUser, update_redis_conf, update_wp_config
from cpanel import reload_redis


class WposModifyUserHook(ModifyUserHook):
    """
    Update user's data in Redis and WP configs.
    """

    def post_modify_user(self, username: str, new_name: str = None, **kwargs):
        """
        Update the name of the user's home directory in:
        - ~/.clwpos/redis.conf,
        - wp-config.php for Wordpresses with enabled WPOS object cache module.
        """
        if new_name is None:
            return

        new_user = WposUser(new_name)
        if not new_user.home_dir.endswith(new_name):
            raise WposError('Internal Error. Contact CloudLinux support')
        old_user_homedir = os.path.join(new_user.home_dir[:-len(new_name)], username)
        old_user = WposUser(username, homedir=old_user_homedir)

        with drop_privileges(new_name):
            # Update ~/.clwpos/redis.conf
            if not os.path.exists(new_user.redis_conf):
                # we don't continue if redis.conf is missing
                # because it means that user has never enabled the module
                return

            update_redis_conf(new_user, old_user)

            # Update wp-config.php files
            # use user's WPOS config to get paths to Wordpresses with WPOS object cache enabled
            user_config = UserConfig(new_name)
            for abs_wp_path in user_config.wp_paths_with_enabled_module(OBJECT_CACHE_MODULE):
                update_wp_config(abs_wp_path, new_user, old_user)

            try:
                reload_redis()
            except Exception as e:
                print(f'Error occurred during daemon reload: {e}', file=sys.stderr)

    def post_create_user(self, username, owner, **kwargs):
        subprocess.run(["/opt/alt/python37/bin/python3", "/usr/sbin/clwpos_collect_information.py", username])

Zerion Mini Shell 1.0