HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/apache.cpython-310.pyc
o

�N�g)1�@s�dZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlm
Z
e�e�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zd#dd�Zd$dd�Zdd�Zd%dd�Zd#dd�Zd&d!d"�ZdS)'a)
Support for Apache

.. note::
    The functions in here are generic functions designed to work with
    all implementations of Apache. Debian-specific functions have been moved into
    deb_apache.py, but will still load under the ``apache`` namespace when a
    Debian-based system is detected.
�N)�
SaltExceptioncCst�}tjj�|�rdSdS)z5
    Only load the module if apache is installed
    Zapache)FzFThe apache execution module cannot be loaded: apache is not installed.)�
_detect_os�salt�utils�path�which)�cmd�r	�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/apache.py�__virtual__srcCs,td}|dkr
dS|dks|dkrdSdS)zA
    Apache commands and paths differ depending on packaging
    �	os_familyZRedHatZ	apachectlZDebianZSuseZ
apache2ctl)Z
__grains__)rr	r	r
r'srcCs2t��d�}td|���}|d�d�}|dS)z
    Return server version (``apachectl -v``)

    CLI Example:

    .. code-block:: bash

        salt '*' apache.version
    z -v�cmd.runr�: �)r�__salt__�
splitlines�split)r�out�retr	r	r
�version5s
rcCs�t��d�}i}g|d<td|���}t�d�}|D]2}d|vr<|�d�}|s)q|d��||d�����dd	�<qd
|vrM|�	d|�}|d�
|�q|S)z�
    Return server version (``apachectl -V``)

    CLI Example:

    .. code-block:: bash

        salt '*' apache.fullversion
    z -VZ
compiled_withr
z	^\s+-D\s+rrr� �_z -D�)rrr�re�compiler�strip�lower�replace�sub�append)rrrZ	define_re�line�compsZcwithr	r	r
�fullversionEs 


&�r"cCs�t��d�}i}g|d<g|d<td|���}|D]#}|��}|s#qd|vr0|d�|d�d|vr=|d�|d�q|S)z�
    Return list of static and shared modules (``apachectl -M``)

    CLI Example:

    .. code-block:: bash

        salt '*' apache.modules
    z -MZstaticZsharedr
z(static)rz(shared))rrrrr)rrrr r!r	r	r
�modulesbs
�r#cCsJt��d�}g}td|���}|D]}|sqd|vr"|�|���q|S)z�
    Return list of modules compiled into the server (``apachectl -l``)

    CLI Example:

    .. code-block:: bash

        salt '*' apache.servermods
    z -lr
z.c)rrrrr)rrrr r	r	r
�
servermods|s
�r$cCsht��d�}i}td|�}|�dd�}|��D]}|sq|�d�}d�|dd��}|||d<q|S)	z�
    Return list of directives together with expected arguments
    and places where the directive is valid (``apachectl -L``)

    CLI Example:

    .. code-block:: bash

        salt '*' apache.directives
    z -Lr
z
	�	�
rNr)rrrrr�join)rrrr r!�descr	r	r
�
directives�s
r)cCst��d�}i}d}td|�}|��D]r}|sq|��}d|vr*|d}i||<q|ddkrOi||d<|d||dd<t�d	d|d
�||dd<|ddkr�i|||d
<|d
|||d
d<t�d	d|d
�|||d
d<|d|||d
d<q|S)aj
    Show the settings as parsed from the config file (currently
    only shows the virtualhost settings) (``apachectl -S``).
    Because each additional virtual host adds to the execution
    time, this command may require a long timeout be specified
    by using ``-t 10``.

    CLI Example:

    .. code-block:: bash

        salt -t 10 '*' apache.vhosts
    z -Srr
zis a NameVirtualHostr�default�Zvhostz\(|\)��conf�port�r)rrrrrr)rrZ	namevhostrr r!r	r	r
�vhosts�s,
"�r0cCs�d}d}||vr||vrdS||vrd|��}nd|��}t�|}td|�}|dr8|dr8|d��}|S|drD|d��}|S|d	rP|d	��}|Sd
|�d�}|S)z�
    Signals httpd to start, restart, or stop.

    CLI Example:

    .. code-block:: bash

        salt '*' apache.signal restart
    )Z
configtest�statusZ
fullstatus)�start�stopZrestartZgracefulz
graceful-stopNz -k rzcmd.run_all�retcode�stderr�stdoutz
Command: "z" completed successfully!)rrr)�signalZ
no_extra_args�
valid_signalsZ	argumentsrrrr	r	r
r7�s(


	���r7rcCstd||||�S)a{
    Add HTTP user using the ``htpasswd`` command. If the ``htpasswd`` file does not
    exist, it will be created. Valid options that can be passed are:

    .. code-block:: text

        n  Don't update file; display results on stdout.
        m  Force MD5 hashing of the password (default).
        d  Force CRYPT(3) hashing of the password.
        p  Do not hash the password (plaintext).
        s  Force SHA1 hashing of the password.

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.useradd /etc/httpd/htpasswd larry badpassword
        salt '*' apache.useradd /etc/httpd/htpasswd larry badpass opts=ns
    zwebutil.useradd�r)�pwfile�user�password�optsr	r	r
�useradd�sr>cCstd||�S)z�
    Delete HTTP user from the specified ``htpasswd`` file.

    CLI Example:

    .. code-block:: bash

        salt '*' apache.userdel /etc/httpd/htpasswd larry
    zwebutil.userdelr9)r:r;r	r	r
�userdels
r?r*c

Cs�ddddddddddddd�i}tdd|�d�d�}tdd|�d�d	�}tdd|�d
�d	�}tdd|�d�d	�}tdd|�d�d
�}|rr|rrtj��}|j||||d�tj��}|j||||d�tj�tj�||��|d7}ztjj||d��	��
�}	Wntjjy�YdSw|	D]K}
|
�
dd�}|d��|d<|d��|d<|ddkr�|dD]}|d|d7<q�q�|d��r�t|d�||d<q�t|d�||d<q�|S)ar
    Get Information from the Apache server-status handler

    .. note::

        The server-status handler is disabled by default.
        In order for this function to work it needs to be enabled.
        See http://httpd.apache.org/docs/2.2/mod/mod_status.html

    The following configuration needs to exists in pillar/grains.
    Each entry nested in ``apache.server-status`` is a profile of a vhost/server.
    This would give support for multiple apache servers/vhosts.

    .. code-block:: yaml

        apache.server-status:
          default:
            url: http://localhost/server-status
            user: someuser
            pass: password
            realm: 'authentication realm for digest passwords'
            timeout: 5

    CLI Examples:

    .. code-block:: bash

        salt '*' apache.server_status
        salt '*' apache.server_status other-profile
    Z
Scoreboardr)r�S�R�W�K�D�C�L�G�I�.z
config.getzapache.server-status:z:urlzhttp://localhost/server-statusz:userrz:passz:realmz:timeout�)�realmZurir;�passwdz?auto)�timeout�error�:r)r�urllib�requestZHTTPBasicAuthHandlerZadd_passwordZHTTPDigestAuthHandlerZinstall_openerZbuild_opener�urlopen�readrrN�URLErrorrr�isdigit�int�float)
Zprofiler�urlr;rLrKrMZbasic�digest�responser Zsplt�cr	r	r
�
server_statussZ ���

��r\c	Cs�t��}t|t�r!|rt|�d|��|dd�n�t|�|dd�n�t|t�r�d}|D]}d|vr8d}t|d�}q*|rptd|�d|�d�|d	�|D]}|��D]\}}|dkrctt|t|��|d	�qPqJtd
|�d�|d	�nx|D]
}tt|t|��|d	�qrngt|t�r�ztd�	||d�|d	�Wnt
y�td�	|���w|��D]6\}}|dkr�t|t�r�t|�d|��|d	�q�t|t�r�tt||�|d	�q�t|t�r�tt||�|d	�q�td
|�d�|d	�|�d
�|�
�S)z�
    Recursively goes through config structure and builds final Apache configuration

    :param conf: defined config structure
    :param slot: name of section container if needed
    rr)�file�endF�thisT�<�>)r]z</z<{} {}>zOApache section container "<{}>" expects attribute. Specify it using key "this".r)�io�StringIO�
isinstance�str�print�list�items�
_parse_config�dict�format�KeyErrorr�seekrS)	r-ZslotrZ
is_section�itemZ	slot_this�key�val�valuer	r	r
rirsZ

����
��


�
riTcCs�g}|D]}tt|����}|�t|||��qd�tjj�	|��}|rMtjj
�|d��}|�d�|�tjj
�|��Wd�|S1sHwY|S)a�
    Create VirtualHost configuration files

    name
        File for the virtual host
    config
        VirtualHost configurations

    .. note::

        This function is not meant to be used from the command line.
        Config is meant to be an ordered dict of all of the apache configs.

    CLI Example:

    .. code-block:: bash

        salt '*' apache.config /etc/httpd/conf.d/ports.conf config="[{'Listen': '22'}]"
    r&�wz # This file is managed by Salt.
N)�next�iter�keysrrir'rr�data�decode�filesZfopen�writeZstringutilsZto_str)�name�configZeditZconfigs�entryroZconfigstextZ
configfiler	r	r
r{�s

��r{)N)r)r*)T)�__doc__rb�loggingr�urllib.errorrP�urllib.requestZsalt.utils.datarZsalt.utils.filesZsalt.utils.pathZsalt.utils.stringutilsZsalt.exceptionsr�	getLogger�__name__�logrrrr"r#r$r)r0r7r>r?r\rir{r	r	r	r
�<module>s4



&
%

Z3