UI services modals and default CSP update (fix new tab links)

This commit is contained in:
bunkerity 2020-12-22 11:42:49 +01:00
parent 208b5acb30
commit 459bb8ea1c
No known key found for this signature in database
GPG Key ID: 654FFF51CEF7CC47
8 changed files with 66 additions and 12 deletions

View File

@ -55,7 +55,7 @@ HTTPS_PROTOCOLS="${HTTPS_PROTOCOLS-TLSv1.2 TLSv1.3}"
STRICT_TRANSPORT_SECURITY="${STRICT_TRANSPORT_SECURITY-max-age=31536000}"
USE_MODSECURITY="${USE_MODSECURITY-yes}"
USE_MODSECURITY_CRS="${USE_MODSECURITY_CRS-yes}"
CONTENT_SECURITY_POLICY="${CONTENT_SECURITY_POLICY-object-src 'none'; frame-ancestors 'self'; form-action 'self'; block-all-mixed-content; sandbox allow-forms allow-same-origin allow-scripts; base-uri 'self';}"
CONTENT_SECURITY_POLICY="${CONTENT_SECURITY_POLICY-object-src 'none'; frame-ancestors 'self'; form-action 'self'; block-all-mixed-content; sandbox allow-forms allow-same-origin allow-scripts allow-popups; base-uri 'self';}"
COOKIE_FLAGS="${COOKIE_FLAGS-* HttpOnly SameSite=Lax}"
COOKIE_AUTO_SECURE_FLAG="${COOKIE_AUTO_SECURE_FLAG-yes}"
SERVE_FILES="${SERVE_FILES-yes}"

View File

@ -33,7 +33,6 @@ def instances():
@app.route('/services')
def services():
check, services = wrappers.get_services()
print(services, flush=True)
if not check :
return render_template("error.html", title="Error", error=services)
return render_template("services.html", title="Services", services=services)

File diff suppressed because one or more lines are too long

5
ui/static/js/custom.js Normal file
View File

@ -0,0 +1,5 @@
var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'))
var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl, { container: 'body' })
})

View File

@ -1 +1,2 @@
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/custom.js"></script>

View File

@ -9,25 +9,69 @@
<div class="card border-primary mb-3" style="max-width: 80rem;">
<div class="card-header border-primary bg-primary text-white">
{{ service["SERVER_NAME"] }}
<button class="btn btn-sm ms-2 float-end btn-light"><i class="fas fa-trash-alt"></i></button>
<button class="btn btn-sm mx-2 float-end btn-light"><i class="fas fa-edit"></i></button>
<a class="btn btn-sm mx-2 float-end btn-light" href="http://{{ service["SERVER_NAME"] }}" target="_blank" ><i class="fas fa-eye"></i></a>
<button class="btn btn-sm ms-2 float-end btn-light" data-bs-toggle="modal" data-bs-target="#modal-delete-id-{{ service["SERVER_NAME"].replace(".", "-") }}"><i class="fas fa-trash-alt"></i></button>
<button class="btn btn-sm mx-2 float-end btn-light" data-bs-toggle="modal" data-bs-target="#modal-edit-id-{{ service["SERVER_NAME"].replace(".", "-") }}"><i class="fas fa-edit"></i></button>
<a class="btn btn-sm mx-2 float-end btn-light" href="http://{{ service["SERVER_NAME"] }}" target="_blank"><i class="fas fa-eye"></i></a>
</div>
<div class="card-body text-dark">
<h5 class="card-title">Summary</h5>
<span class="card-text">
<div class="row justify-content-center">
<div class="col col-6">Serve files</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["SERVE_FILES"], "yes") }}"></i></div>
<div class="col col-6">Reverse proxy</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["USE_REVERSE_PROXY"], "yes") }}"></i></div>
<div class="col col-6">Serve files</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["SERVE_FILES"], "yes") }}"></i></div>
<div class="col col-6">Remote PHP</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["REMOTE_PHP"], ".+") }}"></i></div>
<div class="col col-6">HTTPS</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["AUTO_LETS_ENCRYPT"], "yes") }}"></i></div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class([service["AUTO_LETS_ENCRYPT"], service["USE_CUSTOM_HTTPS"], service["GENERATE_SELF_SIGNED_SSL"]], ["yes", "yes", "yes"]) }}"></i></div>
<div class="col col-6">ModSecurity</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["USE_MODSECURITY"], "yes") }}"></i></div>
<div class="col col-6">Fail2Ban</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["USE_FAIL2BAN"], "yes") }}"></i></div>
<div class="col col-6">Limit req</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["USE_LIMIT_REQ"], "yes") }}"></i></div>
<div class="col col-6">DNSBL</div>
<div class="col col-6 text-center"><i class="fas fa-{{ env_to_summary_class(service["USE_DNSBL"], "yes") }}"></i></div>
</div>
</span>
</div>
</div>
</div>
<div class="modal fade" id="modal-edit-id-{{ service["SERVER_NAME"].replace(".", "-") }}" tabindex="-1" aria-labelledby="modal-edit-label-{{ service["SERVER_NAME"].replace(".", "-") }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modal-edit-label-{{ service["SERVER_NAME"].replace(".", "-") }}">View/edit {{ service["SERVER_NAME"] }} configuration</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
{{ service }}
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save</button>
</div>
</div>
</div>
</div>
<div class="modal fade" id="modal-delete-id-{{ service["SERVER_NAME"].replace(".", "-") }}" tabindex="-1" aria-labelledby="modal-delete-label-{{ service["SERVER_NAME"].replace(".", "-") }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="modal-delete-label-{{ service["SERVER_NAME"].replace(".", "-") }}">Delete {{ service["SERVER_NAME"] }} configuration</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
Are you sure you want to delete the configuration of {{ service["SERVER_NAME"] }} ?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
</div>
{% endfor %}
</div>

View File

@ -1,6 +1,6 @@
#!/usr/bin/python3
import datetime
import datetime, re
def log(event) :
print("[" + str(datetime.datetime.now().replace(microsecond=0)) + "] " + event, flush=True)
@ -13,6 +13,13 @@ def replace_in_file(file, old_str, new_str) :
f.write(data)
def env_to_summary_class(var, value) :
if var == value :
if type(var) is list and type(value) is list :
for i in range(0, len(var)) :
if re.search(value[i], var[i]) :
return "check text-success"
return "times text-danger"
if not isinstance(var, str) :
return "times text-danger"
if re.search(value, var) :
return "check text-success"
return "times text-danger"

View File

@ -32,7 +32,6 @@ def get_services() :
for root, dirs, files in os.walk("/etc/nginx") :
for file in files :
filepath = os.path.join(root, file)
print(filepath, flush=True)
if filepath.endswith("/nginx.env") :
with open(filepath, "r") as f :
service = {}