1
0
mirror of https://github.com/Mailu/Mailu.git synced 2025-02-09 13:23:54 +02:00

Added checks to SETUP to make sure JavaScript is enabled and that all JS files could be loaded when loading the site page.

The setup site malfunctions if this is not the case.
Regular expression for checking the Mailu storage path was invalid.
This commit is contained in:
Dimitri Huisman 2023-10-29 12:55:40 +00:00
parent 4e351e1dd4
commit 67d11c47c8
No known key found for this signature in database
8 changed files with 40 additions and 12 deletions

View File

@ -14,6 +14,10 @@ COPY main.py ./main.py
RUN echo $VERSION >> /version
#Note: This is appended so we can explicitly check if this JS file has been loaded
#by the user's internet browser when accessing the setup site.
RUN echo var jQueryMailu=\'loaded\'\; >> ./static/jquery.min.js
EXPOSE 80/tcp
HEALTHCHECK --start-period=350s CMD curl -skfLo /dev/null http://localhost/
USER mailu

View File

@ -10,12 +10,14 @@ import random
import ipaddress
import hashlib
import time
from flask_bootstrap import StaticCDN
version = os.getenv("this_version", "master")
static_url_path = "/" + version + "/static"
app = flask.Flask(__name__, static_url_path=static_url_path)
flask_bootstrap.Bootstrap(app)
# Load our jQuery. Do not use jQuery 1.
app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN()
db = redis.StrictRedis(host='redis', port=6379, db=0)

2
setup/static/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,3 +1,4 @@
var render = 'RenderLoaded';
//Store API token in variable.
var token = $("#api_token").val();

View File

@ -4,7 +4,16 @@
{% block title %}Mailu setup{% endblock %}
{% block content %}
<div class="container">
<noscript>
<style type="text/css">
.container {display:none;}
</style>
<div class="noscriptmsg">
JavaScript is not enabled. The Mailu setup site does not function without JavaScript enabled.
</div>
</noscript>
<div id="container" class="container">
<h1>Mailu configuration</h1>
<p>
Version
@ -27,4 +36,20 @@ For production scenarios we recommend to use the stable version.
</div>
<p></p>
{% endblock %}
{% block scripts %}
<script type="text/javascript" src="{{ url_for('static', filename='jquery.min.js') }}"></script>
<script type="text/javascript" src="{{ url_for('static', filename='render.js') }}"></script>
<script>
if ( typeof jQueryMailu == "undefined" || typeof jQuery == "undefined" || typeof render == "undefined"){
console.log("jQuery or render.js or bootstrap js are not defined");
document.getElementById("container").style["display"] = "none";
const message = document.createElement("p");
message.innerText = "JQuery or render.js or bootstrap could not be downloaded and initialized. JavaScript must be enabled. Do not block any scripts and do not block any site downloads.";
document.body.appendChild(message);
}
</script>
{{super()}}
{% endblock %}

View File

@ -73,9 +73,4 @@ the security implications caused by such an increase of attack surface.<p>
<i>Tika enables the functionality for searching through attachments. Tika scans documents in email attachments, process (OCR, keyword extraction) and then index them in a way they can be efficiently searched. This requires significant resources (RAM, CPU and storage).</i>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='render.js') }}"></script>
{% endcall %}

View File

@ -4,7 +4,7 @@
<div class="form-group">
<label>Mailu storage path: </label>
<!-- Validates path -->
<input class="form-control" type="text" name="root" value="/mailu" required pattern="^/[-_A-Za-z0-9]+(/[-_A-Za-z0-9]*)*">
<input class="form-control" type="text" name="root" value="/mailu" required pattern="^\/[\-_A-Za-z0-9\.]+(\/[\-_A-Za-z0-9\.]*)*">
</div>
<p>In the following sections we need to set the postmaster address. This is a combination of the <i>postmaster</i> local part and the <i>main mail domain</i>.
@ -99,8 +99,4 @@ manage your email domains, users, etc.</p>
<input class="form-control" type="text" name="api_token" id="api_token" style="display: none" value="{{ secret(32) }}">
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script type="text/javascript" src="{{ url_for('static', filename='render.js') }}"></script>
{% endcall %}

View File

@ -0,0 +1,3 @@
Setup:
Regular expression for checking the Mailu storage path was invalid.
Added checks to make sure JavaScript is enabled and that all JS files could be loaded. The setup site malfunctions if this is not the case.