GIT THIS
BIN
asset/0.png
Normal file
After Width: | Height: | Size: 124 KiB |
BIN
asset/1.png
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
asset/2.png
Normal file
After Width: | Height: | Size: 125 KiB |
BIN
asset/3.png
Normal file
After Width: | Height: | Size: 123 KiB |
BIN
asset/4.png
Normal file
After Width: | Height: | Size: 122 KiB |
BIN
asset/5.png
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
asset/6.png
Normal file
After Width: | Height: | Size: 122 KiB |
BIN
asset/7.png
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
asset/8.png
Normal file
After Width: | Height: | Size: 124 KiB |
BIN
asset/9.png
Normal file
After Width: | Height: | Size: 122 KiB |
1
counter.numb
Normal file
|
@ -0,0 +1 @@
|
|||
0
|
73
myapp.pl
Executable file
|
@ -0,0 +1,73 @@
|
|||
#!/usr/bin/env perl
|
||||
use Mojolicious::Lite -signatures;
|
||||
|
||||
my $counter_file = 'counter.numb';
|
||||
my $counter = 0;
|
||||
my $number_length = 6;
|
||||
|
||||
app->hook(before_server_start => sub ($server, $app) {
|
||||
if (! (-e $counter_file)) {
|
||||
open my $fh, '>', $counter_file;
|
||||
syswrite $fh, $counter, length $counter, 0;
|
||||
close $fh;
|
||||
}
|
||||
open my $fh, '<', $counter_file;
|
||||
sysread $fh, $counter, 20; # 20 bytes to read which is more than enough for a counter
|
||||
close $fh;
|
||||
|
||||
-e '/bin/montage' or die 'ImageMagick not installed? `/bin/montage`';
|
||||
});
|
||||
|
||||
get '/' => sub ($c) {
|
||||
make_image(to_number_length($counter++));
|
||||
$c->res->headers->header('Content-Security-Policy' => 'img-src * artemis.venus.place');
|
||||
$c->res->headers->header('Server' => 'nginx/1.22.1'); # lie :)
|
||||
$c->reply->file('tmp/counter.png');
|
||||
open my $fh, '>', $counter_file;
|
||||
syswrite $fh, $counter, length $counter, 0;
|
||||
close $fh;
|
||||
};
|
||||
|
||||
sub to_number_length ($counter) {
|
||||
while (length $counter lt 6) {
|
||||
$counter = "0$counter";
|
||||
}
|
||||
return $counter;
|
||||
}
|
||||
|
||||
## returns path for image
|
||||
sub make_image ($counter) {
|
||||
|
||||
my @args;
|
||||
for my $i (split(//, $counter)) {
|
||||
push @args, "asset/$i.png";
|
||||
}
|
||||
push @args, qw( -tile 6x1 -geometry +0+0 -background none -scale 50 );
|
||||
my $o = 'tmp/counter.png';
|
||||
push @args, $o;
|
||||
|
||||
if (! (-w 'tmp/' and -d 'tmp/')) {
|
||||
mkdir 'tmp';
|
||||
}
|
||||
|
||||
# user can refresh the page faster than this can run
|
||||
# I guess in theory someone can DOS me just by refreshing the page enough times
|
||||
system('/bin/montage', @args);
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
app->start;
|
||||
__DATA__
|
||||
|
||||
@@ index.html.ep
|
||||
% layout 'default';
|
||||
% title 'Welcome';
|
||||
<h1>Welcome to the Mojolicious real-time web framework!</h1>
|
||||
|
||||
@@ layouts/default.html.ep
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head><title><%= title %></title></head>
|
||||
<body><%= content %></body>
|
||||
</html>
|