From 84c34f8fea1a72b1174ab184b26ca084b16a2c4a Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Mon, 25 Nov 2013 19:20:03 +0100 Subject: [PATCH 1/6] Fix guantanamo syntax --- process/exec/guantanamo.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/process/exec/guantanamo.pl b/process/exec/guantanamo.pl index 745a120..1b209dd 100644 --- a/process/exec/guantanamo.pl +++ b/process/exec/guantanamo.pl @@ -121,13 +121,13 @@ sub master_launch } for my $node (@lnodes) { - my $o = $ret{$node}->documentElement->getElementsByTagName("out"); - if ($o) { + my @o = $ret{$node}->documentElement->getElementsByTagName("out"); + if (@o) { $output .= $o[0]->firstChild->nodeValue; } - $e = $ret{$node}->documentElement->getElementsByTagName("err"); - if ($e) { + my @e = $ret{$node}->documentElement->getElementsByTagName("err"); + if (@e) { $output .= $e[0]->firstChild->nodeValue; } $output .= $e[0]->firstChild->nodeValue; From dfb66035eb2d5f5321b57780633bc0d9b2313552 Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Tue, 26 Nov 2013 19:17:19 +0100 Subject: [PATCH 2/6] New hook post-update --- Makefile | 1 + hooks/post-update | 96 ++++++++++++++++++++++++++++++++++++++++++++ hooks/submissions.pl | 39 +++--------------- 3 files changed, 103 insertions(+), 33 deletions(-) create mode 100755 hooks/post-update diff --git a/Makefile b/Makefile index 12886aa..7b856b5 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ install: $(COPY) -r ACU/ $(DEST) ! test -d $(GITOLITE_DEST) || $(MAKEDIR) -p $(GITOLITE_DEST)/update.secondary.d ! test -d $(GITOLITE_DEST) || $(COPY) hooks/gl-pre-git $(GITOLITE_DEST)/ + ! test -d $(GITOLITE_DEST) || $(COPY) hooks/post-update $(GITOLITE_DEST)/ ! test -d $(GITOLITE_DEST) || $(COPY) hooks/subjects.pl $(GITOLITE_DEST)/update.secondary.d/ ! test -d $(GITOLITE_DEST) || $(COPY) hooks/conferences.pl $(GITOLITE_DEST)/update.secondary.d/ ! test -d $(GITOLITE_DEST) || $(COPY) hooks/submissions.pl $(GITOLITE_DEST)/update.secondary.d/ diff --git a/hooks/post-update b/hooks/post-update new file mode 100755 index 0000000..7fede19 --- /dev/null +++ b/hooks/post-update @@ -0,0 +1,96 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use v5.10; +use File::Basename; +use utf8; + +use ACU::API::Projects; +use ACU::API::Submission; +use ACU::LDAP; +use ACU::Log; +$ACU::Log::log_file = "/var/log/hooks/" . basename($0) . ".log"; +use ACU::Process; + +my $promo; +my $id_project; +my $repo_login; + +# First, extract information, from config then guess from repository adress +if (my $tmp = `git config hooks.promo`) { chomp $tmp; $promo = $tmp; } +if (my $tmp = `git config hooks.idproject`) { chomp $tmp; $id_project = $tmp; } +if (my $tmp = `git config hooks.login`) { chomp $tmp; $repo_login = $tmp; } + +$promo = $1 if (!$promo && $ENV{'GL_REPO'} =~ m/([0-9]{4}).*/); +$id_project = $1 if (!$id_project && $ENV{'GL_REPO'} =~ m/.*\/(.*)\//); +$repo_login = $1 if (!$repo_login && $ENV{'GL_REPO'} =~ m/.*\/.*\/(.*)/); + +exit(0) if (!$promo || !$id_project || !$repo_login); + +for my $ref (@ARGV) +{ + if ($ref =~ m<^refs/tags/(.+)$>) + { + my $tag = $1; + log DEBUG, "Tag $tag on repository $ENV{GL_REPO} from IP $ENV{'SSH_CLIENT'} updated."; + + # Get project informations + my $project; + eval { + $project = API::Projects::get($id_project, $promo); + }; + if ($@ or !$project) + { + my $err = $@; + log TRACE, $err; + log ERROR, "Impossible d'envoyer de tags ; si le problème persiste, passez au laboratoire."; + exit 1; + } + + # Extract lot of data + my @rendus = grep { + exists $_->{vcs} and $_->{vcs}{tag} eq $tag; + } @{ $project->{submissions} }; + + if (@rendus) + { + eval + { + Process::Client::launch("send_git", + { + "year" => $promo, + "id" => $id_project, + "rendu" => $tag, + "login" => $repo_login, +# "path" => "ssh://git\@localhost/".$ENV{GL_REPO}, # Optional + }, + undef, # Don't give any file + 1 # Launch in background + ); + }; + if ($@) + { + my $err = $@; + log DEBUG, "ERROR: ".$err; + } + + # Send data to API + my $last_commit = `git log "refs/tags/$tag" -1 --decorate --tags`; + eval { + API::Submission::add($promo, $id_project, $tag, $repo_login, $last_commit); + }; + if ($@) + { + my $err = $@; + log DEBUG, "ERROR: ".$err; + log DONE, "Tag '$tag' effectué avec succès !"; + } + else { + log DONE, "Tag '$tag' effectué avec succès ! Vérifiez-le sur l'intranet."; + } + } + } +} + +exit 0; diff --git a/hooks/submissions.pl b/hooks/submissions.pl index 4720bc9..5311df7 100755 --- a/hooks/submissions.pl +++ b/hooks/submissions.pl @@ -52,7 +52,7 @@ if ($ref =~ m<^refs/tags/(.+)$>) my $err = $@; log TRACE, $err; log ERROR, "Impossible d'envoyer de tags ; si le problème persiste, passez au laboratoire."; - exit 1; + exit(1); } log TRACE, $project; @@ -119,40 +119,13 @@ if ($ref =~ m<^refs/tags/(.+)$>) } } - if ($newsha eq '0' x 40) { - log USAGE, "Mais pour quelle raison voudriez-vous supprimer un tag ?!"; - } - else + if (@rendus && $newsha eq '0' x 40) { - eval { - Process::Client::launch("send_git", - { - "year" => $promo, - "id" => $id_project, - "rendu" => $tag, - "login" => $repo_login, -# "path" => "ssh://git\@localhost/".$ENV{GL_REPO}, - }, undef, 1); - }; - if ($@) { - my $err = $@; - log DEBUG, "ERROR: ".$err; - } - - # Send data to API - my $last_commit = `git log $newsha -1 --decorate --tags`; - eval { - API::Submission::add($promo, $id_project, $tag, $repo_login, $last_commit); - }; - if ($@) { - my $err = $@; - log DEBUG, "ERROR: ".$err; - log DONE, "Tag '$tag' effectué avec succès !"; - } - else { - log DONE, "Tag '$tag' effectué avec succès ! Vérifiez-le sur l'intranet."; - } + log USAGE, "Mais pour quelle raison voudriez-vous supprimer un tag ?!"; + exit(7); } +# elsif @rendus : new rendu => accepted +# else user defined tag => accepted } exit 0; From 5fe1d4c80d48a6cbaf0ae8dfc86a937f91ddb1b0 Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Wed, 27 Nov 2013 15:26:13 +0100 Subject: [PATCH 3/6] Fix utf-8 --- hooks/gl-pre-git | 1 + 1 file changed, 1 insertion(+) diff --git a/hooks/gl-pre-git b/hooks/gl-pre-git index 261160d..a66d5af 100755 --- a/hooks/gl-pre-git +++ b/hooks/gl-pre-git @@ -5,6 +5,7 @@ use warnings; use v5.10; use File::Basename; use Net::IP; +use utf8; use ACU::Log; $ACU::Log::log_file = "/var/log/hooks/" . basename($0) . ".log"; From a0f9002efd67727d373c2b6fbafe52bb5ecfd7f4 Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Thu, 28 Nov 2013 20:28:52 +0100 Subject: [PATCH 4/6] Guantanamo: use sh to parse command --- process/exec/guantanamo_node.pl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/process/exec/guantanamo_node.pl b/process/exec/guantanamo_node.pl index 0e0cdeb..0abac28 100644 --- a/process/exec/guantanamo_node.pl +++ b/process/exec/guantanamo_node.pl @@ -53,10 +53,18 @@ sub node_launch $command->appendText($c->{nodeValue}); $cmd->appendChild($command); - my($wtr, $rdr, $stderr); - my $pid = open3($wtr, $rdr, $stderr, $c->{nodeValue}); - waitpid( $pid, 0 ); - my $rv = $? >> 8; + my($wtr, $rdr, $rv); + my $stderr = ""; + eval { + my $pid = open3($wtr, $rdr, $stderr, "sh", "-c", $c->{nodeValue}); + waitpid( $pid, 0 ); + $rv = $? >> 8; + }; + if ($@) + { + $stderr = $@ . $stderr; + $rv = -1; + } my $out = $doc->createElement("out"); my $str = ""; From ad2748650b93f8e19e60de56302d1131ce81f071 Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Thu, 28 Nov 2013 20:32:49 +0100 Subject: [PATCH 5/6] Guantanamo: avoid deadlock by sending register action in background --- process/exec/guantanamo_node.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/process/exec/guantanamo_node.pl b/process/exec/guantanamo_node.pl index 0abac28..8f2f920 100644 --- a/process/exec/guantanamo_node.pl +++ b/process/exec/guantanamo_node.pl @@ -110,7 +110,7 @@ if ($#ARGV == 0) { log INFO, "Starting guantanamo.pl as node process"; - Process::Client::launch("guantanamo", {"action" => "register", "nodename" => $ARGV[0]}); + Process::Client::launch("guantanamo", {"action" => "register", "nodename" => $ARGV[0]}, undef, 1); Process::register("guantanamo_".$ARGV[0], \&process_node); } From 55bec752b5b40e6c4641b6bcfb2e15140c9f645e Mon Sep 17 00:00:00 2001 From: Mercier Pierre-Olivier Date: Fri, 29 Nov 2013 17:37:52 +0100 Subject: [PATCH 6/6] Really close account when strong-auth close --- utils/lpt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/utils/lpt b/utils/lpt index acc9162..8ce5293 100644 --- a/utils/lpt +++ b/utils/lpt @@ -200,7 +200,7 @@ sub cmd_account_alias($@) return cmd_account_multiple_vieworchange('mailAlias', 'alias', @_); } -sub cmd_account_close($@) +sub cmd_account_close($;@) { my $login = shift; @@ -1572,6 +1572,8 @@ sub cmd_no_strong_auth_close(@) say $entry->get_value("uid"); + cmd_account_close($entry->get_value("uid")); + my $body = "Bonjour ".decode('UTF-8', $entry->get_value("cn"), Encode::FB_CROAK).", Après plusieurs relances de notre part, vous n'avez toujours pas activé