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__/cron.cpython-310.pyc
o

�N�g6p�@sPdZddlZddlZddlZddlZddlZddlZddlZddl	ZdZ
dZdZe�
e�Zdd�Zdd	�Zd
d�Zd5dd
�Zdd�Zdd�Zd5dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zejj� ed"�Z!d6d#d$�Z"d7d&d'�Z#d(d)�Z$	%		d7d*d+�Z%d6d,d-�Z&						d8d.d/�Z'ejj� e'd0�Z(d5d1d2�Z)d3d4�Z*dS)9z�
Work with cron

.. note::
    Salt does not escape cron metacharacters automatically. You should
    backslash-escape percent characters and any other metacharacters that might
    be interpreted incorrectly by the shell.
�Nz4# Lines below here are managed by Salt, do not edit
�SALT_CRON_IDENTIFIERz	NO ID SETcCstjj�d�r	dSdS)N�crontabT)Fz2Cannot load cron module: crontab command not found)�salt�utils�path�which�rr�E/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/cron.py�__virtual__sr
cCs8t|t�s	t|�}ztjj�|�WStyYdSw)N�)�
isinstance�strrr�stringutilsZ
to_unicode�	TypeError)�valrrr	�_ensure_string"s
�rcCs*d}|dr|d}nt}|rt|�SdS)z4SAFETYBELT, Only set if we really have an identifierN�
identifier)�SALT_CRON_NO_IDENTIFIERr)�cron�cidrrr	�_cron_id-s
�rcCs�d\}}t|�}|r9|st}t|�}|�dd�|kr%|tkr%|tkr%d}n|�dd�|kr5|tkr5|r5|}||k}|durE||�dd�ksG|rId}|S)aoCheck if:
    - we find a cron with same cmd, old state behavior
    - but also be smart enough to remove states changed crons where we do
      not removed priorly by a cron.absent by matching on the provided
      identifier.
      We assure retrocompatibility by only checking on identifier if
      and only if an identifier was set on the serialized crontab
    )FN�cmdNFT)rrr�get)rrr�retZ
id_matchedrZeidentifierrrr	�
_cron_matched8s&	�rcCs0||kr|dkr|dkrdSdS|durdSdS)N�random�*TFr)�old�newrrr	�
_needs_changebs�rc
Cs
g}|dD]
}|�|�d��q|r|dtkr|�t�n|�t�|dD]&}|ddus6|ddkrA|�d�|d	��q(|�d
�|d	|d��q(|dD]Z}|ddusa|d
dur�d}|drt|d�|d�dd��7}|d
r�|d�t|d
�7}|d7}|�|�|�d�|ddur�dp�d|d|d|d|d|d|d��qS|dD]P}|ddus�|d
dur�d}|dr�|d�|d���dd��7}|d
r�|d�t|d
�7}|d7}|�|�|�d�|ddur�dp�d|d|d��q�|S)z[
    Takes a tab list structure and renders it to a list for applying it to
    a file
    �pre�
����env�valueNrz{}=""
�namez{}={}
�crons�commentr�#z {}z
# z {}:{}z{}{} {} {} {} {} {}
�	commentedT�
#DISABLED#�minute�hour�daymonth�month�dayweekr�specialz{}{} {}
�spec)�append�TAG�format�replacer�rstrip)�lstrr r#rr'rrr	�_render_tabmsb
�

��
��r8cCs"|rd|��}nd}|�d|��S)zI
    Returns a format string, to be used to build a crontab command.
    �crontab -u r� r)r�userrrrr	�_get_cron_cmdstr�sr<cCst��td|�kS)zO
    Returns true if running instance's UID matches the specified user UID
    �file.user_to_uid)�os�geteuid�__salt__)r;rrr	�_check_instance_uid_match�srAcCs�t�d�dvrtdt|�|dd�dkSt|�r$tdt|�dd�dkStd�r5tdt||�dd�dkStdt|�|dd�dkS)	a1
    Writes the contents of a file to a user's crontab

    CLI Example:

    .. code-block:: bash

        salt '*' cron.write_cron_file root /tmp/new_cron

    .. versionchanged:: 2015.8.9

    .. note::

        Some OS' do not support specifying user via the `crontab` command i.e. (Solaris, AIX)
    �	os_family��SolarisZAIXzcmd.retcodeF��runas�python_shellr�rG�root��
__grains__rr@r<rA�r;rrrr	�write_cron_file�s(
�����
���rMcCstt�d�dvrtdt|�|dd�St|�r tdt|�dd�Std�r/tdt||�dd�Stdt|�|dd�S)a[
    Writes the contents of a file to a user's crontab and return error message on error

    CLI Example:

    .. code-block:: bash

        salt '*' cron.write_cron_file_verbose root /tmp/new_cron

    .. versionchanged:: 2015.8.9

    .. note::

        Some OS' do not support specifying user via the `crontab` command i.e. (Solaris, AIX)
    rBrC�cmd.run_allFrErHrIrJrLrrr	�write_cron_file_verbose�s
�
�rOcCs�dd�|D�}tjj��}t�d�dvrDtjjj|dtd|�dd��
}|�|�Wd	�n1s3wYtd
t	|�|dd�}n�t
|�rrtjjj|ddd
��
}|�|�Wd	�n1sbwYtd
t	|�dd�}n^t
d�r�tjjj|ddd
��
}|�|�Wd	�n1s�wYtd
t	||�dd�}n/tjjj|dtd|�dd��
}|�|�Wd	�n1s�wYtd
t	|�|dd�}t�|�|S)zQ
    Takes a list of lines to be committed to a user's crontab and writes it
    cSsg|]	}tjj�|��qSr)rrrZto_str)�.0Z_lrrr	�
