]> iEval git - gruntmaster-page.git/blame - app.psgi
Add mindcoding logos and default theme
[gruntmaster-page.git] / app.psgi
CommitLineData
7dc32473
MG
1#!/usr/bin/perl -w
2use v5.14;
3
c85bf4a6 4use Apache2::Authen::Passphrase qw/pwcheck/;
5a879d9a
MG
5use Apache2::AuthzCaps qw/hascaps/;
6use Gruntmaster::Data;
7dc32473 7use Plack::App::Gruntmaster;
c85bf4a6
MG
8use Plack::Builder;
9use Plack::Request;
10
5a879d9a
MG
11$Apache2::AuthzCaps::rootdir = $Apache2::Authen::Passphrase::rootdir;
12my $word = qr,(\w+),a;
13
14sub debug {
15 local $Log::Log4perl::caller_depth = $Log::Log4perl::caller_depth + 1;
16 $_[0]->{'psgix.logger'}->({qw/level debug message/ => $_[1]})
17}
18
c85bf4a6
MG
19sub some_auth_required {
20 my $r = Plack::Request->new($_[0]);
5a879d9a
MG
21 return 1 if $_[0]->{'gruntmaster.reqadmin'} || $r->path eq '/action/passwd' || $r->path =~ m,/pb/$word/submit$,;
22 0
23}
24
25sub admin_required {
26 local $_ = $_[0];
27 return 1 if m,^/pb/$word, && problem_private $1;
28 return 1 if m,^/log/(?:job|src)/$word, && job_private $1;
29 return 1 if m,^/ct/$word/(?:pb|log), && time < contest_start $1;
30 return 1 if m,^/ct/$word/log/src, && time < contest_end $1;
c85bf4a6
MG
31 0
32}
7dc32473 33
5a879d9a
MG
34sub require_admin {
35 my $app = $_[0];
36 sub {
37 *__ANON__ = "require_admin_middleware";
38 my $env = $_[0];
39 my $r = Plack::Request->new($env);
40 $env->{'gruntmaster.reqadmin'} = 1 if admin_required $r->path;
41 $app->($env)
42 }
43}
44
45sub authenticate {
46 my ($user, $pass, $env) = @_;
47 return unless eval {
48 pwcheck $user, $pass;
49 1
50 };
51
52 return if $env->{'gruntmaster.reqadmin'} && !hascaps $user, 'gmadm';
53 1
54}
55
7dc32473 56builder {
287424cb 57 enable 'ContentLength';
c85bf4a6 58 enable 'Static', path => qr,/static/,;
7dc32473 59 enable 'Log4perl', category => 'plack', conf => 'log.conf';
5a879d9a
MG
60 enable \&require_admin;
61 enable_if \&some_auth_required, 'Auth::Basic', authenticator => \&authenticate, realm => 'Gruntmaster 6000';
7dc32473
MG
62 Plack::App::Gruntmaster->to_app
63}
This page took 0.026813 seconds and 4 git commands to generate.