Telefonní systém kosmické lodi Hipporion ze SKSP2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
1.3 KiB

5 years ago
my $app = sub {
my ($env) = @_;
my $path = $env->{PATH_INFO};
my $meth = $env->{REQUEST_METHOD};
if ($path =~ m|^/hraj/?$| && $meth eq "GET") {
my $r = '<html><body>';
$r .= qq[<div><form action="/hraj/stop" method="POST"><button style="font-size: 28px;" type="submit">Zastavit vše</button></form></div>];
opendir my $dir, "/opt/ksp/znelky" or die "Cannot open directory: $!";
for (readdir $dir) {
next if /^\./;
$r .= qq[<div><form action="/hraj/play/$_" method="POST" onsubmit="return confirm('Přehrát $_?')"><button style="font-size: 28px;" type="submit">$_</button></form></div>];
}
closedir $dir;
$r .= '</body></html>';
return [200, ['Content-Type' => 'text/html; charset=UTF-8'], [$r]];
} elsif ($path =~ m|^/hraj/play/(.*)$| && $meth eq "POST") {
system "/opt/ksp/ann_play.sh", "/opt/ksp/znelky/$1";
my $r = '<html><body style="font-size: large; ">';
$r .= qq[Přehrávám $1<br/><a href="/hraj">Zpět</a>];
$r .= '</body></html>';
return [200, ['Content-Type' => 'text/html; charset=UTF-8'], [$r]];
} elsif ($path =~ m|^/hraj/stop$| && $meth eq "POST") {
system "/opt/ksp/ann_stop.sh";
my $r = '<html><body style="font-size: large; ">';
$r .= qq[Zastaveno<br/><a href="/hraj">Zpět</a>];
$r .= '</body></html>';
return [200, ['Content-Type' => 'text/html; charset=UTF-8'], [$r]];
} else {
return [404, [], []];
}
}