diff --git a/app/forms.py b/app/forms.py index ebb878e..1de53bb 100644 --- a/app/forms.py +++ b/app/forms.py @@ -15,7 +15,7 @@ def hostname_check(form, field): def wifi_length_check(form, field): if len(field.data) > 63: raise ValidationError(_l('Wifi password cannot be longer than 63 characters.')) - if len(field.data) in range(1,9): + if len(field.data) in range(1,8): raise ValidationError(_l('Wifi password cannot be shorter than 8 characters.')) class LoginForm(FlaskForm): diff --git a/app/routes.py b/app/routes.py index 097d603..f7cdf9f 100644 --- a/app/routes.py +++ b/app/routes.py @@ -1,3 +1,6 @@ +import io +import re + from app import app from flask import render_template, flash, redirect, url_for, send_file from app.forms import LoginForm, SettingsForm, Step1Form, Step2Form, Step3Form, Step4Form @@ -25,7 +28,10 @@ RASPAP_INSTALLED = os.path.exists("/var/www/html/raspap") def gen_username() -> str: words = top_n_list("en", 5000) prefix = random.randint(1000, 9999) - return f"{random.choice(words)}{random.choice(words)}{prefix}" + word1 = re.sub(r'[^a-zA-Z ]', '', random.choice(words)) + word2 = re.sub(r'[^a-zA-Z ]', '', random.choice(words)) + print(word1, word2) + return f"{word1}{word2}{prefix}" def gen_password() -> str: characters = string.ascii_letters + string.digits @@ -346,15 +352,17 @@ def messaging(): return render_template('messaging.html', get_setting=get_setting) @app.route("/deltachat_credentials", methods=["POST"]) -def generate_random_deltachat_credentials(): +def deltachat_credentials(): ip = app.config['BUTTERBOX_DEFAULT_IP'] username = gen_username() password = gen_password() - - flash(f"Username: {username}") - flash(f"Password: {password}") - flash(f"IP: {ip}") - return redirect(url_for("messaging")) + hostname = f"{get_setting('butterbox_hostname')}.local" + dclink = f"dclogin:{username}@{hostname}/?p={password}&v=1&ih={ip}&ip=143&sh={ip}&sp=25&is=plain&ss=plain&sc=3" + img = qrcode.make(dclink) + file_object = io.BytesIO() + img.save(file_object, 'PNG') + base64img = "data:image/png;base64," + base64.b64encode(file_object.getvalue()).decode('ascii') + return render_template('deltachat_creds.html',dclink=dclink, base64img=base64img, get_setting=get_setting) @app.route('/share') def share(): diff --git a/app/templates/deltachat_creds.html b/app/templates/deltachat_creds.html new file mode 100644 index 0000000..afa9f25 --- /dev/null +++ b/app/templates/deltachat_creds.html @@ -0,0 +1,24 @@ +{% extends "base.html" %} + +{% block content %} +
{{ _('Scan the following QR code with a device where DeltaChat is installed:') }}
+{{ _('If your device does not have a camera, select "Create new profile" in DeltaChat, choose "Use Other Server" and find "Paste from clipboard", to paste the following link') }}:
{{ dclink}}
+{{ _("To use secure messaging, install Delta Chat and then return to this page to create your local offline account.")}}
+{{ _("To use secure messaging, install Delta Chat and then create your local offline account.")}}