]>
Commit | Line | Data |
---|---|---|
c492afe8 | 1 | #!/usr/bin/perl |
7dc32473 | 2 | use v5.14; |
c492afe8 | 3 | use warnings; |
7dc32473 | 4 | |
5a879d9a | 5 | use Gruntmaster::Data; |
7dc32473 | 6 | use Plack::App::Gruntmaster; |
c85bf4a6 | 7 | use Plack::Builder; |
3b69df7a | 8 | use Plack::Util; |
68d5c3ff MG |
9 | use Log::Log4perl; |
10 | ||
031ffaf5 MG |
11 | sub CONTENT_SECURITY_POLICY () { |
12 | my $csp = <<CSP; | |
13 | default-src 'none' | |
14 | connect-src 'self' | |
15 | form-action 'self' | |
16 | frame-ancestors 'none' | |
bd623b0d | 17 | img-src 'self' https://static.mindcoding.ro |
031ffaf5 | 18 | referrer origin-when-cross-origin |
0f623f3d MG |
19 | script-src 'self' |
20 | style-src 'self' | |
031ffaf5 MG |
21 | CSP |
22 | chomp $csp; | |
23 | $csp =~ s/\n/; /gr; | |
24 | } | |
c85bf4a6 | 25 | |
be1da3f9 | 26 | my $db; |
5a879d9a | 27 | |
be1da3f9 MG |
28 | sub add_database { |
29 | my $app = $_[0]; | |
30 | sub { | |
31 | my ($env) = @_; | |
32 | $db //= Gruntmaster::Data->connect($ENV{GRUNTMASTER_DSN} // 'dbi:Pg:'); | |
33 | $env->{'gruntmaster.dbic'} = $db; | |
34 | $app->($env) | |
35 | } | |
36 | } | |
37 | ||
3b69df7a MG |
38 | sub add_headers { |
39 | my $app = $_[0]; | |
40 | sub { | |
41 | my $resp = $app->($_[0]); | |
42 | my $hdrs = Plack::Util::headers($resp->[1]); | |
43 | $hdrs->set('Content-Security-Policy', CONTENT_SECURITY_POLICY); | |
3b69df7a MG |
44 | $resp->[1] = $hdrs->headers; |
45 | $resp; | |
46 | } | |
47 | } | |
48 | ||
28b3c465 | 49 | Log::Log4perl->init_once('log.conf'); |
58a0ba09 | 50 | $ENV{DBIC_NULLABLE_KEY_NOWARN} = 1; |
68d5c3ff | 51 | |
7dc32473 | 52 | builder { |
28aeef34 | 53 | enable_if { $_[0]->{PATH_INFO} eq '/ok' } sub { sub{ [200, [], []] }}; |
287424cb | 54 | enable 'ContentLength'; |
3b69df7a | 55 | enable \&add_headers; |
68d5c3ff | 56 | enable 'Log4perl', category => 'plack'; |
be1da3f9 | 57 | enable \&add_database; |
8d725691 MG |
58 | enable '+Plack::App::Gruntmaster::Auth', |
59 | dbi_connect => [$ENV{GRUNTMASTER_DSN} // 'dbi:Pg:', '', ''], | |
60 | realm => 'Gruntmaster 6000', | |
61 | mail_from => $ENV{GRUNTMASTER_RESET_FROM}; | |
594d53ba | 62 | Plack::App::Gruntmaster->run_if_script |
7dc32473 | 63 | } |