Add deltachat spport page
This commit is contained in:
parent
c0b4ca1021
commit
ebfd20da3f
7 changed files with 106 additions and 40 deletions
|
|
@ -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"))
|
||||
Loading…
Add table
Add a link
Reference in a new issue