Forum Discussion
Data group list checks in v11
Hi
Is it possible to check both the address and value of a data group list in combination within an if statement?
For example i have a data group list containing “192.168.1.1” := “fred_jones” and i want to test if both are correct (fred is logging in from that IP address) before i allow fred access to a site.
I want the IF to trigger if the name/value pair is found and not report if individual names and values are matched. Something like this:
If {([class match -name [IP::client_addr] equals sample_list] && [class match -value “fred_jones” equals sample_list])} {
Do something
}
Thanks
11 Replies
- uni
Altocumulus
Try something like this (untested):set lookupname [class lookup [IP::client_addr] sample_list] if { $lookupname eq "" } { ip address not in list } else { if { $lookupname eq $username } { Do something } else { wrong ip for this user } } - uni
Altocumulus
You might be asking for trouble doing this though. You are limiting each ip address to one user, so if you have two users behind a proxy you're stuck. Reversing the class and test doesn't help much, as a client may be behind a pool of proxies, multiple gateways, or have a dynamically assigned address. - Yozzer
Nimbostratus
Hi
I have noticed that there is also a restriction on the data you can put in a data group list (as you cant have the same address/string (IP) twice):
“192.168.1.1” := "fred_jones"
"192.168.1.1" := "Paul_jones"
"192.168.1.2" := "fred_jones"
The requested string class member (/Common/sample_list 192.168.1.1) already exists in partition Common.
So this only allows a 1 to 1 relationship. So i don't think this can be done using the same data group list. Possibly with two data group lists. - What_Lies_Bene1
Cirrostratus
I'd have thought two would do it but it's a shame, I was unaware that duplicates were not possible, thanks for the info. - hoolio
Cirrostratus
You can add the two values for the same IP to one entry:
"192.168.1.1" := "fred_jones|Paul_jones"
When you do the lookup, you can split the value on the delimiter and check each sub-value:
http://www.tcl.tk/man/tcl8.4/TclCmd/split.htmforeach name [split $value "|"] { if {$name eq $user_name}{ ... } }
Aaron - Yozzer
Nimbostratus
Thanks hoolio - James_Deucker_2Historic F5 Account
If you're using values that contain no spaces then you can just use space as the separator and gain direct list functions:
when
RULE_INIT{setlookupname[class lookup192.168.1.1test]loglocal0."lookupname$lookupname"foreachname $lookupname{loglocal0."name$name"}loglocal0."james_a[lsearch$lookupname"james_a"]"loglocal0."john_b[lsearch$lookupname"john_b"]"loglocal0."george_k[lsearch$lookupname"george_k"]"loglocal0."james_a[lsearch[class lookup192.168.1.1test]"james_a"]"if{[expr{[lsearch[class lookup192.168.1.1test]"james_a"]+1}]}{loglocal0."james_a exists"}else{loglocal0."james_a does not exist"}if{[expr{[lsearch[class lookup192.168.1.1test]"george_k"]+1}]}{loglocal0."george_k exists"}else{loglocal0."george_k does not exist"}}
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : lookupname james_a john_b fred_c
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : name james_a
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : name john_b
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : name fred_c
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : james_a 0
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : john_b 1
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : george_k -1
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : james_a 0
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : james_a exists
Nov 20 21:20:18 bigip1 info tmm[29813]: Rule /Common/test_r : george_k does not exist
- hoolio
Cirrostratus
That's a handy option James. Nice work!
Aaron - hoolio
Cirrostratus
You could probably also use matchclass and findclass against the result if it's space delimited to check for a match or get the match value.
Aaron - Yozzer
Nimbostratus
for the instruction:
set lookupname [class lookup $user sample_list]
how can i make this find partial values? i.e. if i was looking for just "_jones"
"fred_jones" := “192.168.1.1|192.168.1.2”
"Paul_jones" := "192.168.1.2"
thanks
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com