mirror of
https://github.com/dw-0/kiauh.git
synced 2025-12-11 17:44:28 +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
|
||||
|
||||
[fluidd]
|
||||
port: 81
|
||||
port: 80
|
||||
unstable_releases: False
|
||||
|
||||
@@ -40,20 +40,25 @@ def print_client_already_installed_dialog(name: str) -> None:
|
||||
def print_client_port_select_dialog(
|
||||
name: str, port: int, ports_in_use: List[int]
|
||||
) -> None:
|
||||
Logger.print_dialog(
|
||||
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}",
|
||||
"\n\n",
|
||||
f"In case you need {name} to be served on a specific port, you can set it "
|
||||
f"now. Make sure that the port is not already used by another application "
|
||||
f"on your system!",
|
||||
"\n\n",
|
||||
"The following ports were found to be in use already:",
|
||||
*[f"● {port}" for port in ports_in_use],
|
||||
],
|
||||
)
|
||||
dialog_content: List[str] = [
|
||||
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}",
|
||||
"\n\n",
|
||||
f"In case you need {name} to be served on a specific port, you can set it "
|
||||
f"now. Make sure that the port is not already used by another application "
|
||||
f"on your system!",
|
||||
]
|
||||
|
||||
if ports_in_use:
|
||||
dialog_content.extend(
|
||||
[
|
||||
"\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:
|
||||
|
||||
@@ -23,7 +23,6 @@ from components.webui_client.client_config.client_config_setup import (
|
||||
install_client_config,
|
||||
)
|
||||
from components.webui_client.client_dialogs import (
|
||||
print_client_port_select_dialog,
|
||||
print_install_client_config_dialog,
|
||||
print_moonraker_not_found_dialog,
|
||||
)
|
||||
@@ -33,18 +32,15 @@ from components.webui_client.client_utils import (
|
||||
create_nginx_cfg,
|
||||
detect_client_cfg_conflict,
|
||||
enable_mainsail_remotemode,
|
||||
get_next_free_port,
|
||||
is_valid_port,
|
||||
read_ports_from_nginx_configs,
|
||||
get_client_port_selection,
|
||||
symlink_webui_nginx_log,
|
||||
)
|
||||
from core.instance_manager.instance_manager import InstanceManager
|
||||
from core.logger import Logger
|
||||
from core.settings.kiauh_settings import KiauhSettings
|
||||
from utils.common import check_install_dependencies
|
||||
from utils.config_utils import add_config_section
|
||||
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.sys_utils import (
|
||||
cmd_sysctl_service,
|
||||
@@ -92,21 +88,7 @@ def install_client(client: BaseWebClient) -> None:
|
||||
question = f"Download the recommended {client_config.display_name}?"
|
||||
install_client_cfg = get_confirm(question, allow_go_back=False)
|
||||
|
||||
settings = KiauhSettings()
|
||||
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)
|
||||
port: int = get_client_port_selection(client)
|
||||
|
||||
check_install_dependencies({"nginx"})
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ from components.webui_client.base_data import (
|
||||
BaseWebClient,
|
||||
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.mainsail_data import MainsailData
|
||||
from core.backup_manager.backup_manager import BackupManager
|
||||
@@ -33,7 +34,7 @@ from core.constants import (
|
||||
RESET_FORMAT,
|
||||
)
|
||||
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 (
|
||||
SimpleConfigParser,
|
||||
)
|
||||
@@ -44,6 +45,7 @@ from utils.git_utils import (
|
||||
get_latest_remote_tag,
|
||||
get_latest_unstable_tag,
|
||||
)
|
||||
from utils.input_utils import get_number_input
|
||||
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))
|
||||
|
||||
|
||||
def is_valid_port(port: int, ports_in_use: List[int]) -> bool:
|
||||
return port not in ports_in_use
|
||||
def get_client_port_selection(client: BaseWebClient) -> int:
|
||||
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:
|
||||
|
||||
Reference in New Issue
Block a user