def get_initial(self): """Get initial form data.""" return { 'network_topology': kvstore.get_default(networks.NETWORK_TOPOLOGY_TYPE_KEY, 'to_router') }
def get_initial(self): """Return initial data for the form.""" return { 'router_config': kvstore.get_default(networks.ROUTER_CONFIGURATION_TYPE_KEY, 'not_configured') }
def get_initial(self): """Return initial data for the form.""" return { 'internet_connection_type': kvstore.get_default(networks.INTERNET_CONNECTION_TYPE_KEY, 'unknown') }
def certificate_get_last_seen_modified_time(lineage): """Return the last seen expiry date of a certificate.""" from plinth import kvstore info = kvstore.get_default('letsencrypt_certificate_info', '{}') info = json.loads(info) try: return info[str(lineage)]['last_seen_modified_time'] except KeyError: return 0
def is_completed(): """Return whether first boot process is completed.""" from plinth import kvstore global _is_completed if _is_completed is None: _is_completed = kvstore.get_default('firstboot_completed', 0) return bool(_is_completed)
def dispatch(self, request, *args, **kwargs): """Don't show wizard step if FreedomBox is not behind a router.""" network_topology = kvstore.get_default( networks.NETWORK_TOPOLOGY_TYPE_KEY, 'to_router') if network_topology != 'to_router': first_boot.mark_step_done('router_setup_wizard') return HttpResponseRedirect(reverse_lazy(first_boot.next_step())) return super().dispatch(request, *args, *kwargs)
def index(request): """Show connection list.""" connections = network.get_connection_list() network_topology = kvstore.get_default(networks.NETWORK_TOPOLOGY_TYPE_KEY, 'to_router') internet_connection_type = kvstore.get_default( networks.INTERNET_CONNECTION_TYPE_KEY, 'unknown') return TemplateResponse( request, 'networks_configuration.html', { 'app_id': 'networks', 'app_info': networks.app.info, 'title': _('Network Connections'), 'has_diagnostics': True, 'is_enabled': True, 'connections': connections, 'network_topology': network_topology, 'internet_connectivity_type': internet_connection_type, })
def next_step_or_none(): """Return the next first boot step required to run. If there are no more step remaining, return None. """ from plinth import kvstore for step in _get_steps(): done = kvstore.get_default(step['id'], 0) if not done: return step.get('url')
def process_request(request): """Handle a request as Django middleware request handler.""" state = kvstore.get_default('firstboot_state', 0) firstboot_index_url = reverse('first_boot:index') user_requests_firstboot = request.path.startswith(firstboot_index_url) # Setup is complete: Forbid accessing firstboot if state >= 10 and user_requests_firstboot: return HttpResponseRedirect(reverse('index')) # Setup is not complete: Forbid accessing anything but firstboot if state < 10 and not user_requests_firstboot: return HttpResponseRedirect(reverse('first_boot:state%d' % state))
def get_storages(storage_type=None): """Get all repositories from store.""" storages = kvstore.get_default(STORAGE_KEY, {}) if storages: storages = json.loads(storages) if storage_type: storages = { uuid: storage for uuid, storage in storages.items() if storage['storage_type'] == storage_type } return storages
def certificate_set_last_seen_modified_time(lineage): """Write to store a certificate's last seen expiry date.""" lineage = pathlib.Path(lineage) output = actions.superuser_run( 'letsencrypt', ['get-modified-time', '--domain', lineage.name]) modified_time = int(output) from plinth import kvstore info = kvstore.get_default('letsencrypt_certificate_info', '{}') info = json.loads(info) certificate_info = info.setdefault(str(lineage), {}) certificate_info['last_seen_modified_time'] = modified_time kvstore.set('letsencrypt_certificate_info', json.dumps(info))
def is_backports_requested(): """Return whether user has chosen to activate backports.""" from plinth import kvstore return kvstore.get_default(BACKPORTS_REQUESTED_KEY, False)
def is_enabled(self): """Return whether all leader components are enabled and flag is set.""" from plinth import kvstore enabled = super().is_enabled() return enabled and kvstore.get_default('wireguard-enabled', False)
def get_advanced_mode(): """Get whether option is enabled.""" from plinth import kvstore return kvstore.get_default(ADVANCED_MODE_KEY, False)
def is_enabled(self): """Return whether the app/component is enabled.""" from plinth import kvstore return kvstore.get_default(self.key, False)
def test_get_default(): """Verify that either a set value or its default can be retrieved.""" expected = 'default' actual = kvstore.get_default('bad_key', expected) assert expected == actual
def get_internet_connection_type(): """Return the currently configured internet connection type or default.""" return kvstore.get_default('networks_internet_type', 'unknown')
def test_get_default(self): """Verify that either a set value or its default can be retrieved.""" expected = 'default' actual = kvstore.get_default('bad_key', expected) self.assertEqual(expected, actual)
def get_router_configuration_type(): """Return the currently configured router configuration type or default.""" return kvstore.get_default('networks_router_configuration_type', 'not_configured')
def get_network_topology_type(): """Return the currently configured network topology type or default.""" return kvstore.get_default('networks_topology_type', 'to_router')
def firstboot_is_finished(): """Return whether firstboot process is completed.""" state = kvstore.get_default('firstboot_state', 0) return state >= 10
def is_dist_upgrade_enabled(): """Return whether user has enabled dist upgrade.""" return kvstore.get_default(DIST_UPGRADE_ENABLED_KEY, False)