%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python2.7/site-packages/salt/modules/
Upload File :
Create Path :
Current File : //lib/python2.7/site-packages/salt/modules/win_iis.pyo

�
���^c@@s�dZddlmZmZmZddlZddlZddlZddlZ	ddl
Z	ddlmZddl
mZmZddlmZeje�ZdZd9Zeedd��ZdZd
�Zdddd�Zdd�Zd�Zed�Zd�Z ddddd	d�Z!ddd�Z#d�Z$d�Z%d�Z&d�Z'd�Z(dddd	dd�Z)ddddd�Z*dddd �Z+d!�Z,ddd"dd#�Z-ddd"d$�Z.d%�Z/d&�Z0d'�Z1d(�Z2d)�Z3d*�Z4d+�Z5d,�Z6d-�Z7dd.�Z8d/�Z9ed0�Z:ed1�Z;ed2�Z<d3�Z=d4�Z>d5�Z?d6�Z@d7�ZAd8�ZBdS(:u'
Microsoft IIS site management via WebAdministration powershell module

:maintainer:    Shane Lee <slee@saltstack.com>, Robert Booth <rbooth@saltstack.com>
:platform:      Windows
:depends:       PowerShell
:depends:       WebAdministration module (PowerShell) (IIS)

.. versionadded:: 2016.3.0
i(tabsolute_importtprint_functiontunicode_literalsN(trange(tSaltInvocationErrortCommandExecutionError(tsixu/uftpuhttpuhttpsiuwin_iiscC@satjjj�stdfStddt�}|dsCtdfSd|dkr]tdfStS(	uW
    Load only on Windows
    Requires PowerShell and the WebAdministration module
    u!Only available on Windows systemsucmd.shell_infou
powershellu	installeduPowerShell not availableuWebAdministrationumodulesuIIS is not installed(tsalttutilstplatformt
is_windowstFalset__salt__tTruet__virtualname__(tpowershell_info((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt__virtual__#s



uu*iPcC@s+dj|tj|�|jdd�g�S(u8
    Combine the host header, IP address, and TCP port into bindingInformation
    format. Binding Information specifies information to communicate with a
    site. It includes the IP address, the port number, and an optional host
    header (usually a host name) to communicate with the site.

    Args:
        host_header (str): Usually a hostname
        ip_address (str): The IP address
        port (int): The port

    Returns:
        str: A properly formatted bindingInformation string (IP:port:hostheader)
            eg: 192.168.0.12:80:www.contoso.com
    u:u u(tjoinRt	text_typetreplace(thost_headert
ip_addresstport((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt_get_binding_info5suMyc
C@s't�}ddg}dddj|�ddg}td|d	t�}y#tjjj|d
dt�}Wnt	k
r�t
d��nXx�|D]�}t�}x1|D])}||kr�||||j�<q�q�Wg|d
<|drg|dD]}	|	d^q�|d
<n|||d<q�W|S(u
    List details of available certificates in the LocalMachine certificate
    store.

    Args:
        certificate_store (str): The name of the certificate store on the local
            machine.

    Returns:
        dict: A dictionary of certificates found in the store
    uDnsNameListu
Thumbprintu
Get-ChildItemu-Pathu'Cert:\LocalMachine\{0}'u|uESelect-Object DnsNameList, SerialNumber, Subject, Thumbprint, Versiontcmdtreturn_jsonustdouttstrictu$Unable to parse return data as Json.udnsnamesuUnicode(tdicttformatt_srvmgrR
RRtjsontloadsRt
ValueErrorRtlower(
tcertificate_storetrettblacklist_keystps_cmdtcmd_rettitemstitemt	cert_infotkeytname((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt_list_certsIs*		#

	


(cC@s�g}|jd�|jd�t|dt�}y#tjjj|ddt�}Wntk
rvt	j
d�dSXtjdj
|d	d
|d	d��S(Nu6Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\InetStp\\u+ | Select-Object MajorVersion, MinorVersionRustdoutRu$Unable to parse return data as Json.i����u{0}.{1}iuMajorVersionuMinorVersion(tappendRR
RRRRRR tlogterrortdecimaltDecimalR(tpscmdR&R'((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt_iisVersionts

#

cC@s�t|t�r!dj|�}n|r9dj|�}ndj|�}td|dddt�}|dd	kr�d
j||d�}tj|�n|S(u:
    Execute a powershell command from the WebAdministration PS module.

    Args:
        cmd (list): The command to execute in a list
        return_json (bool): True formats the return in JSON, False just returns
            the output of the command.

    Returns:
        str: The output from the command
    u u5ConvertTo-Json -Compress -Depth 4 -InputObject @({0})u$Import-Module WebAdministration; {0}ucmd.run_alltshellu
powershelltpython_shelluretcodeiu)Unable to execute command: {0}
Error: {1}ustderr(t
isinstancetlistRRRR
R.R/(RRR#tmsg((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyR�scC@s�t�}dddddg}d!}td
|dt�}y#tjjj|dd
t�}Wntk
r{t	d��nXx<|D]4}t�}x�|ddD]�}|dd"kr�q�nt�}x;|D]3}	|	|kr�|j
i||	|	j�6�q�q�W|djdd�}
g|
D]}|j
�^q!\}}
}|j
i|d6|d6|
d6�|||d<q�Wi|dd6|d6|dd6|dd6|dd6||d<q�W|s�tjd |d�n|S(#u�
    List all the currently deployed websites.

    Returns:
        dict: A dictionary of the IIS sites and their properties.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_sites
    u
Get-ChildItemu-Pathu'IIS:\Sites'u|uFSelect-Object applicationPool, Bindings, ID, Name, PhysicalPath, StateucertificateHashucertificateStoreNameuprotocolusslFlagsRRustdoutRu$Unable to parse return data as Json.ubindingsu
CollectionuhttpuhttpsubindingInformationu:iu
hostheaderu	ipaddressuportuapplicationPooluapppooluidustateuphysicalPathu
sourcepathunameuNo sites found in output: %s(ucertificateHashucertificateStoreNameuprotocolusslFlags(uhttpuhttps(RRR
RRRRRR RtupdateR!tsplittstripR.twarning(R#R%t	keep_keysR&R'R(tbindingstbindingtfiltered_bindingR*tbinding_infotelementt	ipaddressRt
hostheader((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
list_sites�sD
		#

		
%(c	C@s�tj|�j�}dj|�}t|||�}t�}	||	kr_tjd|�tS|t	kr�dj|t	�}
t
|
��ndddj|�ddj|�dd	j||�g}|r>|t�kr�tjd
|�ntjd|�t|�|j
dddj|�d
dddj|�g�nt|�}|ddkrdj||d�}
t|
��ntjd|�tS(ud
    Create a basic website in IIS.

    .. note::

        This function only validates against the site name, and will return True
        even if the site already exists with a different configuration. It will
        not modify the configuration of an existing site.

    Args:
        name (str): The IIS site name.
        sourcepath (str): The physical path of the IIS site.
        apppool (str): The name of the IIS application pool.
        hostheader (str): The host header of the binding. Usually the hostname
            or website name, ie: www.contoso.com
        ipaddress (str): The IP address of the binding.
        port (int): The TCP port of the binding.
        protocol (str): The application protocol of the binding. (http, https,
            etc.)

    Returns:
        bool: True if successful, otherwise False.

    .. note::

        If an application pool is specified, and that application pool does not
        already exist, it will be created.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.create_site name='My Test Site' sourcepath='c:\stage' apppool='TestPool'
    uIIS:\Sites\{0}uSite '%s' already present.u4Invalid protocol '{0}' specified. Valid formats: {1}uNew-Itemu-Pathu'{0}'u
-PhysicalPathu	-Bindingsu0@{{ protocol='{0}'; bindingInformation='{1}' }};u+Utilizing pre-existing application pool: %su$Application pool will be created: %suSet-ItemPropertyu-NameuApplicationPoolu-Valueuretcodeiu%Unable to create site: {0}
Error: {1}ustderruSite created successfully: %s(RRR!RRRER.tdebugR
t_VALID_PROTOCOLSRt
list_apppoolstcreate_apppooltextendRR(R+t
sourcepathtapppoolRDRCRtprotocolt	site_pathRAt
current_sitestmessageR%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytcreate_site�sB$			

	c	C@stdj|�}t�}||kr>tjdj|��tSt�}|r�|jdddj|�ddddj|�g�n|r|t�kr�tjd	j|��n tjd
