Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timezones may sometimes be incorrectly calculated #4403

Closed
alcatron opened this issue Sep 17, 2021 · 14 comments
Closed

Timezones may sometimes be incorrectly calculated #4403

alcatron opened this issue Sep 17, 2021 · 14 comments
Labels
bug Undesired behaviour resolved A fixed issue
Milestone

Comments

@alcatron
Copy link

alcatron commented Sep 17, 2021

Im running Cacti 1.2.17 and Centos 8, if I enable SSL on apache, the RRD graphs are -30minutes behind, however if i just go in via plain HTTP, the graphs show the correct time.

I have 2 systems with the issue - Apache/2.4.37 (centos) with Centos 8, and Redhat Enterprise 8.4 with Apache/2.4.37

On regular http graph time shows correct when i zoom in the last 2 hours or so, on the https when i zoom in the time is off by 30mins

I had a PHP developer look at everything and everything in PHP turned out to the fine as well as SQL.
The actual problem is in cacti and cookie timezone calculation

I commented out the following lines below, and once this was taken out the RRD axis graphs showed the correct time and were not offset by minus 30minutes.

/usr/share/cacti/include/global.php - Line 550

/* Commented out due to graph time issues
        if (isset($_COOKIE['CactiTimeZone'])) {
                $minutes = $_COOKIE['CactiTimeZone'];
                $hours   = $minutes / 60;

                putenv('TZ=GMT' . ($hours > 0 ? '-':'+') . abs($hours));
                ini_set('date.timezone', 'Etc/GMT' . ($hours > 0 ? '-':'+') . abs($hours));
        }
*/
@alcatron alcatron added bug Undesired behaviour unverified Some days we don't have a clue labels Sep 17, 2021
@TheWitness
Copy link
Member

What is your pollers time zone? You have to edit the data collector to see the value.

@alcatron
Copy link
Author

poller timezone is set same as php, and is showing correct, no issues seen with poller timezone.

@TheWitness
Copy link
Member

The way that this works is that your relative time, based upon your PC is passed back to the server and used as an offset. So what is in that cookie? Can you print it out into the cacti log?

@TheWitness
Copy link
Member

Off by 30 minutes. Yea, show us the output.

@alcatron
Copy link
Author

Only The RRD graphs Axis is affected by -30mins when zooming in, all other time is fine, even the time that is stamped below the graph is fine, and only occurs for HTTPS request.

This is what the developer told me is happening:

For https request as example what the browser is interpreting:
Cookie:
CactiTimeZone=330; Cacti=cqsf7748usoerjllkhr1lib7do; CactiDateTime=Wed Sep 15 2021 22:11:11 GMT+0530 (India Standard Time)

For http request :
Cookie:
Cacti=or8is0j5b48kbuoj5vg7gfp42u

Cookie 'secure' only set with https and not with http so that was the issue
So cookie. ie set by http can't be accessible by https or vice-versa

HTTPS cookie secure was re-calculating the timezone, when HTTP was not

This is part of the code thats causing the issue for some reason, and hashed it out.
ini_set('date.timezone', 'Etc/GMT' . ($hours > 0 ? '-':'+') . abs($hours));

Happy to ask further clarity what is going on, but thats what i was advised.

@bmfmancini
Copy link
Member

I can't seem to recreate this

Can you post a sample or what your graph looks like?

@TheWitness
Copy link
Member

He's likely in a timeline where the offset is a half hour from Zulu.

@TheWitness
Copy link
Member

There are only a few places in the world this is true, one of course is IST. I was hoping to be able to detect the clients timezone, but we may have to ask it instead, which is a pain. I'm going to do a small patch in the mean time.

@TheWitness TheWitness changed the title Cacti 1.2.17 and SSL Cacti having issues detecting client timezones Sep 19, 2021
@TheWitness TheWitness removed the unverified Some days we don't have a clue label Sep 19, 2021
@TheWitness TheWitness added this to the 1.2.19 milestone Sep 19, 2021
TheWitness added a commit that referenced this issue Sep 19, 2021
This is only a partial fix in that the PHP zone support does not provide a good body of GMT option including the 30 and 45 minute past types.
@TheWitness TheWitness added the resolved A fixed issue label Sep 19, 2021
TheWitness added a commit that referenced this issue Sep 19, 2021
This solution should address all the current oddball timezones.
@TheWitness
Copy link
Member

Okay, handling IST and the others better now. I don't like it, but it's better than nothing.

@alcatron
Copy link
Author

The PHP developer based in india, however i am also based in AEST timezone Australia, which is offset by 30mins, i think something with -30mins was having an issue

@TheWitness
Copy link
Member

Yea, you have to pull lib/functions.php and include/global.php from the 1.2.x branch, and you should be all set.

@alcatron
Copy link
Author

alright, out of interest, what kind of change did you have to make in the code?

@netniV
Copy link
Member

netniV commented Sep 25, 2021

You can see the changes above by looking at the differences of the commits.

@netniV netniV changed the title Cacti having issues detecting client timezones Timezones may sometimes be incorrectly calculated Oct 3, 2021
@ddb4github
Copy link
Contributor

ddb4github commented Oct 22, 2021

Abbr zone name is not valid for PHP function ini_set('date.timezone', $abbr);
PHP function timezone_name_from_abbr can return full zone name from limited(not all) offset if not specified first param 'abbr'.
Also JS function Intl.DateTimeFormat().resolvedOptions().timeZone can return browser side timezone full name. But that fullname might be not supported by PHP, like America/Ensenada
BTW, we can get PHP supported zone list by:

foreach (DateTimeZone::listIdentifiers() as $tz) { echo $tz . "\n"; }

And full list abbr by

foreach (DateTimeZone::listAbbreviations() as $abbr => $tz) { echo $abbr. "\n"; }

@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

5 participants