freedombone-app-mumble 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Mumble application
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. VARIANTS='full full-vim chat'
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=1
  31. # Password used for mumble server
  32. MUMBLE_SERVER_PASSWORD=
  33. # Port on which mumble server listens
  34. MUMBLE_PORT=64738
  35. # Location of mumble database and configuration
  36. MUMBLE_DATABASE="mumble-server.sqlite"
  37. MUMBLE_CONFIG_FILE="mumble-server.ini"
  38. MUMBLE_SHORT_DESCRIPTION=$'Mumble'
  39. MUMBLE_DESCRIPTION=$'Mumble'
  40. MUMBLE_ICON_URL=
  41. MUMBLE_MOBILE_APP_URL='https://f-droid.org/packages/com.morlunk.mumbleclient'
  42. mumble_variables=(MY_USERNAME
  43. DEFAULT_DOMAIN_NAME
  44. MUMBLE_PORT
  45. ONION_ONLY
  46. ADMIN_USERNAME)
  47. function logging_on_mumble {
  48. if [ -f /etc/mumble-server.ini ]; then
  49. sed -i 's|logfile=.*|logfile=/var/log/mumble-server.log|g' /etc/mumble-server.ini
  50. fi
  51. }
  52. function logging_off_mumble {
  53. if [ -f /etc/mumble-server.ini ]; then
  54. sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
  55. if [ -d /var/log/mumble-server ]; then
  56. $REMOVE_FILES_COMMAND /var/log/mumble-server/*
  57. rm -rf /var/log/mumble-server
  58. fi
  59. fi
  60. }
  61. function install_interactive_mumble {
  62. echo -n ''
  63. APP_INSTALLED=1
  64. }
  65. function change_password_mumble {
  66. new_mumble_password="$2"
  67. set_password_for_all_users mumble "$new_mumble_password"
  68. sed -i "s|serverpassword=.*|serverpassword=$new_mumble_password|g" /etc/mumble-server.ini
  69. systemctl restart mumble-server
  70. }
  71. function reconfigure_mumble {
  72. echo -n ''
  73. }
  74. function upgrade_mumble {
  75. if [ -d /etc/letsencrypt ]; then
  76. usermod -a -G ssl-cert mumble-server
  77. fi
  78. if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
  79. if ! grep -q "mumble.pem" /etc/mumble-server.ini; then
  80. sed -i 's|sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
  81. sed -i 's|sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
  82. systemctl restart mumble
  83. fi
  84. else
  85. if ! grep -q "${DEFAULT_DOMAIN_NAME}/fullchain.pem" /etc/mumble-server.ini; then
  86. usermod -a -G ssl-cert mumble-server
  87. sed -i "s|sslCert=.*|sslCert=/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem|g" /etc/mumble-server.ini
  88. sed -i "s|sslKey=.*|sslKey=/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/privkey.pem|g" /etc/mumble-server.ini
  89. systemctl restart mumble
  90. fi
  91. fi
  92. }
  93. function backup_local_mumble {
  94. if [ -f /etc/mumble-server.ini ]; then
  95. echo $"Backing up Mumble settings"
  96. temp_backup_dir=/root/tempmumblebackup
  97. if [ ! -d $temp_backup_dir ]; then
  98. mkdir -p $temp_backup_dir
  99. fi
  100. cp -f /etc/mumble-server.ini $temp_backup_dir
  101. cp -f /var/lib/mumble-server/mumble-server.sqlite $temp_backup_dir
  102. backup_directory_to_usb $temp_backup_dir mumble
  103. echo $"Mumble settings backup complete"
  104. fi
  105. }
  106. function restore_local_mumble {
  107. if [ -d "$USB_MOUNT/backup/mumble" ]; then
  108. echo $"Restoring mumble settings"
  109. temp_restore_dir=/root/tempmumble
  110. function_check restore_directory_from_usb
  111. restore_directory_from_usb $temp_restore_dir voip
  112. restore_directory_from_usb $temp_restore_dir mumble
  113. if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
  114. cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini" /etc/
  115. else
  116. cp -f $temp_restore_dir/mumble-server.ini /etc/
  117. fi
  118. # shellcheck disable=SC2181
  119. if [ ! "$?" = "0" ]; then
  120. rm -rf $temp_restore_dir
  121. function_check set_user_permissions
  122. set_user_permissions
  123. function_check backup_unmount_drive
  124. backup_unmount_drive
  125. exit 3679
  126. fi
  127. if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
  128. cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite" /var/lib/mumble-server/
  129. else
  130. cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
  131. fi
  132. # shellcheck disable=SC2181
  133. if [ ! "$?" = "0" ]; then
  134. rm -rf $temp_restore_dir
  135. function_check set_user_permissions
  136. set_user_permissions
  137. function_check backup_unmount_drive
  138. backup_unmount_drive
  139. exit 276
  140. fi
  141. rm -rf $temp_restore_dir
  142. cp /etc/ssl/certs/mumble* /var/lib/mumble-server
  143. cp /etc/ssl/private/mumble* /var/lib/mumble-server
  144. chown -R mumble-server:mumble-server /var/lib/mumble-server
  145. systemctl restart mumble-server
  146. fi
  147. }
  148. function backup_remote_mumble {
  149. if [ -f /etc/mumble-server.ini ]; then
  150. echo $"Backing up mumble settings"
  151. if [ ! -d /root/tempmumblebackup ]; then
  152. mkdir -p /root/tempmumblebackup
  153. fi
  154. cp -f /etc/mumble-server.ini /root/tempmumblebackup
  155. cp -f /var/lib/mumble-server/mumble-server.sqlite /root/tempmumblebackup
  156. backup_directory_to_friend /root/tempmumblebackup mumble
  157. echo $"Backup of mumble settings complete"
  158. fi
  159. }
  160. function restore_remote_mumble {
  161. if [ -d "$SERVER_DIRECTORY/backup/mumble" ]; then
  162. echo $"Restoring Mumble settings"
  163. temp_restore_dir=/root/tempmumble
  164. function_check restore_directory_from_friend
  165. restore_directory_from_friend $temp_restore_dir mumble
  166. if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
  167. cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.ini" /etc/
  168. else
  169. cp -f $temp_restore_dir/mumble-server.ini /etc/
  170. fi
  171. # shellcheck disable=SC2181
  172. if [ ! "$?" = "0" ]; then
  173. rm -rf $temp_restore_dir
  174. exit 7823
  175. fi
  176. if [ -d "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup" ]; then
  177. cp -f "$temp_restore_dir/home/$ADMIN_USERNAME/tempbackup/mumble-server.sqlite" /var/lib/mumble-server/
  178. else
  179. cp -f $temp_restore_dir/mumble-server.sqlite /var/lib/mumble-server/
  180. fi
  181. # shellcheck disable=SC2181
  182. if [ ! "$?" = "0" ]; then
  183. rm -rf $temp_restore_dir
  184. exit 276
  185. fi
  186. rm -rf $temp_restore_dir
  187. cp /etc/ssl/certs/mumble* /var/lib/mumble-server
  188. cp /etc/ssl/private/mumble* /var/lib/mumble-server
  189. chown -R mumble-server:mumble-server /var/lib/mumble-server
  190. systemctl restart mumble-server
  191. echo $"Restore of Mumble complete"
  192. fi
  193. }
  194. function remove_mumble {
  195. apt-get -yq remove --purge mumble-server
  196. if [[ $ONION_ONLY == "no" ]]; then
  197. firewall_remove ${MUMBLE_PORT}
  198. fi
  199. if [ -f /etc/mumble-server.ini ]; then
  200. rm /etc/mumble-server.ini
  201. fi
  202. remove_certs mumble
  203. if [ -d /var/lib/mumble-server ]; then
  204. rm -rf /var/lib/mumble-server
  205. fi
  206. function_check remove_onion_service
  207. remove_onion_service mumble ${MUMBLE_PORT}
  208. sed -i '/mumble/d' "$COMPLETION_FILE"
  209. }
  210. function configure_firewall_for_mumble {
  211. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  212. return
  213. fi
  214. if [[ $ONION_ONLY != "no" ]]; then
  215. return
  216. fi
  217. firewall_add Mumble ${MUMBLE_PORT}
  218. mark_completed "${FUNCNAME[0]}"
  219. }
  220. function install_mumble {
  221. apt-get -yq install mumble-server
  222. if [ -f "$IMAGE_PASSWORD_FILE" ]; then
  223. MUMBLE_SERVER_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
  224. else
  225. if [ ! "$MUMBLE_SERVER_PASSWORD" ]; then
  226. MUMBLE_SERVER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  227. if [ ${#MUMBLE_SERVER_PASSWORD} -lt "$MINIMUM_PASSWORD_LENGTH" ]; then
  228. MUMBLE_SERVER_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  229. fi
  230. fi
  231. fi
  232. if [[ ${ONION_ONLY} == 'no' ]]; then
  233. if [ ! -d "/var/www/${DEFAULT_DOMAIN_NAME}/htdocs" ]; then
  234. mkdir "/var/www/${DEFAULT_DOMAIN_NAME}/htdocs"
  235. fi
  236. if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
  237. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
  238. rm "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt"
  239. fi
  240. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam" ]; then
  241. rm "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam"
  242. fi
  243. echo $'Obtaining certificate for the main domain'
  244. function_check create_site_certificate
  245. create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
  246. chmod 755 "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam"
  247. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.crt" ]; then
  248. echo $'Incorrect certificate generated'
  249. exit 78352
  250. fi
  251. fi
  252. chgrp -R ssl-cert /etc/letsencrypt
  253. chmod -R g=rX /etc/letsencrypt
  254. fi
  255. # Make an ssl cert for the server
  256. if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
  257. if [ ! -f /etc/ssl/certs/mumble.dhparam ]; then
  258. "${PROJECT_NAME}-addcert" -h mumble --dhkey "$DH_KEYLENGTH"
  259. function_check check_certificates
  260. check_certificates mumble
  261. fi
  262. fi
  263. # Check that the cert was created
  264. if [ ! -f /etc/ssl/certs/mumble.crt ]; then
  265. echo $'mumble server certificate not created'
  266. exit 57892
  267. fi
  268. if [ ! -f /etc/ssl/private/mumble.key ]; then
  269. echo $'mumble server key not created'
  270. exit 57893
  271. fi
  272. if [ ! -d /var/lib/mumble-server ]; then
  273. mkdir /var/lib/mumble-server
  274. fi
  275. cp /etc/ssl/certs/mumble.* /var/lib/mumble-server
  276. cp /etc/ssl/private/mumble.key /var/lib/mumble-server
  277. if [ ! -f /var/lib/mumble-server/mumble.pem ]; then
  278. mv /var/lib/mumble-server/mumble.crt /var/lib/mumble-server/mumble.pem
  279. fi
  280. chown -R mumble-server:mumble-server /var/lib/mumble-server
  281. sed -i "s|welcometext=.*|welcometext=\"<br />Welcome to $DEFAULT_DOMAIN_NAME <b>mumble</b>.<br />Chat freely!<br />\"|g" /etc/mumble-server.ini
  282. if [[ $MUMBLE_SERVER_PASSWORD ]]; then
  283. sed -i "s|serverpassword=.*|serverpassword=$MUMBLE_SERVER_PASSWORD|g" /etc/mumble-server.ini
  284. fi
  285. sed -i 's|#autobanAttempts.*|autobanAttempts = 10|g' /etc/mumble-server.ini
  286. sed -i 's|#autobanTimeframe.*|autobanTimeframe = 120|g' /etc/mumble-server.ini
  287. sed -i 's|#autobanTime.*|autobanTime = 300|g' /etc/mumble-server.ini
  288. sed -i 's|#sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
  289. sed -i 's|sendversion=.*|sendversion=False|g' /etc/mumble-server.ini
  290. if ! grep -q "allowping" /etc/mumble-server.ini; then
  291. echo 'allowping=False' >> /etc/mumble-server.ini
  292. fi
  293. sed -i 's|allowping=.*|allowping=False|g' /etc/mumble-server.ini
  294. if [ ! -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
  295. sed -i 's|#sslCert=.*|sslCert=/var/lib/mumble-server/mumble.pem|g' /etc/mumble-server.ini
  296. sed -i 's|#sslKey=.*|sslKey=/var/lib/mumble-server/mumble.key|g' /etc/mumble-server.ini
  297. else
  298. sed -i "s|#sslCert=.*|sslCert=/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem|g" /etc/mumble-server.ini
  299. sed -i "s|#sslKey=.*|sslKey=/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/privkey.pem|g" /etc/mumble-server.ini
  300. fi
  301. sed -i 's|#certrequired=.*|certrequired=True|g' /etc/mumble-server.ini
  302. sed -i 's|users=100|users=10|g' /etc/mumble-server.ini
  303. sed -i 's|#channelnestinglimit=10|channelnestinglimit=10|g' /etc/mumble-server.ini
  304. sed -i 's|#textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
  305. sed -i 's|textmessagelength=.*|textmessagelength=1000|g' /etc/mumble-server.ini
  306. sed -i 's|#imagemessagelength=.*|imagemessagelength=131072|g' /etc/mumble-server.ini
  307. sed -i 's|#allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
  308. sed -i 's|allowhtml=.*|allowhtml=False|g' /etc/mumble-server.ini
  309. sed -i "s|port=.*|port=${MUMBLE_PORT}|g" /etc/mumble-server.ini
  310. #MUMBLE_ONION_HOSTNAME=$(add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT})
  311. add_onion_service mumble ${MUMBLE_PORT} ${MUMBLE_PORT}
  312. # turn off logs by default
  313. sed -i 's|logfile=.*|logfile=/dev/null|g' /etc/mumble-server.ini
  314. if [ -d /etc/letsencrypt ]; then
  315. usermod -a -G ssl-cert mumble-server
  316. fi
  317. update_default_domain
  318. systemctl restart mumble-server
  319. set_password_for_all_users mumble "$MUMBLE_SERVER_PASSWORD"
  320. function_check configure_firewall_for_mumble
  321. configure_firewall_for_mumble
  322. APP_INSTALLED=1
  323. }
  324. # NOTE: deliberately no exit 0