diff --git a/glances/client.py b/glances/client.py index a8f659bd6..dd7867785 100644 --- a/glances/client.py +++ b/glances/client.py @@ -11,15 +11,20 @@ import sys import time +from defusedxml import xmlrpc + from glances import __version__ -from glances.globals import Fault, ProtocolError, ServerProxy, Transport, json_loads +from glances.globals import json_loads from glances.logger import logger from glances.outputs.glances_curses import GlancesCursesClient from glances.stats_client import GlancesStatsClient from glances.timer import Counter +# Correct issue #1025 by monkey path the xmlrpc lib +xmlrpc.monkey_patch() + -class GlancesClientTransport(Transport): +class GlancesClientTransport(xmlrpc.xmlrpc_client.Transport): """This class overwrite the default XML-RPC transport and manage timeout.""" def set_timeout(self, timeout): @@ -57,7 +62,7 @@ def __init__(self, config=None, args=None, timeout=7, return_to_browser=False): # Configure the server timeout transport.set_timeout(timeout) try: - self.client = ServerProxy(self.uri, transport=transport) + self.client = xmlrpc.xmlrpc_client.ServerProxy(self.uri, transport=transport) except Exception as e: self.log_and_exit(f"Client couldn't create socket {self.uri}: {e}") @@ -101,7 +106,7 @@ def _login_glances(self): print(fall_back_msg) else: logger.info(fall_back_msg) - except ProtocolError as err: + except xmlrpc.xmlrpc_client.ProtocolError as err: # Other errors msg = f"Connection to server {self.uri} failed" if err.errcode == 401: @@ -197,7 +202,7 @@ def update_glances(self): except OSError: # Client cannot get server stats return "Disconnected" - except Fault: + except xmlrpc.xmlrpc_client.Fault: # Client cannot get server stats (issue #375) return "Disconnected" else: diff --git a/glances/client_browser.py b/glances/client_browser.py index 47bd6645d..06d4fbf36 100644 --- a/glances/client_browser.py +++ b/glances/client_browser.py @@ -10,14 +10,19 @@ import threading +from defusedxml import xmlrpc + from glances.autodiscover import GlancesAutoDiscoverServer from glances.client import GlancesClient, GlancesClientTransport -from glances.globals import Fault, ProtocolError, ServerProxy, json_loads +from glances.globals import json_loads from glances.logger import LOG_FILENAME, logger from glances.outputs.glances_curses_browser import GlancesCursesBrowser from glances.password_list import GlancesPasswordList as GlancesPassword from glances.static_list import GlancesStaticServer +# Correct issue #1025 by monkey path the xmlrpc lib +xmlrpc.monkey_patch() + class GlancesClientBrowser: """This class creates and manages the TCP client browser (servers list).""" @@ -86,7 +91,7 @@ def __update_stats(self, server): # Get common stats from Glances server try: - s = ServerProxy(uri, transport=t) + s = xmlrpc.xmlrpc_client.ServerProxy(uri, transport=t) except Exception as e: logger.warning(f"Client browser couldn't create socket ({e})") return server @@ -107,12 +112,12 @@ def __update_stats(self, server): if 'key' in column: d_json = d_json.get(column['key']) server[server_key + '_decoration'] = d_json[column['field']]['decoration'] - except (KeyError, IndexError, Fault) as e: + except (KeyError, IndexError, xmlrpc.xmlrpc_client.Fault) as e: logger.debug(f"Error while grabbing stats form server ({e})") except OSError as e: logger.debug(f"Error while grabbing stats form server ({e})") server['status'] = 'OFFLINE' - except ProtocolError as e: + except xmlrpc.xmlrpc_client.ProtocolError as e: if e.errcode == 401: # Error 401 (Authentication failed) # Password is not the good one... diff --git a/glances/globals.py b/glances/globals.py index d0d78ba63..98d20008d 100644 --- a/glances/globals.py +++ b/glances/globals.py @@ -33,12 +33,6 @@ from urllib.parse import urlparse from urllib.request import Request, urlopen from xmlrpc.client import Fault, ProtocolError, Server, ServerProxy, Transport -from xmlrpc.server import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer - -from defusedxml.xmlrpc import monkey_patch - -# Correct issue #1025 by monkey path the xmlrpc lib -monkey_patch() # Prefer faster libs for JSON (de)serialization # Preference Order: orjson > ujson > json (builtin) diff --git a/glances/server.py b/glances/server.py index ce33c5a08..25f342133 100644 --- a/glances/server.py +++ b/glances/server.py @@ -13,15 +13,19 @@ import sys from base64 import b64decode +from defusedxml import xmlrpc + from glances import __version__ from glances.autodiscover import GlancesAutoDiscoverClient -from glances.globals import SimpleXMLRPCRequestHandler, SimpleXMLRPCServer from glances.logger import logger from glances.stats_server import GlancesStatsServer from glances.timer import Timer +# Correct issue #1025 by monkey path the xmlrpc lib +xmlrpc.monkey_patch() + -class GlancesXMLRPCHandler(SimpleXMLRPCRequestHandler): +class GlancesXMLRPCHandler(xmlrpc.xmlrpc_server.SimpleXMLRPCRequestHandler): """Main XML-RPC handler.""" rpc_paths = ('/RPC2',) @@ -71,7 +75,7 @@ def check_user(self, username, password): return False def parse_request(self): - if SimpleXMLRPCRequestHandler.parse_request(self): + if xmlrpc.xmlrpc_server.SimpleXMLRPCRequestHandler.parse_request(self): # Next we authenticate if self.authenticate(self.headers): return True @@ -84,7 +88,7 @@ def log_message(self, log_format, *args): pass -class GlancesXMLRPCServer(SimpleXMLRPCServer): +class GlancesXMLRPCServer(xmlrpc.xmlrpc_server.SimpleXMLRPCServer): """Init a SimpleXMLRPCServer instance (IPv6-ready).""" finished = False