feat(CGI): refs #5576 RewriteMap
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
gitea/salix/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
1f515f4ad6
commit
30d417473b
|
@ -22,11 +22,12 @@ 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
|
||||
RUN chmod +x /usr/local/apache2/htdocs/script2.pl
|
||||
RUN chmod +x /usr/local/apache2/htdocs/script3.pl
|
||||
RUN chmod +x /usr/local/apache2/htdocs/extract_characters.pl
|
||||
|
||||
# CMD y ENTRYPOINT para iniciar Apache2, según la imagen original
|
||||
CMD ["httpd-foreground"]
|
||||
|
|
|
@ -1,11 +1,30 @@
|
|||
# apache2.conf
|
||||
<VirtualHost *:80>
|
||||
DocumentRoot /usr/local/apache2/htdocs
|
||||
<Directory "/usr/local/apache2/htdocs">
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
Options +ExecCGI
|
||||
AddHandler cgi-script .cgi .pl
|
||||
</Directory>
|
||||
RewriteMap sub "prg:/usr/local/apache2/htdocs/script3.pl"
|
||||
<Directory "/usr/local/apache2/htdocs">
|
||||
Options Indexes FollowSymLinks
|
||||
AllowOverride All
|
||||
Require all granted
|
||||
Options +ExecCGI
|
||||
AddHandler cgi-script .cgi .pl
|
||||
RewriteEngine On
|
||||
|
||||
# RewriteCond %{REQUEST_URI} ^/(.+)$
|
||||
# RewriteRule .* - [E=REDIRECT_STATUS:%{REQUEST_URI}]
|
||||
|
||||
# RewriteCond %{ENV:REDIRECT_STATUS} ^(.+)$
|
||||
# RewriteRule .* /images/%1 [R,L]
|
||||
# RewriteCond %{ENV:REDIRECT_STATUS} 75/50
|
||||
# /images/75/50
|
||||
|
||||
# RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?value=/images/${sub:%0}/${sub:%2}/${sub:%1} [L,QSA]
|
||||
RewriteRule ^(.+)\.(jpg|png|jpeg)$ /asd [L]
|
||||
|
||||
# RewriteCond %{REQUEST_URI} !^/images/asd/
|
||||
# RewriteRule ^(.*)$ /75/$1 [L]
|
||||
# RewriteRule ^(.+)\.(jpg|png|jpeg)$ /${sub:%2}/$1 [L]
|
||||
|
||||
</Directory>
|
||||
|
||||
</VirtualHost>
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
# Lee la ruta de la URL desde la variable de entorno QUERY_STRING
|
||||
my $query_string = $ENV{'QUEsRY_STRING'};
|
||||
|
||||
# Extrae los dos primeros caracteres del nombre del archivo
|
||||
my $first_two_characters = substr($query_string, 0, 2);
|
||||
|
||||
# Imprime la ruta que se pasará al RewriteRule
|
||||
print "Content-type: text/plain\r\n";
|
||||
print "\r\n";
|
||||
print "/$first_two_characters/";
|
|
@ -5,46 +5,13 @@ 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;
|
||||
my $input_value = $cgi->param('value') || "defaudlt";
|
||||
# Imprime el encabezado HTTP
|
||||
print "Content-type: text/plain\r\n";
|
||||
print "\r\n"; # Imprime una línea en blanco para indicar el final del encabezado
|
||||
|
||||
# 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;
|
||||
}
|
||||
# Imprime el texto deseado
|
||||
print $input_value ;
|
||||
print "¡Hola, mundo!\n";
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
#!/usr/bin/perl
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Digest::SHA qw(sha1_hex);
|
||||
use CGI;
|
||||
|
||||
# Imprime un texto cualquiera por consola
|
||||
|
||||
my $cgi = CGI->new;
|
||||
my $input_name = $cgi->param('name') || "default";
|
||||
my $input_value = $cgi->param('value') || "default";
|
||||
my $new_path;
|
||||
|
||||
# Imprime el encabezado HTTP
|
||||
print "Content-type: text/plain\r\n";
|
||||
print "\r\n"; # Imprime una línea en blanco para indicar el final del encabezado
|
||||
|
||||
# Imprime el texto deseado
|
||||
print "¡Hola, mundo!\n";
|
||||
|
||||
# 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=$input_value;
|
||||
my $file= (split('/', $input_value))[-1];
|
||||
my $exists = -e "$input_value";
|
||||
|
||||
# Compruebo si existe el archivo en la caperta general o no
|
||||
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);
|
||||
# print "images/$first_characters/$second_characters/$file";
|
||||
if($exists) {
|
||||
$new_path ="$input_value";
|
||||
} else {
|
||||
# Calcula el valor hash MD5 del string
|
||||
|
||||
$new_path ="images/$first_characters/$second_characters/$file";
|
||||
}
|
||||
# Verifica si $imagen está definida antes de intentar usarla
|
||||
if (defined $new_path) {
|
||||
xabrir_imagen($new_path);
|
||||
}
|
||||
sub abrir_imagen {
|
||||
my ($ruta) = @_;
|
||||
|
||||
# print "Ruta\n";
|
||||
print $ruta . "\n";
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
$ENV{'REDIRECT_STATUS'} = '75/50';
|
||||
print "Content-type: text/html\n\n";
|
||||
print "Content";
|
Loading…
Reference in New Issue