From df66a7ffe9bf3b7cb8eebd10f234a3ab01f6ac0c Mon Sep 17 00:00:00 2001 From: nicolargo Date: Fri, 26 Apr 2024 09:28:24 +0200 Subject: [PATCH] Please add a startup flag to select an alternate web server static file path #2612 --- README.rst | 10 ++++++---- conf/glances.conf | 11 +++++++++-- docker-compose/glances.conf | 11 +++++++++-- glances/outputs/glances_restful_api.py | 12 ++++++++---- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 5c86f7dc..4d80de92 100644 --- a/README.rst +++ b/README.rst @@ -201,8 +201,8 @@ or *Note*: This is only supported on some GNU/Linux distributions and Mac OS X. If you want to support other distributions, please contribute to `glancesautoinstall`_. -Docker: the fun way -------------------- +Docker: the cloudy way +---------------------- Glances Docker images are availables. You can use it to monitor your server and all your containers ! @@ -268,7 +268,8 @@ may not be the latest version and only basics plugins are enabled. Note: The Debian package (and all other Debian-based distributions) do not include anymore the JS statics files used by the Web interface (see ``issue2021``). If you want to add it to your Glances installation, -follow the instructions: ``issue2021comment``. +follow the instructions: ``issue2021comment``. In Glances version 4 and +higher, the path to the statics file is configurable (see ``issue2612``). FreeBSD ------- @@ -490,6 +491,7 @@ Glances is distributed under the LGPL version 3 license. See ``COPYING`` for mor .. _package: https://repology.org/project/glances/versions .. _sponsors: https://github.com/sponsors/nicolargo .. _wishlist: https://www.amazon.fr/hz/wishlist/ls/BWAAQKWFR3FI?ref_=wl_share -.. _issue2021: https://github.com/nicolargo/glances/issues/2021#issuecomment-1197831157 +.. _issue2021: https://github.com/nicolargo/glances/issues/2021 .. _issue2021comment: https://github.com/nicolargo/glances/issues/2021#issuecomment-1197831157 +.. _issue2612: https://github.com/nicolargo/glances/issues/2612 .. _Docker: https://github.com/nicolargo/glances/blob/develop/docs/docker.rst diff --git a/conf/glances.conf b/conf/glances.conf index e3f52711..3f1ca9a7 100644 --- a/conf/glances.conf +++ b/conf/glances.conf @@ -29,11 +29,18 @@ separator=True #left_menu=network,wifi,connections,ports,diskio,fs,irq,folders,raid,smart,sensors,now # Limit the number of processes to display (for the WebUI) max_processes_display=25 -# Set the URL prefix (for the WebUI and the API) +# Set URL prefix for the WebUI and the API # Example: url_prefix=/glances/ => http://localhost/glances/ -# The final / is mandatory +# Note: The final / is mandatory # Default is no prefix (/) #url_prefix=/glances/ +# Set root path for WebUI statics files +# Why ? On Debian system, WebUI statics files are not provided. +# You can download it in a specific folder +# thanks to https://github.com/nicolargo/glances/issues/2021 +# then configure this folder with the webui_root_path key +# Default is folder where glances_restfull_api.py is hosted +#webui_root_path= ############################################################################## # plugins diff --git a/docker-compose/glances.conf b/docker-compose/glances.conf index de023d07..644bee55 100755 --- a/docker-compose/glances.conf +++ b/docker-compose/glances.conf @@ -29,11 +29,18 @@ separator=True #left_menu=network,wifi,connections,ports,diskio,fs,irq,folders,raid,smart,sensors,now # Limit the number of processes to display (for the WebUI) max_processes_display=25 -# Set the URL prefix (for the WebUI and the API) +# Set URL prefix for the WebUI and the API # Example: url_prefix=/glances/ => http://localhost/glances/ -# The final / is mandatory +# Note: The final / is mandatory # Default is no prefix (/) #url_prefix=/glances/ +# Set root path for WebUI statics files +# Why ? On Debian system, WebUI statics files are not provided. +# You can download it in a specific folder +# thanks to https://github.com/nicolargo/glances/issues/2021 +# then configure this folder with the webui_root_path key +# Default is folder where glances_restfull_api.py is hosted +#webui_root_path= ############################################################################## # plugins diff --git a/glances/outputs/glances_restful_api.py b/glances/outputs/glances_restful_api.py index 35935c77..178a52f0 100644 --- a/glances/outputs/glances_restful_api.py +++ b/glances/outputs/glances_restful_api.py @@ -2,7 +2,7 @@ # # This file is part of Glances. # -# SPDX-FileCopyrightText: 2023 Nicolas Hennion +# SPDX-FileCopyrightText: 2024 Nicolas Hennion # # SPDX-License-Identifier: LGPL-3.0-only # @@ -14,7 +14,6 @@ import sys import tempfile from io import open import webbrowser -import socket from urllib.parse import urljoin # Replace typing_extensions by typing when Python 3.8 support will be dropped @@ -115,8 +114,13 @@ class GlancesRestfulApi(object): self._app.include_router(APIRouter(prefix=self.url_prefix.rstrip('/'))) # Set path for WebUI - self.STATIC_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/public') - self.TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'static/templates') + webui_root_path = config.get_value('outputs', + 'webui_root_path', + default=os.path.dirname(os.path.realpath(__file__))) + if webui_root_path == '': + webui_root_path = os.path.dirname(os.path.realpath(__file__)) + self.STATIC_PATH = os.path.join(webui_root_path, 'static/public') + self.TEMPLATE_PATH = os.path.join(webui_root_path, 'static/templates') self._templates = Jinja2Templates(directory=self.TEMPLATE_PATH) # FastAPI Enable CORS