403Webshell
Server IP : 35.236.43.222  /  Your IP : 216.73.216.143
Web Server : Apache
System : Linux order-form-vm-001 5.10.0-37-cloud-amd64 #1 SMP Debian 5.10.247-1 (2025-12-11) x86_64
User : deploy ( 1002)
PHP Version : 8.1.31
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/certbot/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/certbot/__pycache__/reverter.cpython-39.pyc
a

�`�U�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
ddl	mZddlm
Z
ddlmZddlmZe�e�ZGdd	�d	e�ZdS)
zGReverter class saves configuration checkpoints and allows for recovery.�N)�errors)�util)�	constants)�
filesystem)�osc@s�eZdZdZdd�Zdd�Zd(dd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'S))�ReverterafReverter Class - save and revert configuration checkpoints.

    This class can be used by the plugins, especially Installers, to
    undo changes made to the user's system. Modifications to files and
    commands to do undo actions taken by the plugin should be registered
    with this class before the action is taken.

    Once a change has been registered with this class, there are three
    states the change can be in. First, the change can be a temporary
    change. This should be used for changes that will soon be reverted,
    such as config changes for the purpose of solving a challenge.
    Changes are added to this state through calls to
    :func:`~add_to_temp_checkpoint` and reverted when
    :func:`~revert_temporary_config` or :func:`~recovery_routine` is
    called.

    The second state a change can be in is in progress. These changes
    are not temporary, however, they also have not been finalized in a
    checkpoint. A change must become in progress before it can be
    finalized. Changes are added to this state through calls to
    :func:`~add_to_checkpoint` and reverted when
    :func:`~recovery_routine` is called.

    The last state a change can be in is finalized in a checkpoint. A
    change is put into this state by first becoming an in progress
    change and then calling :func:`~finalize_checkpoint`. Changes
    in this state can be reverted through calls to
    :func:`~rollback_checkpoints`.

    As a final note, creating new files and registering undo commands
    are handled specially and use the methods
    :func:`~register_file_creation` and :func:`~register_undo_command`
    respectively. Both of these methods can be used to create either
    temporary or in progress changes.

    .. note:: Consider moving everything over to CSV format.

    :param config: Configuration.
    :type config: :class:`certbot.interfaces.IConfig`

    cCs ||_t�|jtj|jj�dS)N)�configr�make_or_verify_dir�
backup_dirr�CONFIG_DIRS_MODE�strict_permissions)�selfr�r�2/usr/lib/python3/dist-packages/certbot/reverter.py�__init__?s�zReverter.__init__cCsVtj�|jj�rRz|�|jj�Wn.tjyPt�	d|jj�t�d��Yn0dS)aReload users original configuration files after a temporary save.

        This function should reinstall the users original configuration files
        for all saves with temporary=True

        :raises .ReverterError: when unable to revert config

        z$Incomplete or failed recovery for %sz!Unable to revert temporary configN)
r�path�isdirr�temp_checkpoint_dir�_recover_checkpointr�
ReverterError�logger�critical�r
rrr�revert_temporary_configEs	�z Reverter.revert_temporary_config�cCs�zt|�}Wn&ty2t�d�t�d��Yn0|dkrPt�d�t�d��t�|jj	�}|�
�|svt�d�nt|�|kr�t�d|t|��|dkr�|r�tj
�|jj	|���}z|�|�Wn(tjy�t�d�t�d��Yn0|d8}q�d	S)
ayRevert 'rollback' number of configuration checkpoints.

        :param int rollback: Number of checkpoints to reverse. A str num will be
           cast to an integer. So "2" is also acceptable.

        :raises .ReverterError:
            if there is a problem with the input or if the function is
            unable to correctly revert the configuration checkpoints

        z,Rollback argument must be a positive integerz
Invalid InputrzHCertbot hasn't modified your configuration, so rollback isn't available.z0Unable to rollback %d checkpoints, only %d existz)Failed to load checkpoint during rollbackz)Unable to load checkpoint during rollbackrN)�int�
ValueErrorr�errorrrr�listdirrr
�sort�warning�lenr�join�poprr)r
ZrollbackZbackups�cp_dirrrr�rollback_checkpointsYs8


��
�
zReverter.rollback_checkpointscCs|�|jj||�dS)z�Add files to temporary checkpoint.

        :param set save_files: set of filepaths to save
        :param str save_notes: notes about changes during the save

        N)�_add_to_checkpoint_dirrr�r
�
save_files�
save_notesrrr�add_to_temp_checkpoint�s
�zReverter.add_to_temp_checkpointcCs |�|�|�|jj||�dS)z�Add files to a permanent checkpoint.

        :param set save_files: set of filepaths to save
        :param str save_notes: notes about changes during the save

        N)�_check_tempfile_savesr&r�in_progress_dirr'rrr�add_to_checkpoint�s

�zReverter.add_to_checkpointc	
Cs t�|tj|jj�|�tj�	|d��\}}t
|�}|D]�}||vr8t�d|�z>t
�|tj�	|tj�|�dt|���|�d�|��Wn:ty�|��t�d||�t�d�||���Yn0|d7}q8|��ttj�	|d�d	��}|�|�Wd
�n1�s0Yd
S)agAdd save files to checkpoint directory.

        :param str cp_dir: Checkpoint directory filepath
        :param set save_files: set of files to save
        :param str save_notes: notes about changes made during the save

        :raises IOError: if unable to open cp_dir + FILEPATHS file
        :raises .ReverterError: if unable to add checkpoint

        �	FILEPATHSzCreating backup of %s�_�{0}
z&Unable to add file %s to checkpoint %sz(Unable to add file {0} to checkpoint {1}r�
CHANGES_SINCE�aN)rr	rrrr�_read_and_appendrrr"r!r�debug�shutil�copy2�basename�str�write�format�IOError�closerrr�open)	r
r$r(r)�op_fdZexisting_filepaths�idx�filenameZnotes_fdrrrr&�s<������

zReverter._add_to_checkpoint_dircCs:tj�|�r$t|d�}|����}ng}t|d�}||fS)z�Reads the file lines and returns a file obj.

        Read the file returning the lines, and a pointer to the end of the file.

        zr+�w)rr�isfiler=�read�
splitlines)r
�filepathr>�linesrrrr3�s

zReverter._read_and_appendc
CsFtj�tj�|d��r*|�tj�|d��tj�tj�|d��r�z~ttj�|d���X}|����}t|�D]2\}}t	�
tj�|tj�|�dt|��|�qjWd�n1s�0YWn0t
tfy�t�d|�t�d|��Yn0|�tj�|d��zt	�|�Wn.t�y@t�d|�t�d|��Yn0dS)aRecover a specific checkpoint.

        Recover a specific checkpoint provided by cp_dir
        Note: this function does not reload augeas.

        :param str cp_dir: checkpoint directory file path

        :raises errors.ReverterError: If unable to recover checkpoint

        �COMMANDSr.r/NzUnable to recover files from %s�	NEW_FILESzUnable to remove directory: %s)rrrBr"�_run_undo_commandsr=rCrD�	enumerater5r6r7r8r;�OSErrorrrrr�_remove_contained_filesZrmtree)r
r$Zpaths_fd�	filepathsr?rrrrr�s4
��(�
�zReverter._recover_checkpointcCs�tjddkrddini}t|dfi|���b}t�|�}tt|��D]:}zt�|�WqDt	j
y|t�dd�
|��YqD0qDWd�n1s�0YdS)	zRun all commands in a file.r��newline��rzUnable to run undo command: %s� N)�sys�version_infor=�csv�reader�reversed�listrZ
run_scriptrZSubprocessErrorrrr")r
rE�kwargsZcsvfileZ	csvreader�commandrrrrI�s

�zReverter._run_undo_commandscCs�g}tj�|jjd�}tj�|�r^t|d��"}|�|���	��Wd�n1sT0Ytj�|jjd�}tj�|�r�t|d��"}|�|���	��Wd�n1s�0Y|D]}||vr�t
�d|��q�dS)z�Verify save isn't overwriting any temporary files.

        :param set save_files: Set of files about to be saved.

        :raises certbot.errors.ReverterError:
            when save is attempting to overwrite a temporary file.

        r.rQNrHz+Attempting to overwrite challenge file - %s)rrr"rrrBr=�extendrCrDrr)r
r(Zprotected_filesZ	temp_pathZprotected_fd�new_pathr@rrrr+
s 	00��zReverter._check_tempfile_savesc	Gs�|st�d��|�|�}d}z�z>|�tj�|d��\}}|D]}||vr<|�d�|��q<Wn2t	t
fy�t�d|�t�d�|���Yn0W|dur�|�
�n|dur�|�
�0dS)aARegister the creation of all files during certbot execution.

        Call this method before writing to the file to make sure that the
        file will be cleaned up if the program exits unexpectedly.
        (Before a save occurs)

        :param bool temporary: If the file creation registry is for
            a temp or permanent save.
        :param \*files: file paths (str) to be registered

        :raises certbot.errors.ReverterError: If
            call does not contain necessary parameters or if the file creation
            is unable to be registered.

        z,Forgot to provide files to registration callNrHr0z(Unable to register file creation(s) - %sz)Unable to register file creation(s) - {0})rr�_get_cp_dirr3rrr"r9r:r;rKrrr<)r
�	temporary�filesr$Znew_fdZex_filesrrrr�register_file_creation+s$

�
�zReverter.register_file_creationc	Cs�tj�|�|�d�}d}tjddkr.ddini}z�zJtj�|�rVt|dfi|��}nt|dfi|��}t�	|�}|�
|�Wn*ttfy�t
�d	�t�d
��Yn0W|dur�|��n|dur�|��0dS)a�Register a command to be run to undo actions taken.

        .. warning:: This function does not enforce order of operations in terms
            of file modification vs. command registration.  All undo commands
            are run first before all normal files are reverted to their previous
            state.  If you need to maintain strict order, you may create
            checkpoints before and after the the command registration. This
            function may be improved in the future based on demand.

        :param bool temporary: Whether the command should be saved in the
            IN_PROGRESS or TEMPORARY checkpoints.
        :param command: Command to be run.
        :type command: list of str

        rGNrrNrOrPr2rAzUnable to register undo commandz Unable to register undo command.)rrr"r]rSrTrBr=rU�writerZwriterowr;rKrrrrr<)r
r^rZZcommands_fpZcommand_filerYZ	csvwriterrrr�register_undo_commandRs$

�
�zReverter.register_undo_commandcCs.|r|jj}n|jj}t�|tj|jj�|S)z%Return the proper reverter directory.)rrr,rr	rrr)r
r^r$rrrr]xs
�zReverter._get_cp_dircCsf|��tj�|jj�rbz|�|jj�Wn6tjy`t	�
d|jj�t�d|jj��Yn0dS)aCRevert configuration to most recent finalized checkpoint.

        Remove all changes (temporary and permanent) that have not been
        finalized. This is useful to protect against crashes and other
        execution interruptions.

        :raises .errors.ReverterError: If unable to recover the configuration

        z=Incomplete or failed recovery for IN_PROGRESS checkpoint - %sN)rrrrrr,rrrrrrrrr�recovery_routine�s���zReverter.recovery_routinec	Cs�tj�|�sdSzht|d��J}|����}|D](}tj�|�rJt�|�q.t�	d|�q.Wd�n1sl0YWn2t
