Refactored to Selection Menu and Warning
This commit is contained in:
parent
ff321b63d1
commit
fd50d54a70
|
|
@ -76,6 +76,7 @@ class ApplicationMenu(AbstractSubMenu[ApplicationConfiguration]):
|
|||
MenuItem(
|
||||
text=tr('Firewall'),
|
||||
action=select_firewall,
|
||||
value=self._app_config.firewall_config,
|
||||
preview_action=self._prev_firewall,
|
||||
key='firewall_config',
|
||||
),
|
||||
|
|
@ -121,7 +122,9 @@ class ApplicationMenu(AbstractSubMenu[ApplicationConfiguration]):
|
|||
def _prev_firewall(self, item: MenuItem) -> str | None:
|
||||
if item.value is not None:
|
||||
config: FirewallConfiguration = item.value
|
||||
return f'{tr("Firewall")}: {config.firewall.value}'
|
||||
output = f'{tr("Firewall")}: {config.firewall.value}'
|
||||
output += '\n'
|
||||
output += f'{tr("Allow SSH")}: {config.allow_ssh}'
|
||||
return None
|
||||
|
||||
def _prev_fonts(self, item: MenuItem) -> str | None:
|
||||
|
|
@ -230,7 +233,28 @@ async def select_firewall(preset: FirewallConfiguration | None = None) -> Firewa
|
|||
case ResultType.Skip:
|
||||
return preset
|
||||
case ResultType.Selection:
|
||||
return FirewallConfiguration(firewall=result.get_value())
|
||||
selected_firewall = result.get_value()
|
||||
header = tr('Would you like to allow incoming SSH connections through the firewall?') + '\n'
|
||||
preset_ssh = preset.allow_ssh if preset else False
|
||||
|
||||
ssh_result = await Confirmation(
|
||||
header=header,
|
||||
allow_skip=True,
|
||||
preset=preset_ssh,
|
||||
).show()
|
||||
|
||||
match ssh_result.type_:
|
||||
case ResultType.Skip:
|
||||
allow_ssh = preset_ssh
|
||||
case ResultType.Selection:
|
||||
allow_ssh = ssh_result.get_value()
|
||||
case ResultType.Reset:
|
||||
allow_ssh = False
|
||||
|
||||
return FirewallConfiguration(
|
||||
firewall=selected_firewall,
|
||||
allow_ssh=allow_ssh,
|
||||
)
|
||||
case ResultType.Reset:
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -9,32 +9,6 @@ from archinstall.tui.menu_item import MenuItem, MenuItemGroup
|
|||
from archinstall.tui.result import ResultType
|
||||
|
||||
|
||||
async def confirm_ufw(config: ArchConfig) -> bool:
|
||||
firewall_config = config.app_config.firewall_config
|
||||
is_ufw = firewall_config and firewall_config.firewall and firewall_config.firewall.value == 'ufw'
|
||||
has_openssh = 'openssh' in config.packages
|
||||
|
||||
if not (is_ufw and has_openssh):
|
||||
return True
|
||||
|
||||
else:
|
||||
header = f'{tr("You have both ufw and OpenSSH in your packages")}. '
|
||||
header += tr('Would you like to allow incoming SSH connections through the firewall?') + '\n'
|
||||
group = MenuItemGroup.yes_no()
|
||||
|
||||
result = await Confirmation(
|
||||
group=group,
|
||||
header=header,
|
||||
allow_skip=False,
|
||||
preset=True,
|
||||
).show()
|
||||
|
||||
if result and result.get_value():
|
||||
config.app_config.firewall_config.allow_ssh = True
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def confirm_config(config: ArchConfig) -> bool:
|
||||
header = f'{tr("The specified configuration will be applied")}. '
|
||||
header += tr('Would you like to continue?') + '\n'
|
||||
|
|
|
|||
|
|
@ -364,6 +364,8 @@ class GlobalMenu(AbstractMenu[None]):
|
|||
firewall_config = app_config.firewall_config
|
||||
output += f'{tr("Firewall")}: {firewall_config.firewall.value}'
|
||||
output += '\n'
|
||||
output += f'{tr("Allow SSH")}: {firewall_config.allow_ssh}'
|
||||
output += '\n'
|
||||
|
||||
return output
|
||||
|
||||
|
|
@ -500,6 +502,13 @@ class GlobalMenu(AbstractMenu[None]):
|
|||
if not isinstance(self._arch_config.network_config, NetworkConfiguration):
|
||||
warnings.append(tr('No network configuration selected. Network will need to be set up manually on the installed system.'))
|
||||
|
||||
firewall_config = self._arch_config.app_config.firewall_config
|
||||
is_ufw = firewall_config and firewall_config.firewall and firewall_config.firewall.value == 'ufw'
|
||||
has_openssh = 'openssh' in self._arch_config.packages
|
||||
|
||||
if is_ufw and has_openssh and not firewall_config.allow_ssh:
|
||||
warnings.append(tr('SSH not allowed through ufw. Rules will need to be set up manually on the installed system.'))
|
||||
|
||||
return warnings
|
||||
|
||||
def _prev_install_invalid_config(self, item: MenuItem) -> PreviewResult | None:
|
||||
|
|
|
|||
|
|
@ -287,7 +287,7 @@ class ApplicationConfiguration(SubConfig):
|
|||
if self.firewall_config:
|
||||
out.append(tr('Firewall "{}"').format(self.firewall_config.firewall))
|
||||
if self.firewall_config.allow_ssh:
|
||||
out.append({tr('SSH allowed')})
|
||||
out.append(tr('SSH allowed'))
|
||||
|
||||
if self.fonts_config and self.fonts_config.fonts:
|
||||
fonts = ', '.join(f.value for f in self.fonts_config.fonts)
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ from archinstall.lib.applications.application_handler import ApplicationHandler
|
|||
from archinstall.lib.args import ArchConfig, ArchConfigHandler
|
||||
from archinstall.lib.authentication.authentication_handler import AuthenticationHandler
|
||||
from archinstall.lib.bootloader.utils import validate_bootloader_layout
|
||||
from archinstall.lib.configuration import confirm_config, confirm_ufw
|
||||
from archinstall.lib.configuration import confirm_config
|
||||
from archinstall.lib.disk.filesystem import FilesystemHandler
|
||||
from archinstall.lib.disk.utils import disk_layouts
|
||||
from archinstall.lib.general.general_menu import PostInstallationAction, select_post_installation
|
||||
|
|
@ -230,7 +230,6 @@ def main(arch_config_handler: ArchConfigHandler | None = None) -> None:
|
|||
|
||||
if not arch_config_handler.args.silent:
|
||||
aborted = False
|
||||
tui.run(lambda: confirm_ufw(arch_config_handler.config))
|
||||
res: bool = tui.run(lambda: confirm_config(arch_config_handler.config))
|
||||
|
||||
if not res:
|
||||
|
|
|
|||
Loading…
Reference in New Issue