From e8456e63920058f2e4dfc4dfb6124505120f5396 Mon Sep 17 00:00:00 2001 From: guillermo Date: Tue, 2 Jul 2024 12:51:13 +0200 Subject: [PATCH 1/6] feat: refs #7022 Added cdn --- cdn/Dockerfile | 20 ++++++++++++++++++++ cdn/apache2.conf | 18 ++++++++++++++++++ cdn/docker-compose.yml | 8 ++++++++ cdn/rwmap.pl | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 81 insertions(+) create mode 100644 cdn/Dockerfile create mode 100644 cdn/apache2.conf create mode 100644 cdn/docker-compose.yml create mode 100755 cdn/rwmap.pl diff --git a/cdn/Dockerfile b/cdn/Dockerfile new file mode 100644 index 0000000..055ca85 --- /dev/null +++ b/cdn/Dockerfile @@ -0,0 +1,20 @@ +FROM httpd:2.4.60 + +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 rwmap.pl /usr/local/apache2/htdocs/ +RUN chmod +x /usr/local/apache2/htdocs/rwmap.pl + +CMD ["httpd-foreground"] diff --git a/cdn/apache2.conf b/cdn/apache2.conf new file mode 100644 index 0000000..c685548 --- /dev/null +++ b/cdn/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/cdn/docker-compose.yml b/cdn/docker-compose.yml new file mode 100644 index 0000000..ac8896a --- /dev/null +++ b/cdn/docker-compose.yml @@ -0,0 +1,8 @@ +version: '3' +services: + apache: + build: + context: . + dockerfile: Dockerfile + ports: + - "80:80" diff --git a/cdn/rwmap.pl b/cdn/rwmap.pl new file mode 100755 index 0000000..c150734 --- /dev/null +++ b/cdn/rwmap.pl @@ -0,0 +1,35 @@ +#!/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 = $_; + 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"; + } +} From 25fc5e0745472dc74bba943cd0b44531ed8038aa Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 8 Jul 2024 07:29:53 +0200 Subject: [PATCH 2/6] feat: refs #7022 Requested changes --- cdn/docker-compose.yml | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 cdn/docker-compose.yml diff --git a/cdn/docker-compose.yml b/cdn/docker-compose.yml deleted file mode 100644 index ac8896a..0000000 --- a/cdn/docker-compose.yml +++ /dev/null @@ -1,8 +0,0 @@ -version: '3' -services: - apache: - build: - context: . - dockerfile: Dockerfile - ports: - - "80:80" From 3f389c0ea0242ea31f8bef4644fb51fcda8cc56c Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 14 Aug 2024 11:07:18 +0200 Subject: [PATCH 3/6] feat: refs #7022 Changes --- cdn/Dockerfile | 18 ++++-------------- cdn/apache2.conf | 18 ------------------ cdn/rwmap.pl | 31 +++++++++++-------------------- 3 files changed, 15 insertions(+), 52 deletions(-) delete mode 100644 cdn/apache2.conf diff --git a/cdn/Dockerfile b/cdn/Dockerfile index 055ca85..2c760ee 100644 --- a/cdn/Dockerfile +++ b/cdn/Dockerfile @@ -1,20 +1,10 @@ -FROM httpd:2.4.60 +FROM httpd:2.4.61 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 www/rwmap.pl /usr/local/bin/ +RUN chmod +x /usr/local/bin/rwmap.pl -COPY apache2.conf /usr/local/apache2/conf/extra/httpd-vhosts.conf - -COPY rwmap.pl /usr/local/apache2/htdocs/ -RUN chmod +x /usr/local/apache2/htdocs/rwmap.pl - -CMD ["httpd-foreground"] +RUN echo "IncludeOptional conf.d/*.conf" >> conf/httpd.conf diff --git a/cdn/apache2.conf b/cdn/apache2.conf deleted file mode 100644 index c685548..0000000 --- a/cdn/apache2.conf +++ /dev/null @@ -1,18 +0,0 @@ - - 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/cdn/rwmap.pl b/cdn/rwmap.pl index c150734..0c811cc 100755 --- a/cdn/rwmap.pl +++ b/cdn/rwmap.pl @@ -4,32 +4,23 @@ 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 = $_; - my ($path, $filename) = split('/', $input); + $input =~ /^\/image\/(.*)\/([a-z0-9-_]+)\.(png)$/; + my $collection = $1; + my $name = $2; + my $extension = $3; - 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); + my $newPath = "images/$collection/$first/$last/$name.$extension"; - 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"; - } + if (-e "/usr/local/apache2/htdocs/$newPath") { + print "/$newPath\n"; } else { - print "Status: 400 Bad Request\n"; + print "/image/$input\n"; } } From ebdf01b7b032353aa146989100e44c500fe5a3d9 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 14 Aug 2024 11:11:56 +0200 Subject: [PATCH 4/6] feat: refs #7022 Changes --- cdn/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdn/Dockerfile b/cdn/Dockerfile index 2c760ee..b31eba2 100644 --- a/cdn/Dockerfile +++ b/cdn/Dockerfile @@ -4,7 +4,7 @@ RUN apt-get update \ && apt-get install -y curl libcgi-pm-perl \ && rm -rf /var/lib/apt/lists/* -COPY www/rwmap.pl /usr/local/bin/ +COPY rwmap.pl /usr/local/bin/ RUN chmod +x /usr/local/bin/rwmap.pl RUN echo "IncludeOptional conf.d/*.conf" >> conf/httpd.conf From 1567ed052d0d16a1068607607e4b4de5859088a8 Mon Sep 17 00:00:00 2001 From: guillermo Date: Wed, 14 Aug 2024 11:30:57 +0200 Subject: [PATCH 5/6] feat: refs #7022 Deleted curl --- cdn/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdn/Dockerfile b/cdn/Dockerfile index b31eba2..e245810 100644 --- a/cdn/Dockerfile +++ b/cdn/Dockerfile @@ -1,7 +1,7 @@ FROM httpd:2.4.61 RUN apt-get update \ - && apt-get install -y curl libcgi-pm-perl \ + && apt-get install -y libcgi-pm-perl \ && rm -rf /var/lib/apt/lists/* COPY rwmap.pl /usr/local/bin/ From 60f9b44b228c3a2a7c4c61b4535f2180a07aa250 Mon Sep 17 00:00:00 2001 From: guillermo Date: Mon, 2 Sep 2024 07:42:28 +0200 Subject: [PATCH 6/6] feat: refs #7022 Requested changes --- cdn/rwmap.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdn/rwmap.pl b/cdn/rwmap.pl index 0c811cc..23a5657 100755 --- a/cdn/rwmap.pl +++ b/cdn/rwmap.pl @@ -21,6 +21,6 @@ while () { if (-e "/usr/local/apache2/htdocs/$newPath") { print "/$newPath\n"; } else { - print "/image/$input\n"; + print "/$input\n"; } }