mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-08-26 12:46:08 +00:00
xmpp: Always use LDAP authentication.
This commit is contained in:
parent
cb7c9c26f7
commit
b840875c16
50
actions/xmpp
50
actions/xmpp
@ -53,18 +53,6 @@ def parse_arguments():
|
|||||||
# Setup jwchat apache conf
|
# Setup jwchat apache conf
|
||||||
subparsers.add_parser('setup', help='Setup jwchat apache conf')
|
subparsers.add_parser('setup', help='Setup jwchat apache conf')
|
||||||
|
|
||||||
# Get whether LDAP authentication is enabled
|
|
||||||
subparsers.add_parser('is-ldap-enabled',
|
|
||||||
help='Get whether LDAP authentication is enabled')
|
|
||||||
|
|
||||||
# Enable LDAP authentication
|
|
||||||
subparsers.add_parser('enable-ldap',
|
|
||||||
help='Enable LDAP authentication')
|
|
||||||
|
|
||||||
# Disable LDAP authentication
|
|
||||||
subparsers.add_parser('disable-ldap',
|
|
||||||
help='Disable LDAP authentication')
|
|
||||||
|
|
||||||
# Get whether inband registration is enabled
|
# Get whether inband registration is enabled
|
||||||
subparsers.add_parser('is-inband-enabled',
|
subparsers.add_parser('is-inband-enabled',
|
||||||
help='Get whether inband registration is enabled')
|
help='Get whether inband registration is enabled')
|
||||||
@ -134,21 +122,7 @@ def subcommand_pre_install(arguments):
|
|||||||
|
|
||||||
|
|
||||||
def subcommand_setup(_):
|
def subcommand_setup(_):
|
||||||
"""Setup jwchat apache conf"""
|
"""Enabled LDAP authentication and setup jwchat apache conf"""
|
||||||
with action_utils.WebserverChange() as webserver_change:
|
|
||||||
webserver_change.disable('jwchat', kind='site')
|
|
||||||
webserver_change.enable('jwchat-plinth')
|
|
||||||
|
|
||||||
|
|
||||||
def subcommand_is_ldap_enabled(_):
|
|
||||||
"""Get whether LDAP authentication is enabled"""
|
|
||||||
conffile = open(EJABBERD_CONFIG, 'r')
|
|
||||||
conf = yaml.safe_load(conffile)
|
|
||||||
print('ldap' in conf['auth_method'])
|
|
||||||
|
|
||||||
|
|
||||||
def subcommand_enable_ldap(_):
|
|
||||||
"""Enable LDAP authentication"""
|
|
||||||
with open(EJABBERD_CONFIG, 'r') as conffile:
|
with open(EJABBERD_CONFIG, 'r') as conffile:
|
||||||
lines = conffile.readlines()
|
lines = conffile.readlines()
|
||||||
|
|
||||||
@ -171,25 +145,9 @@ def subcommand_enable_ldap(_):
|
|||||||
except subprocess.CalledProcessError as err:
|
except subprocess.CalledProcessError as err:
|
||||||
print('Failed to restart ejabberd with new configuration: %s', err)
|
print('Failed to restart ejabberd with new configuration: %s', err)
|
||||||
|
|
||||||
|
with action_utils.WebserverChange() as webserver_change:
|
||||||
def subcommand_disable_ldap(_):
|
webserver_change.disable('jwchat', kind='site')
|
||||||
"""Disable LDAP authentication"""
|
webserver_change.enable('jwchat-plinth')
|
||||||
with open(EJABBERD_CONFIG, 'r') as conffile:
|
|
||||||
lines = conffile.readlines()
|
|
||||||
|
|
||||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
|
||||||
for line in lines:
|
|
||||||
if '## auth_method: internal' in line:
|
|
||||||
conffile.write('auth_method: internal\n')
|
|
||||||
elif 'auth_method: ldap' in line:
|
|
||||||
conffile.write('## auth_method: ldap\n')
|
|
||||||
else:
|
|
||||||
conffile.write(line)
|
|
||||||
|
|
||||||
try:
|
|
||||||
subprocess.check_output(['ejabberdctl', 'restart'])
|
|
||||||
except subprocess.CalledProcessError as err:
|
|
||||||
print('Failed to restart ejabberd with new configuration: %s', err)
|
|
||||||
|
|
||||||
|
|
||||||
def subcommand_is_inband_enabled(_):
|
def subcommand_is_inband_enabled(_):
|
||||||
|
|||||||
@ -86,10 +86,6 @@ def index(request):
|
|||||||
|
|
||||||
class ConfigureForm(forms.Form): # pylint: disable-msg=W0232
|
class ConfigureForm(forms.Form): # pylint: disable-msg=W0232
|
||||||
"""Configuration form"""
|
"""Configuration form"""
|
||||||
ldap_enabled = forms.BooleanField(
|
|
||||||
label=_('Use LDAP for authentication'), required=False,
|
|
||||||
help_text=_('When enabled, only LDAP users will be able to login to \
|
|
||||||
the XMPP service'))
|
|
||||||
inband_enabled = forms.BooleanField(
|
inband_enabled = forms.BooleanField(
|
||||||
label=_('Allow In-Band Registration'), required=False,
|
label=_('Allow In-Band Registration'), required=False,
|
||||||
help_text=_('When enabled, anyone who can reach this server will be \
|
help_text=_('When enabled, anyone who can reach this server will be \
|
||||||
@ -120,12 +116,9 @@ def configure(request):
|
|||||||
|
|
||||||
def get_status():
|
def get_status():
|
||||||
"""Return the current status"""
|
"""Return the current status"""
|
||||||
output = actions.run('xmpp', ['is-ldap-enabled'])
|
|
||||||
ldap_enabled = 'True' in output.split()
|
|
||||||
output = actions.run('xmpp', ['is-inband-enabled'])
|
output = actions.run('xmpp', ['is-inband-enabled'])
|
||||||
inband_enabled = 'True' in output.split()
|
inband_enabled = 'True' in output.split()
|
||||||
return {'ldap_enabled': ldap_enabled,
|
return {'inband_enabled': inband_enabled}
|
||||||
'inband_enabled': inband_enabled}
|
|
||||||
|
|
||||||
|
|
||||||
def _apply_changes(request, old_status, new_status):
|
def _apply_changes(request, old_status, new_status):
|
||||||
@ -134,25 +127,6 @@ def _apply_changes(request, old_status, new_status):
|
|||||||
|
|
||||||
setting_changed = False
|
setting_changed = False
|
||||||
|
|
||||||
if not old_status['ldap_enabled'] and new_status['ldap_enabled']:
|
|
||||||
setting_changed = True
|
|
||||||
output = actions.superuser_run('xmpp', ['enable-ldap'])
|
|
||||||
if 'Failed' in output:
|
|
||||||
messages.error(request,
|
|
||||||
_('Error when configuring XMPP server: %s') %
|
|
||||||
output)
|
|
||||||
else:
|
|
||||||
messages.success(request, _('LDAP authentication enabled'))
|
|
||||||
elif old_status['ldap_enabled'] and not new_status['ldap_enabled']:
|
|
||||||
setting_changed = True
|
|
||||||
output = actions.superuser_run('xmpp', ['disable-ldap'])
|
|
||||||
if 'Failed' in output:
|
|
||||||
messages.error(request,
|
|
||||||
_('Error when configuring XMPP server: %s') %
|
|
||||||
output)
|
|
||||||
else:
|
|
||||||
messages.success(request, _('LDAP authentication disabled'))
|
|
||||||
|
|
||||||
if not old_status['inband_enabled'] and new_status['inband_enabled']:
|
if not old_status['inband_enabled'] and new_status['inband_enabled']:
|
||||||
setting_changed = True
|
setting_changed = True
|
||||||
output = actions.superuser_run('xmpp', ['enable-inband'])
|
output = actions.superuser_run('xmpp', ['enable-inband'])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user