|
@@ -144,6 +144,12 @@ comprobarError() {
|
|
401)
|
|
401)
|
|
error="\n$type $codeNum:\tError al instalar 'certbot' (Let's Encrypt).\n"
|
|
error="\n$type $codeNum:\tError al instalar 'certbot' (Let's Encrypt).\n"
|
|
;;
|
|
;;
|
|
|
|
+ 402)
|
|
|
|
+ error="\n$type $codeNum:\tImposible generar Certificados Autofirmados.\n"
|
|
|
|
+ ;;
|
|
|
|
+ 403)
|
|
|
|
+ error="\n$type $codeNum:\tImposible generar claves de intercambio Diffie-Hellman.\n"
|
|
|
|
+ ;;
|
|
501)
|
|
501)
|
|
error="\n$type $codeNum:\tImposible descargar MediaWiki-1.31.0.\n"
|
|
error="\n$type $codeNum:\tImposible descargar MediaWiki-1.31.0.\n"
|
|
;;
|
|
;;
|
|
@@ -774,6 +780,11 @@ instalarApache() {
|
|
webServerName="httpd"
|
|
webServerName="httpd"
|
|
result=$(yum -y install httpd 2>&1)
|
|
result=$(yum -y install httpd 2>&1)
|
|
comprobarError $? 101 $result
|
|
comprobarError $? 101 $result
|
|
|
|
+ if [ $sslOn = true ];then
|
|
|
|
+ # Instalamos módulo mod_ssl (no se instala por defecto)
|
|
|
|
+ result=$(yum -y install mod_ssl 2>&1)
|
|
|
|
+ comprobarError $? 101 $result
|
|
|
|
+ fi
|
|
else
|
|
else
|
|
comprobarError 1 104
|
|
comprobarError 1 104
|
|
fi
|
|
fi
|
|
@@ -798,21 +809,39 @@ configurarApache() {
|
|
# Activamos mod_rewrite (no viene activado por defecto)
|
|
# Activamos mod_rewrite (no viene activado por defecto)
|
|
a2enmod rewrite >/dev/null 2>&1
|
|
a2enmod rewrite >/dev/null 2>&1
|
|
comprobarError $? 108
|
|
comprobarError $? 108
|
|
|
|
+ # Activamos mod_ssl y mod_headers (no viene activado por defecto)
|
|
|
|
+ if [ $sslOn = true ];then
|
|
|
|
+ a2enmod ssl >/dev/null 2>&1
|
|
|
|
+ comprobarError $? 108
|
|
|
|
+ a2enmod headers >/dev/null 2>&1
|
|
|
|
+ comprobarError $? 108
|
|
|
|
+ fi
|
|
|
|
+ unset apacheConfFile
|
|
elif [ $rhelOS = true ];then
|
|
elif [ $rhelOS = true ];then
|
|
apacheConfFile="./etc/apache2/conf/httpd.conf"
|
|
apacheConfFile="./etc/apache2/conf/httpd.conf"
|
|
|
|
+ sslConfFile="./etc/apache2/conf.d/ssl.conf"
|
|
welcomeConfFile="/etc/apache2/conf.d/welcome.conf"
|
|
welcomeConfFile="/etc/apache2/conf.d/welcome.conf"
|
|
if [ ! -f $apacheConfFile ];then
|
|
if [ ! -f $apacheConfFile ];then
|
|
comprobarError 1 4 $apacheConfFile
|
|
comprobarError 1 4 $apacheConfFile
|
|
fi
|
|
fi
|
|
cp -f $apacheConfFile /etc/$webServerName/conf/httpd.conf 2>/dev/null
|
|
cp -f $apacheConfFile /etc/$webServerName/conf/httpd.conf 2>/dev/null
|
|
comprobarError $? 108
|
|
comprobarError $? 108
|
|
|
|
+ # Desactivamos Mensaje de Bienvenida
|
|
if [ -f $welcomeConfFile ];then
|
|
if [ -f $welcomeConfFile ];then
|
|
sed -i -e 's/^/#/' $welcomeConfFile
|
|
sed -i -e 's/^/#/' $welcomeConfFile
|
|
comprobarError $? 108
|
|
comprobarError $? 108
|
|
fi
|
|
fi
|
|
|
|
+ # Configuramos mod_ssl
|
|
|
|
+ if [ $sslOn = true ];then
|
|
|
|
+ if [ ! -f $sslConfFile ];then
|
|
|
|
+ comprobarError 1 4 $sslConfFile
|
|
|
|
+ fi
|
|
|
|
+ cp -f $sslConfFile /etc/$webServerName/conf.d/ssl.conf 2>/dev/null
|
|
|
|
+ comprobarError $? 108
|
|
|
|
+ fi
|
|
webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
|
|
webServerUser=$(grep ^User /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
|
|
webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
|
|
webServerGroup=$(grep ^Group /etc/$webServerName/conf/httpd.conf | cut -d ' ' -f 2)
|
|
- unset apacheConfFile welcomeConfFile
|
|
|
|
|
|
+ unset apacheConfFile sslConfFile welcomeConfFile
|
|
fi
|
|
fi
|
|
if [ ! -d "/etc/$webServerName/sites-available" ];then
|
|
if [ ! -d "/etc/$webServerName/sites-available" ];then
|
|
mkdir "/etc/$webServerName/sites-available" 2>/dev/null
|
|
mkdir "/etc/$webServerName/sites-available" 2>/dev/null
|
|
@@ -916,6 +945,12 @@ instalarVirtualHost() {
|
|
comprobarError $? 908
|
|
comprobarError $? 908
|
|
sed -i '/CustomLog /c\\tCustomLog logs/'"$dominioVirtualHost"'-access.log common' $virtualHostFile
|
|
sed -i '/CustomLog /c\\tCustomLog logs/'"$dominioVirtualHost"'-access.log common' $virtualHostFile
|
|
comprobarError $? 908
|
|
comprobarError $? 908
|
|
|
|
+ if [ $sslOn = true ];then
|
|
|
|
+ sed -i '/SSLCertificateFile /c\\tSSLCertificateFile ssl/'"$dominioVirtualHost"'.crt' $virtualHostFile
|
|
|
|
+ comprobarError $? 908
|
|
|
|
+ sed -i '/SSLCertificateKeyFile /c\\tSSLCertificateKeyFile ssl/'"$dominioVirtualHost"'.key' $virtualHostFile
|
|
|
|
+ comprobarError $? 908
|
|
|
|
+ fi
|
|
elif [ $nginxOn = true ];then
|
|
elif [ $nginxOn = true ];then
|
|
# Configuramos root, dominio, logs y php-fpm.sock (NGINX)
|
|
# Configuramos root, dominio, logs y php-fpm.sock (NGINX)
|
|
sed -i '/root /c\\troot '$rootVirtualHost';' "$virtualHostFile"
|
|
sed -i '/root /c\\troot '$rootVirtualHost';' "$virtualHostFile"
|
|
@@ -928,6 +963,13 @@ instalarVirtualHost() {
|
|
comprobarError $? 908
|
|
comprobarError $? 908
|
|
socket=$(find /var/run/ -type s -name 'php*.sock')
|
|
socket=$(find /var/run/ -type s -name 'php*.sock')
|
|
sed -i '/fastcgi_pass /c\\t\tfastcgi_pass unix:'"$socket"';' $virtualHostFile
|
|
sed -i '/fastcgi_pass /c\\t\tfastcgi_pass unix:'"$socket"';' $virtualHostFile
|
|
|
|
+ comprobarError $? 908
|
|
|
|
+ if [ $sslOn = true ];then
|
|
|
|
+ sed -i '/ssl_certificate /c\\tssl_certificate ssl/'"$dominioVirtualHost"'.crt;' $virtualHostFile
|
|
|
|
+ comprobarError $? 908
|
|
|
|
+ sed -i '/ssl_certificate_key /c\\tssl_certificate_key ssl/'"$dominioVirtualHost"'.key;' $virtualHostFile
|
|
|
|
+ comprobarError $? 908
|
|
|
|
+ fi
|
|
fi
|
|
fi
|
|
# Copiamos ficheros de configuración
|
|
# Copiamos ficheros de configuración
|
|
cp -f $virtualHostFile "/etc/$webServerName/sites-available/$virtualHostName" >> $logFile 2>&1
|
|
cp -f $virtualHostFile "/etc/$webServerName/sites-available/$virtualHostName" >> $logFile 2>&1
|
|
@@ -1230,6 +1272,68 @@ instalarLetsEncrypt() {
|
|
fi
|
|
fi
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+generarCertAutofirmado() {
|
|
|
|
+# Genera certificados autofirmados
|
|
|
|
+# Estos certificados no son seguros, pero valen para pruebas o como paso intermedio para obtener los válidos
|
|
|
|
+# Uso: generarCertAutofirmado $dominio
|
|
|
|
+ dominio=$1
|
|
|
|
+ sslDir="/etc/$webServerName/ssl"
|
|
|
|
+ keyFile="$sslDir/$dominio.key"
|
|
|
|
+ reqFile="$sslDir/$dominio.csr"
|
|
|
|
+ certFile="$sslDir/$dominio.crt"
|
|
|
|
+ if [ ! -d "$sslDir" ];then
|
|
|
|
+ mkdir "$sslDir" 2>/dev/null
|
|
|
|
+ comprobarError $? 5 "$sslDir"
|
|
|
|
+ fi
|
|
|
|
+ # Generamos clave privada RSA de 2048 bits
|
|
|
|
+ openssl genrsa -out "$keyFile" 2048 >/dev/null 2>&1
|
|
|
|
+ comprobarError $? 402
|
|
|
|
+ # Generamos petición de firma
|
|
|
|
+ echo -en "ES\nMadrid\nMadrid\n$dominio\n$dominio\n$dominio\nadmin@$dominio\n\n\n" | openssl req -new -key "$keyFile" -out "$reqFile" >/dev/null 2>&1
|
|
|
|
+ comprobarError $? 402
|
|
|
|
+ # Autofirmados clave para 2 años (730 días)
|
|
|
|
+ openssl x509 -req -days 730 -in "$reqFile" -signkey "$keyFile" -out "$certFile" >/dev/null 2>&1
|
|
|
|
+ comprobarError $? 402
|
|
|
|
+ # Eliminamos petición
|
|
|
|
+ rm -f $reqFile
|
|
|
|
+ comprobarError $? 402
|
|
|
|
+ # Cambiamos permisos
|
|
|
|
+ chmod 644 $certFile
|
|
|
|
+ comprobarError $? 402
|
|
|
|
+ chmod 400 $keyFile
|
|
|
|
+ comprobarError $? 402
|
|
|
|
+ unset dominio sslDir keyFile reqFile certFile
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+generarDHParam() {
|
|
|
|
+# Genera clave de intercambio Diffie-Hellman y lo configuramos
|
|
|
|
+# Esto aumenta notablemente la seguridad de SSL/TLS
|
|
|
|
+ sslDir="/etc/$webServerName/ssl"
|
|
|
|
+ dhParamFile="$sslDir/dhparam.pem"
|
|
|
|
+ apacheConfFile=""
|
|
|
|
+ nginxConfFile="/etc/$webServerName/nginx.conf"
|
|
|
|
+ if [ ! -d "$sslDir" ];then
|
|
|
|
+ mkdir "$sslDir" 2>/dev/null
|
|
|
|
+ comprobarError $? 5 "$sslDir"
|
|
|
|
+ fi
|
|
|
|
+ openssl dhparam -out "$dhParamFile" 2048
|
|
|
|
+ comprobarError $? 403
|
|
|
|
+ # Configuramos Servidor Web
|
|
|
|
+ if [ $apacheOn = true ];then
|
|
|
|
+ if [ $debianOS = true ];then
|
|
|
|
+ apacheConfFile="/etc/$webServerName/apache2.conf"
|
|
|
|
+ elif [ $rhelOS = true ];then
|
|
|
|
+ apacheConfFile="/etc/$webServerName/conf/httpd.conf"
|
|
|
|
+ fi
|
|
|
|
+ echo -en "\n# Set Stronger Diffie-Hellman key exchange\n" >> $apacheConfFile
|
|
|
|
+ echo -en "SSLOpenSSLConfCmd DHParameters \"$dhParamFile\"\n" >> $apacheConfFile
|
|
|
|
+ elif [ $nginxOn = true ];then
|
|
|
|
+ sed -i '/ssl_param /c\\tssl_dhparam '$dhParamFile';' $nginxConfFile
|
|
|
|
+ comprobarError $? 403
|
|
|
|
+ fi
|
|
|
|
+ unset sslDir dhParamFile apacheConfFile nginxConfFile
|
|
|
|
+}
|
|
|
|
+
|
|
habilitarServicio() {
|
|
habilitarServicio() {
|
|
# Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
|
|
# Arrancamos y habilitamos el servicio (con SystemD, Upstart o SystemV)
|
|
# Intentamos con systemctl (SystemD)
|
|
# Intentamos con systemctl (SystemD)
|
|
@@ -1604,15 +1708,16 @@ instalarPHPInfo() {
|
|
}
|
|
}
|
|
|
|
|
|
# Comprobación del sistema e inicialización
|
|
# Comprobación del sistema e inicialización
|
|
-inicializarVariables
|
|
|
|
-comprobarRoot
|
|
|
|
-OSInfo
|
|
|
|
-comprobarDependencias
|
|
|
|
|
|
+ inicializarVariables
|
|
|
|
+ comprobarRoot
|
|
|
|
+ OSInfo
|
|
|
|
+ comprobarDependencias
|
|
|
|
|
|
# Bienvenida
|
|
# Bienvenida
|
|
-mostrarBienvenida
|
|
|
|
|
|
+ mostrarBienvenida
|
|
|
|
+
|
|
# Selección de componentes (express vs avanzada)
|
|
# Selección de componentes (express vs avanzada)
|
|
-mostrarExpress
|
|
|
|
|
|
+ mostrarExpress
|
|
|
|
|
|
# Instalación Servidor Web
|
|
# Instalación Servidor Web
|
|
if [ $apacheOn = true ]; then
|
|
if [ $apacheOn = true ]; then
|
|
@@ -1624,6 +1729,7 @@ mostrarExpress
|
|
instalarNginx
|
|
instalarNginx
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
|
|
+
|
|
# Instalación Base de Datos
|
|
# Instalación Base de Datos
|
|
if [ $mySQLOn = true ]; then
|
|
if [ $mySQLOn = true ]; then
|
|
echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
|
|
echo -en "Instalando Base de Datos MySQL..." | tee -a $logFile
|
|
@@ -1634,6 +1740,7 @@ mostrarExpress
|
|
instalarMariaDB
|
|
instalarMariaDB
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
|
|
+
|
|
# Instalación PHP-7.2
|
|
# Instalación PHP-7.2
|
|
if [ $phpOn = true ]; then
|
|
if [ $phpOn = true ]; then
|
|
echo -en "Instalando PHP-7..." | tee -a $logFile
|
|
echo -en "Instalando PHP-7..." | tee -a $logFile
|
|
@@ -1646,6 +1753,7 @@ mostrarExpress
|
|
instalarLetsEncrypt
|
|
instalarLetsEncrypt
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
|
|
+
|
|
# Configuración Web Server
|
|
# Configuración Web Server
|
|
if [ $apacheOn = true ];then
|
|
if [ $apacheOn = true ];then
|
|
echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
|
|
echo -en "Configurando Servidor Web Apache..." | tee -a $logFile
|
|
@@ -1656,7 +1764,8 @@ mostrarExpress
|
|
configurarNginx
|
|
configurarNginx
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
-# Configuración Database (Arrancar Base de Datos, establecer contraseña y configuración segura)
|
|
|
|
|
|
+
|
|
|
|
+# Configuración Database (Configurar Ficheros, Arrancar Base de Datos, establecer contraseña y configuración segura)
|
|
if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
|
|
if [ $mySQLOn = true ] || [ $mariaDBOn = true ];then
|
|
echo -en "Configurando Base de Datos..." | tee -a $logFile
|
|
echo -en "Configurando Base de Datos..." | tee -a $logFile
|
|
configurarSQL
|
|
configurarSQL
|
|
@@ -1666,37 +1775,44 @@ mostrarExpress
|
|
establecerSQLPasswd
|
|
establecerSQLPasswd
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
|
|
+
|
|
# Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
|
|
# Configuración PHP (cgi.fix_pathinfo=0 y Configurar máximo de subida de archivos)
|
|
if [ $phpOn = true ];then
|
|
if [ $phpOn = true ];then
|
|
echo -en "Configurando PHP-7..." | tee -a $logFile
|
|
echo -en "Configurando PHP-7..." | tee -a $logFile
|
|
configurarPHP
|
|
configurarPHP
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
|
|
+
|
|
# Configuración SSL/TLS
|
|
# Configuración SSL/TLS
|
|
# Generar certificados auto-firmados
|
|
# Generar certificados auto-firmados
|
|
if [ $sslOn = true ];then
|
|
if [ $sslOn = true ];then
|
|
- echo -en "Generando certificados autofirmados..." | tee -a $logFile
|
|
|
|
- sleep 2
|
|
|
|
|
|
+ echo -en "Generando Certificados Auto-Firmados..." | tee -a $logFile
|
|
|
|
+ if [ $mediaWikiOn = true ];then
|
|
|
|
+ generarCertAutofirmado $dominioMediaWiki
|
|
|
|
+ fi
|
|
|
|
+ if [ $moodleOn = true ];then
|
|
|
|
+ generarCertAutofirmado $dominioMoodle
|
|
|
|
+ fi
|
|
|
|
+ if [ $infoPHPOn = true ];then
|
|
|
|
+ generarCertAutofirmado "localhost"
|
|
|
|
+ fi
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
- fi
|
|
|
|
- # Generar certificados Let's Encrypt
|
|
|
|
- if [ $letsEncryptOn = true ];then
|
|
|
|
- echo -en "Generando certificados válidos Let's Encrypt..." | tee -a $logFile
|
|
|
|
- sleep 2
|
|
|
|
|
|
+ echo -en "Generando claves de intercambio Diffie-Hellman (puede llevar un largo tiempo)..." | tee -a $logFile
|
|
|
|
+ generarDHParam
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
|
|
+
|
|
# Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
|
|
# Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
|
|
echo -en "Habilitando todos los servicios..." | tee -a $logFile
|
|
echo -en "Habilitando todos los servicios..." | tee -a $logFile
|
|
- if [ $apacheOn = true ];then
|
|
|
|
- habilitarServicio $webServerName
|
|
|
|
- elif [ $nginxOn = true ];then
|
|
|
|
|
|
+ if [ $apacheOn = true ] || [ $nginxOn = true ];then
|
|
habilitarServicio $webServerName
|
|
habilitarServicio $webServerName
|
|
- if [ $phpOn = true ];then
|
|
|
|
- habilitarServicio $phpFPMName
|
|
|
|
- fi
|
|
|
|
|
|
+ fi
|
|
|
|
+ if [ $nginxOn = true ] && [ $phpOn = true ];then
|
|
|
|
+ habilitarServicio $phpFPMName
|
|
fi
|
|
fi
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
-# MediaWiki
|
|
|
|
|
|
+
|
|
|
|
+# Instalar MediaWiki
|
|
if [ $mediaWikiOn = true ]; then
|
|
if [ $mediaWikiOn = true ]; then
|
|
# Descargar MediaWiki
|
|
# Descargar MediaWiki
|
|
echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
|
|
echo -en "Descargando MediaWiki-1.31.0..." | tee -a $logFile
|
|
@@ -1707,7 +1823,8 @@ mostrarExpress
|
|
configurarMediaWiki
|
|
configurarMediaWiki
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
-# Moodle
|
|
|
|
|
|
+
|
|
|
|
+# Instalar Moodle
|
|
if [ $moodleOn = true ]; then
|
|
if [ $moodleOn = true ]; then
|
|
# Descargar Moodle
|
|
# Descargar Moodle
|
|
echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
|
|
echo -en "Descargando Moodle-3.5.1..." | tee -a $logFile
|
|
@@ -1718,8 +1835,8 @@ mostrarExpress
|
|
configurarMoodle
|
|
configurarMoodle
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
-# Configurar Virtual Hosts
|
|
|
|
- # Instalar info.php
|
|
|
|
|
|
+
|
|
|
|
+# Instalar info.php
|
|
if [ $infoPHPOn = true ];then
|
|
if [ $infoPHPOn = true ];then
|
|
echo -en "Configurando 'info.php'..." | tee -a $logFile
|
|
echo -en "Configurando 'info.php'..." | tee -a $logFile
|
|
instalarPHPInfo
|
|
instalarPHPInfo
|
|
@@ -1729,10 +1846,19 @@ mostrarExpress
|
|
echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
|
|
echo -en " Ya se encuentra configurado.\n" | tee -a $logFile
|
|
fi
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
+
|
|
# Añadir reglas del cortafuegos
|
|
# Añadir reglas del cortafuegos
|
|
echo -en "Configurando Cortafuegos..." | tee -a $logFile
|
|
echo -en "Configurando Cortafuegos..." | tee -a $logFile
|
|
configurarCortafuegos
|
|
configurarCortafuegos
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
echo -en " OK.\n" | tee -a $logFile
|
|
|
|
+
|
|
|
|
+# Generar certificados Let's Encrypt
|
|
|
|
+ if [ $letsEncryptOn = true ];then
|
|
|
|
+ echo -en "Generando Certificados Válidos Let's Encrypt..." | tee -a $logFile
|
|
|
|
+ sleep 2
|
|
|
|
+ echo -en " OK.\n" | tee -a $logFile
|
|
|
|
+ fi
|
|
|
|
+
|
|
# Configurar Backup
|
|
# Configurar Backup
|
|
if [ $backupOn = true ]; then
|
|
if [ $backupOn = true ]; then
|
|
echo -en "Configurando Backup Automático..." | tee -a $logFile
|
|
echo -en "Configurando Backup Automático..." | tee -a $logFile
|