Add deltachat spport page
This commit is contained in:
parent
c0b4ca1021
commit
ebfd20da3f
7 changed files with 106 additions and 40 deletions
|
|
@ -10,14 +10,15 @@ def seed_defaults():
|
|||
"butterbox_logo": current_app.config["BUTTERBOX_LOGO"],
|
||||
"ssid": current_app.config["BUTTERBOX_SSID"],
|
||||
"wifi_password": current_app.config["BUTTERBOX_WIFI_PASSWORD"],
|
||||
"disable_access_point": current_app.config["DISABLE_ACCESS_POINT"],
|
||||
"enable_access_point": current_app.config["ENABLE_ACCESS_POINT"],
|
||||
"apply_changes": "false",
|
||||
"onboarding_complete": "false",
|
||||
"lock_root_password": "false",
|
||||
"disable_file_viewer": current_app.config["DISABLE_FILE_VIEWER"],
|
||||
"disable_map_viewer": current_app.config["DISABLE_MAP_VIEWER"],
|
||||
"disable_chat": current_app.config["DISABLE_CHAT"],
|
||||
"disable_app_store": current_app.config["DISABLE_APP_STORE"],
|
||||
"enable_file_viewer": current_app.config["ENABLE_FILE_VIEWER"],
|
||||
"enable_map_viewer": current_app.config["ENABLE_MAP_VIEWER"],
|
||||
"enable_chat": current_app.config["ENABLE_CHAT"],
|
||||
"enable_app_store": current_app.config["ENABLE_APP_STORE"],
|
||||
"enable_deltachat": current_app.config["ENABLE_DELTACHAT"],
|
||||
"ssh_password": "",
|
||||
"admin_password": current_app.config["ADMIN_PASSWORD"],
|
||||
}
|
||||
|
|
|
|||
11
app/forms.py
11
app/forms.py
|
|
@ -15,15 +15,16 @@ class SettingsForm(FlaskForm):
|
|||
# Access point settings
|
||||
ssid = StringField('SSID', validators=[DataRequired()])
|
||||
wifi_password = PasswordField(_l('WiFi Password'))
|
||||
disable_access_point = BooleanField(_l('Disable Access Point'))
|
||||
enable_access_point = BooleanField(_l('Enable Access Point'))
|
||||
# Customisation settings
|
||||
butterbox_name = StringField(_l('Butterbox Name'), validators=[DataRequired()])
|
||||
butterbox_logo = FileField((_l('Butterbox Logo')), validators=[FileAllowed(['jpg', 'png', 'svg'], 'Images only!')])
|
||||
# Services settings
|
||||
disable_file_viewer = BooleanField(_l('Disable File Viewer'))
|
||||
disable_map_viewer = BooleanField(_l('Disable Map Viewer'))
|
||||
disable_chat = BooleanField(_l('Disable Chat'))
|
||||
disable_app_store = BooleanField(_l('Disable App Store'))
|
||||
enable_file_viewer = BooleanField(_l('Enable File Viewer'))
|
||||
enable_map_viewer = BooleanField(_l('Enable Map Viewer'))
|
||||
enable_chat = BooleanField(_l('Enable Chat'))
|
||||
enable_app_store = BooleanField(_l('Enable App Store'))
|
||||
enable_deltachat = BooleanField(_l('Enable DeltaChat'))
|
||||
# Access Settings
|
||||
admin_password = PasswordField(_l('Admin Password'))
|
||||
ssh_password = PasswordField(_l('SSH Password'))
|
||||
|
|
|
|||
|
|
@ -13,6 +13,22 @@ from werkzeug.datastructures import FileStorage
|
|||
import json
|
||||
from flask_babel import _
|
||||
import base64
|
||||
import random
|
||||
from wordfreq import top_n_list
|
||||
import secrets
|
||||
import string
|
||||
|
||||
def gen_username():
|
||||
words = top_n_list("en", 5000)
|
||||
prefix = random.randint(1000, 9999)
|
||||
return f"{random.choice(words)}{random.choice(words)}{prefix}"
|
||||
|
||||
def gen_password():
|
||||
characters = string.ascii_letters + string.digits
|
||||
password = ''.join(secrets.choice(characters) for i in range(20))
|
||||
return password
|
||||
|
||||
|
||||
|
||||
def get_setting(name) -> str:
|
||||
setting = db.session.scalar(sa.select(Setting).where(Setting.key == name))
|
||||
|
|
@ -33,21 +49,24 @@ def dump_settings(filename: str) -> None:
|
|||
@app.route('/')
|
||||
@app.route('/index')
|
||||
def index():
|
||||
disable_chat = get_setting("disable_chat")
|
||||
disable_app_store = get_setting("disable_app_store")
|
||||
disable_map_viewer = get_setting("disable_map_viewer")
|
||||
disable_file_viewer = get_setting("disable_file_viewer")
|
||||
enable_chat = get_setting("enable_chat")
|
||||
enable_app_store = get_setting("enable_app_store")
|
||||
enable_map_viewer = get_setting("enable_map_viewer")
|
||||
enable_file_viewer = get_setting("enable_file_viewer")
|
||||
enable_deltachat = get_setting("enable_deltachat")
|
||||
service_array = []
|
||||
usb_inserted = False # actual test of whether USB is inserted
|
||||
usb_has_maps = False # actual test of whether USB has maps folder
|
||||
usb_has_appstore = False # actual test of whether USB has an appstore
|
||||
if disable_chat == 'false':
|
||||
if enable_deltachat == 'true':
|
||||
service_array.append({"name": "Secure Messaging", "image": url_for("static", filename="images/deltachat-icon.png"), "url": url_for("messaging") })
|
||||
if enable_chat == 'true':
|
||||
service_array.append({"name": "Message Board", "image": url_for("static", filename="images/chat-icon.png"), "url": app.config["CONVENE_INSTALL_PATH"] })
|
||||
if disable_app_store == 'false' and usb_has_appstore:
|
||||
if enable_app_store == 'true' and usb_has_appstore:
|
||||
service_array.append({"name": "Apps", "image": url_for("static", filename="images/appstore-icon.svg")})
|
||||
if disable_map_viewer == 'false' and usb_has_maps:
|
||||
if enable_map_viewer == 'true' and usb_has_maps:
|
||||
service_array.append({"name": "Offline Maps", "image": url_for("static", filename="images/maps-icon.png")})
|
||||
if disable_file_viewer == 'false':
|
||||
if enable_file_viewer == 'true':
|
||||
name = "Files"
|
||||
if not usb_inserted:
|
||||
name = "Insert USB to browse files"
|
||||
|
|
@ -85,9 +104,9 @@ def logout():
|
|||
@login_required
|
||||
def admin():
|
||||
form = SettingsForm()
|
||||
populate_settings = ['butterbox_name', 'wifi_password', 'disable_access_point', 'ssid', 'disable_file_viewer', 'disable_map_viewer', 'disable_app_store', 'disable_chat' ]
|
||||
populate_settings = ['butterbox_name', 'wifi_password', 'enable_access_point', 'ssid', 'enable_file_viewer', 'enable_map_viewer', 'enable_app_store', 'enable_chat', 'enable_deltachat' ]
|
||||
|
||||
bool_settings = ['disable_access_point','disable_file_viewer', 'disable_map_viewer', 'disable_app_store', 'disable_chat']
|
||||
bool_settings = ['enable_access_point','enable_file_viewer', 'enable_map_viewer', 'enable_app_store', 'enable_chat', 'enable_deltachat']
|
||||
|
||||
if not form.is_submitted():
|
||||
for s in populate_settings:
|
||||
|
|
@ -95,7 +114,7 @@ def admin():
|
|||
getattr(form, s).data = (get_setting(s) == "true")
|
||||
else:
|
||||
getattr(form, s).data = get_setting(s)
|
||||
|
||||
non_admin_settings_changed = False
|
||||
if form.validate_on_submit():
|
||||
if form.submit.data:
|
||||
for s in populate_settings:
|
||||
|
|
@ -106,7 +125,8 @@ def admin():
|
|||
if new_value != existing_value:
|
||||
print(f"New value was changed for {s}. Existing value was {existing_value}, new value was {new_value}")
|
||||
set_setting(s, new_value)
|
||||
if s in ['butterbox_name', 'wifi_password', 'ssid', 'disable_access_point']:
|
||||
non_admin_settings_changed = True
|
||||
if s in ['butterbox_name', 'wifi_password', 'ssid', 'enable_access_point', 'enable_chat', 'enable_delta_chat']:
|
||||
app.config['SETTINGS_CHANGED'] = True
|
||||
|
||||
new_logo = form.butterbox_logo.data
|
||||
|
|
@ -117,18 +137,21 @@ def admin():
|
|||
new_value = f"data:{file_mimetype};base64,{b64_logo}"
|
||||
existing_value = get_setting('butterbox_logo')
|
||||
if new_value != existing_value:
|
||||
print( f"New value was changed for logo")
|
||||
set_setting('butterbox_logo', new_value)
|
||||
non_admin_settings_changed = True
|
||||
new_admin_password = form.admin_password.data
|
||||
if new_admin_password:
|
||||
existing_admin_password = get_setting('admin_password')
|
||||
if new_admin_password != existing_admin_password:
|
||||
print( f"New value was changed for admin password")
|
||||
set_setting('admin_password', new_admin_password)
|
||||
print(get_setting('admin_password'))
|
||||
non_admin_settings_changed = True
|
||||
|
||||
if app.config['SETTINGS_CHANGED']:
|
||||
flash(_("⚠️ Some settings won't take effect until the Butter Box restarts. Click 'Apply Changes' to restart."))
|
||||
flash(_("⚠️ Some settings won't fully take effect until the Butter Box restarts. Click 'Apply Changes' to restart."))
|
||||
else:
|
||||
if non_admin_settings_changed:
|
||||
flash(
|
||||
_("Settings successfully changed."))
|
||||
db.session.commit()
|
||||
|
||||
if form.apply_changes.data:
|
||||
|
|
@ -138,3 +161,19 @@ def admin():
|
|||
|
||||
|
||||
return render_template('admin.html', get_setting=get_setting, form=form)
|
||||
|
||||
|
||||
@app.route('/messaging', methods=['GET', 'POST'])
|
||||
def messaging():
|
||||
return render_template('messaging.html', get_setting=get_setting)
|
||||
|
||||
@app.route("/deltachat_credentials", methods=["POST"])
|
||||
def generate_random_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"))
|
||||
BIN
app/static/images/deltachat-icon.png
Normal file
BIN
app/static/images/deltachat-icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 57 KiB |
|
|
@ -5,9 +5,6 @@
|
|||
{% import "bulma_wtf.html" as wtf %}
|
||||
<form action="" method="post" enctype="multipart/form-data" novalidate >
|
||||
{{ form.hidden_tag() }}
|
||||
{% if config['SETTINGS_CHANGED'] %}
|
||||
<p>{{ form.apply_changes(class="button is-warning") }}</p>
|
||||
{% endif %}
|
||||
<div class="field">
|
||||
{{ wtf.form_input_field(form.ssid) }}
|
||||
<p class="help"> This is the name of the advertised Wi-Fi network. Current SSID: {{ get_setting('ssid') }}</p>
|
||||
|
|
@ -23,23 +20,27 @@
|
|||
Current name: {{ get_setting('butterbox_name') }}, accessed at {{ get_setting('butterbox_name') }}.local.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
{{ wtf.form_bool_field(form.disable_access_point) }}
|
||||
{{ wtf.form_bool_field(form.enable_access_point) }}
|
||||
<p class="help">Whether this box will advertise a WiFi network.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
{{ wtf.form_bool_field(form.disable_map_viewer) }}
|
||||
{{ wtf.form_bool_field(form.enable_map_viewer) }}
|
||||
<p class="help">Whether map services are enabled.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
{{ wtf.form_bool_field(form.disable_chat) }}
|
||||
{{ wtf.form_bool_field(form.enable_chat) }}
|
||||
<p class="help">Whether chat services are enabled.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
{{ wtf.form_bool_field(form.disable_file_viewer) }}
|
||||
{{ wtf.form_bool_field(form.enable_deltachat) }}
|
||||
<p class="help">Whether secure messaging using DeltaChat is enabled.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
{{ wtf.form_bool_field(form.enable_file_viewer) }}
|
||||
<p class="help">Whether files services via USB are enabled.</p>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
{{ wtf.form_bool_field(form.disable_app_store) }}
|
||||
{{ wtf.form_bool_field(form.enable_app_store) }}
|
||||
<p class="help">Whether app store services are enabled.</p>
|
||||
</div>
|
||||
<div class="field">
|
||||
|
|
@ -55,7 +56,11 @@
|
|||
<p class="help">This is the logo shown in the UI. Current logo: <br>
|
||||
<img src="{{ get_setting('butterbox_logo') }}" style="height: 50px"> </p>
|
||||
</div>
|
||||
<p>{{ form.submit( class="button is-link") }}</p>
|
||||
<p> {{ form.submit( class="button is-link") }}
|
||||
{% if config['SETTINGS_CHANGED'] %}
|
||||
{{ form.apply_changes(class="button is-warning") }}
|
||||
{% endif %}
|
||||
</p>
|
||||
</form>
|
||||
|
||||
<a href="{{ url_for('logout') }}">Logout</a>
|
||||
|
|
|
|||
18
app/templates/messaging.html
Normal file
18
app/templates/messaging.html
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="block">
|
||||
<p> To use secure messaging, install Delta Chat and then return to this page to create your local offline account</p>
|
||||
</div>
|
||||
<a href="{{ url_for('static', filename='DeltaChat_2.35.0_APKPure.apk') }}"><button class="button is-link is-fullwidth block">
|
||||
<p>Step 1<br> Download and install</p>
|
||||
</button>
|
||||
</a>
|
||||
<div class="block"></div>
|
||||
<form action="{{ url_for('generate_random_deltachat_credentials') }}" method="post">
|
||||
<button type="submit" class="button is-link is-fullwidth block">
|
||||
<p>Step 2 <br> Create offline account </p>
|
||||
</button>
|
||||
</form>
|
||||
{% endblock %}
|
||||
12
config.py
12
config.py
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue