mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-04-29 10:10:19 +00:00
xmpp: Fix hacky quoted strings in ejabberd config
- Use a parser generated data type exposed by ruamel.yaml library to get the necessary double-quoted strings that we want in the output file. - Simplify reading and writing to a YAML file. - Fix incorrect dependency of ruamel.yaml Debian package. The correct one is python3-ruamel.yaml.
This commit is contained in:
parent
edecd74ccf
commit
d2800ab6ce
2
INSTALL
2
INSTALL
@ -29,7 +29,7 @@
|
|||||||
python3-gi \
|
python3-gi \
|
||||||
python3-psutil \
|
python3-psutil \
|
||||||
python3-requests \
|
python3-requests \
|
||||||
python3-ruamel-yaml \
|
python3-ruamel.yaml \
|
||||||
python3-setuptools \
|
python3-setuptools \
|
||||||
xmlto
|
xmlto
|
||||||
|
|
||||||
|
|||||||
30
actions/xmpp
30
actions/xmpp
@ -100,9 +100,8 @@ 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 file_handle:
|
||||||
confdata = conffile.read()
|
conf = ruamel.yaml.round_trip_load(file_handle, preserve_quotes=True)
|
||||||
conf = ruamel.yaml.round_trip_load(confdata, preserve_quotes=True)
|
|
||||||
|
|
||||||
for listen_port in conf['listen']:
|
for listen_port in conf['listen']:
|
||||||
if 'starttls' in listen_port:
|
if 'starttls' in listen_port:
|
||||||
@ -112,13 +111,11 @@ def subcommand_setup(_):
|
|||||||
|
|
||||||
conf['auth_method'] = 'ldap'
|
conf['auth_method'] = 'ldap'
|
||||||
conf['ldap_servers'] = ['localhost']
|
conf['ldap_servers'] = ['localhost']
|
||||||
conf['ldap_base'] = '"ou=users,dc=thisbox"'
|
conf['ldap_base'] = ruamel.yaml.scalarstring.DoubleQuotedScalarString(
|
||||||
|
'ou=users,dc=thisbox')
|
||||||
|
|
||||||
confdata = ruamel.yaml.round_trip_dump(conf)
|
with open(EJABBERD_CONFIG, 'w') as file_handle:
|
||||||
confdata = confdata.replace(
|
ruamel.yaml.round_trip_dump(conf, file_handle)
|
||||||
'\'"ou=users,dc=thisbox"\'', '"ou=users,dc=thisbox"')
|
|
||||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
|
||||||
conffile.write(confdata)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output(['ejabberdctl', 'restart'])
|
subprocess.check_output(['ejabberdctl', 'restart'])
|
||||||
@ -221,17 +218,14 @@ def subcommand_change_domainname(arguments):
|
|||||||
subprocess.call(['pkill', '-u', 'ejabberd'])
|
subprocess.call(['pkill', '-u', 'ejabberd'])
|
||||||
|
|
||||||
# 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 file_handle:
|
||||||
confdata = conffile.read()
|
conf = ruamel.yaml.round_trip_load(file_handle, preserve_quotes=True)
|
||||||
conf = ruamel.yaml.round_trip_load(confdata, preserve_quotes=True)
|
|
||||||
|
|
||||||
conf['hosts'].append('"' + domainname + '"')
|
conf['hosts'].append(ruamel.yaml.scalarstring.DoubleQuotedScalarString(
|
||||||
|
domainname))
|
||||||
|
|
||||||
confdata = ruamel.yaml.round_trip_dump(conf)
|
with open(EJABBERD_CONFIG, 'w') as file_handle:
|
||||||
confdata = confdata.replace(
|
ruamel.yaml.round_trip_dump(conf, file_handle)
|
||||||
'\'"' + domainname + '"\'', '"' + domainname + '"')
|
|
||||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
|
||||||
conffile.write(confdata)
|
|
||||||
|
|
||||||
action_utils.service_start('ejabberd')
|
action_utils.service_start('ejabberd')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user