mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-01-28 08:03:36 +00:00
Track which section of ejabberd config we are in, and only edit the hosts section.
Check for jwchat config and ejabberd dumpfile before trying to modify them.
This commit is contained in:
parent
6fc721a727
commit
10b234921b
50
actions/xmpp
50
actions/xmpp
@ -69,37 +69,53 @@ def subcommand_get_installed(_):
|
||||
def subcommand_change_hostname(arguments):
|
||||
"""Update ejabberd and jwchat with new hostname"""
|
||||
if not get_installed():
|
||||
print('Failed to update XMPP hostname: ejabberd is not installed.')
|
||||
return
|
||||
|
||||
old_hostname = arguments.old_hostname
|
||||
new_hostname = arguments.new_hostname
|
||||
|
||||
with open(JWCHAT_CONFIG, 'r') as conffile:
|
||||
lines = conffile.readlines()
|
||||
with open(JWCHAT_CONFIG, 'w') as conffile:
|
||||
for line in lines:
|
||||
conffile.write(re.sub('var SITENAME = "' + old_hostname + '";',
|
||||
'var SITENAME = "' + new_hostname + '";',
|
||||
line))
|
||||
# update jwchat's sitename, if it's installed
|
||||
if os.path.exists(JWCHAT_CONFIG):
|
||||
with open(JWCHAT_CONFIG, 'r') as conffile:
|
||||
lines = conffile.readlines()
|
||||
with open(JWCHAT_CONFIG, 'w') as conffile:
|
||||
for line in lines:
|
||||
conffile.write(re.sub('var SITENAME = "' + old_hostname + '";',
|
||||
'var SITENAME = "' + new_hostname + '";',
|
||||
line))
|
||||
|
||||
# update ejabberd hosts
|
||||
with open(EJABBERD_CONFIG, 'r') as conffile:
|
||||
lines = conffile.readlines()
|
||||
with open(EJABBERD_CONFIG, 'w') as conffile:
|
||||
in_hosts_section = False
|
||||
for line in lines:
|
||||
conffile.write(re.sub(old_hostname, new_hostname, line))
|
||||
if in_hosts_section:
|
||||
if line.startswith(' - "'):
|
||||
conffile.write(re.sub(old_hostname, new_hostname, line))
|
||||
else:
|
||||
in_hosts_section = False
|
||||
conffile.write(line)
|
||||
else:
|
||||
if line.startswith('hosts:'):
|
||||
in_hosts_section = True
|
||||
conffile.write(line)
|
||||
|
||||
with open(EJABBERD_BACKUP, 'r') as dumpfile:
|
||||
lines = dumpfile.readlines()
|
||||
with open(EJABBERD_BACKUP, 'w') as dumpfile:
|
||||
for line in lines:
|
||||
dumpfile.write(re.sub(old_hostname, new_hostname, line))
|
||||
# update ejabberd backup database
|
||||
if os.path.exists(EJABBERD_BACKUP):
|
||||
with open(EJABBERD_BACKUP, 'r') as dumpfile:
|
||||
lines = dumpfile.readlines()
|
||||
with open(EJABBERD_BACKUP, 'w') as dumpfile:
|
||||
for line in lines:
|
||||
dumpfile.write(re.sub(old_hostname, new_hostname, line))
|
||||
|
||||
subprocess.call(['service', 'ejabberd', 'restart'])
|
||||
|
||||
# load backup database
|
||||
time.sleep(10)
|
||||
subprocess.call(['ejabberdctl', 'load', EJABBERD_BACKUP])
|
||||
os.remove(EJABBERD_BACKUP)
|
||||
if os.path.exists(EJABBERD_BACKUP):
|
||||
time.sleep(10)
|
||||
subprocess.call(['ejabberdctl', 'load', EJABBERD_BACKUP])
|
||||
os.remove(EJABBERD_BACKUP)
|
||||
|
||||
|
||||
def subcommand_register(arguments):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user