1 package Gruntmaster
::Handlers
;
6 our $VERSION = '0.001';
8 use constant FORMAT_EXTENSION
=> {
13 use Apache2
::AuthzCaps qw
/hascaps/;
14 use Apache2
::RequestRec
;
15 use Apache2
::RequestIO
;
17 use Apache2
::Const qw
/OK DECLINED/;
22 use File
::Basename qw
/fileparse/;
23 use File
::Temp qw
/tempdir/;
24 use File
::Copy qw
/move/;
25 use YAML
::Any qw
/LoadFile DumpFile/;
29 chdir $r->dir_config('root');
30 my $req = Apache2
::Request
->new($r);
31 my ($problem, $format, $contest) = map {scalar $req->param($_)} 'problem', 'prog_format', 'contest';
32 my $ext = FORMAT_EXTENSION
->{$format};
33 my $prog = $req->upload('prog');
34 die if defined $contest && $contest !~ /^\w+$/;
36 if (defined $contest) {
37 my $meta = LoadFile
"ct/$contest/meta.yml";
38 die unless time >= $meta->{start
} && time <= $meta->{end
}
42 $prog->link("$dir/prog.$ext");
43 DumpFile
"$dir/meta.yml", {
53 defined $contest ?
(contest
=> $contest) : (),
56 my $jobname = int rand 1_000_000_000
;
57 $jobname = int rand 1_000_000_000
while -d
"jobs/$jobname";
58 move
$dir, "jobs/$jobname" or die $!;
60 $r->print("Job submitted");
66 my $dir = (fileparse
$r->uri)[1];
68 chdir $r->dir_config('root') . $dir;
70 for my $requirement (map { $_->{requirement
} } @
{$r->requires}) {
71 my ($command, @args) = split ' ', $requirement;
74 when('admin-if-private'){
75 my $meta = LoadFile
'meta.yml';
76 return OK
if !$meta->{private
} || ($r->user && hascaps
$r->user, 'gmadm')
87 # Below is stub documentation for your module. You'd better edit it!
91 Gruntmaster::Handlers - Perl extension for blah blah blah
95 use Gruntmaster::Handlers;
100 Stub documentation for Gruntmaster::Handlers, created by h2xs. It looks like the
101 author of the extension was negligent enough to leave the stub
109 Mention other useful documentation such as the documentation of
110 related modules or operating system documentation (such as man pages
111 in UNIX), or any relevant external documentation such as RFCs or
114 If you have a mailing list set up for your module, mention it here.
116 If you have a web site set up for your module, mention it here.
120 Marius Gavrilescu, E<lt>marius@E<gt>
122 =head1 COPYRIGHT AND LICENSE
124 Copyright (C) 2013 by Marius Gavrilescu
126 This library is free software; you can redistribute it and/or modify
127 it under the same terms as Perl itself, either Perl version 5.18.1 or,
128 at your option, any later version of Perl 5 you may have available.