diff --git a/files/geant_acme_web.py b/files/geant_acme_web.py index b3bc094e7bf6e6744446e36f5e8aad7b117896a7..1a08ee71f817a74947393d542f108265bb992857 100644 --- a/files/geant_acme_web.py +++ b/files/geant_acme_web.py @@ -8,7 +8,8 @@ from flask import request from flask import render_template from flask import send_from_directory -APP = Flask(__name__, template_folder='/var/www/acme_web', static_url_path='') +APP = Flask(__name__, root_path='/var/www/acme_web', template_folder='/var/www/acme_web', + static_folder='static', static_url_path='/var/www/acme_web') BASE_URLS = ['/sectigo_ev', '/sectigo_ov', '/letsencrypt', '/sectigo_ev/', '/sectigo_ov/', '/letsencrypt/', '/sectigo_ev/index.html', '/sectigo_ov/index.html', @@ -17,23 +18,27 @@ EXPIRED_URLS = ['/sectigo_ev/expiry_date.html', '/sectigo_ov/expiry_date.html', '/letsencrypt/expiry_date.html'] +def create_json(provider): + """ runs cert2json """ + script_cmd = ["cert2json.sh", provider] + print(script_cmd) + sp.Popen(script_cmd, stdout=sp.PIPE, stderr=sp.PIPE) + + @APP.route('/<provider>') -@APP.route('/static/<path:path>') +@APP.route('/static/<filename>') @APP.route('/') -def index(provider=None): +def index(provider=None, filename=None): """ check the git environment and run g10k """ url_name = str(request.path) - - def create_json(provider): - """ runs cert2json """ - script_cmd = "/usr/bin/cert2json.sh {}".format(provider) - print(script_cmd.split()) - sp.Popen(script_cmd.split(), stdout=sp.PIPE, stderr=sp.STDOUT) - return True + print("provider is {}".format(provider)) if url_name == '/': return render_template("index.html") + if url_name.startswith("/static") or url_name.startswith("static"): + return send_from_directory(APP.static_folder, filename) + if url_name in BASE_URLS: stripped_url = url_name.replace("/", "") create_json(stripped_url) @@ -44,8 +49,8 @@ def index(provider=None): create_json(stripped_url) return render_template("{}/expiry_date.html".format(stripped_url)) - if url_name.startswith('static'): - return send_from_directory('static', provider) + return "Oh no! NOT Found", 404 + if __name__ == '__main__': diff --git a/manifests/flask/files.pp b/manifests/flask/files.pp index 48e66cc3afe1be5c792d195b403c01febef4f24b..195910b4d1afb4805d74adb533f2a7be0b61d27e 100644 --- a/manifests/flask/files.pp +++ b/manifests/flask/files.pp @@ -12,7 +12,7 @@ class geant_acme::flask::files ($web_base = $geant_acme::params::web_base) { notify => Service['acme-web'], source => "puppet:///modules/${module_name}/geant_acme_web.py"; '/usr/bin/cert2json.sh': - content => "#!/usr/bin/bash\n/usr/bin/flock /tmp/cert2json.lock /root/bin/cert2json.py -p \$1\n"; + content => "#!/usr/bin/bash\n/usr/bin/flock /tmp/${1}_cert2json.lock /root/bin/cert2json.py -p \$1\n"; '/root/bin/cert2json.py': source => "puppet:///modules/${module_name}/cert2json.py"; [$web_base, "${web_base}/letsencrypt", "${web_base}/sectigo_ov", "${web_base}/sectigo_ev"]: @@ -37,31 +37,37 @@ class geant_acme::flask::files ($web_base = $geant_acme::params::web_base) { source => 'puppet:///modules/depot/anvil/anvil.png'; "${web_base}/letsencrypt/index.html": content => epp("${module_name}/index.html.epp", { + provider => 'letsencrypt', json_file => 'letsencrypt', html_title => 'LetsEncrypt'} ); "${web_base}/letsencrypt/expiry_date.html": content => epp("${module_name}/index.html.epp", { + provider => 'letsencrypt', json_file => 'letsencrypt_expired', html_title => 'LetsEncrypt'} ); "${web_base}/sectigo_ev/index.html": content => epp("${module_name}/index.html.epp", { + provider => 'sectigo_ev', json_file => 'sectigo_ev', html_title => 'SectiGO EV'} ); "${web_base}/sectigo_ev/expiry_date.html": content => epp("${module_name}/index.html.epp", { + provider => 'sectigo_ev', json_file => 'sectigo_ev_expired', html_title => 'SectiGO EV'} ); "${web_base}/sectigo_ov/index.html": content => epp("${module_name}/index.html.epp", { + provider => 'sectigo_ov', json_file => 'sectigo_ov', html_title => 'SectiGO OV'} ); "${web_base}/sectigo_ov/expiry_date.html": content => epp("${module_name}/index.html.epp", { + provider => 'sectigo_ov', json_file => 'sectigo_ov_expired', html_title => 'SectiGO OV'} );