Merge branch 'develop' of github.com:nicolargo/glances into issue1985

This commit is contained in:
nicolargo 2023-02-25 15:05:20 +01:00
commit 2fb510afb0
10 changed files with 21 additions and 30 deletions

View File

@ -173,11 +173,7 @@ class Config(object):
if not self.parser.has_section('global'): if not self.parser.has_section('global'):
self.parser.add_section('global') self.parser.add_section('global')
self.set_default('global', 'strftime_format', '') self.set_default('global', 'strftime_format', '')
self.set_default('global', 'check_update', 'true')
# check_update
if not self.parser.has_section('global'):
self.parser.add_section('global')
self.set_default('global', 'check_update', 'false')
# Quicklook # Quicklook
if not self.parser.has_section('quicklook'): if not self.parser.has_section('quicklook'):

View File

@ -111,7 +111,6 @@ class Export(GlancesExport):
# Write input to the Cassandra table # Write input to the Cassandra table
try: try:
stmt = "INSERT INTO {} (plugin, time, stat) VALUES (?, ?, ?)".format(self.table) stmt = "INSERT INTO {} (plugin, time, stat) VALUES (?, ?, ?)".format(self.table)
query = self.session.prepare(stmt) query = self.session.prepare(stmt)
self.session.execute(query, (name, uuid_from_time(datetime.now()), data)) self.session.execute(query, (name, uuid_from_time(datetime.now()), data))

View File

@ -47,10 +47,7 @@ class Export(GlancesExport):
if not self.export_enable: if not self.export_enable:
return None return None
server_uri = 'mongodb://%s:%s@%s:%s' % (quote_plus(self.user), server_uri = 'mongodb://%s:%s@%s:%s' % (quote_plus(self.user), quote_plus(self.password), self.host, self.port)
quote_plus(self.password),
self.host,
self.port)
try: try:
client = pymongo.MongoClient(server_uri) client = pymongo.MongoClient(server_uri)

View File

@ -49,10 +49,15 @@ class Outdated(object):
# Set default value... # Set default value...
self.data = {u'installed_version': __version__, u'latest_version': '0.0', u'refresh_date': datetime.now()} self.data = {u'installed_version': __version__, u'latest_version': '0.0', u'refresh_date': datetime.now()}
# Read the configuration file
self.load_config(config) # Disable update check if `packaging` is not installed
if not PACKAGING_IMPORT: if not PACKAGING_IMPORT:
self.args.disable_check_update = True self.args.disable_check_update = True
# Read the configuration file only if update check is not explicitly disabled
if not self.args.disable_check_update:
self.load_config(config)
logger.debug("Check Glances version up-to-date: {}".format(not self.args.disable_check_update)) logger.debug("Check Glances version up-to-date: {}".format(not self.args.disable_check_update))
# And update ! # And update !

View File

@ -127,10 +127,8 @@ class GlancesBottle(object):
if username == self.args.username: if username == self.args.username:
from glances.password import GlancesPassword from glances.password import GlancesPassword
pwd = GlancesPassword(username=username, pwd = GlancesPassword(username=username, config=self.config)
config=self.config) return pwd.check_password(self.args.password, pwd.get_hash(password))
return pwd.check_password(self.args.password,
pwd.get_hash(password))
else: else:
return False return False
@ -162,7 +160,9 @@ class GlancesBottle(object):
'/api/%s/<plugin>/<item>/history/<nb:int>' % self.API_VERSION, method="GET", callback=self._api_item_history '/api/%s/<plugin>/<item>/history/<nb:int>' % self.API_VERSION, method="GET", callback=self._api_item_history
) )
self._app.route('/api/%s/<plugin>/<item>/<value>' % self.API_VERSION, method="GET", callback=self._api_value) self._app.route('/api/%s/<plugin>/<item>/<value>' % self.API_VERSION, method="GET", callback=self._api_value)
self._app.route('/api/%s/<plugin>/<item>/<value:path>' % self.API_VERSION, method="GET", callback=self._api_value) self._app.route(
'/api/%s/<plugin>/<item>/<value:path>' % self.API_VERSION, method="GET", callback=self._api_value
)
bindmsg = 'Glances RESTful API Server started on {}api/{}/'.format(self.bind_url, self.API_VERSION) bindmsg = 'Glances RESTful API Server started on {}api/{}/'.format(self.bind_url, self.API_VERSION)
logger.info(bindmsg) logger.info(bindmsg)

View File

