For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

MW1's avatar
MW1
Icon for Cirrus rankCirrus
May 01, 2013

How can I insert the client's IP back to them in a HTTP:RESPOND content

I am sure this must be simple so apoligies if I am missing the obvious here. I have an irule that does some checking on the clients IP and other payload of a post a custom error message back to the user which appears to be working well, however I have been asked if I can return the client's IP to them in the message, i.e. Your IP address 1.2.3.4 has not been recognized


set data {
Your IP address has not been recognized.  

Please contact company support.false
}


 Match the data for specific companyid and is a login request
   if {  [HTTP::payload] contains ">127708" and    [HTTP::payload] contains "
log local0. "TEST-irule matched company and login request"
 Match the clients IP to register list and respond with block MSG if not found
 if { ![matchclass [IP::client_addr] equals IPlist] } {
log local0. "TEST-irule going to reply with block to [IP::client_addr] "
 HTTP::respond 200 content $data "Content-Type" "text/xml; charset=utf-8"
}

If I try to add [IP::client_addr] to the set data it does not substitute for the IP, and if I try to create split the data it also fails e.g:


set data {
Your IP address
 
set data2 has not been recognized.  

Please contact company support.false
}


 HTTP::respond 200 content $data [IP::client_addr] $data2  "Content-Type" "text/xml; charset=utf-8"
 

Am I missing an obvious way to get achieve this?

Thanks!

1 Reply

  • Special Cases for Using Braces

    You can also use braces to enclose strings, just as you would double quotes, but variables won't expand within them unless a command also inside the braces refers to them. Because of that difference, if you need to handle strings containing $, \, [], (), or other special characters, braces will work where double quotes won't.iRules Optimization 101 - 04 - Delimiters: Braces, Brackets, Quotes and more by Deb Allen

    https://devcentral.f5.com/tech-tips/articles/irules-optimization-101-04-delimiters-braces-brackets-quotes-and-more

    so, you may try something like this.

    e.g.

     example1
    
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
       set data "\r\nYour [IP::client_addr] has not been recognized.\r\n\r\nPlease contact company support.false\r\n"
       HTTP::respond 200 content $data noserver "Content-Type" "text/xml; charset=utf-8"
    }
    }
    
    [root@centos17 ~] curl http://172.28.19.252
    
    Your 172.28.20.17 has not been recognized.
    
    Please contact company support.false
    
     example2
    
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when RULE_INIT {
       set static::data {
    Your IP address has not been recognized.
    
    Please contact company support.false
    }
    }
    when HTTP_REQUEST {
       HTTP::respond 200 content [string map [list "IP address" [IP::client_addr]] $static::data] noserver "Content-Type" "text/xml; charset=utf-8"
    }
    }
    
    [root@centos17 ~] curl http://172.28.19.252
    
    Your 172.28.20.17 has not been recognized.
    
    Please contact company support.false