j|��t|�|r�|j	d�n|jdddj|�ddddj|�g�nt
|�}|d
dkr`dj||d�}t|��ntjd|�tS(uU
    Modify a basic website in IIS.

    .. versionadded:: 2017.7.0

    Args:
        name (str): The IIS site name.
        sourcepath (str): The physical path of the IIS site.
        apppool (str): The name of the IIS application pool.

    Returns:
        bool: True if successful, otherwise False.

    .. note::

        If an application pool is specified, and that application pool does not
        already exist, it will be created.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.modify_site name='My Test Site' sourcepath='c:\new_path' apppool='NewTestPool'
    uIIS:\Sites\{0}uSite '{0}' not defined.uSet-ItemPropertyu-Pathu'{0}'u-NameuPhysicalPathu-Valueu,Utilizing pre-existing application pool: {0}u%Application pool will be created: {0}u;uApplicationPooluretcodeiu%Unable to modify site: {0}
Error: {1}ustderruSite modified successfully: %s(
RRER.RFRR7RJRHRIR-RRR
(R+RKRLRNROR%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytmodify_site1s<			

	cC@s�t�}||kr)tjd|�tSdddj|�g}t|�}|ddkr�dj||d�}t|��ntjd	|�tS(
uQ
    Delete a website from IIS.

    Args:
        name (str): The IIS site name.

    Returns:
        bool: True if successful, otherwise False

    .. note::

        This will not remove the application pool used by the site.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.remove_site name='My Test Site'

    uSite already absent: %suRemove-WebSiteu-Nameu'{0}'uretcodeiu%Unable to remove site: {0}
Error: {1}ustderruSite removed successfully: %s(RER.RFR
RRR(R+ROR%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytremove_sitevs	cC@s/ddj|�g}t|�}|ddkS(u%
    Stop a Web Site in IIS.

    .. versionadded:: 2017.7.0

    Args:
        name (str): The name of the website to stop.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.stop_site name='My Test Site'
    uStop-WebSiteu'{0}'uretcodei(RR(R+R%R&((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt	stop_site�scC@s/ddj|�g}t|�}|ddkS(u(
    Start a Web Site in IIS.

    .. versionadded:: 2017.7.0

    Args:
        name (str): The name of the website to start.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.start_site name='My Test Site'
    u
Start-WebSiteu'{0}'uretcodei(RR(R+R%R&((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
start_site�scC@st|�ot|�S(u.
    Restart a Web Site in IIS.

    .. versionadded:: 2017.7.0

    Args:
        name (str): The name of the website to restart.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.restart_site name='My Test Site'
    (RTRU(R+((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytrestart_site�scC@s]t�}t�}||kr2tjd|�|S||d}|sYtjd|�n|S(u 
    Get all configured IIS bindings for the specified site.

    Args:
        site (str): The name if the IIS Site

    Returns:
        dict: A dictionary of the binding names and properties.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_bindings site
    uSite not found: %subindingsuNo bindings found for site: %s(RRER.R<(tsiteR#tsites((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
list_bindings�s		cC@stj|�j�}t|||�}|tkrTdj|t�}t|��n|r�t|�}|tkr�dj|tdtd�}t|��q�nt	|�}||kr�t
jd|�tS|r9dddj|�d	dj|�d
dj|�ddj|�ddj|�d
dj|�g
}	nTdddj|�d	dj|�d
dj|�ddj|�ddj|�g}	t
|	�}
|
ddkr�dj||
d�}t|��n|t	|�kr�t
jd|�tSt
jd|�tS(u�
    Create an IIS Web Binding.

    .. note::

        This function only validates against the binding
        ipaddress:port:hostheader combination, and will return True even if the
        binding already exists with a different configuration. It will not
        modify the configuration of an existing binding.

    Args:
        site (str): The IIS site name.
        hostheader (str): The host header of the binding. Usually a hostname.
        ipaddress (str): The IP address of the binding.
        port (int): The TCP port of the binding.
        protocol (str): The application protocol of the binding.
        sslflags (str): The flags representing certificate type and storage of
            the binding.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.create_binding site='site0' hostheader='example.com' ipaddress='*' port='80'
    u4Invalid protocol '{0}' specified. Valid formats: {1}u@Invalid sslflags '{0}' specified. Valid sslflags range: {1}..{2}ii����uBinding already present: %suNew-WebBindingu-Nameu'{0}'u-HostHeaderu
-IpAddressu-Portu	-Protocolu	-SslFlagsu{0}uretcodeu(Unable to create binding: {0}
Error: {1}ustderru Binding created successfully: %suUnable to create binding: %s(RRR!RRGRRtintt_VALID_SSL_FLAGSRYR.RFR
RRR/R(RWRDRCRRMtsslflagsR+RPtcurrent_bindingsR%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytcreate_bindingsPcC@sY|dk	rD|tkrDdj|tdtd�}t|��nt�}||krmtjd|�tSt|�}||kr�tjd|�tS|j	d�\}	}
}dj
|dk	r�|n|	|dk	r�tj|�ntj|
�|dk	r|n|g�}||kr�ddd	j|�d
d	j|�ddd
d	j|�g	}
t
|
�}|ddkr�dj||d�}t|��q�n|dk	rE|||d|dkrEddd	j|�d
d	j|�ddd
d	j|�g	}
t
|
�}|ddkrEdj||d�}t|��qEntjd|�tS(u�
    Modify an IIS Web Binding. Use ``site`` and ``binding`` to target the
    binding.

    .. versionadded:: 2017.7.0

    Args:
        site (str): The IIS site name.
        binding (str): The binding to edit. This is a combination of the
            IP address, port, and hostheader. It is in the following format:
            ipaddress:port:hostheader. For example, ``*:80:`` or
            ``*:80:salt.com``
        hostheader (str): The host header of the binding. Usually the hostname.
        ipaddress (str): The IP address of the binding.
        port (int): The TCP port of the binding.
        sslflags (str): The flags representing certificate type and storage of
            the binding.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    The following will seat the host header of binding ``*:80:`` for ``site0``
    to ``example.com``

    .. code-block:: bash

        salt '*' win_iis.modify_binding site='site0' binding='*:80:' hostheader='example.com'
    u@Invalid sslflags '{0}' specified. Valid sslflags range: {1}..{2}ii����uSite '%s' not defined.uBinding '%s' not defined.u:uSet-WebBindingu-Nameu'{0}'u-BindingInformationu
-PropertyNameuBindingInformationu-Valueuretcodeu(Unable to modify binding: {0}
Error: {1}ustderrubindingsusslflagsu2Unable to modify binding SSL Flags: {0}
Error: {1}u!Binding modified successfully: %sN(tNoneR[RRRER.RFRRYR:RRRRRR
(RWR?RDRCRR\RPROR]titpthtnew_bindingR%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytmodify_bindingVsR 	'c	C@s�t|||�}t|�}||kr>tjd|�tSdddj|�ddj|�ddj|�g}t|�}|ddkr�d	j||d
�}t|��n|t|�kr�tjd|�tStjd|�t	S(
u�
    Remove an IIS binding.

    Args:
        site (str): The IIS site name.
        hostheader (str): The host header of the binding.
        ipaddress (str): The IP address of the binding.
        port (int): The TCP port of the binding.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.remove_binding site='site0' hostheader='example.com' ipaddress='*' port='80'
    uBinding already absent: %suRemove-WebBindingu-HostHeaderu'{0}'u
-IpAddressu-Porturetcodeiu(Unable to remove binding: {0}
Error: {1}ustderru Binding removed successfully: %suUnable to remove binding: %s(
RRYR.RFR
RRRR/R(	RWRDRCRR+R]R%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytremove_binding�s&cC@s�t�}t�}||kr2tjd|�|SxE||dD]5}||d|drA||d|||<qAqAW|s�tjd|�n|S(u.
    List certificate bindings for an IIS site.

    .. versionadded:: 2016.11.0

    Args:
        site (str): The IIS site name.

    Returns:
        dict: A dictionary of the binding names and properties.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_bindings site
    uSite not found: %subindingsucertificatehashu*No certificate bindings found for site: %s(RRER.R<(RWR#RXR?((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytlist_cert_bindings�s		i�cC@s�tj|�j�}t|||�}t�dkrP|jd�dd}ndj|jdd��}|tkr�dj|tdtd�}t	|��nt
|�}	||	kr�tjd|�t
Sd}
x+|	D]#}||kr�|	|d	}
q�q�Wtjd
|
�tjd|�||
krCtjd|�tSt�}||krltjd
|�t
St�dkr�|jdd�}
|
jd�r�|
d }
ndddj|
�ddj|�g}n6dddj|�ddj|�ddj|�g}t|�}|ddkrJdj||d�}t|��nt|�}||krvtjd|�t
S|||d	kr�tjd|�tStjd|�t
S(u
    Assign a certificate to an IIS Web Binding.

    .. versionadded:: 2016.11.0

    .. note::

        The web binding that the certificate is being assigned to must already
        exist.

    Args:
        name (str): The thumbprint of the certificate.
        site (str): The IIS site name.
        hostheader (str): The host header of the binding.
        ipaddress (str): The IP address of the binding.
        port (int): The TCP port of the binding.
        sslflags (int): Flags representing certificate type and certificate storage of the binding.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.create_cert_binding name='AAA000' site='site0' hostheader='example.com' ipaddress='*' port='443'
    iu:iuIIS:\SslBindings\{0}u!u@Invalid sslflags '{0}' specified. Valid sslflags range: {1}..{2}i����uBinding not present: %sucertificatehashu"Current certificate thumbprint: %suNew certificate thumbprint: %su+Certificate already present for binding: %suCertificate not present: %su\*!u	\0.0.0.0!uNew-Itemu-Pathu'{0}'u-Thumbprintu	-SSLFlagsu{0}uretcodeu4Unable to create certificate binding: {0}
Error: {1}ustderru,Certificate binding created successfully: %su(Unable to create certificate binding: %sN(RRtupperRR3t
rpartitionRRR[RRYR.R/RR_RFR
R,tendswithRRRf(R+RWRDRCRR\RAtbinding_pathRPR]tcurrent_nametcurrent_bindingtcertstiis7pathR%R&R8tnew_cert_bindings((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytcreate_cert_binding�sh


	
c
C@sZtj|�j�}t|||�}ddddddj|�ddd	j|�d
g
}t|�}||kr�tjd|�tS|||dkr�tj	d
|�tSt
|�}|ddkr�dj||d�}	t|	��nt|�}
||
krtjd|�tS||
|dkrFtj	d|�tStjd|�t
S(u�
    Remove a certificate from an IIS Web Binding.

    .. versionadded:: 2016.11.0

    .. note::

        This function only removes the certificate from the web binding. It does
        not remove the web binding itself.

    Args:
        name (str): The thumbprint of the certificate.
        site (str): The IIS site name.
        hostheader (str): The host header of the binding.
        ipaddress (str): The IP address of the binding.
        port (int): The TCP port of the binding.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.remove_cert_binding name='AAA000' site='site0' hostheader='example.com' ipaddress='*' port='443'
    u$Site = Get-ChildItemu-Pathu'IIS:\Sites'u|uWhere-Objectu {{ $_.Name -Eq '{0}' }};u$$Binding = $Site.Bindings.Collectionu&| Where-Object { $_.bindingInformationu
-Eq '{0}' }};u$Binding.RemoveSslCertificate()uBinding not found: %sucertificatehashu&Certificate binding already absent: %suretcodeiu4Unable to remove certificate binding: {0}
Error: {1}ustderru,Certificate binding removed successfully: %su(Unable to remove certificate binding: %s(RRRgRRRfR.R<R
RFRRR/R(R+RWRDRCRRAR%tcurrent_cert_bindingsR&R8Ro((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytremove_cert_bindingns:		cC@s�t�}g}|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd�|jd	�|jd
�|jd�|jd�td
|dt�}y#tjjj|ddt�}Wnt	k
rt
d��nXx�|D]{}t�}t|dt�rTd|dkre||dd7}qen|j|d�i|dd6|d6||d<q
W|s�t
jd|d�n|S(u�
    List all configured IIS application pools.

    Returns:
        dict: A dictionary of IIS application pools and their details.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_apppools
    u?Get-ChildItem -Path 'IIS:\AppPools' | Select-Object Name, Stateu>, @{ Name = 'Applications'; Expression = { $AppPool = $_.Name;u%$AppPath = 'machine/webroot/apphost';u?$FilterBase = '/system.applicationHost/sites/site/application';u=$FilterBase += "[@applicationPool = '$($AppPool)' and @path";u0$FilterRoot = "$($FilterBase) = '/']/parent::*";u*$FilterNonRoot = "$($FilterBase) != '/']";uLGet-WebConfigurationProperty -Filter $FilterRoot -PsPath $AppPath -Name Nameu| ForEach-Object { $_.Value };uOGet-WebConfigurationProperty -Filter $FilterNonRoot -PsPath $AppPath -Name Pathu;| ForEach-Object { $_.Value } | Where-Object { $_ -ne '/' }u} }RRustdoutRu$Unable to parse return data as Json.uApplicationsuvalueustateuapplicationsunameu(No application pools found in output: %s(RR-RR
RRRRRR RR7R6R.R<(R#R%R&R'R(tapplications((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyRH�s<
	











#

	$	cC@s�t�}dj|�}||kr8tjd|�tSdddj|�g}t|�}|ddkr�dj||d	�}t|��ntjd
|�tS(u,
    Create an IIS application pool.

    .. note::

        This function only validates against the application pool name, and will
        return True even if the application pool already exists with a different
        configuration. It will not modify the configuration of an existing
        application pool.

    Args:
        name (str): The name of the IIS application pool.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.create_apppool name='MyTestPool'
    uIIS:\AppPools\{0}u&Application pool '%s' already present.uNew-Itemu-Pathu'{0}'uretcodeiu1Unable to create application pool: {0}
Error: {1}ustderru)Application pool created successfully: %s(RHRR.RFR
RR(R+tcurrent_apppoolstapppool_pathR%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyRI�s	cC@s�t�}dj|�}||kr8tjd|�tSdddj|�dg}t|�}|ddkr�d	j||d
�}t|��ntjd|�tS(u
    Remove an IIS application pool.

    Args:
        name (str): The name of the IIS application pool.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.remove_apppool name='MyTestPool'
    uIIS:\AppPools\{0}u#Application pool already absent: %suRemove-Itemu-Pathu'{0}'u-Recurseuretcodeiu1Unable to remove application pool: {0}
Error: {1}ustderru)Application pool removed successfully: %s(RHRR.RFR
RR(R+RtRuR%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytremove_apppools	cC@s/ddj|�g}t|�}|ddkS(u-
    Stop an IIS application pool.

    .. versionadded:: 2017.7.0

    Args:
        name (str): The name of the App Pool to stop.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.stop_apppool name='MyTestPool'
    uStop-WebAppPoolu'{0}'uretcodei(RR(R+R%R&((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytstop_apppoolBscC@s/ddj|�g}t|�}|ddkS(u0
    Start an IIS application pool.

    .. versionadded:: 2017.7.0

    Args:
        name (str): The name of the App Pool to start.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.start_apppool name='MyTestPool'
    uStart-WebAppPoolu'{0}'uretcodei(RR(R+R%R&((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
start_apppool[scC@s/ddj|�g}t|�}|ddkS(u8
    Restart an IIS application pool.

    .. versionadded:: 2016.11.0

    Args:
        name (str): The name of the IIS application pool.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.restart_apppool name='MyTestPool'
    uRestart-WebAppPoolu'{0}'uretcodei(RR(R+R%R&((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytrestart_apppooltscC@s�t�}t�}t�}dj||�}|sDtjd�|S|jd�x�|D]�}|jdddj|�ddj|�dd	d
dg	�|jdj|��|jd
j|��|jd�|jd�|jd�|jd�|jdj|��|jd�qXWtd|dt�}|ddkrYd}	t	|	��n|jd�td|dt�}ySt
jjj
|ddt�}
t|
t�r�|j|
d�n
|j|
�Wntk
r�td��nX|S(uk
    Get the value of the setting for the IIS container.

    .. versionadded:: 2016.11.0

    Args:
        name (str): The name of the IIS container.
        container (str): The type of IIS container. The container types are:
            AppPools, Sites, SslBindings
        settings (dict): A dictionary of the setting names and their values.

    Returns:
        dict: A dictionary of the provided settings and their values.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.get_container_setting name='MyTestPool' container='AppPools'
            settings="['processModel.identityType']"
    uIIS:\{0}\{1}uNo settings providedu$Settings = @{};uGet-ItemPropertyu-Pathu'{0}'u-Nameu-ErrorActionuStopu|u	Out-Null;u($Property = Get-ItemProperty -Path '{0}'u-Name '{0}' -ErrorAction Stop;u8if (([String]::IsNullOrEmpty($Property) -eq $False) -andu:($Property.GetType()).Name -eq 'ConfigurationAttribute') {u%$Property = $Property | Select-Objectu-ExpandProperty Value };u&$Settings['{0}'] = [String] $Property;u$Property = $Null;RRuretcodeiuMOne or more invalid property names were specified for the provided container.u	$SettingsustdoutRu$Unable to parse return data as Json.(RR7RR.R<R-RJRR
RRRRRRR6R9R R(R+t	containertsettingsR#R%tps_cmd_validatetcontainer_pathtsettingR&RPR'((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytget_container_setting�sH			


	






cC@s�idd6dd6dd6dd6d	d
6}idd6dd6dd6dd6d
d	6}t�}dj||�}|s�tjd�tSx%|D]}tj||�||<q�Wtd
|d|d|j��}||kr�tj	d�t
Sx�|D]�}yt||�||}	Wn$tk
r9dj||�}	nX|dkrm|||j�krm|||}	n|j
dddj|�ddj|�ddj|	�g�q�Wt|�}
|
ddkr�dj||�}t|��ntd
|d|d|j��}t�}
x||D]t}|dkrY|||j�krY|||||<ntj||�tj||�kr|||
|<qqW|
r�tjd|
�tStj	d|j��t
S(u^
    Set the value of the setting for an IIS container.

    .. versionadded:: 2016.11.0

    Args:
        name (str): The name of the IIS container.
        container (str): The type of IIS container. The container types are:
            AppPools, Sites, SslBindings
        settings (dict): A dictionary of the setting names and their values.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.set_container_setting name='MyTestPool' container='AppPools'
            settings="{'managedPipeLineMode': 'Integrated'}"
    uLocalSystemu0uLocalServiceu1uNetworkServiceu2uSpecificUseru3uApplicationPoolIdentityu4uIIS:\{0}\{1}uNo settings providedR+RzR{u-Settings already contain the provided values.u'{0}'uprocessModel.identityTypeuSet-ItemPropertyu-Pathu-Nameu-Valueu{0};uretcodeiu#Unable to set settings for {0}: {1}uFailed to change settings: %su$Settings configured successfully: %s(R7RR.R<RRRRtkeysRFR
tcomplexR RJRRRR/(R+RzR{tidentityType_map2stringtidentityType_map2numericR%R}R~tcurrent_settingstvalueR&R8tnew_settingstfailed_settings((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytset_container_setting�sV))	




"		
"&cC@sxt�}t�}|jdj|��|jd�|jd�|jd�|jd�td|dt�}y#tjjj	|dd	t
�}Wntk
r�td
��nXx�|D]�}t�}t
|dt�rd|dkr||dd7}qn|j|d�i|d
d6|dd6|dd6|d6|dd6||d<q�W|sttjd|�n|S(u
    Get all configured IIS applications for the specified site.

    Args:
        site (str): The IIS site name.

    Returns: A dictionary of the application names and properties.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_apps site
    uGet-WebApplication -Site '{0}'uD| Select-Object applicationPool, path, PhysicalPath, preloadEnabled,u;@{ Name='name'; Expression={ $_.path.Split('/', 2)[-1] } },uC@{ Name='protocols'; Expression={ @( $_.enabledProtocols.Split(',')u$| Foreach-Object { $_.Trim() } ) } }RRustdoutRu$Unable to parse return data as Json.u	protocolsuvalueuapplicationPooluapppoolupathupreloadEnabledupreloaduPhysicalPathu
sourcepathunameuNo apps found in output: %s(RR7R-RRR
RRRRRR RR6R.R<(RWR#R%R&R'R(t	protocols((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt	list_apps3s4		



#

	c	C@s.t|�}||kr,tjd|�tStjj|�sRtjd|�tSdddj	|�ddj	|�ddj	|�g}|r�|j
ddj	|�g�nt|�}|d	d
kr�dj	||d�}t|��nt|�}||krtjd
|�tStjd|�tS(u�
    Create an IIS application.

    .. note::

        This function only validates against the application name, and will
        return True even if the application already exists with a different
        configuration. It will not modify the configuration of an existing
        application.

    Args:
        name (str): The IIS application.
        site (str): The IIS site name.
        sourcepath (str): The physical path.
        apppool (str): The name of the IIS application pool.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.create_app name='app0' site='site0' sourcepath='C:\site0' apppool='site0'
    uApplication already present: %suPath is not present: %suNew-WebApplicationu-Nameu'{0}'u-Siteu
-PhysicalPathu-ApplicationPooluretcodeiu,Unable to create application: {0}
Error: {1}ustderru$Application created successfully: %su Unable to create application: %s(
R�R.RFR
tostpathtisdirR/RRRJRR(	R+RWRKRLtcurrent_appsR%R&R8tnew_apps((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
create_appjs0cC@s�t|�}||kr,tjd|�tSdddj|�ddj|�g}t|�}|ddkr�dj||d	�}t|��nt|�}||kr�tjd
|�tStjd|�tS(u*
    Remove an IIS application.

    Args:
        name (str): The application name.
        site (str): The IIS site name.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.remove_app name='app0' site='site0'
    uApplication already absent: %suRemove-WebApplicationu-Nameu'{0}'u-Siteuretcodeiu,Unable to remove application: {0}
Error: {1}ustderru$Application removed successfully: %su Unable to remove application: %s(	R�R.RFR
RRRR/R(R+RWR�R%R&R8R�((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
remove_app�s$cC@s�t�}dddj|�ddj|�dddg}td|d	t�}y#tjjj|d
dt�}Wnt	k
r�t
d��nXx'|D]}i|d
d6||d<q�W|s�tjd|�n|S(u�
    Get all configured IIS virtual directories for the specified site, or for
    the combination of site and application.

    Args:
        site (str): The IIS site name.
        app (str): The IIS application.

    Returns:
        dict: A dictionary of the virtual directory names and properties.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_vdirs site
    uGet-WebVirtualDirectoryu-Siteu'{0}'u-Applicationu|u-Select-Object PhysicalPath, @{ Name = 'name';u)Expression = { $_.path.Split('/')[-1] } }RRustdoutRu$Unable to parse return data as Json.uphysicalPathu
sourcepathunameuNo vdirs found in output: %s(
RRRR
RRRRRR RR.R<(RWtappR#R%R&R'R(((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
list_vdirs�s 		#

c	C@s:t||�}||kr/tjd|�tStjj|�sUtjd|�tSdddj	|�ddj	|�ddj	|�g}|t
kr�|jddj	|�g�nt|�}|d	d
kr�dj	||d�}t
|��nt||�}||kr&tjd
|�tStjd|�tS(u�
    Create an IIS virtual directory.

    .. note::

        This function only validates against the virtual directory name, and
        will return True even if the virtual directory already exists with a
        different configuration. It will not modify the configuration of an
        existing virtual directory.

    Args:
        name (str): The virtual directory name.
        site (str): The IIS site name.
        sourcepath (str): The physical path.
        app (str): The IIS application.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.create_vdir name='vd0' site='site0' sourcepath='C:\inetpub\vdirs\vd0'
    u%Virtual directory already present: %suPath is not present: %suNew-WebVirtualDirectoryu-Nameu'{0}'u-Siteu
-PhysicalPathu-Applicationuretcodeiu2Unable to create virtual directory: {0}
Error: {1}ustderru*Virtual directory created successfully: %su&Unable to create virtual directory: %s(R�R.RFR
R�R�R�R/RRt_DEFAULT_APPRJRR(	R+RWRKR�t
current_vdirsR%R&R8t	new_vdirs((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytcreate_vdir�s0c
C@st||�}tjj|jd�jd��}|rKdj|�}ndj|||�}||kr�tjd|�t	Sdddj|�dg}t
|�}|d	d
kr�dj||d�}t|��nt||�}	||	krtjd
|�t	Stjd|�t
S(u`
    Remove an IIS virtual directory.

    Args:
        name (str): The virtual directory name.
        site (str): The IIS site name.
        app (str): The IIS application.

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.remove_vdir name='vdir0' site='site0'
    u/u{0}\uIIS:\Sites\{0}\{1}{2}u$Virtual directory already absent: %suRemove-Itemu-Pathu'{0}'u-Recurseuretcodeiu2Unable to remove virtual directory: {0}
