| Current Path : /proc/self/root/lib/python3/dist-packages/certbot_apache/__pycache__/ |
| Current File : //proc/self/root/lib/python3/dist-packages/certbot_apache/__pycache__/parser.cpython-38.pyc |
U
���]� � @ s� d Z ddlZddlZddlZddlZddlZddlZddlZddlm Z m
Z
mZ ddlm
Z
ddlmZ ddlmZ e�e�ZG dd� de�Zd d
� Zdd� ZdS )
z@ApacheParser is a member object of the ApacheConfigurator class.� N)�Dict�List�Set)�errors)�os)� constantsc @ s� e Zd ZdZe�d�Zedddddg�Zdbd
d�Z dd
� Z
dd� Zdd� Zdd� Z
dd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd$d%� Zd&d'� Zd(d)� Zd*d+� Zd,d-� Zd.d/� Zd0d1� Zdcd3d4�Zddd5d6�Zd7d8� Zd9d:� Z d;d<� Z!ded=d>�Z"dfd@dA�Z#dBdC� Z$dDdE� Z%dFdG� Z&dHdI� Z'dJdK� Z(dLdM� Z)dNdO� Z*dPdQ� Z+dRdS� Z,dTdU� Z-dVdW� Z.dXdY� Z/dZd[� Z0d\d]� Z1d^d_� Z2d`da� Z3dS )g�ApacheParsera� Class handles the fine details of parsing the Apache Configuration.
.. todo:: Make parsing general... remove sites-available etc...
:ivar str root: Normalized absolute path to the server root
directory. Without trailing slash.
:ivar set modules: All module names that are currently enabled.
:ivar dict loc: Location to place directives, root - configuration origin,
default - user config file, name - NameVirtualHost,
z\$\{[^ \}]*}�*�?�\�[�]N�� � c C s� || _ d | _| �� | �� s&t�d��t� | _i | _i | _ t
j�|�| _
d| �� i| _| �| jd � |dkrv| �� | �� | �� | j�| �� � t�| j�| _|r�| �t
j�|�d | j �d� � |dk r�| jddd�r�t�d ��d S )
Nz�Apache plugin support requires libaugeas0 and augeas-lenses version 1.2.0 or higher, please make sure you have you have those installed.�rootr �/Zvhost_filesZDefineF)�excludezError parsing runtime variables)�configurator�aug�init_augeas�check_aug_versionr ZNotSupportedError�set�modules�parser_paths� variablesr �path�abspathr �_find_config_root�loc�
parse_file�update_runtime_variables�standardize_excl�
parse_modules�update�_set_locations�copy�deepcopy�existing_paths�option�find_dir�PluginError)�selfr Z vhostroot�versionr � r. �7/usr/lib/python3/dist-packages/certbot_apache/parser.py�__init__% s4 �
�zApacheParser.__init__c C sV zddl }W n tk
r* t�d��Y nX |jtj|jj|jjB |jj B d�| _
dS )z' Initialize the actual Augeas instance r NzProblem in Augeas installation)Zloadpath�flags)�augeas�ImportErrorr �NoInstallationErrorZAugeasr ZAUGEAS_LENS_DIRZNONEZNO_MODL_AUTOLOADZENABLE_SPANr )r, r2 r. r. r/ r [ s ���zApacheParser.init_augeasc C sv | j �d�}|D ]`}| j �|d �}|r||krd�|dt|�d � | j �|d �| j �|d ��}t�|��qdS ) z�Verify Augeas can parse all of the lens files.
:param str lens: lens to check for errors
:raises .errors.PluginError: If there has been an error in parsing with
the specified lens.
�/augeas//errorz/lensz@There has been an error in parsing the file {0} on line {1}: {2}�
� z/linez/messageN)r �match�get�format�lenr r+ )r, ZlensZerror_filesr Z lens_path�msgr. r. r/ �check_parsing_errorsl s ��z!ApacheParser.check_parsing_errorsc C sR | j �dd� z| j �d�}W n" tk
r@ | j �d� Y dS X | j �d� |S )z� Checks that we have recent enough version of libaugeas.
If augeas version is recent enough, it will support case insensitive
regexp matchingz/test/path/testing/argZaRgUMeNTz,/test//*[self::arg=~regexp('argument', 'i')]z
/test/pathF)r r r8 �RuntimeError�remove)r, �matchesr. r. r/ r � s �zApacheParser.check_aug_versionc C s� | j �d�}| j �dd� | j �d�}z| j �� W n4 ttfk
rh | �|� d| j_ t
�d��Y nX | j �d|� | j �d�}t� }|r�|D ]}|�| j �|�dd� � q�|S ) a� Lists files that have modified Augeas DOM but the changes have not
been written to the filesystem yet, used by `self.save()` and
ApacheConfigurator to check the file state.
:raises .errors.PluginError: If there was an error in Augeas, in
an attempt to save the configuration, or an error creating a
checkpoint
:returns: `set` of unsaved files
z/augeas/saveZnoopr5 � z-Error saving files, check logs for more info.z/augeas/events/savedr7 N)
r r9 r r8 �saver>