@ -45,17 +45,12 @@ class GlancesPassword(object):
def get_hash(self, plain_password, salt=''): def get_hash(self, plain_password, salt=''):
"""Return the hashed password, salt + pbkdf2_hmac.""" """Return the hashed password, salt + pbkdf2_hmac."""
return to_hex(hashlib.pbkdf2_hmac('sha256', return to_hex(hashlib.pbkdf2_hmac('sha256', plain_password.encode(), salt.encode(), 100000, dklen=128))
plain_password.encode(),
salt.encode(),
100000,
dklen=128))
def hash_password(self, plain_password): def hash_password(self, plain_password):
"""Hash password with a salt based on UUID (universally unique identifier).""" """Hash password with a salt based on UUID (universally unique identifier)."""
salt = uuid.uuid4().hex salt = uuid.uuid4().hex
encrypted_password = self.get_hash(plain_password, encrypted_password = self.get_hash(plain_password, salt=salt)
salt=salt)
return salt + '$' + encrypted_password return salt + '$' + encrypted_password
def check_password(self, hashed_password, plain_password): def check_password(self, hashed_password, plain_password):
@ -64,8 +59,7 @@ class GlancesPassword(object):
Return the comparison with the encrypted_password. Return the comparison with the encrypted_password.
""" """
salt, encrypted_password = hashed_password.split('$') salt, encrypted_password = hashed_password.split('$')
re_encrypted_password = self.get_hash(plain_password, re_encrypted_password = self.get_hash(plain_password, salt=salt)
salt = salt)
return encrypted_password == re_encrypted_password return encrypted_password == re_encrypted_password
def get_password(self, description='', confirm=False, clear=False): def get_password(self, description='', confirm=False, clear=False):

View File

@ -51,7 +51,7 @@ def __secure_popen(cmd):
for sub_cmd in cmd.split('|'): for sub_cmd in cmd.split('|'):
# Split by space character, but do no split spaces within quotes (remove surrounding quotes, though) # Split by space character, but do no split spaces within quotes (remove surrounding quotes, though)
tmp_split = [_ for _ in list(filter(None, re.split(r'(\s+)|(".*?"+?)|(\'.*?\'+?)', sub_cmd))) if _ != ' '] tmp_split = [_ for _ in list(filter(None, re.split(r'(\s+)|(".*?"+?)|(\'.*?\'+?)', sub_cmd))) if _ != ' ']
sub_cmd_split = [_[1:-1] if (_[0]==_[-1]=='"') or (_[0]==_[-1]=='\'') else _ for _ in tmp_split] sub_cmd_split = [_[1:-1] if (_[0] == _[-1] == '"') or (_[0] == _[-1] == '\'') else _ for _ in tmp_split]
p = Popen(sub_cmd_split, shell=False, stdin=sub_cmd_stdin, stdout=PIPE, stderr=PIPE) p = Popen(sub_cmd_split, shell=False, stdin=sub_cmd_stdin, stdout=PIPE, stderr=PIPE)
if p_last is not None: if p_last is not None:
# Allow p_last to receive a SIGPIPE if p exits. # Allow p_last to receive a SIGPIPE if p exits.

View File

@ -94,7 +94,6 @@ class GlancesXMLRPCServer(SimpleXMLRPCServer, object):
finished = False finished = False
def __init__(self, bind_address, bind_port=61209, requestHandler=GlancesXMLRPCHandler, config=None): def __init__(self, bind_address, bind_port=61209, requestHandler=GlancesXMLRPCHandler, config=None):
self.bind_address = bind_address self.bind_address = bind_address
self.bind_port = bind_port self.bind_port = bind_port
self.config = config self.config = config

View File

@ -24,7 +24,6 @@ class GlancesSNMPClient(object):
"""SNMP client class (based on pysnmp library).""" """SNMP client class (based on pysnmp library)."""
def __init__(self, host='localhost', port=161, version='2c', community='public', user='private', auth=''): def __init__(self, host='localhost', port=161, version='2c', community='public', user='private', auth=''):
super(GlancesSNMPClient, self).__init__() super(GlancesSNMPClient, self).__init__()
self.cmdGen = cmdgen.CommandGenerator() self.cmdGen = cmdgen.CommandGenerator()

View File

@ -14,7 +14,6 @@ import time
from glances.globals import WINDOWS from glances.globals import WINDOWS
from glances.logger import logger from glances.logger import logger
from glances.outputs.glances_stdout_json import GlancesStdoutJson
from glances.processes import glances_processes from glances.processes import glances_processes
from glances.stats import GlancesStats from glances.stats import GlancesStats
from glances.outputs.glances_curses import GlancesCursesStandalone from glances.outputs.glances_curses import GlancesCursesStandalone
@ -193,3 +192,6 @@ class GlancesStandalone(object):
) )
) )
print("You should consider upgrading using: pip install --upgrade glances") print("You should consider upgrading using: pip install --upgrade glances")
print("Disable this warning temporarily using: glances --disable-check-update")
print("To disable it permanently, refer config reference at "
"https://glances.readthedocs.io/en/latest/config.html#syntax")