o
    Œ }i×  ã                   @   s²   d Z ddlZddlZddlZddlZe e¡ZdZ	dZ
dd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zejjj d¡dd„ ƒZejjj d¡dd„ ƒZdS )zÚ
Support for Apache

Please note: The functions in here are Debian-specific. Placing them in this
separate file will allow them to load only on Debian-based systems, while still
loading under the ``apache`` namespace.
é    NÚapachez/etc/apache2/sites-enabledc                  C   s(   t ƒ } tjj | ¡rtd dkrtS dS )z5
    Only load the module if apache is installed
    Ú	os_familyÚDebian)Fz9apache execution module not loaded: apache not installed.)Ú
_detect_osÚsaltÚutilsÚpathÚwhichÚ
__grains__Ú__virtualname__)Úcmd© r   úD/opt/saltstack/salt/extras-3.10/saltext/apache/modules/deb_apache.pyÚ__virtual__   s   r   c                   C   s$   t d dkrdS t d dkrdS dS )zA
    Apache commands and paths differ depending on packaging
    r   ZRedHatZ	apachectlr   Z
apache2ctl)r
   r   r   r   r   r       s
   r   c                 C   sZ   |   d¡r| }n| › d�}tj t› d|› �¡rdS | dkr+tj t› d|› �¡r+dS dS )aT  
    Checks to see if the specific site symlink is in /etc/apache2/sites-enabled.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.check_site_enabled example.com
        salt '*' apache.check_site_enabled example.com.conf
    ú.confú/TÚdefaultz/000-F)ÚendswithÚosr   ÚislinkÚSITE_ENABLED_DIR)ÚsiteZ	site_filer   r   r   Úcheck_site_enabled,   s   

r   c              
   C   óž   i }d| g}z
t d |dd�}W n ty$ } z|W  Y d}~S d}~ww d|d< | |d< |d	kr;d
| › d�|d< |S |dkrId
| › d�|d< |S ||d< |S )zã
    Runs a2ensite for the given site.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.a2ensite example.com
    Úa2ensiteúcmd.retcodeF©Zpython_shellNzApache2 Enable SiteÚNameÚSiteé   úSite ú
 Not foundÚStatusr   ú enabled©Z__salt__Ú	Exception©r   ÚretÚcommandÚstatusÚer   r   r   r   E   ó$   €ÿûþr   c              
   C   r   )zå
    Runs a2dissite for the given site.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.a2dissite example.com
    Ú	a2dissiter   Fr   NzApache2 Disable Siter   r   é   r    r!   r"   r   ú	 disabledr$   r&   r   r   r   r,   g   r+   r,   c                 C   s6   |   d¡s
|   d¡r| }n| › d�}tj d|› �¡S )a|  
    Checks to see if the specific mod symlink is in /etc/apache2/mods-enabled.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.check_mod_enabled status
        salt '*' apache.check_mod_enabled status.load
        salt '*' apache.check_mod_enabled status.conf
    z.loadr   z/etc/apache2/mods-enabled/©r   r   r   r   )ÚmodZmod_filer   r   r   Úcheck_mod_enabled‰   s   
r1   c              
   C   r   )zà
    Runs a2enmod for the given mod.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.a2enmod vhost_alias
    Úa2enmodr   Fr   NzApache2 Enable Modr   ÚModr   úMod r!   r"   r   r#   r$   ©r0   r'   r(   r)   r*   r   r   r   r2   Ÿ   r+   r2   c              
   C   r   )zâ
    Runs a2dismod for the given mod.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.a2dismod vhost_alias
    Úa2dismodr   Fr   NzApache2 Disable Modr   r3   r-   r4   r!   r"   r   r.   r$   r5   r   r   r   r6   Á   r+   r6   c                 C   s,   |   d¡r| }n| › d�}tj d|› �¡S )am  
    .. versionadded:: 2016.3.0

    Checks to see if the specific conf symlink is in /etc/apache2/conf-enabled.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.check_conf_enabled security
        salt '*' apache.check_conf_enabled security.conf
    r   z/etc/apache2/conf-enabled/r/   )ÚconfZ	conf_filer   r   r   Úcheck_conf_enabledã   s   

r8   Úa2enconfc              
   C   r   )a   
    .. versionadded:: 2016.3.0

    Runs a2enconf for the given conf.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.a2enconf security
    r9   r   Fr   NzApache2 Enable Confr   ÚConfr   úConf r!   r"   r   r#   r$   ©r7   r'   r(   r)   r*   r   r   r   r9   ú   ó$   €ÿûþÚ	a2disconfc              
   C   r   )a  
    .. versionadded:: 2016.3.0

    Runs a2disconf for the given conf.

    This will only be functional on Debian-based operating systems (Ubuntu,
    Mint, etc).

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.a2disconf security
    r>   r   Fr   NzApache2 Disable Confr   r:   r-   r;   r!   r"   r   r.   r$   r<   r   r   r   r>     r=   )Ú__doc__Úloggingr   Zsalt.utils.decorators.pathr   Zsalt.utils.pathÚ	getLoggerÚ__name__Úlogr   r   r   r   r   r   r,   r1   r2   r6   r8   r   Z
decoratorsr   r	   r9   r>   r   r   r   r   Ú<module>   s*    

""""
$