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

3
4
set -e

5
6
# Import tor_is_working()
. /usr/local/lib/tails-shell-library/tor.sh
7

8
# Import the TBB_EXT variable, and guess_best_tor_browser_locale().
9
10
. /usr/local/lib/tails-shell-library/tor-browser.sh

Tails developers's avatar
Tails developers committed
11
12
13
14
15
# Import try_cleanup_browser_chroot(), setup_browser_chroot(),
# configure_chroot_dns_servers(), configure_chroot_browser(),
# configure_chroot_browser(), set_chroot_browser_locale()
# set_chroot_browser_name(), set_chroot_browser_permissions()
# and run_chroot_browser().
16
17
. /usr/local/lib/tails-shell-library/chroot-browser.sh

18
error () {
19
20
    local cli_text="${CMD}: `gettext \"error:\"` ${@}"
    local dialog_text="<b><big>`gettext \"Error\"`</big></b>
21

22
${@}"
23
    echo "${cli_text}" >&2
24
    sudo -u "${SUDO_USER}" zenity --error --title "" --text "${dialog_text}"
25
26
27
    exit 1
}

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

Tails developers's avatar
Tails developers committed
32
`gettext \"Network activity within the Unsafe Browser is <b>not anonymous</b>. Only use the Unsafe Browser if necessary, for example if you have to login or register to activate your Internet connection.\"`"
33
34
35
36
    local launch="`gettext \"_Launch\"`"
    local exit="`gettext \"_Exit\"`"
    # Since zenity can't set the default button to cancel, we switch the
    # labels and interpret the return value as its negation.
37
    if sudo -u "${SUDO_USER}" zenity --question --title "" --ok-label "${exit}" \
38
       --cancel-label "${launch}" --text "${dialog_msg}"; then
39
40
41
        exit 0
    fi
}
42

43
44
45
show_start_notification () {
    local title="`gettext \"Starting the Unsafe Browser...\"`"
    local body="`gettext \"This may take a while, so please be patient.\"`"
46
    tails-notify-user "${title}" "${body}" 10000
47
48
49
50
51
}

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.\"`"
52
    tails-notify-user "${title}" "${body}" 10000
53
54
}

55
56
57
58
59
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)
    if ! tor_is_working; then
60
        echo "* Restarting Tor"
61
62
        restart-tor
        if ! service tor status >/dev/null; then
63
64
            error "`gettext \"Failed to restart Tor.\"`"
        fi
65
66
    fi
}
67

68
69
# Main script:

70
71
CMD=$(basename "${0}")
LOCK="/var/lock/${CMD}"
72
73
74
75
76

. gettext.sh
TEXTDOMAIN="tails"
export TEXTDOMAIN

77
78
79
80
81
82
CONF_DIR="/var/lib/unsafe-browser"
COW="${CONF_DIR}/cow"
CHROOT="${CONF_DIR}/chroot"
BROWSER_NAME="unsafe-browser"
BROWSER_USER="clearnet"
NM_ENV_FILE="/var/lib/NetworkManager/env"
83
84
85
86
87
88
89
90
91
92
BEST_LOCALE="$(guess_best_tor_browser_locale)"

WARNING_PAGE='/usr/share/doc/tails/website/misc/unsafe_browser_warning'
LANG_CODE="$(echo ${LANG} | head -c 2)"
if [ -r "${WARNING_PAGE}.${LANG_CODE}.html" ]; then
   START_PAGE="${WARNING_PAGE}.${LANG_CODE}.html"
else
   START_PAGE="${WARNING_PAGE}.en.html"
fi

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

99
# Get the DNS servers that was obtained from NetworkManager, if any...
100
if [ -r "${NM_ENV_FILE}" ]; then
Tails developers's avatar
Tails developers committed
101
    # Import the IP4_NAMESERVERS variable.
102
    . "${NM_ENV_FILE}"
103
104
105
106
107
fi
# ... otherwise fail.
# FIXME: Or would it make sense to fallback to Google's DNS or OpenDNS?
# Some stupid captive portals may allow DNS to any host, but chances are
# that only the portal's DNS would forward to the login page.
108
if [ -z "${IP4_NAMESERVERS}" ]; then
Tails developers's avatar
Tails developers committed
109
    error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`"
110
111
fi

112
verify_start
113
show_start_notification
114

115
echo "* Setting up chroot"
116
setup_browser_chroot "${CHROOT}" "${COW}" "${BROWSER_USER}" || \
117
    error "`gettext \"Failed to setup chroot.\"`"
118

119
echo "* Configuring chroot"
120
121
configure_chroot_dns_servers "${CHROOT}" "${IP4_NAMESERVERS}"
configure_chroot_browser "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" \
122
    "${START_PAGE}" "${TBB_EXT}"/langpack-*.xpi
123
set_chroot_browser_locale "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" "${BEST_LOCALE}"
124
set_chroot_browser_name "${CHROOT}" "`gettext \"Unsafe Browser\"`" "${BEST_LOCALE}"
125
set_chroot_browser_permissions "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}"
126

127
echo "* Starting Unsafe Browser"
128
run_chroot_browser "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" "${SUDO_USER}"
129
130

echo "* Exiting the Unsafe Browser"
131
show_shutdown_notification
132
maybe_restart_tor
133
134

exit 0