From 1196b3214803fbfd4606bc02b99eab978d3a967a Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 22 Dec 2023 09:46:04 +0100 Subject: [PATCH] refs #5576 perf: remove bad code --- images/Dockerfile | 39 +++++------------------ images/_.htaccess | 17 ---------- images/apache2.conf | 6 ---- images/cgi-bin/.htaccess | 2 -- images/cgi-bin/hola_mundo.pl | 8 ----- images/cgi-bin/mostrar-md5.pl | 18 ----------- images/cgi-bin/script.pl | 27 ---------------- images/docker-compose.yml | 1 - images/httpd.conf | 22 ------------- images/www/index.html | 2 -- images/www/nuevo_script.js | 4 --- images/www/script.js | 8 ----- images/www/script.pl | 28 ++++------------ storage/image/Dockerfile | 30 ----------------- storage/image/mi-configuracion-httpd.conf | 24 -------------- 15 files changed, 14 insertions(+), 222 deletions(-) delete mode 100644 images/_.htaccess delete mode 100644 images/cgi-bin/.htaccess delete mode 100644 images/cgi-bin/hola_mundo.pl delete mode 100644 images/cgi-bin/mostrar-md5.pl delete mode 100644 images/cgi-bin/script.pl delete mode 100644 images/httpd.conf delete mode 100644 images/www/index.html delete mode 100644 images/www/nuevo_script.js delete mode 100644 images/www/script.js delete mode 100644 storage/image/Dockerfile delete mode 100644 storage/image/mi-configuracion-httpd.conf diff --git a/images/Dockerfile b/images/Dockerfile index f6f807795..d267dcfce 100644 --- a/images/Dockerfile +++ b/images/Dockerfile @@ -1,55 +1,32 @@ FROM httpd:latest -# Habilitar mod_rewrite y configurar Apache - RUN apt-get update && apt-get install -y curl libcgi-pm-perl -# Habilitar mod_rewrite y mod_cgi + +# Habilitar mod_rewrite RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf -RUN sed -i '/mod_cgi/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 mod_rewrite si aún no está habilitado -RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf +# Habilitar reescritura +RUN echo "RewriteEngine On" >> /usr/local/apache2/conf/extra/httpd-vhosts.conf -# Configurar Apache para ejecutar scripts CGI -# RUN echo "ScriptAlias /cgi-bin/ \"/usr/local/apache2/cgi-bin/\"" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " AllowOverride None" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Options +ExecCGI" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Require all granted" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf - -# Configurar Apache para ejecutar scripts CGI -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Options +ExecCGI" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " AllowOverride None" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " AddHandler cgi-script .cgi .pl" >> /usr/local/apache2/conf/httpd.conf -# RUN echo " Require all granted" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "" >> /usr/local/apache2/conf/httpd.conf -# Copiar scripts CGI al directorio correspondiente -COPY cgi-bin/ /usr/local/apache2/cgi-bin/ # 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 las imágenes al directorio 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/ -RUN chmod +x /usr/local/apache2/htdocs/script.pl -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 +# 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/_.htaccess b/images/_.htaccess deleted file mode 100644 index 4a5135d8e..000000000 --- a/images/_.htaccess +++ /dev/null @@ -1,17 +0,0 @@ - - - Options +ExecCGI -AddHandler cgi-script .pl - - - RewriteEngine On - RewriteBase /images/ - RewriteRule ^(.*)$ /cgi-bin/script.pl?nombre=$1 [L,QSA,NC] - - - diff --git a/images/apache2.conf b/images/apache2.conf index de6efeac2..9e5018bd3 100644 --- a/images/apache2.conf +++ b/images/apache2.conf @@ -1,12 +1,6 @@ # apache2.conf - ServerAdmin webmaster@localhost DocumentRoot /usr/local/apache2/htdocs - - Options +ExecCGI - AddHandler cgi-script .cgi .pl - Require all granted - Options Indexes FollowSymLinks AllowOverride All diff --git a/images/cgi-bin/.htaccess b/images/cgi-bin/.htaccess deleted file mode 100644 index c4e0a039a..000000000 --- a/images/cgi-bin/.htaccess +++ /dev/null @@ -1,2 +0,0 @@ -Options +ExecCGI -AddHandler cgi-script .pl diff --git a/images/cgi-bin/hola_mundo.pl b/images/cgi-bin/hola_mundo.pl deleted file mode 100644 index cc65e1479..000000000 --- a/images/cgi-bin/hola_mundo.pl +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; - -print "Content-type: text/html\n\n"; -print "Hola Mundo en Perl"; -print "

