SILENT KILLERPanel

Current Path: > > opt > cloudlinux > venv > lib64 > python3.11 > site-packages > lvestats > lib > > commons


Operation   : Linux premium131.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
Software     : Apache
Server IP    : 162.0.232.56 | Your IP: 216.73.216.111
Domains      : 1034 Domain(s)
Permission   : [ 0755 ]

Files and Folders in: //opt/cloudlinux/venv/lib64/python3.11/site-packages/lvestats/lib//commons

NameTypeSizeLast ModifiedActions
__pycache__ Directory - -
__init__.py File 219 bytes May 30 2025 10:30:46.
argparse_utils.py File 11516 bytes May 30 2025 10:30:46.
dateutil.py File 5738 bytes May 30 2025 10:30:46.
decorators.py File 893 bytes May 30 2025 10:30:46.
func.py File 16268 bytes May 30 2025 10:30:46.
htpasswd.py File 2304 bytes May 30 2025 10:30:46.
litespeed.py File 6833 bytes May 30 2025 10:30:46.
logsetup.py File 4610 bytes May 30 2025 10:30:46.
proctitle.py File 2966 bytes May 30 2025 10:30:46.
profiler.py File 575 bytes May 30 2025 10:30:46.
progress.py File 1016 bytes May 30 2025 10:30:46.
sentry.py File 6313 bytes May 30 2025 10:30:46.
server_status.py File 1346 bytes May 30 2025 10:30:46.
sizeutil.py File 2653 bytes May 30 2025 10:30:46.
users_manager.py File 3042 bytes May 30 2025 10:30:46.

Reading File: //opt/cloudlinux/venv/lib64/python3.11/site-packages/lvestats/lib//commons/users_manager.py

#!/usr/bin/python
# coding=utf-8

# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
import logging
from collections import namedtuple
from typing import Optional, Dict, Generator, Tuple, List  # NOQA

from clcommon import cpapi, FormattedException
from lvestats.lib.commons import func


class UserNotFoundError(FormattedException):
    pass


class User(namedtuple('User', ['username', 'domain', 'reseller'])):
    pass


class UsersInfoManager(object):
    """
    Implements some different functions for user management;
    """
    def __init__(self):
        self.users_cache = {}  # type: Dict[str, User]

    def build_users_cache(self, reseller):
        # type: (Optional[str]) -> None
        """Cache data from cpapi for given reseller"""
        try:
            self.users_cache = dict(self._iter_panel_users(reseller))
        except cpapi.NotSupported:
            logging.info("Control panel API is not implemented, "
                         "some features may not work properly")

    def _iter_panel_users(self, reseller):
        # type: (Optional[str]) -> Generator[Tuple[str, User]]
        for login, reseller_, domain in self._iter_panel_users_tuples(reseller):
            yield login, User(username=login, reseller=reseller_, domain=domain)

    @staticmethod
    def _iter_panel_users_tuples(reseller):
        # type: (Optional[str]) -> Tuple[str, str, str]
        if reseller is None:
            for login, reseller_, domain in cpapi.cpinfo(keyls=('cplogin', 'reseller', 'dns')):
                yield login, reseller_, domain
        else:
            # TODO: do we really need get_reseller_domains?
            for login, domain in list(func.get_reseller_domains(reseller).items()):
                yield login, reseller, domain

    def get_domain(self, username, raise_exc=True):
        # type: (str, bool) -> Optional[str]
        """Get domain for user"""
        try:
            return self.users_cache[username].domain
        except KeyError as e:
            if raise_exc:
                raise UserNotFoundError({
                    'message': "An error occurred while getting domain for user %(username)s",
                    'context': {'username': username}}) from e
            return None

    def get_reseller(self, username, raise_exc=True):
        # type: (str, bool) -> Optional[str]
        """Get reseller for user"""
        try:
            return self.users_cache[username].reseller
        except KeyError as e:
            if raise_exc:
                raise UserNotFoundError({
                    'message': "An error occurred while getting reseller for user %(username)s",
                    'context': {'username': username}}) from e
            return None

    def get_login_list(self):
        # type: () -> List[str]
        """Get list of cached users"""
        return list(self.users_cache.keys())


g_users_manager = UsersInfoManager()

SILENT KILLER Tool