Forum Discussion

Wes_98712's avatar
Wes_98712
Icon for Nimbostratus rankNimbostratus
Nov 09, 2005

undefined procedure: elseif

Ok,

 

 

This conversion process is killing me, I almost had a good chunk of my v4.X converted, and working (meaning my 3400 series LB wasn't rebooting...good thing). Now I have a strange issue, by adding the last line in the following code I get the following error:

 

 

 01070151:3: Rule [r_wes_test] error: 
line 27: [undefined procedure: elseif] [elseif { $my_uri starts_with "/worldseries"} { HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/worldseries/index.tbapp?affiliate_id=1b" }]

 

 

Here are my irules as of now:

 

 set my_uri [HTTP::uri]
   set my_query [HTTP::query]
   if { [HTTP::host] equals "soaringdreams.ameriquest.com"} {
      HTTP::respond 301 "Location" "http://www.ameriquestsoaringdreams.com"
   }
   elseif { $my_uri contains "texas" } {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=texasfair"
   }
   elseif { $my_uri matches_regex "cfide" } {
         discard
   }
   elseif { $my_uri starts_with "/Amigo"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?lang=es&ad=LMAMIGO"
   }
   elseif { $my_uri starts_with "/LuisMiguelFriend"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?ad=LMFRIEND"
   }
   elseif { $my_uri contains "directmerchantsbank"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=directmerchantsbank"
   }
   elseif { $my_uri starts_with "/refi"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=SHAPEMAIL001"
   }
   elseif { $my_uri starts_with "/freedom"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=SHAPEMAIL002"
   }
   elseif { $my_uri contains "propertyvalue"} {
         HTTP::respond 301 "Location" "http://homevalue.ameriquest.com/fares.html?ad=propertyvalue"
   }
   elseif { $my_uri contains "espanol"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=espanol"
   }
   elseif { $my_uri contains "bonuspack"} {
         HTTP::respond 301 "Location" "http://homevalue.ameriquest.com/fares.html?ad=bonuspak"
   }
   elseif { $my_uri contains "bonuspak"} {
         HTTP::respond 301 "Location" "http://homevalue.ameriquest.com/fares.html?ad=bonuspak"
   }
   elseif { $my_uri contains "prime"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/disclaimers/bedford.html"
   }
   elseif { $my_uri contains "woody"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/welcome.html?ad=woody"
   }
   elseif { $my_uri starts_with "/house"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/wwwmodules/house.html"
   }
   elseif { $my_uri contains "freepayments"} {
         HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house2005/english/index.tbapp?pic=h"
   }
   elseif { $my_uri contains "baseball"} {
         HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house/?pic=d"
   }
   elseif { $my_uri starts_with "/freehousepayments"} {
         HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house2005/english/index.tbapp?pic=h"
   }
   elseif { $my_uri contains "monster"} {
         HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/house/?pic=m"
   }
   elseif { $my_uri contains "careers"} {
         HTTP::respond 301 "Location" "http://careers.ameriquest.com"
   }
   elseif { $my_uri contains "subsection=welcome&ad="} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/welcome.html?$my_query"
   }
   elseif { $my_uri starts_with "/creditreport"} {
         HTTP::respond 301 "Location" "http://www.onlinecreditinformation.biz/?website=amc"
   }
   elseif { $my_uri starts_with "/dothemath"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=infom001"
   }   
 

 

 

I thought that perhaps the TCL implementation has some aversions to white spaces, but if I remove the /worldseries statement it takes the rule just fine, if I move the /worldseries statement behind the /dothemath statement, as follows:

 

 

 elseif { $my_uri starts_with "/dothemath"} {
         HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/doTheMath.html?ad=infom001"
   } elseif { $my_uri starts_with "/worldseries"} {
        HTTP::respond 301 "Location" "http://clients.eprize.net/ameriquest/worldseries/index.tbapp?affiliate_id=1b"
   } 

 

 

it takes it, if I try to keep the formatting the same it throws an exception. I have no friggen clue why. Thoughts?

 

 

-Wes
  • FYI: If anyone is interested I fixed this by reformatting the code as follows:

     

     

    
    when HTTP_REQUEST {
       set my_uri [HTTP::uri]
       set my_query [HTTP::query]
       if { [HTTP::host] equals "soaringdreams.ameriquest.com"} {
          HTTP::respond 301 "Location" "http://www.ameriquestsoaringdreams.com"
       } elseif { $my_uri contains "texas" } {
             HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=texasfair"
       } elseif { $my_uri matches_regex "cfide" } {
             discard
       } elseif { $my_uri starts_with "/Amigo"} {
             HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?lang=es&ad=LMAMIGO"
       } elseif { $my_uri starts_with "/LuisMiguelFriend"} {
             HTTP::respond 
       }   
    }

     

     

    seems the TCL engine is kind of whitespace sensitive, not good...really not good...it makes the whole entire process too **bleep** complicated.

     

     

    -Wes
  • This is a common issue that seems to crop up every so often. Actually, TCL forces elseif's to be on the same line as the closing brace and the opening brace after it has to be on the same line as well. We've made some changes to the TCL interpreter to allow newlines but there is a bug that you can't have whitespace after the brace and before the newline. I believe this has been fixed in the latest release.

    So, as a rule, you should probably go with the way that TCL mandates to avoid any issues...

    if { condition } {
      ...
    } elseif { condition } {
      ...
    } else {
      ...
    }

    Sorry for the inconvenience...

    BTW, I would highly suggest you remove the matches_regex in your iRule. You are incurring the cost of the regular expression engine when you aren't actually using a regular expression. The contains operator is much more efficient.

    when HTTP_REQUEST {
       set my_uri [HTTP::uri]
       set my_query [HTTP::query]
       if { [HTTP::host] equals "soaringdreams.ameriquest.com"} {
          HTTP::respond 301 "Location" "http://www.ameriquestsoaringdreams.com"
       } elseif { $my_uri contains "texas" } {
             HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/index.html?ad=texasfair"
       } elseif { $my_uri contains "cfide" } {
             discard
       } elseif { $my_uri starts_with "/Amigo"} {
             HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/sweepStakes/showRegistration.html?lang=es&ad=LMAMIGO"
       } elseif { $my_uri starts_with "/LuisMiguelFriend"} {
             HTTP::respond 
       }   
    }

    Is there a reason why the matches_regex is in there that I'm missing?

    -Joe
  • Thanks Joe, that worked perfectly.

     

     

    As far as the matches_regex, I think we had some issues with URI strings coming in with potentially different character cases (e.g. upper/lower or combination of the two). In v4.X the contains parameter didn't seem to address the issue at all, I had to switch it to matches_regex. Perhaps in v9 that has been addressed? I will test it out, and yes I agree, contains is far more efficient as far as processing time.

     

     

    -Wes
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    There's two options for dealing with case. The first is to simply convert the uri either to all lower case or all upper case with the "string tolower" or "string toupper" commands. The second option is to use "string first -nocase" which searches for the first occurence of a string within a string without regard to case.

     

    The contains operator still does a case-sensitive match.
  • Interesting, then I will try the string tolower and see how it works. Thanks. Is there an updated irules PDF that I can reference, I'm finding the one I have for v9 is not accurate at all.
  • I tried the following and it skips the rule completley, doesn't even log anything:

    } elseif { [string tolower [HTTP::uri]] contains "StonesReg"} {
          log local0.
          HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/wwwmodules/stonessweeps.html?ad=1K" }

    I also tried the following and it as well doesn't log anything and skips the rule

    
    set my_uri [HTTP::uri]
    if { [string tolower $my_uri] contains "StonesReg"} {
          log local0.
          HTTP::respond 301 "Location" "http://www.ameriquestmortgage.com/wwwmodules/stonessweeps.html?ad=1K"
        }

    I must be doing something wrong here. All I want to do is take whatever combo of characters are passed through for the string stonesreg and redirect accordingly.

    Thoughts?
  • You are converting the URI to lowercase, but then doing a case-comparison with a mixed case string so of course it will never match. Try comparing to a all lowercase string (ie. "StonesReg" => "stonesreg").

     

     

    Also, you need to add something to log. Your log statement "log local0." needs a string afterwards. (ie. log local0. "found match").

     

     

    -Joe
  • unRuleY_95363's avatar
    unRuleY_95363
    Historic F5 Account
    Um, I hate to point out the obvious, but "StonesReg" is upper and lowercase. The "string tolower" command converts the uri to all lowercase. Try "stonesreg" as the string you are comparing to...
  • Yeah I just figured that out, stupid, stupid stupid...I can't believe I didn't address that before posting. ;-)

     

     

    -Wes