tfy�t�d|�t
�d�|���Yn0dS)a Erase all files contained within file_list.

        :param str file_list: file containing list of file paths to be deleted

        :returns: Success
        :rtype: bool

        :raises certbot.errors.ReverterError: If
            all files within file_list cannot be removed

        FrQzVFile: %s - Could not be found to be deleted
 - Certbot probably shut down unexpectedlyNz.Unable to remove filepaths contained within %sz/Unable to remove filepaths contained within {0}T)rrrBr=rCrD�lexists�removerr r;rKrrrr:)r
Z	file_listZlist_fdrMrrrrrL�s,�(���
z Reverter._remove_contained_filesc	CsLtj�|jj�sdStj�|jjd�}tj�|jjd�}tj�|�s�t�d�t	|d��}|�
d�Wd�n1sx0Yz�t	|d��V}|�
d|�t	|d��}|�
|���Wd�n1s�0YWd�n1s�0Yt�
||�Wn<ttf�y>t�d	�t�d
t���t�d��Yn0|��dS)aZFinalize the checkpoint.

        Timestamps and permanently saves all changes made through the use
        of :func:`~add_to_checkpoint` and :func:`~register_file_creation`

        :param str title: Title describing checkpoint

        :raises certbot.errors.ReverterError: when the
            checkpoint is not able to be finalized.

        Nr1zCHANGES_SINCE.tmpz/Rollback checkpoint is empty (no changes made?)rAzNo changes
