From 0302cdcd57edc631bab28312c94429aada6a874d Mon Sep 17 00:00:00 2001 From: nicolargo Date: Sun, 16 Oct 2022 10:32:35 +0200 Subject: [PATCH] Password files in same configuration dir in effect #2143 --- conf/glances.conf | 5 ++++- glances/password.py | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/conf/glances.conf b/conf/glances.conf index 86c2b92a..986b523a 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -432,13 +432,16 @@ disable=False #server_4_port=61237 [passwords] -# Define the passwords list +# Define the passwords list related to the [serverlist] section # Syntax: host=password # Where: host is the hostname # password is the clear password # Additionally (and optionally) a default password could be defined #localhost=abc #default=defaultpassword +# +# Define the path of the local '.pwd' file (default is system one) +#local_password_path=~/.config/glances ############################################################################## # Exports diff --git a/glances/password.py b/glances/password.py index e3b1a8d9..26919ca6 100644 --- a/glances/password.py +++ b/glances/password.py @@ -26,12 +26,22 @@ class GlancesPassword(object): """This class contains all the methods relating to password.""" - def __init__(self, username='glances'): + def __init__(self, username='glances', config=None): self.username = username - self.password_dir = user_config_dir() + + self.config = config + self.password_dir = self.local_password_path() self.password_filename = self.username + '.pwd' self.password_file = os.path.join(self.password_dir, self.password_filename) + def local_password_path(self): + """Return the local password path. + Related toissue: Password files in same configuration dir in effect #2143 + """ + return self.config.get_value('passwords', + 'local_password_path', + default=user_config_dir()) + def sha256_hash(self, plain_password): """Return the SHA-256 of the given password.""" return hashlib.sha256(b(plain_password)).hexdigest()