From 28f919d8d75d04d2e1944b654c752d9a09a627bb Mon Sep 17 00:00:00 2001 From: Rawley Fowler Date: Tue, 11 Jul 2023 11:40:06 -0600 Subject: [PATCH] fix --- .gitignore | 1 + site.pl | 12 ++++++++---- upload.pl | 0 3 files changed, 9 insertions(+), 4 deletions(-) mode change 100644 => 100755 upload.pl diff --git a/.gitignore b/.gitignore index f639b70..ab5c099 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ posts/*.post bookshelf.txt site.db* less/cache/ +*.secret \ No newline at end of file diff --git a/site.pl b/site.pl index 7aaf866..e6e4434 100644 --- a/site.pl +++ b/site.pl @@ -3,10 +3,14 @@ use 5.016; use Mojolicious::Lite -signatures; use Mojo::SQLite; +use Mojo::File; use Carp qw(croak); -croak qq{No AUTH_HEADER value in environment.} unless exists $ENV{AUTH_HEADER}; -croak qq{No AUTH_KEY value in environment.} unless exists $ENV{AUTH_KEY}; +my $AUTH_HEADER = [ split( /,/, Mojo::File->new('.secret')->slurp ) ]->[0]; +my $AUTH_KEY = [ split( /,/, Mojo::File->new('.secret')->slurp ) ]->[1]; + +croak qq{No AUTH_HEADER value in .secret} unless $AUTH_HEADER; +croak qq{No AUTH_KEY value in .secret} unless $AUTH_KEY; my $sql = Mojo::SQLite->new('sqlite:site.db'); helper db => sub { state $db = $sql->db }; @@ -58,8 +62,8 @@ get '/blog/:post' => sub { post '/blog' => sub { my $c = shift; - my $auth = $c->req->headers->to_hash->{ $ENV{AUTH_HEADER} }; - return $c->rendered(400) unless $auth and ( $auth eq $ENV{AUTH_KEY} ); + my $auth = $c->req->headers->to_hash->{$AUTH_HEADER}; + return $c->rendered(400) unless $auth and ( $auth eq $AUTH_KEY ); if ( my $old_post = $c->db->select( 'posts', ['id'], { slug => $c->req->json->{slug} } ) diff --git a/upload.pl b/upload.pl old mode 100644 new mode 100755