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/");
}
4 responses