mirror of https://github.com/CGAL/cgal
274 lines
5.6 KiB
Perl
Executable File
274 lines
5.6 KiB
Perl
Executable File
#!/sw/bin/perl -w
|
|
|
|
use strict;
|
|
|
|
my $treated_messages_log =
|
|
'/projects/CGAL/submissions/autohandle/data/treated_submit_messages';
|
|
my $install_submission_program =
|
|
'/projects/CGAL/admin_scripts/install_www_submission';
|
|
|
|
my $scripts_dir= '/projects/CGAL/admin_scripts';
|
|
my $receive_testresult_program =
|
|
'/users/geert/tmp/echo_to_log';
|
|
my $update_submissions_www_page_program = "$scripts_dir/create_packages_page";
|
|
my $receive_result_collection_program = "$scripts_dir/treat_result_collection";
|
|
my $MAIL_PROG="$scripts_dir/send_cgal_mail";
|
|
#my $MAIL_PROG='/usr/sbin/Mail';
|
|
|
|
my $Sender;
|
|
my $maintainer= 'geert@cs.uu.nl';
|
|
my $no_of_succesful_submissions = 0;
|
|
|
|
my @trusted_hosts = (
|
|
'cgal.org',
|
|
'cs.uu.nl',
|
|
'inria.fr',
|
|
'informatik.uni-halle.de',
|
|
'inf.ethz.ch',
|
|
'math.ethz.ch',
|
|
'mpi-sb.mpg.de',
|
|
'inf.fu-berlin.de',
|
|
'uni-trier.de',
|
|
'clipper.ens.fr',
|
|
'schtroumpf.ens.fr',
|
|
'eleves.ens.fr',
|
|
'cs.unc.edu',
|
|
'twi.tudelft.nl',
|
|
'tau.ac.il');
|
|
|
|
sub get_url()
|
|
{
|
|
my $html_address="";
|
|
while (<>) {
|
|
chomp;
|
|
if (/^\s*$/) {
|
|
return $html_address;
|
|
}
|
|
s/\s//g;
|
|
$html_address .= $_;
|
|
if ($html_address =~ /\.tar\.gz$/) {
|
|
return $html_address;
|
|
}
|
|
if ($html_address =~ /\.tgz$/) {
|
|
return $html_address;
|
|
}
|
|
if ($html_address =~ /\.zip$/) {
|
|
return $html_address;
|
|
}
|
|
}
|
|
return "";
|
|
}
|
|
|
|
sub is_trusted_url($)
|
|
{
|
|
my $URL = shift;
|
|
foreach (@trusted_hosts) {
|
|
if ($URL =~ m|^\s*http://[\.\w-]+\.$_[/:]|) {
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
sub is_trusted_sender($)
|
|
{
|
|
my $sender = shift;
|
|
foreach (@trusted_hosts) {
|
|
if ($sender =~ m|$_\s*$|) {
|
|
return 1;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
sub treat_submission($)
|
|
{
|
|
my ($URL,$option);
|
|
$option = shift;
|
|
$URL = get_url;
|
|
if ($URL eq "") {
|
|
# mail $Sender that something went wrong.
|
|
# do the same to maintainer.
|
|
open NOTICE, "|$MAIL_PROG \"CGAL autohandle failure!\" $Sender
|
|
$maintainer";
|
|
print NOTICE <<"TOTHIER";
|
|
Your submission (or one of your submissions) had an unrecognized URL.
|
|
The URL should be on a separate line, directly following the line
|
|
with the submission keyword, e.g as in:
|
|
|
|
submission::
|
|
http://www.mysite.mycountry/mypackage.zip
|
|
|
|
Please resend your request or send a message to cgal-submit asking for more
|
|
information.
|
|
|
|
TOTHIER
|
|
close NOTICE;
|
|
return;
|
|
}
|
|
if (! is_trusted_url($URL)) {
|
|
open NOTICE, "|$MAIL_PROG \"Untrusted URL!\" $maintainer";
|
|
print NOTICE <<"TOTHIER";
|
|
The submission by $Sender with URL
|
|
$URL
|
|
is not trusted and did not proceed.
|
|
Please take manual action.
|
|
|
|
TOTHIER
|
|
close NOTICE;
|
|
return;
|
|
}
|
|
if (system("$install_submission_program", "$URL") == 0)
|
|
{ ++$no_of_succesful_submissions; }
|
|
}
|
|
|
|
sub treat_result_collection()
|
|
{
|
|
my ($URL);
|
|
$URL = get_url;
|
|
if (!$URL) {
|
|
# mail $Sender that something went wrong.
|
|
# do the same to maintainer.
|
|
return;
|
|
}
|
|
if (! is_trusted_url($URL)) {
|
|
open NOTICE, "|$MAIL_PROG \"Untrusted URL!\" $maintainer";
|
|
print NOTICE <<"TOTHIER";
|
|
The Testresult with URL
|
|
$URL
|
|
is not trusted and did not proceed.
|
|
Please take manual action.
|
|
|
|
TOTHIER
|
|
close NOTICE;
|
|
return;
|
|
}
|
|
system("$receive_result_collection_program", $URL);
|
|
}
|
|
|
|
sub treat_testresult($)
|
|
{
|
|
my ($URL,$release);
|
|
$release = shift;
|
|
$URL = get_url;
|
|
if (!$URL) {
|
|
# mail $Sender that something went wrong.
|
|
# do the same to maintainer.
|
|
return;
|
|
}
|
|
if (! is_trusted_url($URL)) {
|
|
open NOTICE, "|$MAIL_PROG \"Untrusted URL!\" $maintainer";
|
|
print NOTICE <<"TOTHIER";
|
|
The Testresult with URL
|
|
$URL
|
|
is not trusted and did not proceed.
|
|
Please take manual action.
|
|
|
|
TOTHIER
|
|
close NOTICE;
|
|
return;
|
|
}
|
|
system("$receive_testresult_program", "$release", "$Sender", "$URL");
|
|
}
|
|
|
|
sub message_processed($)
|
|
{
|
|
my $message_id = shift;
|
|
open(TREATED_MESSAGES, "<$treated_messages_log");
|
|
while (<TREATED_MESSAGES>) {
|
|
chomp;
|
|
if ($message_id eq $_) {
|
|
close TREATED_MESSAGES;
|
|
return 1;
|
|
}
|
|
}
|
|
close TREATED_MESSAGES;
|
|
open(TREATED_MESSAGES, ">>$treated_messages_log");
|
|
print TREATED_MESSAGES "$message_id\n";
|
|
close TREATED_MESSAGES;
|
|
return 0;
|
|
}
|
|
|
|
sub main()
|
|
{
|
|
my ($from);
|
|
my $command_found = 0;
|
|
$_ = <>;
|
|
chomp;
|
|
($from, $Sender) = split;
|
|
if ($from ne "From") {
|
|
exit 1;
|
|
}
|
|
|
|
$Sender =~ s/\s*//g;
|
|
|
|
if ( $Sender eq 'daemon@cs.uu.nl') {
|
|
while(<>) {
|
|
if (/^\s*Sender\s*:\s*(.+)$/) {
|
|
$Sender = $1;
|
|
last;
|
|
}
|
|
}
|
|
}
|
|
if (!is_trusted_sender($Sender)) {
|
|
open NOTICE, "|$MAIL_PROG \"Untrusted sender!\" $maintainer";
|
|
print NOTICE <<"TOTHIER";
|
|
The submission with sender
|
|
$Sender
|
|
is not trusted and did not proceed.
|
|
-------------- start of message --------------
|
|
TOTHIER
|
|
while(<>) {
|
|
print NOTICE $_;
|
|
}
|
|
print NOTICE "-------------- end of message --------------\n";
|
|
close NOTICE;
|
|
exit 0;
|
|
}
|
|
|
|
while(<>) {
|
|
if (/^\s*message-id\s*:\s*(.*?)\s*$/i) {
|
|
last if message_processed($1);
|
|
}
|
|
elsif (/^\s*submission\s*:\s*([^:]*?)\s*:\s*$/) {
|
|
$command_found = 1;
|
|
treat_submission($1);
|
|
}
|
|
elsif (/^\s*result[\s_-]?collection\s*:\s*:\s*$/){
|
|
$command_found = 1;
|
|
treat_result_collection();
|
|
}
|
|
elsif (/^\s*testresult\s*:\s*([^:]*?)\s*:\s*$/){
|
|
$command_found = 1;
|
|
treat_testresult($1);
|
|
} else {
|
|
}
|
|
}
|
|
if ($no_of_succesful_submissions > 0) {
|
|
system($update_submissions_www_page_program);
|
|
}
|
|
if (!$command_found) {
|
|
open NOTICE, "|$MAIL_PROG \"CGAL autohandle warning\" $Sender";
|
|
print NOTICE <<"TOTHIER";
|
|
Your submission did not contain any command.
|
|
A command is e.g.
|
|
|
|
submission::
|
|
|
|
Note the two colons (and note that it is on a separate line).
|
|
|
|
TOTHIER
|
|
close NOTICE;
|
|
}
|
|
}
|
|
|
|
# don't break off processing of a message
|
|
|
|
$SIG{INT}='IGNORE';
|
|
$SIG{QUIT} = 'IGNORE';
|
|
$SIG{TERM} = 'IGNORE';
|
|
|
|
main;
|
|
exit 0;
|
|
|