A live bird collage card for your Home Assistant dashboard.
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
frederik421575423c8d
diff --git a/homepage/index.php b/homepage/index.phpindex 57db34b2..2e856083 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.phpindex 9dc6050e..8b0ea32f 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']);-session_start();$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.phpindex d1c73f31..f05f9cf0 100644--- a/scripts/config.php+++ b/scripts/config.php@@ -1,7 +1,10 @@<?phperror_reporting(E_ERROR);ini_set('display_errors',1);-+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");$home = shell_exec("awk -F: '/1000/{print $6}' /etc/passwd");$home = trim($home);@@ -114,6 +117,7 @@ if(isset($_GET["latitude"])){if(isset($timezone) && in_array($timezone, DateTimeZone::listIdentifiers())) {shell_exec("sudo timedatectl set-timezone ".$timezone);+ $_SESSION['my_timezone'] = $timezone;date_default_timezone_set($timezone);echo "<script>setTimeout(function() {@@ -688,7 +692,7 @@ https://discordapp.com/api/webhooks/{WebhookID}/{WebhookToken}Select a timezone</option><?php- $current_timezone = trim(shell_exec("cat /etc/timezone"));+ $current_timezone = trim(shell_exec("timedatectl show --value --property=Timezone"));$timezone_identifiers = DateTimeZone::listIdentifiers(DateTimeZone::ALL);$n = 425;