Add wifi sharing as a card, new settings for lan url, root and ssh

This commit is contained in:
Ana Custura 2026-02-19 16:42:57 +00:00
parent 947b4ac59a
commit ed1b03a609
52 changed files with 9067 additions and 94 deletions

View file

@ -33,13 +33,13 @@ def get_file_suffix(path: str) -> str:
def get_file_icon_url(path: str) -> str:
if os.path.isdir(path):
return url_for("static", filename=f"images/extension-icons/directory.svg")
suffix = get_file_suffix(path)
if suffix:
if suffix in ['apk', 'deb', 'dmg', 'exe', 'jpg', 'mp3', 'pbf', 'pdf', 'png',
'ppt', 'pptx']:
return url_for("static", filename=f"images/extension-icons/ext-{suffix}.svg")
return url_for("static", filename=f"images/extension-icons/ext-unknown.svg")
def get_last_modified(path: str) -> str:
mod_time = time.ctime(os.path.getmtime(path))
#print(mod_time)
@ -73,7 +73,7 @@ def set_setting(name: str, value: str):
def dump_settings(filename: str) -> None:
settings = db.session.execute(sa.select(Setting)).scalars().all()
settings_dict = {s.key: s.value for s in settings}
print(settings_dict)
#settings_dict.pop('admin_password')
with open(filename, "w") as f:
json.dump(settings_dict, f, indent=4)
@app.route('/')
@ -84,14 +84,17 @@ def index():
enable_map_viewer = get_setting("enable_map_viewer")
enable_file_viewer = get_setting("enable_file_viewer")
enable_deltachat = get_setting("enable_deltachat")
enable_wifi_sharing = get_setting("enable_wifi_sharing")
service_array = []
usb_inserted = False # actual test of whether USB is inserted
if os.path.exists(app.config["BUTTERBOX_USB_PATH"]):
usb_inserted = True
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 enable_wifi_sharing == 'true':
service_array.append({"name": "Share WiFi", "image": url_for("static", filename="images/share-icon.svg"), "url": url_for("share")})
if enable_deltachat == 'true':
service_array.append({"name": "Secure Messaging", "image": url_for("static", filename="images/deltachat-icon.png"), "url": url_for("messaging") })
service_array.append({"name": "Secure Messaging", "image": url_for("static", filename="images/deltachat-icon.svg"), "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 enable_app_store == 'true' and usb_has_appstore:
@ -118,10 +121,8 @@ def files(path):
render_files = []
if os.path.exists(current_path):
render_files = get_files_in_path(current_path)
if not render_files:
flash(_('Empty directory.'))
else:
flash(_('Path does not exist.'))
return redirect(url_for('files', path=""))
return render_template('usb-file-viewer.html', title='File Viewer', current_path=current_path, render_files=render_files, get_setting=get_setting)
@app.route('/serve_file/<path:filepath>')
@ -150,20 +151,21 @@ def login():
@app.route('/logout')
def logout():
logout_user()
return redirect(url_for('index'))
return redirect(url_for('admin'))
@app.route('/admin', methods=['GET', 'POST'])
@login_required
def admin():
form = SettingsForm()
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 = ['enable_access_point','enable_file_viewer', 'enable_map_viewer', 'enable_app_store', 'enable_chat', 'enable_deltachat']
populate_settings = ['butterbox_name', 'wifi_password', 'ssid', 'butterbox_hostname']
bool_settings = ['enable_access_point','enable_file_viewer', 'enable_map_viewer', 'enable_app_store', 'enable_chat', 'enable_deltachat', 'enable_wifi_sharing']
populate_settings.extend(bool_settings)
if not form.is_submitted():
for s in populate_settings:
if s in bool_settings:
getattr(form, s).data = (get_setting(s) == "true")
else:
print(s, get_setting(s))
getattr(form, s).data = get_setting(s)
non_admin_settings_changed = False
if form.validate_on_submit():
@ -172,12 +174,15 @@ def admin():
new_value = getattr(form, s).data
if s in bool_settings:
new_value = str(new_value).lower() # all settings are str fow now
if s == 'butterbox_hostname':
new_value = new_value.lower().replace(" ", "")
existing_value = get_setting(s)
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)
non_admin_settings_changed = True
if s in ['butterbox_name', 'wifi_password', 'ssid', 'enable_access_point', 'enable_chat', 'enable_delta_chat']:
if s in ['butterbox_name', 'wifi_password', 'ssid', 'enable_access_point', 'enable_chat', 'enable_delta_chat', 'butterbox_hostname',
'ssh_access_settings', 'root_account_settings']:
app.config['SETTINGS_CHANGED'] = True
new_logo = form.butterbox_logo.data
@ -192,11 +197,14 @@ def admin():
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:
set_setting('admin_password', new_admin_password)
admin_user = db.session.scalar(sa.select(User).where(User.username == 'admin'))
if not admin_user.check_password(new_admin_password):
admin_user.set_password(new_admin_password)
db.session.add(admin_user)
non_admin_settings_changed = True
else:
form.admin_password.errors.append(
_("New admin password same as old password. Not changing."))
if app.config['SETTINGS_CHANGED']:
flash(_("⚠️ Some settings won't fully take effect until the Butter Box restarts. Click 'Apply Changes' to restart."))
else:
@ -233,16 +241,10 @@ def share():
display_wifi_password = False
wifi_password = get_setting("wifi_password")
if wifi_password:
wifi_ssid = get_setting("ssid")
wifi_encryption_type = "WPA2"
img = qrcode.make(f"WIFI:T:{wifi_encryption_type};S:{wifi_ssid};P:{wifi_password};;")
img.save("app/static/images/wifi_qr_code.png")
display_wifi_password = True
else:
if os.path.exists("app/static/images/wifi_qr_code.png"):
os.remove("app/static/images/wifi_qr_code.png")
wifi_ssid = get_setting("ssid")
wifi_encryption_type = "WPA2"
img = qrcode.make(f"WIFI:T:{wifi_encryption_type};S:{wifi_ssid};P:{wifi_password};;")
img.save("app/static/images/wifi_qr_code.png")
return render_template('share.html', get_setting=get_setting, display_wifi_password=display_wifi_password)
@app.route('/about')
def about():
return render_template('about.html', get_setting=get_setting)