From 0da816ca35d8efd0d9eeecdcb6aaaf51c03087e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Segarra=20Mart=C3=ADnez?= Date: Sun, 17 Dec 2023 00:07:33 +0100 Subject: [PATCH] approach --- images/.htaccess | 2 +- images/Dockerfile | 5 ++- images/_.htaccess | 2 +- images/docker-compose.yml | 3 ++ images/www/script.pl | 65 ++++++++++++++++++++++++++------------- 5 files changed, 52 insertions(+), 25 deletions(-) diff --git a/images/.htaccess b/images/.htaccess index 57cde653f..84c8c997b 100644 --- a/images/.htaccess +++ b/images/.htaccess @@ -1,4 +1,4 @@ RewriteEngine On - RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1&ext=$2 [L,QSA] + RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1 [L,QSA] diff --git a/images/Dockerfile b/images/Dockerfile index 27cd1308d..f6f807795 100644 --- a/images/Dockerfile +++ b/images/Dockerfile @@ -40,7 +40,7 @@ COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf COPY www/ /usr/local/apache2/htdocs/ # Copia las imágenes al directorio htdocs/images -COPY images/ /usr/local/apache2/htdocs/images/ +# COPY images/ /usr/local/apache2/htdocs/images/ # Copia el archivo .htaccess para configurar el directorio htdocs/images COPY .htaccess /usr/local/apache2/htdocs/ @@ -50,3 +50,6 @@ RUN chmod +x /usr/local/apache2/cgi-bin/script.pl # Habilitar reescritura y reiniciar Apache2 RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf RUN echo "Include conf/extra/httpd-vhosts.conf" >> /usr/local/apache2/conf/httpd.conf + +# CMD y ENTRYPOINT para iniciar Apache2, según la imagen original +CMD ["httpd-foreground"] diff --git a/images/_.htaccess b/images/_.htaccess index ac787882a..4a5135d8e 100644 --- a/images/_.htaccess +++ b/images/_.htaccess @@ -1,4 +1,4 @@ - + Options +ExecCGI AddHandler cgi-script .pl diff --git a/images/docker-compose.yml b/images/docker-compose.yml index 2cb335a4a..42f1e31a4 100644 --- a/images/docker-compose.yml +++ b/images/docker-compose.yml @@ -1,6 +1,9 @@ version: '3' services: apache: + volumes: + - ./images:/usr/local/apache2/htdocs/images/ + build: context: . dockerfile: Dockerfile diff --git a/images/www/script.pl b/images/www/script.pl index ad4327359..eb67254d5 100644 --- a/images/www/script.pl +++ b/images/www/script.pl @@ -1,42 +1,63 @@ #!/usr/bin/perl use strict; use warnings; +use Cwd qw(abs_path); +my $script_path = abs_path($0); use CGI; -use Digest::MD5 qw(md5_hex); - +use Digest::SHA qw(sha1_hex); +my $pwd = `pwd`; my $cgi = CGI->new; +my $query_string = $ENV{'QUERY_STRING'}; +# print "Content-type: text/html\n\n"; -print "Content-type: text/html\n\n"; # print $cgi->header('text/javascript'); my $name = $cgi->param('name') || 'default'; my $ext = $cgi->param('ext') || 'default'; my $param = $cgi->param('param') || 'default'; # Obtén el string desde la línea de comandos o proporciona un valor predeterminado +# print "Ruta del script Perl: "; my $input_string = $cgi->param('name') || "Hola, mundo!"; # Calcula el valor hash MD5 del string -my $hash_value = md5_hex($input_string); +my $hash_value = sha1_hex($input_string); # Obtiene solo los 2 primeros caracteres del hash MD5 -my $first_characters = substr($hash_value, 0, 2); +my $first_characters = substr($hash_value, 2, 2); # Obtiene solo los 2 primeros caracteres del hash MD5 -my $second_characters = substr($hash_value, 2, 2); +my $second_characters = substr($hash_value, 0, 2); +my $request_path = $ENV{'REQUEST_PATH'} || ''; +my $new_path ="../../images/transform/$first_characters/$second_characters/$input_string"; # Imprime el resultado -print "String: $input_string\n"; -print "Hash MD5: $hash_value\n"; +# print "String: $input_string\n"; +# print "Hash MD5: $hash_value\n"; # Contenido HTML o cualquier otra salida del script -print " -

$ext

-

$input_string

-

$hash_value

-

$first_characters

-

$second_characters

- "; +# print " +#

$ext

+#

$script_path

+#

$new_path

+#

$input_string

+#

$pwd

+#

$query_string

+#

$request_path

+#

$hash_value

+#

$first_characters

+#

$second_characters

+# Abre la imagen en modo binario +print "Content-type: image/jpeg\n\n" +open my $imagen, '<', '../images/_DSC5308.jpg' 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; + # print "";