diff --git a/images/Dockerfile b/images/Dockerfile new file mode 100644 index 000000000..740563a06 --- /dev/null +++ b/images/Dockerfile @@ -0,0 +1,20 @@ +FROM httpd:latest + +RUN apt-get update \ + && apt-get install -y curl libcgi-pm-perl \ + && rm -rf /var/lib/apt/lists/* + +RUN echo "ServerName localhost\n" \ + "Include conf/extra/httpd-vhosts.conf\n" \ + "LoadModule rewrite_module modules/mod_rewrite.so\n" \ + "LoadModule cgid_module modules/mod_cgid.so\n" \ + "LoadModule proxy_module modules/mod_proxy.so\n" \ + "LoadModule proxy_http_module modules/mod_proxy_http.so" \ + >> "/usr/local/apache2/conf/httpd.conf" + +COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf +COPY www/ /usr/local/apache2/htdocs/ + +RUN chmod +x /usr/local/apache2/htdocs/rwmap.pl + +CMD ["httpd-foreground"] diff --git a/images/apache2.conf b/images/apache2.conf new file mode 100644 index 000000000..c68554866 --- /dev/null +++ b/images/apache2.conf @@ -0,0 +1,18 @@ + + DocumentRoot /usr/local/apache2/htdocs + + RewriteEngine On + RewriteMap rwmap prg:/usr/local/apache2/htdocs/rwmap.pl + RewriteRule ^/image/catalog/(.+)$ ${rwmap:$1} [PT,QSA] + + + Require all granted + + + + Options Indexes FollowSymLinks ExecCGI + AllowOverride All + Require all granted + AddHandler cgi-script .pl + + \ No newline at end of file diff --git a/images/docker-compose.yml b/images/docker-compose.yml new file mode 100644 index 000000000..f646f465b --- /dev/null +++ b/images/docker-compose.yml @@ -0,0 +1,10 @@ +version: '3' +services: + apache: + volumes: + - ./images:/usr/local/apache2/htdocs/images/ + build: + context: . + dockerfile: Dockerfile + ports: + - "80:80" \ No newline at end of file diff --git a/images/www/rwmap.pl b/images/www/rwmap.pl new file mode 100755 index 000000000..4fa488260 --- /dev/null +++ b/images/www/rwmap.pl @@ -0,0 +1,36 @@ +#!/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 () { + 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"; + } +}