Skip to content
Snippets Groups Projects
Unverified Commit 07636992 authored by Max Adamo's avatar Max Adamo
Browse files

final changes to flask script

parent 273d3df8
No related branches found
No related tags found
No related merge requests found
...@@ -3,10 +3,7 @@ ...@@ -3,10 +3,7 @@
run flask CGI that will trigger cert2json.py -p <provider> run flask CGI that will trigger cert2json.py -p <provider>
""" """
import subprocess as sp import subprocess as sp
from flask import Flask from flask import Flask, request, redirect, render_template, send_from_directory
from flask import request
from flask import render_template
from flask import send_from_directory
APP = Flask(__name__, root_path='/var/www/acme_web', template_folder='/var/www/acme_web', 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') static_folder='static', static_url_path='/var/www/acme_web')
...@@ -14,6 +11,7 @@ BASE_URLS = ['/sectigo_ev', '/sectigo_ov', '/letsencrypt', ...@@ -14,6 +11,7 @@ BASE_URLS = ['/sectigo_ev', '/sectigo_ov', '/letsencrypt',
'/sectigo_ev/', '/sectigo_ov/', '/letsencrypt/'] '/sectigo_ev/', '/sectigo_ov/', '/letsencrypt/']
OTHER_URLS = ['/sectigo_ev/index.html', '/sectigo_ov/index.html', OTHER_URLS = ['/sectigo_ev/index.html', '/sectigo_ov/index.html',
'/letsencrypt/index.html', '/sectigo_ev/expiry_date.html', '/letsencrypt/index.html', '/sectigo_ev/expiry_date.html',
'/sectigo_ov/expiry_date.html', '/letsencrypt/expiry_date.html',
'/sectigo_ov/sectigo_ov.json', '/sectigo_ov/sectigo_ov_expired.json', '/sectigo_ov/sectigo_ov.json', '/sectigo_ov/sectigo_ov_expired.json',
'/sectigo_ov/sectigo_ev.json', '/sectigo_ov/sectigo_ev_expired.json', '/sectigo_ov/sectigo_ev.json', '/sectigo_ov/sectigo_ev_expired.json',
'/letsencrypt/letsencrypt.json', '/letsencrypt/letsencrypt_expired.json'] '/letsencrypt/letsencrypt.json', '/letsencrypt/letsencrypt_expired.json']
...@@ -21,17 +19,17 @@ OTHER_URLS = ['/sectigo_ev/index.html', '/sectigo_ov/index.html', ...@@ -21,17 +19,17 @@ OTHER_URLS = ['/sectigo_ev/index.html', '/sectigo_ov/index.html',
def create_json(provider): def create_json(provider):
""" runs cert2json """ """ runs cert2json """
script_cmd = ["cert2json.sh", provider] sp.Popen(["cert2json.sh", provider], stdout=sp.PIPE, stderr=sp.PIPE)
sp.Popen(script_cmd, stdout=sp.PIPE, stderr=sp.PIPE)
@APP.route('/<provider>') @APP.route('/<provider>')
@APP.route('/<provider>/<filename>')
@APP.route('/static/<filename>') @APP.route('/static/<filename>')
@APP.route('/') @APP.route('/')
def index(provider=None, filename=None): def index(provider=None, filename=None):
""" check the git environment and run g10k """ """ run cert2json.py and serve ACME static files """
url_name = str(request.path) url_name = str(request.path)
print("provider is {}".format(provider)) host_name = str(request.host_url)
if url_name == '/': if url_name == '/':
return render_template("index.html") return render_template("index.html")
...@@ -39,17 +37,12 @@ def index(provider=None, filename=None): ...@@ -39,17 +37,12 @@ def index(provider=None, filename=None):
if url_name.startswith("/static") or url_name.startswith("static"): if url_name.startswith("/static") or url_name.startswith("static"):
return send_from_directory(APP.static_folder, filename) return send_from_directory(APP.static_folder, filename)
if url_name in BASE_URLS:
stripped_url = url_name.replace("/", "")
create_json(stripped_url)
return render_template("{}/index.html".format(stripped_url))
if url_name in OTHER_URLS: if url_name in OTHER_URLS:
stripped_base_url = url_name.split("/")[0] create_json(filename)
stripped_url = url_name.split("/")[1] return render_template("{}/{}".format(provider, filename))
create_json(stripped_url)
print("{}/{}".format(stripped_base_url, stripped_url)) if url_name in BASE_URLS:
return render_template("{}/{}".format(stripped_base_url, stripped_url)) return redirect("{}{}/index.html".format(host_name, provider), code=302)
return "Oh no! NOT Found", 404 return "Oh no! NOT Found", 404
......
...@@ -24,9 +24,9 @@ ...@@ -24,9 +24,9 @@
<table class="table" id="patching"> <table class="table" id="patching">
<thead> <thead>
<tr> <tr>
<th><a href="<%= $provider %>/index.html">Certificate name</a></th> <th><a href="index.html">Certificate name</a></th>
<th>Domains (SANs)</th> <th>Domains (SANs)</th>
<th><a href="<%= $provider %>/expiry_date.html">Expiry Date</a></th> <th><a href="expiry_date.html">Expiry Date</a></th>
<th>Serial Number</th> <th>Serial Number</th>
<th>&nbsp;</th> <th>&nbsp;</th>
</tr> </tr>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment