HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //lib/python3.9/site-packages/ansible/plugins/shell/__pycache__/powershell.cpython-39.pyc
a

�)gp,�@s�ddlmZmZmZeZdZddlZddlZddl	Z	ddl
Z
ddlZddlm
mZddlZddlmZmZddlmZgd�Zddd	�ZGd
d�de�ZdS)
�)�absolute_import�division�print_functionaL
name: powershell
version_added: historical
short_description: Windows PowerShell
description:
- The only option when using 'winrm' or 'psrp' as a connection plugin.
- Can also be used when using 'ssh' as a connection plugin and the C(DefaultShell) has been configured to PowerShell.
extends_documentation_fragment:
- shell_windows
N)�to_bytes�to_text)�	ShellBase)Z
PowerShellz
-NoProfilez-NonInteractivez-ExecutionPolicyZUnrestricted�Errorc	s�g}|r�|�d�d}||�d�|�}||d�}t�|�}t�d|j�}|r^d|�d�nd}|�d	|�}|��fd
d�|D��qt	d�
|��S)
z�
    Takes a byte string like '#< CLIXML
<Objs...' and extracts the stream
    message encoded in the XML data. CLIXML is used by PowerShell to encode
    multiple objects in stderr.
    s</Objs>�s<Objs Nz{(.*)}z{%s}��z./%sScs*g|]"}|j�d��kr|j�dd��qS)�SZ_x000D__x000A_r)Zattrib�get�text�replace)�.0�e��stream��D/usr/lib/python3.9/site-packages/ansible/plugins/shell/powershell.py�
<listcomp>7�z!_parse_clixml.<locals>.<listcomp>z
)�find�ETZ
fromstring�re�match�tag�group�findall�extendr�join)	�datar�linesZend_idxZcurrent_elementZclixmlZnamespace_match�	namespace�stringsrrr�
_parse_clixml!s
r%c@s�eZdZe�ZdZdZdZdZdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zd*dd�Zd+dd�Zd,dd�Zdd�Zdd�Zd-d d!�Zd"d#�Zd$d%�Zd&d'�Zd.d(d)�ZdS)/�ShellModuleZ
powershellz> $null�;TcKsdS)Nrr)�self�kwargsrrr�
env_prefixMszShellModule.env_prefixcs:�fdd�|D�}tj|dgdd�|dd�D��R�S)Ncsg|]}t���|���qSr)�ntpath�normpath�_unquote)r�arg�r(rrrSrz)ShellModule.join_path.<locals>.<listcomp>rcSsg|]}|�d��qS)�\��strip)r�partrrrrXrr
)r+r )r(�args�partsrr/r�	join_pathQszShellModule.join_pathcCs@tj�|���}tj�|���\}}|��dvr8|dS|��S)N)�.ps1z.exer7)�os�path�basenamer2�splitext�lower)r(�pathname�	base_name�name�extrrr�get_remote_filenameZs
zShellModule.get_remote_filenamecCs|�|�}|�d�p|�d�S)N�/r0)r-�endswith)r(r9rrr�path_has_trailing_slashcs
z#ShellModule.path_has_trailing_slashcCstd��dS)Nz'chmod is not implemented for Powershell��NotImplementedError)r(�paths�moderrr�chmodhszShellModule.chmodcCstd��dS)Nz'chown is not implemented for PowershellrE)r(rG�userrrr�chownkszShellModule.chowncCstd��dS)Nz/set_user_facl is not implemented for PowershellrE)r(rGrJrHrrr�
set_user_faclnszShellModule.set_user_faclFcCs4|�|�|��}|r"|�d|�S|�d|�SdS)Nz!Remove-Item '%s' -Force -Recurse;zRemove-Item '%s' -Force;��_escaper-�_encode_script)r(r9Zrecurserrr�removeqszShellModule.removeNcCsJ|s|j��}|�|�|��}|r&|n|�d�}d||f}|�|���S)NZ
remote_tmpz�
        $tmp_path = [System.Environment]::ExpandEnvironmentVariables('%s')
        $tmp = New-Item -Type Directory -Path $tmp_path -Name '%s'
        Write-Output -InputObject $tmp.FullName
        )�	__class__Z_generate_temp_dir_namerNr-Z
get_optionrOr2)r(Zbasefile�systemrHZtmpdirZ
basetmpdir�scriptrrr�mkdtempxs
�zShellModule.mkdtemprcCsR|�|�}|dkrd}n0|�d�r:d|�|dd��}nd|�|�}|�|�S)N�~z Write-Output (Get-Location).Pathz~\z)Write-Output ((Get-Location).Path + '%s')r
zWrite-Output '%s')r-�
startswithrNrO)r(Zuser_home_path�usernamerSrrr�expand_user�s

zShellModule.expand_usercCs"|�|�|��}d|}|�|�S)Nz�
            If (Test-Path '%s')
            {
                $res = 0;
            }
            Else
            {
                $res = 1;
            }
            Write-Output '$res';
            Exit $res;
         rM)r(r9rSrrr�exists�s
�zShellModule.existscOs(|�|�|��}dt|d�}|�|�S)Na}
            If (Test-Path -PathType Leaf '%(path)s')
            {
                $sp = new-object -TypeName System.Security.Cryptography.SHA1CryptoServiceProvider;
                $fp = [System.IO.File]::Open('%(path)s', [System.IO.Filemode]::Open, [System.IO.FileAccess]::Read);
                [System.BitConverter]::ToString($sp.ComputeHash($fp)).Replace("-", "").ToLower();
                $fp.Dispose();
            }
            ElseIf (Test-Path -PathType Container '%(path)s')
            {
                Write-Output "3";
            }
            Else
            {
                Write-Output "1";
            }
        )r9)rNr-�dictrO)r(r9r4r)rSrrr�checksum�s
�zShellModule.checksumc	Cst�dd�}|dkr$|j|ddd�Stj|dd�}ttt|��}|r�|��dkr�|�	|d����
d	�s~d
|�	|d�|d<d|dd|j|ddd�}|S|r�|�d
�r�|�d|dd��n |s�|�	|d�|d<|�
|�d|d�|�f}|j|dd�S)Nzansible.executor.powershellzbootstrap_wrapper.ps1rF)rS�strict_mode�preserve_rc)�posixz#!powershellrr7z"%s.ps1"ztype z | z#!�a
            Try
            {
                %s
                %s
            }
            Catch
            {
                $_obj = @{ failed = $true }
                If ($_.Exception.GetType)
                {
                    $_obj.Add('msg', $_.Exception.Message)
                }
                Else
                {
                    $_obj.Add('msg', $_.ToString())
                }
                If ($_.InvocationInfo.PositionMessage)
                {
                    $_obj.Add('exception', $_.InvocationInfo.PositionMessage)
                }
                ElseIf ($_.ScriptStackTrace)
                {
                    $_obj.Add('exception', $_.ScriptStackTrace)
                }
                Try
                {
                    $_obj.Add('error_record', ($_ | ConvertTo-Json | ConvertFrom-Json))
                }
                Catch
                {
                }
                Echo $_obj | ConvertTo-Json -Compress -Depth 99
                Exit 1
            }
        � )r])�pkgutil�get_datarO�shlex�split�list�maprr<r-rCrV�insert�appendr )	r(Z
env_stringZshebang�cmdZarg_pathZbootstrap_wrapper�	cmd_partsZwrapper_cmdrSrrr�build_module_command�s& 
#�$z ShellModule.build_module_commandcCsd|S)Nz& %s; exit $LASTEXITCODEr)r(rirrr�
wrap_for_exec�szShellModule.wrap_for_execcCsDt|pd�}t�d|�}|r&|�d�St�d|�}|r@|�d�S|S)z5Remove any matching quotes that wrap the given value.rz^\s*?\'(.*?)\'\s*?$r
z^\s*?"(.*?)"\s*?$)rrrr)r(�value�mrrrr-�s

zShellModule._unquotecCst�d��d|�S)z9Return value escaped for use in PowerShell single quotes.u(['‘’‚‛])z\1\1)r�compile�sub)r(rmrrrrNszShellModule._escapecCs�t|�}|dkrtddg}nR|r*d|}|r6d|}d�dd�|��D��}tt�|�d��d	�}td
|g}|rx|Sd�|�S)z?Convert a PowerShell script to a single base64-encoded command.�-z-Commandz"Set-StrictMode -Version Latest
%szz%s
If (-not $?) { If (Get-Variable LASTEXITCODE -ErrorAction SilentlyContinue) { exit $LASTEXITCODE } Else { exit 1 } }
�
cSsg|]}|��r|���qSrr1)r�xrrrrrz.ShellModule._encode_script.<locals>.<listcomp>z	utf-16-lezutf-8z-EncodedCommandr`)r�_common_argsr �
splitlines�base64Z	b64encode�encode)r(rSZas_listr\r]rjZencoded_scriptrrrrO
s�zShellModule._encode_script)F)NFNN)r)N)FTT)�__name__�
__module__�__qualname__�	frozensetZCOMPATIBLE_SHELLSZSHELL_FAMILYZ_SHELL_REDIRECT_ALLNULLZ
_SHELL_ANDZ_IS_WINDOWSr*r6rArDrIrKrLrPrTrXrYr[rkrlr-rNrOrrrrr&<s,		




=r&)r)Z
__future__rrr�typeZ
__metaclass__Z
DOCUMENTATIONrvr8rrcraZxml.etree.ElementTreeZetreeZElementTreerr+Zansible.module_utils._textrrZansible.plugins.shellrrtr%r&rrrr�<module>s