diff options
Diffstat (limited to 'util/vndb.pl')
-rwxr-xr-x | util/vndb.pl | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/util/vndb.pl b/util/vndb.pl index 0fd6e08d..b6056dd4 100755 --- a/util/vndb.pl +++ b/util/vndb.pl @@ -12,11 +12,10 @@ our $ROOT; BEGIN { ($ROOT = abs_path $0) =~ s{/util/vndb\.pl$}{}; } -use lib $ROOT.'/yawf/lib'; use lib $ROOT.'/lib'; -use YAWF ':html'; +use TUWF ':html'; use VNDB::L10N; use SkinFile; @@ -42,13 +41,23 @@ require $ROOT.'/data/global.pl'; system "make -sC $ROOT" if $S{regen_static}; -YAWF::init( +$TUWF::OBJ->{$_} = $S{$_} for (keys %S); +TUWF::set( %O, - namespace => 'VNDB', - object_data => \%S, pre_request_handler => \&reqinit, error_404_handler => \&handle404, + log_format => \&logformat, + # for compatibility with YAWF + validate_templates => { + mail => { regex => qr/^[^@<>]+@[^@.<>]+(?:\.[^@.<>]+)+$/ }, + url => { regex => qr/^(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$/ }, + asciiprint => { regex => qr/^[\x20-\x7E]*$/ }, + int => { regex => qr/^-?\d+$/ }, + pname => { regex => qr/^[a-z0-9-]*$/ }, + }, ); +TUWF::load_recursive('VNDB::Util', 'VNDB::DB', 'VNDB::Handler'); +TUWF::run(); sub reqinit { @@ -85,20 +94,16 @@ sub reqinit { $rmcookie = 1 if $cookie && $cookie eq $browser; $handle = VNDB::L10N->get_handle($cookie) if $cookie && $browser ne $cookie; } - $self->resHeader('Set-Cookie', "l10n= ; expires=Sat, 01-Jan-2000 00:00:00 GMT; path=/; domain=$self->{cookie_domain}") - if $rmcookie; + $self->resCookie(l10n => undef) if $rmcookie; $self->{l10n} = $handle; # check for IE - if($self->reqHeader('User-Agent') && $self->reqHeader('User-Agent') =~ /MSIE [67]/ - && !$self->reqCookie('ie-sucks') && $self->reqPath ne 'we-dont-like-ie') { - # act as if we're opening /we-dont-like-ie6 (ugly hack, until YAWF supports preventing URL handlers from firing) - $ENV{HTTP_REFERER} = $ENV{REQUEST_URI}; - $ENV{REQUEST_URI} = '/we-dont-like-ie'; - } + return 0 if !$self->ieCheck; # load some stats (used for about all pageviews, anyway) $self->{stats} = $self->dbStats; + + return 1; } @@ -110,10 +115,22 @@ sub handle404 { h1 'Page not found'; div class => 'warning'; h2 'Oops!'; - p "It seems the page you were looking for does not exist,\n". - "you may want to try using the menu on your left to find what you are looking for."; + 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; } + +# 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; +} + |