<listcomp>�z%_write_cron_lines.<locals>.<listcomp>rBrCzw+r=i�)�uid�modeNrNFrE)rTrHrI)
rr�filesZmkstemprKrZfpopenr@�
writelinesr<rAr>�remove)r;�linesrZfp_rrrr	�_write_cron_linessB��
�����
�
rYcst��fdd�dD��S)z|
    Returns true if the minute, hour, etc. params match their counterparts from
    the dict returned from list_tab().
    csNg|]#}��|�dup$�|t�|�kp$t�|���dko$�|dk�qS)Nrr)rr
�lower�rP�x�r�kwargsrr	rQ3s���z$_date_time_match.<locals>.<listcomp>�r+r,r-r.r/)�allr]rr]r	�_date_time_match-s
��rac	Cs�t�d�dvrd}tjj�td||dddd���d�}nKt|�r6d}tjj�td|dddd���d�}n2td	�rSd
|�d�}tjj�td|dddd���d�}nd}tjj�td||dddd���d�}|rv|d�	d
�rv|dd�=d�
|�S)z�
    Return the contents of the user's crontab

    CLI Example:

    .. code-block:: bash

        salt '*' cron.raw_cron root
    rBrCz
crontab -lzcmd.run_stdoutTF)rF�ignore_retcoder6rG)rbr6rGrIr9z -lrz8# DO NOT EDIT THIS FILE - edit the master and reinstall.�r)rKrrr�data�decoder@�
splitlinesrA�
startswith�join)r;rrXrrr	�raw_cron<sP
���������
����

ricCsNt|�}ggggd�}d}d}d}|��D�]}|dkrd}q|�rd}|�d�r1|dd�}d}|�d�rti}|��}	t|	�d	krCq|	d
|d<d�|	d
d��|d<||d<||d<d|d<|rfd|d<|d�|�d}d}d}q|�d�r�|�d�}
t|
vr�|
�t�}|d
�	�}
t|d
�d
kr�|d
d
d�}|dur�|
}q|d|
7}q|�
d�d
kr�d|vs�|�d�|�d�kr�|�dd
�}	i}|	d
|d<|	d
|d<|d�|�qt|�d��dk�r|�d�}	|	d
|	d
|	d	|	d|	d|d�|	dd��|dd�	}|�rd|d<|d�|�d}d}d}q|d�|�q|S) z�
    Return the contents of the specified user's crontab

    CLI Example:

    .. code-block:: bash

        salt '*' cron.list_tab root
    )r r&r0r#FNz3# Lines below here are managed by Salt, do not editTr*�
�@�rr1r:�rrr'r)r0r(z# r!�=r%r$r#�rc�)	r+r,r-r.r/rrr'r)r&r )rirfrg�split�lenrhr2�lstriprr6�find�index)r;rdr�flagr'r�lineZcommented_cron_jobZdat�compsZcomment_line�partsrrr	�list_tabrs�






��rz�lscCsx|r|rt�d�d}t|��dg�t|��dg�}|D]}|r,|�d�|kr,|S|r9|�d�|kr9|SqdS)a�
    Return the specified entry from user's crontab.
    identifier will be used if specified, otherwise will lookup cmd
    Either identifier or cmd should be specified.

    user:
        User's crontab to query

    identifier:
        Search for line with identifier

    cmd:
        Search for cron line with cmd

    CLI Example:

    .. code-block:: bash

        salt '*' cron.get_entry root identifier=task1
    z=Both identifier and cmd are specified. Only using identifier.Nr&r0rrF)�log�warningrzr)r;rrZcron_entriesZ
cron_entryrrr	�	get_entry�s
 �r~Fc
Cst|�}|d|dD]�}t|�}t|||�r�|ddur tp#|d}	|d|f|d|f||	f|�d�df|�d�df|�d	�df|�d
�df|�d�df|�d�|fg	}
|s[|rd|
�|d
|f�tdd�|
D��r�d|vryt|||d�nt|||d�t	|�d�|�s�|�d�}t	|�d�|�s�|�d�}t	|�d�|�s�|�d�}t	|d
|�s�|d
}|tkr�|r�|}|tkr�|ddur�d}||d<|r�|r�t	||�s�|}t
||||||d�}|dkr�dS|SdSq|||||d�}|d�|�t|t|��}|d�r
|dSdS)z�
    Set up a special command in the crontab.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.set_special root @hourly 'echo foobar'
    r&r0rNr'r)r+r,r-r.r/r1rcS�g|]	\}}t||��qSr�r�rPr\�yrrr	rQrRzset_special.<locals>.<listcomp>�r�r)r'rr�updated�present)r1rrr'r)�retcode�stderr)
