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

�N�gM�@s�dZddlZddlZddlZddlmZmZmZddlZ	ddl
Z	ddlZ	ddlm
Z
mZddlmZe�e�ZdZdd�Zd	d
�Zdd�Zd
d�Zd>dd�Zd>dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z d>dd �Z!d>d!d"�Z"d>d#d$�Z#							d?d%d&�Z$d>d'd(�Z%d>d)d*�Z&Gd+d,�d,e�Z'd-d.�Z(d/d0�Z)d1d2�Z*d3d4�Z+d5d6�Z,d7d8�Z-d9Z.ed8�d:d;��Z/ed8�d<d=��Z0dS)@a�
Support for reboot, shutdown, etc on POSIX-like systems.

.. note::

    If you have configured a wrapper such as ``molly-guard`` to
    intercept *interactive* shutdown commands, be aware that calling
    ``system.halt``, ``system.poweroff``, ``system.reboot``, and
    ``system.shutdown`` with ``salt-call`` will hang indefinitely
    while the wrapper script waits for user input. Calling them with
    ``salt`` will work as expected.

�N)�datetime�	timedelta�tzinfo)�CommandExecutionError�SaltInvocationError)�depends�systemcCs4tjj��rdStjj��rdStjj��rdStS)zc
    Only supported on POSIX-like systems
    Windows, Solaris, and Mac have their own modules
    )Fz'This module is not available on Windows)Fz&This module is not available on Mac OS)Fz%This module is not available on SunOS)�salt�utils�platformZ
is_windowsZ	is_darwinZis_sunos�__virtualname__�r
r
�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/system.py�__virtual__srcC�dg}td|dd�}|S)zi
    Halt a running system

    CLI Example:

    .. code-block:: bash

        salt '*' system.halt
    �halt�cmd.runF��python_shell��__salt__��cmd�retr
r
rr0�
rcCsd|�g}td|dd�}|S)z�
    Change the system runlevel on sysV compatible systems

    CLI Example:

    .. code-block:: bash

        salt '*' system.init 3
    �initrFrr)Zrunlevelrrr
r
rr?s

rcCr)zq
    Poweroff a running system

    CLI Example:

    .. code-block:: bash

        salt '*' system.poweroff
    �poweroffrFrrrr
r
rrNrrcCs(dd|r|�ndg}td|dd�}|S)z�
    Reboot the system

    at_time
        The wait time in minutes before the system will be rebooted.

    CLI Example:

    .. code-block:: bash

        salt '*' system.reboot
    �shutdownz-r�nowrFrr)�at_timerrr
r
r�reboot]s
r cCsVtjj��stjj��stjj��rd}nd}d||r|�ndg}td|dd�}|S)z�
    Shutdown a running system

    at_time
        The wait time in minutes before the system will be shutdown.

    CLI Example:

    .. code-block:: bash

        salt '*' system.shutdown 5
    z-pz-hrrrFr)r	r
rZ
is_freebsdZ	is_netbsdZ
is_openbsdr)r�flagrrr
r
rros
�
�
�rc	Cs�dg}|��dur||��}|jtd�d�}|�d�dj|���}||g}td|dd	�}|d
dkr[dj|���}||g}td|dd	�}|d
dkr[d�|d
�}t|��dS)z�
    set the system date/time using the date command

    Note using a strictly posix-compliant date binary we can only set the date
    up to the minute.
    �dateNr�rz-uz%{1:02}{2:02}{3:02}{4:02}{0:04}.{5:02}�cmd.run_allFr�retcodez {1:02}{2:02}{3:02}{4:02}{0:04}zdate failed: {}�stderrT)�	utcoffset�replace�_FixedOffset�append�format�	timetuplerr)	Znew_daterZ	non_posixZ
non_posix_cmdZ
ret_non_posix�posixZ	posix_cmdZ	ret_posix�msgr
r
r�_date_bin_set_datetime�s 


r/cCs<tjj�dg�durtdgd�dddd�}|d	d
kSdS)z�
    Returns True if the system has a hardware clock capable of being
    set from software.

    CLI Example:

    .. code-block:: bash

        salt '*' system.has_settable_hwclock
    �hwclockNr$)r0z--test�	--systohcF�quietT)rZoutput_loglevelZignore_retcoder%r)r	r
�pathZ	which_binr��resr
r
r�has_settable_hwclock�s�r6cCs4tdddgdd�}|ddkrt�d|d	�d
S)z8
    Set hardware clock to value of software clock.
    r$r0r1Frr%rz<hwclock failed to set hardware clock from software clock: %sr&T)r�log�warnr4r
r
r�_swclock_to_hwclock�s�r9c	Cs8d}|D]}z
t�||�}W|StyYqw|S)a
    Attempts to parse the input time_str as a date.

    :param str time_str: A string representing the time
    :param list fmts: A list of date format strings.

    :return: Returns a datetime object if parsed properly. Otherwise None
    :rtype datetime:
    N)r�strptime�
