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

3
4
set -e

Tails developers's avatar
Tails developers committed
5
CMD=$(basename ${0})
6
LOCK=/var/lock/${CMD}
Tails developers's avatar
Tails developers committed
7
8

. gettext.sh
9
TEXTDOMAIN="tails"
Tails developers's avatar
Tails developers committed
10
11
export TEXTDOMAIN

12
13
14
CONF_DIR=/var/lib/unsafe-browser
COW=${CONF_DIR}/cow
CHROOT=${CONF_DIR}/chroot
15
BROWSER_NAME=unsafe-browser
16
BROWSER_USER=clearnet
17
18
19

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

21
# Import the TBB_EXT variable, and guess_best_tor_browser_locale().
22
23
. /usr/local/lib/tails-shell-library/tor-browser.sh

24
25
. /usr/local/lib/tails-shell-library/chroot-browser.sh

26
27
28
29
30
31
32
33
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

34
cleanup () {
35
    try_cleanup_browser_chroot ${CHROOT} ${COW} ${BROWSER_USER}
36
37
38
}

error () {
39
40
    local cli_text="${CMD}: `gettext \"error:\"` ${@}"
    local dialog_text="<b><big>`gettext \"Error\"`</big></b>
41

42
${@}"
43
    echo "${cli_text}" >&2
44
    sudo -u ${SUDO_USER} zenity --error --title "" --text "${dialog_text}"
45
46
47
    exit 1
}

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

Tails developers's avatar
Tails developers committed
52
`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.\"`"
53
54
55
56
57
58
    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.
    if sudo -u ${SUDO_USER} zenity --question --title "" --ok-label "${exit}" \
       --cancel-label "${launch}" --text "${dialog_msg}"; then
59
60
61
        exit 0
    fi
}
62

63
64
65
show_start_notification () {
    local title="`gettext \"Starting the Unsafe Browser...\"`"
    local body="`gettext \"This may take a while, so please be patient.\"`"
66
    tails-notify-user "${title}" "${body}" 10000
67
68
69
70
71
}

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.\"`"
72
    tails-notify-user "${title}" "${body}" 10000
73
74
}

75
76
77
78
79
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
80
        echo "* Restarting Tor"
81
82
        restart-tor
        if ! service tor status >/dev/null; then
83
84
            error "`gettext \"Failed to restart Tor.\"`"
        fi
85
86
    fi
}
87

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

94
# Get the DNS servers that was obtained from NetworkManager, if any...
95
96
97
98
99
100
101
102
NM_ENV=/var/lib/NetworkManager/env
if [ -r "${NM_ENV}" ]; then
    . ${NM_ENV}
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.
103
if [ -z "${IP4_NAMESERVERS}" ]; then
Tails developers's avatar
Tails developers committed
104
    error "`gettext \"No DNS server was obtained through DHCP or manually configured in NetworkManager.\"`"
105
106
fi

107
verify_start
108
show_start_notification
109

110
111
112
echo "* Setting up chroot"
setup_browser_chroot ${CHROOT} ${COW} || \
    error "`gettext \"Failed to setup chroot.\"`"
113

114
echo "* Configuring chroot"
115
116
117
118
119
120
121
122
configure_chroot_dns_servers "${CHROOT}" "${IP4_NAMESERVERS}"
configure_chroot_browser "${CHROOT}" "${BROWSER_NAME}" "${BROWSER_USER}" \
    "${START_PAGE}" "${CHROOT}/${TBB_EXT}"/langpack-*.xpi
BEST_LOCALE="$(guess_best_tor_browser_locale)"
set_chroot_browser_locale "${CHROOT}" "${BROWSER_USER}" "${BEST_LOCALE}"
set_chroot_browser_name ${CHROOT} "`gettext \"Unsafe Browser\"`" "${BEST_LOCALE}"
set_chroot_browser_permissions "${CHROOT}" "${BROWSER_USER}"

123
echo "* Starting Unsafe Browser"
124
run_chroot_browser ${CHROOT} ${BROWSER_USER} ${SUDO_USER}
125
show_shutdown_notification
126
maybe_restart_tor
127
128

exit 0