#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
shopt -s inherit_errexit
shopt -s shift_verbose
export LC_ALL=C

# shellcheck source=../../../../kicksecure/helper-scripts/usr/libexec/helper-scripts/get_colors.sh
source "${HELPER_SCRIPTS_PATH:-}"/usr/libexec/helper-scripts/get_colors.sh

if [ -f /usr/share/anon-gw-base-files/gateway ]; then

   printf '%s\n' "\
${bold}Documentation can be found on Whonix homepage.
https://www.whonix.org

Whonix is based on Debian, VirtualBox and Tor.

The following commands are available on Whonix-Gateway...${reset}

${under}Terminal status monitor for Tor
(Vidalia / arm alternative, Tor Controller as console application):${reset}
nyx

${under}Restart Network:${reset}
sudo service networking restart

${under}Restart Tor:${reset}
sudo service tor@default restart

${under}Manually set System Clock:${reset}
sudo date -s \"17 FEB 2012 24:00:00\" && sudo hwclock -w

${under}Update operating system:${reset}
sudo apt-get update
sudo apt-get dist-upgrade

${under}Check Network Time Synchronization and Tor connection:${reset}
systemcheck

${under}Switch to clearnet user. clearnet user has direct internet access:${reset}
(see DNS notes below)
sudo su clearnet

${under}Reboot:${reset}
sudo reboot

${under}Power off:${reset}
sudo poweroff

${under}Circumvent using uwt wrapper (Experts / Debugging only!):${reset}
/usr/bin/apt-get.anondist-orig
/usr/bin/wget.anondist-orig
/usr/bin/curl.anondist-orig
/usr/bin/gpg.anondist-orig
/usr/bin/ssh.anondist-orig

${under}Check if DNS resolution is functional:${reset}
- Experts only!
- This is only a summary.
- You normally do not need to manually resolve DNS on Whonix-Gateway.
- Whonix has by default a feature to hide the fact, that you are a Whonix user.
  - This will NOT hide the fact that you are a Tor user from your ISP!
    - Hiding the fact, that you are a Tor user, is available as an optional configuration.
  - Whonix-Workstations traffic goes through Tors Socks-, Dns- or TransPorts.
  - Whonix-Gateway can only send traffic through Tor as well.
    - Whonix-Gateway has no longer a Trans- or DnsPort.
    - For example, apt-get will actually call the uwt wrapper /usr/bin/apt-get.
    - The apt-get uwt wrapper will with help of uwt and torsocks force also
      Whonix-Gateways traffic through Tor.
    - Thus hiding the fact, that you are a Whonix user.
- Only as either,
  - as clearnet user or
  - after activation of transparent proxying for Whonix-Gateway
    in /etc/whonix_firewall.d/ or
  - after allowing Whonix-Gateways root sending non-Tor traffic
    in /etc/whonix_firewall.d/
- nslookup check.torproject.org

${under}Important configuration files:${reset}
nano /usr/local/etc/torrc.d/50_user.conf

${under}Important configuration folders:${reset}
/etc/whonix_firewall.d/

${under}Important logs:${reset}
https://www.whonix.org/wiki/Troubleshooting#System_Logs

${under}Connection Wizard (Enable/Disable Tor)${reset}
sudo whonixsetup

${under}Change keyboard layout:${reset}
sudo dpkg-reconfigure keyboard-configuration
sudo dpkg-reconfigure console-data

${under}Default username and password for Whonix-Gateway and Whonix-Workstation:${reset}
Default username: user
Default password: No password required. (Passwordless login.)

${under}For slower output, run:${reset}
whonix | more

${bold}End of Whonix help.${reset}
"

elif [ -f /usr/share/anon-ws-base-files/workstation ]; then

   printf '%s\n' "\
${bold}Documentation can be found on Whonix homepage.
https://www.whonix.org

Whonix is based on Debian, VirtualBox and Tor.

The following commands are available on Whonix-Workstation...${reset}

${under}Restart Network:${reset}
sudo service networking restart

${under}Manually set System Clock:${reset}
sudo date -s \"17 FEB 2012 24:00:00\" && sudo hwclock -w

${under}Update operating system:${reset}
sudo apt-get update
sudo apt-get dist-upgrade

${under}Check Network Time Synchronization, Tor connection, Operating system updates, Whonix Version, Whonix News:${reset}
systemcheck

${under}Reboot:${reset}
sudo reboot

${under}Power off:${reset}
sudo poweroff

${under}Circumvent using uwt wrapper (Experts / Debugging only!):${reset}
/usr/bin/apt-get.anondist-orig
/usr/bin/wget.anondist-orig
/usr/bin/curl.anondist-orig
/usr/bin/gpg.anondist-orig
/usr/bin/git.anondist-orig
/usr/bin/ssh.anondist-orig

${under}Check if DNS resolution is functional:${reset}
nslookup check.torproject.org

${under}Important configuration folders:${reset}
/etc/whonix_firewall.d/

${under}Important logs:${reset}
https://www.whonix.org/wiki/Troubleshooting#System_Logs

${under}Change keyboard layout:${reset}
sudo dpkg-reconfigure keyboard-configuration
sudo dpkg-reconfigure console-data

${under}Try to produce a leak (see Whonix documentation):${reset}
leaktest

${under}Reset xchat identity:${reset}
xchat-reset

${under}Tor Browser Launcher:${reset}
torbrowser

${under}Tor Browser Updater:${reset}
update-torbrowser

${under}Default username and password for Whonix-Gateway and Whonix-Workstation:${reset}
Default username: user
Default password: No password required. (Passwordless login.)

${under}For slower output, run:${reset}
whonix | more

${under}user-sysmaint-split${reset}
Whonix uses user-sysmaint-split by default. You will not be able to run
commands with sudo while booted into 'PERSISTENT Mode - USER Session' or 'LIVE
Mode - USER Session'. To run commands as root, reboot into 'PERSISTENT Mode -
SYSMAINT Session'.

${bold}End of Whonix help.${reset}
"

fi
