mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-11-29 08:25:10 +00:00
Merge remote-tracking branch 'upstream/master' into dynamicdns
This commit is contained in:
commit
6c214c915c
26 files changed
+546
-223
No files matched your search
@@ -31,6 +31,8 @@ import socket
|
||||
|
||||
from plinth import actions
|
||||
from plinth import cfg
|
||||
from plinth.signals import pre_hostname_change, post_hostname_change
|
||||
from plinth.signals import domainname_change
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
@@ -41,6 +43,12 @@ def get_hostname():
|
||||
return socket.gethostname()
|
||||
|
||||
|
||||
def get_domainname():
|
||||
"""Return the domainname"""
|
||||
fqdn = socket.getfqdn()
|
||||
return '.'.join(fqdn.split('.')[1:])
|
||||
|
||||
|
||||
class TrimmedCharField(forms.CharField):
|
||||
"""Trim the contents of a CharField"""
|
||||
def clean(self, value):
|
||||
@@ -68,6 +76,15 @@ and must not be greater than 63 characters in length.'),
|
||||
validators.RegexValidator(r'^[a-zA-Z][a-zA-Z0-9]{,62}$',
|
||||
_('Invalid hostname'))])
|
||||
|
||||
domainname = TrimmedCharField(
|
||||
label=_('Domain Name'),
|
||||
help_text=_('Your domain name is the global name by which other \
|
||||
machines on the Internet can reach you. It must consist of alphanumeric words \
|
||||
separated by dots.'),
|
||||
validators=[
|
||||
validators.RegexValidator(r'^[a-zA-Z][a-zA-Z0-9.]*$',
|
||||
_('Invalid domain name'))])
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# pylint: disable-msg=E1101, W0233
|
||||
forms.Form.__init__(self, *args, **kwargs)
|
||||
@@ -124,6 +141,7 @@ def index(request):
|
||||
def get_status():
|
||||
"""Return the current status"""
|
||||
return {'hostname': get_hostname(),
|
||||
'domainname': get_domainname(),
|
||||
'time_zone': open('/etc/timezone').read().rstrip()}
|
||||
|
||||
|
||||
@@ -140,6 +158,17 @@ def _apply_changes(request, old_status, new_status):
|
||||
else:
|
||||
messages.info(request, _('Hostname is unchanged'))
|
||||
|
||||
if old_status['domainname'] != new_status['domainname']:
|
||||
try:
|
||||
set_domainname(new_status['domainname'])
|
||||
except Exception as exception:
|
||||
messages.error(request, _('Error setting domain name: %s') %
|
||||
exception)
|
||||
else:
|
||||
messages.success(request, _('Domain name set'))
|
||||
else:
|
||||
messages.info(request, _('Domain name is unchanged'))
|
||||
|
||||
if old_status['time_zone'] != new_status['time_zone']:
|
||||
try:
|
||||
actions.superuser_run('timezone-change', [new_status['time_zone']])
|
||||
@@ -154,11 +183,34 @@ def _apply_changes(request, old_status, new_status):
|
||||
|
||||
def set_hostname(hostname):
|
||||
"""Sets machine hostname to hostname"""
|
||||
old_hostname = get_hostname()
|
||||
|
||||
# Hostname should be ASCII. If it's unicode but passed our
|
||||
# valid_hostname check, convert to ASCII.
|
||||
hostname = str(hostname)
|
||||
|
||||
pre_hostname_change.send_robust(sender='config',
|
||||
old_hostname=old_hostname,
|
||||
new_hostname=hostname)
|
||||
|
||||
LOGGER.info('Changing hostname to - %s', hostname)
|
||||
actions.superuser_run('xmpp-pre-hostname-change')
|
||||
actions.superuser_run('hostname-change', hostname)
|
||||
actions.superuser_run('xmpp-hostname-change', hostname, async=True)
|
||||
|
||||
post_hostname_change.send_robust(sender='config',
|
||||
old_hostname=old_hostname,
|
||||
new_hostname=hostname)
|
||||
|
||||
|
||||
def set_domainname(domainname):
|
||||
"""Sets machine domain name to domainname"""
|
||||
old_domainname = get_domainname()
|
||||
|
||||
# Domain name should be ASCII. If it's unicode, convert to ASCII.
|
||||
domainname = str(domainname)
|
||||
|
||||
LOGGER.info('Changing domain name to - %s', domainname)
|
||||
actions.superuser_run('domainname-change', domainname)
|
||||
|
||||
domainname_change.send_robust(sender='config',
|
||||
old_domainname=old_domainname,
|
||||
new_domainname=domainname)
|
||||
@@ -26,6 +26,7 @@ import logging
|
||||
|
||||
from plinth import actions
|
||||
from plinth import cfg
|
||||
from plinth import package
|
||||
from plinth.signals import service_enabled
|
||||
import plinth.service as service_module
|
||||
|
||||
@@ -42,13 +43,9 @@ def init():
|
||||
|
||||
|
||||
@login_required
|
||||
@package.required('firewalld')
|
||||
def index(request):
|
||||
"""Serve introcution page"""
|
||||
if not get_installed_status():
|
||||
return TemplateResponse(request, 'firewall.html',
|
||||
{'title': _('Firewall'),
|
||||
'firewall_status': 'not_installed'})
|
||||
|
||||
if not get_enabled_status():
|
||||
return TemplateResponse(request, 'firewall.html',
|
||||
{'title': _('Firewall'),
|
||||
@@ -65,14 +62,8 @@ def index(request):
|
||||
'external_enabled_services': external_enabled_services})
|
||||
|
||||
|
||||
def get_installed_status():
|
||||
"""Return whether firewall is installed"""
|
||||
output = _run(['get-installed'], superuser=True)
|
||||
return output.split()[0] == 'installed'
|
||||
|
||||
|
||||
def get_enabled_status():
|
||||
"""Return whether firewall is installed"""
|
||||
"""Return whether firewall is enabled"""
|
||||
output = _run(['get-status'], superuser=True)
|
||||
return output.split()[0] == 'running'
|
||||
|
||||
|
||||
@@ -29,13 +29,7 @@ threat from the Internet.</p>
|
||||
|
||||
<p>The following is the current status:</p>
|
||||
|
||||
{% if firewall_status = 'not_installed' %}
|
||||
<p>Firewall is not installed. Please install it. Firewall comes
|
||||
pre-installed with {{ cfg.box_name }}. On any Debian based system (such
|
||||
as {{ cfg.box_name }}) you may install it using the
|
||||
command <code>aptitude install firewalld</code></p>
|
||||
|
||||
{% elif firewall_status = 'not_running' %}
|
||||
{% if firewall_status = 'not_running' %}
|
||||
|
||||
<p>Firewall daemon is not running. Please run it. Firewall comes
|
||||
enabled by default on {{ cfg.box_name }}. On any Debian based system
|
||||
|
||||
@@ -23,6 +23,7 @@ from gettext import gettext as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth import cfg
|
||||
from plinth import package
|
||||
from plinth import service
|
||||
|
||||
|
||||
@@ -47,6 +48,7 @@ def init():
|
||||
|
||||
|
||||
@login_required
|
||||
@package.required('postgresql', 'php5-pgsql', 'owncloud')
|
||||
def index(request):
|
||||
"""Serve the ownCloud configuration page"""
|
||||
status = get_status()
|
||||
|
||||
@@ -27,14 +27,10 @@
|
||||
|
||||
<h2>ownCloud</h2>
|
||||
|
||||
<p>When enabled, the owncloud installation will be available
|
||||
<p>When enabled, the ownCloud installation will be available
|
||||
from <a href="/owncloud">/owncloud</a> path on the web server.
|
||||
Visit this URL to set up the initial administration account for
|
||||
owncloud.</p>
|
||||
|
||||
<p><strong>Note: Setting up owncloud for the first time might take
|
||||
5 minutes or more, depending on download bandwidth from the
|
||||
Debian APT sources.</strong></p>
|
||||
ownCloud.</p>
|
||||
|
||||
{{ form|bootstrap }}
|
||||
<input type="submit" class="btn btn-primary btn-md" value="Update setup"/>
|
||||
|
||||
@@ -30,6 +30,7 @@ import logging
|
||||
|
||||
from plinth import actions
|
||||
from plinth import cfg
|
||||
from plinth import package
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
@@ -101,6 +102,7 @@ https://pagekite.net/wiki/Howto/SshOverPageKite/">instructions</a>'))
|
||||
|
||||
|
||||
@login_required
|
||||
@package.required('pagekite')
|
||||
def configure(request):
|
||||
"""Serve the configuration form"""
|
||||
status = get_status()
|
||||
@@ -131,11 +133,6 @@ def get_status():
|
||||
"""
|
||||
status = {}
|
||||
|
||||
# Check if PageKite is installed
|
||||
output = _run(['get-installed'])
|
||||
if output.split()[0] != 'installed':
|
||||
return None
|
||||
|
||||
# PageKite service enabled/disabled
|
||||
output = _run(['get-status'])
|
||||
status['enabled'] = (output.split()[0] == 'enabled')
|
||||
|
||||
@@ -22,15 +22,6 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if not status %}
|
||||
|
||||
<p>PageKite is not installed, please install it. PageKite comes
|
||||
pre-installed with {{ cfg.box_name }}. On any Debian based system
|
||||
(such as {{ cfg.box_name }}) you may install it using the command
|
||||
<code>aptitude install pagekite<code></p>
|
||||
|
||||
{% else %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
||||
@@ -52,8 +43,6 @@
|
||||
|
||||
</form>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block page_js %}
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
|
||||
<h2>Tor</h2>
|
||||
|
||||
{% if is_installed %}
|
||||
|
||||
<h3>Status</h3>
|
||||
|
||||
<p>
|
||||
@@ -80,15 +78,6 @@ port-forwarded, if necessary:</p>
|
||||
<p>A Tor SOCKS port is available on your {{ cfg.box_name }} on TCP port
|
||||
9050.</p>
|
||||
|
||||
{% else %}
|
||||
|
||||
<p>Tor is not installed, please install it. Tor comes pre-installed
|
||||
with {{ cfg.box_name }}. On any Debian-based system (such as
|
||||
{{ cfg.box_name }}) you may install it using the command
|
||||
<code>aptitude install tor</code>.</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block sidebar %}
|
||||
|
||||
@@ -27,6 +27,7 @@ from gettext import gettext as _
|
||||
|
||||
from plinth import actions
|
||||
from plinth import cfg
|
||||
from plinth import package
|
||||
|
||||
|
||||
class TorForm(forms.Form): # pylint: disable=W0232
|
||||
@@ -43,6 +44,7 @@ def init():
|
||||
|
||||
|
||||
@login_required
|
||||
@package.required('tor')
|
||||
def index(request):
|
||||
"""Service the index page"""
|
||||
status = get_status()
|
||||
@@ -61,7 +63,6 @@ def index(request):
|
||||
|
||||
return TemplateResponse(request, 'tor.html',
|
||||
{'title': _('Tor Control Panel'),
|
||||
'is_installed': status['is_installed'],
|
||||
'is_running': status['is_running'],
|
||||
'tor_ports': status['ports'],
|
||||
'tor_hs_enabled': status['hs_enabled'],
|
||||
@@ -72,9 +73,6 @@ def index(request):
|
||||
|
||||
def get_status():
|
||||
"""Return the current status"""
|
||||
is_installed = actions.superuser_run(
|
||||
'tor',
|
||||
['get-installed']).strip() == 'installed'
|
||||
is_running = actions.superuser_run('tor', ['is-running']).strip() == 'yes'
|
||||
|
||||
output = actions.superuser_run('tor-get-ports')
|
||||
@@ -103,8 +101,7 @@ def get_status():
|
||||
hs_hostname = hs_info[0]
|
||||
hs_ports = hs_info[1]
|
||||
|
||||
return {'is_installed': is_installed,
|
||||
'is_running': is_running,
|
||||
return {'is_running': is_running,
|
||||
'ports': ports,
|
||||
'hs_enabled': hs_enabled,
|
||||
'hs_hostname': hs_hostname,
|
||||
|
||||
@@ -22,8 +22,6 @@
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% if is_installed %}
|
||||
|
||||
<p>XMPP is an open and standardized communication protocol. Here you
|
||||
can run and configure your XMPP server, called ejabberd. To actually
|
||||
communicate, you can use the <a href='/jwchat'>web client</a> or any
|
||||
@@ -33,16 +31,4 @@
|
||||
<p><a href='/jwchat' target='_blank'class='btn btn-primary'> Launch web
|
||||
client</a></p>
|
||||
|
||||
{% else %}
|
||||
|
||||
<h2>XMPP Server</h2>
|
||||
|
||||
<p>The XMPP server <i>ejabberd</i> is not installed.</p>
|
||||
|
||||
<p>ejabberd comes pre-installed with {{ cfg.box_name }}. On any Debian-based
|
||||
system (such as {{ cfg.box_name }}) you may install it using the command
|
||||
<code>aptitude install ejabberd</code>.</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
+50
-11
@@ -25,7 +25,10 @@ import logging
|
||||
|
||||
from plinth import actions
|
||||
from plinth import cfg
|
||||
from plinth import package
|
||||
from plinth import service
|
||||
from plinth.signals import pre_hostname_change, post_hostname_change
|
||||
from plinth.signals import domainname_change
|
||||
|
||||
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
@@ -53,23 +56,18 @@ def init():
|
||||
'xmpp-bosh', _('Chat Server - web interface'), is_external=True,
|
||||
enabled=True)
|
||||
|
||||
pre_hostname_change.connect(on_pre_hostname_change)
|
||||
post_hostname_change.connect(on_post_hostname_change)
|
||||
domainname_change.connect(on_domainname_change)
|
||||
|
||||
|
||||
@login_required
|
||||
@package.required('jwchat', 'ejabberd')
|
||||
def index(request):
|
||||
"""Serve XMPP page"""
|
||||
is_installed = actions.superuser_run(
|
||||
'xmpp',
|
||||
['get-installed']).strip() == 'installed'
|
||||
|
||||
if is_installed:
|
||||
index_subsubmenu = subsubmenu
|
||||
else:
|
||||
index_subsubmenu = None
|
||||
|
||||
return TemplateResponse(request, 'xmpp.html',
|
||||
{'title': _('XMPP Server'),
|
||||
'is_installed': is_installed,
|
||||
'subsubmenu': index_subsubmenu})
|
||||
'subsubmenu': subsubmenu})
|
||||
|
||||
|
||||
class ConfigureForm(forms.Form): # pylint: disable-msg=W0232
|
||||
@@ -178,3 +176,44 @@ def _register_user(request, data):
|
||||
messages.error(request,
|
||||
_('Failed to register account for %s: %s') %
|
||||
(data['username'], output))
|
||||
|
||||
|
||||
def on_pre_hostname_change(sender, old_hostname, new_hostname, **kwargs):
|
||||
"""
|
||||
Backup ejabberd database before hostname is changed.
|
||||
"""
|
||||
del sender # Unused
|
||||
del kwargs # Unused
|
||||
|
||||
actions.superuser_run('xmpp',
|
||||
['pre-change-hostname',
|
||||
'--old-hostname', old_hostname,
|
||||
'--new-hostname', new_hostname])
|
||||
|
||||
|
||||
def on_post_hostname_change(sender, old_hostname, new_hostname, **kwargs):
|
||||
"""
|
||||
Update ejabberd and jwchat config after hostname is changed.
|
||||
"""
|
||||
del sender # Unused
|
||||
del kwargs # Unused
|
||||
|
||||
actions.superuser_run('xmpp',
|
||||
['change-hostname',
|
||||
'--old-hostname', old_hostname,
|
||||
'--new-hostname', new_hostname],
|
||||
async=True)
|
||||
|
||||
|
||||
def on_domainname_change(sender, old_domainname, new_domainname, **kwargs):
|
||||
"""
|
||||
Update ejabberd and jwchat config after domain name is changed.
|
||||
"""
|
||||
del sender # Unused
|
||||
del old_domainname # Unused
|
||||
del kwargs # Unused
|
||||
|
||||
actions.superuser_run('xmpp',
|
||||
['change-domainname',
|
||||
'--domainname', new_domainname],
|
||||
async=True)
|
||||
Reference in new issue
Block a user