templating - auth basic support

This commit is contained in:
bunkerity 2021-05-25 12:18:40 +02:00
parent 289ad106cb
commit 23aa053003
No known key found for this signature in database
GPG Key ID: 3D80806F12602A7C
4 changed files with 13 additions and 3 deletions

View File

@ -1,2 +1,2 @@
auth_basic "{{ AUTH_BASIC_TEXT }}";
auth_basic_user_file {{ NGINX_PREFIX }}.htpasswd;
auth_basic_user_file {{ NGINX_PREFIX }}htpasswd;

View File

@ -1,4 +1,4 @@
location {{ AUTH_BASIC_LOCATION }} {
auth_basic "{{ AUTH_BASIC_TEXT }}";
auth_basic_user_file {{ NGINX_PREFIX }}.htpasswd;
auth_basic_user_file {{ NGINX_PREFIX }}htpasswd;
}

3
confs2/site/htpasswd Normal file
View File

@ -0,0 +1,3 @@
{% if USE_AUTH_BASIC == "yes" %}
{{ AUTH_BASIC_USER }}:{{ sha512_crypt(AUTH_BASIC_PASSWORD) }}
{% endif %}

View File

@ -1,4 +1,4 @@
import jinja2, glob, os, pathlib, copy
import jinja2, glob, os, pathlib, copy, crypt
class Templator :
@ -30,11 +30,15 @@ class Templator :
real_config["NGINX_PREFIX"] = self.__target_path
if real_config["MULTISITE"] == "yes" and type == "site" :
real_config["NGINX_PREFIX"] += first_server + "/"
for variable, value in self.__config.items() :
if variable.startswith(first_server + "_") :
real_config[variable.replace(first_server + "_", "", 1)] = value
for filename in glob.iglob(self.__input_path + "/" + type + "**/**", recursive=True) :
if os.path.isfile(filename) :
relative_filename = filename.replace(self.__input_path, "").replace(type + "/", "")
template = self.__template_env.get_template(type + "/" + relative_filename)
template.globals["has_value"] = Templator.has_value
template.globals["sha512_crypt"] = Templator.sha512_crypt
output = template.render(real_config, all=real_config)
if real_config["MULTISITE"] == "yes" and type == "site" :
relative_filename = first_server + "/" + relative_filename
@ -50,3 +54,6 @@ class Templator :
if (k == name or k.endswith("_" + name)) and v == value :
return True
return False
def sha512_crypt(password) :
return crypt.crypt(password, crypt.mksalt(crypt.METHOD_SHA512))