bagder: curl-www latest.cgi,1.27,1.28 ipwhere.pm,NONE,1.1

[email protected]
Newsgroups gmane.comp.web.curl.www.cvs
Message-ID <[email protected]>
Update of /cvsroot/curl/curl-www
In directory labb:/tmp/cvs-serv25316

Modified Files:
	latest.cgi 
Added Files:
	ipwhere.pm 
Log Message:
initial IP=>country mapping experiements to better filter the list of provided
packages


Index: latest.cgi
===================================================================
RCS file: /cvsroot/curl/curl-www/latest.cgi,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- latest.cgi	25 Oct 2005 15:19:07 -0000	1.27
+++ latest.cgi	14 Nov 2005 10:14:52 -0000	1.28
@@ -1,6 +1,7 @@
 #!/usr/bin/perl
 
 require "CGI.pm";
+require "ipwhere.pm";
 
 use strict;
 use latest;
@@ -25,9 +26,15 @@
 
 my $what=$req->param('curl');
 
+my $showall=$req->param('all'); # override geographic checks
+
+my ($mytld, $mycontinent, $mycountry);
+my $inmycountry;
+my $inmycontinent;
+
 sub otherarchive {
 
-    print "<form method=\"GET\" action=\"latest.cgi\">\n";
+    print "<form method=\"GET\" action=\"$script\">\n";
     print "<p> Select another archive: \n";
     print "<select name=\"curl\">\n";
     for(sort {$latest::desc{$a} cmp $latest::desc{$b}} keys %latest::desc) {
@@ -116,7 +123,7 @@
     return sort { return int(rand(4)-2); } @_;
 }
 
-sub flag {
+sub gettld {
     my ($country)=@_;
     my $tld;
 
@@ -165,6 +172,13 @@
     elsif($country =~ /Taiwan/) {
         $tld="tw";
     }
+    return $tld;
+}
+
+sub flag {
+    my ($country)=@_;
+
+    my $tld = gettld($country);
 
     if($tld) {
         return "<img src=\"/pix/flags/$tld.png\" alt=\"$tld\">";
@@ -223,7 +237,7 @@
     "<br><b>MD5:</b> <tt>".$md5."</tt>\n",
     "<br><b>Size:</b> ".$latest::size{$what}." bytes\n",
     "<br><b>Version:</b> ".$latest::version{$what}."\n";
-    
+
     if( -r "download/$archive.asc" ) {
         print "<br><b>GPG signature:</b> <a href=\"download/$archive.asc\">$archive.asc</a>";
     }
@@ -233,6 +247,28 @@
         otherarchive();
     }
 
+    my $myip = $ENV{'REMOTE_ADDR'} || "193.15.23.28";
+
+    ($mytld, $mycontinent, $mycountry) = mycountry($myip);
+    #($mytld, $mycontinent, $mycountry) = ("NO", "Oceania", "NORWAY");
+
+    $mycountry = ucfirst(lc($mycountry));
+
+    # print "<p>ME: $tld in $cont\n";
+    
+    for(@dl) {
+        my $url=$_;
+        my $flag = gettld($where{$url});
+        my $urlcontinent = tld2continent( $flag );
+
+        if($flag eq lc($mytld)) {
+            $inmycountry++;
+        }
+        if($urlcontinent eq $mycontinent) {
+            $inmycontinent++;
+        }
+    }
+
     if($latest::headver ne $latest::version{$what}) {
         print "<p><i>Note that this is </i>not<i> the most recent",
         " release ($latest::headver) of the curl package!</i>";
@@ -246,8 +282,18 @@
     }
     else {
         
-        print "the following ".($#dl+1)." sites ",
+        print " ".($#dl+1)." sites ",
         "(<a href=\"#verified\">verified</a> ".&time_ago.")\n";
+
+        if($showall && ($inmycontinent || $inmycountry)) {
+            print "<p> <a href=\"$script?curl=$what\">Show my best mirrors</a>";
+        }
+        elsif($inmycountry) {
+            print "<p>$inmycountry of these mirrors are located in ".ucfirst(lc($mycountry))." where it looks like you are located. <a href=\"$script?curl=$what&all=yes\">Show all</a>\n";
+        }
+        elsif($inmycontinent) {
+            print "<p>$inmycontinent of these mirrors are located in ".ucfirst(lc($mycontinent))." where it looks like you are located. Showing those mirrors only!\n";
+        }
         
         print "<table><tr class=\"tabletop\">";
         for(('&nbsp;', 'Location', 'Proto', 'Host', 'File')) {
@@ -261,6 +307,20 @@
 
             my $flag = flag($where{$url});
 
+            if($showall) {
+                ;
+            }
+            elsif($inmycountry) {
+                if(gettld($where{$url}) ne lc($mytld)) {
+                    next;
+                }
+            }
+            elsif($inmycontinent) {
+                if(tld2continent( gettld($where{$url})) ne $mycontinent) {
+                    next;
+                }
+            }
+
             $i++;
             printf "<tr class=\"%s\"><td>%s</td><td><b>%s</b></td><td>%s</td><td>%s</td><td><a href=\"%s\">%s</a></td></tr>\n",
             $i&1?"odd":"even",
@@ -283,12 +343,47 @@
 otherarchive();
 
 print <<MOO
+<h2>Mirroring</h2>
+MOO
+    ;
 
-<p> This service automatically and frequently scans through known <a
+if(!$inmycontinent && $mycontinent) {
+print <<MOO
+<p>
+
+ There is currently <b>no download mirrors in your continent</b> holding this
+ package. If this is a new package, there might appear one later on, or we
+ hope that <i>you</i> <a href="/mirror/">start hosting a mirror</a> in
+ $mycontinent!
+
+MOO
+;
+}
+
+elsif(!$inmycountry && $mycountry) {
+print <<MOO
+<p>
+
+ There is currently <b>no download mirrors in your country</b> holding this
+ package. If this is a new package, there might appear one later on, or we
+ hope that <i>you</i> <a href="/mirror/">start hosting a mirror</a> in
+ $mycountry!
+
+MOO
+;
+}
+
+print <<MOO
+<p>
+This service automatically and frequently scans through known <a
 href="mirrors.html">mirrors</a> and builds links to the latest versions of
 many different curl archives. This page is fine to bookmark!
 
-<h2>Verification of Mirrored Packages</h2>
+<p> Our system that tries to detect your location is using data from <a
+href="http://hostip.info/">hostip.info</a>. If it seems to do wrong, please go
+there and update the info about your IP!
+
+<h2>Verification of Packages</h2>
 <a name="verified"></a>
 
 The script that "verifies" mirrored files only checks if they are present or

--- NEW FILE: ipwhere.pm ---
my %tld2cont =
('ae' => 'Asia',
'af' => 'Asia',
'ag' => 'South America',
'ai' => 'Asia',
'al' => 'Europe',
'am' => 'Asia',
'an' => 'Asia',
'ao' => 'Africa',
'aq' => 'Antarctica',
'ar' => 'South America',
'as' => 'Oceania',
'at' => 'Europe',
'au' => 'Oceania',
'aw' => 'South America',
'az' => 'Europe',
'ba' => 'Europe',
'bb' => 'South America',
'bd' => 'Asia',
'be' => 'Europe',
'bf' => 'Africa',
'bg' => 'Europe',
'bh' => 'Asia',
'bi' => 'Asia',
'bj' => 'Africa',
'bm' => 'South America',
'bn' => 'Asia',
'bo' => 'South America',
'br' => 'South America',
'bs' => 'South America',
'bt' => 'Asia',
'bv' => 'Europe',
'bw' => 'Africa',
'by' => 'Asia',
'bz' => 'South America',
'ca' => 'North America',
'cc' => 'Asia',
'cf' => 'Africa',
'cg' => 'Africa',
'ch' => 'Europe',
'ci' => 'Africa',
'ck' => 'Oceania',
'cl' => 'South America',
'cm' => 'Africa',
'cn' => 'Asia',
'co' => 'South America',
'cr' => 'South America',
'cu' => 'South America',
'cv' => 'Africa',
'cx' => 'Asia',
'cy' => 'Europe',
'cz' => 'Europe',
'de' => 'Europe',
'dj' => 'Africa',
'dk' => 'Europe',
'dm' => 'South America',
'do' => 'South America',
'dz' => 'Africa',
'ec' => 'South America',
'ee' => 'Europe',
'eg' => 'Africa',
'eh' => 'Africa',
'es' => 'Europe',
'et' => 'Africa',
'fi' => 'Europe',
'fj' => 'Oceania',
'fk' => 'South America',
'fm' => 'Oceania',
'fo' => 'Europe',
'fr' => 'Europe',
'fx' => 'Europe',
'ga' => 'Africa',
'gb' => 'Europe',
'gd' => 'South America',
'ge' => 'Asia',
'gf' => 'Africa',
'gh' => 'Africa',
'gi' => 'Europe',
'gl' => 'Europe',
'gm' => 'Africa',
'gn' => 'Africa',
'gp' => 'Africa',
'gq' => 'Africa',
'gr' => 'Europe',
'gt' => 'South America',
'gu' => 'Oceania',
'gw' => 'Africa',
'gy' => 'Africa',
'hk' => 'Asia',
'hm' => 'Oceania',
'hn' => 'South America',
'hr' => 'Europe',
'ht' => 'South America',
'hu' => 'Europe',
'id' => 'Asia',
'ie' => 'Europe',
'il' => 'Asia',
'in' => 'Asia',
'io' => 'Asia',
'iq' => 'Asia',
'ir' => 'Asia',
'is' => 'Europe',
'it' => 'Europe',
'jm' => 'South America',
'jo' => 'Asia',
'jp' => 'Asia',
'ke' => 'Africa',
'kg' => 'Asia',
'kh' => 'Asia',
'ki' => 'Oceania',
'km' => 'Asia',
'kn' => 'Asia',
'kp' => 'Asia',
'kr' => 'Asia',
'kw' => 'Asia',
'ky' => 'Asia',
'kz' => 'Asia',
'la' => 'Asia',
'lb' => 'Asia',
'lc' => 'Asia',
'li' => 'Europe',
'lk' => 'Asia',
'lr' => 'Africa',
'ls' => 'Africa',
'ls' => 'Africa',
'lt' => 'Europe',
'lu' => 'Europe',
'lv' => 'Europe',
'ly' => 'Africa',
'ma' => 'Africa',
'mc' => 'Europe',
'md' => 'Europe',
'mg' => 'Africa',
'mh' => 'Oceania',
'mk' => 'Europe',
'ml' => 'Africa',
'mm' => 'Africa',
'mn' => 'Asia',
'mo' => 'Asia',
'mp' => 'Oceania',
'mq' => 'Africa',
'mr' => 'Africa',
'ms' => 'Africa',
'mt' => 'Europe',
'mu' => 'Africa',
'mv' => 'Asia',
'mw' => 'Africa',
'mx' => 'North America',
'my' => 'Asia',
'mz' => 'Africa',
'na' => 'Africa',
'nc' => 'Oceania',
'ne' => 'Africa',
'nf' => 'Oceania',
'ng' => 'Africa',
'ni' => 'South America',
'nl' => 'Europe',
'no' => 'Europe',
'np' => 'Asia',
'nr' => 'Oceania',
'nt' => 'Asia',
'nu' => 'Oceania',
'nz' => 'Oceania',
'om' => 'Asia',
'pa' => 'South America',
'pe' => 'South America',
'pf' => 'Oceania',
'pg' => 'Asia',
'ph' => 'Asia',
'pk' => 'Asia',
'pl' => 'Europe',
'pm' => 'North America',
'pn' => 'Oceania',
'pr' => 'South America',
'pt' => 'Europe',
'pw' => 'Oceania',
'py' => 'South America',
'qa' => 'Asia',
're' => 'Africa',
'ro' => 'Europe',
'ru' => 'Europe',
'rw' => 'Africa',
'sa' => 'Asia',
'sb' => 'Oceania',
'sc' => 'Asia',
'sd' => 'Africa',
'se' => 'Europe',
'sg' => 'Asia',
'sh' => 'Africa',
'si' => 'Europe',
'sj' => 'Europe',
'sk' => 'Europe',
'sl' => 'Africa',
'sm' => 'Europe',
'sn' => 'Africa',
'so' => 'Africa',
'sr' => 'South America',
'st' => 'South America',
'su' => 'Asia',
'sv' => 'South America',
'sy' => 'Asia',
'sz' => 'Africa',
'tc' => 'Asia',
'td' => 'Africa',
'tf' => 'Africa',
'tg' => 'Africa',
'th' => 'Asia',
'tj' => 'Asia',
'tk' => 'Oceania',
'tm' => 'Asia',
'tn' => 'Africa',
'to' => 'Oceania',
'tp' => 'Asia',
'tr' => 'Asia',
'tt' => 'South America',
'tv' => 'Oceania',
'tw' => 'Asia',
'tz' => 'Africa',
'ua' => 'Europe',
'ug' => 'Africa',
'uk' => 'Europe',
'um' => 'North America',
'us' => 'North America',
'uy' => 'South America',
'uz' => 'Asia',
'va' => 'Europe',
'vc' => 'South America',
've' => 'South America',
'vg' => 'South America',
'vi' => 'South America',
'vn' => 'Asia',
'vu' => 'Oceania',
'wf' => 'Oceania',
'ws' => 'Oceania',
'ye' => 'Asia',
'yt' => 'Africa',
'yu' => 'Europe',
'za' => 'Africa',
'zm' => 'Africa',
'zr' => 'Africa',
'zw' => 'Africa',
'er' => 'Africa',
 );

sub mycountry {
    my ($ip)=@_;
    my @o=`/home/dast/bin/ipwhere $ip`;
    my ($tld, $area, $full);
    for(@o) {
        if($_ =~ /^TLD: (.*)/) {
            $tld = $1;
        }
        elsif($_ =~ /^AREA: (.*)/) {
            $area = $1;
        }
        elsif($_ =~ /^FULL: (.*)/) {
            $full = $1;
        }
    }

    return ($tld, $area, $full);
}

# convert a two-letter TLD to a full text continent string
sub tld2continent {
    my ($tld)=@_;

    return $tld2cont{lc($tld)};
}

1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.