From 047d66653119f41b2fc83ed78c27b7e441be2645 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 24 Jul 2016 11:04:47 +0100 Subject: [PATCH] Tidying --- src/freedombone-app-mumble | 416 ++++++++++++++++++------------------- 1 file changed, 208 insertions(+), 208 deletions(-) diff --git a/src/freedombone-app-mumble b/src/freedombone-app-mumble index 8134628a..34f43a76 100755 --- a/src/freedombone-app-mumble +++ b/src/freedombone-app-mumble @@ -40,254 +40,254 @@ VOIP_DATABASE="mumble-server.sqlite" VOIP_CONFIG_FILE="mumble-server.ini" function reconfigure_mumble { - echo -n '' + echo -n '' } function upgrade_mumble { - echo -n '' + echo -n '' } function backup_local_mumble { - 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" + 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 } function restore_local_mumble { - 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 + 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 } function backup_remote_mumble { - 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" + 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 { - 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" + 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 } function remove_mumble { - if !grep -Fxq "install_mumble" $COMPLETION_FILE; then - if ! grep -Fxq "install_voip" $COMPLETION_FILE; then - return - fi + if !grep -Fxq "install_mumble" $COMPLETION_FILE; then + if ! grep -Fxq "install_voip" $COMPLETION_FILE; then + return fi - apt-get -y remove --purge mumble-server - 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 - 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 + fi + apt-get -y remove --purge mumble-server + 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 + 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 } function get_voip_server_password { - 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 + 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 } function configure_firewall_for_voip { - 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 + 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 - OPEN_PORTS+=("Mumble $VOIP_PORT") - echo 'configure_firewall_for_voip' >> $COMPLETION_FILE + OPEN_PORTS+=("Mumble $VOIP_PORT") + echo 'configure_firewall_for_voip' >> $COMPLETION_FILE } function install_mumble { - if grep -Fxq "install_mumble" $COMPLETION_FILE; then - return - fi - if grep -Fxq "install_voip" $COMPLETION_FILE; then - return - fi - apt-get -y install mumble-server + if grep -Fxq "install_mumble" $COMPLETION_FILE; then + return + fi + if grep -Fxq "install_voip" $COMPLETION_FILE; then + return + fi + apt-get -y install mumble-server - 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 + 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 - # 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 + # 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 + + # 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 + + sed -i "s|welcometext=.*|welcometext=\"
Welcome to $DEFAULT_DOMAIN_NAME VoIP.
Chat freely!
\"|g" /etc/mumble-server.ini + + if [[ $VOIP_SERVER_PASSWORD && $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then + sed -i "s|serverpassword=.*|serverpassword=$VOIP_SERVER_PASSWORD|g" /etc/mumble-server.ini + fi + + 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 + + VOIP_ONION_HOSTNAME=$(add_onion_service voip ${VOIP_PORT} ${VOIP_PORT}) + if ! grep -q $"VoIP onion domain" $COMPLETION_FILE; then + echo "VoIP onion domain:$VOIP_ONION_HOSTNAME" >> $COMPLETION_FILE + fi + + systemctl restart mumble-server + + 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 - # 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 - - sed -i "s|welcometext=.*|welcometext=\"
Welcome to $DEFAULT_DOMAIN_NAME VoIP.
Chat freely!
\"|g" /etc/mumble-server.ini - - if [[ $VOIP_SERVER_PASSWORD && $SYSTEM_TYPE != "$VARIANT_MESH" ]]; then - sed -i "s|serverpassword=.*|serverpassword=$VOIP_SERVER_PASSWORD|g" /etc/mumble-server.ini - fi - - 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 - - VOIP_ONION_HOSTNAME=$(add_onion_service voip ${VOIP_PORT} ${VOIP_PORT}) - if ! grep -q $"VoIP onion domain" $COMPLETION_FILE; then - echo "VoIP onion domain:$VOIP_ONION_HOSTNAME" >> $COMPLETION_FILE - fi - - systemctl restart mumble-server - - 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 - - function_check configure_firewall_for_voip - configure_firewall_for_voip - echo 'install_mumble' >> $COMPLETION_FILE + function_check configure_firewall_for_voip + configure_firewall_for_voip + echo 'install_mumble' >> $COMPLETION_FILE } # NOTE: deliberately no exit 0