From 421575423c8dabe2910715a0d3dcce9d658dcdf9 Mon Sep 17 00:00:00 2001 From: frederik Date: Wed, 21 Feb 2024 17:09:30 +0100 Subject: [PATCH] fix: do not rely on /etc/timezone to get the time zone. timedatectl does not update it immediately (anymore), it only gets updated after a reboot --- homepage/index.php | 21 +++------------------ homepage/views.php | 26 ++++++-------------------- scripts/config.php | 8 ++++++-- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/homepage/index.php b/homepage/index.php index 57db34b..2e85608 100644 --- a/homepage/index.php +++ b/homepage/index.php @@ -4,25 +4,10 @@ $_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); -$sys_timezone = ""; -// If we can get the timezome from the systems timezone file ust that -if (file_exists('/etc/timezone')) { - $tz_data = file_get_contents('/etc/timezone'); - if ($tz_data !== false) { - $sys_timezone = trim($tz_data); - } -} else { -// Else get timezone from the timedatectl command - $tz_data = shell_exec('timedatectl show'); - $tz_data_array = parse_ini_string($tz_data); - if (is_array($tz_data_array) && array_key_exists('Timezone', $tz_data_array)) { - $sys_timezone = $tz_data_array['Timezone']; - } -} -//Finally if we have a valod timezone, set it as the one PHP uses -if ($sys_timezone !== "") { - date_default_timezone_set($sys_timezone); +if(!isset($_SESSION['my_timezone'])) { + $_SESSION['my_timezone'] = trim(shell_exec('timedatectl show --value --property=Timezone')); } +date_default_timezone_set($_SESSION['my_timezone']); if (file_exists('./scripts/thisrun.txt')) { $config = parse_ini_file('./scripts/thisrun.txt'); diff --git a/homepage/views.php b/homepage/views.php index 9dc6050..8b0ea32 100644 --- a/homepage/views.php +++ b/homepage/views.php @@ -4,27 +4,13 @@ $_GET = filter_input_array(INPUT_GET, FILTER_SANITIZE_STRING); $_POST = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING); -$sys_timezone = ""; -// If we can get the timezome from the systems timezone file ust that -if (file_exists('/etc/timezone')) { - $tz_data = file_get_contents('/etc/timezone'); - if ($tz_data !== false) { - $sys_timezone = trim($tz_data); - } -} else { -// else get timezone from the timedatectl command - $tz_data = shell_exec('timedatectl show'); - $tz_data_array = parse_ini_string($tz_data); - if (is_array($tz_data_array) && array_key_exists('Timezone', $tz_data_array)) { - $sys_timezone = $tz_data_array['Timezone']; - } -} -// finally if we have a valod timezone, set it as the one PHP uses -if ($sys_timezone !== "") { - date_default_timezone_set($sys_timezone); -} - session_start(); + +if(!isset($_SESSION['my_timezone'])) { + $_SESSION['my_timezone'] = trim(shell_exec('timedatectl show --value --property=Timezone')); +} +date_default_timezone_set($_SESSION['my_timezone']); + $user = shell_exec("awk -F: '/1000/{print $1}' /etc/passwd"); $user = trim($user); $home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd"); diff --git a/scripts/config.php b/scripts/config.php index d1c73f3..f05f9cf 100644 --- a/scripts/config.php +++ b/scripts/config.php @@ -1,7 +1,10 @@ setTimeout( function() { @@ -688,7 +692,7 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken} Select a timezone