Forum Discussion

TJ_Vreugdenhil's avatar
Aug 30, 2011

Parse errors

I am trying to fight the parse errors using the GUI and the iRule editor line by line, however I am getting stuck at line 8 using the iRule below for 10.x

 

 

 


when HTTP_REQUEST {
     logging for debug purposes. The following message in particular will place heavy load on the system. Remove for prod!
    log local0.info "processing request for [HTTP::host][HTTP::uri]"
    handle the */awdServer/* case.
if {[HTTP::uri] contains "/awdServer/"} {
if the Referer header does not exist this is a hard-bookmarked or malicious request and it will be logged and rejected.
     if { [HTTP::header exists "Referer"] } {
            if { [HTTP::header Referer equals ""] {
                log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a null Referer header"
                 HTTP::respond 404 "Object not found."
                }
                set ref_query [URI::query [HTTP::header "Referer"]]
                set orig_query [HTTP::query]
                set servlet [URI::query ${ref_query} servlet]
                set awd_uri "${servlet}?${orig_query}&${ref_query}"
                log local0.info "rewriting URI from [HTTP::uri] to ${awd_uri}"
                HTTP::uri ${awd_uri}
            } else {
                log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a missing Referer header"
                   HTTP::respond 404 "Object not found."
               }
        }
         handle the /awd/ case
        if { [HTTP::uri] starts_with "/awd/" {
            if the Referer header does not exist this is a hard-bookmarked or malicous request and it will be logged and rejected.
            if { HTTP::header exists "Referer" } {
                if { HTTP::header "Referer" equals "" } {
                    log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a null Referer header"
                       HTTP::respond 404 "Object not found."
                }
                 grab the query string from the Referer header
                set ref_uri [URI::query [HTTP::header Referer]]
                 grab the Platform from the Referer header query string, if present
                if { [URI::query  $ref_uri platform] != "" } {
                    set ref_Platform "[URI::query $ref_uri platform]/"
                }
                 collect the CLIENT value from the Referer header query string, if present.
                if [ [URI::query $ref_uri client] != "" } {
                    set ref_Client [URI::query $ref_uri client]
                }
                 if there was a host value in the Referer query string, rewrite the Host header
                set orig_URI [HTTP::uri]
                if { [URI::query $ref_uri host] != "" } {
                    set ref_Host [URI::query $ref_uri host]
                    log local0.info "rewriting Host header [HTTP::host] to $ref_Host"
                    HTTP::header replace Host ${ref_Host}}
                }
                rewrite the URI to /PLATFORM/CLIENT/OriginalURI
                set awd_uri "/${ref_Platform}${ref_Client}${orig_URI}"
                log local0.info "rewriting [HTTP::uri] to ${awd_uri}"
                HTTP::uri ${awd_uri}
                 load-balance to the AWD Pool
                pool http_test
            } else {
                log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a missing Referer header"
                   HTTP::respond 404 "Object not found."
               }
        }
    }
}
[code/]
Thanks!
  • I think it needs a close }

    original:

    
                if { [HTTP::header Referer equals ""] {
    

    might help:

    
                if { [HTTP::header Referer equals ""] } {
     

    Nat
  • Thanks for the reply. I tried that, and no go. It looks to be a argument issue:

     

     

    "line 8: [wrong args] [HTTP::header Referer equals ""] line 24: [parse error: PARSE syntax "

     

     

    Can 'HTTP:header' & 'Referer' go together? Doesn't look like they can from the wiki below. Is there another way to check "the HTTP::header Referer"?

     

     

    http://devcentral.f5.com/wiki/irules.HTTP__header.ashx

     

     

    Thanks!

     

     

    -TJ
  • There were quite a few mismatched curly and square braces. Also, you need to use the keyword "content" with HTTP::respond. Can you try this? I haven't checked it fully for logic, but it loads at least.

    when HTTP_REQUEST {
     logging for debug purposes. The following message in particular will place heavy load on the system. Remove for prod!
    log local0.info "processing request for [HTTP::host][HTTP::uri]"
    handle the */awdServer/* case.
    if {[HTTP::uri] contains "/awdServer/"} {
    if the Referer header does not exist this is a hard-bookmarked or malicious request and it will be logged and rejected.
     if { [HTTP::header exists "Referer"] } {
    if { [HTTP::header Referer] equals "" } {
    log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a null Referer header"
    HTTP::respond 404 content "Object not found."
    return
    }
    set ref_query [URI::query [HTTP::header "Referer"]]
    set orig_query [HTTP::query]
    set servlet [URI::query ${ref_query} servlet]
    set awd_uri "${servlet}?${orig_query}&${ref_query}"
    log local0.info "rewriting URI from [HTTP::uri] to ${awd_uri}"
    HTTP::uri ${awd_uri}
    } else {
    log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a missing Referer header"
       HTTP::respond 404 "Object not found."
    }
    }
     handle the /awd/ case
    if { [HTTP::uri] starts_with "/awd/"} {
    if the Referer header does not exist this is a hard-bookmarked or malicous request and it will be logged and rejected.
    if { [HTTP::header exists "Referer"] } {
    if { [HTTP::header "Referer"] equals "" } {
    log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a null Referer header"
       HTTP::respond 404 content "Object not found."
       return
    }
     grab the query string from the Referer header
    set ref_uri [URI::query [HTTP::header Referer]]
     grab the Platform from the Referer header query string, if present
    if { [URI::query  $ref_uri platform] ne "" } {
    set ref_Platform "[URI::query $ref_uri platform]/"
    }
     collect the CLIENT value from the Referer header query string, if present.
    if { [URI::query $ref_uri client] ne "" } {
    set ref_Client [URI::query $ref_uri client]
    }
     if there was a host value in the Referer query string, rewrite the Host header
    set orig_URI [HTTP::uri]
    if { [URI::query $ref_uri host] ne "" } {
    set ref_Host [URI::query $ref_uri host]
    log local0.info "rewriting Host header [HTTP::host] to $ref_Host"
    HTTP::header replace Host $ref_Host
    }
    rewrite the URI to /PLATFORM/CLIENT/OriginalURI
    set awd_uri "/${ref_Platform}${ref_Client}${orig_URI}"
    log local0.info "rewriting [HTTP::uri] to ${awd_uri}"
    HTTP::uri $awd_uri
     load-balance to the AWD Pool
    pool http_test
    } else {
    log local0.warn "request for [HTTP::host][HTTP::uri] was dropped due to a missing Referer header"
    HTTP::respond 404 content "Object not found."
    }
    }
    }
    

    Aaron