From ee1a78aeacdbaf70681d86dd768cb56b2fdc3c89 Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Tue, 30 Jul 2019 13:18:23 +0200 Subject: [kiosk-chromium] implement SLX_BROWSER_RELOAD_SECS + space-safe arguments array for chromium-browser call + directly create bookmark template without creating a billion tempfiles... --- .../pam/hooks/session-open.d/00-chromium-policies | 19 ++- .../opt/openslx/scripts/kiosk-launch.d/00-chromium | 135 +++++++++++---------- 2 files changed, 79 insertions(+), 75 deletions(-) diff --git a/core/modules/kiosk-chromium/data/opt/openslx/pam/hooks/session-open.d/00-chromium-policies b/core/modules/kiosk-chromium/data/opt/openslx/pam/hooks/session-open.d/00-chromium-policies index 743d53ed..9f7712d2 100644 --- a/core/modules/kiosk-chromium/data/opt/openslx/pam/hooks/session-open.d/00-chromium-policies +++ b/core/modules/kiosk-chromium/data/opt/openslx/pam/hooks/session-open.d/00-chromium-policies @@ -3,28 +3,27 @@ . /opt/openslx/config -chromium_policies() { - # create managed policy file, those settings cannot be changed by the user - # (if he even gets to the settings dialog in the first place) - local chromium_policy_file="/etc/chromium-browser/policies/managed/kiosk-mode.json" - [ -e "$chromium_policy_file" ] && rm -f "$chromium_policy_file" - - mkdir -p ${chromium_policy_file%/*} - +# creates managed policy file, those settings cannot be changed by the user +# (if he even gets to the settings dialog in the first place) +create_chromium_policies() { if [ -n "$SLX_BROWSER_BOOKMARKS" ]; then bookmarkbar=true else bookmarkbar=false fi - cat <<- EOF > "$chromium_policy_file" + cat <<- EOF > "/etc/chromium-browser/policies/managed/kiosk-mode.json" { "AutoFillEnabled": false, "BackgroundModeEnabled": false, "BookmarkBarEnabled": $bookmarkbar, "DefaultBrowserSettingEnabled": true, "DownloadRestrictions": 3, + "HomepageLocation": "$SLX_BROWSER_URL", + "NewTabPageLocation": "$SLX_BROWSER_URL", "PasswordManagerEnabled": false, + "RestoreOnStartup": 4, + "RestoreOnStartupURLs": "$SLX_BROWSER_URL", "ShowAppsShortcutInBookmarkBar": false, "TranslateEnabled": false } @@ -32,6 +31,6 @@ chromium_policies() { } if [ "${PAM_SERVICE//autologin/}" != "$PAM_SERVICE" -a "$PAM_TTY" = ":0" ]; then - chromium_policies + create_chromium_policies fi true diff --git a/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium b/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium index 8221cadb..806b3e2a 100644 --- a/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium +++ b/core/modules/kiosk-chromium/data/opt/openslx/scripts/kiosk-launch.d/00-chromium @@ -3,62 +3,12 @@ . /opt/openslx/config -# swallow keyboard shortcuts of chromium -cat <<- EOF > "$HOME/.xbindkeysrc" -"true" - Control+d -"true" - Control+t -"true" - Control+s -"true" - Control+n -"true" - Control+j -"true" - Control+p -"true" - Control+h -"true" - Control+Shift+o -EOF -# xbinkeys requires a daemon, run it -xbindkeys_autostart & - -[ -n "$SLX_BROWSER_INSECURE" ] && SLX_BROWSER_INSECURE="--allow-running-insecure-content --ignore-certificate-errors" - # clear state of previous sessions [ -e "$HOME/.config/chromium" ] && rm -rf -- "$HOME/.config/chromium" mkdir -p "$HOME/.config/chromium/Default" -bookmark_template="$(mktemp)" -cat <<-EOF > "$bookmark_template" -{ - "roots": { - "bookmark_bar": { - "children": [ ], - "id": "1", - "name": "Lesezeichenleiste", - "type": "folder" - }, - "other": { - "children": [ ], - "id": "2", - "name": "Weitere Lesezeichen", - "type": "folder" - }, - "synced": { - "children": [ ], - "id": "3", - "name": "Mobile Lesezeichen", - "type": "folder" - } - }, - "version": 1 -} -EOF - -# copy the Bookmark json template and fill in our bookmarks +# Helper to json'ize bookmarks given as arguments in the form: +# , -> e.g. Google,https://www.google.com json_bookmarks() { cur=0 echo -n '[' @@ -72,20 +22,75 @@ json_bookmarks() { echo -n ']' } -# set the bookmarks in the user's home directory jq ".roots.bookmark_bar.children += $(json_bookmarks $SLX_BROWSER_BOOKMARKS)" \ - "$bookmark_template" > "$HOME/.config/chromium/Default/Bookmarks" + <(cat <<-EOF + { + "roots": { + "bookmark_bar": { + "children": [ ], + "id": "1", + "name": "Lesezeichenleiste", + "type": "folder" + }, + "other": { + "children": [ ], + "id": "2", + "name": "Weitere Lesezeichen", + "type": "folder" + }, + "synced": { + "children": [ ], + "id": "3", + "name": "Mobile Lesezeichen", + "type": "folder" + } + }, + "version": 1 + } + EOF + ) > "$HOME/.config/chromium/Default/Bookmarks" + +# default chromium arguments +chromium_args=("--noerrdialogs" "--disable-new-avatar-menu" "--disable-infobars") + +if [ -z "$SLX_BROWSER_INTERACTIVE" ]; then + # non-interactive, set to kiosk mode + chromium_args+=("--kiosk") + + # swallow keyboard shortcuts of chromium + cat <<- EOF > "$HOME/.xbindkeysrc" + "true" + Control+d + "true" + Control+t + "true" + Control+s + "true" + Control+n + "true" + Control+j + "true" + Control+p + "true" + Control+h + "true" + Control+Shift+o + EOF + # xbinkeys requires a daemon, run it + xbindkeys_autostart & + + if [ -n "$SLX_BROWSER_RELOAD_SECS" ]; then + while true; do + xdotool windowactivate "$(xdotool search --onlyvisible --class browser)" + xdotool key Alt+Home + sleep "$SLX_BROWSER_RELOAD_SECS" + done & + fi +fi -if [ -n "$SLX_BROWSER_INTERACTIVE" ]; then - SLX_KIOSK='' -else - SLX_KIOSK='--kiosk' +if [ -n "$SLX_BROWSER_INSECURE" ]; then + chromium_args+=("--allow-running-insecure-content" "--ignore-certificate-errors") fi -# finally start chromium -exec chromium-browser \ - --noerrdialogs \ - --disable-infobars \ - $SLX_KIOSK \ - $SLX_BROWSER_INSECURE \ - "$SLX_BROWSER_URL" +# finally exec to chromium +exec chromium-browser "${chromium_args[@]}" -- cgit v1.2.3-55-g7522