diff --git a/pgadmin/__init__.py b/pgadmin/__init__.py index c20016bbc..42ccfd874 100644 --- a/pgadmin/__init__.py +++ b/pgadmin/__init__.py @@ -586,10 +586,22 @@ def create_app(app_name=None): servergroup = servergroups.first() servergroup_id = servergroup.id + # BEGIN Yunohost Patch + from pgadmin.utils.master_password import get_crypt_key + from pgadmin.utils.exception import CryptKeyMissing + from pgadmin.utils.crypto import encrypt + + crypt_key_present, crypt_key = get_crypt_key() + if not crypt_key_present: + raise CryptKeyMissing + # END Yunohost Patch + '''Add a server to the config database''' + # BEGIN Yunohost Patch def add_server(user_id, servergroup_id, name, superuser, port, - discovery_id, comment): + discovery_id, comment, password): + # END Yunohost Patch # Create a server object if needed, and store it. servers = Server.query.filter_by( user_id=user_id, @@ -609,7 +621,11 @@ def create_app(app_name=None): connection_params={'sslmode': 'prefer', 'connect_timeout': 10}, comment=comment, - discovery_id=discovery_id) + # BEGIN Yunohost Patch + discovery_id=discovery_id, + password=encrypt(password, crypt_key), + save_password=1) + # END Yunohost Patch db.session.add(svr) db.session.commit() @@ -676,7 +692,7 @@ def create_app(app_name=None): registry = ConfigParser() try: - registry.read('/etc/postgres-reg.ini') + registry.read(config.REGISTRY_CONFIG_FILE) sections = registry.sections() # Loop the sections, and get the data from any that are PG or PPAS @@ -703,9 +719,12 @@ def create_app(app_name=None): svr_comment = gettext("Auto-detected {0} installation " "with the data directory at {1}" ).format(description, data_directory) + # BEGIN Yunohost Patch + password = registry.get(section, 'Password') add_server(user_id, servergroup_id, svr_name, svr_superuser, svr_port, svr_discovery_id, - svr_comment) + svr_comment, password) + # END Yunohost Patch except Exception as e: print(str(e))