approach
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Javier Segarra 2023-12-17 00:07:33 +01:00
parent 838c56d770
commit 0da816ca35
5 changed files with 52 additions and 25 deletions

View File

@ -1,4 +1,4 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1&ext=$2 [L,QSA]
RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1 [L,QSA]
</IfModule>

View File

@ -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"]

View File

@ -1,4 +1,4 @@
<Directory "/usr/local/apache2/cgi-bin">
<Directory "/usr/local/apache2/cgi-bin">
Options +ExecCGI
AddHandler cgi-script .pl

View File

@ -1,6 +1,9 @@
version: '3'
services:
apache:
volumes:
- ./images:/usr/local/apache2/htdocs/images/
build:
context: .
dockerfile: Dockerfile

View File

@ -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 "<html><body style=' margin: 0px;
height: 100%;
background-color: rgb(14, 14, 14);'>
<h1>$ext</h1>
<h1>$input_string</h1>
<h1>$hash_value</h1>
<h1>$first_characters</h1>
<h1>$second_characters</h1>
<img style= 'display: block;
-webkit-user-select: none;
margin: auto;
cursor: zoom-in;
background-color: hsl(0, 0%, 90%);
transition: background-color 300ms;' src='../images/$name.jpg' width='100%' height='100%' alt='' srcset=''></body></html>";
# print "<html><body style=' margin: 0px;
# height: 100%;
# background-color: rgb(14, 14, 14);'>
# <h1>$ext</h1>
# <h1>$script_path</h1>
# <h1>$new_path</h1>
# <h1>$input_string</h1>
# <h1>$pwd</h1>
# <h1>$query_string</h1>
# <h1>$request_path</h1>
# <h1>$hash_value</h1>
# <h1>$first_characters</h1>
# <h1>$second_characters</h1>
# 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 "<img style= 'display: block;
# -webkit-user-select: none;
# margin: auto;
# cursor: zoom-in;
# background-color: hsl(0, 0%, 90%);
# transition: background-color 300ms;' src='../../images/_DSC5308.jpg' width='100%' height='100%' alt='' srcset=''>";