⚝
One Hat Cyber Team
⚝
Your IP:
216.73.217.4
Server IP:
41.128.143.86
Server:
Linux host.raqmix.cloud 6.8.0-1025-azure #30~22.04.1-Ubuntu SMP Wed Mar 12 15:28:20 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.3.23
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
local
/
psa
/
admin
/
sbin
/
modules
/
ntp-timesync
/
View File Name :
time-mng.sh
#!/usr/bin/env bash ### Copyright 1999-2024. WebPros International GmbH. All rights reserved. PN=$(basename "$0") usage() { cat << EOT Usage: $PN [OPTIONS...] COMMAND Commands: --reload SERVICE reloads systemd service --enable SERVICE enables systemd service --disable SERVICE disables systemd service --enable-sync enable network time synchronization --disable-sync disable network time synchronization --is-sync-enabled checks whether network time synchronization is enabled --is-synced checks whether clock is syncing with the remote server --list-service-overrides reports the list of service overrides EOT } ############################################################################### # Puts message to STDERR and halts execution # Arguments: # Any amount of strings # Output: # Concatenated strings to STDERR fail() { echo "$*" >&2 exit 1 } ############################################################################### # Tries to extract SYSTEMD_TIMEDATED_NTP_SERVICES value from the input # Arguments: # String with the list of envvars # Output: # Value of the SYSTEMD_TIMEDATED_NTP_SERVICES, split into newlines read_env_override() { local env env=$(grep -oEm 1 'SYSTEMD_TIMEDATED_NTP_SERVICES=[a-zA-Z0-9:_.\\-]+' <<<"$1") if [[ -n "$env" ]]; then cut -d'=' -f2 <<<"$env" | tr ':' $'\n' return 0 fi return 1 } ############################################################################### # Sends a DBus request to timedate1 endpoint and reads it as boolean # Arguments: # Property of the DBus listener # (https://man7.org/linux/man-pages/man5/org.freedesktop.timedate1.5.html) # Output: # "true", or "false", based on the content of the property timedate1_dbus_request() { local response='' property="${1:?'DBus property was not provided to function'}" if ! response=$(dbus-send --system \ --dest=org.freedesktop.timedate1 \ --print-reply=literal \ /org/freedesktop/timedate1 \ org.freedesktop.DBus.Properties.Get \ string:org.freedesktop.timedate1 \ "string:${property}" 2>&1 \ ); then fail "Cannot get time synchronization status: dbus-send failed with: $response" fi if grep -q "true" <<<"$response"; then echo "true" else echo "false" fi } ############################################################################### # Lists systemd NTP unit overrides in correct order # Output: # systemd NTP unit names get_override_services() { local env file # SYSTEMD_TIMEDATED_NTP_SERVICES has precedence over configuration files if read_env_override "$(systemctl show-environment)"; then return 0 fi if read_env_override "$(systemctl show --property=Environment systemd-timesyncd.service)"; then return 0 fi while read -r env; do file=$(awk -F'=' '{ gsub(/^[\s-]+/, "", $2); print $2 }' <<<"$env") if [[ -f "$file" ]]; then if read_env_override "$(tac "$file")"; then return 0 fi fi done < <(systemctl cat systemd-timesyncd.service | grep EnvironmentFile | tac) [[ ! -d /usr/lib/systemd/ntp-units.d/ ]] && return 0 find /usr/lib/systemd/ntp-units.d/ -maxdepth 1 -type f -name '*.list' -print0 \ | sort -nz | xargs -0 cat return $? } ############################################################################### # Reloads, or restarts a systemd service # Arguments: # Service name # Output: # systemd informational output reload() { local service="${1?:'Service name was not provided to reload'}" # Recent systemd versions name this function as try-reload-or-restart systemctl status "$service" && systemctl reload-or-try-restart "$service" || systemctl start "$service" return $? } ############################################################################### # Sets NTP sync status # Arguments: # New status ("true" or "false") # Output: # timedatectl informational output set_sync_status() { local bool="${1?:'New status was not provided to set_sync_status'}" timedatectl set-ntp "$bool" exit $? } ############################################################################### # Gets NTP sync capability # Output: # "true" or "false", based on whether systemd detects a compatible unit get_sync_capability() { timedate1_dbus_request "CanNTP" return $? } ############################################################################### # Gets whether system clock is synchronized with NTP # Output: # "true" or "false", based on the sync status is_synced() { timedate1_dbus_request "NTPSynchronized" return $? } main() { local arg command="$1" case "$command" in --reload) arg="${2?:'Service name was not provided to the command'}" reload "$arg" exit $? ;; --enable-sync) set_sync_status "true" exit $? ;; --disable-sync) set_sync_status "false" exit $? ;; --is-sync-possible) get_sync_capability exit $? ;; --is-synced) is_synced exit $? ;; --list-service-overrides) get_override_services exit $? ;; -h|--help) usage ;; *) usage fail "Unrecognized command: ${command}" esac } main "$@"