#!/usr/bin/perl -wT use Email::Sender::Simple 'sendmail'; use Email::Simple; use Email::Simple::Creator; use File::Slurp qw/slurp/; $ENV{PATH} = ""; $ENV{HOME} = "/home/smash"; $ENV{'LANG'} = 'en_US.UTF-8'; $< = $>; use warnings; use strict; my @allowed = ('jno','jj','ambs','narcarvalho'); my $LOG; undef $/; my $text = <>; my $email = Email::Simple->new($text); my $subject = $email->header("Subject"); my $from_header = $email->header("From"); $LOG .= "From: $from_header\n"; exit 1 unless $from_header; my $ok = 0; foreach (@allowed) { $ok++ if $from_header =~ m/$_\@di\.uminho\.pt/; } exit 2 unless $ok; my $body = $email->body; while ($body =~ m/update\s+([\w\d\_]+)\s*(\-force)?/g) { my $id = $1; my $force = $2; my $dir = '/home/smash/playground/natura.svn.main/musica/Abc/Wiki-Score-Proto'; chdir $dir; $LOG .= `/usr/bin/id` . "\n"; $LOG .= `/bin/pwd` . "\n"; $LOG .= "/usr/bin/svn up:" . "\n"; $LOG .= `/usr/bin/svn up` . "\n"; $LOG .= "/bin/chmod 664 *.hs:" . "\n"; $LOG .= `/bin/chmod 664 *.hs` . "\n"; save_log(); exit 3 unless -e "$id.hs"; my $content = slurp "$id.hs"; $content =~ m/prj = initWSPproject\s+"([\w\d\-\_]+)"/s; my $json = $1; $LOG .= "/usr/bin/ghc $id -e main" . "\n"; $LOG .= `/usr/bin/ghc $id -e main` . "\n"; $LOG .= "/usr/bin/sudo /usr/local/bin/mabc_init_proj $force /home/natura/wiki-score $json.json $id.hs" . "\n"; $LOG .= `/usr/bin/sudo /usr/local/bin/mabc_init_proj $force /home/natura/wiki-score $json.json $id.hs` . "\n"; $LOG .= "/usr/bin/sudo /bin/chown www-data /home/natura/wiki-score/data/pages/$id/*.txt " . "\n"; $LOG .= `/usr/bin/sudo /bin/chown www-data /home/natura/wiki-score/data/pages/$id/*.txt ` . "\n"; $LOG .= "/usr/bin/sudo /bin/chown www-data /home/natura/wiki-score/data/media/$id/*.txt " . "\n"; $LOG .= `/usr/bin/sudo /bin/chown www-data /home/natura/wiki-score/data/media/$id/*.txt ` . "\n"; } my $message = Email::Simple->create( header => [ To => $from_header, From => 'noreply@natura.di.uminho.pt', Subject => "Re: $subject", ], body => <<"EOEMAIL"); Original body: $body Execution Log: $LOG EOEMAIL sendmail($message); save_log(); exit 0; sub save_log { open(my $fh, '>>', '/tmp/mabc_wsadmin.log'); print $fh $LOG; close($fh); }