feat: add ipv6 check before installing webclients

Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
dw-0
2024-06-27 17:47:15 +02:00
parent e421a12daf
commit dbe15e3a32
3 changed files with 70 additions and 19 deletions

View File

@@ -13,6 +13,7 @@ from typing import List
from components.webui_client.base_data import BaseWebClient from components.webui_client.base_data import BaseWebClient
from core.menus.base_menu import print_back_footer from core.menus.base_menu import print_back_footer
from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT from utils.constants import COLOR_CYAN, COLOR_YELLOW, RESET_FORMAT
from utils.logger import DialogType, Logger
def print_moonraker_not_found_dialog(): def print_moonraker_not_found_dialog():
@@ -84,25 +85,35 @@ def print_client_port_select_dialog(name: str, port: int, ports_in_use: List[int
print(dialog, end="") print(dialog, end="")
def print_install_client_config_dialog(client: BaseWebClient): def print_install_client_config_dialog(client: BaseWebClient) -> None:
name = client.display_name name = client.display_name
url = client.client_config.repo_url.replace(".git", "") url = client.client_config.repo_url.replace(".git", "")
line1 = f"have {name} fully functional and working." Logger.print_dialog(
line2 = f"The recommended macros for {name} can be seen here:" DialogType.INFO,
dialog = textwrap.dedent( [
f""" f"It is recommended to use special macros in order to have {name} fully "
/=======================================================\\ f"functional and working.",
| It is recommended to use special macros in order to | "\n\n",
| {line1:<54}| f"The recommended macros for {name} can be seen here:",
| | url,
| {line2:<54}| "\n\n",
| {url:<54}| "If you already use these macros skip this step. Otherwise you should "
| | "consider to answer with 'Y' to download the recommended macros.",
| If you already use these macros skip this step. | ],
| Otherwise you should consider to answer with 'Y' to | end="",
| download the recommended macros. | )
\\=======================================================/
"""
)[1:]
print(dialog, end="")
def print_ipv6_warning_dialog() -> None:
Logger.print_dialog(
DialogType.WARNING,
[
"It looks like IPv6 is enabled on this system!",
"This may cause issues with the installation of NGINX in the following "
"steps! It is recommended to disable IPv6 on your system to avoid this issue.",
"\n\n",
"If you think this warning is a false alarm, and you are sure that "
"IPv6 is disabled, you can continue with the installation.",
],
end="",
)

View File

@@ -24,6 +24,7 @@ from components.webui_client.client_config.client_config_setup import (
from components.webui_client.client_dialogs import ( from components.webui_client.client_dialogs import (
print_client_port_select_dialog, print_client_port_select_dialog,
print_install_client_config_dialog, print_install_client_config_dialog,
print_ipv6_warning_dialog,
print_moonraker_not_found_dialog, print_moonraker_not_found_dialog,
) )
from components.webui_client.client_utils import ( from components.webui_client.client_utils import (
@@ -49,6 +50,7 @@ from utils.fs_utils import (
from utils.input_utils import get_confirm, get_number_input from utils.input_utils import get_confirm, get_number_input
from utils.logger import Logger from utils.logger import Logger
from utils.sys_utils import ( from utils.sys_utils import (
check_ipv6,
cmd_sysctl_service, cmd_sysctl_service,
download_file, download_file,
get_ipv4_addr, get_ipv4_addr,
@@ -115,6 +117,13 @@ def install_client(client: BaseWebClient) -> None:
) )
valid_port = is_valid_port(port, ports_in_use) valid_port = is_valid_port(port, ports_in_use)
# check if ipv6 is enabled, as this may cause issues with nginx
if check_ipv6():
print_ipv6_warning_dialog()
if not get_confirm(f"Continue with {client.display_name} installation?"):
Logger.print_info(f"Exiting {client.display_name} installation ...")
return
check_install_dependencies(["nginx", "unzip"]) check_install_dependencies(["nginx", "unzip"])
try: try:

View File

@@ -402,3 +402,34 @@ def log_process(process: Popen) -> None:
if process.poll() is not None: if process.poll() is not None:
break break
def check_ipv6() -> bool:
"""
Check if IPv6 is enabled
:return: True if IPv6 is enabled, False otherwise
"""
try:
file1 = Path("/proc/sys/net/ipv6/conf/all/disable_ipv6")
if file1.exists():
with open(file1, "r") as file:
if file.read().strip() == "0":
return True
elif file.read().strip() == "1":
return False
file3 = Path("/etc/sysctl.conf")
if file3.exists():
with open(file3, "r") as file:
for line in file.readlines():
if (
"net.ipv6.conf.all.disable_ipv6" in line
and not line.startswith("#")
and line.split("=")[1].strip() == "0"
):
return True
return False
except Exception as e:
Logger.print_error(f"Error checking IPv6: {e}")
return True