Forum Discussion

Dev_16_371257's avatar
Dev_16_371257
Icon for Nimbostratus rankNimbostratus
Sep 05, 2018

Need help In irule to execute condition based on URI Values

Hi Experts,

I am trying to write the I-rule where uri have 10digit numeric value and it should not contain any special character/alphabet , also the length of that numeric value is not more than 10 digit not less than that, If this condition pass have second condition , the URI must ends with .xlsx or .docs extension.

I tried below syntax, but some how not able to capture the length ... can any one tell us how to proceed further !

http://www.hostname.com/uripath/sn=1234567890/abouttoopenhomepage.docx

when HTTP_REQUEST {

set SN_value [getfield [getfield [HTTP::path] "/" 2] "=" 2] if { [string is digit $SN_value] && ([HTTP::uri] ends_with ".docx" or ".xlsx") }

---- Ho to add the length verification which will pass the 10 digit SN_value !

{ log local0. "Correct File extension && The uri path entry $SN_value is okay (all digits)."
return
}

else { log local0. "The URL path entry $SN_value is not okay (non-digit characters were found)."}

}

=============

Regards, Dev

4 Replies

  • http://www.hostname.com/uripath/sn=1234567890/abouttoopenhomepage.docx

     

    ---- Ho to add the length verification which will pass the 10 digit SN_value !

     

    when HTTP_REQUEST {

     

    set SN_value [getfield [getfield [HTTP::path] "/" 2] "=" 2] if { [string is digit $SN_value] && ([HTTP::uri] ends_with ".docx" or ".xlsx") }

     

    { log local0. "Correct File extension && The uri path entry $SN_value is okay (all digits)." return } else { log local0. "The URL path entry $SN_value is not okay (non-digit characters were found)." } }

     

  • Hi Dev,

    I write and tested this irule with success:

    Your example: http://www.hostname.com/uripath/sn=1234567890/abouttoopenhomepage.docx

    when HTTP_REQUEST {
    
    set uri [string tolower [HTTP::uri]]
    
     retrieve SN Value
    set SN_value  [findstr $uri /sn= 4 /]
    log local0. "$SN_value"
    
    
     define if SN_value is digit (catch error if not digit)
    if { [catch {
    regexp {^([0-9]+)$} $SN_value -> value
    log local0. "cn value = $value is a digit"
    set digit 1 } ] } {
        set digit 0
        log local0. "cn value is not only digit"
    }
    
    if {[string length $SN_value] == 10 && $digit == 1 && ($uri ends_with ".docx" || $uri ends_with ".xlsx")} {
        log local0. "cn value is a digit and is lenght is not more than 10 and not less than 10 digit "
    }
    
    }
    

    Keep me in touch and if you need more details don't hesitate.

    regards

  • Try this too,

    when HTTP_REQUEST {
    set split ""
    set split [getfield [getfield [HTTP::uri] "sn=" 2] "/" 1]
    if { [string is digit $split] && [string length $split] == 10 && ([HTTP::uri] ends_with ".docx" || [HTTP::uri] ends_with ".xlsx")} {
    HTTP::respond 200 content {
    success
    }
    } else {
    HTTP::respond 200 content {
    failed
    }
    }
    }
    
  • You can try this code.

     

    First test the URI extension before splitting the URI

     

    when HTTP_REQUEST {
    
      if { ([HTTP::path] ends_with ".docx" || [HTTP::path] ends_with ".xlsx") && [string is digit set SN_value [getfield [URI::path [HTTP::uri] 1 2] 2 ]] &&  [string length $SN] == 10 } {
        log local0. "Correct File extension && The uri path entry $SN_value is okay (all digits)."
      return
      }
      else { 
        log local0. "The URL path entry $SN_value is not okay (non-digit characters were found)."
        }
    
    }