Przeglądaj źródła

* Añadidos VirtualHosts para Moodle
* Cambio en VirtualHost de MediaWiki
* configurarMoodle()
* mostrarMoodle()

Guzmán Castanedo Villalba 6 lat temu
rodzic
commit
59a1837a36

+ 10 - 0
etc/apache2/sites-available/moodle.conf

@@ -0,0 +1,10 @@
+<VirtualHost _default_:80>
+	ServerName localhost
+	DocumentRoot /var/www/mediawiki
+
+	ErrorLog logs/error.log
+	LogFormat "%h %l %u %t \"%r\" %>s %b" common
+	CustomLog logs/access.log common
+
+</VirtualHost>
+

+ 0 - 4
etc/nginx/sites-available/mediawiki.conf

@@ -13,10 +13,6 @@ server {
 	access_log /var/log/nginx/wiki-access.log;
 	error_log /var/log/nginx/wiki-error.log;
 
-	# Activate HSTS (HTTP Strict Transport Security)
-	# Note: reinclude if in a location a header is set
-	include snippets/hsts.conf;
-
 	# Allow favicon.ico, robots.txt, .well-known/
 	# Deny *.txt, *.log, .*/*.php, .*, *.json, .lock, *.ht
 	include snippets/allowed.conf;

+ 65 - 0
etc/nginx/sites-available/moodle-ssl.conf

@@ -0,0 +1,65 @@
+
+server {
+	listen 80;
+	listen [::]:80;
+	server_name localhost;
+	# Redirect HTTP to HTTPS
+	return 301 https://$host$request_uri;
+}
+
+server {
+	# SSL configuration
+	#
+	listen 443 ssl;
+	listen [::]:443;
+    ssl_certificate /etc/letsencrypt/live/wiki.castanedo.es/fullchain.pem; # managed by Certbot
+    ssl_certificate_key /etc/letsencrypt/live/wiki.castanedo.es/privkey.pem; # managed by Certbot
+	#
+	# Note: You should disable gzip for SSL traffic.
+	# See: https://bugs.debian.org/773332
+	#
+	# Read up on ssl_ciphers to ensure a secure configuration.
+	# See: https://bugs.debian.org/765782
+	#
+	# Self signed certs generated by the ssl-cert package
+	# Don't use them in a production server!
+	#
+	# include snippets/snakeoil.conf;
+
+	root /var/www/moodle;
+
+	# Add index.php to the list if you are using PHP
+	index index.php index.html index.htm;
+
+	server_name localhost;
+
+	access_log /var/log/nginx/moodle-access.log;
+	error_log /var/log/nginx/moodle-error.log;
+
+	# Activate HSTS (HTTP Strict Transport Security)
+	# Note: reinclude if in a location a header is set
+	include snippets/hsts.conf;
+
+	# Allow favicon.ico, robots.txt, .well-known/
+	# Deny *.txt, *.log, .*/*.php, .*, *.json, .lock, *.ht
+	include snippets/allowed.conf;
+	include snippets/denied.conf;
+
+	location / {
+		# First attempt to serve request as file, then
+		# as directory, then fall back to displaying a 404.
+		try_files $uri $uri/ =404;
+	}
+
+	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+	#
+	location ~ [^/]\.php(/|$) {
+		fastcgi_split_path_info ^(.+\.php)(/.+)$;
+		fastcgi_index index.php;
+		fastcgi_pass unix:/run/php/php7.2-fpm.sock;
+		include fastcgi_params;
+		fastcgi_param PATH_INFO $fastcgi_path_info;
+		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+	}
+}
+

+ 38 - 0
etc/nginx/sites-available/moodle.conf

@@ -0,0 +1,38 @@
+
+server {
+	listen 80;
+	listen [::]:80;
+
+	root /var/www/moodle;
+
+	# Add index.php to the list if you are using PHP
+	index index.php index.html index.htm;
+
+	server_name localhost;
+
+	access_log /var/log/nginx/moodle-access.log;
+	error_log /var/log/nginx/moodle-error.log;
+
+	# Allow favicon.ico, robots.txt, .well-known/
+	# Deny *.txt, *.log, .*/*.php, .*, *.json, .lock, *.ht
+	include snippets/allowed.conf;
+	include snippets/denied.conf;
+
+	location / {
+		# First attempt to serve request as file, then
+		# as directory, then fall back to displaying a 404.
+		try_files $uri $uri/ =404;
+	}
+
+	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
+	#
+	location ~ [^/]\.php(/|$) {
+		fastcgi_split_path_info ^(.+\.php)(/.+)$;
+		fastcgi_index index.php;
+		fastcgi_pass unix:/run/php/php7.2-fpm.sock;
+		include fastcgi_params;
+		fastcgi_param PATH_INFO $fastcgi_path_info;
+		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+	}
+}
+

+ 59 - 6
install

@@ -484,6 +484,8 @@ inicializarVariables() {
 	phpFPMName=""
 	nombreMediaWiki=""
 	dominioMediaWiki=""
+	nombreMoodle=""
+	dominioMoodle=""
 }
 
 instalacionExpress() {
@@ -587,6 +589,7 @@ mostrarComponentes() {
 				;;
 			\"Moodle\")
 				moodleOn=true
+				mostrarMoodle
 				progresoTotal=$((progresoTotal + 2))
 				;;
 			\"InfoPHP\")
@@ -672,7 +675,37 @@ mostrarMediaWiki(){
 			control=true
 		fi
 	done
-	unset control error passwdMediaWiki2 cont serverName
+	unset control error passwdMediaWiki2 dominio cont serverName
+}
+
+mostrarMoodle() {
+	# Introducir nombre Moodle
+	while [ -z "$nombreMoodle" ]; do
+		nombreMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el nombre del campus virtual:" $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
+		comprobarError $? 1
+		# Mejora: comprobar si el dominio ya está en uso
+	done
+	# Introducir dominio
+	while [ -z "$dominioMoodle" ]; do
+		dominioMoodle=$(whiptail --title "CONFIGURACION MOODLE" --inputbox "Introduzca el dominio/subdominio del campus virtual.\nMoodle SÓLO permite un ÚNICO DOMINIO." $((ALTO * 9 / 10)) $((ANCHO * 9 / 10)) moodle.$hostname --ok-button "Continuar" --cancel-button "Salir" 3>&1 1>&2 2>&3)
+		comprobarError $? 1
+		# Mejora: comprobar si el dominio ya está en uso
+	done
+	cont=1
+	serverName=""
+	aliasMoodle=""
+	for dominio in $dominioMoodle;do
+		if [ $cont -eq 1 ];then
+			# Dominio Principal (ServerName)
+			serverName=$dominio
+		else
+			# Dominios Secundarios (ServerAlias)
+			aliasMeoodle=$aliasMoodle" "$dominio
+		fi
+		cont=$((cont + 1))
+	done
+	dominioMoodle=$serverName
+	unset dominio cont serverName aliasMoodle
 }
 
 establecerFQDN() {
@@ -850,7 +883,7 @@ instalarVirtualHost() {
 	ln -s "/etc/$webServerName/sites-available/$virtualHostName" "/etc/$webServerName/sites-enabled/$virtualHostName" >> $logFile 2>&1
 	comprobarError $? 911 $virtualHostName
 	recargarServicio $webServerName
-	unset rootVirtualHost dominioVirtualHost virtualHostFile virtualHostName aliasVirtualHost
+	unset rootVirtualHost dominioVirtualHost virtualHostFile virtualHostName aliasVirtualHost socket
 }
 
 mostrarDatabase() {
@@ -1374,7 +1407,7 @@ configurarMediaWiki() {
 			comprobarError $? 502
 		fi
 		instalarVirtualHost "/var/www/$dominioMediaWiki" $virtualHost $dominioMediaWiki $aliasMediaWiki
-		unset virtualHost socket
+		unset virtualHost
 	else
 		comprobarError 1 503 $dominioMediaWiki
 	fi
@@ -1396,15 +1429,33 @@ configurarMoodle() {
 	# Configurar Moodle
 	if [ ! -f /var/www/$dominioMoodle/config.php ];then
 		# Copiamos archivos
-		cp -fR ./var/moodle/ /var/www/$dominioMoodle
+		cp -Rf ./var/moodle/ /var/www/$dominioMoodle
 		comprobarError $? 602
 		# Crear carperta de datos (no online)
+		if [ ! -d /var/www/moodledata ];then
+			mkdir /var/www/moodledata 2>/dev/null
+			comprobarError $? 602
+		fi
 		# Creamos Base de Datos
 		nombreDBMo=$(echo $dominioMoodle | sed -e 's/\./_/g')
 		userDBMo=$(echo $dominioMoodle | sed -e 's/\./_/g')
 		crearDBMoodle
 		# Actualizamos permisos
-		chown -R $webServerUser:$webServerGroup /var/www/$dominioMoodle
+		chown -R $webServerUser:$webServerGroup /var/www/$dominioMoodle /var/www/moodledata
+		# Configuramos VirtualHost
+		if [ $apacheOn = true ] && [ $sslOn = false ];then
+			virtualHost="./etc/apache2/sites-available/moodle.conf"
+		elif [ $nginxOn = true ] && [ $sslOn = false ];then
+			virtualHost="./etc/nginx/sites-available/moodle.conf"
+		elif [ $apacheOn = true ] && [ $sslOn = true ];then
+			virtualHost="./etc/apache2/sites-available/moodle-ssl.conf"
+		elif [ $nginxOn = true ] && [ $sslOn = true ];then
+			virtualHost="./etc/nginx/sites-available/moodle-ssl.conf"
+		else
+			comprobarError 1 602
+		fi
+		instalarVirtualHost "/var/www/$dominioMoodle" $virtualHost $dominioMoodle
+		unset virtualHost
 	else
 		comprobarError 1 603 $dominioMoodle
 	fi
@@ -1554,6 +1605,7 @@ mostrarExpress
 		echo -en " OK.\n" | tee -a $logFile
 	fi
 # Arrancar y habilitar todos los servicios (SystemD, Service o SystemV)
+	echo -en "Habilitando todos los servicios..." | tee -a $logFile
 #	{
 #		echo -en "%s\n" $((100 * progreso / progresoTotal))
 		if [ $apacheOn = true ];then
@@ -1566,6 +1618,7 @@ mostrarExpress
 		fi
 		progreso=$((progreso + 1))
 #	} > >(whiptail --gauge "Arrancando Servicios..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
+	echo -en " OK.\n" | tee -a $logFile
 # MediaWiki
 	if [ $mediaWikiOn = true ]; then
 		# Descargar MediaWiki
@@ -1599,7 +1652,7 @@ mostrarExpress
 		echo -en "Configurando Moodle..." | tee -a $logFile
 #		{
 #			echo -en "%s\n" $((100 * progreso / progresoTotal))
-			#configurarMoodle
+			configurarMoodle
 			progreso=$((progreso + 1))
 #		} > >(whiptail --gauge "Configurando Moodle..." $((ALTO * 4 / 10)) $((ANCHO * 9 / 10)) $((100 * progreso / progresoTotal)))
 		echo -en " OK.\n" | tee -a $logFile