z	-- %s --
rQz,Unable to finalize checkpoint - adding titlezException was:
%szUnable to add title)rrrrr,r"�existsr�infor=r9rCr5Zmover;rKrr4�	traceback�
format_excrr�_timestamp_progress_dir)r
�titleZchanges_since_pathZchanges_since_tmp_path�fZchanges_tmpZchanges_origrrr�finalize_checkpoint�s&

(J
zReverter.finalize_checkpointcCs�tt���}t�tj�|jjd��}dd�|D�}|�|�|�	�|d|krxtt
|d�d�}t�d||�|}n<t
|�dkr�|d|kr�t�d|�tt
|d�d	�}|}|S)
zBDetermine the timestamp of the checkpoint, enforcing monotonicity.z[0-9]*cSsg|]}tj�|��qSr)rrr7)�.0�drrr�
<listcomp>��z2Reverter._checkpoint_timestamp.<locals>.<listcomp>���rzyCurrent timestamp %s does not correspond to newest reverter checkpoint; your clock probably jumped. Time travelling to %s���z6Race condition with timestamp %s, incrementing by 0.01g{�G�z�?)r8�time�globrrr"rr
�appendr�floatrr r!r4)r
�	timestampZothersZ
timetravelrrr�_checkpoint_timestamp�s 
�zReverter._checkpoint_timestampc	Cs�tj�d�D]V}|��}tj�|jj|�}zt	�
|jj|�WdSty`t
�d|�Yq0qt
�d|jj|�t�d��dS)zTimestamp the checkpoint.rNNz1Extreme, unexpected race condition, retrying (%s)z'Unable to finalize checkpoint, %s -> %sz&Unable to finalize checkpoint renaming)�sixZmoves�rangeryrrr"rr
r�replacer,rKrr rrr)r
r/rxZ	final_dirrrrrjs��z Reverter._timestamp_progress_dirN)r)�__name__�
__module__�__qualname__�__doc__rrr%r*r-r&r3rrIr+r`rbr]rcrLrmryrjrrrrrs&)
*
-''&&)r)r�rUruZloggingr5rSrtrhrzZcertbotrrZcertbot._internalrZcertbot.compatrrZ	getLoggerr}r�objectrrrrr�<module>s


Youez - 2016 - github.com/yon3zu
LinuXploit