Hackfut Security File Manager
Current Path:
/opt/alt/python37/lib/python3.7/site-packages/clwpos
opt
/
alt
/
python37
/
lib
/
python3.7
/
site-packages
/
clwpos
/
📁
..
📄
__init__.py
(665 B)
📁
__pycache__
📄
cl_wpos_exceptions.py
(3.51 KB)
📄
collect_information.py
(5.15 KB)
📄
constants.py
(3.13 KB)
📄
daemon.py
(26.29 KB)
📄
daemon_base.py
(5.1 KB)
📄
daemon_main.py
(963 B)
📄
daemon_redis_lib.py
(12.58 KB)
📁
feature_suites
📁
hooks
📄
logsetup.py
(4.37 KB)
📁
object_cache
📁
optimization_features
📄
parse.py
(2.21 KB)
📄
redis_configuration_pid_file_cleaner.py
(998 B)
📄
report_generator.py
(18.37 KB)
📄
socket_utils.py
(3.95 KB)
📄
stats.py
(3.57 KB)
📁
user
📄
utils.py
(33.13 KB)
📄
wp_config.py
(725 B)
📄
wpos_admin.py
(25.71 KB)
📄
wpos_hooks.py
(3.89 KB)
📄
wpos_req_scanner.py
(4.38 KB)
Editing: stats.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 import os import pwd from typing import List from clcommon import cpapi from clcommon.clpwd import drop_privileges from clwpos.logsetup import setup_logging from clwpos.optimization_features import ALL_OPTIMIZATION_FEATURES from clwpos.feature_suites import get_allowed_modules from clwpos.utils import get_admin_options from clwpos.user.config import UserConfig _logger = setup_logging('clwpos_statistics') def get_sites_count_with_enabled_wpos_statistics(user: str, checked_modules: List[str]) -> int: """ Calculates total count of sites with at least one enabled module per user """ count = 0 try: with drop_privileges(user): uc = UserConfig(user) count = uc.get_enabled_sites_count_by_modules(checked_modules) except Exception as e: _logger.warning('Error while getting info from clwpos user config %s', str(e)) return count return count def get_users_count_with_allowed_wpos_statistics(user: str, checked_modules: List[str]) -> int: """ Checks if there are any allowed modules for user """ try: uid = pwd.getpwnam(user).pw_uid except KeyError: _logger.debug('Unable to get uid for %s', user) return False allowed_modules = get_allowed_modules(uid) return any(checked_module in allowed_modules for checked_module in checked_modules) def _get_wpos_statistics_total_count(modules: List[str], kind: str = 'allowed'): """ Returns total count of users with allowed wpos module or total count of sites with enabled wpos module for all panel users on server """ total_count = 0 panel_users = cpapi.cpusers() for user in panel_users: if kind == 'allowed': if get_users_count_with_allowed_wpos_statistics(user, modules): total_count += 1 else: total_count += get_sites_count_with_enabled_wpos_statistics(user, modules) return total_count def is_accelerate_wp_icon_enabled(): """ Obtains admin`s options, e.g show_icon """ try: options = get_admin_options() except Exception as e: _logger.error('Error when getting admin options: %s', str(e)) return -42 return options.get('show_icon') def fill_current_wpos_statistics(): """ Returns current statistics with enabled sites/allowed users counters per module and in total """ is_feature_flag = os.path.isfile('/var/lve/enable-wpos.flag') is_feature_icon_enabled = is_accelerate_wp_icon_enabled() result = { 'allowed_users': dict(), # total: # object_cache: # site_optimization: 'enabled_sites': dict(), # total: # object_cache: # site_optimization: 'is_accelerate_wp_flag_enabled': is_feature_flag, 'is_accelerate_wp_icon_enabled': is_feature_icon_enabled } result['allowed_users']['total'] = _get_wpos_statistics_total_count( ALL_OPTIMIZATION_FEATURES, 'allowed') result['enabled_sites']['total'] = _get_wpos_statistics_total_count( ALL_OPTIMIZATION_FEATURES, 'enabled') for module in ALL_OPTIMIZATION_FEATURES: result['allowed_users'][module] = _get_wpos_statistics_total_count( [module], 'allowed') result['enabled_sites'][module] = _get_wpos_statistics_total_count( [module], 'enabled') return result
Upload File
Create Folder