HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/rdp.cpython-310.pyc
o

�N�g8�@s�dZddlZddlZddlZddlmZzddlZddlm	Z
dZWney-dZYnwe�
e�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zee�ddd��Zee�dd��Zee�dd��Zee�dd��ZdS)z'
Manage RDP Service on Windows servers
�N)�depends)�errorTFcCstjj��rdSdS)z'
    Only works on Windows systems
    �rdp)FzModule only works on Windows.)�salt�utils�platformZ
is_windows�rr�D/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/rdp.py�__virtual__sr
cCs"t�d|�}|s
dSt|�d��S)zP
    return from the input string the return code of the powershell command
    zReturnValue\s*: (\d*))Fz'Could not parse PowerShell return code.�)�re�search�int�group)�stringZregexrrr	�_parse_return_code_powershellsrcCs d}td|�d|��ddd�S)z�
    Create a Win32_TerminalServiceSetting WMI Object as $RDP and execute the
    command cmd returns the STDOUT of the command
    z�$RDP = Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace root\CIMV2\TerminalServices -Computer . -Authentication 6 -ErrorAction Stopzcmd.runz ; Z
powershellT)�shellZpython_shell)Z__salt__)�cmdrrrr	�_psrdp+s�rcC�ttd��dkS)zw
    Enable RDP the service on the server

    CLI Example:

    .. code-block:: bash

        salt '*' rdp.enable
    z$RDP.SetAllowTsConnections(1,1)r�rrrrrr	�enable8�rcCr)zy
    Disable RDP the service on the server

    CLI Example:

    .. code-block:: bash

        salt '*' rdp.disable
    z$RDP.SetAllowTsConnections(0,1)rrrrrr	�disableFrrcCsttd����}|dkS)zw
    Show if rdp is enabled on the server

    CLI Example:

    .. code-block:: bash

        salt '*' rdp.status
    zecho $RDP.AllowTSConnectionsr)rr�strip)�outrrr	�statusTsrc
Cs&t�}tj}tjdtjdtjdi}tjdtjdtjdtj	dtj
dtjd	tjd
tj
dtjdtjd
i
}t�|�D]M}t�||dtj�pCd}t�||dtj�}t�||dtj�}|�|d�}	|�|d�}
|dpid}|
|	|d||d�}|r~|r}|�|�q6|�|�q6|s�t�d�t|dd�d�S)a9
    List information about the sessions.

    .. versionadded:: 2016.11.0

    :param logged_in_users_only: If True, only return sessions with users logged in.
    :return: A list containing dictionaries of session information.

    CLI Example:

    .. code-block:: bash

        salt '*' rdp.list_sessions
    ZconsoleZcitrixrZactive�	connectedZ
connect_queryZshadowZdisconnectedZidle�listen�resetZdown�initZ	SessionIdN�unknownZWinStationNameZDisconnected)�connection_status�protocol�
session_id�station�userzNo sessions found.cSs|dS)Nr$r)�krrr	�<lambda>�szlist_sessions.<locals>.<lambda>)�key)�list�win32ts�WTS_CURRENT_SERVER_HANDLEZWTS_PROTOCOL_TYPE_CONSOLEZWTS_PROTOCOL_TYPE_ICAZWTS_PROTOCOL_TYPE_RDPZ	WTSActiveZWTSConnectedZWTSConnectQueryZ	WTSShadowZWTSDisconnectedZWTSIdleZ	WTSListenZWTSResetZWTSDownZWTSInitZWTSEnumerateSessionsZWTSQuerySessionInformationZWTSUserNameZWTSClientProtocolTypeZWTSConnectState�get�append�_LOG�warning�sorted)
Zlogged_in_users_only�retZserverZ	protocolsZstatuses�sessionr&Zprotocol_idZ	status_idr#r"r%Zconnection_inforrr	�
list_sessionscs\��
�����
�
r4cs>t�}t�}�fdd�|D�}|r|d}|st�d��|S)a2
    Get information about a session.

    .. versionadded:: 2016.11.0

    :param session_id: The numeric Id of the session.
    :return: A dictionary of session information.

    CLI Example:

    .. code-block:: bash

        salt '*' rdp.get_session session_id

        salt '*' rdp.get_session 99
    csg|]
}|d�kr|�qS�r$r)�.0�itemr5rr	�
<listcomp>�szget_session.<locals>.<listcomp>rzNo session found for id: %s)�dictr4r/r0)r$r2Zsessionsr3rr5r	�get_session�sr:c
C�Jzt�tj|d�WdSty$}z
t�d|�WYd}~dSd}~ww)aI
    Disconnect a session.

    .. versionadded:: 2016.11.0

    :param session_id: The numeric Id of the session.
    :return: A boolean representing whether the disconnect succeeded.

    CLI Example:

    .. code-block:: bash

        salt '*' rdp.disconnect_session session_id

        salt '*' rdp.disconnect_session 99
    Tz&Error calling WTSDisconnectSession: %sNF)r+ZWTSDisconnectSessionr,�
PyWinErrorr/r�r$rrrr	�disconnect_session�s����r>c
Cr;)aI
    Initiate the logoff of a session.

    .. versionadded:: 2016.11.0

    :param session_id: The numeric Id of the session.
    :return: A boolean representing whether the logoff succeeded.

    CLI Example:

    .. code-block:: bash

        salt '*' rdp.logoff_session session_id

        salt '*' rdp.logoff_session 99
    Tz"Error calling WTSLogoffSession: %sNF)r+ZWTSLogoffSessionr,r<r/rr=rrr	�logoff_session�s���r?)F)�__doc__�loggingrZsalt.utils.platformrZsalt.utils.decoratorsrr+Z
pywintypesrr<Z_HAS_WIN32TS_DEPENDENCIES�ImportError�	getLogger�__name__r/r
rrrrrr4r:r>r?rrrr	�<module>s6�
	
E