mirror of
https://github.com/Mailu/Mailu.git
synced 2025-01-20 03:29:50 +02:00
Check IPv4 and subnet server side, flash message if these are invalid.
This commit is contained in:
parent
e332a7de6a
commit
d1a2a4d15e
@ -10,11 +10,13 @@ import random
|
||||
import ipaddress
|
||||
import hashlib
|
||||
import time
|
||||
import secrets
|
||||
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)
|
||||
app.secret_key = secrets.token_hex(16)
|
||||
flask_bootstrap.Bootstrap(app)
|
||||
# Load our jQuery. Do not use jQuery 1.
|
||||
app.extensions['bootstrap']['cdns']['jquery'] = StaticCDN()
|
||||
@ -92,12 +94,33 @@ def build_app(path):
|
||||
def submit():
|
||||
data = flask.request.form.copy()
|
||||
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:
|
||||
data['dns'] = str(ipaddress.IPv4Network(data['subnet'], strict=False)[-2])
|
||||
except ValueError as err:
|
||||
return "Error while generating files: " + str(err)
|
||||
db.set(data['uid'], json.dumps(data))
|
||||
return flask.redirect(flask.url_for('.setup', uid=data['uid']))
|
||||
flask.flash('Invalid configuration: ' + str(err))
|
||||
valid = False
|
||||
if valid:
|
||||
db.set(data['uid'], json.dumps(data))
|
||||
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"])
|
||||
@root_bp.route("/setup/<uid>", methods=["GET"])
|
||||
|
@ -1,5 +1,6 @@
|
||||
{% extends "bootstrap/base.html" %}
|
||||
{% import "macros.html" as macros %}
|
||||
{% from 'bootstrap/utils.html' import flashed_messages %}
|
||||
|
||||
{% block title %}Mailu setup{% endblock %}
|
||||
|
||||
@ -15,6 +16,7 @@
|
||||
|
||||
<div id="container" class="container">
|
||||
<h1>Mailu configuration</h1>
|
||||
{{ flashed_messages() }}
|
||||
<p>
|
||||
Version
|
||||
<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">
|
||||
<label>IPv4 listen address</label>
|
||||
<!-- Validates IPv4 address -->
|
||||
<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]?)$">
|
||||
<input class="form-control" type="text" name="bind4" value="127.0.0.1" >
|
||||
<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>
|
||||
<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]))$"
|
||||
value="192.168.203.0/24">
|
||||
<input class="form-control" type="text" name="subnet" value="192.168.203.0/24">
|
||||
</div>
|
||||
|
||||
<div class="form-check form-check-inline">
|
||||
|
Loading…
x
Reference in New Issue
Block a user