#!/bin/bash # uncomment for very verbose script debugging... #set -x # Copyright (C) 2012-2017 by Debian Edu project, http://wiki.debian.org/DebianEdu # 2012-2017, Mike Gabriel # 2016, Daniel Teichmann # 2017, Benjamin Schlüter # Midori Display is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # Midori Display is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the # Free Software Foundation, Inc., # 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. # dependencies: # wmctrl # matchbox-window-manager # pulseaudio-utils # xprintidle # xdotool # xmodmap # # recommendations: # unclutter # pulseaudio # x11-xserver-utils VERSION="0.0.1" # Can be configured at "/etc/default/midori-display" DEFAULT_WWW_URI="file:///usr/share/doc/midori-display/midori-display.html" DEFAULT_RESOLUTION="" # all displays that need to be changed declare -A DISPLAYS # launch pulseaudio daemon if not already running WITH_PULSEAUDIO="yes" # hide idle mouse pointer HIDE_IDLE_POINTER="yes" # allocate "left-click" mouse button functionality to mouse buttons # 1-2-3 (left middle right) alike, i.e. esp. disable right click in # Midori sessions! POINTER_BUTTON_MAP="1 0 0 4 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" # default screensaver settings SCREENSAVER_SETTINGS="" # don't use an HTTP proxy by default HTTP_PROXY_URL="" # URI block list, if any unset URI_BLOCKLIST # log to stderr, if not set to "yes" in one of the config files... LOG_TO_SYSLOG=no # interval of browser inactivity before the session is reset automatically (in seconds) INACTIVITY_INTERVAL="300" if type -p xrandr 1>/dev/null; then currentOutput=`echo "$(xrandr)" | grep -w 'connected' | sed -r -e 's/connected.*//' | head -n 1` fi if [ -r /etc/default/midori-display ] && [ ! -d /etc/default/midori-display ]; then . /etc/default/midori-display fi if [ -r $HOME/.midori-display/config ] && [ ! -d $HOME/.midori-display/config ]; then . $HOME/.midori-display/config fi if [ "x$LOG_TO_SYSLOG" = "xyes" ]; then OUTPUT="logger -t midori-display" else OUTPUT="echo" fi workdir="$HOME/.midori-display" mkdir -p "$workdir" session_lock="$workdir/.session-lock.$$" midori_lock="$workdir/.midori-lock" midori_config_dir=`mktemp -d -p "$workdir" midori-display-profile-XXXXXX` # provide pulseaudio support in the browser session, if not # already available... if ! pacmd stat 1>/dev/null 2>/dev/null; then if [ "x$WITH_PULSEAUDIO" = "xyes" ]; then if which pulseaudio 1>/dev/null; then pulseaudio -D -n \ -L 'module-udev-detect' \ --exit-idle-time=65535 fi fi fi # launch matchbox manager if ! wmctrl -m 1>/dev/null 2>/dev/null; then if which matchbox-window-manager 1>/dev/null; then matchbox-window-manager 1>/dev/null 2>/dev/null& fi fi # use unclutter to hide idle mouse pointers if [ "x$HIDE_IDLE_POINTER" = "xyes" ]; then if which unclutter 1>/dev/null; then unclutter 1>/dev/null 2>/dev/null & fi fi # hack mouse pointer functionality to e.g. disable "right-click" in Midori session sanitized_pointer_button_map=$(echo ${POINTER_BUTTON_MAP//[^0-9\ ]/} | sed -e 's/^\s*//' -e 's/\s*$//') count_buttons_pointer_button_map=$(echo -n "${sanitized_pointer_button_map//[0-9]/}"| wc -m) if which xmodmap 1>/dev/null; then if [ -n "$POINTER_BUTTON_MAP" ] && [ "x$POINTER_BUTTON_MAP" = "x$sanitized_pointer_button_map" ] && \ [ $count_buttons_pointer_button_map -lt 32 ]; then xmodmap -e "pointer = $POINTER_BUTTON_MAP" fi # furthermore... let's deactivate the "Control" modifier key to disable most hotkeys in Midori xmodmap -e "clear Control" else $OUTPUT "WARNING: Cannot strip down mouse/pointer button functionality. Make sure 'xmodmap' is installed." fi # if FAKE_HOSTNAME is not empty, use that string for hostname THIS_HOSTNAME=$(hostname -f) if [ -n "$FAKE_HOSTNAME" ]; then THIS_HOSTNAME="$FAKE_HOSTNAME" fi if `echo ${!DISPLAYS[@]} | grep -q "$THIS_HOSTNAME"`; then $OUTPUT "INFO: $THIS_HOSTNAME has extra properties. loading them.." if echo ${DISPLAYS[$THIS_HOSTNAME]} | grep -q "www_uri="; then WWW_URI=`echo ${DISPLAYS[$THIS_HOSTNAME]} | sed -r -e 's/(^|.*\|)www_uri=([^|]*).*/\2/'` else WWW_URI="$DEFAULT_WWW_URI" fi if echo ${DISPLAYS[$THIS_HOSTNAME]} | grep -q "res="; then RESOLUTION=`echo ${DISPLAYS[$THIS_HOSTNAME]} | sed -r -e 's/(^|.*\|)res=([^|]*).*/\2/'` else RESOLUTION="$DEFAULT_RESOLUTION" fi else WWW_URI="$DEFAULT_WWW_URI" RESOLUTION="$DEFAULT_RESOLUTION" fi if ! echo "$WWW_URI" | grep -q -E "^(file://|http://|https://).*"; then $OUTPUT "ERROR: WWW_URI format not supported: $WWW_URI" $OUTPUT " Use file:///. or http(s):////.." $OUTPUT " Doing nothing." exit -1 fi # if URI_BLOCKLIST is not set, populate it and limit access to the WWW_SERVER that WWW_URI points to only. if [ ! -v URI_BLOCKLIST ]; then URI_TYPE=`echo "$WWW_URI" | sed -r -e 's@(file://|http(|s)://)[^/]+/.*@\1@'` WWW_SERVER="" if echo "$URI_TYPE" | grep -q -E "^http(|s)://([^/]+)/.*"; then WWW_SERVER=`echo "$WWW_URI" | sed -r -e 's@^http(|s)://([^/]+)/.*@\2@'` fi URI_BLOCKLIST='^((?!'$URI_TYPE'.*'$WWW_SERVER'/).).*$' fi if [ -n "$URI_BLOCKLIST" ]; then URI_BLOCKLIST="-b $URI_BLOCKLIST" fi if [ -n "${RESOLUTION}" ]; then if type -p xrandr 1>/dev/null; then xrandr -d :0 --output "$(echo $currentOutput)" --mode $RESOLUTION fi fi # Set screensaver settings if which xset 1>/dev/null; then xset s ${SCREENSAVER_SETTINGS} fi # set some proxy related env variables, if requested... if [ -n "$HTTP_PROXY_URL" ]; then export http_proxy="$HTTP_PROXY_URL" export https_proxy="$HTTP_PROXY_URL" export ftp_proxy="$HTTP_PROXY_URL" fi function cleanup { if type -p xrandr 1>/dev/null; then $OUTPUT "Info: resetting resolution" xrandr -d :0 --output "$(echo $currentOutput)" --auto fi if [ -r "$midori_lock" ]; then midori_pid=$(cat "$midori_lock" | sed -e 's/[^0-9]*//g') if [ -n "$midori_pid" ]; then kill -0 $midori_pid 2>/dev/null && kill "$midori_pid" fi fi if [ -d "$midori_config_dir" ]; then rm -R "$midori_config_dir" fi for rmfile in $midori_lock \ $session_lock \ ; do if [ -e "$rmfile" ]; then rm "$rmfile" fi done } trap "cleanup" SIGINT SIGTERM ERR EXIT function midori_loop { if [ "x$INACTIVITY_INTERVAL" != "x0" ]; then ( while [ -e "$session_lock" ]; do sleep 1 if [ `xprintidle 2>/dev/null || echo 0` -gt $(($INACTIVITY_INTERVAL*1000)) ]; then echo -n "RESTART" > $midori_lock $OUTPUT "INFO: Triggering browser restart, too much idling around..." # reset X11 idle counter by some harmless key event xdotool key Shift fi done ) & fi } function midori_session { if which midori 1>/dev/null; then while [ -e "$session_lock" ]; do $OUTPUT "INFO: Starting a new instance of the midori application." midori \ -e Fullscreen \ -e enable-plugins=false \ -e enable-page-cache=false \ -e open-new-pages-in=MIDORI_NEW_PAGE_CURRENT \ -e close-buttons-on-tabs=false \ -e show-menubar=false \ -e show-statusbar=false \ -e show-bookmarkbar=false \ -e show-panel=false \ -e show-crash-dialog=false \ -e open-tabs-in-the-background=false \ -e open-tabs-next-to-current=false \ -e open-popups-in-tabs=false \ -e enable-xss-auditor=false \ -e enable-javascript=true \ -e enable-developer-extras=false \ -e enable-html5-database=true \ -e enable-running-of-insecure-content=false \ -e enable-display-of-insecure-content=false \ -e javascript-can-access-clipboard=false \ -e print-without-dialog=true \ -c "${midori_config_dir}" \ ${URI_BLOCKLIST} \ -a "${WWW_URI}" 1>/dev/null 2>/dev/null & midori_pid=$! echo -n "$midori_pid" > "$midori_lock" while [ -r "$midori_lock" ] && [ "$(cat $midori_lock)" != "RESTART" ] && [ -e "$session_lock" ]; do sleep 1 if ! kill -0 "$midori_pid" 2>/dev/null; then if [ -e ${session_lock} ]; then rm "${session_lock}" fi if [ -d "${midori_config_dir}" ]; then rm -R "${midori_config_dir}" fi break midori_config_dir=`mktemp -d -p "$workdir" midori-display-profile-XXXXXX` fi done kill -0 "$midori_pid" 2>/dev/null && kill "$midori_pid" $OUTPUT "INFO: The midori application has terminated." done else $OUTPUT "ERROR: The midori application is not installed." fi } function create_lock { touch "$session_lock" } ### MAIN ### $OUTPUT "INFO: midori Display (version $VERSION)" $OUTPUT "INFO: HOSTNAME set to: $THIS_HOSTNAME" if [ -n "$WWW_URI" ]; then $OUTPUT "INFO: WWW_URI is configured. Using content from given URL: $WWW_URI" create_lock midori_loop else $OUTPUT "ERROR: WWW_URI hasn't been configured. Doing nothing." exit 0 fi midori_session exit 0