feature: the VPN, the router, the name server and WebDAV are components switched on the System tab and installed on demand, Caddy from the Ubuntu archive is a dependency and serves every HTTP and HTTPS port, HTTPS is chosen at install, its certificate is of the Servers Issuing CA or self-signed by default, of ACME or of another CA, the issuing CAs are in one tab, a locked account is unlocked again, the name of a CA is fixed once the CA exists, and a run of setup is no longer cut short by a change.
Release / release (push) Failing after 8s
Release / release (push) Failing after 8s
This commit is contained in:
1 parent
a649331aa2
commit
a7bfabcb89
97 files changed
+4498
-1834
No files matched your search
@@ -0,0 +1,83 @@
|
||||
"""/components: the installable components of the server, which the Manager's System tab switches."""
|
||||
|
||||
import linuxmanager
|
||||
import linuxmanager_net
|
||||
|
||||
from .common import settings_change, unit_state
|
||||
|
||||
|
||||
def router_choices(cfg):
|
||||
"""The interfaces the router may take as its internal one: the NICs but the external interface."""
|
||||
external = cfg['interfaces']['external'].strip()
|
||||
if not external and (cfg['general']['mode'] or 'manual') == 'auto':
|
||||
try:
|
||||
external, _ = linuxmanager_net.detect_interfaces(internal=False)
|
||||
except linuxmanager_net.ConfigError:
|
||||
external = ''
|
||||
return [name for name in linuxmanager_net.nics() if name != external]
|
||||
|
||||
|
||||
def listing(cfg):
|
||||
"""Each component of linuxmanager.COMPONENTS: {name, enabled, state}, state being installing or failed while its
|
||||
installation unit is, else installed or not installed; the router also has available, whether the server has an
|
||||
interface for its internal side or the router is on, the interfaces to choose from, general.mode and its current
|
||||
internal_interface, int_addr and int_gateway_ip."""
|
||||
found = []
|
||||
for name, (_, packages) in linuxmanager.COMPONENTS.items():
|
||||
unit = unit_state(f'linux-manager-install@{name}.service')
|
||||
state = {'activating': 'installing', 'active': 'installing', 'failed': 'failed'}.get(unit) or \
|
||||
('installed' if linuxmanager.packages_installed(packages) else 'not installed')
|
||||
entry = {'name': name, 'enabled': linuxmanager.component_on(cfg, name), 'state': state}
|
||||
if name == 'router':
|
||||
choices = router_choices(cfg)
|
||||
entry.update({'available': entry['enabled'] or bool(choices), 'interfaces': choices,
|
||||
'mode': cfg['general']['mode'] or 'manual',
|
||||
'internal_interface': cfg['interfaces']['internal'].strip(),
|
||||
'int_addr': cfg['local']['int_addr'].strip(),
|
||||
'int_gateway_ip': cfg['local']['int_gateway_ip'].strip()})
|
||||
found.append(entry)
|
||||
return found
|
||||
|
||||
|
||||
def components(method, path, body):
|
||||
"""Answer a /components request: the HTTP status and the JSON document.
|
||||
|
||||
GET /components {"components": [...]} (listing)
|
||||
PUT /components/<name> switch a component: {"enabled"}, for the router switched on also "internal_interface",
|
||||
"int_addr" and "int_gateway_ip" as general.mode needs them; {"components": [...]}
|
||||
|
||||
A switched-on component's packages are installed by linux-manager-setup (linux-manager-install@<name>), which a
|
||||
change starts without waiting for it; switching a component off removes no package. The configuration's validation
|
||||
refuses a change it does not allow, such as the VPN off while IKEv2, OpenVPN or WireGuard is on.
|
||||
"""
|
||||
if body == 'invalid' or (body is not None and not isinstance(body, dict)):
|
||||
return 400, {'error': 'the body must be a JSON object'}
|
||||
body = body or {}
|
||||
parts = path.strip('/').split('/')
|
||||
cfg = linuxmanager.load_config()
|
||||
if method in ('GET', 'HEAD') and parts == ['components']:
|
||||
return 200, {'components': listing(cfg)}
|
||||
if method != 'PUT' or len(parts) != 2 or parts[1] not in linuxmanager.COMPONENTS:
|
||||
return 404, {'error': f'no route {method} {path}'}
|
||||
name, enabled = parts[1], body.get('enabled')
|
||||
if not isinstance(enabled, bool):
|
||||
return 400, {'error': 'enabled must be true or false'}
|
||||
(section, setting), _ = linuxmanager.COMPONENTS[name]
|
||||
changes = {section: {setting: enabled}}
|
||||
if name == 'router' and enabled and not cfg['router']['enabled']:
|
||||
choices = router_choices(cfg)
|
||||
if not choices:
|
||||
return 409, {'error': 'the router needs a second network interface; the server has only one'}
|
||||
values = {key: body.get(key, '') for key in ('internal_interface', 'int_addr', 'int_gateway_ip')}
|
||||
if any(not isinstance(value, str) for value in values.values()):
|
||||
return 400, {'error': 'internal_interface, int_addr and int_gateway_ip must be strings'}
|
||||
if values['internal_interface'] and values['internal_interface'] not in choices:
|
||||
return 400, {'error': f'internal_interface must be one of {", ".join(choices)}'}
|
||||
if values['internal_interface']:
|
||||
changes['interfaces'] = {'internal': values['internal_interface']}
|
||||
if values['int_addr'] or values['int_gateway_ip']:
|
||||
changes['local'] = {'int_addr': values['int_addr'].strip(), 'int_gateway_ip': values['int_gateway_ip'].strip()}
|
||||
changed = settings_change(changes)
|
||||
if isinstance(changed, tuple):
|
||||
return changed
|
||||
return 200, {'components': listing(changed)}
|
||||
Reference in new issue
Block a user