mbolli / nfsen-ng

Responsive NetFlow visualizer built on top of nfdump tools.
Apache License 2.0
231 stars 43 forks source link

fronted uses the client's timezone #68

Closed zavndw closed 5 months ago

zavndw commented 2 years ago

if the client looks at the server graphs from a different time zone, it is required to set the time shift in the interface

whh516 commented 2 years ago

Hi zavndw can you tell how to config the timezone for frontend , I found frontend dumping flow with wrong timerzone.

zavndw commented 2 years ago

Hi zavndw can you tell how to config the timezone for frontend , I found frontend dumping flow with wrong timerzone.

Hello. Requires a little frontend revision. Now he takes the timezone from the browser, you need to make this behavior customization. If I understand correctly, then in this place you need to make changes https://github.com/mbolli/nfsen-ng/blob/master/frontend/js/nfsen-ng.js#L672

whh516 commented 2 years ago

fixed,THX

mbolli commented 2 years ago

what would be your preference: to take the timezone from the server or to specify it in the config? or both?

zavndw commented 2 years ago

select the time zone on the web. Default server zone

FontouraAbreu commented 7 months ago

Got the same problem but didn't quite understand which variable or value I should change.

If I understand correctly, then in this place you need to make changes https://github.com/mbolli/nfsen-ng/blob/master/frontend/js/nfsen-ng.js#L672

Is this the correct method I should edit?

/**
* reads options from api_graph_options, performs a request on the API
* and tries to display the received data in the dygraph.
*/
function updateGraph()
FontouraAbreu commented 7 months ago

I believe here is where I should edit the position var

$.each(data.data, function (datetime, series) {
                    var position = [new Date(datetime * 1000)];

                    // add all serie values to position array
                    $.each(series, function (y, val) {
                        position.push(val);
                    });

                    // push position array to dygraph data
                    if (dygraph_did_zoom !== true) {
                        dygraph_data.push(position);
                    } else {
                        // when zoomed in, insert position array at the start index of replacement data
                        dygraph_data.splice(index_to_insert, 0, position);
                        index_to_insert++; // increase index, or data will get inserted backwards
                    }
                });

I changed var position = [new Date(datetime * 1000)]; to var position = [new Date((datetime * 1000) - (3 * 60 * 60 * 1000))];

and then /var/www/html/nfsen-ng/backend/cli.php stop | start. But nothing changed.

Am I missing something here?

FontouraAbreu commented 7 months ago

I changed var position = [new Date(datetime 1000)]; to var position = [new Date((datetime 1000) - (3 60 60 * 1000))];

Oopsie, the correct should be:

var position = [new Date((datetime * 1000) + (3 * 60 * 60 * 1000))];

since my TZ is UTC-3

Solved.

mbolli commented 7 months ago

@FontouraAbreu can you test #90 or apply these changes https://github.com/mbolli/nfsen-ng/pull/90/commits/8334fc9243aeefa0ce27794e997dc0090f343541 to see if the automatic server timezone detection works?

FontouraAbreu commented 7 months ago

Sure thing! I will start redoing everything from scratch by next week's end and will use the prep-php-82 branch.

Personally, I prefer a '.conf' file to set these kind of things as said in #17. But I'll surely give preference to an updated php version.

FontouraAbreu commented 6 months ago

@FontouraAbreu can you test #90 or apply these changes 8334fc9 to see if the automatic server timezone detection works?

Testing this one now, but just to make sure:

This server you talked about, is it the host machine where the application is running or the apache server?


I'm using apache2 so nfsen-ng should detect the timezone setting I made at /etc/php/8.2/apache2/php.ini?

If this is the case for the "server" mentioned, I've already changed it to my current timezone(UTC-3) and restarted the apache and the nfsen-ng service.

Graph date is being displayed correctly:

image

As my last .nfcap files are from 13h00. But the graph still tries to fill the remaining utc offset hours. Is this just a visual issue?

FontouraAbreu commented 6 months ago

I've just noticed the dates are wrong. For some reason its showing that this data is from 2022, not sure why this is happening


My profiles-data directory structure:

root@nfsen-ng:~# tree -d /var/nfdump/profiles-data/live/source/
/var/nfdump/profiles-data/live/source/
└── 2024
    └── 02
        ├── 21
        ├── 22
        ├── 23
        ├── 24
        ├── 25
        └── 26

9 directories

My machine current date:

root@nfsen-ng:~# date
Mon Feb 26 13:28:47 -03 2024
mbolli commented 6 months ago

very weird. when using nfdump does it show the correct dates?

FontouraAbreu commented 6 months ago

@mbolli - yes it does show the correct date

image

FontouraAbreu commented 5 months ago

@mbolli any hints on why this might be happening?

mbolli commented 5 months ago

@FontouraAbreu are you on v0.3.1?

FontouraAbreu commented 5 months ago

oops, now I am. It works now: image

Thanks

mbolli commented 5 months ago

perfect! :)