mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-13 18:44:29 +05:00
refactor: do not silently configure Fluidd for port 81 (#582)
* refactor: use port 80 as default for fluidd Signed-off-by: Dominik Willner <th33xitus@gmail.com> * refactor: improve port selection logic, write last port selection for client to kiauh.cfg Signed-off-by: Dominik Willner <th33xitus@gmail.com> --------- Signed-off-by: Dominik Willner <th33xitus@gmail.com>
This commit is contained in:
@@ -14,5 +14,5 @@ port: 80
|
|||||||
unstable_releases: False
|
unstable_releases: False
|
||||||
|
|
||||||
[fluidd]
|
[fluidd]
|
||||||
port: 81
|
port: 80
|
||||||
unstable_releases: False
|
unstable_releases: False
|
||||||
|
|||||||
@@ -40,20 +40,25 @@ def print_client_already_installed_dialog(name: str) -> None:
|
|||||||
def print_client_port_select_dialog(
|
def print_client_port_select_dialog(
|
||||||
name: str, port: int, ports_in_use: List[int]
|
name: str, port: int, ports_in_use: List[int]
|
||||||
) -> None:
|
) -> None:
|
||||||
Logger.print_dialog(
|
dialog_content: List[str] = [
|
||||||
DialogType.CUSTOM,
|
f"Please select the port, {name} should be served on. If your are unsure "
|
||||||
[
|
f"what to select, hit Enter to apply the suggested value of: {port}",
|
||||||
f"Please select the port, {name} should be served on. If your are unsure "
|
"\n\n",
|
||||||
f"what to select, hit Enter to apply the suggested value of: {port}",
|
f"In case you need {name} to be served on a specific port, you can set it "
|
||||||
"\n\n",
|
f"now. Make sure that the port is not already used by another application "
|
||||||
f"In case you need {name} to be served on a specific port, you can set it "
|
f"on your system!",
|
||||||
f"now. Make sure that the port is not already used by another application "
|
]
|
||||||
f"on your system!",
|
|
||||||
"\n\n",
|
if ports_in_use:
|
||||||
"The following ports were found to be in use already:",
|
dialog_content.extend(
|
||||||
*[f"● {port}" for port in ports_in_use],
|
[
|
||||||
],
|
"\n\n",
|
||||||
)
|
"The following ports were found to be in use already:",
|
||||||
|
*[f"● {port}" for port in ports_in_use],
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
Logger.print_dialog(DialogType.CUSTOM, dialog_content)
|
||||||
|
|
||||||
|
|
||||||
def print_install_client_config_dialog(client: BaseWebClient) -> None:
|
def print_install_client_config_dialog(client: BaseWebClient) -> None:
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ from components.webui_client.client_config.client_config_setup import (
|
|||||||
install_client_config,
|
install_client_config,
|
||||||
)
|
)
|
||||||
from components.webui_client.client_dialogs import (
|
from components.webui_client.client_dialogs import (
|
||||||
print_client_port_select_dialog,
|
|
||||||
print_install_client_config_dialog,
|
print_install_client_config_dialog,
|
||||||
print_moonraker_not_found_dialog,
|
print_moonraker_not_found_dialog,
|
||||||
)
|
)
|
||||||
@@ -33,18 +32,15 @@ from components.webui_client.client_utils import (
|
|||||||
create_nginx_cfg,
|
create_nginx_cfg,
|
||||||
detect_client_cfg_conflict,
|
detect_client_cfg_conflict,
|
||||||
enable_mainsail_remotemode,
|
enable_mainsail_remotemode,
|
||||||
get_next_free_port,
|
get_client_port_selection,
|
||||||
is_valid_port,
|
|
||||||
read_ports_from_nginx_configs,
|
|
||||||
symlink_webui_nginx_log,
|
symlink_webui_nginx_log,
|
||||||
)
|
)
|
||||||
from core.instance_manager.instance_manager import InstanceManager
|
from core.instance_manager.instance_manager import InstanceManager
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
|
||||||
from utils.common import check_install_dependencies
|
from utils.common import check_install_dependencies
|
||||||
from utils.config_utils import add_config_section
|
from utils.config_utils import add_config_section
|
||||||
from utils.fs_utils import unzip
|
from utils.fs_utils import unzip
|
||||||
from utils.input_utils import get_confirm, get_number_input
|
from utils.input_utils import get_confirm
|
||||||
from utils.instance_utils import get_instances
|
from utils.instance_utils import get_instances
|
||||||
from utils.sys_utils import (
|
from utils.sys_utils import (
|
||||||
cmd_sysctl_service,
|
cmd_sysctl_service,
|
||||||
@@ -92,21 +88,7 @@ def install_client(client: BaseWebClient) -> None:
|
|||||||
question = f"Download the recommended {client_config.display_name}?"
|
question = f"Download the recommended {client_config.display_name}?"
|
||||||
install_client_cfg = get_confirm(question, allow_go_back=False)
|
install_client_cfg = get_confirm(question, allow_go_back=False)
|
||||||
|
|
||||||
settings = KiauhSettings()
|
port: int = get_client_port_selection(client)
|
||||||
port: int = settings.get(client.name, "port")
|
|
||||||
ports_in_use: List[int] = read_ports_from_nginx_configs()
|
|
||||||
|
|
||||||
# check if configured port is a valid number and not in use already
|
|
||||||
valid_port = is_valid_port(port, ports_in_use)
|
|
||||||
while not valid_port:
|
|
||||||
next_port = get_next_free_port(ports_in_use)
|
|
||||||
print_client_port_select_dialog(client.display_name, next_port, ports_in_use)
|
|
||||||
port = get_number_input(
|
|
||||||
f"Configure {client.display_name} for port",
|
|
||||||
min_count=int(next_port),
|
|
||||||
default=next_port,
|
|
||||||
)
|
|
||||||
valid_port = is_valid_port(port, ports_in_use)
|
|
||||||
|
|
||||||
check_install_dependencies({"nginx"})
|
check_install_dependencies({"nginx"})
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from components.webui_client.base_data import (
|
|||||||
BaseWebClient,
|
BaseWebClient,
|
||||||
WebClientType,
|
WebClientType,
|
||||||
)
|
)
|
||||||
|
from components.webui_client.client_dialogs import print_client_port_select_dialog
|
||||||
from components.webui_client.fluidd_data import FluiddData
|
from components.webui_client.fluidd_data import FluiddData
|
||||||
from components.webui_client.mainsail_data import MainsailData
|
from components.webui_client.mainsail_data import MainsailData
|
||||||
from core.backup_manager.backup_manager import BackupManager
|
from core.backup_manager.backup_manager import BackupManager
|
||||||
@@ -33,7 +34,7 @@ from core.constants import (
|
|||||||
RESET_FORMAT,
|
RESET_FORMAT,
|
||||||
)
|
)
|
||||||
from core.logger import Logger
|
from core.logger import Logger
|
||||||
from core.settings.kiauh_settings import KiauhSettings
|
from core.settings.kiauh_settings import KiauhSettings, WebUiSettings
|
||||||
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
from core.submodules.simple_config_parser.src.simple_config_parser.simple_config_parser import (
|
||||||
SimpleConfigParser,
|
SimpleConfigParser,
|
||||||
)
|
)
|
||||||
@@ -44,6 +45,7 @@ from utils.git_utils import (
|
|||||||
get_latest_remote_tag,
|
get_latest_remote_tag,
|
||||||
get_latest_unstable_tag,
|
get_latest_unstable_tag,
|
||||||
)
|
)
|
||||||
|
from utils.input_utils import get_number_input
|
||||||
from utils.instance_utils import get_instances
|
from utils.instance_utils import get_instances
|
||||||
|
|
||||||
|
|
||||||
@@ -368,8 +370,29 @@ def read_ports_from_nginx_configs() -> List[int]:
|
|||||||
return sorted(ports_to_ints_list, key=lambda x: int(x))
|
return sorted(ports_to_ints_list, key=lambda x: int(x))
|
||||||
|
|
||||||
|
|
||||||
def is_valid_port(port: int, ports_in_use: List[int]) -> bool:
|
def get_client_port_selection(client: BaseWebClient) -> int:
|
||||||
return port not in ports_in_use
|
settings = KiauhSettings()
|
||||||
|
default_port: int = int(settings.get(client.name, "port"))
|
||||||
|
|
||||||
|
ports_in_use: List[int] = read_ports_from_nginx_configs()
|
||||||
|
next_free_port: int = get_next_free_port(ports_in_use)
|
||||||
|
|
||||||
|
port: int = next_free_port if default_port in ports_in_use else default_port
|
||||||
|
|
||||||
|
print_client_port_select_dialog(client.display_name, port, ports_in_use)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
question = f"Configure {client.display_name} for port"
|
||||||
|
port_input = get_number_input(question, min_count=80, default=port)
|
||||||
|
|
||||||
|
if port_input not in ports_in_use:
|
||||||
|
client_settings: WebUiSettings = settings[client.name]
|
||||||
|
client_settings.port = port_input
|
||||||
|
settings.save()
|
||||||
|
|
||||||
|
return port_input
|
||||||
|
|
||||||
|
Logger.print_error("This port is already in use. Please select another one.")
|
||||||
|
|
||||||
|
|
||||||
def get_next_free_port(ports_in_use: List[int]) -> int:
|
def get_next_free_port(ports_in_use: List[int]) -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user