You've already forked Mailu
mirror of
https://github.com/Mailu/Mailu.git
synced 2025-06-29 00:41:33 +02:00
Check IPv4 and subnet server side, flash message if these are invalid.
This commit is contained in:
@ -10,11 +10,13 @@ import random
|
|||||||
import ipaddress
|
import ipaddress
|
||||||
import hashlib
|
import hashlib
|
||||||
import time
|
import time
|
||||||
|
import secrets
|
||||||
from flask_bootstrap import StaticCDN
|
from flask_bootstrap import StaticCDN
|
||||||
|
|
||||||
version = os.getenv("this_version", "master")
|
version = os.getenv("this_version", "master")
|
||||||
static_url_path = "/" + version + "/static"
|
static_url_path = "/" + version + "/static"
|
||||||
app = flask.Flask(__name__, static_url_path=static_url_path)
|
app = flask.Flask(__name__, static_url_path=static_url_path)
|
||||||
|
app.secret_key = secrets.token_hex(16)
|
||||||
flask_bootstrap.Bootstrap(app)
|
flask_bootstrap.Bootstrap(app)
|
||||||
# Load our jQuery. Do not use jQuery 1.
|
# Load our jQuery. Do not use jQuery 1.
|
||||||
app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN()
|
app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN()
|
||||||
@ -92,12 +94,33 @@ def build_app(path):
|
|||||||
def submit():
|
def submit():
|
||||||
data = flask.request.form.copy()
|
data = flask.request.form.copy()
|
||||||
data['uid'] = str(uuid.uuid4())
|
data['uid'] = str(uuid.uuid4())
|
||||||
|
valid = True
|
||||||
|
try:
|
||||||
|
ipaddress.ip_address(data['bind4'])
|
||||||
|
except:
|
||||||
|
flask.flash('Configured IPv4 address is invalid', 'error')
|
||||||
|
valid = False
|
||||||
|
try:
|
||||||
|
ipaddress.ip_network(data['subnet'])
|
||||||
|
except:
|
||||||
|
flask.flash('Configured subnet is invalid.', 'error')
|
||||||
|
valid = False
|
||||||
try:
|
try:
|
||||||
data['dns'] = str(ipaddress.IPv4Network(data['subnet'], strict=False)[-2])
|
data['dns'] = str(ipaddress.IPv4Network(data['subnet'], strict=False)[-2])
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
return "Error while generating files: " + str(err)
|
flask.flash('Invalid configuration: ' + str(err))
|
||||||
|
valid = False
|
||||||
|
if valid:
|
||||||
db.set(data['uid'], json.dumps(data))
|
db.set(data['uid'], json.dumps(data))
|
||||||
return flask.redirect(flask.url_for('.setup', uid=data['uid']))
|
return flask.redirect(flask.url_for('.setup', uid=data['uid']))
|
||||||
|
else:
|
||||||
|
return flask.render_template(
|
||||||
|
'wizard.html',
|
||||||
|
flavor="compose",
|
||||||
|
steps=sorted(os.listdir(os.path.join(path, "templates", "steps", "compose"))),
|
||||||
|
subnet6=random_ipv6_subnet()
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@prefix_bp.route("/setup/<uid>", methods=["GET"])
|
@prefix_bp.route("/setup/<uid>", methods=["GET"])
|
||||||
@root_bp.route("/setup/<uid>", methods=["GET"])
|
@root_bp.route("/setup/<uid>", methods=["GET"])
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
{% extends "bootstrap/base.html" %}
|
{% extends "bootstrap/base.html" %}
|
||||||
{% import "macros.html" as macros %}
|
{% import "macros.html" as macros %}
|
||||||
|
{% from 'bootstrap/utils.html' import flashed_messages %}
|
||||||
|
|
||||||
{% block title %}Mailu setup{% endblock %}
|
{% block title %}Mailu setup{% endblock %}
|
||||||
|
|
||||||
@ -15,6 +16,7 @@
|
|||||||
|
|
||||||
<div id="container" class="container">
|
<div id="container" class="container">
|
||||||
<h1>Mailu configuration</h1>
|
<h1>Mailu configuration</h1>
|
||||||
|
{{ flashed_messages() }}
|
||||||
<p>
|
<p>
|
||||||
Version
|
Version
|
||||||
<select id=version_select onchange="window.location.href=this.value;" class="btn btn-primary dropdown-toggle">
|
<select id=version_select onchange="window.location.href=this.value;" class="btn btn-primary dropdown-toggle">
|
||||||
|
@ -16,12 +16,10 @@ avoid generic all-interfaces addresses like <code>0.0.0.0</code> or <code>::</co
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>IPv4 listen address</label>
|
<label>IPv4 listen address</label>
|
||||||
<!-- Validates IPv4 address -->
|
<!-- Validates IPv4 address -->
|
||||||
<input class="form-control" type="text" name="bind4" value="127.0.0.1"
|
<input class="form-control" type="text" name="bind4" value="127.0.0.1" >
|
||||||
pattern="^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$">
|
|
||||||
<label>Subnet of the docker network. This should not conflict with any networks to which your system is connected. (Internal and external!)
|
<label>Subnet of the docker network. This should not conflict with any networks to which your system is connected. (Internal and external!)
|
||||||
Fourth number is always 0. Normally the format is '*.*.*.0/24'</label>
|
Fourth number is always 0. Normally the format is '*.*.*.0/24'</label>
|
||||||
<input class="form-control" type="text" name="subnet" required pattern="^([0-9]{1,3}\.){3}[0](\/([0-9]|[1-2][0-9]|3[0-2]))$"
|
<input class="form-control" type="text" name="subnet" value="192.168.203.0/24">
|
||||||
value="192.168.203.0/24">
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check form-check-inline">
|
<div class="form-check form-check-inline">
|
||||||
|
Reference in New Issue
Block a user