Forum Discussion

aschi_6586's avatar
aschi_6586
Icon for Nimbostratus rankNimbostratus
Oct 31, 2013

Regular Expression

Hi

I just want that the following Path are valid and sent to the Pool, otherwise the "Forbidden" Message should appear.

/manorbon

/manorbon/

/manorbon/anything

I tested the regex "/manorbon([/]._|[/]?)" on http://regexpal.com/ and it worked as expected but it seems that it doesn't work in the iRule. I always get the Forbidden Message.

If I just use "/manorbon*" it works but also anything starting with /manorbon like /manorbons which i don't want.

iRule: when HTTP_REQUEST {

switch -glob [HTTP::path] {

  "/manorbon([/].*|[/]?)" {

    SSL::disable serverside

    use pool ACA-Pool_appl.com_http

}

  default {

    HTTP::respond 200 content "Forbidden"

}

} }

is there another way to implement this? Best Regards, Roger

9 Replies

  • Maybe something simpler will do?

    when HTTP_REQUEST {
        if { ( [string tolower [HTTP::uri]] equals "/manorbon" ) or ( [string tolower [HTTP::uri]] starts_with "/manorbon/" ) } {
            SSL::disable serverside
            pool ACA-Pool_app1.com_http
        } else {
            HTTP::respond 200 content "Forbidden"
        }
    }
    
  • Hi Thanks a lot for your answer. That would be a cool solution if I had just one if Statement. But i have choosen the switch statement because I have a lot of different path. I just added one in the sample to keep it simple. Or is possible and best practice to combine switch an if? Best Regards, Roger

     

  • Perhaps then a data group:

    when HTTP_REQUEST {
        if { [class match [string tolower [HTTP::uri]] starts_with dc-uri-filter-dg] } {
            set local_var [class match -name [string tolower [HTTP::uri]] starts_with dc-uri-filter-dg]
            if { ( [string tolower [HTTP::uri]] equals $local_var ) or ( [string tolower [HTTP::uri]] starts_with "${local_var}/" ) } {
                SSL::disable serverside
                pool ACA-Pool_appl.com_http
            } else {
                HTTP::respond 200 content "Forbidden"
            }
        }   
    }
    

    where "dc-uri-filter-dg" is a string-based data group that contains the base URI. Example:

    "/manorbon" := ""
    "/foo" := ""
    "/bar" := ""
    "/test" := ""
    

    The iRule will match only the defined base URI (equals) or the base URI plus a "/" (starts_with).

  • Thanks For the moment i have just 2 different Pools for 10 different Path. I can use If and a elseif for these two Pools. But I think that in the near future I'll have a single Pool for each Path. And that would be a nightmare to administrate with if, elseif, elseif, and so on.

     

    What do you think? Go for the nightmare or another solution? Best Regards, Roger

     

  • You could assign the pool names in the data group, then you'd just add the following to the above iRule:

    pool [class match -value [string tolower [HTTP::uri]] starts_with dc-uri-filter-dg]
    

    And then the only thing you would need to manage is the data group.

  • So the simple answer is;

    when HTTP_REQUEST {
    
        switch -glob [string tolower [HTTP::path]] {
            "/manorbon" -
            "/manorbon/*" {
                SSL::disable serverside
               pool ACA-Pool_appl.com_http
            }
    
            default {
                HTTP::respond 200 content "Forbidden"
                return
           }
       }
    
  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    Here's a variant of Joanna's response, which could equally be done using if/else:

    when HTTP_REQUEST {
        switch -- [string tolower [getfield [HTTP::path] "/" 2]] {
            "manorbon" {
                SSL::disable serverside
                pool ACA-Pool_appl.com_http
            }
            default {
                HTTP::respond 200 content "Forbidden"
                return
           }
       }
    }
    
  • aschi's avatar
    aschi
    Icon for Nimbostratus rankNimbostratus

    Thanks a lot, The sample from IheartF5 was exactly what I was looking for. I do not really understand stand the logic of it but it works.