Skip to content

Commit 3898c94

Browse files
committed
Fixed: FS#2418 - PHP: Timezone ID 'CEST' is invalid
1 parent f601d97 commit 3898c94

File tree

2 files changed

+50
-10
lines changed

2 files changed

+50
-10
lines changed

install/install.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,16 +104,7 @@
104104

105105
//** Select the language and set default timezone
106106
$conf['language'] = $inst->simple_query('Select language', array('en','de'), 'en');
107-
108-
exec('date +%z', $tmp_out);
109-
$tmp_zone = intval($tmp_out[0]);
110-
if(substr($tmp_out[0],0,1) == '+') {
111-
$conf['timezone'] = 'Etc/GMT+'.$tmp_zone;
112-
} else {
113-
$conf['timezone'] = 'Etc/GMT-'.$tmp_zone;
114-
}
115-
unset($tmp_out);
116-
unset($tmp_zone);
107+
$conf['timezone'] = get_system_timezone();
117108

118109
//* Set defaukt theme
119110
$conf['theme'] = 'default';

install/lib/install.lib.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,55 @@ function is_ispconfig_ssl_enabled() {
750750
}
751751
}
752752

753+
/**
754+
Function to find the hash file for timezone detection
755+
(c) 2012 Marius Cramer, pixcept KG, m.cramer@pixcept.de
756+
*/
757+
function find_hash_file($hash, $dir, $basedir = '') {
758+
$res = opendir($dir);
759+
if(!$res) return false;
760+
761+
if(substr($dir, -1) === '/') $dir = substr($dir, 0, strlen($dir) - 1);
762+
if($basedir === '') $basedir = $dir;
763+
764+
while($cur = readdir($res)) {
765+
if($cur == '.' || $cur == '..') continue;
766+
$entry = $dir.'/'.$cur;
767+
if(is_dir($entry)) {
768+
$result = find_hash_file($hash, $entry, $basedir);
769+
if($result !== false) return $result;
770+
} elseif(md5_file($entry) === $hash) {
771+
$entry = substr($entry, strlen($basedir));
772+
if(substr($entry, 0, 7) === '/posix/') $entry = substr($entry, 7);
773+
return $entry;
774+
}
775+
}
776+
closedir($res);
777+
return false;
778+
}
779+
780+
/**
781+
Function to get the timezone of the Linux system
782+
(c) 2012 Marius Cramer, pixcept KG, m.cramer@pixcept.de
783+
*/
784+
function get_system_timezone() {
785+
if(is_link('/etc/localtime')) {
786+
$timezone = readlink('/etc/localtime');
787+
$timezone = str_replace('/usr/share/zoneinfo/', '', $timezone);
788+
if(substr($timezone, 0, 6) === 'posix/') $timezone = substr($timezone, 6);
789+
} else {
790+
$hash = md5_file('/etc/localtime');
791+
$timezone = find_hash_file($hash, '/usr/share/zoneinfo');
792+
}
793+
794+
if(!$timezone) {
795+
exec('date +%Z', $tzinfo);
796+
$timezone = $tzinfo[0];
797+
}
798+
799+
return $timezone;
800+
}
801+
753802

754803

755804
?>

0 commit comments

Comments
 (0)