You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1869 lines
62 KiB

6 years ago
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Administrator control panel for the Freedombone system
#
# License
# =======
#
# Copyright (C) 2015-2016 Bob Mottram <bob@freedombone.net>
6 years ago
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
6 years ago
# 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
6 years ago
#
# 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/>.
6 years ago
PROJECT_NAME='freedombone'
export TEXTDOMAIN=${PROJECT_NAME}-controlpanel
export TEXTDOMAINDIR="/usr/share/locale"
UTILS_FILES=/usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-*
for f in $UTILS_FILES
do
source $f
done
APP_FILES=/usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-*
for f in $APP_FILES
do
source $f
done
6 years ago
COMPLETION_FILE=$HOME/${PROJECT_NAME}-completed.txt
6 years ago
SELECTED_USERNAME=
SIP_CONFIGURATION_FILE=/etc/sipwitch.conf
ADMIN_USER=
UPGRADE_SCRIPT_NAME="${PROJECT_NAME}-upgrade"
UPDATE_DATE_SCRIPT=/usr/bin/updatedate
6 years ago
# Minimum number of characters in a password
MINIMUM_PASSWORD_LENGTH=$(cat /usr/share/${PROJECT_NAME}/utils/${PROJECT_NAME}-utils-passwords | grep 'MINIMUM_PASSWORD_LENGTH=' | head -n 1 | awk -F '=' '{print $2}')
# Mumble
MUMBLE_PORT=64738
MUMBLE_ONION_PORT=8095
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=''
WIFI_INTERFACE=wlan0
WIFI_SSID=
WIFI_TYPE='wpa2-psk'
WIFI_PASSPHRASE=
6 years ago
WIFI_HOTSPOT='no'
6 years ago
WIFI_NETWORKS_FILE=~/${PROJECT_NAME}-wifi.cfg
USB_DRIVE=sdb
# get default USB from config file
5 years ago
CONFIGURATION_FILE=$HOME/${PROJECT_NAME}.cfg
5 years ago
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
if [[ $USB_DRIVE == *"dev"* ]]; then
USB_DRIVE=$(echo ${USB_DRIVE} | awk -F '/' '{print $3}' | sed 's|1||g' | sed 's|2||g')
fi
# Mirrors settings
FRIENDS_MIRRORS_SERVER=
FRIENDS_MIRRORS_SSH_PORT=2222
FRIENDS_MIRRORS_PASSWORD=
MY_MIRRORS_PASSWORD=
6 years ago
function any_key {
echo ' '
read -n1 -r -p $"Press any key to continue..." key
6 years ago
}
function check_for_updates {
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
. /etc/cron.weekly/$UPGRADE_SCRIPT_NAME
any_key
}
function set_main_repo {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Main Repository (Mirrors)" \
--form $"If you do not wish to use the default repositories they can be obtained from mirrors on another ${PROJECT_NAME} server." 14 60 3 \
$"URL:" 1 1 "$FRIENDS_MIRRORS_SERVER" 1 14 40 15 \
$"SSH Port:" 2 1 "$FRIENDS_MIRRORS_SSH_PORT" 2 14 40 10000 \
$"Password:" 3 1 "$FRIENDS_MIRRORS_PASSWORD" 3 14 40 10000 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
new_mirrors_url=$(cat $data | sed -n 1p)
new_mirrors_ssh_port=$(cat $data | sed -n 2p)
new_mirrors_password=$(cat $data | sed -n 3p)
if [ ${#new_mirrors_url} -lt 2 ]; then
return
fi
if [ ${#new_mirrors_ssh_port} -lt 1 ]; then
return
fi
if [ ${#new_mirrors_password} -lt 10 ]; then
dialog --title $"Main Repository" \
--msgbox $'Mirrors password was too short. Should be at least 10 characters.' 6 40
return
fi
if [[ $new_mirrors_url == *"."* ]]; then
FRIENDS_MIRRORS_SERVER=$new_mirrors_url
FRIENDS_MIRRORS_SSH_PORT=$new_mirrors_ssh_port
FRIENDS_MIRRORS_PASSWORD=$new_mirrors_password
5 years ago
write_config_param "FRIENDS_MIRRORS_SERVER" "$FRIENDS_MIRRORS_SERVER"
write_config_param "FRIENDS_MIRRORS_SSH_PORT" "$FRIENDS_MIRRORS_SSH_PORT"
write_config_param "FRIENDS_MIRRORS_PASSWORD" "$FRIENDS_MIRRORS_PASSWORD"
# re-read the repos
read_repo_servers
dialog --title $"Main Repository" \
--msgbox $"Main repository set to $FRIENDS_MIRRORS_SERVER" 6 60
fi
}
6 years ago
function add_user {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Add new user" \
--form "\n" 8 60 3 \
$"Username:" 1 1 "" 1 28 16 15 \
$"ssh public key (optional):" 2 1 "" 2 28 40 10000 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
new_user_username=$(cat $data | sed -n 1p)
new_user_ssh_public_key=$(cat $data | sed -n 2p)
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
${PROJECT_NAME}-adduser "$new_user_username"
any_key
else
if [[ "$new_user_ssh_public_key" == "ssh-"* ]]; then
clear
${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
6 years ago
}
6 years ago
function pad_string {
echo -n -e "$1" | sed -e :a -e 's/^.\{1,25\}$/& /;ta'
6 years ago
}
6 years ago
function show_domains {
5 years ago
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 '--------------------------------------------------------------------------'
if grep -q "ssh onion domain" $COMPLETION_FILE; then
echo -n -e "$(pad_string 'ssh')"
echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
echo "$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')"
fi
5 years ago
if grep -q "email onion domain" $COMPLETION_FILE; then
echo -n -e "$(pad_string 'Email')"
echo -n -e "$(pad_string ${DEFAULT_DOMAIN_NAME})"
5 years ago
echo "$(cat ${COMPLETION_FILE} | grep 'email onion domain' | awk -F ':' '{print $2}')"
fi
for app_name in "${APPS_INSTALLED_NAMES[@]}"
do
if ! grep -q "SHOW_ON_ABOUT=1" /usr/share/${PROJECT_NAME}/apps/${PROJECT_NAME}-app-${app_name}; then
continue
fi
icann_address=${DEFAULT_DOMAIN_NAME}
5 years ago
onion_address="-"
# handle the foibles of capitalisation
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
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
if [ ${#app_name} -gt 0 ]; then
if grep -q "${app_name} domain" $COMPLETION_FILE; then
icann_address=$(cat ${COMPLETION_FILE} | grep "${app_name} domain" | head -n 1 | awk -F ':' '{print $2}')
fi
if grep -q "${app_name} onion domain" $COMPLETION_FILE; then
onion_address=$(cat ${COMPLETION_FILE} | grep "${app_name} onion domain" | head -n 1 | awk -F ':' '{print $2}')
fi
echo -n -e "$(pad_string "${app_name}")"
echo -n -e "$(pad_string "${icann_address}")"
echo "${onion_address}"
if grep -q "${app_name}_mobile onion domain" $COMPLETION_FILE; then
if grep -q "${app_name}_mobile onion domain" $COMPLETION_FILE; then
onion_address=$(cat ${COMPLETION_FILE} | grep "${app_name}_mobile onion domain" | head -n 1 | awk -F ':' '{print $2}')
fi
echo -n -e "$(pad_string "${app_name} (mobile)")"
echo -n -e "$(pad_string "${icann_address}")"
echo "${onion_address}"
fi
fi
done
5 years ago
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
if [ -d /var/lib/tor/hidden_service_ttrss_mobile ]; then
echo -n -e "$(pad_string 'RSS mobile')"
RSSMOBILEDOM='-'
echo -n -e "$(pad_string ${RSSMOBILEDOM})"
echo -n "$(cat /var/lib/tor/hidden_service_ttrss_mobile/hostname)"
echo ''
fi
fi
echo ''
6 years ago
}
function show_users {
echo 'Users'
echo '====='
echo ''
echo -n -e "$(pad_string 'Name')"
echo -n -e "$(pad_string 'SIP ext')"
echo -n -e "$(pad_string 'Data')"
echo ''
echo '--------------------------------------------------------------------------'
for d in /home/*/ ; do
USRNAME=$(echo "$d" | awk -F '/' '{print $3}')
5 years ago
if [[ $(is_valid_user "$USRNAME") == "1" ]]; then
echo -n -e "$(pad_string ${USRNAME})"
# get the SIP extension
SIPEXT=
5 years ago
if [ -f $SIP_CONFIGURATION_FILE ]; then
while read ext; do
if [[ $ext == *"user id"* ]]; then
CURR_UID=$(echo "$ext" | awk -F '"' '{print $2}' | awk -F '"' '{print $1}')
fi
5 years ago
if [[ $ext == *"extension"* ]]; then
if [[ $CURR_UID == $USRNAME ]]; then
SIPEXT=$(echo "$ext" | awk -F '>' '{print $2}' | awk -F '<' '{print $1}')
fi
fi
done < $SIP_CONFIGURATION_FILE
fi
if [ $SIPEXT ]; then
echo -n -e "$(pad_string SIP:${SIPEXT})"
else
echo -n -e "$(pad_string '')"
fi
# size of the home directory
echo "$(du -s -h /home/${USRNAME} | awk -F ' ' '{print $1}')"
fi
done
echo ''
6 years ago
}
function show_mirrors_password {
if [ ! /home/mirrors ]; then
return
fi
5 years ago
read_config_param "MY_MIRRORS_PASSWORD"
echo 'Local Mirrors'
echo '============='
echo ''
echo -n "URL: "
echo "$(cat ${COMPLETION_FILE} | grep 'ssh onion domain' | awk -F ':' '{print $2}')"
echo "SSH Port: $SSH_PORT"
echo "Password: $MY_MIRRORS_PASSWORD"
echo ''
}
function show_tahoe_introducer {
if [ ! -f /home/tahoelafs/.tahoe-introducer/private/introducer.furl ]; then
return
fi
echo 'Tahoe-LAFS'
echo '=========='
echo ''
cat /home/tahoelafs/.tahoe-introducer/private/introducer.furl
echo ''
}
function show_ip_addresses {
echo 'IP/DNS addresses'
echo '================'
echo ''
echo -n "IPv4: $(get_ipv4_address)"
ipv6_address="$(get_ipv6_address)"
if [ ${#ipv6_address} -gt 0 ]; then
5 years ago
echo " IPv6: ${ipv6_address}"
fi
echo ''
echo ''
}
6 years ago
function show_about {
clear
echo ''
echo $' Detecting installed apps...'
detect_apps
get_apps_installed_names
clear
show_ip_addresses
show_domains
show_mirrors_password
show_tahoe_introducer
show_users
any_key
}
6 years ago
function select_user {
SELECTED_USERNAME=
users_array=($(ls /home))
delete=(mirrors git)
for del in ${delete[@]}
do
users_array=(${users_array[@]/$del})
done
i=0
W=()
name=()
for u in ${users_array[@]}
do
if [[ $(is_valid_user "$u") == "1" ]]; then
i=$((i+1))
W+=($i "$u")
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)
if [ $? -eq 0 ]; then
SELECTED_USERNAME="${name[$((user_index-1))]}"
fi
fi
6 years ago
}
function delete_user {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
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
${PROJECT_NAME}-rmuser $SELECTED_USERNAME
any_key
6 years ago
}
function configure_remote_backups {
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
if [ ! -d /home/$ADMIN_USER ]; then
dialog --title $"Administrator user" \
--msgbox $"Home directory not found" 6 40
return
fi
${PROJECT_NAME}-remote -u $ADMIN_USER
if [ ! "$?" = "0" ]; then
any_key
fi
}
6 years ago
function change_password {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
dialog --title $"Change password" \
--passwordbox $"New password for user $SELECTED_USERNAME" 8 40 2> $data
newpassword=$(<$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
6 years ago
}
function change_ssh_public_key {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
if grep -Fxq "Admin user:$SELECTED_USERNAME" $COMPLETION_FILE; then
dialog --title $"Change ssh public key" \
--backtitle $"Freedombone Control Panel" \
--defaultno \
--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
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Change ssh public key for $SELECTED_USERNAME" \
--backtitle $"Freedombone Control Panel" \
--inputbox $"Paste the ssh public key below" 8 60 2>$data
sel=$?
case $sel in
0)
SSH_PUBLIC_KEY=$(<$data)
if [ "$SSH_PUBLIC_KEY" ]; then
if [ ${#SSH_PUBLIC_KEY} -gt 5 ]; then
if [ -f "$SSH_PUBLIC_KEY" ]; then
if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
mkdir /home/$SELECTED_USERNAME/.ssh
fi
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
if [ ! -d /home/$SELECTED_USERNAME/.ssh ]; then
mkdir /home/$SELECTED_USERNAME/.ssh
fi
echo "$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
fi
fi
fi
fi
;;
esac
}
function remove_user_from_mailing_list {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
USER_MAILING_LISTS=$(cat "/home/$SELECTED_USERNAME/.procmailrc" | grep '\[' | grep '\]' | awk -F '\[' '{print $2}' | awk -F '\\' '{print $1}')
i=0
W=()
list_name=()
while read -r listname; do
i=$((i+1))
W+=($i "$listname")
list_name+=("$listname")
echo $listname
done <<< "$USER_MAILING_LISTS"
i=$((i+1))
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)
if [ $? -eq 0 ]; then # Exit with OK
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
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
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
echo "$line" >> /home/${SELECTED_USERNAME}/.procmailrc_new
if [[ "$line" == *"\[${remove_list_name}\\]"* ]]; then
line_number=${i}
fi
done < "/home/$SELECTED_USERNAME/.procmailrc"
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
}
6 years ago
function add_to_mailing_list {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Subscribe $SELECTED_USERNAME to a mailing list" \
--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 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
LIST_NAME=$(cat $data | sed -n 1p)
LIST_SUBJECT=$(cat $data | sed -n 2p)
LIST_EMAIL=$(cat $data | sed -n 3p)
LIST_PUBLIC=$(cat $data | sed -n 4p)
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
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
return
fi
fi
if [ ${#LIST_SUBJECT} -gt 1 ]; then
${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
return
else
${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
6 years ago
}
function email_rule {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title $"Email rule for user $SELECTED_USERNAME" \
--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 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
RULE_EMAIL=$(cat $data | sed -n 1p)
RULE_FOLDER=$(cat $data | sed -n 2p)
RULE_PUBLIC=$(cat $data | sed -n 3p)
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
return
fi
if [ ${#RULE_FOLDER} -lt 2 ]; then
dialog --title $"Add email rule" \
--msgbox $"No folder name was given" 6 40
return
fi
if [[ "$RULE_EMAIL" != *"@"* || "$RULE_EMAIL" != *"."* ]]; then
dialog --title $"Add email rule" \
--msgbox $"Unrecognised email address" 6 40
return
fi
${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
6 years ago
}
function block_unblock_email {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
blockstr=$"Block/Unblock email going to"
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title "$blockstr $SELECTED_USERNAME" \
--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 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
BLOCK_EMAIL=$(cat $data | sed -n 1p)
BLOCK=$(cat $data | sed -n 2p)
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
${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
${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
6 years ago
}
function block_unblock_subject {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
blockstr=$"Block/Unblock email going to"
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --backtitle $"Freedombone Control Panel" \
--title "$blockstr $SELECTED_USERNAME" \
--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 \
2> $data
sel=$?
case $sel in
1) return;;
255) return;;
esac
BLOCK_SUBJECT=$(cat $data | sed -n 1p)
BLOCK=$(cat $data | sed -n 2p)
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
${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
${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
6 years ago
}
function create_keydrive_master {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
dialog --title $"USB Master Keydrive" \
--msgbox $"Plug in a LUKS encrypted USB drive" 6 40
clear
${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME --master 'yes'
any_key
6 years ago
}
function create_keydrive_fragment {
select_user
if [ ! $SELECTED_USERNAME ]; then
return
fi
dialog --title $"USB Fragment Keydrive" \
--msgbox $"Plug in a LUKS encrypted USB drive" 6 40
clear
${PROJECT_NAME}-keydrive -u $SELECTED_USERNAME
any_key
6 years ago
}
function backup_data {
dialog --title $"Backup data to USB" \
--msgbox $"Plug in a LUKS encrypted USB drive" 6 40
clear
detect_usb_drive
echo ''
echo $"Detected USB drive $USB_DRIVE"
echo ''
echo $'Enter the passphrase for your LUKS encrypted backup drive:'
${PROJECT_NAME}-backup-local
any_key
6 years ago
}
function restore_data_from_storage {
restore_type="$1"
5 years ago
AllStr=$"all"
ExitStr=$"Exit"
RestoreStr=$"Restore apps"
5 years ago
if [[ $restore_type != "local" ]]; then
restore_command="${PROJECT_NAME}-restore-remote $remote_domain_name configuration;;"
else
remote_domain_name="$1"
detect_usb_drive
5 years ago
restore_command="${PROJECT_NAME}-restore-local $USB_DRIVE"
RestoreStr=$"Restore apps from USB drive $USB_DRIVE"
fi
utils_installed=(configfiles
mariadb
letsencrypt
mutt
gpg
procmail
spamassassin
readme
ssh
userconfig
userlocal
userfin
certs
personal
email)
detect_apps
while true
do
app_list=()
n=1
applist="$n $AllStr off"
n=$[n+1]
app_list+=("$AllStr")
util_index=0
for a in "${utils_installed[@]}"
do
applist="$applist $n $a off"
app_name=${utils_installed[util_index]}
n=$[n+1]
util_index=$[util_index+1]
app_list+=("$app_name")
done
app_index=0
for a in "${APPS_INSTALLED_NAMES[@]}"
do
applist="$applist $n $a off"
n=$[n+1]
app_name=${APPS_INSTALLED_NAMES[app_index]}
app_index=$[app_index+1]
app_list+=("$app_name")
done
applist="$applist $n $ExitStr on"
n=$[n+1]
app_list+=("$ExitStr")
5 years ago
choice=$(dialog --stdout --backtitle $"Freedombone" \
--title "$RestoreStr" \
5 years ago
--radiolist $'Choose:' \
5 years ago
30 50 20 $applist)
5 years ago
if [ $? -ne 0 ]; then
break
fi
app_index=$[choice-1]
app_name=${app_list[app_index]}
# exit
5 years ago
if [[ "$app_name" == "$ExitStr" ]]; then
break
fi
clear
# Restore all
5 years ago
if [[ "$app_name" == "$AllStr" ]]; then
$restore_command
retcode="$?"
if [[ "$retcode" != "0" ]]; then
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
if [[ "$1" == "local" ]]; then
dialog --title $"Restore all apps from USB" \
--msgbox $"Restore complete" 6 40
else
dialog --title $"Restore all apps from $1" \
--msgbox $"Restore complete" 6 40
fi
break
fi
# Restore an app
$restore_command "${app_name}"
retcode="$?"
if [[ "$retcode" != "0" ]]; then
dialog --title $"Restore apps from USB" \
--msgbox $"Restore of ${app_name} failed with code $retcode" 6 60
return
fi
# finished
if [[ "$1" == "local" ]]; then
dialog --title $"Restore apps from USB" \
--msgbox $"Restore complete" 6 40
else
dialog --title $"Restore apps from $1" \
--msgbox $"Restore complete" 6 40
fi
done
}
6 years ago
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:'
restore_data_from_storage local
6 years ago
}
function restore_data_remote {
if [ ! $ADMIN_USER ]; then
dialog --title $"Restore data from remote server" \
--msgbox $"Unknown admin user" 6 40
return
fi
data=$(tempfile 2>/dev/null)