diff options
author | Yorhel <git@yorhel.nl> | 2019-09-18 12:38:18 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2019-09-18 12:40:20 +0200 |
commit | 98c9d95e9b7a1e78f5cda93904c6624d57df4518 (patch) | |
tree | c54c17740bd0874a996d520323ebe2e7ed7ef029 /util | |
parent | cc2a1d72e499f7befe1b615a1322952dfb628fab (diff) |
v2rw: Convert authentication code to VNWeb::Auth
More churn!
Also converted v3 to use VNWeb::Auth, considering the API is pretty much
the same. Converted VNWeb::* to use VNDB::Config directly rather than
read from tuwf->{}, converted VNWeb::HTML to use VNWeb::Auth, and
updated util/vndb.pl with the new code style.
I tested as much as I could, but I'm sure I broke something.
Diffstat (limited to 'util')
-rwxr-xr-x | util/vndb.pl | 86 |
1 files changed, 33 insertions, 53 deletions
diff --git a/util/vndb.pl b/util/vndb.pl index 8ec102e5..d2b1a964 100755 --- a/util/vndb.pl +++ b/util/vndb.pl @@ -1,9 +1,9 @@ #!/usr/bin/perl -use strict; +use v5.24; use warnings; use Cwd 'abs_path'; -use TUWF ':html'; +use TUWF ':html_'; $|=1; # Disable buffering on STDOUT, otherwise vndb-dev-server.pl won't pick up our readyness notification. @@ -13,6 +13,7 @@ BEGIN { ($ROOT = abs_path $0) =~ s{/util/vndb\.pl$}{}; } use lib $ROOT.'/lib'; use SkinFile; use VNDB::Config; +use VNWeb::HTML (); # load the skins @@ -27,60 +28,39 @@ tuwf->{permissions} = {qw| board 1 boardmod 2 edit 4 tag 16 dbmod 32 tagmo tuwf->{default_perm} = 1+4+16; # Keep synchronised with the default value of users.perm tuwf->{$_} = config->{$_} for keys %{ config() }; -TUWF::set( - %{ config->{tuwf} }, - pre_request_handler => \&reqinit, - error_404_handler => \&handle404, - log_format => \&logformat, -); -TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler', 'VNWeb'); -TUWF::run(); - +TUWF::set %{ config->{tuwf} }; -sub reqinit { - my $self = shift; - # If we're running standalone, serve www/ and static/ too. - if($TUWF::OBJ->{_TUWF}{http}) { - if($self->resFile("$ROOT/www", $self->reqPath) || $self->resFile("$ROOT/static", $self->reqPath)) { - $self->resHeader('Cache-Control' => 'max-age=31536000'); - return 0; +TUWF::hook before => sub { + # If we're running standalone, serve www/ and static/ too. + if(tuwf->{_TUWF}{http}) { + if(tuwf->resFile("$ROOT/www", tuwf->reqPath) || tuwf->resFile("$ROOT/static", tuwf->reqPath)) { + tuwf->resHeader('Cache-Control' => 'max-age=31536000'); + tuwf->done; + } } - } - - # check authentication cookies - $self->authInit; - - # load some stats (used for about all pageviews, anyway) - $self->{stats} = $self->dbStats; - return 1; -} - - -sub handle404 { - my $self = shift; - $self->resStatus(404); - $self->htmlHeader(title => 'Page Not Found'); - div class => 'mainbox'; - h1 'Page not found'; - div class => 'warning'; - h2 'Oops!'; - p; - txt 'It seems the page you were looking for does not exist,'; - br; - txt 'you may want to try using the menu on your left to find what you are looking for.'; - end; - end; - end; - $self->htmlFooter; -} + # load some stats (used for about all pageviews, anyway) + tuwf->{stats} = tuwf->dbStats; +}; + + +TUWF::set error_404_handler => sub { + tuwf->resStatus(404); + VNWeb::HTML::framework_ title => 'Page Not Found', noindex => 1, sub { + div_ class => 'mainbox', sub { + h1_ 'Page not found'; + div_ class => 'warning', sub { + h2_ 'Oops!'; + p_; + txt_ 'It seems the page you were looking for does not exist,'; + br_; + txt_ 'you may want to try using the menu on your left to find what you are looking for.'; + } + } + } +}; -# log user IDs (necessary for determining performance issues, user preferences -# have a lot of influence in this) -sub logformat { - my($self, $uri, $msg) = @_; - sprintf "[%s] %s %s: %s\n", scalar localtime(), $uri, - $self->authInfo->{id} ? 'u'.$self->authInfo->{id} : '-', $msg; -} +TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler', 'VNWeb'); +TUWF::run(); |