ValueError)Ztime_str�fmts�result�fmtr
r
r�_try_parse_datetime�s
��r?cCs^t�d|�}|std��|�d�dkrdnd}t|�d��}t|�d��}||d|}|S)	z�
    Helper function that converts the utc offset string into number of minutes
    offset. Input is in form "[+-]?HHMM". Example valid inputs are "+0500"
    "-0300" and "0800". These would return -300, 180, 480 respectively.
    z^([+-])?(\d\d)(\d\d)$zInvalid UTC offset��-������<)�re�matchr�group�int)�
utc_offsetrG�signZhours_offsetZminutes_offsetZtotal_offsetr
r
r�_offset_to_min�srLcCsF|durt|�}t|d�}t��|}|jt|�d�}|St��}|S)zf
    Will return the current time adjusted using the input timezone offset.

    :rtype datetime:
    N��minutesr#)rLrr�utcnowr(r)r)rJrN�offset�offset_timer
r
r�_get_offset_time�s
�rRcC�t|�}t�|d�S)a
    Get the system time.

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns the system time in HH:MM:SS AM/PM format.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_system_time
    �%I:%M:%S %p�rRr�strftime�rJrQr
r
r�get_system_time�rXcCs4gd�}t||�}|durdSt|j|j|j|d�S)a�
    Set the system time.

    :param str newtime:
        The time to set. Can be any of the following formats.
        - HH:MM:SS AM/PM
        - HH:MM AM/PM
        - HH:MM:SS (24 hour)
        - HH:MM (24 hour)

        Note that the salt command line parser parses the date/time
        before we obtain the argument (preventing us from doing utc)
        Therefore the argument must be passed in as a string.
        Meaning you may have to quote the text twice from the command line.

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns True if successful. Otherwise False.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_system_time "'11:20'"
    )rTz%I:%M %pz%H:%M:%Sz%H:%MNF)�hoursrN�secondsrJ)r?�set_system_date_time�hour�minute�second)ZnewtimerJr<�dt_objr
r
r�set_system_time"s
�racCrS)a-
    Get the system date/time.

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns the system time in YYYY-MM-DD hh:mm:ss format.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_system_date_time "'-0500'"
    z%Y-%m-%d %H:%M:%SrUrWr
r
r�get_system_date_timeMrYrbc

Cs�t|�}|dur|j}|dur|j}|dur|j}|dur |j}|dur'|j}|dur.|j}zt||||||d|j�}Wnt	yM}	zt
|	j��d}	~	wwt|�sTdSt
�rZt�SdS)a�
    Set the system date and time. Each argument is an element of the date, but
    not required. If an element is not passed, the current system value for
    that element will be used. For example, if you don't pass the year, the
    current system year will be used. (Used by set_system_date and
    set_system_time)

    Updates hardware clock, if present, in addition to software
    (kernel) clock.

    :param int years: Years digit, ie: 2015
    :param int months: Months digit: 1 - 12
    :param int days: Days digit: 1 - 31
    :param int hours: Hours digit: 0 - 23
    :param int minutes: Minutes digit: 0 - 59
    :param int seconds: Seconds digit: 0 - 59
    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: True if successful. Otherwise False.
    :rtype: bool

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_system_date_time 2015 5 12 11 37 53 "'-0500'"
    NrFT)rR�year�month�dayr]r^r_rrr;r�messager/r6r9)
