Forum Discussion

CMR-NYC_176898's avatar
CMR-NYC_176898
Icon for Nimbostratus rankNimbostratus
Oct 05, 2016

DataGroup (string & value) tolower

I have some data [string] which I'm accessing in a Data Group from an iRule. Data example: EU = Blocked US = Blocked RU = Blocked

 

I am using the following code to access the datagroup. I need to ensure that date which is pulled from the datagroup is always lowercase regardless of what data is put into the datagroup. I am normalizing the data from the session variable as follows before I'm comparing the data from the datagroup. **How can I always make sure the data from the datagroup is lowercase (string and value)?

 

set strCountryCode [string toupper [ACCESS::session data get session.user.ipgeolocation.country_code]]

 

when ACCESS_POLICY_AGENT_EVENT { if { [set strCountryAuthorization [class match -value $strCountryCode contains Blocked_Countries_dg]] ne "" } { } else { set strCountryAuthorization "allowed" } Terminate Session if Country is Blocked if {$strCountryAuthorization eq "Blocked"} {

 

         Kill Session
        ACCESS::session remove
        }

}

 

1 Reply

  • Hamish's avatar
    Hamish
    Icon for Cirrocumulus rankCirrocumulus

    Apologies... I read this at least two ways...

     

    Do you mean you want to return the value (strCountryAuthorization in your code) and then convert it to lower case?

     

    Use

     

    [string tolower $variable]
    Returns string with all the letters converted from upper to lower case.

    This should do what you're asking for. Simply use the [string tolower $variable] TCL command to convert the string. e.g.

     

    when ACCESS_POLICY_AGENT_EVENT { 
      if { [set strCountryAuthorization [class match -value $strCountryCode contains Blocked_Countries_dg]] ne "" } {
       } else {
         set strCountryAuthorization "allowed" 
       } 
    
        Terminate Session if Country is Blocked 
       if {[string tolower $strCountryAuthorization] eq "blocked"} {
    
            Kill Session
           ACCESS::session remove
       }
    }

    I'm not sure if you use strCountryAuthorization elsewhere if it's set to 'allowed'. If not, then that 'else' setting it to allowed is wasted CPU cycles.