freedombone/src/freedombone-controlpanel

2344 lines
76 KiB
Plaintext
Raw Normal View History

2015-10-31 21:14:23 +01:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Administrator control panel for the Freedombone system
#
# License
# =======
#
2018-01-25 18:04:25 +01:00
# Copyright (C) 2015-2018 Bob Mottram <bob@freedombone.net>
2015-10-31 21:14:23 +01:00
#
# This program is free software: you can redistribute it and/or modify
2016-02-13 23:09:27 +01:00
# it under the terms of the GNU Affero General Public License as published by
2015-10-31 21:14:23 +01:00
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
2016-02-13 23:09:27 +01:00
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
2015-10-31 21:14:23 +01:00
#
2016-02-13 23:09:27 +01:00
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2015-10-31 21:14:23 +01:00
2015-11-27 12:42:16 +01:00
PROJECT_NAME='freedombone'
2015-11-27 17:52:23 +01:00
export TEXTDOMAIN=${PROJECT_NAME}-controlpanel
2015-11-27 12:42:16 +01:00
export TEXTDOMAINDIR="/usr/share/locale"
2017-06-23 11:35:58 +02:00
if [[ $USER != 'root' ]]; then
# show the user version of the control panel
#${PROJECT_NAME}-controlpanel-user
controluser
exit 0
fi
2017-06-05 20:59:04 +02:00
function please_wait {
local str width height length
width=$(tput cols)
height=$(tput lines)
2017-06-14 22:25:25 +02:00
str=$"Please wait"
2017-06-05 20:59:04 +02:00
length=${#str}
clear
tput cup $((height / 2)) $(((width / 2) - (length / 2)))
echo "$str"
2017-06-07 21:25:44 +02:00
tput cup $((height * 3 / 5)) $(((width / 2)))
2017-06-07 21:24:33 +02:00
echo -n ''
2017-06-05 20:59:04 +02:00
}
2017-06-11 23:19:15 +02:00
please_wait
2017-06-05 20:59:04 +02:00
2017-06-23 11:35:58 +02:00
# Start including files
2017-06-22 15:37:48 +02:00
source /usr/local/bin/${PROJECT_NAME}-vars
2017-06-22 12:55:28 +02:00
2018-03-02 20:17:02 +01:00
UTILS_FILES="/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*"
2016-07-09 19:02:33 +02:00
for f in $UTILS_FILES
do
2018-03-02 20:17:02 +01:00
source "$f"
2017-06-11 21:31:52 +02:00
done
2017-06-11 23:19:15 +02:00
2018-03-02 20:17:02 +01:00
APP_FILES="/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*"
2017-06-11 21:31:52 +02:00
for f in $APP_FILES
do
2018-03-02 20:17:02 +01:00
source "$f"
2017-06-11 21:31:52 +02:00
done
2017-06-23 11:35:58 +02:00
# End including files
2018-03-02 20:17:02 +01:00
COMPLETION_FILE="$HOME/${PROJECT_NAME}-completed.txt"
2015-10-31 21:14:23 +01:00
SELECTED_USERNAME=
2015-11-03 17:06:19 +01:00
ADMIN_USER=
2015-11-27 13:31:28 +01:00
UPGRADE_SCRIPT_NAME="${PROJECT_NAME}-upgrade"
UPDATE_DATE_SCRIPT=/usr/bin/updatedate
2015-10-31 21:14:23 +01:00
2015-12-23 14:39:00 +01:00
# Minimum number of characters in a password
2018-03-02 20:17:02 +01:00
MINIMUM_PASSWORD_LENGTH=$(grep 'MINIMUM_PASSWORD_LENGTH=' "/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords" | head -n 1 | awk -F '=' '{print $2}')
2015-12-23 14:39:00 +01:00
# Mumble
MUMBLE_PORT=64738
MUMBLE_ONION_PORT=8095
2016-01-06 11:11:13 +01:00
2016-01-27 13:11:58 +01:00
SSH_PORT=2222
# outgoing SMTP proxy
SMTP_PROXY_ENABLE=$'no'
SMTP_PROXY_PROTOCOL='smtps'
SMTP_PROXY_SERVER='mail.myispdomain'
SMTP_PROXY_PORT=465
SMTP_PROXY_USERNAME=''
SMTP_PROXY_PASSWORD=''
2016-04-20 16:21:41 +02:00
WIFI_INTERFACE=wlan0
WIFI_SSID=
WIFI_TYPE='wpa2-psk'
WIFI_PASSPHRASE=
2016-04-21 13:24:20 +02:00
WIFI_HOTSPOT='no'
2018-03-02 20:17:02 +01:00
WIFI_NETWORKS_FILE="$HOME/${PROJECT_NAME}-wifi.cfg"
2016-04-20 16:21:41 +02:00
2015-12-18 15:27:51 +01:00
USB_DRIVE=sdb
# get default USB from config file
2018-03-02 20:17:02 +01:00
CONFIGURATION_FILE="$HOME/${PROJECT_NAME}.cfg"
2016-10-14 15:28:45 +02:00
read_config_param WIFI_HOTSPOT
read_config_param WIFI_INTERFACE
read_config_param WIFI_TYPE
read_config_param WIFI_SSID
read_config_param WIFI_PASSPHRASE
read_config_param SSH_PORT
read_config_param SMTP_PROXY_ENABLE
read_config_param SMTP_PROXY_PROTOCOL
read_config_param SMTP_PROXY_SERVER
read_config_param SMTP_PROXY_PORT
read_config_param SMTP_PROXY_USERNAME
read_config_param SMTP_PROXY_PASSWORD
read_config_param USB_DRIVE
2017-03-07 00:59:18 +01:00
read_config_param MY_USERNAME
read_config_param ONION_ONLY
2016-10-14 15:28:45 +02:00
if [[ $USB_DRIVE == *"dev"* ]]; then
USB_DRIVE=$(echo ${USB_DRIVE} | awk -F '/' '{print $3}' | sed 's|1||g' | sed 's|2||g')
2015-12-18 15:27:51 +01:00
fi
2015-10-31 21:14:23 +01:00
function any_key {
echo ''
read -n1 -rsp $"Press any key to continue..." key
}
function any_key_verify {
echo ''
read -n1 -rsp $"Press any key to continue or C to check a hash..." key
if [[ "$key" != 'c' && "$key" != 'C' ]]; then
return
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title $"Check tripwire hash" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Paste your tripwire hash below and it will be checked against the current database" 12 60 2>"$data"
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
GIVEN_HASH=$(<"$data")
if [ ${#GIVEN_HASH} -gt 8 ]; then
if [[ "$GIVEN_HASH" == *' '* ]]; then
dialog --title $"Check tripwire" \
2018-03-02 20:17:02 +01:00
--msgbox $"\\nThe hash should not contain any spaces" 10 40
else
2018-03-02 20:17:02 +01:00
DBHASH=$(sha512sum "/var/lib/tripwire/${HOSTNAME}.twd" | awk -F ' ' '{print $1}')
if [[ "$DBHASH" == "$GIVEN_HASH" ]]; then
dialog --title $"Check tripwire" \
2018-03-02 20:17:02 +01:00
--msgbox $"\\nSuccess\\n\\nThe hash you gave matches the current tripwire database" 10 40
else
dialog --title $"Check tripwire" \
2018-03-02 20:17:02 +01:00
--msgbox $"\\nFailed\\n\\nThe hash you gave does not match the current tripwire database. This might be because you reset the tripwire, or there could have been an unauthorised modification of the system" 12 50
fi
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2015-10-31 21:14:23 +01:00
}
2016-11-21 11:20:30 +01:00
function get_app_icann_address {
app_name="$1"
2018-03-02 20:17:02 +01:00
if grep -q "${app_name} domain" "$COMPLETION_FILE"; then
grep "${app_name} domain" "${COMPLETION_FILE}" | head -n 1 | awk -F ':' '{print $2}'
2016-11-21 11:36:09 +01:00
return
else
2018-03-02 20:17:02 +01:00
app_name_upper="$(echo "$app_name" | tr '[:lower:]' '[:upper:]')_DOMAIN_NAME"
if [ "$app_name_upper" ]; then
param_value=$(grep "${app_name_upper}=" "$CONFIGURATION_FILE" | head -n 1 | awk -F '=' '{print $2}')
if [ "${param_value}" ]; then
echo "${param_value}"
return
fi
fi
2016-11-21 11:20:30 +01:00
fi
2016-11-21 11:36:09 +01:00
echo "${DEFAULT_DOMAIN_NAME}"
2016-11-21 11:20:30 +01:00
}
2016-11-19 16:45:15 +01:00
function passwords_select_user {
SELECTED_USERNAME=
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2207
2016-11-19 16:45:15 +01:00
users_array=($(ls /home))
2017-06-29 19:09:31 +02:00
delete=(git)
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2068
2016-11-19 16:45:15 +01:00
for del in ${delete[@]}
do
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2206
2016-11-19 16:45:15 +01:00
users_array=(${users_array[@]/$del})
done
i=0
W=()
name=()
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2068
2016-11-19 16:45:15 +01:00
for u in ${users_array[@]}
do
if [[ $(is_valid_user "$u") == "1" ]]; then
i=$((i+1))
2018-03-02 20:17:02 +01:00
W+=("$i" "$u")
2016-11-19 16:45:15 +01:00
name+=("$u")
fi
done
if [ $i -eq 1 ]; then
SELECTED_USERNAME="${name[0]}"
else
user_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select User" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2181
2016-11-19 16:45:15 +01:00
if [ $? -eq 0 ]; then
SELECTED_USERNAME="${name[$((user_index-1))]}"
fi
fi
}
function passwords_show_apps {
SELECTED_APP=
2016-11-19 17:12:03 +01:00
i=0
W=()
name=()
2016-11-19 16:45:15 +01:00
for a in "${APPS_AVAILABLE[@]}"
do
2018-03-02 20:17:02 +01:00
if [[ $(function_exists "change_password_${a}") == "1" ]]; then
i=$((i+1))
2018-03-02 20:17:02 +01:00
W+=("$i" "$a")
2016-11-19 17:29:04 +01:00
name+=("$a")
fi
2016-11-19 16:45:15 +01:00
done
2017-06-27 20:51:44 +02:00
i=$((i+1))
2018-03-02 20:17:02 +01:00
W+=("$i" "mariadb")
2017-06-27 20:51:44 +02:00
name+=("mariadb")
2016-11-19 16:45:15 +01:00
selected_app_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select App" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2181
2016-11-19 16:45:15 +01:00
if [ $? -eq 0 ]; then
SELECTED_APP="${name[$((selected_app_index-1))]}"
2016-11-19 16:45:15 +01:00
fi
}
function reset_password_tries {
passwords_select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
2018-03-02 20:17:02 +01:00
pam_tally --user "$SELECTED_USERNAME" --reset
dialog --title $"Reset password tries" \
--msgbox $"Password tries have been reset for $SELECTED_USERNAME" 6 60
}
2016-11-19 16:45:15 +01:00
function view_or_change_passwords {
passwords_select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
2016-11-19 16:45:15 +01:00
return
fi
detect_installed_apps
passwords_show_apps
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_APP" ]; then
2016-11-19 16:45:15 +01:00
return
fi
2018-03-02 20:17:02 +01:00
CURR_PASSWORD=$("${PROJECT_NAME}-pass" -u "${SELECTED_USERNAME}" -a "${SELECTED_APP}")
2016-11-19 16:45:15 +01:00
2018-02-02 17:22:33 +01:00
icann_address=$(get_app_icann_address "${SELECTED_APP}")
2016-11-21 11:20:30 +01:00
onion_address=$(get_app_onion_address "${SELECTED_APP}")
titlestr=$"View or Change Password"
2016-11-21 11:20:30 +01:00
if [ ${#onion_address} -gt 0 ]; then
2018-03-02 20:17:02 +01:00
viewstr=$"${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address or $onion_address\\n\\nCopy or change it if you wish."
2016-11-21 11:20:30 +01:00
else
2018-03-02 20:17:02 +01:00
viewstr=$"${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address\\n\\nCopy or change it if you wish."
2016-11-21 11:20:30 +01:00
fi
if [ -f /root/.nostore ]; then
titlestr=$"Change Password"
if [ ${#onion_address} -gt 0 ]; then
viewstr=$"Change the ${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address or $onion_address."
else
viewstr=$"Change the ${SELECTED_APP} password for ${SELECTED_USERNAME} on $icann_address."
fi
fi
2017-06-27 20:51:44 +02:00
if [[ "${SELECTED_APP}" == 'mariadb' ]]; then
2018-03-02 20:17:02 +01:00
CURR_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
2017-06-27 20:51:44 +02:00
dialog --title $"MariaDB database password" \
2018-03-02 20:17:02 +01:00
--msgbox "\\n ${CURR_PASSWORD}" 7 40
2017-06-27 20:51:44 +02:00
return
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title "$titlestr" \
2016-11-19 16:45:15 +01:00
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox "$viewstr" 12 75 "$CURR_PASSWORD" 2>"$data"
2016-11-19 16:45:15 +01:00
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
CURR_PASSWORD=$(<"$data")
2016-11-19 16:45:15 +01:00
if [ ${#CURR_PASSWORD} -gt 8 ]; then
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-pass" -u "${SELECTED_USERNAME}" -a "${SELECTED_APP}" -p "${CURR_PASSWORD}"
"change_password_${SELECTED_APP}" "${SELECTED_USERNAME}" "${CURR_PASSWORD}"
dialog --title $"Change password" \
--msgbox $"The password was changed" 6 40
2017-05-22 15:35:40 +02:00
else
dialog --title $"Change password" \
--msgbox $"The password given must be at least 8 characters" 6 40
2016-11-19 16:45:15 +01:00
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2016-11-19 16:45:15 +01:00
}
2015-11-26 11:53:54 +01:00
function check_for_updates {
2018-03-02 20:17:02 +01:00
if [ ! -f "/etc/cron.weekly/$UPGRADE_SCRIPT_NAME" ]; then
dialog --title $"Check for updates" \
--msgbox $"Upgrade script was not found" 6 40
return
fi
clear
2018-03-02 20:17:02 +01:00
/etc/cron.weekly/$UPGRADE_SCRIPT_NAME
any_key
2015-11-26 11:53:54 +01:00
}
2015-10-31 21:14:23 +01:00
function add_user {
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Add new user" \
2018-03-02 20:17:02 +01:00
--form "\\n" 8 60 3 \
$"Username:" 1 1 "" 1 28 16 15 \
$"ssh public key (optional):" 2 1 "" 2 28 40 10000 \
2018-03-02 20:17:02 +01:00
2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
2018-03-02 20:17:02 +01:00
new_user_username=$(sed -n 1p < "$data")
new_user_ssh_public_key=$(sed -n 2p < "$data")
rm -f "$data"
if [ ${#new_user_username} -lt 2 ]; then
dialog --title $"New username" \
--msgbox $"No username was given" 6 40
return
fi
if [[ "$new_user_username" == *" "* ]]; then
dialog --title $"Invalid username" \
--msgbox $"The username should not contain any spaces" 6 40
return
fi
if [ ${#new_user_ssh_public_key} -lt 20 ]; then
clear
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-adduser" "$new_user_username"
any_key
else
if [[ "$new_user_ssh_public_key" == "ssh-"* ]]; then
clear
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-adduser" "$new_user_username" "$new_user_ssh_public_key"
any_key
else
dialog --title $"ssh public key" \
--msgbox $"This does not look like an ssh public key" 6 40
fi
fi
2015-10-31 21:14:23 +01:00
}
2016-01-03 13:24:12 +01:00
function pad_string {
echo -n -e "$1" | sed -e :a -e 's/^.\{1,25\}$/& /;ta'
2016-01-03 13:24:12 +01:00
}
2016-01-03 12:24:10 +01:00
function show_domains {
2016-10-14 15:28:45 +02:00
read_config_param "DEFAULT_DOMAIN_NAME"
echo 'Domains'
echo '======='
echo ''
echo -n -e "$(pad_string 'Name')"
echo -n -e "$(pad_string 'ICANN')"
echo -n -e "$(pad_string 'Tor')"
echo ''
echo '--------------------------------------------------------------------------'
2018-03-02 20:17:02 +01:00
if grep -q "ssh onion domain" "$COMPLETION_FILE"; then
echo -n -e "$(pad_string 'ssh')"
2018-03-02 20:17:02 +01:00
echo -n -e "$(pad_string "${DEFAULT_DOMAIN_NAME}")"
grep 'ssh onion domain' "${COMPLETION_FILE}" | awk -F ':' '{print $2}'
fi
2018-03-02 20:17:02 +01:00
if grep -q "email onion domain" "$COMPLETION_FILE"; then
echo -n -e "$(pad_string 'Email')"
2018-03-02 20:17:02 +01:00
echo -n -e "$(pad_string "${DEFAULT_DOMAIN_NAME}")"
grep 'email onion domain' "${COMPLETION_FILE}" | awk -F ':' '{print $2}'
fi
2018-03-02 20:17:02 +01:00
if grep -q "sks onion domain" "$COMPLETION_FILE"; then
read_config_param "KEYSERVER_DOMAIN_NAME"
echo -n -e "$(pad_string 'SKS')"
2018-03-02 20:17:02 +01:00
echo -n -e "$(pad_string "${KEYSERVER_DOMAIN_NAME}")"
grep 'sks onion domain' "${COMPLETION_FILE}" | awk -F ':' '{print $2}'
fi
for app_name in "${APPS_INSTALLED_NAMES[@]}"
do
2018-03-02 20:17:02 +01:00
if ! grep -q "SHOW_ON_ABOUT=1" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
continue
fi
# handle the foibles of capitalisation
2018-03-02 20:17:02 +01:00
if ! grep -q "${app_name} domain" "$COMPLETION_FILE"; then
app_name_upper=$(echo "${app_name}" | awk '{print toupper($0)}')
if grep -q "${app_name_upper} domain" "$COMPLETION_FILE"; then
app_name=${app_name_upper}
else
2018-03-02 20:17:02 +01:00
app_name_first_upper="$(tr '[:lower:]' '[:upper:]' <<< "${app_name:0:1}")${app_name:1}"
if grep -q "${app_name_first_upper} domain" "$COMPLETION_FILE"; then
app_name=${app_name_first_upper}
fi
fi
fi
2016-10-01 15:31:18 +02:00
if [ ${#app_name} -gt 0 ]; then
2016-11-21 11:20:30 +01:00
icann_address=$(get_app_icann_address "$app_name")
2018-03-02 20:17:02 +01:00
if grep -q "SHOW_ICANN_ADDRESS_ON_ABOUT=0" "/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}"; then
2017-03-10 00:33:41 +01:00
icann_address='-'
fi
2018-03-02 20:17:02 +01:00
if [[ "$ONION_ONLY" != 'no' ]]; then
if [[ "${icann_address}" != "${LOCAL_NAME}.local" ]]; then
icann_address='-'
fi
fi
2016-11-21 11:20:30 +01:00
onion_address=$(get_app_onion_address "$app_name")
2016-11-21 11:36:09 +01:00
if [ ${#onion_address} -eq 0 ]; then
onion_address="-"
fi
2016-10-01 15:31:18 +02:00
echo -n -e "$(pad_string "${app_name}")"
echo -n -e "$(pad_string "${icann_address}")"
echo "${onion_address}"
2016-10-02 22:04:43 +02:00
2018-03-02 20:17:02 +01:00
if grep -q "mobile${app_name} onion domain" "$COMPLETION_FILE"; then
2016-11-21 11:29:29 +01:00
onion_address=$(get_app_onion_address "${app_name}" "mobile")
2016-10-02 22:04:43 +02:00
echo -n -e "$(pad_string "${app_name} (mobile)")"
echo -n -e "$(pad_string "${icann_address}")"
echo "${onion_address}"
fi
2016-10-01 15:31:18 +02:00
fi
done
2018-03-02 20:17:02 +01:00
if grep -q "rss reader domain" "$COMPLETION_FILE"; then
if [ -d /var/lib/tor/hidden_service_ttrss ]; then
echo -n -e "$(pad_string 'RSS reader')"
RSSDOM='-'
echo -n -e "$(pad_string ${RSSDOM})"
echo -n "$(cat /var/lib/tor/hidden_service_ttrss/hostname)"
echo ''
fi
2018-01-29 15:50:32 +01:00
if [ -d /var/lib/tor/hidden_service_mobilerss ]; then
echo -n -e "$(pad_string 'RSS mobile')"
RSSMOBILEDOM='-'
echo -n -e "$(pad_string ${RSSMOBILEDOM})"
2018-01-29 15:50:32 +01:00
echo -n "$(cat /var/lib/tor/hidden_service_mobilerss/hostname)"
echo ''
fi
fi
echo ''
2016-01-03 12:24:10 +01:00
}
function show_users {
echo 'Users'
echo '====='
echo ''
echo -n -e "$(pad_string 'Name')"
echo -n -e "$(pad_string 'Data')"
echo ''
echo '----------------------------------'
for d in /home/*/ ; do
USRNAME=$(echo "$d" | awk -F '/' '{print $3}')
2016-10-01 11:48:07 +02:00
if [[ $(is_valid_user "$USRNAME") == "1" ]]; then
2018-03-02 20:17:02 +01:00
echo -n -e "$(pad_string "${USRNAME}")"
# size of the home directory
2018-03-02 20:17:02 +01:00
du -s -h "/home/${USRNAME}" | awk -F ' ' '{print $1}'
fi
done
echo ''
2016-01-03 12:24:10 +01:00
}
2017-03-07 00:59:18 +01:00
function show_tahoelafs {
if [ ! -f /home/tahoelafs/storage/private/storage.furl ]; then
return
fi
2017-03-07 00:59:18 +01:00
echo 'Tahoe-LAFS Storage Node'
echo '======================='
echo ''
2017-03-07 00:59:18 +01:00
echo "Hostname: $(get_tahoelafs_storage_hostname)"
echo "Public key: $(get_tahoelafs_public_key)"
echo "Nickname: $(get_tahoelafs_nick)"
echo "FURL: $(get_tahoelafs_furl)"
echo ''
2016-01-27 13:11:58 +01:00
}
function show_ip_addresses {
2016-11-23 00:28:27 +01:00
echo $'IP/DNS addresses'
echo '================'
echo ''
echo -n "IPv4: $(get_ipv4_address)/$(get_external_ipv4_address)"
ipv6_address="$(get_ipv6_address)"
if [ ${#ipv6_address} -gt 0 ]; then
echo " IPv6: ${ipv6_address}"
fi
echo ''
echo ''
}
function show_tor_bridges {
bridges_list=$(grep "Bridge " /etc/tor/torrc | grep -v '##')
if [ ${#bridges_list} -gt 0 ]; then
echo $'Tor Bridges'
echo '==========='
echo ''
echo "${bridges_list}"
echo ''
echo ''
fi
2016-12-22 14:46:31 +01:00
if ! grep -q "#BridgeRelay" /etc/tor/torrc; then
if grep -q "BridgeRelay 1" /etc/tor/torrc; then
read_config_param 'TOR_BRIDGE_PORT'
read_config_param 'TOR_BRIDGE_NICKNAME'
if [ ${#TOR_BRIDGE_NICKNAME} -gt 0 ]; then
echo "Tor bridge on this system"
echo '========================='
echo ''
echo "IP Address: $(get_ipv4_address)"
echo "Port: ${TOR_BRIDGE_PORT}"
echo "Nickname: ${TOR_BRIDGE_NICKNAME}"
echo ''
echo ''
fi
fi
fi
}
2016-11-23 00:28:27 +01:00
function show_ssh_public_key {
2016-11-23 00:58:49 +01:00
echo $'SSH Public Keys'
echo '==============='
2016-11-23 00:28:27 +01:00
echo ''
2018-03-02 20:17:02 +01:00
get_ssh_server_key
2016-11-23 00:28:27 +01:00
echo ''
echo ''
}
function show_tahoelafs_introducer {
2017-03-05 11:32:01 +01:00
INTRODUCER_FILENAME=/home/tahoelafs/data/private/introducer.furl
if [ ! -f $INTRODUCER_FILENAME ]; then
return
fi
echo $'Tahoe-LAFS introducer'
echo '====================='
echo ''
2018-03-02 20:17:02 +01:00
cat $INTRODUCER_FILENAME
echo ''
echo ''
}
2016-01-03 12:24:10 +01:00
function show_about {
2016-10-18 18:53:18 +02:00
detect_apps
get_apps_installed_names
clear
2017-06-28 12:54:24 +02:00
echo "==== ${PROJECT_NAME} version ${VERSION} ($DEBIAN_VERSION) ===="
echo ''
show_ip_addresses
show_tor_bridges
2016-11-23 00:28:27 +01:00
show_ssh_public_key
show_domains
2017-03-07 00:59:18 +01:00
show_tahoelafs
show_users
any_key
2015-11-02 17:28:18 +01:00
}
2015-10-31 21:14:23 +01:00
function select_user {
SELECTED_USERNAME=
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2207
users_array=($(ls /home))
2017-06-29 19:09:31 +02:00
delete=(git)
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2068
for del in ${delete[@]}
do
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2206
users_array=(${users_array[@]/$del})
done
i=0
W=()
name=()
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2068
for u in ${users_array[@]}
do
2016-10-17 19:17:11 +02:00
if [[ $(is_valid_user "$u") == "1" ]]; then
i=$((i+1))
2018-03-02 20:17:02 +01:00
W+=("$i" "$u")
2016-10-17 19:17:11 +02:00
name+=("$u")
fi
done
if [ $i -eq 1 ]; then
SELECTED_USERNAME="${name[0]}"
else
user_index=$(dialog --backtitle $"Freedombone Control Panel" --title $"Select User" --menu $"Select one of the following:" 24 40 17 "${W[@]}" 3>&2 2>&1 1>&3)
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
SELECTED_USERNAME="${name[$((user_index-1))]}"
fi
fi
2015-10-31 21:14:23 +01:00
}
function delete_user {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
2018-03-02 20:17:02 +01:00
if grep -Fxq "Admin user:$SELECTED_USERNAME" "$COMPLETION_FILE"; then
dialog --title $"Administrator user" \
--msgbox $"You can't delete the administrator user" 6 40
return
fi
clear
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-rmuser" "$SELECTED_USERNAME"
any_key
2015-10-31 21:14:23 +01:00
}
function configure_remote_backups {
2018-03-02 20:17:02 +01:00
if ! grep -Fxq "Admin user:$ADMIN_USER" "$COMPLETION_FILE"; then
dialog --title $"Administrator user" \
--msgbox $"No Administrator user found. Check $COMPLETION_FILE" 6 40
return
fi
if [ ${#ADMIN_USER} -lt 2 ]; then
dialog --title $"Administrator user" \
--msgbox $"Username not found" 6 40
return
fi
2018-03-02 20:17:02 +01:00
if [ ! -d "/home/$ADMIN_USER" ]; then
dialog --title $"Administrator user" \
--msgbox $"Home directory not found" 6 40
return
fi
2018-03-02 20:17:02 +01:00
if ! "${PROJECT_NAME}-remote" -u "$ADMIN_USER"; then
any_key
fi
}
2015-10-31 21:14:23 +01:00
function change_password {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
dialog --title $"Change password" \
2018-03-02 20:17:02 +01:00
--passwordbox $"New password for user $SELECTED_USERNAME" 8 40 2> "$data"
newpassword=$(<"$data")
rm -f "$data"
if [ "${#newpassword}" -lt "${MINIMUM_PASSWORD_LENGTH}" ]; then
dialog --title $"Change password" \
--msgbox $"The password should be ${MINIMUM_PASSWORD_LENGTH} or more characters" 6 40
return
fi
echo "$SELECTED_USERNAME:$newpassword"|chpasswd
dialog --title $"Change password" \
--msgbox $"Password for $SELECTED_USERNAME was changed" 6 40
2015-10-31 21:14:23 +01:00
}
2015-11-01 11:51:54 +01:00
function change_ssh_public_key {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
2018-03-02 20:17:02 +01:00
if grep -Fxq "Admin user:$SELECTED_USERNAME" "$COMPLETION_FILE"; then
dialog --title $"Change ssh public key" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nThis is the administrator user.\\n\\nAre you sure you want to change the ssh public key for the administrator?" 10 60
sel=$?
case $sel in
1) return;;
255) return;;
esac
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title $"Change ssh public key for $SELECTED_USERNAME" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Paste the ssh public key below" 8 60 2>"$data"
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
SSH_PUBLIC_KEY=$(<"$data")
if [ "$SSH_PUBLIC_KEY" ]; then
if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
if [ -f "$SSH_PUBLIC_KEY" ]; then
2018-03-02 20:17:02 +01:00
if [ ! -d "/home/$SELECTED_USERNAME/.ssh" ]; then
mkdir "/home/$SELECTED_USERNAME/.ssh"
fi
2018-03-02 20:17:02 +01:00
cp "$SSH_PUBLIC_KEY" \
"/home/$SELECTED_USERNAME/.ssh/authorized_keys"
chown -R "$SELECTED_USERNAME":"$SELECTED_USERNAME" \
"/home/$SELECTED_USERNAME/.ssh"
dialog --title $"Change ssh public key" \
--msgbox $"ssh public key was installed" 6 40
else
if [[ "$SSH_PUBLIC_KEY" == "ssh-"* ]]; then
2018-03-02 20:17:02 +01:00
if [ ! -d "/home/$SELECTED_USERNAME/.ssh" ]; then
mkdir "/home/$SELECTED_USERNAME/.ssh"
fi
echo "$SSH_PUBLIC_KEY" > \
2018-03-02 20:17:02 +01:00
"/home/$SELECTED_USERNAME/.ssh/authorized_keys"
chown -R "$SELECTED_USERNAME":"$SELECTED_USERNAME" \
"/home/$SELECTED_USERNAME/.ssh"
dialog --title $"Change ssh public key" \
--msgbox $"ssh public key was installed" 6 40
fi
fi
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2015-11-01 11:51:54 +01:00
}
function remove_user_from_mailing_list {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
2018-03-02 20:17:02 +01:00
USER_MAILING_LISTS=$(grep '\[' "/home/$SELECTED_USERNAME/.procmailrc" | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
i=0
W=()
list_name=()
while read -r listname; do
i=$((i+1))
2018-03-02 20:17:02 +01:00
W+=("$i" "$listname")
list_name+=("$listname")
2018-03-02 20:17:02 +01:00
echo "$listname"
done <<< "$USER_MAILING_LISTS"
i=$((i+1))
2018-03-02 20:17:02 +01:00
W+=("$i" $"Exit back to user mainenance")
list_selected=$(dialog --default-item "$i" --backtitle $"Freedombone Control Panel" --title $"Remove a mailing list for $SELECTED_USERNAME" --menu $"Select one of the following:" 24 50 17 "${W[@]}" 3>&2 2>&1 1>&3)
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then # Exit with OK
2018-03-02 20:17:02 +01:00
if [ "${list_selected}" -ne "${i}" ]; then
remove_list_name="${list_name[$((list_selected-1))]}"
# find the line number where the list is defined
line_number=0
i=0
while read -r line
do
2018-03-02 20:17:02 +01:00
if [[ "$line" == *"\\[${remove_list_name}\\]"* ]]; then
line_number=${i}
fi
i=$((i+1))
done < "/home/$SELECTED_USERNAME/.procmailrc"
if [ ${line_number} -eq 0 ]; then
# no match was found
return
fi
# recreate the file
2018-03-02 20:17:02 +01:00
if [ -f "/home/${SELECTED_USERNAME}/.procmailrc_new" ]; then
rm "/home/${SELECTED_USERNAME}/.procmailrc_new"
fi
i=0
clip=0
while read -r line
do
i=$((i+1))
if [ ${i} -gt $((line_number-1)) ]; then
if [ ${clip} -eq 0 ]; then
clip=1
fi
if [ ${clip} -eq 1 ]; then
if [ ${i} -lt $((line_number+2)) ]; then
continue
else
if [ ${#line} -lt 1 ]; then
clip=2
continue
fi
if [[ "$line" == ":"* || "$line" == "#"* ]]; then
clip=2
else
continue
fi
fi
fi
fi
2018-03-02 20:17:02 +01:00
echo "$line" >> "/home/${SELECTED_USERNAME}/.procmailrc_new"
2018-03-02 20:17:02 +01:00
if [[ "$line" == *"\\[${remove_list_name}\\]"* ]]; then
line_number=${i}
fi
done < "/home/$SELECTED_USERNAME/.procmailrc"
2018-03-02 20:17:02 +01:00
cp "/home/${SELECTED_USERNAME}/.procmailrc_new" "/home/${SELECTED_USERNAME}/.procmailrc"
rm "/home/${SELECTED_USERNAME}/.procmailrc_new"
chown "${SELECTED_USERNAME}":"${SELECTED_USERNAME}" "/home/${SELECTED_USERNAME}/.procmailrc"
dialog --title $"Remove user from mailing list" \
--msgbox $"${SELECTED_USERNAME} has been removed from ${remove_list_name}" 6 50
fi
fi
}
2015-10-31 21:14:23 +01:00
function add_to_mailing_list {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Subscribe $SELECTED_USERNAME to a mailing list" \
2018-03-02 20:17:02 +01:00
--form $"You can either enter a subject or an email address\\n" 11 68 4 \
$"List folder name:" 1 1 "" 1 35 26 25 \
$"Name between [] on subject line:" 2 1 "" 2 35 26 25 \
$"List email address:" 3 1 "" 3 35 26 25 \
$"Public:" 4 1 $"yes" 4 35 4 25 \
2018-03-02 20:17:02 +01:00
2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
2018-03-02 20:17:02 +01:00
LIST_NAME=$(sed -n 1p < "$data")
LIST_SUBJECT=$(sed -n 2p < "$data")
LIST_EMAIL=$(sed -n 3p < "$data")
LIST_PUBLIC=$(sed -n 4p < "$data")
if [ ${#LIST_PUBLIC} -lt 1 ]; then
LIST_PUBLIC='no'
fi
if [[ $LIST_PUBLIC == $'y' || $LIST_PUBLIC == $'Y' || $LIST_PUBLIC == $'true' || $LIST_PUBLIC == $'True' || $LIST_PUBLIC == $'yes' || $LIST_PUBLIC == $'Yes' || $LIST_PUBLIC == $'YES' ]]; then
LIST_PUBLIC='yes'
else
LIST_PUBLIC='no'
fi
if [ ${#LIST_NAME} -lt 2 ]; then
dialog --title $"Add mailing list" \
--msgbox $"No mailing list name was given" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
if [ ${#LIST_SUBJECT} -lt 2 ]; then
if [ ${#LIST_EMAIL} -lt 2 ]; then
dialog --title $"Add mailing list" \
--msgbox $"No mailing list subject or address was given" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
fi
if [ ${#LIST_SUBJECT} -gt 1 ]; then
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-addlist" -u "$SELECTED_USERNAME" -l "$LIST_NAME" \
-s "$LIST_SUBJECT" --public "$LIST_PUBLIC"
else
if [[ "$LIST_EMAIL" != *"@"* || "$LIST_EMAIL" != *"."* ]]; then
dialog --title $"Add mailing list" \
--msgbox $"Unrecognised email address" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
else
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-addlist" -u "$SELECTED_USERNAME" -l "$LIST_NAME" \
-e "$LIST_EMAIL" --public "$LIST_PUBLIC"
fi
fi
dialog --title $"Add mailing list" \
--msgbox $"$LIST_NAME list was added" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
2015-10-31 21:14:23 +01:00
}
function email_rule {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Email rule for user $SELECTED_USERNAME" \
2018-03-02 20:17:02 +01:00
--form "\\n" 9 65 4 \
$"When email arrives from address:" 1 1 "" 1 35 24 28 \
$"Move to folder:" 2 1 "" 2 35 24 28 \
$"Public:" 3 1 $"no" 3 35 4 25 \
2018-03-02 20:17:02 +01:00
2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
2018-03-02 20:17:02 +01:00
RULE_EMAIL=$(sed -n 1p < "$data")
RULE_FOLDER=$(sed -n 2p < "$data")
RULE_PUBLIC=$(sed -n 3p < "$data")
if [ ${#RULE_PUBLIC} -lt 1 ]; then
RULE_PUBLIC='no'
fi
if [[ $RULE_PUBLIC == $'y' || $RULE_PUBLIC == $'Y' || $RULE_PUBLIC == $'true' || $RULE_PUBLIC == $'True' || $RULE_PUBLIC == $'yes' || $RULE_PUBLIC == $'Yes' || $RULE_PUBLIC == $'YES' ]]; then
RULE_PUBLIC='yes'
else
RULE_PUBLIC='no'
fi
if [ ${#RULE_EMAIL} -lt 2 ]; then
dialog --title $"Add email rule" \
--msgbox $"No email address was given" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
if [ ${#RULE_FOLDER} -lt 2 ]; then
dialog --title $"Add email rule" \
--msgbox $"No folder name was given" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
dialog --title $"Add email rule" \
--msgbox $"Unrecognised email address" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-addemail" -u "$SELECTED_USERNAME" -e "$RULE_EMAIL" \
-g "$RULE_FOLDER" --public $RULE_PUBLIC
dialog --title $"Add email rule" \
--msgbox $"Email rule for $RULE_EMAIL was added" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
2015-10-31 21:14:23 +01:00
}
function block_unblock_email {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
blockstr=$"Block/Unblock email going to"
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title "$blockstr $SELECTED_USERNAME" \
2018-03-02 20:17:02 +01:00
--form "\\n" 8 65 3 \
$"When email arrives from address:" 1 1 "" 1 35 24 100 \
$"Block it:" 2 1 "yes" 2 35 4 4 \
2018-03-02 20:17:02 +01:00
2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
2018-03-02 20:17:02 +01:00
BLOCK_EMAIL=$(sed -n 1p < "$data")
BLOCK=$(sed -n 2p < "$data")
rm -f "$data"
if [ ${#BLOCK_EMAIL} -lt 2 ]; then
dialog --title $"Block/Unblock an email" \
--msgbox $"No email address was given" 6 40
return
fi
if [[ "$BLOCK_EMAIL" != *"@"* || "$BLOCK_EMAIL" != *"."* ]]; then
dialog --title $"Block/Unblock an email" \
--msgbox $"Unrecognised email address" 6 40
return
fi
if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-ignore" -u "$SELECTED_USERNAME" -e "$BLOCK_EMAIL"
dialog --title $"Block an email" \
--msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME blocked" 6 75
else
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-unignore" -u "$SELECTED_USERNAME" -e "$BLOCK_EMAIL"
dialog --title $"Unblock an email" \
--msgbox "Email from $BLOCK_EMAIL to $SELECTED_USERNAME unblocked" 6 75
fi
2015-10-31 21:14:23 +01:00
}
function block_unblock_subject {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
blockstr=$"Block/Unblock email going to"
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title "$blockstr $SELECTED_USERNAME" \
2018-03-02 20:17:02 +01:00
--form "\\n" 8 70 3 \
$"When email arrives with subject text:" 1 1 "" 1 40 24 28 \
$"Block it:" 2 1 "yes" 2 40 4 4 \
2018-03-02 20:17:02 +01:00
2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
2018-03-02 20:17:02 +01:00
BLOCK_SUBJECT=$(sed -n 1p < "$data")
BLOCK=$(sed -n 2p < "$data")
rm -f "$data"
if [ ${#BLOCK_SUBJECT} -lt 2 ]; then
dialog --title $"Block/Unblock an email" \
--msgbox $"No subject was given" 6 40
return
fi
if [[ $BLOCK == "y"* || $BLOCK == "Y"* ]]; then
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-ignore" -u "$SELECTED_USERNAME" -t "$BLOCK_SUBJECT"
dialog --title $"Block an email" \
--msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME blocked" 6 40
else
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-unignore" -u "$SELECTED_USERNAME" -t "$BLOCK_SUBJECT"
dialog --title $"Unblock an email" \
--msgbox "Email with subject $BLOCK_SUBJECT to $SELECTED_USERNAME unblocked" 6 40
fi
2015-10-31 21:14:23 +01:00
}
function create_keydrive_master {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
dialog --title $"USB Master Keydrive" \
--msgbox $"Plug in a LUKS encrypted USB drive" 6 40
clear
detect_usb_drive
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-keydrive" -u "$SELECTED_USERNAME" --master 'yes' -d "$USB_DRIVE"
any_key
2015-10-31 21:14:23 +01:00
}
function create_keydrive_fragment {
select_user
2018-03-02 23:39:47 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
dialog --title $"USB Fragment Keydrive" \
--msgbox $"Plug in a LUKS encrypted USB drive" 6 40
clear
detect_usb_drive
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-keydrive" -u "$SELECTED_USERNAME" -d "$USB_DRIVE"
any_key
2015-10-31 21:14:23 +01:00
}
function backup_data {
dialog --title $"Backup data to USB" \
--msgbox $"Plug in a LUKS encrypted USB drive" 6 40
clear
2016-10-25 11:40:49 +02:00
detect_usb_drive
echo ''
echo $"Detected USB drive $USB_DRIVE"
echo ''
echo $'Enter the passphrase for your LUKS encrypted backup drive:'
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-backup-local"
any_key
2015-10-31 21:14:23 +01:00
}
2016-10-14 15:13:14 +02:00
function restore_data_from_storage {
restore_type="$1"
2016-10-24 19:00:09 +02:00
AllStr=$"all"
ExitStr=$"Exit"
2016-10-25 11:52:45 +02:00
RestoreStr=$"Restore apps"
2016-10-24 19:00:09 +02:00
2016-10-14 15:13:14 +02:00
if [[ $restore_type != "local" ]]; then
restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;"
else
remote_domain_name="$1"
2016-10-25 11:40:49 +02:00
detect_usb_drive
2016-10-20 17:35:25 +02:00
restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE"
2016-10-25 11:52:45 +02:00
RestoreStr=$"Restore apps from USB drive $USB_DRIVE"
2016-10-14 15:13:14 +02:00
fi
utils_installed=(configfiles
2017-06-26 12:08:38 +02:00
blocklist
2016-10-14 15:13:14 +02:00
mariadb
2017-11-05 17:22:44 +01:00
postgresql
2016-10-14 15:13:14 +02:00
letsencrypt
2016-11-19 15:28:07 +01:00
passwords
2016-10-14 15:13:14 +02:00
mutt
gpg
procmail
spamassassin
readme
ssh
userconfig
userlocal
userfin
certs
2016-10-27 16:39:48 +02:00
personal
email)
2016-10-14 15:13:14 +02:00
detect_apps
2016-10-14 15:13:14 +02:00
2016-10-24 18:55:05 +02:00
while true
2016-10-14 15:13:14 +02:00
do
2016-10-24 18:55:05 +02:00
2016-10-24 19:20:17 +02:00
app_list=()
2016-10-24 18:55:05 +02:00
n=1
applist="$n $AllStr off"
2018-03-02 20:17:02 +01:00
n=$((n+1))
2016-10-24 19:20:17 +02:00
app_list+=("$AllStr")
2016-10-14 15:13:14 +02:00
2016-10-24 19:20:17 +02:00
util_index=0
2016-10-24 18:55:05 +02:00
for a in "${utils_installed[@]}"
do
applist="$applist $n $a off"
2016-10-24 19:20:17 +02:00
app_name=${utils_installed[util_index]}
2018-03-02 20:17:02 +01:00
n=$((n+1))
util_index=$((util_index+1))
2016-10-24 19:20:17 +02:00
app_list+=("$app_name")
2016-10-24 18:55:05 +02:00
done
2016-10-24 19:20:17 +02:00
app_index=0
2016-10-24 18:55:05 +02:00
for a in "${APPS_INSTALLED_NAMES[@]}"
do
applist="$applist $n $a off"
2018-03-02 20:17:02 +01:00
n=$((n+1))
2016-10-24 19:20:17 +02:00
app_name=${APPS_INSTALLED_NAMES[app_index]}
2018-03-02 20:17:02 +01:00
app_index=$((app_index+1))
2016-10-24 19:20:17 +02:00
app_list+=("$app_name")
2016-10-24 18:55:05 +02:00
done
applist="$applist $n $ExitStr on"
2018-03-02 20:17:02 +01:00
n=$((n+1))
2016-10-24 19:20:17 +02:00
app_list+=("$ExitStr")
2016-10-24 19:28:36 +02:00
choice=$(dialog --stdout --backtitle $"Freedombone" \
2016-10-25 11:52:45 +02:00
--title "$RestoreStr" \
2016-10-24 19:28:36 +02:00
--radiolist $'Choose:' \
2018-03-02 20:17:02 +01:00
30 50 20 "$applist")
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2181
2016-10-24 19:26:21 +02:00
if [ $? -ne 0 ]; then
break
fi
2018-03-02 20:17:02 +01:00
app_index=$((choice-1))
2016-10-24 19:26:21 +02:00
app_name=${app_list[app_index]}
2016-10-14 15:13:14 +02:00
2016-10-24 18:55:05 +02:00
# exit
2016-10-24 19:00:09 +02:00
if [[ "$app_name" == "$ExitStr" ]]; then
2016-10-24 18:55:05 +02:00
break
fi
2016-10-14 15:13:14 +02:00
2016-10-24 18:55:05 +02:00
clear
# Restore all
2016-10-24 19:00:09 +02:00
if [[ "$app_name" == "$AllStr" ]]; then
2016-10-24 18:55:05 +02:00
$restore_command
retcode="$?"
if [[ "$retcode" != "0" ]]; then
2017-06-25 14:07:40 +02:00
any_key
2016-10-24 18:55:05 +02:00
if [[ "$1" == "local" ]]; then
dialog --title $"Restore all apps from USB" \
--msgbox $"Restore failed with code $retcode" 6 60
else
dialog --title $"Restore all apps from $1" \
--msgbox $"Restore failed with code $retcode" 6 60
fi
break
fi
2016-10-24 10:50:12 +02:00
2016-10-14 15:13:14 +02:00
if [[ "$1" == "local" ]]; then
2016-10-24 10:47:17 +02:00
dialog --title $"Restore all apps from USB" \
2016-10-24 18:55:05 +02:00
--msgbox $"Restore complete" 6 40
2016-10-14 15:13:14 +02:00
else
2016-10-24 10:47:17 +02:00
dialog --title $"Restore all apps from $1" \
2016-10-24 18:55:05 +02:00
--msgbox $"Restore complete" 6 40
2016-10-14 15:13:14 +02:00
fi
2016-10-24 18:55:05 +02:00
break
fi
# Restore an app
$restore_command "${app_name}"
retcode="$?"
if [[ "$retcode" != "0" ]]; then
2017-06-25 14:07:40 +02:00
any_key
2016-10-24 18:55:05 +02:00
dialog --title $"Restore apps from USB" \
--msgbox $"Restore of ${app_name} failed with code $retcode" 6 60
2016-10-14 15:13:14 +02:00
return
fi
2016-10-24 10:47:17 +02:00
2016-10-24 18:55:05 +02:00
# finished
2016-10-24 10:47:17 +02:00
if [[ "$1" == "local" ]]; then
2016-10-24 18:55:05 +02:00
dialog --title $"Restore apps from USB" \
2016-10-24 10:47:17 +02:00
--msgbox $"Restore complete" 6 40
else
2016-10-24 18:55:05 +02:00
dialog --title $"Restore apps from $1" \
2016-10-24 10:47:17 +02:00
--msgbox $"Restore complete" 6 40
fi
2016-10-24 18:55:05 +02:00
done
}
2015-10-31 21:14:23 +01:00
function restore_data {
dialog --title $"Restore data from USB" \
--msgbox $"Plug in your backup USB drive" 6 40
clear
echo ' '
echo $'Enter the passphrase for your LUKS encrypted backup drive:'
2016-10-14 15:13:14 +02:00
restore_data_from_storage local
2015-10-31 21:14:23 +01:00
}
2015-10-31 22:01:24 +01:00
function restore_data_remote {
if [ ! $ADMIN_USER ]; then
dialog --title $"Restore data from remote server" \
--msgbox $"Unknown admin user" 6 40
return
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title $"Restore from remote server" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Enter the domain name of the server from which you wish to restore" 8 60 2>"$data"
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
friend_server_domain_name=$(<"$data")
if [ ${#friend_server_domain_name} -lt 2 ]; then
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
if [[ $friend_server_domain_name != *"."* ]]; then
dialog --title $"Remote server domain name" \
--msgbox $"Invalid domain name" 6 40
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
2018-03-02 20:17:02 +01:00
restore_data_from_storage "$friend_server_domain_name"
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2015-10-31 22:01:24 +01:00
}
2015-12-23 19:52:24 +01:00
function ping_enable_disable {
2018-03-02 20:17:02 +01:00
ping_str=$"\\nDo you want to enable other systems to ping this machine?\\n\\nPing may be useful for diagnostic purposes, but for added security you may not want to enable it."
enable_ping="no"
dialog --title $"Enable Ping / ICMP" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
--yesno "$ping_str" 10 60
sel=$?
case $sel in
0) enable_ping="yes";;
255) return;;
esac
if [[ $enable_ping == "yes" ]]; then
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -A OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
echo "0" > /proc/sys/net/ipv4/icmp_echo_ignore_all
else
iptables -D INPUT -p icmp --icmp-type echo-request -j ACCEPT
iptables -D OUTPUT -p icmp --icmp-type echo-reply -j ACCEPT
echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all
fi
2015-12-23 19:52:24 +01:00
}
2015-10-31 23:55:09 +01:00
function logging_on_off {
logging="no"
dialog --title $"Logging" \
--backtitle $"Freedombone Control Panel" \
2016-11-28 15:05:30 +01:00
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nDo you want to turn logging on?" 7 60
sel=$?
case $sel in
0) logging="yes";;
255) return;;
esac
clear
echo ''
echo $'This may take a few seconds. Please wait...'
if [[ $logging == "no" ]]; then
${PROJECT_NAME}-logging off
else
${PROJECT_NAME}-logging on
fi
2015-10-31 23:55:09 +01:00
}
2015-10-31 22:01:24 +01:00
function restore_gpg_key {
select_user
2018-03-02 20:17:02 +01:00
if [ ! "$SELECTED_USERNAME" ]; then
return
fi
restorestr=$"Restore GPG key for user"
dialog --title "$restorestr $SELECTED_USERNAME" \
--msgbox $"Plug in your USB keydrive" 6 40
clear
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-recoverkey" -u "$SELECTED_USERNAME"
any_key
2015-10-31 22:01:24 +01:00
}
2015-11-03 10:24:55 +01:00
function security_settings {
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-sec"
any_key
2015-11-03 10:24:55 +01:00
}
2017-08-05 14:30:58 +02:00
function show_tripwire_verification_code {
2018-03-02 20:17:02 +01:00
if [ ! -f "/var/lib/tripwire/${HOSTNAME}.twd" ]; then
return
fi
2017-08-05 21:22:45 +02:00
clear
2017-08-05 14:30:58 +02:00
echo ''
echo $'Tripwire Verification Code'
echo ''
2018-03-02 20:17:02 +01:00
DBHASH=$(sha512sum "/var/lib/tripwire/${HOSTNAME}.twd")
2017-09-03 12:02:50 +02:00
echo -n "$DBHASH" | qrencode -t UTF8
2017-08-05 14:30:58 +02:00
echo ''
echo "$DBHASH"
echo ''
}
function reset_tripwire {
if [ ! -f /usr/bin/reset-tripwire ]; then
2017-07-15 12:25:57 +02:00
echo $'Missing /usr/bin/reset-tripwire'
any_key
return
fi
2018-03-02 20:17:02 +01:00
if [ ! -f "/etc/tripwire/${HOSTNAME}-local.key" ]; then
if [ -f "/etc/tripwire/${PROJECT_NAME}-local.key" ]; then
# shellcheck disable=SC2086
mv /etc/tripwire/${PROJECT_NAME}-local.key /etc/tripwire/${HOSTNAME}-local.key
# shellcheck disable=SC2086
mv /etc/tripwire/${PROJECT_NAME}-site.key /etc/tripwire/${HOSTNAME}-site.key
2018-01-20 19:34:09 +01:00
else
echo $'Error: missing local key'
any_key
return
fi
2017-07-14 23:42:31 +02:00
fi
2017-08-05 21:22:45 +02:00
clear
2017-08-05 23:23:52 +02:00
echo $'Turing off logging...'
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-logging" off
2017-08-05 21:24:46 +02:00
echo $'Locking down permissions...'
2017-08-05 21:13:11 +02:00
lockdown_permissions
2017-08-05 12:26:24 +02:00
echo $'Creating configuration...'
echo '
2018-03-02 20:17:02 +01:00
' | twadmin --create-cfgfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twcfg.txt
2017-08-05 12:26:24 +02:00
echo $'Resetting policy...'
echo '
2018-03-02 20:17:02 +01:00
' | twadmin --create-polfile -S "/etc/tripwire/${HOSTNAME}-site.key" /etc/tripwire/twpol.txt
2017-08-05 12:26:24 +02:00
echo $'Creating tripwire database'
echo '
2018-03-02 20:17:02 +01:00
' | tripwire --init --cfgfile /etc/tripwire/tw.cfg --polfile /etc/tripwire/tw.pol --dbfile "/var/lib/tripwire/${HOSTNAME}.twd"
echo $'Resetting the Tripwire...'
2017-08-05 12:26:24 +02:00
echo ''
echo '
' | reset-tripwire
2017-08-05 12:33:13 +02:00
echo ''
# Sometimes nginx fails to restart if matrix is installed
# Restart matrix first
if [ -d /etc/matrix ]; then
systemctl restart matrix
systemctl restart nginx
fi
2018-03-02 20:17:02 +01:00
if [ -f "/var/lib/tripwire/${HOSTNAME}.twd" ]; then
2017-08-05 14:30:58 +02:00
show_tripwire_verification_code
echo $'Tripwire is now reset. Take a note of the above hash, or record'
echo $'the QR code using a mobile device. This will enable you to independently'
echo $'verify the integrity of the tripwire.'
2017-08-05 14:15:35 +02:00
else
echo $'ERROR: tripwire database was not created'
fi
2017-08-09 12:29:56 +02:00
any_key
}
function format_drive {
2016-10-25 11:40:49 +02:00
detect_usb_drive
dialog --title $"Format USB drive $USB_DRIVE" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nPlease confirm that you wish to format drive\\n\\n ${USB_DRIVE}\\n\\nAll current data on the drive will be lost, and you will be prompted to give a password used to encrypt the drive.\\n\\nDANGER: If you screw up here and format the wrong drive it's your own fault!" 16 60
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) return;;
255) return;;
esac
clear
2016-10-25 11:40:49 +02:00
echo ''
echo $"Formatting drive $USB_DRIVE. ALL CONTENTS WILL BE LOST."
echo ''
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-format" "$USB_DRIVE"
any_key
}
2015-12-09 10:58:58 +01:00
function remove_backups {
2016-10-25 11:40:49 +02:00
detect_usb_drive
2018-03-02 23:39:47 +01:00
# shellcheck disable=SC2154
2016-10-25 11:40:49 +02:00
dialog --title $"Remove backups from a USB drive $USB_DRIVE" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nPlease confirm that you wish to remove backups from this drive\\n\\n ${drive}\\n\\nYou will not be able to recover them afterwards." 12 60
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) return;;
255) return;;
esac
clear
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-backup-local" "$USB_DRIVE" remove
any_key
2015-12-09 10:58:58 +01:00
}
2015-11-21 21:01:53 +01:00
function shut_down_system {
dialog --title $"Power off the system" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nPlease confirm that you wish to power off the system.\\n\\nWARNING: to power on again you will need to have physical access to the hardware." 10 60
sel=$?
case $sel in
1) return;;
255) return;;
esac
2017-06-19 16:27:21 +02:00
systemctl poweroff
2015-11-21 21:01:53 +01:00
}
function restart_system {
dialog --title $"Restart the system" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nPlease confirm that you wish to restart the system.\\n\\nWARNING: If you are using full disk encryption then you will need physical access to the hardware to type in the password" 10 60
sel=$?
case $sel in
1) return;;
255) return;;
esac
2017-06-10 15:26:52 +02:00
systemctl reboot -i
2015-11-21 21:01:53 +01:00
}
2015-12-02 18:30:44 +01:00
function change_system_name {
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title $"Change the name of this system" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $'Enter a new name for this system on your local network\\n\\nIt will appear as newname.local' 10 60 2>"$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
0) NEW_SYSTEM_NAME=$(<"$data")
if [ "$NEW_SYSTEM_NAME" ]; then
if [ ${#NEW_SYSTEM_NAME} -gt 1 ]; then
sed -i "s|host-name=.*|host-name=$NEW_SYSTEM_NAME|g" /etc/avahi/avahi-daemon.conf
systemctl restart avahi-daemon
if grep -q "host-name=$NEW_SYSTEM_NAME" /etc/avahi/avahi-daemon.conf; then
dialog --title $"New local network name" \
--msgbox $"The name of this system on your local network was changed successfully" 6 70
fi
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2015-12-02 18:30:44 +01:00
}
function set_dynamic_IP {
revert_to_dynamic=
dialog --title $"Return to using a dynamic IP address" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--yesno $"\\nDo you wish to go back to using a dynamic IP address?" 8 60
sel=$?
case $sel in
0) revert_to_dynamic=1
;;
2016-10-22 23:16:21 +02:00
1) return;;
esac
if [ $revert_to_dynamic ]; then
2016-10-22 23:36:07 +02:00
wifi_original_network_settings
clear
echo ''
echo $'Changing to a dynamic IP address.'
echo ''
echo $"System is rebooting. You may need to close this terminal and log in from a new one."
2017-06-10 15:26:52 +02:00
systemctl reboot -i
fi
}
2015-12-07 15:30:19 +01:00
function set_static_IP {
IPv4_address=$(get_ipv4_address)
IPv4_address_base=$(echo "$IPv4_address" | awk -F '.' '{print $1"."$2"."$3}')
STATIC_IP="${IPv4_address_base}.60"
STATIC_GATEWAY="${IPv4_address_base}.1"
NEW_STATIC_IP=
NEW_STATIC_GATEWAY=
if [ -f /etc/network/interfaces.d/static ]; then
2018-03-02 20:17:02 +01:00
STATIC_IP=$(grep "address " /etc/network/interfaces.d/static | head -n 1 | awk -F ' ' '{print $2}')
STATIC_GATEWAY=$(grep "gateway " /etc/network/interfaces.d/static | head -n 1 | awk -F ' ' '{print $2}')
fi
# get the IP for the box
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title $"Set a static local IP address" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"In order to forward incoming internet traffic to this system most internet routers need to know a static local IP address to send the data to.\\n\\n
Enter a static local IP address for this system.\\n\\nIt will typically be ${IPv4_address_base}.x\\n\\nIf you leave this field blank then the system will revert to using a dynamic IP address." 18 60 "$STATIC_IP" 2>"$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
0) NEW_STATIC_IP=$(<"$data")
if [[ "$NEW_STATIC_IP" != *"."* ]]; then
set_dynamic_IP
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
;;
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
# get the gateway
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title $"Set the IP address of your internet router/modem" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Set the local IP address for your internet router or ADSL modem.\\n\\nIt will typically be ${IPv4_address_base}.1, ${IPv4_address_base}.254, or similar" 12 60 "$STATIC_GATEWAY" 2>"$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
0) NEW_STATIC_GATEWAY=$(<"$data")
if [[ "$NEW_STATIC_GATEWAY" != *"."* ]]; then
2018-03-02 20:17:02 +01:00
rm -f "$data"
return
fi
;;
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
if [[ "$NEW_STATIC_GATEWAY" == *"."* && "$NEW_STATIC_IP" == *"."* ]]; then
2017-06-22 22:17:35 +02:00
ip_addresses_have_changed=1
if [ -f /etc/network/interfaces.d/static ]; then
2017-06-22 22:17:35 +02:00
ip_addresses_have_changed=
if ! grep -q "address ${NEW_STATIC_IP}" /etc/network/interfaces.d/static; then
ip_addresses_have_changed=1
fi
if ! grep -q "gateway ${NEW_STATIC_GATEWAY}" /etc/network/interfaces.d/static; then
ip_addresses_have_changed=1
fi
fi
if [ $ip_addresses_have_changed ]; then
2016-10-22 22:25:42 +02:00
write_config_param "NETWORK_IS_STATIC" "1"
2016-10-23 15:15:48 +02:00
write_config_param "LOCAL_NETWORK_STATIC_IP_ADDRESS" "$NEW_STATIC_IP"
2016-10-22 22:25:42 +02:00
write_config_param "ROUTER_IP_ADDRESS" "$NEW_STATIC_GATEWAY"
email_change_relay "$NEW_STATIC_IP"
2016-10-30 12:19:32 +01:00
static_wifi_address=
if [[ $(config_param_exists "WIFI_INTERFACE") == "1" ]]; then
dialog --title $"Static local IP address" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--yesno $"\\nSet a static address for the wifi adapter?\\n\\nIf you select 'no' then wired ethernet will be used." 10 60
2016-10-30 12:19:32 +01:00
sel=$?
case $sel in
0) static_wifi_address=1
write_config_param "NETWORK_IS_STATIC" "1"
;;
esac
fi
echo '# This file describes the network interfaces available on your system' > /etc/network/interfaces
echo '# and how to activate them. For more information, see interfaces(5).' >> /etc/network/interfaces
echo 'source /etc/network/interfaces.d/*' >> /etc/network/interfaces
2016-10-30 12:19:32 +01:00
if [ ! $static_wifi_address ]; then
2016-10-22 22:25:42 +02:00
# wired network
2016-10-30 12:19:32 +01:00
remove_wifi_startup_script
2018-03-02 20:17:02 +01:00
{ echo 'auto eth0';
echo 'iface eth0 inet static';
echo " address ${NEW_STATIC_IP}";
echo ' netmask 255.255.255.0';
echo " gateway ${NEW_STATIC_GATEWAY}"; } >> /etc/network/interfaces.d/static
2016-10-30 12:19:32 +01:00
else
# wifi network
wifi_settings
2016-10-22 22:25:42 +02:00
fi
2016-10-19 13:48:15 +02:00
clear
echo ''
echo $'Restarting the network daemon.'
echo ''
echo $'If you logged in using the previous IP address then you may need to close this terminal and log in again on the new one.'
function_check pihole_change_ipv4
2018-03-02 20:17:02 +01:00
pihole_change_ipv4 "${NEW_STATIC_IP}"
dialog --title $"Static local IP address" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--yesno $"\\nFor the change to take effect your system will now need to reboot. Do this now?" 8 60
sel=$?
case $sel in
2017-06-10 15:26:52 +02:00
0) systemctl reboot -i;;
esac
fi
fi
2018-03-02 20:17:02 +01:00
rm -f "$data"
2015-12-07 15:30:19 +01:00
}
2016-04-20 16:21:41 +02:00
function wifi_settings {
if [ -f /etc/hostapd/hostapd.conf ]; then
return
fi
TEMP_WIFI_NETWORKS_FILE=~/.temp-${PROJECT_NAME}-wifi.cfg
${PROJECT_NAME}-wifi --networksinteractive $TEMP_WIFI_NETWORKS_FILE
if [ -f $TEMP_WIFI_NETWORKS_FILE ]; then
2018-03-02 20:17:02 +01:00
cp "$TEMP_WIFI_NETWORKS_FILE" "$WIFI_NETWORKS_FILE"
rm $TEMP_WIFI_NETWORKS_FILE
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-wifi" --networks "$WIFI_NETWORKS_FILE"
2016-10-22 16:43:15 +02:00
create_wifi_startup_script
2016-10-22 00:19:04 +02:00
if [[ $(wifi_is_running) == "1" ]]; then
dialog --title $"Wifi Settings" \
--msgbox $"Wifi settings were changed." 6 60
else
dialog --title $"Wifi Settings" \
2016-10-22 16:43:15 +02:00
--msgbox $"Wifi settings were changed. You will need to restart the system with ethernet cable removed for the changes to take effect." 7 60
2016-10-22 00:19:04 +02:00
fi
2016-10-22 16:43:15 +02:00
else
remove_wifi_startup_script
fi
2016-04-20 16:21:41 +02:00
}
2016-04-27 20:15:11 +02:00
function wifi_edit_networks {
if [ -f /etc/hostapd/hostapd.conf ]; then
return
fi
2018-03-02 20:17:02 +01:00
if [ ! -f "$WIFI_NETWORKS_FILE" ]; then
{ echo $'# Add wifi networks as follows:';
echo '#';
echo $'# MySSID';
echo $'# wpa2-psk';
echo $'# myWifiPassphrase';
echo '#';
echo $'# AnotherSSID';
echo $'# none';
echo '#'; } > "$WIFI_NETWORKS_FILE"
fi
2018-03-02 20:17:02 +01:00
editor "$WIFI_NETWORKS_FILE"
"${PROJECT_NAME}-wifi" --networks "$WIFI_NETWORKS_FILE"
2016-04-27 20:15:11 +02:00
}
2016-04-27 13:24:55 +02:00
function hotspot_settings {
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Hotspot Settings" \
--form $"" 10 60 4 \
$"Enabled (yes/no):" 1 1 "$WIFI_HOTSPOT" 1 24 5 5 \
$"SSID:" 2 1 "$WIFI_SSID" 2 24 256 256 \
$"Type (wpa2-psk/none):" 3 1 "$WIFI_TYPE" 3 24 10 10 \
$"Passphrase:" 4 1 "$WIFI_PASSPHRASE" 4 24 256 256 \
2018-03-02 20:17:02 +01:00
2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
return;;
esac
2018-03-02 20:17:02 +01:00
TEMP_WIFI_HOTSPOT=$(sed -n 1p < "$data")
TEMP_WIFI_SSID=$(sed -n 2p < "$data")
TEMP_WIFI_TYPE=$(sed -n 3p < "$data")
TEMP_WIFI_PASSPHRASE=$(sed -n 4p < "$data")
rm -f "$data"
if [ ${#TEMP_WIFI_SSID} -lt 2 ]; then
return
fi
if [ ${#TEMP_WIFI_TYPE} -lt 2 ]; then
return
fi
WIFI_EXTRA=''
if [[ $TEMP_WIFI_HOTSPOT == $'yes' || $TEMP_WIFI_HOTSPOT == $'y' || $TEMP_WIFI_HOTSPOT == $'on' ]]; then
TEMP_WIFI_HOTSPOT='yes'
else
TEMP_WIFI_HOTSPOT='no'
2018-03-02 20:17:02 +01:00
if [ -f "$WIFI_NETWORKS_FILE" ]; then
WIFI_EXTRA="--networks $WIFI_NETWORKS_FILE"
fi
fi
if [[ $TEMP_WIFI_TYPE != $'none' ]]; then
2018-03-02 20:17:02 +01:00
if [ ! "$TEMP_WIFI_PASSPHRASE" ]; then
dialog --title $"Wifi Settings" \
--msgbox $"No wifi hotspot passphrase was given" 6 40
return
fi
if [ ${#TEMP_WIFI_PASSPHRASE} -lt 2 ]; then
dialog --title $"Wifi Settings" \
--msgbox $"Wifi hotspot passphrase was too short" 6 40
return
fi
WIFI_HOTSPOT=$TEMP_WIFI_HOTSPOT
WIFI_SSID=$TEMP_WIFI_SSID
WIFI_TYPE=$TEMP_WIFI_TYPE
WIFI_PASSPHRASE=$TEMP_WIFI_PASSPHRASE
2018-03-02 20:17:02 +01:00
if ! "${PROJECT_NAME}-wifi" -i "$WIFI_INTERFACE" -s "$WIFI_SSID" -t "$WIFI_TYPE" -p "$WIFI_PASSPHRASE" --hotspot "$WIFI_HOTSPOT" "$WIFI_EXTRA"; then
echo $"Can't enable wifi hotspot"
any_key
fi
else
WIFI_HOTSPOT=$TEMP_WIFI_HOTSPOT
WIFI_SSID=$TEMP_WIFI_SSID
WIFI_TYPE=$TEMP_WIFI_TYPE
WIFI_PASSPHRASE=$TEMP_WIFI_PASSPHRASE
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-wifi" -i "$WIFI_INTERFACE" -s "$WIFI_SSID" -t "$WIFI_TYPE" --hotspot "$WIFI_HOTSPOT" "$WIFI_EXTRA"
fi
# store any changes
2016-10-14 15:28:45 +02:00
write_config_param "WIFI_HOTSPOT" "$WIFI_HOTSPOT"
write_config_param "WIFI_SSID" "$WIFI_SSID"
write_config_param "WIFI_TYPE" "$WIFI_TYPE"
write_config_param "WIFI_PASSPHRASE" "$WIFI_PASSPHRASE"
dialog --title $"Wifi Settings" \
--msgbox $"Hotspot settings were changed" 6 40
2016-04-27 13:24:55 +02:00
}
function reinstall_mariadb {
dialog --title $"Reinstall MariaDB" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nThis should be a LAST RESORT, if the mysql daemon won't start. You will lose ALL databases and will then need to restore them from backup.\\n\\nAre you sure that you wish to continue?" 12 60
sel=$?
case $sel in
1) return;;
255) return;;
esac
clear
database_reinstall
dialog --title $"Reinstall MariaDB" \
--msgbox $"MariaDB has been reinstalled" 6 40
}
function show_firewall {
clear
echo $"Firewall Settings"
echo ''
2018-03-02 20:17:02 +01:00
while read -r line; do
firewall_name=$(awk "$line" -F '=' '{print $1}')
firewall_port=$(awk "$line" -F '=' '{print $2}')
echo -n -e "$(pad_string "${firewall_name}")"
echo "${firewall_port}"
2018-03-02 20:17:02 +01:00
done < "$FIREWALL_CONFIG"
any_key
}
function email_extra_domains {
2018-03-02 20:17:02 +01:00
email_hostnames=$(grep "dc_other_hostnames" /etc/exim4/update-exim4.conf.conf | awk -F "'" '{print $2}')
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --title $"Email Domains" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Enter the list of email domains to use, separated by semicolons" 8 60 "$email_hostnames" 2>"$data"
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
emailhostnames=$(<"$data")
if [ ${#emailhostnames} -gt 2 ]; then
2016-10-22 18:36:21 +02:00
if [[ "$email_hostnames" != "$emailhostnames" ]]; then
if [[ "$emailhostnames" == *"."* ]]; then
if [[ "$emailhostnames" != *" "* ]]; then
sed -i "s|dc_other_hostnames=.*|dc_other_hostnames='$emailhostnames'|g" /etc/exim4/update-exim4.conf.conf
update-exim4.conf
dpkg-reconfigure --frontend noninteractive exim4-config
systemctl restart saslauthd
dialog --title $"Email Domains" \
--backtitle $"Freedombone Control Panel" \
--msgbox $"Email domains were changed" 6 50
else
dialog --title $"Email Domains not set" \
--backtitle $"Freedombone Control Panel" \
--msgbox $"There should be no spaces in the list" 6 50
fi
fi
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
}
function email_smtp_proxy {
MUTTRC_FILE=/home/$ADMIN_USER/.muttrc
if [ ! -f $MUTTRC_FILE ]; then
return
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"SMTP Proxy for $ADMIN_USER" \
--form $"You may need to proxy outgoing email via your ISP's mail server. If so enter the details below." 14 75 6 \
$"Enable proxy:" 1 1 "$SMTP_PROXY_ENABLE" 1 24 5 5 \
$"Protocol (smtp/smtps):" 2 1 "$SMTP_PROXY_PROTOCOL" 2 24 5 5 \
$"ISP mail server:" 3 1 "$SMTP_PROXY_SERVER" 3 24 40 10000 \
$"Port:" 4 1 "$SMTP_PROXY_PORT" 4 24 5 5 \
$"Username:" 5 1 "$SMTP_PROXY_USERNAME" 5 24 40 10000 \
$"Password:" 6 1 "$SMTP_PROXY_PASSWORD" 6 24 40 10000 \
2018-03-02 20:17:02 +01:00
2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
return;;
255) rm -f "$data"
return;;
esac
2018-03-02 20:17:02 +01:00
SMTP_PROXY_ENABLE=$(sed -n 1p < "$data")
SMTP_PROXY_PROTOCOL=$(sed -n 2p < "$data")
SMTP_PROXY_SERVER=$(sed -n 3p < "$data")
SMTP_PROXY_PORT=$(sed -n 4p < "$data")
SMTP_PROXY_USERNAME=$(sed -n 5p < "$data")
SMTP_PROXY_PASSWORD=$(sed -n 6p < "$data")
rm -f "$data"
# change muttrc
2018-03-02 20:17:02 +01:00
if [ "$SMTP_PROXY_ENABLE" != $'no' ]; then
if ! grep -q "set smtp_url" "$MUTTRC_FILE"; then
echo "set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"" >> "$MUTTRC_FILE"
else
2018-03-02 20:17:02 +01:00
sed -i "s|set smtp_url=.*|set smtp_url=\"${SMTP_PROXY_PROTOCOL}://${SMTP_PROXY_USERNAME}:${SMTP_PROXY_PASSWORD}@${SMTP_PROXY_SERVER}:${SMTP_PROXY_PORT}/\"|g" "$MUTTRC_FILE"
fi
2018-03-02 20:17:02 +01:00
sed -i 's|#set smtp_url|set smtp_url|g' "$MUTTRC_FILE"
else
2018-03-02 20:17:02 +01:00
if grep -q "set smtp_url" "$MUTTRC_FILE"; then
sed -i 's|set smtp_url|#set smtp_url|g' "$MUTTRC_FILE"
fi
fi
# save settings within the main configuration file
write_config_param "SMTP_PROXY_ENABLE" "$SMTP_PROXY_ENABLE"
write_config_param "SMTP_PROXY_PROTOCOL" "$SMTP_PROXY_PROTOCOL"
write_config_param "SMTP_PROXY_SERVER" "$SMTP_PROXY_SERVER"
write_config_param "SMTP_PROXY_PORT" "$SMTP_PROXY_PORT"
write_config_param "SMTP_PROXY_USERNAME" "$SMTP_PROXY_USERNAME"
write_config_param "SMTP_PROXY_PASSWORD" "$SMTP_PROXY_PASSWORD"
}
2015-11-01 11:29:42 +01:00
function menu_backup_restore {
while true
do
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Backup and Restore" \
--radiolist $"Choose an operation:" 19 70 12 \
1 $"Backup data to USB drive" off \
2 $"Restore GPG key from USB keydrive" off \
3 $"Restore data from USB drive" off \
4 $"Reinstall mariadb" off \
5 $"Configure remote backups" off \
6 $"Restore from remote backup" off \
7 $"Backup GPG key to USB (master keydrive)" off \
8 $"Backup GPG key to USB (fragment keydrive)" off \
9 $"Format a USB drive (LUKS encrypted)" off \
10 $"Remove backups from a USB drive" off \
2018-03-02 20:17:02 +01:00
11 $"Back to main menu" on 2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
case $(cat "$data") in
1) backup_data;;
2) restore_gpg_key;;
3) restore_data;;
4) reinstall_mariadb;;
5) configure_remote_backups;;
6) restore_data_remote;;
7) create_keydrive_master;;
8) create_keydrive_fragment;;
9) format_drive;;
10) remove_backups;;
2018-03-02 20:17:02 +01:00
11) rm -f "$data"
break;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
done
2015-11-01 11:29:42 +01:00
}
function menu_email {
while true
do
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Email Menu" \
--radiolist $"Choose an operation:" 15 70 8 \
1 $"Add a user to a mailing list" off \
2 $"Remove a user from a mailing list" off \
3 $"Add an email rule" off \
4 $"Block/Unblock an email address" off \
5 $"Block/Unblock email with subject text" off \
6 $"Outgoing Email Proxy" off \
7 $"Extra email domains" off \
2018-03-02 20:17:02 +01:00
8 $"Back to main menu" on 2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
case $(cat "$data") in
1) add_to_mailing_list;;
2) remove_user_from_mailing_list;;
3) email_rule;;
4) block_unblock_email;;
5) block_unblock_subject;;
6) email_smtp_proxy;;
7) email_extra_domains;;
2018-03-02 20:17:02 +01:00
8) rm -f "$data"
break;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
done
2015-11-01 11:29:42 +01:00
}
function domain_blocking_add {
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
2017-04-27 16:43:09 +02:00
dialog --title $"Block a domain or user" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Enter the domain name or GNU Social/postActiv/Pleroma nick@domain that you wish to block" 8 60 "" 2>"$data"
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
blocked_domain=$(<"$data")
if [ ${#blocked_domain} -gt 2 ]; then
2017-04-15 11:59:13 +02:00
if [[ "${blocked_domain}" == *'.'* ]]; then
2018-03-02 20:17:02 +01:00
firewall_block_domain "$blocked_domain"
if [[ "${blocked_domain}" != *'@'* ]]; then
dialog --title $"Block a domain" \
--msgbox $"The domain $blocked_domain has been blocked" 6 40
else
dialog --title $"Block a GNU Social/postActiv/Pleroma nickname" \
--msgbox $"$blocked_domain has been blocked" 6 40
fi
2017-01-13 21:12:29 +01:00
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
}
2017-07-10 12:29:29 +02:00
function ip_blocking_add {
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
2017-07-10 12:29:29 +02:00
dialog --title $"Block an IP address" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Enter the IP address that you wish to block" 8 60 "" 2>"$data"
2017-07-10 12:29:29 +02:00
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
blocked_ip=$(<"$data")
2017-07-10 12:29:29 +02:00
if [ ${#blocked_ip} -gt 2 ]; then
if [[ "${blocked_ip}" == *'.'* ]]; then
2018-03-02 20:17:02 +01:00
firewall_block_ip "$blocked_ip"
2017-07-10 12:29:29 +02:00
if [[ "${blocked_ip}" != *'@'* ]]; then
dialog --title $"Block an IP address" \
--msgbox $"The IP address $blocked_ip has been blocked" 6 40
fi
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2017-07-10 12:29:29 +02:00
}
function domain_blocking_remove {
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
2017-04-27 16:43:09 +02:00
dialog --title $"Unblock a domain or user" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Enter the domain name or GNU Social/postActiv nick@domain that you wish to unblock" 8 60 "" 2>"$data"
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
unblocked_domain=$(<"$data")
if [ ${#unblocked_domain} -gt 2 ]; then
2017-04-15 11:59:13 +02:00
if [[ "${unblocked_domain}" == *'.'* ]]; then
2018-03-02 20:17:02 +01:00
firewall_unblock_domain "$unblocked_domain"
if [[ "${unblocked_domain}" != *'@'* ]]; then
dialog --title $"Unblock a domain" \
--msgbox $"The domain $unblocked_domain has been unblocked" 6 40
else
dialog --title $"Unblock a GNU Social/postActiv nickname" \
--msgbox $"$unblocked_domain has been unblocked" 6 40
fi
2017-01-13 21:12:29 +01:00
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
}
2017-07-10 12:29:29 +02:00
function ip_blocking_remove {
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
2017-07-10 12:29:29 +02:00
dialog --title $"Unblock an IP address" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"Enter the IP address that you wish to unblock" 8 60 "" 2>"$data"
2017-07-10 12:29:29 +02:00
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
unblocked_ip=$(<"$data")
2017-07-10 12:29:29 +02:00
if [ ${#unblocked_ip} -gt 2 ]; then
if [[ "${unblocked_ip}" == *'.'* ]]; then
2018-03-02 20:17:02 +01:00
firewall_unblock_ip "$unblocked_ip"
2017-07-10 12:29:29 +02:00
if [[ "${unblocked_ip}" != *'@'* ]]; then
dialog --title $"Unblock an IP address" \
--msgbox $"The IP address $unblocked_ip has been unblocked" 6 40
fi
fi
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2017-07-10 12:29:29 +02:00
}
function domain_blocking_show {
2018-03-02 20:17:02 +01:00
if [ -f "$FIREWALL_DOMAINS" ]; then
clear
2017-04-15 12:01:19 +02:00
echo ''
2017-04-27 16:43:09 +02:00
echo $'The following domains or users have been blocked:'
2017-04-15 12:01:19 +02:00
echo ''
2018-03-02 20:17:02 +01:00
sort < "$FIREWALL_DOMAINS"
any_key
2017-04-15 11:59:13 +02:00
else
2017-04-27 16:43:09 +02:00
dialog --title $"Show blocked domains or users" \
--msgbox $"No domains or users are currently blocked" 6 40
fi
}
function domain_blocking {
while true
do
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
2017-04-27 16:43:09 +02:00
--title $"Domain or User Blocking" \
2017-07-10 12:29:29 +02:00
--radiolist $"Choose an operation:" 14 60 6 \
2017-04-27 16:43:09 +02:00
1 $"Block a domain or user" off \
2 $"Unblock a domain or user" off \
2017-07-10 12:29:29 +02:00
3 $"Block an IP address" off \
4 $"Unblock an IP address" off \
5 $"Show blocked domains and users" off \
2018-03-02 20:17:02 +01:00
6 $"Back to main menu" on 2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
case $(cat "$data") in
1) domain_blocking_add;;
2) domain_blocking_remove;;
2017-07-10 12:29:29 +02:00
3) ip_blocking_add;;
4) ip_blocking_remove;;
5) domain_blocking_show;;
2018-03-02 20:17:02 +01:00
6) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
done
}
2015-11-01 11:29:42 +01:00
function menu_users {
while true
do
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Manage Users" \
--radiolist $"Choose an operation:" 13 70 6 \
1 $"Add a user" off \
2 $"Delete a user" off \
3 $"Change user password" off \
4 $"Change user ssh public key" off \
5 $"Reset password tries" off \
2018-03-02 20:17:02 +01:00
6 $"Back to main menu" on 2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
case $(cat "$data") in
1) add_user;;
2) delete_user;;
3) change_password;;
4) change_ssh_public_key;;
5) reset_password_tries;;
2018-03-02 20:17:02 +01:00
6) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
done
2016-04-27 13:26:34 +02:00
}
2016-04-27 18:54:26 +02:00
function wifi_enable {
disable_wifi='yes'
dialog --title $"Enable Wifi" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
2018-03-02 20:17:02 +01:00
--yesno $"\\nDo you wish to enable wifi?" 10 50
sel=$?
case $sel in
0) disable_wifi='no';;
1) disable_wifi='yes';;
255) return;;
esac
2018-03-02 20:17:02 +01:00
"${PROJECT_NAME}-wifi" --disable $disable_wifi
2016-04-27 18:54:26 +02:00
}
2017-11-03 20:36:40 +01:00
function add_clacks {
clacks=
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
2017-11-03 20:36:40 +01:00
dialog --title $"Add Clacks Overhead" \
--backtitle $"Freedombone Control Panel" \
2018-03-02 20:17:02 +01:00
--inputbox $"" 7 60 2>"$data"
2017-11-03 20:36:40 +01:00
sel=$?
case $sel in
0)
2018-03-02 20:17:02 +01:00
clacks=$(<"$data")
2017-11-03 20:36:40 +01:00
if [ ${#clacks} -gt 1 ]; then
2018-03-03 12:49:17 +01:00
WEB_FILES="/etc/nginx/sites-available/"*
2017-11-03 20:36:40 +01:00
for f in $WEB_FILES
do
2018-03-02 20:17:02 +01:00
if grep -q "X-Clacks-Overhead" "$f"; then
sed -i "s|X-Clacks-Overhead .*|X-Clacks-Overhead \"GNU $clacks\";|g" "$f"
2017-11-03 20:36:40 +01:00
else
2018-03-02 20:17:02 +01:00
sed -i "/X-Content-Type-Options/a add_header X-Clacks-Overhead \"GNU $clacks\";" "$f"
2017-11-03 20:36:40 +01:00
fi
done
systemctl restart nginx
2017-11-03 20:36:40 +01:00
dialog --title $"Add Clacks Overhead" \
2018-03-02 20:17:02 +01:00
--msgbox $"\\nAdded for $clacks" 10 60
2017-11-03 20:36:40 +01:00
fi
;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
2017-11-03 20:36:40 +01:00
}
2016-06-04 15:25:46 +02:00
function menu_wifi {
2016-11-02 21:42:56 +01:00
if [[ "$(wifi_exists)" == "0" ]]; then
dialog --title $"Wifi" \
--msgbox $"No wifi adaptors were detected" 6 40
return
fi
while true
do
status_str=$'Wifi OFF'
if [ -f /etc/hostapd/hostapd.conf ]; then
status_str=$'Hotspot ON'
else
if [ -f /etc/network/interfaces.d/wifi ]; then
status_str=$'Wifi ON'
fi
fi
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Wifi Menu" \
2018-03-02 20:17:02 +01:00
--radiolist $"${status_str}\\n\\nChoose an operation:" 14 70 6 \
1 $"Enable or disable Wifi" off \
2 $"Configure wifi networks" off \
3 $"Manually edit wifi networks file" off \
4 $"Hotspot settings" off \
2018-03-02 20:17:02 +01:00
5 $"Exit" on 2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
case $(cat "$data") in
1) wifi_enable;;
2) wifi_settings;;
3) wifi_edit_networks;;
4) hotspot_settings;;
2018-03-02 20:17:02 +01:00
5) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
done
2016-04-26 23:38:03 +02:00
}
2016-09-30 15:59:37 +02:00
function menu_app_settings {
detect_installable_apps
applist=""
appnames=()
n=1
app_index=0
for a in "${APPS_AVAILABLE[@]}"
do
if [[ ${APPS_INSTALLED[$app_index]} != "0" ]]; then
2018-03-02 20:17:02 +01:00
if [[ $(function_exists "configure_interactive_${a}") == "1" ]]; then
applist="$applist $n $a off"
2018-03-02 20:17:02 +01:00
n=$((n+1))
appnames+=("$a")
fi
fi
2018-03-02 20:17:02 +01:00
app_index=$((app_index+1))
done
2016-09-30 15:59:37 +02:00
if [ $n -le 1 ]; then
return
fi
2016-09-30 14:48:36 +02:00
backstr=$'Exit'
applist="$applist $n $backstr on"
appnames+=("Exit")
2016-09-30 14:37:19 +02:00
choice=$(dialog --stdout --backtitle $"Freedombone" \
2017-05-23 18:32:36 +02:00
--title $"Change settings for an App" \
2016-11-19 17:21:33 +01:00
--radiolist $'Choose:' \
2018-03-02 20:17:02 +01:00
26 40 30 "$applist")
2018-03-02 20:17:02 +01:00
# shellcheck disable=SC2181
if [ $? -eq 0 ]; then
2018-03-02 20:17:02 +01:00
app_index=$((choice-1))
2016-09-30 14:37:19 +02:00
chosen_app=${appnames[$app_index]}
if [[ $chosen_app != "Exit" ]]; then
2018-03-02 20:17:02 +01:00
"configure_interactive_${chosen_app}"
2016-09-30 14:37:19 +02:00
fi
fi
2016-04-27 13:26:34 +02:00
}
function menu_top_level {
while true
do
2018-03-02 20:17:02 +01:00
data=$(mktemp 2>/dev/null)
dialog --backtitle $"Freedombone Control Panel" \
--title $"Control Panel" \
2017-11-03 20:36:40 +01:00
--radiolist $"Choose an operation:" 30 70 22 \
1 $"About this system" off \
2016-11-19 16:45:15 +01:00
2 $"Passwords" off \
3 $"Backup and Restore" off \
4 $"Show Firewall" off \
2017-08-05 14:30:58 +02:00
5 $"Verify Tripwire Code" off \
6 $"Reset Tripwire" off \
7 $"App Settings" off \
8 $"Add/Remove Apps" off \
9 $"Logging on/off" off \
10 $"Ping enable/disable" off \
11 $"Manage Users" off \
12 $"Email Menu" off \
13 $"Domain or User Blocking" off \
14 $"Security Settings" off \
15 $"Change the name of this system" off \
16 $"Set a static local IP address" off \
17 $"Wifi menu" off \
2017-11-03 20:36:40 +01:00
18 $"Add Clacks" off \
19 $"Check for updates" off \
20 $"Power off the system" off \
21 $"Restart the system" off \
2018-03-02 20:17:02 +01:00
22 $"Exit" on 2> "$data"
sel=$?
case $sel in
2018-03-02 20:17:02 +01:00
1) rm -f "$data"
2018-01-25 18:04:25 +01:00
exit 1;;
2018-03-02 20:17:02 +01:00
255) rm -f "$data"
2018-01-25 18:04:25 +01:00
exit 1;;
esac
2017-06-05 20:59:04 +02:00
please_wait
2018-03-02 20:17:02 +01:00
case $(cat "$data") in
1) show_about;;
2016-11-19 16:45:15 +01:00
2) view_or_change_passwords;;
3) menu_backup_restore;;
4) show_firewall;;
2017-08-05 14:30:58 +02:00
5) show_tripwire_verification_code
2017-08-09 12:29:56 +02:00
any_key_verify;;
2017-08-05 14:30:58 +02:00
6) reset_tripwire;;
7) menu_app_settings;;
2018-03-02 20:17:02 +01:00
8) if ! /usr/local/bin/addremove; then
2016-12-04 17:23:21 +01:00
any_key
fi
;;
2017-08-05 14:30:58 +02:00
9) logging_on_off;;
10) ping_enable_disable;;
11) menu_users;;
12) menu_email;;
13) domain_blocking;;
14) security_settings;;
15) change_system_name;;
16) set_static_IP;;
17) menu_wifi;;
2017-11-03 20:36:40 +01:00
18) add_clacks;;
19) check_for_updates;;
20) shut_down_system;;
21) restart_system;;
2018-03-02 20:17:02 +01:00
22) rm -f "$data"
2018-01-25 18:04:25 +01:00
break;;
esac
2018-03-02 20:17:02 +01:00
rm -f "$data"
done
2016-04-27 13:26:34 +02:00
}
2018-03-02 20:17:02 +01:00
if [ ! -f "$COMPLETION_FILE" ]; then
echo $'This command should only be run on an installed Freedombone system'
exit 1
2016-04-27 13:26:34 +02:00
fi
2016-10-16 20:50:56 +02:00
ADMIN_USER=$(get_completion_param "Admin user")
2016-04-27 13:26:34 +02:00
menu_top_level
clear
cat /etc/motd
exit 0