�years�months�daysrZrNr[rJZ	date_timeZnew_datetime�errr
r
rr\cs4(�
��r\cCrS)a�
    Get the system date

    :param str utc_offset: The utc offset in 4 digit (+0600) format with an
        optional sign (+/-).  Will default to None which will use the local
        timezone. To set the time based off of UTC use "'+0000'". Note: if
        being passed through the command line will need to be quoted twice to
        allow negative offsets.
    :return: Returns the system date.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_system_date
    z%a %m/%d/%YrUrWr
r
r�get_system_date�rYrkcCs8gd�}t||�}|durtd��t|j|j|j|d�S)at
    Set the system date. Use <mm-dd-yy> format for the date.

    :param str newdate:
        The date to set. Can be any of the following formats:

        - YYYY-MM-DD
        - MM-DD-YYYY
        - MM-DD-YY
        - MM/DD/YYYY
        - MM/DD/YY
        - YYYY/MM/DD

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_system_date '03-28-13'
    )z%Y-%m-%dz%m-%d-%Yz%m-%d-%yz%m/%d/%Yz%m/%d/%yz%Y/%m/%dNzInvalid date format)rgrhrirJ)r?rr\rcrdre)ZnewdaterJr<r`r
r
r�set_system_date�s
�rlcs8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
r)z0
    Fixed offset in minutes east from UTC.
    cst���t|d�|_dS)NrM)�super�__init__r�_FixedOffset__offset)�selfrP��	__class__r
rrn�s
z_FixedOffset.__init__cCs|jS�N)ro�rp�dtr
r
rr'�sz_FixedOffset.utcoffsetcCsdSrsr
rtr
r
r�tzname�sz_FixedOffset.tznamecCstd�S)Nr)rrtr
r
r�dst�sz_FixedOffset.dst)	�__name__�
__module__�__qualname__�__doc__rnr'rvrw�
__classcell__r
r
rqrr)�sr)cCs*|d|dkr|�d�r|dd�S|S)zA
    Helper function to strip off the ' or " off of a string
    rrB)�'�"r@)�
startswith)Zstr_qr
r
r�
_strip_quotes�sr�cCs�tjj�d�}|rtd|ddgdd�}nOd}t�d�}z8tjj�d	d
��&}|�	�D]}tjj
�|�}|�|�}|rCt
|�d����}q*Wd�n1sNwYWn	ty]Ynw|durddS|�dd
��dd��dd��dd�S)a:
    Get PRETTY_HOSTNAME value stored in /etc/machine-info
    If this file doesn't exist or the variable doesn't exist
    return False.

    :return: Value of PRETTY_HOSTNAME if this does not exist False.
    :rtype: str

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_computer_desc
    �hostnamectlr�status�--prettyFrN�^\s*PRETTY_HOSTNAME=(.*)$�/etc/machine-info�rr@z\\�\�\"r~�\n�
�\t�	)r	r
r3�whichrrF�compile�files�fopen�	readlines�stringutils�
to_unicoderGr�rH�strip�OSErrorr()�hostname_cmd�desc�pattern�	mach_info�linerGr
r
r�get_computer_descs8
�

�����
�r�c	Csptjj�|��dd��dd��dd�}tjj�d�}|r0td|d	d
|gdd�}|d
kr.dSdStj�	d�sNtjj
�dd��Wd�n1sIwYt�
d�}tjj�d|�d��}zOtjj
�dd��<}|��}t|�D]\}}|�tjj�|��r�|||<nqp|�|�|�d
d
�|��|�|�	Wd�WdS1s�wYWdSty�YdSw)a�
    Set PRETTY_HOSTNAME value stored in /etc/machine-info
    This will create the file if it does not exist. If
    it is unable to create or modify this file returns False.

    :param str desc: The computer description
    :return: False on failure. True if successful.

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_computer_desc "Michael's laptop"
    r~r�r�r�r�r�r�zcmd.retcodezset-hostnamer�FrrTr��wNr�zPRETTY_HOSTNAME="zr+)r	r
r�r�r(r3r�r�os�isfiler�r�rFr�Zto_strr��	enumeraterGr*�seek�truncate�
writelinesr�)	r�r�r=r�Znew_liner��lines�ir�r
r
r�set_computer_desc4sD���
�

(��r�cCstd|�S)z�
    Modify hostname.

    CLI Example:

    .. code-block:: bash

        salt '*' system.set_computer_name master.saltstack.com
    znetwork.mod_hostnamer)�hostnamer
r
r�set_computer_namejs
r�cCs
td�S)zn
    Get hostname.

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_computer_name
    znetwork.get_hostnamerr
r
r
r�get_computer_namews

r�cCst�d�dkS)z@
    Determine whether the minion is running on NI Linux RT
    Z	os_familyZ	NILinuxRT)Z
__grains__�getr
r
r
r�_is_nilrt_family�sr�z'/var/volatile/tmp/salt/reboot_witnessedc
Cs�d}tj�t�}tj�|�s>zt�|�Wnty0}ztd|�d|j�d|j	����d}~wwt
ddt���}|d}|d	kS)
ad
    This function is used to remember that an event indicating that a reboot is
    required was witnessed. This function writes to a temporary filesystem so
    the event gets cleared upon reboot.

    Returns:
        bool: ``True`` if successful, otherwise ``False``

    .. code-block:: bash

        salt '*' system.set_reboot_required_witnessed
    rBzError creating z (-z): Nr$ztouch r%r)r�r3�dirname�NILRT_REBOOT_WITNESS_PATH�exists�makedirsr�r�errno�strerrorr)ZerrcodeZdir_path�exZrdictr
r
r�set_reboot_required_witnessed�s���r�cCstj�t�S)aR
    Determine if at any time during the current boot session the salt minion
    witnessed an event indicating that a reboot is required.

    Returns:
        bool: ``True`` if the a reboot request was witnessed, ``False`` otherwise

    CLI Example:

    .. code-block:: bash

        salt '*' system.get_reboot_required_witnessed
    )r�r3r�r�r
r
r
r�get_reboot_required_witnessed�sr�rs)NNNNNNN)1r{�loggingZos.pathr�rFrrrZsalt.utils.filesr	Zsalt.utils.pathZsalt.utils.platformZsalt.exceptionsrrZsalt.utils.decoratorsr�	getLoggerrxr7rrrrrr rr/r6r9r?rLrRrXrarbr\rkrlr)r�r�r�r�r�r�r�r�r�r
r
r
r�<module>sb


)



+
�
J
'	.6