%PDF- %PDF-
Mini Shell

Mini Shell

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

�
���^c@@sudZddlmZmZmZddlZddlZddlmZddl	Z
ddlZ
ddlm
Z
y"ddlZddlZ
eZWnek
r�eZnXdZdZeje�ZdZd	�Zd
�Zd�Zd�Zd
�Zd�Zed�Z ed�Z!ed�Z"ed�Z#eed�Z$deed�Z&ed�Z'ded�Z(dS(u�
Module for managing IIS SMTP server configuration on Windows servers.
The Windows features 'SMTP-Server' and 'Web-WMI' must be installed.

:depends: wmi

i(tabsolute_importtunicode_literalstprint_functionN(tSaltInvocationError(tsixu	SmtpSvc/1uMicrosoftIISv2uwin_smtp_servercC@s tjjj�rtrtStS(u(
    Only works on Windows systems.
    (tsalttutilstplatformt
is_windowst_HAS_MODULE_DEPENDENCIESt__virtualname__tFalse(((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pyt__virtual__1sc
C@s�tjjj���yMtjdt�}t||�}||gd|�d}t||�}WnTtjk
r�}t	j
d|j�n,tt
fk
r�}t	j
d||�nXWdQX|S(u>
    Get the value of the setting for the provided class.
    t	namespacetNameiuEncountered WMI error: %suError getting %s: %sN(RRtwinapitComtwmitWMIt_WMI_NAMESPACEtgetattrtx_wmit_LOGterrort	com_errortAttributeErrort
IndexError(twmi_class_nametsettingtservert
connectiont	wmi_classtobjstretR((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pyt_get_wmi_setting:sc
C@stjjj���y8tjdt�}t||�}|d|�d}WnTtjk
rv}t	j
d|j�n,tt
fk
r�}t	j
d||�nXyt|||�tSWnNtjk
r�}t	j
d|j�n&tk
r
}t	j
d||�nXWdQXtS(u>
    Set the value of the setting for the provided class.
    R
RiuEncountered WMI error: %suError getting %s: %suError setting %s: %sN(RRRRRRRRRRRRRRtsetattrtTrueR(RRtvalueRRRR R((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pyt_set_wmi_settingLs"cK@s�t�}tjjj|�}xr|D]j}t||t�r�tjd||�tt	j
||��}dj|�||<q%||||<q%W|S(u_
    Convert setting values that had been improperly converted to a dict back to a string.
    uFixing value: %su{{{0}}}(tdictRRtargstclean_kwargst
isinstanceRtdebugtnextRtiterkeystformat(tsettingsR!Rtvalue_from_key((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pyt_normalize_server_settingses	
c
C@st�}d}tjjj���yjtjdt�}|j�}xE|D]=}t	j
|j�j|dd�}t	j
|j
�||<qJWWnQtjk
r�}tjd|j�n)ttfk
r�}tjd|�nXWdQX|s�tjd�n|S(	u�
    Get all available log format names and ids.

    :return: A dictionary of the log format names and ids.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.get_log_format_types
    ulogging/R
uiuEncountered WMI error: %su%Error getting IISLogModuleSetting: %sNuUnable to get log format types.(R'RRRRRRRtIISLogModuleSettingRt	text_typeRtreplacetLogModuleIdRRRRRR(R!tprefixRR tobjtnameR((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytget_log_format_typesws 
	
!c
C@s�t�}tjjj���yLtjdt�}|j�}x'|D]}|j	t
j|j��qDWWnQtj
k
r�}tjd|j�n)ttfk
r�}tjd|�nXWdQXtjd|�|S(u�
    Get the SMTP virtual server names.

    :return: A list of the SMTP virtual servers.
    :rtype: list

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.get_servers
    R
uEncountered WMI error: %su&Error getting IIsSmtpServerSetting: %sNuFound SMTP servers: %s(tlistRRRRRRRtIIsSmtpServerSettingtappendRR3RRRRRRRR+(R!RR R7R((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytget_servers�s
	
!c
C@s�t�}|s tjd�|Stjjj���y\tjdt	�}|j
|d|�d}x*|D]"}tjt
||��||<qhWWnQtjk
r�}tjd|j�n)ttfk
r�}tjd|�nXWdQX|S(u|
    Get the value of the setting for the SMTP virtual server.

    :param str settings: A list of the setting names.
    :param str server: The SMTP server name.

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

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.get_server_setting settings="['MaxRecipients']"
    uNo settings provided.R
RiuEncountered WMI error: %su&Error getting IIsSmtpServerSetting: %sN(R'RtwarningRRRRRRRR;RR3RRRRRR(R/RR!RR RR((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytget_server_setting�s	

$c	
C@s7|stjd�tSt|�}td|j�d|�}||kr[tjd�tStj	j
j��(y,tj
dt�}|jd|�d}WnQtjk
r�}tjd|j�n)ttfk
r�}tjd	|�nXx�|D]�}tj||�tj||�kr�yt||||�Wq�tjk
rd}tjd|j�q�tk
r�}tjd
||�q�Xq�q�WWdQXtd|j�d|�}t�}xE|D]=}tj||�tj||�kr�||||<q�q�W|rtjd|�tStjd
|j��tS(u�
    Set the value of the setting for the SMTP virtual server.

    .. note::

        The setting names are case-sensitive.

    :param str settings: A dictionary of the setting names and their values.
    :param str server: The SMTP server name.

    :return: A boolean representing whether all changes succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_server_setting settings="{'MaxRecipients': '500'}"
    uNo settings providedR/Ru-Settings already contain the provided values.R
RiuEncountered WMI error: %su&Error getting IIsSmtpServerSetting: %suError setting %s: %sNuFailed to change settings: %su$Settings configured successfully: %s(RR>RR1R?tkeysR+R$RRRRRRRR;RRRRRRR3R#R'(	R/Rtcurrent_settingsRR RRtnew_settingstfailed_settings((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytset_server_setting�sD


&$	
&cC@sZt�}tdd|�}x+|D]#}tj|�||kr"|Sq"Wtjd�dS(u

    Get the active log format for the SMTP virtual server.

    :param str server: The SMTP server name.

    :return: A string of the log format name.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.get_log_format
    uIIsSmtpServerSettinguLogPluginClsiduUnable to determine log format.N(R9R"RR3RR>tNone(Rtlog_format_typest	format_idtkey((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytget_log_format$s	

c	C@s�d}t�}|j|d�}|sNdj||j��}t|��ntjd||�t|�}||kr�tjd|�t	St
d|||�t|�}||k}|r�tjd||�ntjd||�|S(	uo
    Set the active log format for the SMTP virtual server.

    :param str log_format: The log format name.
    :param str server: The SMTP server name.

    :return: A boolean representing whether the change succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_log_format 'Microsoft IIS Log File Format'
    uLogPluginClsidu6Invalid log format '{0}' specified. Valid formats: {1}uId for '%s' found: %su(%s already contains the provided format.uIIsSmtpServerSettingu&Setting %s configured successfully: %su%Unable to configure %s with value: %sN(R9tgetRER.R@RRR+RIR$R&R(	t
log_formatRRRFRGtmessagetcurrent_log_formattnew_log_formatR!((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytset_log_format?s&	c	C@s�t�}d}d}|r't�}ntd||�}xR|D]J}tj||�\}}|r�|jdj||��q@|||<q@W|s�tjd|�n|S(uu
    Get the IPGrant list for the SMTP virtual server.

    :param bool as_wmi_format: Returns the connection IPs as a list in the format WMI expects.
    :param str server: The SMTP server name.

    :return: A dictionary of the IP and subnet pairs.
    :rtype: dict

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.get_connection_ip_list
    uIPGrantu,\s*uIIsIPSecuritySettingu{0}, {1}u%s is empty.(	R'R:R"tretsplitR<R.RR+(	t
as_wmi_formatRR!Rt
reg_separatort	addressestunnormalized_addresst
ip_addresstsubnet((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytget_connection_ip_listls	
c
C@sdd}t�}|s1t�}tjd|�nx7|D]/}|jdj|j�||j���q8Wtdtd|�}t	|�t	|�kr�tjd|�tSt
dd|�}||kr�tjd	|�tdd||�ntd|||�tdtd|�}t	|�t	|�k}	|	rMtjd
||�|	Stjd||�|	S(u�
    Set the IPGrant list for the SMTP virtual server.

    :param str addresses: A dictionary of IP + subnet pairs.
    :param bool grant_by_default: Whether the addresses should be a blacklist or whitelist.
    :param str server: The SMTP server name.

    :return: A boolean representing whether the change succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_connection_ip_list addresses="{'127.0.0.1': '255.255.255.255'}"
    uIPGrantuEmpty %s specified.u{0}, {1}RRRu+%s already contains the provided addresses.uIIsIPSecuritySettinguGrantByDefaultuSetting GrantByDefault to: %su%s configured successfully: %su%Unable to configure %s with value: %s(
R:R'RR+R<R.tstripRXR$tsetR"R&R(
RTtgrant_by_defaultRRtformatted_addressestaddresstcurrent_addressestcurrent_grant_by_defaultt
new_addressesR!((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytset_connection_ip_list�s0		
cC@s�t�}d}td||�}|s\tjd||�|dkrRdg}nt|�Sd}xi|t|�kr�g|||d!D]}tj|�^q�}dj|�}|j	|�|d7}qeW|S(u
    Get the RelayIpList list for the SMTP virtual server.

    :param str server: The SMTP server name.

    :return: A list of the relay IPs.
    :rtype: list

    .. note::

        A return value of None corresponds to the restrictive 'Only the list below' GUI parameter
        with an empty access list, and setting an empty list/tuple corresponds to the more
        permissive 'All except the list below' GUI parameter.

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.get_relay_ip_list
    uRelayIpListuIIsSmtpServerSettingu%s is empty: %siiu.N(
R:R"RR+REtlenRR3tjoinR<(RR!RtlinestitxtoctetsR]((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytget_relay_ip_list�s	
-
c	C@sd}t�}t|�}t|�|krAtjd|�tS|r�|dd	kr`d	}q�x8|D]-}x$|jd�D]}|j|�q}WqgWntjd||�td|||�t|�}t|�|k}|r�tjd||�|Stj	d||�|S(
u*
    Set the RelayIpList list for the SMTP virtual server.

    Due to the unusual way that Windows stores the relay IPs, it is advisable to retrieve
    the existing list you wish to set from a pre-configured server.

    For example, setting '127.0.0.1' as an allowed relay IP through the GUI would generate
    an actual relay IP list similar to the following:

    .. code-block:: cfg

        ['24.0.0.128', '32.0.0.128', '60.0.0.128', '68.0.0.128', '1.0.0.0', '76.0.0.0',
         '0.0.0.0', '0.0.0.0', '1.0.0.0', '1.0.0.0', '2.0.0.0', '2.0.0.0', '4.0.0.0',
         '0.0.0.0', '76.0.0.128', '0.0.0.0', '0.0.0.0', '0.0.0.0', '0.0.0.0',
         '255.255.255.255', '127.0.0.1']

    .. note::

        Setting the list to None corresponds to the restrictive 'Only the list below' GUI parameter
        with an empty access list configured, and setting an empty list/tuple corresponds to the
        more permissive 'All except the list below' GUI parameter.

    :param str addresses: A list of the relay IPs. The order of the list is important.
    :param str server: The SMTP server name.

    :return: A boolean representing whether the change succeeded.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' win_smtp_server.set_relay_ip_list addresses="['192.168.1.1', '172.16.1.1']"
    uRelayIpListu+%s already contains the provided addresses.iu.uFormatted %s addresses: %suIIsSmtpServerSettingu%s configured successfully: %su%Unable to configure %s with value: %sN(
R:RhRR+R$RERQR<R&R(	RTRRR\R^R]toctetR`R!((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pytset_relay_ip_list�s*#		
()t__doc__t
__future__RRRtloggingRPtsalt.exceptionsRtsalt.utils.argsRtsalt.utils.platformtsalt.extRRtsalt.utils.winapiR$R	tImportErrorRt_DEFAULT_SERVERRt	getLoggert__name__RR
RR"R&R1R9R=R?RDRIRORXRERaRhRj(((s@/usr/lib/python2.7/site-packages/salt/modules/win_smtp_server.pyt<module>s>


						#	$G-':+

Zerion Mini Shell 1.0