summaryrefslogtreecommitdiff
path: root/lib/VNWeb
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2021-01-04 14:01:05 +0100
committerYorhel <git@yorhel.nl>2021-01-04 14:01:07 +0100
commit3fc190f1898342d63b1308a83152fe45a88f7c3f (patch)
treef1b14a2ea0ab4b8bb6013a0e75dfa146ba5dd004 /lib/VNWeb
parentf78f37e369567c91896aeeb505e706df4b4c12ff (diff)
v2rw: Some cleanup; Move some functionality out of vndb.pl; Move config out of tuwf->{..}
Config had been in a separate config->{..} object for a while now, old code doesn't need it anymore so we can finally get rid of the tuwf->{..} compact. vndb.pl is not really the place for library code, so moved that around. The old imgpath() and imgurl() functions weren't used anymore, so could be safely replaced with the new functions that take the new vndbid format. (All this to make it easier to write separate scripts that call into VNDB::/VNWeb:: code as a library)
Diffstat (limited to 'lib/VNWeb')
-rw-r--r--lib/VNWeb/Chars/Page.pm2
-rw-r--r--lib/VNWeb/Elm.pm3
-rw-r--r--lib/VNWeb/HTML.pm2
-rw-r--r--lib/VNWeb/Images/Lib.pm2
-rw-r--r--lib/VNWeb/Images/List.pm2
-rw-r--r--lib/VNWeb/Images/Upload.pm10
-rw-r--r--lib/VNWeb/Misc/HomePage.pm4
-rw-r--r--lib/VNWeb/Prelude.pm4
-rw-r--r--lib/VNWeb/VN/Page.pm12
-rw-r--r--lib/VNWeb/Validation.pm7
10 files changed, 27 insertions, 21 deletions
diff --git a/lib/VNWeb/Chars/Page.pm b/lib/VNWeb/Chars/Page.pm
index af1fd8c6..8ea7f316 100644
--- a/lib/VNWeb/Chars/Page.pm
+++ b/lib/VNWeb/Chars/Page.pm
@@ -252,7 +252,7 @@ TUWF::get qr{/$RE{crev}} => sub {
framework_ title => $c->{name}, index => !tuwf->capture('rev'), type => 'c', dbobj => $c, hiddenmsg => 1,
og => {
description => bb_format($c->{desc}, text => 1),
- image => $c->{image} && $c->{image}{votecount} && !$c->{image}{sexual} && !$c->{image}{violence} ? tuwf->imgurl($c->{image}{id}) : undef,
+ image => $c->{image} && $c->{image}{votecount} && !$c->{image}{sexual} && !$c->{image}{violence} ? imgurl($c->{image}{id}) : undef,
},
sub {
_rev_ $c if tuwf->capture('rev');
diff --git a/lib/VNWeb/Elm.pm b/lib/VNWeb/Elm.pm
index 96ccc583..698a7ae8 100644
--- a/lib/VNWeb/Elm.pm
+++ b/lib/VNWeb/Elm.pm
@@ -18,6 +18,7 @@ use VNDB::Config;
use VNDB::Types;
use VNDB::Func 'fmtrating';
use VNDB::ExtLinks ();
+use VNWeb::Validation;
use VNWeb::Auth;
our @EXPORT = qw/
@@ -316,7 +317,7 @@ sub elm_api {
$in = comp $in;
TUWF::post qr{/elm/\Q$name\E\.json} => sub {
- if(!tuwf->samesite && !auth->csrfcheck(tuwf->reqHeader('X-CSRF-Token')||'')) {
+ if(!samesite && !auth->csrfcheck(tuwf->reqHeader('X-CSRF-Token')||'')) {
warn "Invalid CSRF token in request\n";
return elm_CSRF();
}
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 005e0cc9..611d02bb 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -177,7 +177,7 @@ sub _head_ {
if($o->{og}) {
$o->{og}{site_name} ||= 'The Visual Novel Database';
$o->{og}{type} ||= 'object';
- $o->{og}{image} ||= 'https://s.vndb.org/s/angel/bg.jpg'; # TODO: Something better
+ $o->{og}{image} ||= config->{placeholder_img};
$o->{og}{url} ||= tuwf->reqURI;
$o->{og}{title} ||= $o->{title};
meta_ property => "og:$_", content => ($o->{og}{$_} =~ s/\n/ /gr) for sort keys $o->{og}->%*;
diff --git a/lib/VNWeb/Images/Lib.pm b/lib/VNWeb/Images/Lib.pm
index adf9186a..2ca098a9 100644
--- a/lib/VNWeb/Images/Lib.pm
+++ b/lib/VNWeb/Images/Lib.pm
@@ -92,7 +92,7 @@ sub image_ {
label_ class => 'imghover', style => "width: $img->{width}px; height: $img->{height}px", sub {
input_ type => 'checkbox', class => 'visuallyhidden', $hidden ? () : (checked => 'checked') if $hide_on_click;
div_ class => 'imghover--visible', sub {
- img_ src => tuwf->imgurl($img->{id}), $opt{alt} ? (alt => $opt{alt}) : ();
+ img_ src => imgurl($img->{id}), $opt{alt} ? (alt => $opt{alt}) : ();
a_ class => 'imghover--overlay', href => "/img/$img->{id}?view=".viewset(show_nsfw=>1), image_flagging_display $img;
};
div_ class => 'imghover--warning', sub {
diff --git a/lib/VNWeb/Images/List.pm b/lib/VNWeb/Images/List.pm
index ca11a5ab..69925f99 100644
--- a/lib/VNWeb/Images/List.pm
+++ b/lib/VNWeb/Images/List.pm
@@ -50,7 +50,7 @@ sub listing_ {
paginate_ $url, $opt->{p}, $np, 't';
div_ class => 'mainbox imagebrowse', sub {
div_ class => 'imagecard', sub {
- a_ href => "/img/$_->{id}?view=$view", style => 'background-image: url('.tuwf->imgurl($_->{id}, 1).')', '';
+ a_ href => "/img/$_->{id}?view=$view", style => 'background-image: url('.imgurl($_->{id}, 1).')', '';
div_ sub {
a_ href => "/img/$_->{id}?view=$view", $_->{id};
txt_ sprintf ' / %d', $_->{c_votecount},;
diff --git a/lib/VNWeb/Images/Upload.pm b/lib/VNWeb/Images/Upload.pm
index b8625294..ce2c2ae5 100644
--- a/lib/VNWeb/Images/Upload.pm
+++ b/lib/VNWeb/Images/Upload.pm
@@ -23,8 +23,8 @@ TUWF::post qr{/elm/ImageUpload.json}, sub {
height => 0
}, 'RETURNING id');
- my $fn0 = tuwf->imgpath($id, 0);
- my $fn1 = tuwf->imgpath($id, 1);
+ my $fn0 = imgpath($id, 0);
+ my $fn1 = imgpath($id, 1);
my $fntmp = "$fn0-tmp.jpg";
sub resize { (-resize => "$_[0][0]x$_[0][1]>", -print => 'r:%wx%h') }
@@ -34,9 +34,9 @@ TUWF::post qr{/elm/ImageUpload.json}, sub {
'-strip', -define => 'filter:Lagrange',
-background => '#fff', -alpha => 'Remove',
-quality => 90, -print => 'o:%wx%h',
- $type eq 'ch' ? (resize(tuwf->{ch_size}), -write => $fn0, @unsharp, $fntmp) :
- $type eq 'cv' ? (resize(tuwf->{cv_size}), -write => $fn0, @unsharp, $fntmp) :
- $type eq 'sf' ? (-write => $fn0, resize(tuwf->{scr_size}), @unsharp, $fn1) : die
+ $type eq 'ch' ? (resize(config->{ch_size}), -write => $fn0, @unsharp, $fntmp) :
+ $type eq 'cv' ? (resize(config->{cv_size}), -write => $fn0, @unsharp, $fntmp) :
+ $type eq 'sf' ? (-write => $fn0, resize(config->{scr_size}), @unsharp, $fn1) : die
);
run_cmd(\@cmd, '<', \$imgdata, '>', \my $out, '2>', \my $err)->recv;
diff --git a/lib/VNWeb/Misc/HomePage.pm b/lib/VNWeb/Misc/HomePage.pm
index 044303bb..d1ad1c31 100644
--- a/lib/VNWeb/Misc/HomePage.pm
+++ b/lib/VNWeb/Misc/HomePage.pm
@@ -33,8 +33,8 @@ sub screens_ {
p_ class => 'screenshots', sub {
a_ href => "/v$_->{vid}", title => $_->{title}, sub {
- my($w, $h) = imgsize $_->{width}, $_->{height}, tuwf->{scr_size}->@*;
- img_ src => tuwf->imgurl($_->{id}, 1), alt => $_->{title}, width => $w, height => $h;
+ my($w, $h) = imgsize $_->{width}, $_->{height}, config->{scr_size}->@*;
+ img_ src => imgurl($_->{id}, 1), alt => $_->{title}, width => $w, height => $h;
} for @$lst;
}
}
diff --git a/lib/VNWeb/Prelude.pm b/lib/VNWeb/Prelude.pm
index 198d09e2..f00c009b 100644
--- a/lib/VNWeb/Prelude.pm
+++ b/lib/VNWeb/Prelude.pm
@@ -14,7 +14,7 @@
# use VNDB::BBCode;
# use VNDB::Types;
# use VNDB::Config;
-# use VNDB::Func qw/fmtdate fmtage fmtvote fmtspoil fmtmedia minage resolution query_encode lang_attr md2html/;
+# use VNDB::Func qw/fmtdate fmtage fmtvote fmtspoil fmtmedia minage resolution query_encode lang_attr md2html imgurl imgpath/;
# use VNDB::ExtLinks;
# use VNWeb::Auth;
# use VNWeb::HTML;
@@ -59,7 +59,7 @@ sub import {
use VNDB::BBCode;
use VNDB::Types;
use VNDB::Config;
- use VNDB::Func qw/fmtdate fmtage fmtvote fmtspoil fmtmedia minage resolution query_encode lang_attr md2html/;
+ use VNDB::Func qw/fmtdate fmtage fmtvote fmtspoil fmtmedia minage resolution query_encode lang_attr md2html imgurl imgpath/;
use VNDB::ExtLinks;
use VNWeb::Auth;
use VNWeb::HTML;
diff --git a/lib/VNWeb/VN/Page.pm b/lib/VNWeb/VN/Page.pm
index a5d57183..f2f0fc8d 100644
--- a/lib/VNWeb/VN/Page.pm
+++ b/lib/VNWeb/VN/Page.pm
@@ -67,8 +67,8 @@ sub og {
my($v) = @_;
+{
description => bb_format($v->{desc}, text => 1),
- image => $v->{image} && !$v->{image}{sexual} && !$v->{image}{violence} ? tuwf->imgurl($v->{image}{id}) :
- [map $_->{scr}{sexual}||$_->{scr}{violence}?():(tuwf->imgurl($_->{scr}{id})), $v->{screenshots}->@*]->[0]
+ image => $v->{image} && !$v->{image}{sexual} && !$v->{image}{violence} ? imgurl($v->{image}{id}) :
+ [map $_->{scr}{sexual}||$_->{scr}{violence}?():(imgurl($_->{scr}{id})), $v->{screenshots}->@*]->[0]
}
}
@@ -112,7 +112,7 @@ sub rev_ {
a_ href => "/r$_->{rid}", "r$_->{rid}" if $_->{rid};
txt_ 'no release' if !$_->{rid};
txt_ '] ';
- a_ href => tuwf->imgurl($_->{scr}{id}), 'data-iv' => "$_->{scr}{width}x$_->{scr}{height}::$_->{scr}{sexual}$_->{scr}{violence}$_->{scr}{votecount}", $_->{scr}{id};
+ a_ href => imgurl($_->{scr}{id}), 'data-iv' => "$_->{scr}{width}x$_->{scr}{height}::$_->{scr}{sexual}$_->{scr}{violence}$_->{scr}{votecount}", $_->{scr}{id};
txt_ ' [';
a_ href => "/img/$_->{scr}{id}", image_flagging_display $_->{scr};
txt_ '] ';
@@ -689,7 +689,7 @@ sub screenshots_ {
a_ href => "/r$r->{id}", $r->{title};
};
div_ class => 'scr', sub {
- a_ href => tuwf->imgurl($_->{scr}{id}),
+ a_ href => imgurl($_->{scr}{id}),
'data-iv' => "$_->{scr}{width}x$_->{scr}{height}:scr:$_->{scr}{sexual}$_->{scr}{violence}$_->{scr}{votecount}",
mkclass(
scrlnk => 1,
@@ -700,8 +700,8 @@ sub screenshots_ {
nsfw => $_->{scr}{sexual} || $_->{scr}{violence},
),
sub {
- my($w, $h) = imgsize $_->{scr}{width}, $_->{scr}{height}, tuwf->{scr_size}->@*;
- img_ src => tuwf->imgurl($_->{scr}{id}, 1), width => $w, height => $h, alt => "Screenshot $_->{scr}{id}";
+ my($w, $h) = imgsize $_->{scr}{width}, $_->{scr}{height}, config->{scr_size}->@*;
+ img_ src => imgurl($_->{scr}{id}, 1), width => $w, height => $h, alt => "Screenshot $_->{scr}{id}";
} for $rel{$r->{id}}->@*;
}
}
diff --git a/lib/VNWeb/Validation.pm b/lib/VNWeb/Validation.pm
index e64f80ff..5836d001 100644
--- a/lib/VNWeb/Validation.pm
+++ b/lib/VNWeb/Validation.pm
@@ -13,6 +13,7 @@ use Carp 'croak';
use Exporter 'import';
our @EXPORT = qw/
+ samesite
is_insecurepass
form_compile
form_changed
@@ -91,6 +92,10 @@ sub _validate_fuzzyrdate {
}
+# returns true if this request originated from the same site, i.e. not an external referer.
+sub samesite { !!tuwf->reqCookie('samesite') }
+
+
sub is_insecurepass {
config->{password_db} && PWLookup::lookup(config->{password_db}, shift)
}
@@ -270,7 +275,7 @@ sub viewget {
my($view, $token) = tuwf->reqGet('view') =~ /^([^-]*)-(.+)$/;
# Abort this request and redirect if the token is invalid.
- if(length($view) && (!tuwf->samesite || !length($token) || !auth->csrfcheck($token, 'view'))) {
+ if(length($view) && (!samesite || !length($token) || !auth->csrfcheck($token, 'view'))) {
my $qs = join '&', map { my $k=$_; my @l=tuwf->reqGets($k); map uri_escape($k).'='.uri_escape($_), @l } grep $_ ne 'view', tuwf->reqGets();
tuwf->resInit;
tuwf->resRedirect(tuwf->reqPath().($qs?"?$qs":''), 'temp');