From 3b536baa7a57a08b27a38930c5bd77eba50f7fee Mon Sep 17 00:00:00 2001 From: lgromero Date: Wed, 3 Jul 2024 15:53:06 +0200 Subject: [PATCH] refs #477 Adds change of user to nginx conf --- installer/ogboot_installer.py | 79 ++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 33 deletions(-) diff --git a/installer/ogboot_installer.py b/installer/ogboot_installer.py index 1c0b136..bc64553 100755 --- a/installer/ogboot_installer.py +++ b/installer/ogboot_installer.py @@ -863,39 +863,52 @@ print(get_network_interfaces()) #exit (0) def setup_nginx(): - try: - # Obtener la IP del servidor - ip_address_server = subprocess.check_output(["ifconfig", "ens160"]).decode().split("\n")[1].split()[1] - - # Leer y modificar la plantilla de configuración de nginx - template_path = os.path.join(WORKDIR, "ogboot/etc/nginxServer.conf.tmpl") - with open(template_path, 'r') as nginx_file: - nginx_content = nginx_file.read() - - nginx_content = nginx_content.replace("__SERVERIP__", ip_address_server) - - # Ruta de destino para la configuración de nginx - nginx_output = "/etc/nginx/sites-available/ogboot.conf" - with open(nginx_output, 'w') as nginx_file: - nginx_file.write(nginx_content) - - logger.info("Nginx configuration file created successfully.") - - # Crear el enlace simbólico en sites-enabled - subprocess.run(["sudo", "ln", "-sf", nginx_output, "/etc/nginx/sites-enabled/ogboot.conf"]) - - logger.info("Symbolic link for nginx configuration created successfully.") - - # Reiniciar el servicio de samba - subprocess.run(["sudo", "systemctl", "restart", "smbd.service"]) - - logger.info("Samba service restarted successfully.") - except subprocess.CalledProcessError as e: - logger.error(f"Subprocess error: {e}") - exit(1) - except OSError as e: - logger.error(f"OS error: {e}") - exit(1) + try: + # Obtener la IP del servidor + ip_address_server = subprocess.check_output(["ifconfig", "ens160"]).decode().split("\n")[1].split()[1] + + # Leer y modificar la plantilla de configuración de nginx + template_path = os.path.join(WORKDIR, "ogboot/etc/nginxServer.conf.tmpl") + with open(template_path, 'r') as nginx_file: + nginx_content = nginx_file.read() + + nginx_content = nginx_content.replace("__SERVERIP__", ip_address_server) + + # Ruta de destino para la configuración de nginx + nginx_output = "/etc/nginx/sites-available/ogboot.conf" + with open(nginx_output, 'w') as nginx_file: + nginx_file.write(nginx_content) + + logger.info("Nginx configuration file created successfully.") + + # Crear el enlace simbólico en sites-enabled + subprocess.run(["sudo", "ln", "-sf", nginx_output, "/etc/nginx/sites-enabled/ogboot.conf"]) + + logger.info("Symbolic link for nginx configuration created successfully.") + + # Reiniciar el servicio de samba + subprocess.run(["sudo", "systemctl", "restart", "smbd.service"]) + + logger.info("Samba service restarted successfully.") + + # Modificar el archivo de configuración de nginx para ejecutarse como ogboot + nginx_conf_path = "/etc/nginx/nginx.conf" + with open(nginx_conf_path, 'r') as nginx_conf_file: + nginx_conf_content = nginx_conf_file.read() + + nginx_conf_content = nginx_conf_content.replace("user www-data;", "user ogboot;") + + with open(nginx_conf_path, 'w') as nginx_conf_file: + nginx_conf_file.write(nginx_conf_content) + + logger.info("Nginx configuration file modified to run as ogboot.") + + except subprocess.CalledProcessError as e: + logger.error(f"Subprocess error: {e}") + exit(1) + except OSError as e: + logger.error(f"OS error: {e}") + exit(1) def get_php_fpm_version(): try: