freedombone/src/freedombone-app-mumble

292 lines
11 KiB
Plaintext
Raw Normal View History

2016-07-03 17:13:34 +02:00
#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Mumble application
#
# License
# =======
#
# Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
#
# 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
# 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.
#
# 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/>.
2016-07-06 17:47:55 +02:00
VARIANTS='full chat'
2016-07-03 17:13:34 +02:00
# Password used for VoIP server
VOIP_SERVER_PASSWORD=
# Port on which VoIP server listens
VOIP_PORT=64738
# Location of VoIP database and configuration
VOIP_DATABASE="mumble-server.sqlite"
VOIP_CONFIG_FILE="mumble-server.ini"
function install_interactive_mumble {
echo -n ''
}
2016-09-25 12:20:41 +02:00
function change_password_mumble {
echo -n ''
}
2016-07-09 12:36:12 +02:00
function reconfigure_mumble {
2016-09-25 12:20:41 +02:00
echo -n ''
2016-07-09 12:36:12 +02:00
}
2016-07-06 16:01:28 +02:00
function upgrade_mumble {
2016-09-25 12:20:41 +02:00
echo -n ''
2016-07-06 16:01:28 +02:00
}
2016-07-06 15:55:09 +02:00
function backup_local_mumble {
2016-09-25 12:20:41 +02:00
if [ -f /etc/mumble-server.ini ]; then
echo $"Backing up Mumble settings"
temp_backup_dir=/root/tempvoipbackup
if [ ! -d $temp_backup_dir ]; then
mkdir -p $temp_backup_dir
fi
cp -f /etc/mumble-server.ini $temp_backup_dir
cp -f /var/lib/mumble-server/mumble-server.sqlite $temp_backup_dir
backup_directory_to_usb $temp_backup_dir voip
echo $"Mumble settings backup complete"
fi
2016-07-06 15:55:09 +02:00
}
function restore_local_mumble {
2016-09-25 12:20:41 +02:00
if [ -d $USB_MOUNT/backup/voip ]; then
echo $"Restoring VoIP settings"
temp_restore_dir=/root/tempvoip
function_check restore_directory_from_usb
restore_directory_from_usb $temp_restore_dir voip
cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 3679
fi
cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
function_check set_user_permissions
set_user_permissions
function_check backup_unmount_drive
backup_unmount_drive
exit 276
fi
rm -rf $temp_restore_dir
cp /etc/ssl/certs/mumble* /var/lib/mumble-server
cp /etc/ssl/private/mumble* /var/lib/mumble-server
chown -R mumble-server:mumble-server /var/lib/mumble-server
service mumble-server restart
fi
}
2016-07-06 15:55:09 +02:00
function backup_remote_mumble {
2016-09-25 12:20:41 +02:00
if [ -f /etc/mumble-server.ini ]; then
echo $"Backing up VoIP settings"
if [ ! -d /root/tempvoipbackup ]; then
mkdir -p /root/tempvoipbackup
fi
cp -f /etc/mumble-server.ini /root/tempvoipbackup
cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempvoipbackup
backup_directory_to_friend /root/tempvoipbackup voip
echo $"Backup of VoIP settings complete"
fi
}
function restore_remote_mumble {
2016-09-25 12:20:41 +02:00
if [ -d $SERVER_DIRECTORY/backup/voip ]; then
echo $"Restoring Mumble settings"
temp_restore_dir=/root/tempvoip
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir voip
cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini /etc/
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
exit 7823
fi
cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/sipwitch.conf /etc/sipwitch.conf
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
exit 7823
fi
cp -f $temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite /var/lib/mumble-server/
if [ ! "$?" = "0" ]; then
rm -rf $temp_restore_dir
exit 276
fi
rm -rf $temp_restore_dir
cp /etc/ssl/certs/mumble* /var/lib/mumble-server
cp /etc/ssl/private/mumble* /var/lib/mumble-server
chown -R mumble-server:mumble-server /var/lib/mumble-server
service mumble-server restart
echo $"Restore of Mumble complete"
fi
2016-07-04 22:02:22 +02:00
}
2016-07-03 23:30:26 +02:00
function remove_mumble {
2016-09-30 20:34:01 +02:00
if [[ $(app_is_installed mumble) == "0" ]]; then
return
2016-09-25 12:20:41 +02:00
fi
apt-get -y remove --purge mumble-server
if [[ $ONION_ONLY == "no" ]]; then
iptables -D INPUT -p udp --dport $VOIP_PORT -j ACCEPT
iptables -D INPUT -p tcp --dport $VOIP_PORT -j ACCEPT
function_check save_firewall_settings
save_firewall_settings
fi
if [ -f /etc/mumble-server.ini ]; then
rm /etc/mumble-server.ini
fi
function_check remove_onion_service
remove_onion_service voip ${VOIP_PORT}
sed -i '/install_mumble/d' $COMPLETION_FILE
sed -i '/install_voip/d' $COMPLETION_FILE
sed -i '/configure_firewall_for_voip/d' $COMPLETION_FILE
sed -i '/VoIP /d' $COMPLETION_FILE
2016-07-03 23:30:26 +02:00
}
2016-07-03 17:13:34 +02:00
function get_voip_server_password {
2016-09-25 12:20:41 +02:00
if [ -f /home/$MY_USERNAME/README ]; then
if grep -q "VoIP server password" /home/$MY_USERNAME/README; then
if [ ! $VOIP_SERVER_PASSWORD ]; then
VOIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "VoIP server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi
else
if grep -q "Mumble server password" /home/$MY_USERNAME/README; then
if [ ! $VOIP_SERVER_PASSWORD ]; then
VOIP_SERVER_PASSWORD=$(cat /home/$MY_USERNAME/README | grep "Mumble server password" | awk -F ':' '{print $2}' | sed 's/^ *//')
fi
fi
fi
fi
2016-07-03 17:13:34 +02:00
}
function configure_firewall_for_voip {
2016-09-25 12:20:41 +02:00
if grep -Fxq "configure_firewall_for_voip" $COMPLETION_FILE; then
return
fi
if [[ $ONION_ONLY != "no" ]]; then
return
fi
iptables -A INPUT -p udp --dport $VOIP_PORT -j ACCEPT
iptables -A INPUT -p tcp --dport $VOIP_PORT -j ACCEPT
function_check save_firewall_settings
save_firewall_settings
2016-09-25 12:20:41 +02:00
OPEN_PORTS+=("Mumble $VOIP_PORT")
echo 'configure_firewall_for_voip' >> $COMPLETION_FILE
}
2016-07-03 17:13:34 +02:00
function install_mumble {
2016-09-25 12:20:41 +02:00
apt-get -y install mumble-server
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
function_check get_voip_server_password
get_voip_server_password
if [ ! $VOIP_SERVER_PASSWORD ]; then
if [ -f $IMAGE_PASSWORD_FILE ]; then
VOIP_SERVER_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
else
VOIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
if [ ${#VOIP_SERVER_PASSWORD} -lt $MINIMUM_PASSWORD_LENGTH ]; then
VOIP_SERVER_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
fi
fi
fi
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
# Make an ssl cert for the server
if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
${PROJECT_NAME}-addcert -h mumble --dhkey $DH_KEYLENGTH
function_check check_certificates
check_certificates mumble
fi
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
# Check that the cert was created
if [ ! -f /etc/ssl/certs/mumble.crt ]; then
echo $'VoIP server certificate not created'
exit 57892
fi
if [ ! -f /etc/ssl/private/mumble.key ]; then
echo $'VoIP server key not created'
exit 57893
fi
if [ ! -d /var/lib/mumble-server ]; then
mkdir /var/lib/mumble-server
fi
cp /etc/ssl/certs/mumble.* /var/lib/mumble-server
cp /etc/ssl/private/mumble.key /var/lib/mumble-server
chown -R mumble-server:mumble-server /var/lib/mumble-server
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
sed -i "s|welcometext=.*|welcometext=\"<br />Welcome to $DEFAULT_DOMAIN_NAME <b>VoIP</b>.<br />Chat freely!<br />\"|g" /etc/mumble-server.ini
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
if [[ $VOIP_SERVER_PASSWORD && $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then
sed -i "s|serverpassword=.*|serverpassword=$VOIP_SERVER_PASSWORD|g" /etc/mumble-server.ini
fi
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
sed -i 's|#autobanAttempts.*|autobanAttempts = 10|g' /etc/mumble-server.ini
sed -i 's|#autobanTimeframe.*|autobanTimeframe = 120|g' /etc/mumble-server.ini
sed -i 's|#autobanTime.*|autobanTime = 300|g' /etc/mumble-server.ini
sed -i 's|#sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
sed -i 's|sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
if ! grep -q "allowping" /etc/mumble-server.ini; then
echo 'allowping=False' >> /etc/mumble-server.ini
fi
sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.crt|g' /etc/mumble-server.ini
sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
sed -i 's|#certrequired=.*|certrequired=True|g' /etc/mumble-server.ini
sed -i 's|users=100|users=10|g' /etc/mumble-server.ini
sed -i 's|#channelnestinglimit=10|channelnestinglimit=10|g' /etc/mumble-server.ini
sed -i 's|#textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
sed -i 's|textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
sed -i 's|#imagemessagelength=.*|imagemessagelength=131072|g' /etc/mumble-server.ini
sed -i 's|#allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
sed -i "s|port=.*|port=${VOIP_PORT}|g" /etc/mumble-server.ini
2016-07-03 17:13:34 +02:00
VOIP_ONION_HOSTNAME=$(add_onion_service mumble ${VOIP_PORT} ${VOIP_PORT})
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
systemctl restart mumble-server
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
if ! grep -q $"Mumble Server" /home/$MY_USERNAME/README; then
echo '' >> /home/$MY_USERNAME/README
echo '' >> /home/$MY_USERNAME/README
echo $'Mumble Server' >> /home/$MY_USERNAME/README
echo '=============' >> /home/$MY_USERNAME/README
echo $"Mumble onion domain:$VOIP_ONION_HOSTNAME" >> /home/$MY_USERNAME/README
echo $'Mumble server username: mumble-server' >> /home/$MY_USERNAME/README
if [[ $SYSTEM_TYPE != "VARIANT_MESH" ]]; then
echo $"Mumble server password: $VOIP_SERVER_PASSWORD" >> /home/$MY_USERNAME/README
fi
echo '' >> /home/$MY_USERNAME/README
echo $'To connect to the Mumble server use your username and the server password shown above.' >> /home/$MY_USERNAME/README
chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
chmod 600 /home/$MY_USERNAME/README
fi
2016-07-03 17:13:34 +02:00
2016-09-25 12:20:41 +02:00
function_check configure_firewall_for_voip
configure_firewall_for_voip
2016-07-03 17:13:34 +02:00
}
# NOTE: deliberately no exit 0