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

56 lines
1.4 KiB
Plaintext
Raw Normal View History

2013-09-28 09:15:31 +00:00
#!/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}).*/);
2013-10-07 14:42:02 +00:00
exit 0 if (!$ip);
log DEBUG, "Connection to $ENV{GL_REPO} from $ip";
2013-09-28 09:15:31 +00:00
# First, check if the repository is in the YYYY/ directory
exit 0 if ($ENV{GL_REPO} !~ /^2[0-9]{3}\/.+\/.+/);
2013-10-07 18:19:07 +00:00
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/.*\/.*\/(.*)/);
2013-09-28 09:15:31 +00:00
$ip = Net::IP->new($ip) or die ("IP invalide");
2013-09-30 08:27:44 +00:00
my $schoolnetwork = Net::IP->new('10.41.0.0/16');
2013-09-28 09:15:31 +00:00
if ($ip->overlaps($schoolnetwork) != $IP_A_IN_B_OVERLAP)
{
say "Votre IP est : $ip.";
2013-10-07 18:19:07 +00:00
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);
2013-09-28 09:15:31 +00:00
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.";
2013-10-07 18:19:07 +00:00
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);
2013-09-28 09:15:31 +00:00
exit 1;
}
exit 0;