APM: Variable Assign
Variable assign best practice
Username / Domain Management
get username
session.logon.last.username
extract CN from certificate subject and set it in username variable
set subject [split [mcget {session.ssl.cert.subject}] ",="];
foreach {name value} $subject {
if {[string trim $name] equals "CN"} {
return [string trim $value];
}
}
session.logon.last.username
combine username and domain variables
expr { "[mcget {session.logon.last.domain}]\\[mcget {session.logon.last.username}]" }
session.logon.last.ntdomain
extract NT domain name from logon name
if { [mcget {session.logon.last.username}] contains "\\" } {
set username [string tolower [mcget {session.logon.last.logonname}]];
return [string range $username 0 [expr {[string first "\\" $username] -1}] ];
} else {
return {}
}
one-line code
expr {[set username [string tolower [mcget {session.logon.last.logonname}]]] contains "\\" ? [string range $username 0 [expr {[string first "\\" $username] -1}] ] : "" }
session.logon.last.domain
static assignment from ntdomain
switch [string tolower [mcget {session.logon.last.ntdomain}]] {
"domain1" { return "domain1.local" }
"domain2" { return "domain2.local" }
default { return "default.local" }
}
session.logon.last.username
Extract username name from logonname (full username from logon page even if split domain from username is checked)
set username [string trim [mcget {session.logon.last.logonname}]];
if { $username contains "\\" } {
return [string range $username [expr {[string first "\\" $username] +1}] end ];
} else { return $username }
session.logon.last.upn
Extract UPN value from Certificate X509Extension
set extension [string tolower [mcget {session.ssl.cert.x509extension}]];
return [string range $extension [expr {[string first "othername:upn<" $extension] +14}] [expr {[string last ">" $extension] -1}] ];
Session / Timeout Management
session.inactivity_timeout
Change inactivity session timeout based on a checkbox on the logon page (logon variable trusted)
if { [mcget {session.logon.last.trusted}] == 1 } { return {5400} } else { return {1800} }
one-line code (5400 seconds if condition before ? success, 1800 seconds else)
expr { [mcget {session.logon.last.trusted}] == 1 ? {5400} : {1800}}
session.inactivity_timeout
Change inactivity session timeout based on client type (iOS, Android and WindowsPhone : half of inactivity timeout configured in profile parameters)
expr { [mcget {session.client.platform}] == "WindowsPhone" || [mcget {session.client.platform}] == "Android" || [mcget {session.client.platform}] == "iOS" ? [mcget {session.inactivity_timeout}]/2 : [mcget {session.inactivity_timeout}] }
session.max_session_timeout
force to close the session à 17:00
expr { [clock scan "17:00"] - [mcget {session.user.starttime}] }
session.max_session_timeout
After a AD query which retreive attribute logonHours, force to close the session when user at the end of allowed logon hours
set maximumSessionSeconds 604800
if {[set logonHours [mcget {session.ad.last.attr.logonHours}]] != "" && $logonHours != "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"} {
#convert string to binary string
binary scan [binary format H* $logonHours] b* logon_hours_binary_string
# evaluate the number of seconds from last sunday
set time_from_sunday [expr {[clock seconds] - [clock scan "last sunday"]}];
# search in string next hours with 0 value
set current_index [expr {$time_from_sunday / 3600}];
# convert the index to number of seconds from last sunday
if {[set next_denied_index [string first 0 $logon_hours_binary_string$logon_hours_binary_string $current_index]] == $current_index } {return 0}
# evaluate number on seconds to disconnect time
return [expr { $next_denied_index*3600 - $time_from_sunday}]
} else { return $maximumSessionSeconds}
Windows Info
session.windows_info_os.last.fqdn
search and return FQDN hostname in computer names list after windows Info Box
foreach x [split [mcget {session.windows_info_os.last.computer}] "|"] {
if { $x ends_with ".f5demo.lab" } {
return $x
}
}
session.windows_info_os.last.computer_name
search FQDN hostname in computer names list after windows Info Box, then return shortname (without domain name)
foreach x [split [mcget {session.windows_info_os.last.computer}] "|"] {
if { $x ends_with ".f5demo.lab" } {
return [lindex [split $x "."] 0]
}
}
Machine Cert
To allow machine certificate revocation validation, add a variable assign with 2 following variables before OCSP or CRLDP boxes.
session.ssl.cert.whole
store machine certificate as it was user certificate
expr {[mcget {session.check_machinecert.last.cert.cert}]}
session.ssl.cert.certissuer
store machine certificate issuer as it was user certificate issuer
expr {[mcget {session.check_machinecert.last.cert.issuer}]}
HTTP auth returned cookie parsing
session.custom.http_auth_mycookie
extract from HTTP auth cookie list the cookie value of mycookie
expr { [lindex [regexp -inline {mycookie=([^;\\\r]*)} [mcget session.http.last.response_cookie]] 1] }