Permalink
Browse files

Store anonimized IP

  • Loading branch information...
miyagawa committed Mar 18, 2013
1 parent 161b087 commit 8d494bbd05a17adde382c41d32db42f173d24945
Showing with 30 additions and 13 deletions.
  1. +26 −4 app-gw.psgi
  2. +1 −0 cpanfile
  3. +1 −1 index.html
  4. +2 −8 script/drawchart.pl
View
@@ -1,4 +1,20 @@
use Plack::Builder;
+use Digest::SHA1 qw(sha1_hex);
+
+my $salt = int(rand(2**32));
+
+sub almost_uniq_hash {
+ my $ip = shift;
+ $ip =~ s/(\d+)\.?/sprintf("%02x", $1)/ge;
+
+ my $val = join "-", $ip, (hex($ip) % $salt);
+ substr(sha1_hex($val), 0, 16);
+}
+
+sub maybe_travis {
+ local $_ = shift;
+ /^199\.91\.17[01]\./ or /^199\.182\.120\./; # Travis CI
+}
my $app = do "./app.psgi";
@@ -13,12 +29,18 @@ my $head = sub {
};
};
+my $munge_addr = sub {
+ my $app = shift;
+ sub {
+ $_[0]->{REMOTE_ADDR} = almost_uniq_hash($_[0]->{HTTP_FASTLY_CLIENT_IP});
+ $_[0]->{HTTP_USER_AGENT} .= " travis" if maybe_travis($_[0]->{HTTP_FASTLY_CLIENT_IP});
+ $app->($_[0]);
+ };
+};
+
builder {
enable $head;
- enable sub {
- my $app = shift;
- sub { $_[0]->{REMOTE_ADDR} = $_[0]->{HTTP_FASTLY_CLIENT_IP}; $app->($_[0]) };
- };
+ enable $munge_addr;
mount 'http://sunaba.plackperl.org/' => sub {
return [ 404, ['Content-Type', 'text/plain'], ['Not Found'] ];
};
View
@@ -4,3 +4,4 @@ requires 'AnyEvent::HTTP';
requires 'IO::Uncompress::Gunzip';
requires 'Plack';
requires 'Plack::Middleware::ReverseProxy';
+requires 'Digest::SHA1';
View
@@ -30,7 +30,7 @@ <h2 id="privacy">Notes</h2>
</p>
<p>
-The collected data is stored securely on the application server and our CDN provider <a href="http://www.fastly.com">fastly</a> (<a href="http://www.fastly.com/terms">terms</a>), and used to make the service more reliable (e.g. blacklisting DoS attacks) and for data mining purposes such as <a href="http://cpanmetadb.plackperl.org/static/versions/index.html">perl version stats</a>. Unmasked IP addresses are never published nor shared with third parties.
+The collected data is stored securely on the application server (by hashing the IP address to be anonymized) and our CDN provider <a href="http://www.fastly.com">fastly</a> (<a href="http://www.fastly.com/terms">terms</a>), and used to make the service more reliable (e.g. blacklisting DoS attacks) and for data mining purposes such as <a href="http://cpanmetadb.plackperl.org/static/versions/index.html">perl version stats</a>. Unmasked IP addresses are never stored, published nor shared with third parties (besides Fastly, who serves the cached content in behalf of our servers).
</p>
<div id="footer">
View
@@ -8,18 +8,12 @@ sub versionify {
and return join '.', 5, $1+0, $2+0;
}
-sub probably_testers {
- local $_ = shift;
- return 1 if /^199\.91\.17[01]\./ or /^199\.182\.120\./; # Travis CI
- return 0;
-}
-
my(%uniq, %versions);
while (<>) {
my @line = split / /, $_;
- my($ip, $perl) = @line[0, 12];
- next if probably_testers($ip);
+ my($ip, $perl, $travis) = @line[0, 12, 13];
+ next if $travis =~ /travis/;
if ($perl =~ /^perl\/(5\.\d{6})"$/) {
$uniq{"$ip-$1"}++ or $versions{$1}++;
}

0 comments on commit 8d494bb

Please sign in to comment.