Geolocation & Zeus ZXTM 6.0

4

Mozilla’s North American store has been down in maintenance mode (you can read about the why) but not the International Store.

The old store used to redirect non-North American users to the International Store, but unfortunately that redirect wasn’t carried over when we took the store offline.

I was inspired Sunday night to put together a ZXTM TrafficScript rule based off the code sample on Zeus’s knowledgehub (and because of bug 521914).

And then on Wednesday Zeus finally released ZXTM 6.0 with geolocation support!

What was 40 some lines of code is now like 5.

Before:

$ipaddr = request.getRemoteIP();

# Integer representation of $ipaddr >> 1
string.regexmatch( $ipaddr, "(\\d+)\\.(\\d+)\\.(\\d+)\\.(\\d+)" );
$ip = ((($1*256+$2)*256+$3)*128+$4/2);

$arr = resource.get( "geoip.dat" );

# initialize indices
$i = 0; $j = string.len( $arr )/6-1;

# $arr[$i] <= $ip < $arr[$j]
# iteratively halve the distance between $i and $j until they are adjacent

while( $j-$i > 1 ) {
   # midpoint between $i and $j
   $k = ($i+$j)/2;

   # compare $ip with $arr[$k]
   if( string.bytesToInt( string.subString( $arr, $k*6, $k*6+3 ) ) > $ip ) {
      $j = $k;
   } else {
      $i = $k;
   }
}

# Now, $arr[$i] <= $ip < $arr[$j] and $j == $i+1
# Look up the 2-character country code (returns '??' if unknown)
$ccode = string.subString( $arr, $i*6+4, $i*6+5 );

if ( ($ccode != "US") && ($ccode != "CA") ) {
}
else {
   http.redirect("https://intlstore.mozilla.org/");
}

After:

$ipaddr = request.getRemoteIP();

$country = geo.getCountryCode( $ipaddr );

if ( ($country != "US") && ($country != "CA") ) {
      http.redirect("https://intlstore.mozilla.org/");
}
​

Tags: ,

Categories: load balancing, Mozilla

4 responses

  1. Gerv wrote on :

    The old redirect was overrideable – that was very useful for me when I wanted to look up schwag prices on the American store. Is the new one also overrideable? :-)

    Gerv

  2. alex wrote on :

    Perhaps the provider named in the “why” link is in the market for a “certain vendor’s” Application Firewall Module? :-)

  3. nyt wrote on :

    For what it’s worth, ZXTM is no longer. Welcome ZeusTM :-)

  4. carte memoire wrote on :

    I found location-sensitive traffic management policies using TrafficScript and the new geolocation capabilities to handle user requests based on their location by Zeus Traffic Manager 6.0. It also conduct some impressive features like Detailed Traffic Diagnostics, Multi-Hosted Traffic IP addresses and Command-line Interface.