Error: {1}ustderru*Virtual directory removed successfully: %su&Unable to remove virtual directory: %s(R�R�R�RtrstripR:RR.RFR
RRR/R(
R+RWR�R�tapp_patht	vdir_pathR%R&R8R�((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytremove_vdir<s,$	cC@s�t�}ddddg}td|dt�}y#tjjj|ddt�}Wntk
rrt	d	��nXx?|D]7}|d
r�|d
||d<qz|d||d<qzW|s�t
jd
|�n|S(u�
    List the IIS Configuration Backups on the System.

    .. versionadded:: 2017.7.0

    .. note::
        Backups are made when a configuration is edited. Manual backups are
        stored in the ``$env:Windir\System32\inetsrv\backup`` folder.

    Returns:
        dict: A dictionary of IIS Configurations backed up on the system.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_backups
    uGet-WebConfigurationBackupu|uSelect Name, CreationDate,u7@{N="FormattedDate"; E={$_.CreationDate.ToString("G")}}RRustdoutRu$Unable to parse return data as Json.u
FormattedDateuNameuCreationDateuNo backups found in output: %s(RRR
RRRRRR RR.R<(R#R%R&R'R(((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytlist_backupsqs"		#


cC@s�|t�kr'tdj|���ndddj|�g}t|�}|ddkr�dj||d�}t|��n|t�kS(	u�
    Backup an IIS Configuration on the System.

    .. versionadded:: 2017.7.0

    .. note::
        Backups are stored in the ``$env:Windir\System32\inetsrv\backup``
        folder.

    Args:
        name (str): The name to give the backup

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.create_backup good_config_20170209
    uBackup already present: {0}uBackup-WebConfigurationu-Nameu'{0}'uretcodeiu2Unable to backup web configuration: {0}
Error: {1}ustderr(R�RRR(R+R%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
create_backup�scC@s�|t�kr#tjd|�tSdddj|�g}t|�}|ddkr|dj||d�}t|��n|t�kS(	uA
    Remove an IIS Configuration backup from the System.

    .. versionadded:: 2017.7.0

    Args:
        name (str): The name of the backup to remove

    Returns:
        bool: True if successful, otherwise False

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.remove_backup backup_20170209
    uBackup already removed: %suRemove-WebConfigurationBackupu-Nameu'{0}'uretcodeiu2Unable to remove web configuration: {0}
Error: {1}ustderr(R�R.RFR
RRR(R+R%R&R8((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt
remove_backup�scC@s�ddj|�g}td|dt�}y#tjjj|ddt�}Wntk
rlt	d��nXt
�}x |D]}|d||d	<q}W|s�tjd
|�n|S(u~
    Returns a list of worker processes that correspond to the passed
    application pool.

    .. versionadded:: 2017.7.0

    Args:
        apppool (str): The application pool to query

    Returns:
        dict: A dictionary of worker processes with their process IDs

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.list_worker_processes 'My App Pool'
    u
Get-ChildItemu#'IIS:\AppPools\{0}\WorkerProcesses'RRustdoutRu$Unable to parse return data as Json.uappPoolNameu	processIduNo backups found in output: %s(
RRR
RRRRRR RRR.R<(RLR%R&R'R#R(((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytlist_worker_processes�s#
	
cC@s-t�}t�}d}|s/tjd�|S|jd�x|D]}||kr)|dksm|dkr�|jdj||��|jdj|��|jd	�|jd
j|��|jd�n|dks�|dkrV|jdj||��|jd
j|��|jd�qVqCd
j|�}d|d|}t|��qCW|jd�tdt	j
�j|�dt�}	yStj
jj|	ddt�}
t|
t�r�|j|
d�n
|j|
�Wntk
r�tjd�nXdt	j|�kr)d}t|��n|S(u�
    .. versionadded:: 2017.7.0

    Get the value of the setting for the IIS web application.

    .. note::
        Params are case sensitive

    :param str name: The name of the IIS web application.
    :param str site: The site name contains the web application.
        Example: Default Web Site
    :param str settings: A dictionary of the setting names and their values.
        Available settings: physicalPath, applicationPool, userName, password
    Returns:
        dict: A dictionary of the provided settings and their values.

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.get_webapp_settings name='app0' site='Default Web Site'
            settings="['physicalPath','applicationPool']"
    uphysicalPathuapplicationPooluuserNameupassworduNo settings providedu$Settings = @{};u� $Property = Get-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='{0}']/application[@path='/{1}']/virtualDirectory[@path='/']"u. -Name "{0}" -ErrorAction Stop | select Value;u= $Property = $Property | Select-Object -ExpandProperty Value;u' $Settings['{0}'] = [String] $Property;u $Property = $Null;u* $Property = (get-webapplication {0}).{1};u, uUnexpected setting:u. Available settings are: u
 $SettingsRRustdoutRiu$Unable to parse return data as Json.uhSome values are empty - please validate site and web application names. Some commands are case sensitive(uphysicalPathuapplicationPooluuserNameupasswordN(RR7R.R<R-RRRRRRR
RRRRRR6R9R R/R_t
viewvalues(R+RWR{R#R2tavailableSettingsR~tavailSetStrRPR&R'((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytget_webapp_settingssF		




$
c	C@s\t�}t|�}t�}d}||krMd|d}t|��n||krvd|d}t|��n|s�d}t|��nx�|j�D]y}||kr�tj||�||<q�d	j|�}	tj	d
|�tj	d|	�d|d
|	}t|��q�Wt
d|d|d|j��}
||
krYtjd�tSx|D]}yt
||�||}Wn$tk
r�dj||�}nX|dks�|dkr�|jdj||��|jdj||��n|dks|dkr`|jdj||||��|dkrrtjj||�sod||}t|��qoqrq`q`Wt|�}|ddkr�dj|�}t|��nt
d|d|d|j��}
t�}xE|D]=}tj||�tj|
|�kr�||||<q�q�W|r<tj	d|�tStjdj|j���tS(u#
    .. versionadded:: 2017.7.0

    Configure an IIS application.

    .. note::
        This function only configures an existing app. Params are case
        sensitive.

    :param str name: The IIS application.
    :param str site: The IIS site name.
    :param str settings: A dictionary of the setting names and their values.
        - physicalPath: The physical path of the webapp.
        - applicationPool: The application pool for the webapp.
        - userName: "connectAs" user
        - password: "connectAs" password for user
    :return: A boolean representing whether all changes succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_iis.set_webapp_settings name='app0' site='site0' settings="{'physicalPath': 'C:\site0', 'apppool': 'site0'}"
    uphysicalPathuapplicationPooluuserNameupassworduApplicationu
doesn't existuSiteuNo settings providedu, uUnexpected setting: %s uAvailable settings: %suUnexpected setting:u Available settings:R+RWR{u-Settings already contain the provided values.u'{0}'u� Set-WebConfigurationProperty -Filter "system.applicationHost/sites/site[@name='{0}']/application[@path='/{1}']/virtualDirectory[@path='/']"u -Name "{0}" -Value {1};u< Set-ItemProperty "IIS:\Sites\{0}\{1}" -Name {2} -Value {3};uPath is not present: uretcodeiu.Unable to set settings for web application {0}uFailed to change settings: %su%Settings configured successfully: {0}(uphysicalPathuapplicationPooluuserNameupassword(R7R�RERR�RRRR.R/R�R<R
R�R RR-R�R�R�RRRRF(R+RWR{R2R�ROR�R8R~R�R�R�R&R�R�((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pytset_webapp_settingsZsp		


	
&(uftpuhttpuhttps(Ct__doc__t
__future__RRRR0tloggingR�tsalt.utils.jsonRtsalt.utils.platformtsalt.ext.six.movesRtsalt.exceptionsRRtsalt.extRt	getLoggert__name__R.R�RGttupleR[RRRR,R3RRRERQR_RRRSRTRURVRYR^RdReRfRpRrRHRIRvRwRxRyRR�R�R�R�R�R�R�R�R�R�R�R�R�(((s8/usr/lib/python2.7/site-packages/salt/modules/win_iis.pyt<module>sr	+		>OE	(				Q	X-	#	nH	=	+	$				M	Y	7>	,*>5	-	&	#	'	L

Zerion Mini Shell 1.0