HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/incron.cpython-310.pyc
o

�N�g|�@s�dZddlZddlZddlZddlZddlZddlZe�e	�Z
dZdZgd�Z
dd�Zdd	�Zd
d�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zejj�ed�Zdd�Zdd �Zejj�ed!�ZdS)"z
Work with incron
�Nz## Line managed by Salt, do not editz/etc/incron.d/)Z	IN_ACCESSZ	IN_ATTRIBZIN_CLOSE_WRITEZIN_CLOSE_NOWRITEZ	IN_CREATEZ	IN_DELETEZIN_DELETE_SELFZ	IN_MODIFYZIN_MOVE_SELFZ
IN_MOVED_FROMZIN_MOVED_TOZIN_OPENZ
IN_ALL_EVENTSZIN_MOVEZIN_CLOSEZIN_DONT_FOLLOWZ
IN_ONESHOTZ
IN_ONLYDIRZ
IN_NO_LOOPcCs0||kr|dkr|dkrdSdS|durdSdS)N�random�*TF�)�old�newrr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/incron.py�
_needs_change)s�rc	CsTg}|dD]
}|�|�d��q|dD]}|�d�|d|d|d��q|S)z[
    Takes a tab list structure and renders it to a list for applying it to
    a file
    �pre�
�cronsz	{} {} {}
�path�mask�cmd)�append�format)�lst�retr	�cronrrr�_render_tab4s��rcCs
d|��S)zL
    Returns a format string, to be used to build an incrontab command.
    z
incrontab r)rrrr�_get_incron_cmdstrGs
rcCstdt|�|dd�dkS)z�
    Writes the contents of a file to a user's incrontab

    CLI Example:

    .. code-block:: bash

        salt '*' incron.write_incron_file root /tmp/new_incron
    zcmd.retcodeF��runas�python_shellr��__salt__r��userrrrr�write_incron_fileNs
���rcCstdt|�|dd�S)z�
    Writes the contents of a file to a user's incrontab and return error message on error

    CLI Example:

    .. code-block:: bash

        salt '*' incron.write_incron_file_verbose root /tmp/new_incron
    �cmd.run_allFrrrrrr�write_incron_file_verbose`s

�rcCs�|dkri}ttdd�|��|d<|Stjj��}tjj�|d��}|�tjj	�
|��Wd�n1s6wY|dkrMtdd	|�d
|��dd�td
t|�|dd�}t
�|�|S)zS
    Takes a list of lines to be committed to a user's incrontab and writes it
    �system�salt��retcode�wbN�rootzcmd.runzchown � F)rrr)�_write_file�_INCRON_SYSTEM_TAB�joinr!�utils�filesZmkstemp�fopen�
writelines�data�encoderr�os�remove)r�linesrr�fp_rrr�_write_incron_linesos�
�
r4cCs�tj�||�}tj�|�s |�d|�d�}t�|�tt|���tj	j
�|d��}|�tj	j
�|��Wd�dS1s>wYdS)z
    Writes a file to disk
    z cannot be written. z does not exist�wNr)r0rr)�exists�log�error�AttributeError�strr!r*r+r,�writeZstringutilsZto_str)�folder�filenamer.r�msgr3rrrr'�s

��r'cCsntj�||�}z%tjj�|d��}tjj�|�	��Wd�WS1s%wYWdSt
y6YdSw)z2
    Reads and returns the contents of a file
    �rbNr")r0rr)r!r*r+r,r.�decode�	readlines�OSError)r<r=r�contentsrrr�
_read_file�s(��rDcCs"t�dttd��d�ttd��S)z�
    Return the contents of the system wide incrontab

    CLI Example:

    .. code-block:: bash

        salt '*' incron.raw_system_incron
    zread_file %sr!r")r7�debugrDr(r)rrrr�raw_system_incron�s
rFcCsd|��}td|d|dd�S)z�
    Return the contents of the user's incrontab

    CLI Example:

    .. code-block:: bash

        salt '*' incron.raw_incron root
    z
incrontab -l zcmd.run_stdoutF)�rstriprr)r)rrrrr�
raw_incron�s

rHc
Cs�|dkrt�}n
t|�}t�d|�ggd�}d}|��D]4}t|���dkrJ|��}|d}|d}d�|d	d
��}|||d�}	|d�|	�q|d
�|�q|S)z�
    Return the contents of the specified user's incrontab

    CLI Example:

    .. code-block:: bash

        salt '*' incron.list_tab root
    r zuser data %s)rr	F�r�r&�N)rr
rrr	)	rFrHr7rE�
splitlines�len�splitr)r)
rr.r�flag�line�compsrr
rZdatrrr�list_tab�s 

rR�lscs,t|���}|�d�D]
}|tvrd|��Sqd}|�d�}|��t|�}g}t|d�D]A\}}	||	dkrl|	d|krf|	d�d������|krRdSt�fd	d
�|D��r`d}q0|�|	�q0|�|	�q0|�|	�q0|||d�}	|�|	�||d<t	|t
|��}
|
d
r�|
dS|r�dSdS)z�
    Sets an incron job up for a specified user.

    CLI Example:

    .. code-block:: bash

        salt '*' incron.set_job root '/root' 'IN_MODIFY' 'echo "$$ $@ $# $% $&"'
    �,�Invalid mask type: Frrrr
Zpresentcsg|]}|�v�qSrr)�.0�x�Z	cron_maskrr�
<listcomp>szset_job.<locals>.<listcomp>T)rrr
r#�stderr�updatedr)r:�upperrN�_MASK_TYPES�sortrR�	enumerate�anyrr4r)rrr
r�itemr[Zarg_maskrZ
updated_cronsr�comdatrrXr�set_job�s>�

rccCs�t|���}|�d�D]
}|tvrd|��Sqt|�}d}d}t|d�D]\}}	|dur1n||	dkrE||	dkrE||	dkrE|}q'|durS|d�|�d	}t|t|��}
|
d
rb|
dS|S)z�
    Remove a incron job for a specified user. If any of the day/time params are
    specified, the job will only be removed if the specified params match.

    CLI Example:

    .. code-block:: bash

        salt '*' incron.rm_job root /path
    rTrUZabsentNrrrr
Zremovedr#rZ)	r:r\rNr]rRr_�popr4r)rrr
rrarrZrm_Zind�valrbrrr�rm_jobs.
��rf�rm) �__doc__�loggingr0Zsalt.utils.datar!Zsalt.utils.filesZsalt.utils.functoolsZsalt.utils.stringutils�	getLogger�__name__r7ZTAGr(r]rrrrrr4r'rDrFrHrRr*�	functoolsZalias_functionrSrcrfrgrrrr�<module>s4
!:)