mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
xmpp: Use ruamel.yaml to modify ejabberd config
This commit is contained in:
parent
d9197111d8
commit
edecd74ccf
2
INSTALL
2
INSTALL
@ -29,8 +29,8 @@
|
|||||||
python3-gi \
|
python3-gi \
|
||||||
python3-psutil \
|
python3-psutil \
|
||||||
python3-requests \
|
python3-requests \
|
||||||
|
python3-ruamel-yaml \
|
||||||
python3-setuptools \
|
python3-setuptools \
|
||||||
python3-yaml \
|
|
||||||
xmlto
|
xmlto
|
||||||
|
|
||||||
2. Install Plinth:
|
2. Install Plinth:
|
||||||
|
|||||||
54
actions/xmpp
54
actions/xmpp
@ -27,6 +27,7 @@ import shutil
|
|||||||
import socket
|
import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import re
|
import re
|
||||||
|
import ruamel.yaml
|
||||||
|
|
||||||
from plinth import action_utils
|
from plinth import action_utils
|
||||||
|
|
||||||
@ -100,23 +101,24 @@ def subcommand_pre_install(arguments):
|
|||||||
def subcommand_setup(_):
|
def subcommand_setup(_):
|
||||||
"""Enabled LDAP authentication and setup jwchat apache conf"""
|
"""Enabled LDAP authentication and setup jwchat apache conf"""
|
||||||
with open(EJABBERD_CONFIG, 'r') as conffile:
|
with open(EJABBERD_CONFIG, 'r') as conffile:
|
||||||
lines = conffile.readlines()
|
confdata = conffile.read()
|
||||||
|
conf = ruamel.yaml.round_trip_load(confdata, preserve_quotes=True)
|
||||||
|
|
||||||
|
for listen_port in conf['listen']:
|
||||||
|
if 'starttls' in listen_port:
|
||||||
|
listen_port['starttls'] = False
|
||||||
|
if 'tls' in listen_port:
|
||||||
|
listen_port['tls'] = False
|
||||||
|
|
||||||
|
conf['auth_method'] = 'ldap'
|
||||||
|
conf['ldap_servers'] = ['localhost']
|
||||||
|
conf['ldap_base'] = '"ou=users,dc=thisbox"'
|
||||||
|
|
||||||
|
confdata = ruamel.yaml.round_trip_dump(conf)
|
||||||
|
confdata = confdata.replace(
|
||||||
|
'\'"ou=users,dc=thisbox"\'', '"ou=users,dc=thisbox"')
|
||||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
with open(EJABBERD_CONFIG, 'w') as conffile:
|
||||||
for line in lines:
|
conffile.write(confdata)
|
||||||
if re.match(r'^\s*tls:\s+true', line):
|
|
||||||
conffile.write(' tls: false\n')
|
|
||||||
elif 'auth_method: internal' in line:
|
|
||||||
conffile.write('## ' + line)
|
|
||||||
elif '## auth_method: ldap' in line:
|
|
||||||
conffile.write('auth_method: ldap\n')
|
|
||||||
elif '## ldap_servers:' in line:
|
|
||||||
conffile.write('ldap_servers:\n')
|
|
||||||
conffile.write(' - "localhost"\n')
|
|
||||||
elif '## ldap_base:' in line:
|
|
||||||
conffile.write('ldap_base: "ou=users,dc=thisbox"\n')
|
|
||||||
else:
|
|
||||||
conffile.write(line)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(['ejabberdctl', 'restart'])
|
subprocess.check_output(['ejabberdctl', 'restart'])
|
||||||
@ -220,20 +222,16 @@ def subcommand_change_domainname(arguments):
|
|||||||
|
|
||||||
# Add updated domainname to ejabberd hosts list.
|
# Add updated domainname to ejabberd hosts list.
|
||||||
with open(EJABBERD_CONFIG, 'r') as conffile:
|
with open(EJABBERD_CONFIG, 'r') as conffile:
|
||||||
lines = conffile.readlines()
|
confdata = conffile.read()
|
||||||
|
conf = ruamel.yaml.round_trip_load(confdata, preserve_quotes=True)
|
||||||
|
|
||||||
|
conf['hosts'].append('"' + domainname + '"')
|
||||||
|
|
||||||
|
confdata = ruamel.yaml.round_trip_dump(conf)
|
||||||
|
confdata = confdata.replace(
|
||||||
|
'\'"' + domainname + '"\'', '"' + domainname + '"')
|
||||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
with open(EJABBERD_CONFIG, 'w') as conffile:
|
||||||
in_hosts = False
|
conffile.write(confdata)
|
||||||
for line in lines:
|
|
||||||
if in_hosts:
|
|
||||||
if re.match(r'\s*-\s*', line):
|
|
||||||
continue
|
|
||||||
|
|
||||||
in_hosts = False
|
|
||||||
|
|
||||||
conffile.write(line)
|
|
||||||
if re.match(r'\s*hosts:', line):
|
|
||||||
in_hosts = True
|
|
||||||
conffile.write(' - "' + domainname + '"\n')
|
|
||||||
|
|
||||||
action_utils.service_start('ejabberd')
|
action_utils.service_start('ejabberd')
|
||||||
|
|
||||||
|
|||||||
@ -4,4 +4,4 @@ django >= 1.10.0
|
|||||||
django-stronghold
|
django-stronghold
|
||||||
psutil
|
psutil
|
||||||
python-augeas
|
python-augeas
|
||||||
pyyaml
|
ruamel.yaml
|
||||||
|
|||||||
2
setup.py
2
setup.py
@ -185,8 +185,8 @@ setuptools.setup(
|
|||||||
'django-stronghold',
|
'django-stronghold',
|
||||||
'psutil',
|
'psutil',
|
||||||
'python-augeas',
|
'python-augeas',
|
||||||
'pyyaml',
|
|
||||||
'requests',
|
'requests',
|
||||||
|
'ruamel.yaml',
|
||||||
],
|
],
|
||||||
tests_require=['coverage >= 3.7'],
|
tests_require=['coverage >= 3.7'],
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user