From ae64e9e1a1f20769955e640d564efc0830a56fee Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Tue, 12 Mar 2024 11:45:21 +0100 Subject: [PATCH] refs #5576 feat move CGI to #7022 --- images/.htaccess | 4 ---- images/Dockerfile | 32 ------------------------- images/apache2.conf | 11 --------- images/docker-compose.yml | 11 --------- images/www/script.pl | 50 --------------------------------------- 5 files changed, 108 deletions(-) delete mode 100644 images/.htaccess delete mode 100644 images/Dockerfile delete mode 100644 images/apache2.conf delete mode 100644 images/docker-compose.yml delete mode 100644 images/www/script.pl diff --git a/images/.htaccess b/images/.htaccess deleted file mode 100644 index 2b778acaf..000000000 --- a/images/.htaccess +++ /dev/null @@ -1,4 +0,0 @@ - - RewriteEngine On - RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?value=$1.$2&name=$1 [L,QSA] - diff --git a/images/Dockerfile b/images/Dockerfile deleted file mode 100644 index d267dcfce..000000000 --- a/images/Dockerfile +++ /dev/null @@ -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"] diff --git a/images/apache2.conf b/images/apache2.conf deleted file mode 100644 index 9e5018bd3..000000000 --- a/images/apache2.conf +++ /dev/null @@ -1,11 +0,0 @@ -# apache2.conf - - DocumentRoot /usr/local/apache2/htdocs - - Options Indexes FollowSymLinks - AllowOverride All - Require all granted - Options +ExecCGI - AddHandler cgi-script .cgi .pl - - diff --git a/images/docker-compose.yml b/images/docker-compose.yml deleted file mode 100644 index 651face42..000000000 --- a/images/docker-compose.yml +++ /dev/null @@ -1,11 +0,0 @@ -version: '3' -services: - apache: - volumes: - - ./images:/usr/local/apache2/htdocs/images/ - build: - context: . - dockerfile: Dockerfile - ports: - - "8080:80" - diff --git a/images/www/script.pl b/images/www/script.pl deleted file mode 100644 index 0fc4a24c1..000000000 --- a/images/www/script.pl +++ /dev/null @@ -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; -}