parent
e65ed6811e
commit
ae64e9e1a1
|
@ -1,4 +0,0 @@
|
|||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?value=$1.$2&name=$1 [L,QSA]
|
||||
</IfModule>
|
|
@ -1,32 +0,0 @@
|
|||
FROM httpd:latest
|
||||
|
||||
RUN apt-get update && apt-get install -y curl libcgi-pm-perl
|
||||
|
||||
# Habilitar mod_rewrite
|
||||
RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf
|
||||
RUN echo "AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf
|
||||
RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf
|
||||
|
||||
# Habilitar mod_cgi
|
||||
RUN sed -i '/mod_cgi/s/^#//g' /usr/local/apache2/conf/httpd.conf
|
||||
RUN echo "LoadModule cgid_module modules/mod_cgid.so" >> /usr/local/apache2/conf/httpd.conf
|
||||
|
||||
# Habilitar reescritura
|
||||
RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf
|
||||
|
||||
|
||||
|
||||
# Copiar la configuración de Apache2 y los archivos del sitio
|
||||
COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf
|
||||
|
||||
# RUN chmod +x www/script.pl
|
||||
COPY www/ /usr/local/apache2/htdocs/
|
||||
|
||||
# Copia el archivo .htaccess para configurar el directorio htdocs/images
|
||||
COPY .htaccess /usr/local/apache2/htdocs/
|
||||
|
||||
# Habilita permisos de ejecución
|
||||
RUN chmod +x /usr/local/apache2/htdocs/script.pl
|
||||
|
||||
# CMD y ENTRYPOINT para iniciar Apache2, según la imagen original
|
||||
CMD ["httpd-foreground"]
|
|
@ -1,11 +0,0 @@
|
|||
# apache2.conf
|
||||
<VirtualHost *:80>
|
||||
DocumentRoot /usr/local/apache2/htdocs
|
||||
<Directory "/usr/local/apache2/htdocs">
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
Options +ExecCGI
|
||||
AddHandler cgi-script .cgi .pl
|
||||
</Directory>
|
||||
</VirtualHost>
|
|
@ -1,11 +0,0 @@
|
|||
version: '3'
|
||||
services:
|
||||
apache:
|
||||
volumes:
|
||||
- ./images:/usr/local/apache2/htdocs/images/
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
ports:
|
||||
- "8080:80"
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
use CGI;
|
||||
|
||||
my $cgi = CGI->new;
|
||||
my $input_name = $cgi->param('name') || "default";
|
||||
my $input_value = $cgi->param('value') || "default";
|
||||
my $new_path;
|
||||
|
||||
# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo SIN extension
|
||||
my $fileName= (split('/', $input_name))[-1];
|
||||
|
||||
# Dividir la ruta usando el símbolo "/" para extraaer el nombre del archivo CON extension
|
||||
my $file= (split('/', $input_value))[-1];
|
||||
my $exists = -e "$input_value";
|
||||
|
||||
# Compruebo si existe el archivo en la caperta general o no
|
||||
if($exists) {
|
||||
$new_path ="$input_value";
|
||||
} else {
|
||||
# Calcula el valor hash MD5 del string
|
||||
my $hash_value = sha1_hex($fileName);
|
||||
|
||||
# Obtiene solo los 2 primeros caracteres del hash MD5
|
||||
my $first_characters = substr($hash_value, 0, 2);
|
||||
|
||||
# Obtiene solo los 2 segundos caracteres del hash MD5
|
||||
my $second_characters = substr($hash_value, 1, 2);
|
||||
|
||||
$new_path ="images/$first_characters/$second_characters/$file";
|
||||
}
|
||||
# Verifica si $imagen está definida antes de intentar usarla
|
||||
if (defined $new_path) {
|
||||
abrir_imagen($new_path);
|
||||
}
|
||||
sub abrir_imagen {
|
||||
my ($ruta) = @_;
|
||||
print "Content-type: image/jpeg\n\n";
|
||||
open my $imagen, '<', $ruta or die "No se pudo abrir la imagen: $!";
|
||||
|
||||
# Imprime los bytes de la imagen directamente en la salida estándar
|
||||
binmode STDOUT;
|
||||
print while <$imagen>;
|
||||
|
||||
# Cierra el archivo
|
||||
close $imagen;
|
||||
}
|
Loading…
Reference in New Issue