37 lines
1.1 KiB
Perl
Executable File
37 lines
1.1 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
use strict;
|
|
use warnings;
|
|
use Digest::SHA qw(sha1_hex);
|
|
# Desactiva el buffering de salida para que Apache pueda obtener la respuesta inmediatamente
|
|
$| = 1;
|
|
my $serverName = $ENV{'SERVER_NAME'} || 'localhost';
|
|
my $serverPort = $ENV{'SERVER_PORT'} || '80';
|
|
my $scheme = ($serverPort == 443) ? 'https' : 'http';
|
|
my $baseUrl = "$scheme://$serverName";
|
|
$baseUrl .= ":$serverPort" if ($serverPort != 80 && $serverPort != 443);
|
|
|
|
while (<STDIN>) {
|
|
chomp;
|
|
my $input = $_;
|
|
print STDERR "DEBUG: Input recibido: $input\n"; # Mensaje de depuración
|
|
my ($path, $filename) = split('/', $input);
|
|
|
|
if (defined $filename && $filename =~ /^(.+)\.(\w+)$/) {
|
|
my $name = $1;
|
|
my $extension = $2;
|
|
|
|
my $sha1 = sha1_hex($name);
|
|
my $first = substr($sha1, 0, 2);
|
|
my $last = substr($sha1, 1, 2);
|
|
|
|
if (-e "images/catalog/$path/$first/$last/$name.$extension") {
|
|
print "$baseUrl/images/catalog/$path/$first/$last/$name.$extension\n";
|
|
}
|
|
else {
|
|
print "$baseUrl/images/catalog/$path/$name.$extension\n";
|
|
}
|
|
} else {
|
|
print "Status: 400 Bad Request\n";
|
|
}
|
|
}
|