Browse Source

Fixes theme_utils.dirlist allowed paths. Changed its behavior.

sisyphus
JezerM 3 years ago
parent
commit
c7e55022a1
No known key found for this signature in database
GPG Key ID: 66BBC5D01388C6B5
  1. 19
      web-greeter/bridge/ThemeUtils.py
  2. 2
      web-greeter/browser/browser.py

19
web-greeter/bridge/ThemeUtils.py

@ -28,7 +28,7 @@
# Standard Lib # Standard Lib
import os import os
from glob import glob import re
import tempfile import tempfile
# 3rd-Party Libs # 3rd-Party Libs
@ -36,6 +36,7 @@ from browser.bridge import Bridge, BridgeObject
from PyQt5.QtCore import QVariant from PyQt5.QtCore import QVariant
from config import web_greeter_config from config import web_greeter_config
from logger import logger
class ThemeUtils(BridgeObject): class ThemeUtils(BridgeObject):
@ -46,7 +47,9 @@ class ThemeUtils(BridgeObject):
self._greeter = greeter self._greeter = greeter
self._allowed_dirs = ( self._allowed_dirs = (
os.path.dirname(self._config["config"]["greeter"]["theme"]), os.path.dirname(
os.path.realpath(self._config["config"]["greeter"]["theme"])
),
self._config["app"]["theme_dir"], self._config["app"]["theme_dir"],
self._config["config"]["branding"]["background_images_dir"], self._config["config"]["branding"]["background_images_dir"],
self._greeter.shared_data_directory, self._greeter.shared_data_directory,
@ -74,17 +77,17 @@ class ThemeUtils(BridgeObject):
break break
if not allowed: if not allowed:
logger.error("Path \"" + dir_path + "\" is not allowed");
return [] return []
result = []
if only_images: if only_images:
file_types = ('jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp') for f in os.scandir(dir_path):
result = [ if f.is_file() and re.match(r".+\.(jpe?g|png|gif|bmp|webp)", f.name):
glob('{0}/**/*.{1}'.format(dir_path, ftype), recursive=True) result.append(f.path)
for ftype in file_types
]
result = [image for image_list in result for image in image_list]
else: else:
result = [os.path.join(dir_path, f) for f in os.listdir(dir_path)] result = [os.path.join(dir_path, f) for f in os.listdir(dir_path)]
result.sort()
return result return result

2
web-greeter/browser/browser.py

@ -258,6 +258,7 @@ class Browser(Application):
logger.debug("Browser Window created") logger.debug("Browser Window created")
def load(self): def load(self):
self.load_theme()
self.greeter = Greeter() self.greeter = Greeter()
self.greeter_config = Config() self.greeter_config = Config()
self.theme_utils = ThemeUtils(self.greeter) self.theme_utils = ThemeUtils(self.greeter)
@ -265,7 +266,6 @@ class Browser(Application):
self.bridge_objects = (self.greeter, self.greeter_config, self.theme_utils) self.bridge_objects = (self.greeter, self.greeter_config, self.theme_utils)
self.initialize_bridge_objects() self.initialize_bridge_objects()
self.load_script(':/_greeter/js/bundle.js', 'Web Greeter Bundle') self.load_script(':/_greeter/js/bundle.js', 'Web Greeter Bundle')
self.load_theme()
def _initialize_devtools(self): def _initialize_devtools(self):
self.dev_view = QWebEngineView(parent=self.window) self.dev_view = QWebEngineView(parent=self.window)

Loading…
Cancel
Save