2018-08-02 10:41:40 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import subprocess
|
|
|
|
|
|
|
|
from . import tools
|
|
|
|
|
|
|
|
TMP_FILE = '/tmp/confupdater.tmp'
|
|
|
|
|
|
|
|
def replace_file_line(filename, oldline, newline):
|
|
|
|
with open(filename, 'r') as conf, open(TMP_FILE, 'w') as tmp:
|
|
|
|
for line in conf:
|
|
|
|
# Find line starting with oldline
|
|
|
|
if line.startswith(oldline):
|
|
|
|
# Replace te line with oldline, newline, \n (to not repeat the oldline in newline)
|
|
|
|
tmp.write(oldline)
|
|
|
|
tmp.write(newline)
|
|
|
|
tmp.write('\n')
|
|
|
|
# Dump the rest of the file and break the loop
|
|
|
|
tmp.write(conf.read())
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
tmp.write(line)
|
|
|
|
# Copy the file contents to the original file (preserves permissions of the original file)
|
|
|
|
shutil.copyfile(TMP_FILE, filename)
|
|
|
|
os.unlink(TMP_FILE)
|
|
|
|
|
|
|
|
def run_mysql_query(query, database):
|
2018-08-14 16:27:15 +02:00
|
|
|
maria_started = tools.is_service_started('mariadb')
|
2018-08-02 10:41:40 +02:00
|
|
|
if not maria_started:
|
|
|
|
tools.start_service('mariadb')
|
|
|
|
subprocess.run(['docker', 'exec', '-i', 'mariadb', 'mysql', '-e', query, database])
|
|
|
|
if not maria_started:
|
|
|
|
tools.stop_service('mariadb')
|
|
|
|
|
2018-08-14 15:36:09 +02:00
|
|
|
def app_exists(app):
|
|
|
|
return os.path.exists(os.path.join('/srv/', app))
|
|
|
|
|
2018-08-02 10:41:40 +02:00
|
|
|
def update_gmaps_api_key(api_key):
|
|
|
|
# CKAN
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('ckan'):
|
|
|
|
replace_file_line('/srv/ckan/conf/ckan.ini', 'ckanext.geoview.gapi_key = ', api_key)
|
2018-08-02 10:41:40 +02:00
|
|
|
# Crisis Cleanup
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('crisiscleanup'):
|
|
|
|
replace_file_line('/srv/crisiscleanup/conf/boot.rb', 'ENV[\'GOOGLE_MAPS_API_KEY\'] = ', api_key)
|
2018-08-02 10:41:40 +02:00
|
|
|
# Pan.do/ra
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('pandora'):
|
|
|
|
replace_file_line('/srv/pandora/conf/local_settings.py', 'GOOGLE_API_KEY = ', '\'{}\''.format(api_key))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sahana
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sahana'):
|
|
|
|
replace_file_line('/srv/sahana/conf/000_config.py', 'settings.gis.api_google = ', '"{}"'.format(api_key))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sahana Demo
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sahana-demo'):
|
|
|
|
replace_file_line('/srv/sahana-demo/conf/000_config.py', 'settings.gis.api_google = ', '"{}"'.format(api_key))
|
2018-08-02 10:41:40 +02:00
|
|
|
# SAMBRO
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sambro'):
|
|
|
|
replace_file_line('/srv/sambro/conf/000_config.py', 'settings.gis.api_google = ', '"{}"'.format(api_key))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sigmah
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sigmah'):
|
|
|
|
replace_file_line('/srv/sigmah/conf/sigmah.properties', 'maps.key=', api_key)
|
2018-08-02 10:41:40 +02:00
|
|
|
# Ushahidi
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('ushahidi'):
|
|
|
|
replace_file_line('/srv/ushahidi/conf/config.json', ' "google_analytics_id": ', '"{}"'.format(api_key))
|
2018-08-02 10:41:40 +02:00
|
|
|
|
|
|
|
def update_email(email):
|
|
|
|
# CKAN
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('ckan'):
|
|
|
|
replace_file_line('/srv/ckan/conf/ckan.ini', 'smtp.mail_from = ', email)
|
|
|
|
replace_file_line('/srv/ckan-datapusher/conf/datapusher_settings.py', 'FROM_EMAIL = ', '\'{}\''.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Crisis Cleanup
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('crisiscleanup'):
|
|
|
|
replace_file_line('/srv/crisiscleanup/conf/initializers/devise.rb', ' config.mailer_sender = ', '\'{}\''.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# CTS
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('cts'):
|
|
|
|
replace_file_line('/srv/cts/conf/spotter.py', 'SERVER_EMAIL = ', '\'{}\''.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# GNU Health
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('gnuhealth'):
|
|
|
|
replace_file_line('/srv/gnuhealth/conf/trytond.conf', 'from = ', email)
|
2018-08-02 10:41:40 +02:00
|
|
|
# KanBoard
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('kanboard'):
|
|
|
|
replace_file_line('/srv/kanboard/conf/config.php', 'define(\'MAIL_FROM\', ', '\'{}\');'.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Mifos X
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('mifosx'):
|
|
|
|
query = 'UPDATE `c_external_service_properties` SET `value` = "{}" WHERE `external_service_id` = 2 and `name` LIKE "username";'.format(email)
|
|
|
|
run_mysql_query(query, 'mifostenant-default')
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sahana
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sahana'):
|
|
|
|
replace_file_line('/srv/sahana/conf/000_config.py', 'settings.mail.sender = ', '"{}"'.format(email))
|
|
|
|
replace_file_line('/srv/sahana/conf/000_config.py', 'settings.mail.approver = ', '"{}"'.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sahana Demo
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sahana-demo'):
|
|
|
|
replace_file_line('/srv/sahana-demo/conf/000_config.py', 'settings.mail.sender = ', '"{}"'.format(email))
|
|
|
|
replace_file_line('/srv/sahana-demo/conf/000_config.py', 'settings.mail.approver = ', '"{}"'.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# SAMBRO
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sambro'):
|
|
|
|
replace_file_line('/srv/sambro/conf/000_config.py', 'settings.mail.sender = ', '"{}"'.format(email))
|
|
|
|
replace_file_line('/srv/sambro/conf/000_config.py', 'settings.mail.approver = ', '"{}"'.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# SeedDMS
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('seeddms'):
|
|
|
|
replace_file_line('/srv/seeddms/conf/settings.xml', ' <smtp smtpServer="postfix" smtpPort="25" smtpSendFrom=', '"{}" smtpUser="" smtpPassword=""/>'.format(email))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sigmah
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sigmah'):
|
|
|
|
replace_file_line('/srv/sigmah/conf/sigmah.properties', 'mail.from.address=', email)
|
|
|
|
replace_file_line('/srv/sigmah/conf/sigmah.properties', 'mail.support.to=', email)
|
2018-08-02 10:41:40 +02:00
|
|
|
# Ushahidi
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('ushahidi'):
|
2018-08-30 20:11:38 +02:00
|
|
|
email_json = '{{\\"incoming_type\\":\\"IMAP\\",\\"incoming_server\\":\\"localhost\\",\\"incoming_port\\":143,\\"incoming_security\\":\\"None\\",\\"incoming_username\\":\\"{}\\",\\"incoming_password\\":\\"password\\",\\"outgoing_type\\":\\"SMTP\\",\\"outgoing_server\\":\\"postfix\\",\\"outgoing_port\\":25,\\"outgoing_security\\":\\"None\\",\\"outgoing_username\\":\\"{}\\",\\"outgoing_password\\":\\"password\\",\\"from\\":\\"{}\\",\\"from_name\\":\\"Ushahidi\\"}}'.format(email, email, email)
|
2018-08-14 15:36:09 +02:00
|
|
|
query = 'UPDATE `config` SET `config_value` = "{}" WHERE `group_name` LIKE "data-provider" AND `config_key` LIKE "email";'.format(email_json)
|
|
|
|
run_mysql_query(query, 'ushahidi')
|
2018-08-30 20:11:38 +02:00
|
|
|
query = 'UPDATE `config` SET `config_value` = "\\"{}\\"" WHERE `group_name` LIKE "site" AND `config_key` LIKE "email";'.format(email)
|
2018-08-29 11:05:09 +02:00
|
|
|
run_mysql_query(query, 'ushahidi')
|
2018-08-02 10:41:40 +02:00
|
|
|
|
|
|
|
def update_url(host):
|
|
|
|
# CKAN
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('ckan'):
|
|
|
|
replace_file_line('/srv/ckan/conf/ckan.ini', 'ckan.site_url = ', 'https://ckan.{}'.format(host))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Motech
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('motech'):
|
|
|
|
replace_file_line('/srv/motech/conf/config/motech-settings.properties', 'server.url=', 'https://motech.{}'.format(host))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Pan.do/ra
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('pandora'):
|
|
|
|
replace_file_line('/srv/pandora/conf/config.jsonc', ' "url": ', '"pandora.{}"'.format(host))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sahana
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sahana'):
|
|
|
|
replace_file_line('/srv/sahana/conf/000_config.py', 'settings.base.public_url = ', '"https://sahana.{}"'.format(host))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Sahana Demo
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sahana-demo'):
|
|
|
|
replace_file_line('/srv/sahana-demo/conf/000_config.py', 'settings.base.public_url = ', '"https://sahana-demo.{}"'.format(host))
|
2018-08-02 10:41:40 +02:00
|
|
|
# SAMBRO
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('sambro'):
|
|
|
|
replace_file_line('/srv/sambro/conf/000_config.py', 'settings.base.public_url = ', '"https://sambro.{}"'.format(host))
|
2018-08-02 10:41:40 +02:00
|
|
|
# Ushahidi
|
2018-08-14 15:36:09 +02:00
|
|
|
if app_exists('ushahidi'):
|
|
|
|
replace_file_line('/srv/ushahidi/conf/config.json', ' "backend_url": ', '"https://ush.{}/platform",'.format(host))
|
2018-08-14 17:38:54 +02:00
|
|
|
api_url = '\\"https:\\\\/\\\\/ush.{}\\\\/platform\\\\/api\\\\/v3\\\\/config\\\\/data-provider\\"'.format(host)
|
2018-08-14 15:36:09 +02:00
|
|
|
query = 'UPDATE `config` SET `config_value` = "{}" WHERE `group_name` LIKE "data-provider" AND `config_key` LIKE "url";'.format(api_url)
|
|
|
|
run_mysql_query(query, 'ushahidi')
|