From 3f25fa25ab4de5ddaa571757f286bcae3275414b Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Tue, 21 Nov 2023 17:25:36 +0100 Subject: [PATCH] web proxy: fix setting unknown directory Not great, needs a full refactor. --- .../service/modules/addons/template_helpers.py | 4 ++-- .../service/templates/OPNsense/Proxy/squid.conf | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/opnsense/service/modules/addons/template_helpers.py b/src/opnsense/service/modules/addons/template_helpers.py index 81c01fb7c..9c0598bf4 100644 --- a/src/opnsense/service/modules/addons/template_helpers.py +++ b/src/opnsense/service/modules/addons/template_helpers.py @@ -182,10 +182,10 @@ class Helpers(object): :return: bool """ if pathname.startswith('/'): - return os.path.isfile(pathname) + return os.path.exists(pathname) else: template_path = os.path.realpath("%s/../../templates/" % os.path.dirname(__file__)) - return os.path.isfile("%s/%s" % (template_path, pathname)) + return os.path.exists("%s/%s" % (template_path, pathname)) @staticmethod def glob(pathname): diff --git a/src/opnsense/service/templates/OPNsense/Proxy/squid.conf b/src/opnsense/service/templates/OPNsense/Proxy/squid.conf index b7afcd33c..5cdba7560 100644 --- a/src/opnsense/service/templates/OPNsense/Proxy/squid.conf +++ b/src/opnsense/service/templates/OPNsense/Proxy/squid.conf @@ -468,9 +468,19 @@ cache_mgr {{OPNsense.proxy.general.VisibleEmail}} # Set connection timeout connect_timeout {{OPNsense.proxy.general.connecttimeout}} seconds {% endif %} +# Set error directory language {% if not helpers.empty('OPNsense.proxy.general.error_pages') %} error_directory /usr/local/etc/squid/errors/local {% elif helpers.exists('system.language') and system.language != "" %} -# XXX this can end up selecting a nonexistent directory because most languages are without a country shortcut -error_directory /usr/local/share/squid-langpack/{{ system.language|lower|replace("_","-")}} +{% set langdir = system.language|lower|replace('_', '-') %} +{% if helpers.file_exists('/usr/local/share/squid-langpack/' + langdir) %} +error_directory /usr/local/share/squid-langpack/{{ langdir }} +{% else %} +{% set langdir = langdir[:2] %} +{% if helpers.file_exists('/usr/local/share/squid-langpack/' + langdir) %} +error_directory /usr/local/share/squid-langpack/{{ langdir }} +{% else %} +error_directory /usr/local/etc/squid/errors/local +{% endif %} +{% endif %} {% endif %}