plugin_flowview icon indicating copy to clipboard operation
plugin_flowview copied to clipboard

Timespan never saved when editing a filter

Open arno-st opened this issue 3 years ago • 16 comments

On the view filter edit, when you change the timespan it's never saved on the DB. The url use the argument predefined_timespan | "3"

But the save function expect timespan who is not present in the URL, so always saved to 0.

URL: { "__csrf_magic": "sid:e87326ab313c2a12acddc3c2c957bafcaec1b093,1649237479", "name": "B85", "device_id": "1", "predefined_timespan": "3", "rtype": "0", "statistics": "10", "printed": "0", "includeif": "1", "resolve": "Y", "sortfield": "3", "cutofflines": "20", "cutoffoctets": "0", "tcpflags": "", "tosfields": "", "sourceip": "10.85.0.0/16", "sourceport": "", "sourceinterface": "", "sourceas": "", "destip": "", "destport": "", "destinterface": "", "destas": "", "id": "2", "date1": "2022-04-05+11:31", "date2": "2022-04-06+11:31", "action": "save" }

But code: ` $save['id'] = get_nfilter_request_var('id'); $save['name'] = get_nfilter_request_var('name'); $save['device_id'] = get_nfilter_request_var('device_id');

$save['timespan']        = get_nfilter_request_var('timespan');
$save['startdate']       = get_nfilter_request_var('date1');
$save['enddate']         = get_nfilter_request_var('date2');

$save['tosfields']       = get_nfilter_request_var('tosfields');
$save['tcpflags']        = get_nfilter_request_var('tcpflags');

if (is_array(get_nfilter_request_var('protocols')) && cacti_sizeof(get_nfilter_request_var('protocols'))) {
	$save['protocols']   = implode(', ', get_nfilter_request_var('protocols'));
} else {
	$save['protocols']   = '';
}

$save['sourceip']        = get_nfilter_request_var('sourceip');
$save['sourceport']      = get_nfilter_request_var('sourceport');
$save['sourceinterface'] = get_nfilter_request_var('sourceinterface');
$save['sourceas']        = get_nfilter_request_var('sourceas');

$save['destip']          = get_nfilter_request_var('destip');
$save['destport']        = get_nfilter_request_var('destport');
$save['destinterface']   = get_nfilter_request_var('destinterface');
$save['destas']          = get_nfilter_request_var('destas');

$save['statistics']      = get_nfilter_request_var('statistics');
$save['printed']         = get_nfilter_request_var('printed');
$save['includeif']       = get_nfilter_request_var('includeif');
$save['sortfield']       = get_nfilter_request_var('sortfield');
$save['cutofflines']     = get_nfilter_request_var('cutofflines');
$save['cutoffoctets']    = get_nfilter_request_var('cutoffoctets');
$save['resolve']         = get_nfilter_request_var('resolve');

`

arno-st avatar Apr 06 '22 09:04 arno-st

Try again. I just fixed it I think.

TheWitness avatar Apr 06 '22 12:04 TheWitness

Still the same, but if I look my query url cacti/plugins/flowview/flowview.php?action=query&domains=true&query=5&timespan=1&date1=2022-04-06 16:01&date2=2022-04-06 16:31& you can't find the predefined_timespan

