mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
Diaspora: Checking whether domain name is setup before certain actions
This commit is contained in:
parent
5ffcf42278
commit
3a6dc03ee9
@ -21,7 +21,6 @@ Configuration helper for diaspora* pod.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import socket
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
@ -31,7 +30,7 @@ def parse_arguments():
|
|||||||
"""Return parsed command line arguments as dictionary."""
|
"""Return parsed command line arguments as dictionary."""
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
subparsers = parser.add_subparsers(dest='subcommand', help='Sub command')
|
||||||
pre_install = subparsers.add_parser(
|
subparsers.add_parser(
|
||||||
'pre-install',
|
'pre-install',
|
||||||
help='Preseed debconf values before packages are installed.')
|
help='Preseed debconf values before packages are installed.')
|
||||||
|
|
||||||
@ -87,6 +86,7 @@ def subcommand_disable_ssl(_):
|
|||||||
Disable ssl in the diaspora configuration
|
Disable ssl in the diaspora configuration
|
||||||
as the apache server takes care of ssl
|
as the apache server takes care of ssl
|
||||||
"""
|
"""
|
||||||
|
# Using sed because ruamel.yaml has a bug for this kind of files
|
||||||
subprocess.call([
|
subprocess.call([
|
||||||
"sed", "-i", "s/#require_ssl: true/require_ssl: false/g",
|
"sed", "-i", "s/#require_ssl: true/require_ssl: false/g",
|
||||||
"/etc/diaspora/diaspora.yml"
|
"/etc/diaspora/diaspora.yml"
|
||||||
|
|||||||
@ -38,3 +38,11 @@ class DomainRegistrationError(PlinthError):
|
|||||||
class PackageNotInstalledError(PlinthError):
|
class PackageNotInstalledError(PlinthError):
|
||||||
"""Could not complete module setup due to missing package."""
|
"""Could not complete module setup due to missing package."""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class DomainNotRegisteredError(PlinthError):
|
||||||
|
"""
|
||||||
|
An action couldn't be performed because this
|
||||||
|
FreedomBox doesn't have a registered domain
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
#
|
|
||||||
# This file is part of Plinth.
|
# This file is part of Plinth.
|
||||||
#
|
#
|
||||||
# This program is free software: you can redistribute it and/or modify
|
# This program is free software: you can redistribute it and/or modify
|
||||||
@ -15,14 +14,15 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
import subprocess
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from plinth.modules import names
|
from plinth.modules import names
|
||||||
from plinth.utils import format_lazy
|
from plinth.utils import format_lazy
|
||||||
from plinth import actions, action_utils, cfg, frontpage, service as service_module
|
from plinth import actions, action_utils, cfg, frontpage, \
|
||||||
|
service as service_module
|
||||||
|
from plinth.errors import DomainNotRegisteredError
|
||||||
|
|
||||||
domain_name_file = "/etc/diaspora/domain_name"
|
domain_name_file = "/etc/diaspora/domain_name"
|
||||||
lazy_domain_name = None # To avoid repeatedly reading from file
|
lazy_domain_name = None # To avoid repeatedly reading from file
|
||||||
@ -33,15 +33,16 @@ def is_setup():
|
|||||||
|
|
||||||
|
|
||||||
def get_configured_domain_name():
|
def get_configured_domain_name():
|
||||||
|
global lazy_domain_name
|
||||||
if lazy_domain_name:
|
if lazy_domain_name:
|
||||||
return lazy_domain_name
|
return lazy_domain_name
|
||||||
|
|
||||||
if not is_setup():
|
if not is_setup():
|
||||||
return ""
|
raise DomainNotRegisteredError()
|
||||||
|
|
||||||
with open(domain_name_file) as dnf:
|
with open(domain_name_file) as dnf:
|
||||||
global lazy_domain_name
|
global lazy_domain_name
|
||||||
lazy_domain_name = dnf.read().rstrip()
|
lazy_domain_name = dnf.read().rstrip()
|
||||||
return lazy_domain_name
|
return lazy_domain_name
|
||||||
|
|
||||||
|
|
||||||
@ -60,12 +61,14 @@ managed_services = ['diaspora']
|
|||||||
managed_packages = ['diaspora']
|
managed_packages = ['diaspora']
|
||||||
|
|
||||||
description = [
|
description = [
|
||||||
_('diaspora* is a decentralized social network where you can store and control your own data.'
|
_('diaspora* is a decentralized social network where you can store '
|
||||||
),
|
'and control your own data.'),
|
||||||
format_lazy(
|
format_lazy(
|
||||||
'When enabled, the diaspora* pod will be available from '
|
'When enabled, the diaspora* pod will be available from '
|
||||||
'<a href="https://diaspora.{host}">diaspora.{host}</a> path on the web server.'.
|
'<a href="https://diaspora.{host}">diaspora.{host}</a> path on the '
|
||||||
format(host=get_configured_domain_name()))
|
'web server.'.format(host=get_configured_domain_name()) if is_setup()
|
||||||
|
else 'Please register a domain name for your FreedomBox to be able to'
|
||||||
|
' federate with other diaspora* pods.')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@ -126,11 +129,11 @@ def get_domain_names():
|
|||||||
|
|
||||||
def add_shortcut():
|
def add_shortcut():
|
||||||
"""Add shortcut to diaspora on the Plinth homepage"""
|
"""Add shortcut to diaspora on the Plinth homepage"""
|
||||||
frontpage.add_shortcut(
|
if is_setup():
|
||||||
'diaspora',
|
frontpage.add_shortcut(
|
||||||
title,
|
'diaspora', title,
|
||||||
url='https://diaspora.{}'.format(get_configured_domain_name()),
|
url='https://diaspora.{}'.format(get_configured_domain_name()),
|
||||||
login_required=True)
|
login_required=True)
|
||||||
|
|
||||||
|
|
||||||
def is_enabled():
|
def is_enabled():
|
||||||
|
|||||||
@ -40,6 +40,7 @@ class DiasporaSetupView(FormView):
|
|||||||
domain_name = form.cleaned_data['domain_name']
|
domain_name = form.cleaned_data['domain_name']
|
||||||
actions.superuser_run('diaspora',
|
actions.superuser_run('diaspora',
|
||||||
['setup', '--domain-name', domain_name])
|
['setup', '--domain-name', domain_name])
|
||||||
|
diaspora.add_shortcut()
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user