Fifth menu migrated onto lib/menu.sh + lib/config.sh: menus/lockout.sh covers enable/disable, changing the password, inactivity timeout, daily lock time, and boot password. The password is SHA-256 hashed before it's ever assigned to LOCKOUT_PASSWORD (matching main.js's comparison logic) - verified by test that the stored value is the correct hash and never plaintext. Rewrote the legacy configure_password_protection's linear "ask everything, confirm save at the end" wizard as the same immediate-save pattern used by every other migrated menu: each action (change password, change timeout, toggle boot password, ...) is a complete, standalone change, consistent with Sites/Display/Timezone/Hidden PIN. LOCKOUT_ACTIVE_START/END are deliberately left untouched - per the Readme they're inert leftover fields the app ignores, so lib/config.sh just carries whatever is already in config.json through unchanged. Testing this menu surfaced a real gap before it ever shipped: lib/menu.sh never had ask_time/validate_time at all (only validate_integer/ask_integer, ask_url, etc were ported when the framework was first built) - "set a daily lock time" would have failed for every single user with "ask_time: command not found". Ported both from the legacy script. Also promoted the ON/OFF toggle-label helper (previously private to menus/display.sh as display_onoff) to a shared onoff() in lib/menu.sh, since menus/lockout.sh needed the same thing and menu files should only ever depend on lib/, never on each other. Bumped SCRIPT_VERSION to 2.2.0 with matching changelog entries in the script header and Readme, and updated "Modular Management" to list the new menu and drop Password Protection & Lockout from the "not yet migrated" list. Verified: - Full regression: re-ran the Sites, Display, Timezone/PIN scratch-config suites after every change in this round (the onoff refactor, and again after adding ask_time) - all still clean. - New scratch-config test for lockout.sh: enable (password+timeout+daily lock+boot toggle), independently recomputed the expected SHA-256 hash and confirmed it matches config.json exactly, change password, change timeout, clear daily lock, toggle boot password, disable (confirmed every field clears), and that the menu builder's options correctly differ between the enabled and disabled states. - End-to-end: ran the real install.sh as a genuine non-root, non-"kiosk" user - Lockout menu -> enable protection with a real password entered via the masked prompt -> set 20m timeout, 23:00 daily lock, boot password on -> confirmed the menu redraws with the new state -> clean exit (code 0). Checked the resulting config.json and file permissions on disk.
134 lines
4.5 KiB
Bash
134 lines
4.5 KiB
Bash
#!/bin/bash
|
|
################################################################################
|
|
# menus/display.sh - "Display & Interaction" menu.
|
|
#
|
|
# Second menu migrated off the old single-file installer, folding together
|
|
# three small settings screens that used to be separate Core Settings
|
|
# entries (Touch controls, Navigation security, Optional Features). All
|
|
# three are simple scalar/boolean fields on config.json, so this is a
|
|
# deliberately different shape from menus/sites.sh's list CRUD - a toggle
|
|
# list where each entry shows its current value and flips/edits itself,
|
|
# saving immediately (same immediate-save pattern as Sites, so behavior
|
|
# stays consistent no matter which menu you're in).
|
|
#
|
|
# Depends on: lib/menu.sh, lib/config.sh being sourced first.
|
|
################################################################################
|
|
|
|
display_status() {
|
|
echo "Touch gesture mode: $SWIPE_MODE"
|
|
echo "Link navigation: $ALLOW_NAVIGATION"
|
|
echo "Pause button: $(onoff "$ENABLE_PAUSE_BUTTON")"
|
|
echo "Keyboard button: $(onoff "$ENABLE_KEYBOARD_BUTTON")"
|
|
echo "Navigation button: $(onoff "$ENABLE_NAV_BUTTON")"
|
|
}
|
|
|
|
display_menu_builder() {
|
|
MENU_LABELS=(
|
|
"Touch gesture mode (currently: $SWIPE_MODE)"
|
|
"Link navigation security (currently: $ALLOW_NAVIGATION)"
|
|
"Toggle pause button (currently: $(onoff "$ENABLE_PAUSE_BUTTON"))"
|
|
"Toggle on-screen keyboard button (currently: $(onoff "$ENABLE_KEYBOARD_BUTTON"))"
|
|
"Toggle navigation/help button (currently: $(onoff "$ENABLE_NAV_BUTTON"))"
|
|
)
|
|
MENU_HANDLERS=(
|
|
action_set_touch_mode
|
|
action_set_navigation_security
|
|
action_toggle_pause_button
|
|
action_toggle_keyboard_button
|
|
action_toggle_nav_button
|
|
)
|
|
}
|
|
|
|
display_menu() {
|
|
load_existing_config
|
|
run_menu "DISPLAY & INTERACTION" display_menu_builder display_status
|
|
}
|
|
|
|
################################################################################
|
|
# Touch gesture mode
|
|
################################################################################
|
|
|
|
action_set_touch_mode() {
|
|
echo
|
|
echo "DUAL-DIRECTION (recommended for touchscreens):"
|
|
echo " 2-finger swipe = switch pages, 1-finger swipe = navigate within page"
|
|
echo "STANDARD (simpler):"
|
|
echo " 2-finger swipe = switch pages only, 1-finger swipes do nothing"
|
|
echo
|
|
|
|
local default
|
|
[[ "$SWIPE_MODE" == "dual" ]] && default="y" || default="n"
|
|
|
|
if ask_yes_no "Use dual-direction mode?" "$default"; then
|
|
SWIPE_MODE="dual"
|
|
else
|
|
SWIPE_MODE="standard"
|
|
fi
|
|
|
|
log_success "Touch mode: $SWIPE_MODE"
|
|
save_config
|
|
}
|
|
|
|
################################################################################
|
|
# Navigation security
|
|
################################################################################
|
|
|
|
action_set_navigation_security() {
|
|
echo
|
|
echo " r) restricted - only the loaded URL, no link clicking"
|
|
echo " s) same-origin - can click links within the same domain (recommended)"
|
|
echo " o) open - can click any link, browse anywhere"
|
|
echo
|
|
|
|
local choice
|
|
read -r -p "(r)estricted / (s)ame-origin / (o)pen [${ALLOW_NAVIGATION}]: " choice
|
|
|
|
case "${choice,,}" in
|
|
r) ALLOW_NAVIGATION="restricted" ;;
|
|
o) ALLOW_NAVIGATION="open" ;;
|
|
s) ALLOW_NAVIGATION="same-origin" ;;
|
|
"") ;; # keep current value
|
|
*) log_warning "Unrecognized choice, keeping '$ALLOW_NAVIGATION'" ;;
|
|
esac
|
|
|
|
log_success "Link navigation: $ALLOW_NAVIGATION"
|
|
save_config
|
|
}
|
|
|
|
################################################################################
|
|
# On-screen button toggles
|
|
################################################################################
|
|
|
|
action_toggle_pause_button() {
|
|
if [[ "$ENABLE_PAUSE_BUTTON" == "true" ]]; then
|
|
ENABLE_PAUSE_BUTTON="false"
|
|
log_warning "Pause button disabled"
|
|
else
|
|
ENABLE_PAUSE_BUTTON="true"
|
|
log_success "Pause button enabled"
|
|
fi
|
|
save_config
|
|
}
|
|
|
|
action_toggle_keyboard_button() {
|
|
if [[ "$ENABLE_KEYBOARD_BUTTON" == "true" ]]; then
|
|
ENABLE_KEYBOARD_BUTTON="false"
|
|
log_warning "On-screen keyboard button disabled"
|
|
else
|
|
ENABLE_KEYBOARD_BUTTON="true"
|
|
log_success "On-screen keyboard button enabled"
|
|
fi
|
|
save_config
|
|
}
|
|
|
|
action_toggle_nav_button() {
|
|
if [[ "$ENABLE_NAV_BUTTON" == "true" ]]; then
|
|
ENABLE_NAV_BUTTON="false"
|
|
log_warning "Navigation/help button disabled"
|
|
else
|
|
ENABLE_NAV_BUTTON="true"
|
|
log_success "Navigation/help button enabled"
|
|
fi
|
|
save_config
|
|
}
|