Archived
1
0
This repository has been archived on 2021-10-08. You can view files and clone it, but cannot push or open issues or pull requests.
ACU/hooks/gl-pre-git
2013-10-12 02:47:57 +02:00

56 lines
1.4 KiB
Perl
Executable File

#!/usr/bin/env perl
use strict;
use warnings;
use v5.10;
use File::Basename;
use Net::IP;
use ACU::Log;
$ACU::Log::log_file = "/var/log/hooks/" . basename($0) . ".log";
my $ip = $1 if ($ENV{'SSH_CLIENT'} =~ m/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*/);
exit 0 if (!$ip);
log DEBUG, "Connection to $ENV{GL_REPO} from $ip";
# First, check if the repository is in the YYYY/ directory
exit 0 if ($ENV{GL_REPO} !~ /^2[0-9]{3}\/.+\/.+/);
my $read = ($ARGV[0] =~ /R/);
my $write = ($ARGV[0] =~ /W/);
my $promo = $1 if ($ENV{'GL_REPO'} =~ m/([0-9]{4}).*/);
my $id_project = $1 if ($ENV{'GL_REPO'} =~ m/.*\/(.*)\//);
my $repo_login = $1 if ($ENV{'GL_REPO'} =~ m/.*\/.*\/(.*)/);
$ip = Net::IP->new($ip) or die ("IP invalide");
my $schoolnetwork = Net::IP->new('10.41.0.0/16');
if ($ip->overlaps($schoolnetwork) != $IP_A_IN_B_OVERLAP)
{
say "Votre IP est : $ip.";
log ERROR, "Vous n'êtes pas autorisé à envoyer vos modifications depuis cette IP." if ($write);
log ERROR, "Vous n'êtes pas autorisé à accéder à ce dépôt depuis cette IP." if ($read);
exit 1;
}
my $sshnetwork = Net::IP->new('10.41.253.0/24');
if ($ip->overlaps($sshnetwork) == $IP_A_IN_B_OVERLAP)
{
say "Votre IP est : $ip.";
log ERROR, "Vous n'êtes pas autorisé à envoyer vos modifications depuis cette IP." if ($write);
log ERROR, "Vous n'êtes pas autorisé à accéder à ce dépôt depuis cette IP." if ($read);
exit 1;
}
exit 0;