rzrrrrr2�any�
rm_special�rm_jobr�set_specialrYr8)
r;r0rr)r'rr7rr�test_setted_id�tests�jret�comdatrrr	r��s�
��

�


��<�
r�c
	Ksftttd���tttd���tttdd���tttd���d�}i}dD]K}t|�|d����}|dkrCtt�||d�d	�||<q$t|�d
��dkrkt	|�d
��}t
|d	�t
|d�}}tt�||��||<q$|||<q$|dd
��vr{d}n
|dd��vr�d}nd}t|�dd����}	|	dkr�tt�tttd|d���d�d	�|d<|S|	|d<|S)zG
    Returns a dict of date/time values to be used in a cron entry
    �<�rm�
�)r+r,r.r/�1rr�:rlr.z1 3 5 7 8 10 12�z4 6 9 11��r-)�list�ranger
rrZr�samplerrrq�sorted�int�randint)
r^Z	range_maxr�paramr$Z
cron_range�start�endZdaymonth_maxr-rrr	�_get_cron_date_timeNs8�
 ��r�c

Cs�t|���}t|���}t|���}t|���}t|���}t|�}
|
d|
dD�] }t|�}t|||	��rK|ddur@tpC|d}
|d|f|d|f|	|
f|�d�|f|�d�|f|�d	�|f|�d
�|f|�d�|f|�d�dfg	}|s{|	r�|�|d
|f�tdd�|D���rHd|vr�t	|||d�nt
|||d�t|�d�|�s�|�d�}t|�d�|�s�|�d�}t|�d	�|�s�|�d	�}t|�d
�|�s�|�d
�}t|�d�|�s�|�d�}t|d|�s�|d}t|d|�s�|d}t|d
|��s |d
}|tk�r |	�r|	}|tk�r|ddu�rd}||d<|�r,|�r.t||	��s.|}	t||||||||||	d�
}|dk�rDdS|SdSq*||	||d�}|�
t|||||d��|
d�|�t|t|
��}|d�rv|dSdS)z�
    Sets a cron job up for a specified user.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.set_job root '*' '*' '*' '*' 1 /usr/local/weekly
    r&r0rNr'r)r+r,r-r.r/r1rcSrrr�r�rrr	rQ�rRzset_job.<locals>.<listcomp>r�r�rr�r�)rrr'r)r_r�r�)r
rZrzrrrrr2r�r�r�r�set_job�updater�rYr8)r;r+r,r-r.r/rr)r'rr7rrr�r�r�r�rrr	r�ys���

�






�
�H�
��
r�c
Cs�t|�}d}d}t|d�D] \}}|durnt|||d�r.|dur&|}q|d|kr.|}q|dur<|d�|�d}t|t|��}	|	drK|	dS|S)	z�
    Remove a special cron job for a specified user.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.rm_special root /usr/bin/foo
    �absentNr0r�r1�removedr�r�)rz�	enumerater�poprYr8)
r;rr0rr7r�rm_�indrr�rrr	r��s&
�r�c	Cs�t|�}d}	d}
t|d�D].\}}|
durn%t|||d�r<tdd�|||||fD��s0|}
qt||||||d�r<|}
q|
durY|d�|
�d}	t|t|��}
|
d	rY|
d
S|	S)a8
    Remove a cron 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 '*' cron.rm_job root /usr/local/weekly
        salt '*' cron.rm_job root /usr/bin/foo dayweek=1
    r�Nr&r�cSsg|]}|du�qS�Nrr[rrr	rQ0szrm_job.<locals>.<listcomp>r_r�r�r�)rzr�rr�rar�rYr8)r;rr+r,r-r.r/rr7rr�r�rr�rrr	r�s8���r��rmcCs�t|�}|dD]'}||dkr/||dkr,t||�t|||�}|dkr(dS|SdSq||d�}|d�|�t|t|��}|drK|d	SdS)
z�
    Set up an environment variable in the crontab.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.set_env root MAILTO user@example.com
    r#r%r$rr�r�)r%r$r�r�)rz�rm_env�set_envr2rYr8)r;r%r$r7r#r�r�rrr	r�Ks"

�
	r�cCsrt|�}d}d}t|d�D]\}}||dkr|}q|dur(|d�|�d}t|t|��}|dr7|dS|S)z�
    Remove cron environment variable for a specified user.

    CLI Example:

    .. code-block:: bash

        salt '*' cron.rm_env root MAILTO
    r�Nr#r%r�r�r�)rzr�r�rYr8)r;r%r7rr�r�rr�rrr	r�is
�r�r�)NN)FNN)NNNNNN)+�__doc__�loggingr>rZsalt.utils.datarZsalt.utils.filesZsalt.utils.functoolsZsalt.utils.pathZsalt.utils.stringutilsr3rr�	getLogger�__name__r|r
rrrrr8r<rArMrOrYrarirzr�	functoolsZalias_functionr{r~r�r�r�r�r�r�r�r�rrrr	�<module>s\	

*
;+"&6^

#X3
�
y$
�5