unsafe-browser 4.78 KB
Newer Older
1
#!/bin/sh
2

3
set -e
4
set -u
5

6 7 8 9
. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN

segfault's avatar
segfault committed
10 11
# Import tor_has_bootstrapped()
. /usr/local/lib/tails-shell-library/systemd.sh
12

13
# Import the TBB_EXT variable.
14 15
. /usr/local/lib/tails-shell-library/tor-browser.sh

Tails developers's avatar
Tails developers committed
16
# Import localized_tails_doc_page().
17 18
. /usr/local/lib/tails-shell-library/localization.sh

19
# Import setup_chroot_for_browser(), configure_chroot_browser(),
20
# and run_browser_in_chroot().
21 22
. /usr/local/lib/tails-shell-library/chroot-browser.sh

23 24 25
# Import unsafe_browser_is_enabled
. /usr/local/lib/tails-shell-library/tails-greeter.sh

26
error () {
27 28
    local cli_text="${CMD}: `gettext \"error:\"` ${@}"
    local dialog_text="<b><big>`gettext \"Error\"`</big></b>
29

30
${@}"
31
    echo "${cli_text}" >&2
32
    sudo -u "${SUDO_USER}" zenity --error --ellipsize --title "" --text "${dialog_text}"
33 34 35
    exit 1
}

36 37
verify_start () {
    # Make sure the user really wants to start the browser
38
    local dialog_msg="<b><big>`gettext \"Do you really want to launch the Unsafe Browser?\"`</big></b>
39

40
`gettext \"Network activity within the Unsafe Browser is <b>not anonymous</b>.\\nOnly use the Unsafe Browser if necessary, for example\\nif you have to login or register to activate your Internet connection.\"`"
41 42
    local launch="`gettext \"_Launch\"`"
    local exit="`gettext \"_Exit\"`"
43
    if ! sudo -u "${SUDO_USER}" \
44
         zenity --question --ellipsize --title "" --text "${dialog_msg}" --default-cancel \
45
         --ok-label "${launch}"  --cancel-label "${exit}"; then
46 47 48
        exit 0
    fi
}
49

50 51 52
show_start_notification () {
    local title="`gettext \"Starting the Unsafe Browser...\"`"
    local body="`gettext \"This may take a while, so please be patient.\"`"
53
    tails-notify-user "${title}" "${body}" 10000
54 55 56 57 58
}

show_shutdown_notification () {
    local title="`gettext \"Shutting down the Unsafe Browser...\"`"
    local body="`gettext \"This may take a while, and you may not restart the Unsafe Browser until it is properly shut down.\"`"
59
    tails-notify-user "${title}" "${body}" 10000
60 61
}

62 63 64 65
maybe_restart_tor () {
    # Restart Tor if it's not working (a captive portal may have prevented
    # Tor from bootstrapping, and a restart is the fastest way to get
    # wheels turning)
segfault's avatar
segfault committed
66
    if ! tor_has_bootstrapped; then
67
        echo "* Restarting Tor"
68
        restart-tor
69
        if ! systemctl --quiet is-active tor@default.service; then
70 71
            error "`gettext \"Failed to restart Tor.\"`"
        fi
72 73
    fi
}
74

75 76
# Main script:

77
CMD="$(basename "${0}")"
78 79 80 81 82 83
LOCK="/var/lock/${CMD}"
CONF_DIR="/var/lib/unsafe-browser"
COW="${CONF_DIR}/cow"
CHROOT="${CONF_DIR}/chroot"
BROWSER_NAME="unsafe-browser"
BROWSER_USER="clearnet"
Tails developers's avatar
Tails developers committed
84
HUMAN_READABLE_NAME="`gettext \"Unsafe Browser\"`"
85
WARNING_PAGE='/usr/share/doc/tails/website/misc/unsafe_browser_warning'
86
HOME_PAGE="$(localized_tails_doc_page "${WARNING_PAGE}")"
87

88 89
# Check if the Unsafe Browser was disabled in the startup options
if ! unsafe_browser_is_enabled; then
sajolida's avatar
sajolida committed
90 91 92 93
    error "`gettext \"The Unsafe Browser was not enabled in the Welcome Screen.\n\n\
To use the Unsafe Browser, restart Tails and enable \
the Unsafe Browser in the additional settings of the Welcome Screen.\n
To always enable the Unsafe Browser, turn on the Welcome Screen feature of the Persistent Storage."`"
94 95
fi

96
# Prevent multiple instances of the script.
97
exec 9>"${LOCK}"
98 99 100 101
if ! flock -x -n 9; then
    error "`gettext \"Another Unsafe Browser is currently running, or being cleaned up. Please retry in a while.\"`"
fi

102
verify_start
103
show_start_notification
104

105
echo "* Setting up chroot"
106
setup_chroot_for_browser "${CHROOT}" "${COW}" "${BROWSER_USER}" || \
107
    error "`gettext \"Failed to setup chroot.\"`"
108

109
echo "* Configuring chroot"
110
configure_chroot_browser "${CHROOT}" "${BROWSER_USER}" "${BROWSER_NAME}" \
111 112 113
    "${HUMAN_READABLE_NAME}" "${HOME_PAGE}" \
    "${TBB_EXT}"/langpack-*.xpi \
    /usr/share/tails/chroot-browsers/unsafe-browser/extensions/*.xpi || \
114
        error "`gettext \"Failed to configure browser.\"`"
115 116 117
# If /etc/resolv-over-clearnet.conf file is empty or doesn't exist, we
# have no clearnet DNS server.
if [ "$(stat --format=%s /etc/resolv-over-clearnet.conf || echo 0)" -gt 0 ]; then
118
    mount --bind /etc/resolv-over-clearnet.conf "${CHROOT}"/etc/resolv.conf
119 120 121
else
    error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`"
fi
122

123
echo "* Starting Unsafe Browser"
124 125 126 127
# Do not localize the 5th argument: it becomes WM_CLASS and then GNOME
# displays the localized app name found in the matching .desktop file;
# if WM_CLASS were localized then not only string encoding problems
# would happen, but GNOME would pick the wrong icon.
128
run_browser_in_chroot "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" \
129
    "${SUDO_USER}" \
130
    'Unsafe Browser' || \
131
    error "`gettext \"Failed to run browser.\"`"
132 133

echo "* Exiting the Unsafe Browser"
134
show_shutdown_notification
135
maybe_restart_tor
136 137

exit 0