2funky_105078
Apr 09, 2014Cirrus
Solved
data group iRule
Hello iExperts,
I just wanted to double check with you the following irule where i want to double check that the client IP is in a determinate data group range of IPs (ecmvpn_ip_dg) and if so, return a HTTP 302 redirect to such client. Is it the correct and "optimized" way to do it?
when RULE_INIT {
set static::ecmvpn_flag 0
}
when CLIENT_ACCEPTED {
if { [class match [IP::client_addr] equals ecmvpn_ip_dg] } {
set static::ecmvpn_flag 1
}}
when HTTP_REQUEST {
if {$static::ecmvpn_flag==1}{
HTTP::redirect http://ecmvpn.[HTTP::uri]
return
}
switch -glob [string tolower [HTTP::host]] {
"ecm.domain"
{
if { ([HTTP::uri] starts_with "/APPLICATION")} {
HTTP::header insert USER-IP [IP::remote_addr]
persist cookie insert
pool DCTM_ECM_APPLICATION _APPLICATION PORT_PROD (or PREP)
return
}
}
default { return }
}
}
Hi you don't need to use static variables - just use a TCP connection scoped variable set in CLIENT_ACCEPTED. Not too sure what you want from the switch ...anyway updated slightly
when CLIENT_ACCEPTED { set ecmvpn_flag 0 if { [class match [IP::client_addr] equals ecmvpn_ip_dg] } { set ecmvpn_flag 1 } } when HTTP_REQUEST { if {$ecmvpn_flag}{ You need an FQDN here so I've added ".com.au" HTTP::redirect http://ecmvpn.com.au[HTTP::uri] return } switch -glob [string tolower [HTTP::host]] { "ecm.*" { if {[string tolower [HTTP::uri]] starts_with "/application"} { HTTP::header insert USER-IP [IP::remote_addr] You could just use an HTTP persistence profile attached to the virtual for this persist cookie insert pool pl_DCTM_ECM_APPLICATION return } } default { return } } }