Hola Mundo desde Perl

"; -print ""; diff --git a/images/cgi-bin/mostrar-md5.pl b/images/cgi-bin/mostrar-md5.pl deleted file mode 100644 index c432547c9..000000000 --- a/images/cgi-bin/mostrar-md5.pl +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -use Digest::MD5; - -# Leer el nombre del archivo desde la consulta -my $archivo = $ENV{'QUERY_STRING'}; - -# Calcular el MD5 del nombre del archivo -my $md5 = Digest::MD5->new; -$md5->add($archivo); -my $hash = $md5->hexdigest; - -# Imprimir el resultado -print "Content-type: text/html\n\n"; -print "MD5 del nombre del archivo"; -print "

MD5 del nombre del archivo: $hash

"; -print ""; diff --git a/images/cgi-bin/script.pl b/images/cgi-bin/script.pl deleted file mode 100644 index 9852460f6..000000000 --- a/images/cgi-bin/script.pl +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/perl -use strict; -use warnings; -use Digest::MD5; -use File::Basename; - -sub calcular_hash { - my ($archivo) = @_; - - # Obtener solo el nombre del archivo sin la ruta - my $nombre_archivo = fileparse($archivo); - - # Calcular el hash MD5 del nombre del archivo - my $md5 = Digest::MD5->new; - $md5->add($nombre_archivo); - my $hash = $md5->hexdigest; - - return $hash; -} - -# Obtener el nombre del archivo de la URL -my $archivo_url = $ENV{'REQUEST_URI'}; -my $hash_archivo = calcular_hash($archivo_url); - -# Imprimir el hash como respuesta -print "Content-type: text/plain\n\n"; -print "Hash del nombre del archivo: $hash_archivo\n"; diff --git a/images/docker-compose.yml b/images/docker-compose.yml index 42f1e31a4..651face42 100644 --- a/images/docker-compose.yml +++ b/images/docker-compose.yml @@ -3,7 +3,6 @@ services: apache: volumes: - ./images:/usr/local/apache2/htdocs/images/ - build: context: . dockerfile: Dockerfile diff --git a/images/httpd.conf b/images/httpd.conf deleted file mode 100644 index 78e9218f2..000000000 --- a/images/httpd.conf +++ /dev/null @@ -1,22 +0,0 @@ -# # httpd.conf -# -# AllowOverride All -# Options +ExecCGI -# Require all granted -# - -# # httpd.conf -# -# StartServers 5 -# MinSpareServers 5 -# MaxSpareServers 10 -# MaxClients 150 -# MaxRequestsPerChild 0 -# - - -# # httpd.conf -# -# AllowOverride All -# Require all granted -# diff --git a/images/www/index.html b/images/www/index.html deleted file mode 100644 index 7e72cbd38..000000000 --- a/images/www/index.html +++ /dev/null @@ -1,2 +0,0 @@ - - diff --git a/images/www/nuevo_script.js b/images/www/nuevo_script.js deleted file mode 100644 index 0dee10bfa..000000000 --- a/images/www/nuevo_script.js +++ /dev/null @@ -1,4 +0,0 @@ -console.log('adios'); - -window.onload = function() { -}; diff --git a/images/www/script.js b/images/www/script.js deleted file mode 100644 index 3d1fc098b..000000000 --- a/images/www/script.js +++ /dev/null @@ -1,8 +0,0 @@ -console.log('hola'); -window.onload = function() { - // document.body = ''; - let img = document.createElement('img'); - img.src = '../../images/_DSC5302.jpg'; - let src = document.getElementById('header'); - src.appendChild(img); -}; diff --git a/images/www/script.pl b/images/www/script.pl index 005c2f9c1..0fc4a24c1 100644 --- a/images/www/script.pl +++ b/images/www/script.pl @@ -12,45 +12,29 @@ 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"; -# print $exists; -# $exists = -e "$input_value"; -# print $exists; + +# Compruebo si existe el archivo en la caperta general o no if($exists) { - # print "Content-type: text/html\n\n"; $new_path ="$input_value"; - # print "

