Browse Source

Added new Maxmind TOS, colored log output and setuid-bit information

* FIX: Maxmind now allows redistributing GeoLite2-ASN database if requirements are fulfilled (#3)
 * ADD: Maxmind's TOS added as start-up message
 * ADD: Added some useful log output (and colors \o/)
 * ADD: INSTALL notes now giving hint about "setuid-bit" for traceroute command
master
XiCoN-FJS- 2 years ago
parent
commit
c6e1ca9c10
  1. 51
      xtr.pl

51
xtr.pl

@ -14,6 +14,7 @@ use Data::Validate::Domain qw(is_domain);
use Data::Validate::IP qw(is_public_ipv4 is_public_ipv6);
use MaxMind::DB::Reader;
use Archive::Tar;
use Term::ANSIColor;
use Data::Dumper;
@ -28,12 +29,17 @@ use Data::Dumper;
# uses the MaxMind perl module which uses the MaxMind DB library.
#
#
# This product includes GeoLite2 data created by MaxMind, available from
# <a href="https://www.maxmind.com">https://www.maxmind.com</a>
# This product includes GeoLite2 ASN data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>.
######################################################################################################################################################
### CHANGELOG ######################################################################################################################################
# v0.8 (2020-04-14)
# * FIX: Maxmind now allows redistributing GeoLite2-ASN database if requirements are fulfilled (https://git.xicon.eu/xicon/xtr/issues/3)
# * ADD: Maxmind's TOS added as start-up message
# * ADD: Added some useful log output (and colors \o/)
# * ADD: INSTALL notes now giving hint about "setuid-bit" for traceroute command
#
# v0.7 (2019-10-18)
# * ADD: IPv6 requests are now possible
# * ADD: Domain request are now possible (will be resolved to ip address)
@ -61,6 +67,11 @@ use Data::Dumper;
# This is a standalone software which usually runs in the "foreground". Starting it in a screen session or via init.d/systemd/rc.d is
# highly recommended. For testing, starting this script in a screen session is also fine.
#
# To run properly as a non-root user you need to set the setuid-bit on the traceroute binary of your system:
# > chmod 4755 /usr/bin/traceroute
# Depending on your system /usr/bin/traceroute could just be a soft link, but you have to set the setuid to the real binary!
#
#
# Either install all listed modules with "cpan -i <module>" or use your system's package manager (apt, yum, yast).
#
# On Debian just install these packages:
@ -84,9 +95,9 @@ use Data::Dumper;
### VARS ###########################################################################################################################################
my $VERSION = "0.7";
my $VERSION = "0.8";
my $dbfile = 'GeoLite2-ASN.mmdb';
my $db_source = 'http://geolite.maxmind.com/download/geoip/database/GeoLite2-ASN.tar.gz';
my $db_source = 'http://xtr.xicon.eu/GeoLite2-ASN.tar.gz';
my $master_server = 'xtr-master.xicon.eu';
my $get_my_ip_service = 'http://ipv4.xicon.eu/'; # some service, which returns just the ip of the requesting host (in this case, us.)
my $client_protocol_version = 4;
@ -101,13 +112,21 @@ my $my_ext_port = 0; # set different port, if public access port differs from ap
### NOTHING TO CHANGE BELOW HERE ###################################################################################################################
######################################################################################################################################################
### Required mentioning of Maxmind's TOS (https://git.xicon.eu/xicon/xtr/issues/3)
print_maxmind_tos();
### set vars
set port => $my_port;
if($my_ext_ip eq "") { $my_ext_ip = $my_ip; }
if($my_ext_ip eq "0.0.0.0") { die "Couldn't determine my own IP"; }
if($my_ext_ip eq "0.0.0.0") { print colored(['red'], "[ERR] Couldn't determine my own IP. Exiting...\n"); exit 1; }
if($my_ext_port eq 0 || $my_ext_port eq "") { $my_ext_port = $my_port; }
print colored(['green'], "[INFO] ") . color('reset');
print "External IP: ".$my_ext_ip."\n";
print colored(['green'], "[INFO] ") . color('reset');
print "External Port: ".$my_ext_port."\n";
get_maxmind_db($db_source,$dbfile);
### connect to database
@ -142,10 +161,12 @@ get '/v3/client/info/version' => sub {
### give the master server the info, that we are available
if(send_server_status($master_server,$my_ext_ip,$my_ext_port,"1"))
{
print "send the master server ".$master_server." the info, that we are online.\n";
print colored(['green'], "[INFO] ") . color('reset');
print "Sending the master server ".$master_server." the info, that we are online.\n";
}
else
{
print colored(['red'], "[ERR] ") . color('reset');
print "Failed to send our status to the master server ".$master_server." - nobody knows we are online :(\n";
}
@ -290,6 +311,9 @@ sub get_maxmind_db
{
my ($db_source,$dbfile) = @_;
print colored(['green'], "[INFO] ") . color('reset');
print "Fetching latest IP2ASN database: ".$db_source."\n";
my $ff = File::Fetch->new(uri => $db_source);
my $temp_file = $ff->fetch( to => '/tmp' );
@ -301,11 +325,22 @@ sub get_maxmind_db
{
if($file->{'name'}=~/${dbfile}$/)
{
open(FILE,">",$dbfile) or die "Can't open file for writing: $!";
open(FILE,">",$dbfile) or die colored(['red'], "[ERR] Can't open file for writing: $!");
print FILE $file->{'data'};
close(FILE);
}
}
$tar->clear;
unlink($temp_file);
}
}
sub print_maxmind_tos
{
print qq{ --------------------------------------------------------------------------------------------------------------------------------------- };
print "\n";
print qq{ This product includes GeoLite2 ASN data created by MaxMind, available from <a href="http://www.maxmind.com">http://www.maxmind.com</a>. };
print "\n";
print qq{ --------------------------------------------------------------------------------------------------------------------------------------- };
print "\n";
print "\n";
}

Loading…
Cancel
Save