HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3.9/site-packages/ipaclient/install/__pycache__/timeconf.cpython-39.pyc
a

}�f1!�@s�ddlmZddlZddlZddlZddlmZddlmZddl	m
Z
ddlmZddl
mZddlmZdd	lmZe�e�Zdd
d�Zdd
�Zdd�Zddd�ZGdd�de�ZGdd�de�Zdd�Zdd�Zd dd�ZdS)!�)�absolute_importN)�Augeas)�api)�ipautil)�tasks)�services)�paths)�
user_inputcCs$|r|�|�nt�|d|�dS)Nz
%s.ipasave)Zbackup_file�shutil�copy)�path�fstore�r�>/usr/lib/python3.9/site-packages/ipaclient/install/timeconf.py�__backup_config$srcCs�g}d}t�dd�rxtddd�}|r\t�d�|�d�D]"}|��}|�|�t�d	|�q8td
dd�}|rxt�d|�||fS)z�
    While in interactive installation user has to specify NTP server or pool
    to be used in chrony configuration. This method asks user input on these
    values in case that they were not specified before installation start.
    �z@Do you want to configure chrony with NTP server or pool address?FzLEnter NTP source server addresses separated by comma, or press Enter to skipT)Zallow_emptyzUser provided NTP server(s):�,z	%sz7Enter a NTP source pool address, or press Enter to skipzUser provided NTP pool:	%s)rr	�logger�debug�split�strip�append)�ntp_servers�ntp_poolZservers�serverrrr�get_time_source+s(��

�rcCs�tjj��tjj��d}d}tjddt|�ddt|�g}z$t�	d�t
�|�t�	d�WdSt
jy�t�
d	�t�
d
�YdS0dS)
z�
    This method enables chronyd service on boot and restarts it to reload
    chrony configuration file /etc/chrony.conf
    Then it tries to synchronize time with chrony's new or defaut configuration
    ��z-dZwaitsync�0z%Attempting to sync time with chronyc.z$Time synchronization was successful.Tz-Process chronyc waitsync failed to sync time!z�Unable to sync time with chrony server, assuming the time is in sync. Please check that 123 UDP port is opened, and any time server is on network.FN)r�
knownservices�chronyd�enableZrestartrZCHRONYC�strr�infor�runZCalledProcessErrorZwarning)Zsync_attempt_countZsync_attempt_interval�argsrrr�sync_chronyIs$�



�r&Fc
Cs�d}|r|�|dtjj���ttjtjBtj	d�}�z��z,t
�d�tj
�tj�}|�||�|��dj|d�}|�d�|��|�d�|��|�d	�|��|r�t
�d
�t
�d|�|�d�|�|�|�d
�|�d�|�r,t
�d�|D]4}	|�d�|�|	�|�d�|�d�t
�d|	�q�t
�d|�t||�t
�d|�|��t
�d�d}
WnXt�y�t
�d|�d}
Yn6t�y�}zt
�d|�d}
WYd}~n
d}~00W|��n
|��0t�|�|
S)zP
    This method only configures chrony client with ntp_servers or ntp_pool
    Zchrony�enabled)�flagsZloadpathzConfiguring chronyz/files{path})rz	{}/serverz{}/poolz{}/peerzSetting server pool:z'%s'z{}/pool[last()+1]z{}/pool[last()]/iburstNzSetting time servers:z{}/server[last()+1]z{}/server[last()]/iburstzBacking up '%s'zWriting configuration to '%s'z1Configuration of chrony was changed by installer.Tz"Augeas failed to configure file %sFzConfiguration failed with: %s)�backup_staterrr �
is_enabledrZNO_LOADZNO_MODL_AUTOLOADrZUSR_SHARE_IPA_DIRrr�osr�abspathZCHRONY_CONFZ	transform�load�format�remove�setrZsaver#�IOError�error�RuntimeError�closerZrestore_context)rrr
Zsysstorer�moduleZaugZchrony_confrrZ
configured�errr�configure_chronynsV
��





r7c@seZdZdS)�NTPConfigurationErrorN)�__name__�
__module__�__qualname__rrrrr8�sr8cseZdZd�fdd�	Z�ZS)�NTPConflictingServicerNcstt|��||�||_dS)N)�superr<�__init__�conflicting_service)�self�messager?��	__class__rrr>�szNTPConflictingService.__init__)rN)r9r:r;r>�
__classcell__rrrBrr<�sr<cCsBtjD]6}|dkrqt�|t�}|��s0|��rt|jd��qdS)z�
    System may contain conflicting services used for time&date synchronization.
    As IPA server/client supports only chronyd, make sure that other services
    are not enabled to prevent conflicts.
    r )r?N)r�timedate_services�servicerr*�
is_runningr<�service_name)rF�instancerrr�check_timedate_services�s
�rJcCsvtjD]j}|dkrqt�|t�}|��}|��}|s8|r|�|jd|�|�|jd|�|rd|��|r|�	�qdS)zf
    Force chronyd configuration and disable and stop any other conflicting
    time&date service
    r r'�runningN)
rrErFrr*rGr)rH�stop�disable)�
statestorerFrIr'rKrrr�force_chrony�s
rOr cCsdtjD]X}||krq|�|�rt�|t�}|�|jd�}|�|jd�}|rR|��|r|��qdS)zo
    Restore from installation and enable/start service that
    were disabled/stopped during installation
    r'rKN)	rrEZ	has_staterFrZ
restore_staterHr!�start)rNZskip_servicerFrIr'rKrrr�restore_forced_timeservices�s

��rQ)N)NNNF)r ) Z
__future__rZloggingr+r
ZaugeasrZipalibrZ	ipapythonrZipaplatform.tasksrZipaplatformrZipaplatform.pathsrZipapython.ipautilr	Z	getLoggerr9rrrr&r7�	Exceptionr8r<rJrOrQrrrr�<module>s,

%�
>