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

This commit is contained in:
Javier Segarra 2023-12-16 22:52:12 +01:00
parent fc96038125
commit 838c56d770
10 changed files with 159 additions and 18 deletions

View File

@ -1,8 +1,4 @@
Options +ExecCGI
AddHandler cgi-script .pl
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /images/
RewriteRule ^(.*)$ /cgi-bin/script.pl?nombre=$1 [L,QSA,NC]
RewriteRule ^(.+)\.(jpg|png|jpeg)$ script.pl?name=$1&ext=$2 [L,QSA]
</IfModule>

View File

@ -1,20 +1,52 @@
FROM httpd:latest
# Habilita mod_cgi y configura Apache para ejecutar scripts CGI
# Habilitar mod_rewrite y configurar Apache
RUN apt-get update && apt-get install -y curl libcgi-pm-perl
# Habilitar mod_rewrite y mod_cgi
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 "ScriptAlias /cgi-bin/ /usr/local/apache2/cgi-bin/" >> /usr/local/apache2/conf/httpd.conf
RUN chmod -R 755 /usr/local/apache2/cgi-bin/
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
# Habilita mod_rewrite
# Habilitar mod_rewrite si aún no está habilitado
RUN sed -i '/mod_rewrite/s/^#//g' /usr/local/apache2/conf/httpd.conf
# Copia el script CGI al directorio /usr/local/apache2/cgi-bin/
# Configurar Apache para ejecutar scripts CGI
# RUN echo "ScriptAlias /cgi-bin/ \"/usr/local/apache2/cgi-bin/\"" >> /usr/local/apache2/conf/httpd.conf
# RUN echo "<Directory \"/usr/local/apache2/cgi-bin\">" >> /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 "</Directory>" >> /usr/local/apache2/conf/httpd.conf
# Configurar Apache para ejecutar scripts CGI
# RUN echo "<Directory \"/usr/local/apache2/htdocs\">" >> /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 "</Directory>" >> /usr/local/apache2/conf/httpd.conf
# Copiar scripts CGI al directorio correspondiente
COPY cgi-bin/ /usr/local/apache2/cgi-bin/
RUN chmod +x /usr/local/apache2/cgi-bin/script.pl
# 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/images/.htaccess
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

17
images/_.htaccess Normal file
View File

@ -0,0 +1,17 @@
<Directory "/usr/local/apache2/cgi-bin">
Options +ExecCGI
AddHandler cgi-script .pl
</Directory>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /images/
RewriteRule ^(.*)$ /cgi-bin/script.pl?nombre=$1 [L,QSA,NC]
</IfModule>
<!--
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule> -->

17
images/apache2.conf Normal file
View File

@ -0,0 +1,17 @@
# apache2.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /usr/local/apache2/htdocs
<Directory "/usr/local/apache2/cgi-bin">
Options +ExecCGI
AddHandler cgi-script .cgi .pl
Require all granted
</Directory>
<Directory "/usr/local/apache2/htdocs">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Options +ExecCGI
AddHandler cgi-script .cgi .pl
</Directory>
</VirtualHost>

View File

@ -1,8 +1,9 @@
version: '3'
services:
apache:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80"
apache:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:80"

22
images/httpd.conf Normal file
View File

@ -0,0 +1,22 @@
# # httpd.conf
# <Directory "/usr/local/apache2/cgi-bin">
# AllowOverride All
# Options +ExecCGI
# Require all granted
# </Directory>
# # httpd.conf
# <IfModule mpm_prefork_module>
# StartServers 5
# MinSpareServers 5
# MaxSpareServers 10
# MaxClients 150
# MaxRequestsPerChild 0
# </IfModule>
# # httpd.conf
# <Directory "/usr/local/apache2/htdocs">
# AllowOverride All
# Require all granted
# </Directory>

2
images/www/index.html Normal file
View File

@ -0,0 +1,2 @@
<script src="./script.js"></script>
<div id="header"></div>

View File

@ -0,0 +1,4 @@
console.log('adios');
window.onload = function() {
};

8
images/www/script.js Normal file
View File

@ -0,0 +1,8 @@
console.log('hola');
window.onload = function() {
// document.body = '<img src="" alt="" srcset="">';
let img = document.createElement('img');
img.src = '../../images/_DSC5302.jpg';
let src = document.getElementById('header');
src.appendChild(img);
};

42
images/www/script.pl Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use Digest::MD5 qw(md5_hex);
my $cgi = CGI->new;
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
my $input_string = $cgi->param('name') || "Hola, mundo!";
# Calcula el valor hash MD5 del string
my $hash_value = md5_hex($input_string);
# Obtiene solo los 2 primeros caracteres del hash MD5
my $first_characters = substr($hash_value, 0, 2);
# Obtiene solo los 2 primeros caracteres del hash MD5
my $second_characters = substr($hash_value, 2, 2);
# Imprime el resultado
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>";