ok
Direktori : /opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/hooks/cpanel/ |
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clwpos/hooks/cpanel/admin_disable_caching.py |
#!/opt/cloudlinux/venv/bin/python3 -sbb # -*- 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 import json import os import sys from collections import defaultdict from clcommon.cpapi import docroot as get_docroot from clwpos.hooks.lib.admin_disable_caching import ( _run_pre_hook, _run_post_hook ) from clwpos.utils import WposUser, get_parent_pid def main(args): """ If admin triggers this function we are checking all affected users wps for compatibility Need optimization in future Hook is triggered by events Web - WHM: -> MultiPHP Manager: -> User Domain Settings CLI - Whostmgr Lang::PHP::set_vhost_versions post """ domains_affected = {v for k, v in args['data'].items() if 'vhost' in k} # Create 'users_affected_map' dictionary with: # key - user, # value - user's affected domains and docroots. # Example: { # WposUser('user1'): {'domains_affected': {'user1.com'}, # 'docroots_affected': {'/home/user1/public_html'}}, # WposUser('user2'): {'domains_affected': {'user2.com'}, # 'docroots_affected': {'/home/user2/public_html'}} # } users_affected_map = defaultdict( lambda: {'docroots_affected': set(), 'domains_affected': set()} ) for domain in domains_affected: docroot, username = get_docroot(domain) user = WposUser(username) users_affected_map[user]['domains_affected'].add(domain) users_affected_map[user]['docroots_affected'].add(docroot.rstrip('/')) hook_type = args['hook']['stage'] if hook_type == 'pre' and 'version' in args['data']: _run_pre_hook(users_affected_map) elif hook_type == 'post': _run_post_hook(users_affected_map) if __name__ == '__main__': argv = json.loads(sys.stdin.read()) pid = get_parent_pid() # set special envars, further when wp-cli will be called, # presence of these envars will mean to use PHP version that had been written to the special file os.environ.update({'CLWPOS_USE_SAVED_PHP_VERSION': '1', 'CLWPOS_PHP_FILE_ID': str(pid)}) sys.exit(main(argv))