on the code when saving the filter it's based on timespan, but every thing is based on predefined_timespan So if you change the 'general filter-> preset' to something like last 2 hours, nothing is save to the DB, so when you use the filter on flowview.php, it's looking on predefined_timespan: Line 109 !isset_request_var('predefined_timespan')) { set_request_var('predefined_timespan', $q['timespan'] But it's not no the URL since the url called are: cacti/plugins/flowview/flowview.php?action=query&domains=true&query=5&timespan=1&date1=2022-04-06 16:01&date2=2022-04-06 16:31&

So I think it's 2 point: 1: the saved of the filter use the wrong field from the web page, to the DB, and the value is never saved 2: when applying the filter it look for the wrong field on the URL, so it don'0t used it anyway.

I hope I'm not too wrong, I try to help as most as I can, with my knowledge of PHP and web usage

arno-st avatar Apr 06 '22 14:04 arno-st

Yea, I was noting that here during my lunch break.

TheWitness avatar Apr 06 '22 19:04 TheWitness

Hmm interesting! Do I miss something ?

But this time when I'm applying a filter on floview.php cacti/plugins/flowview/flowview.php?action=query&domains=true&query=5&predefined_timespan=1&date1=2022-04-07 10:28&date2=2022-04-07 10:58& I have the field 'predefined_timespan' on the query But still doesn't reflect what I was expecting when I setup the filter. The field timespan in the DB on 'plugin_flowview_queries', doesn't change from 0 (as I said in point 1 before) to whatever it suppose to be when I'm changing from half-hour to 2hours (or something else)

So again either way I don't understand the usage of the field 'Presets' of the filter web page, or since it's not saved on the DB (for me it should be under 'timespan' of the filter I'm changing, and the fact that when applying a filter it always take the default (last half hour) is normal. And changing the field timepsan, to prefered_timespan will not solve the issue.

But as I said maybe I'm totaly wrong on how flowview plugin is suppose to work! And I apology if I'm going the wrong way.

arno-st avatar Apr 07 '22 09:04 arno-st

Your fine, it's still buggy.

TheWitness avatar Apr 07 '22 12:04 TheWitness

I'm wondering if the problem of the filter of the ip address is that the return value of INET6_ATON is a VARBINARY value and mysql can't do a bitwise (&) on more than 64 bits! (at least in version 10.5)

this one work: select INET_ATON("255.255.0.0")&INET_ATON("10.65.1.2") return: 172032000

This don't : select INET6_ATON("255.255.0.0")&INET6_ATON("10.65.1.2") return: 0

arno-st avatar Apr 20 '22 06:04 arno-st

Okay, so I upgrade my DB to Mariadb 1.5.15m and still the function INET6_ATON or INET6_NTOA are not working! It suppose to work if I'm looking on the documentation, but not in real, did you think I have specific settings that make it not working correctly ?

arno-st avatar May 05 '22 09:05 arno-st

Okay, so I upgrade my DB to Mariadb 1.5.15 and still the function INET6_ATON or INET6_NTOA are not working! It suppose to work if I'm looking on the documentation, but not in real, did you think I have specific settings that make it not working correctly ?

I'm using this Mysql function to test it:

this one work: select INET_NTOA(INET_ATON("255.255.0.0")&INET_ATON("10.65.1.2" )) return: 10.65.0.0

This don't : select INET6_NTOA(INET6_ATON("255.255.0.0")&INET6_ATON("10.65.1.2" )) return: null

it's taken from the flowview run_flow_query inside function.php But if I replace all INET6_ATON and INET6_NTOA by the ipv4 equivalent, it dosen't work. why is that ? Is that the problem of 64 vs 128bit whay to handle the & function ? How it was tested ? The only way to solve is it really to rewrite the code, and do a function to handle 2 time 64 bits ?

arno-st avatar May 16 '22 09:05 arno-st

I hope to get back to flowview within the next few weeks. As it is, it's late spring and a lot of my free time is being spent on doing house work and riding my bike.

TheWitness avatar May 17 '22 13:05 TheWitness

Yea Enjoy it ;)

arno-st avatar May 18 '22 05:05 arno-st

Any chance to work on that issue ? MOst important is the filter based on INET6_NTOA or INET6_ATON

arno-st avatar Aug 31 '22 06:08 arno-st

Can you ask this question on the MariaDB Jira page. It's located here: https://jira.mariadb.org. I think the data needs to be binary, at least in my case, the functions were working but only for varbin. Let me know what they come back with.

TheWitness avatar Oct 19 '22 01:10 TheWitness

So here the answer for the INET6_ATON and INET6_NTOA

This is not a bug. Operator & works with integers, and INET6_ATON returns a string, see https://mariadb.com/kb/en/inet6_aton/

arno-st avatar Oct 27 '22 07:10 arno-st

So despite the trailing N it is actually an A clever :)

netniV avatar Oct 28 '22 22:10 netniV

What is the status of the functions INET6_ATON and INET6_NTOA that are unusable since it's a string instead of a integer, how can it be solved ?

Because I need to filter on source-destination IP address and so far not possible

arno-st avatar Feb 17 '23 09:02 arno-st

We would welcome any pull request if you can figure it out. It's going to be easier than the V9/IPFIX changes.

TheWitness avatar Feb 18 '23 13:02 TheWitness