web proxy: fix setting unknown directory

Not great, needs a full refactor.
This commit is contained in:
Franco Fichtner 2023-11-21 17:25:36 +01:00
parent e76bc6ead8
commit 3f25fa25ab
2 changed files with 14 additions and 4 deletions

View File

@ -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):

View File

@ -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 %}