Skip to content

Commit

Permalink
Hide password in the Glances browser form #503
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolargo committed May 9, 2024
1 parent b8304d8 commit e7a3de5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Enhancements:
* [WebUI] Added smart plugin support #2435
* No more threshold display in the WebUI cpu/mem and memswap plugins #2420
* Refactor Glances curses code #2580
* Hide password in the Glances browser form #503
* Replace Bottle by FastAPI #2181
* Replace py3nvml with nvidia-ml-py #2688

Expand Down
3 changes: 2 additions & 1 deletion glances/client_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ def __display_server(self, server):
# Else, the password should be enter by the user
# Display a popup to enter password
clear_password = self.screen.display_popup(
'Password needed for {}: '.format(server['name']), is_input=True
'Password needed for {}: '.format(server['name']),
popup_type='input', is_password=True
)
# Store the password for the selected server
if clear_password is not None:
Expand Down
35 changes: 24 additions & 11 deletions glances/outputs/glances_curses.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from __future__ import unicode_literals

import sys
import getpass

from glances.globals import MACOS, WINDOWS, nativestr, u, itervalues, enable, disable
from glances.logger import logger
Expand Down Expand Up @@ -920,12 +921,17 @@ def __display_right(self, stat_display):
self.display_plugin(stat_display[p])

def display_popup(
self, message, size_x=None, size_y=None, duration=3, popup_type='info', input_size=30, input_value=None
self, message,
size_x=None, size_y=None,
duration=3,
popup_type='info',
input_size=30, input_value=None,
is_password=False
):
"""
Display a centered popup.
popup_type: ='info'
popup_type: ='info'
Just an information popup, no user interaction
Display a centered popup with the given message during duration seconds
If size_x and size_y: set the popup size
Expand Down Expand Up @@ -978,6 +984,8 @@ def display_popup(
self.wait(duration * 1000)
return True
elif popup_type == 'input':
logger.info(popup_type)
logger.info(is_password)
# Create a sub-window for the text field
sub_pop = popup.derwin(1, input_size, 2, 2 + len(m))
sub_pop.attron(self.colors_list['FILTER'])
Expand All @@ -990,16 +998,21 @@ def display_popup(
# Create the textbox inside the sub-windows
self.set_cursor(2)
self.term_window.keypad(1)
textbox = GlancesTextbox(sub_pop, insert_mode=True)
textbox.edit()
self.set_cursor(0)
# self.term_window.keypad(0)
if textbox.gather() != '':
logger.debug("User enters the following string: %s" % textbox.gather())
return textbox.gather()[:-1]
if is_password:
textbox = getpass.getpass('')
self.set_cursor(0)
if textbox != '':
return textbox
else:
return None
else:
logger.debug("User enters an empty string")
return None
textbox = GlancesTextbox(sub_pop, insert_mode=True)
textbox.edit()
self.set_cursor(0)
if textbox.gather() != '':
return textbox.gather()[:-1]
else:
return None
elif popup_type == 'yesno':
# # Create a sub-window for the text field
sub_pop = popup.derwin(1, 2, len(sentence_list) + 1, len(m) + 2)
Expand Down
1 change: 0 additions & 1 deletion glances/password.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ def check_password(self, hashed_password, plain_password):
Return the comparison with the encrypted_password.
"""
logger.info("Check password")
salt, encrypted_password = hashed_password.split('$')
re_encrypted_password = self.get_hash(plain_password, salt=salt)
return encrypted_password == re_encrypted_password
Expand Down
3 changes: 2 additions & 1 deletion glances/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def check_user(self, username, password):
if username in self.server.user_dict:
from glances.password import GlancesPassword

pwd = GlancesPassword(username=username, config=self.config)
# TODO: config is not taken into account: it may be a problem ?
pwd = GlancesPassword(username=username, config=None)
return pwd.check_password(self.server.user_dict[username], password)
else:
return False
Expand Down

0 comments on commit e7a3de5

Please sign in to comment.