Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/rads/__pycache__/_users.cpython-39.pyc
Ðазад
a � hI � @ s d Z ddlmZ ddlZddlZddlZddlZddlZddlm Z m Z mZmZ ddl Z ddlmZ ddlmZmZmZ G dd � d e�Zed �dd�Zd e_eed�dd�Zd e_ed3e d ee d�dd��Zed4e d eeef d�dd��Zd5eeeeef ee f d�dd�Zd e_ed �dd�Zd e_eed�dd�Zd e_eed�dd�Z d e _eee d�dd �Z!d e!_eed�d!d"�Z"d e"_eed�d#d$�Z#d e#_ed%�d&d'�Z$d e$_eed�d(d)�Z%d e%_eed*�d+d,�Z&d e&_ee e d�d-d.�Z'd e'_G d/d0� d0�Z(G d1d2� d2�Z)dS )6z2Functions for fetching basic info on user accounts� )�PathN)�Literal�Optional�Union�overload� )�DumbYamlLoader)� SYS_USERS�STAFF_GROUPS� OUR_RESELLERSc @ s e Zd ZdZdZdS )�CpuserErrorz?Raised when there's something wrong collecting cPanel user info�radsN)�__name__� __module__�__qualname__�__doc__� r r �:/opt/imh-python/lib/python3.9/site-packages/rads/_users.pyr s r ��returnc C s4 zt �� } W n" ty. t�t �� �j} Y n0 | S )zEObtain which user ran this script Returns: username )�os�getlogin�OSError�pwd�getpwuid�geteuid�pw_name)Zblamer r r � get_login s r r )�userr c C s` zt �| �j}W n ty$ Y dS 0 ttj�|�tj�tj� d| ��tj�tj� d| ��f�S )aB Checks if a user is a valid cPanel user. Warning: This only checks if the user exists and will also be true for restricted cPanel users. Use ``cpuser_safe`` instead if you need to check for those Args: user: cPanel username to check Returns: Whether the cPanel user exists Fz/var/cpanel/users�/var/cpanel/userdata) r �getpwnam�pw_dir�KeyError�allr �path�isdir�isfile�join)r �homedirr r r � is_cpuser% s ��r) F)�ownersr c C s d S �Nr �r* r r r �all_cpusers@ s r- Tc C s d S r+ r r, r r r r- D s c C s^ t ddd��}t�|t�}W d � n1 s.0 Y t|t�sJtd��| rR|S t|�� �S )a( Returns cPanel users from /etc/trueuserowners Args: owners: whether to return users as a dict with owners as the values Raises: CpuserError: if /etc/trueuserowners is invalid Returns: either a list of all users, or a dict of users (keys) to owners (vals) z/etc/trueuserowners�utf-8��encodingNz/etc/trueuserowners is invalid) �open�yaml�loadr � isinstance�dictr �list�keys)r* Z userownersZuserdictr r r r- H s * c C s dd� t dd��� D �S )zxGet a all non-child, non-system, "main" cPanel users Raises: CpuserError: if /etc/trueuserowners is invalidc S s$ g | ]\}}|t v s||kr|�qS r )r )�.0r �ownerr r r � <listcomp>c s �z main_cpusers.<locals>.<listcomp>Tr, �r- �itemsr r r r �main_cpusers^ s �r= c C sJ zt dd�| W S tyD } zt| � d��|�W Y d}~n d}~0 0 dS )a� Get a user's owner (even if the account has reseller ownership of itself) Warning: the owner may be root, which is not a cPanel user Hint: If looking this up for multiple users, use ``get_cpusers(owners=True)`` instead Args: user: cPanel username to find the owner for Raises: CpuserError: if /etc/trueuserowners is invalid or the requested user is not defined in there Tr, z is not in /etc/trueuserownersN)r- r"