$new_path

"; } 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"; - # Imprime el resultado - # Establecer el tipo de contenido a imagen JPEG - # print "Content-type: text/html\n\n"; - # print "

Ultimo elemento es: $fileName

"; - # print "

input_name==>$input_name

"; - # print "

input_value==>$input_value

"; - # print "

fileName==>$fileName

"; - # print "

file==>$file

"; - # print "

hash_value==>$hash_value

"; - # print "

first_characters==>$first_characters/$second_characters/$input_value

"; - # print "

new_path==>$new_path

"; - - # Abre la imagen en modo binario - - # open my $imagen, '<', $new_path or die "No se pudo abrir la imagen: $!"; - } # Verifica si $imagen está definida antes de intentar usarla if (defined $new_path) { abrir_imagen($new_path); - # print "

HOLA

"; } sub abrir_imagen { my ($ruta) = @_; diff --git a/storage/image/Dockerfile b/storage/image/Dockerfile deleted file mode 100644 index 91a39b44f..000000000 --- a/storage/image/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -# Usa la imagen oficial de Apache -FROM httpd:latest - -# Añade configuración del MPM prefork -# RUN echo "LoadModule mpm_prefork_module modules/mod_mpm_prefork.so" >> /usr/local/apache2/conf/httpd.conf -# RUN echo "LoadModule mpm_worker_module modules/mod_mpm_worker.so" >> /usr/local/apache2/conf/httpd.conf - -# Copia tu archivo de configuración personalizado (si lo tienes) -# COPY ./mi-configuracion-httpd.conf /usr/local/apache2/conf/httpd.conf -COPY ./image.png /usr/local/apache2/htdocs/ -COPY ./image.png /usr/local/apache2/htdocs/welcome.png -COPY ./.htaccess /usr/local/apache2/htdocs/ -RUN { \ - echo 'IncludeOptional conf.d/*.conf'; \ -} >> /usr/local/apache2/conf/httpd.conf \ - && mkdir /usr/local/apache2/conf.d - # Copy .htaccess into DocumentRoot -COPY ./.htaccess /var/www/html/ -# Habilita el módulo mod_rewrite -RUN sed -i 's/#LoadModule rewrite_module/LoadModule rewrite_module/' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_prefork_module/LoadModule mpm_prefork_module/' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_worker_module modules/mod_mpm_worker.so' /usr/local/apache2/conf/httpd.conf -# RUN sed -i 's/#LoadModule mpm_worker_module/LoadModule mpm_worker_module/' /usr/local/apache2/conf/httpd.conf - -# Establece el propietario del directorio del servidor a www-data (usuario de Apache) -RUN chown -R www-data:www-data /usr/local/apache2/htdocs/ - -# Expón el puerto 80 para que sea accesible desde fuera del contenedor -EXPOSE 80 diff --git a/storage/image/mi-configuracion-httpd.conf b/storage/image/mi-configuracion-httpd.conf deleted file mode 100644 index 8f2954332..000000000 --- a/storage/image/mi-configuracion-httpd.conf +++ /dev/null @@ -1,24 +0,0 @@ -# -# LoadModule mpm_prefork_module modules/mod_mpm_prefork.so -# - - - LoadModule mpm_worker_module modules/mod_mpm_worker.so - - - - - RewriteEngine On - - # Asegúrate de que el módulo crypto esté disponible - RewriteCond %{LA-U:CRYPTO:crypto} ^$ - - # Obtén el nombre del archivo sin la extensión - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteRule ^(.+)\.png$ - [E=FILENAME_NO_EXT:$1] - - # Calcula el hash del nombre del archivo - RewriteCond %{LA-U:CRYPTO:crypto} ^(.+)$ - RewriteRule ^(.+)\.png$ /images/%1.png [L] -