freedombone-app-xmpp 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # XMPP functions
  12. #
  13. # License
  14. # =======
  15. #
  16. # Copyright (C) 2014-2016 Bob Mottram <bob@robotics.uk.to>
  17. #
  18. # This program is free software: you can redistribute it and/or modify
  19. # it under the terms of the GNU Affero General Public License as published by
  20. # the Free Software Foundation, either version 3 of the License, or
  21. # (at your option) any later version.
  22. #
  23. # This program is distributed in the hope that it will be useful,
  24. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. # GNU Affero General Public License for more details.
  27. #
  28. # You should have received a copy of the GNU Affero General Public License
  29. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  30. VARIANTS='full chat'
  31. # Directory where XMPP settings are stored
  32. XMPP_DIRECTORY="/var/lib/prosody"
  33. XMPP_PASSWORD=
  34. XMPP_CIPHERS='"EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA256:EECDH:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!IDEA:!ECDSA:kEDH:CAMELLIA128-SHA:AES128-SHA"'
  35. XMPP_ECC_CURVE='"secp384r1"'
  36. function run_client_xmpp {
  37. torify profanity
  38. }
  39. function install_interactive_xmpp {
  40. echo -n ''
  41. }
  42. function change_password_xmpp {
  43. echo -n ''
  44. }
  45. function reconfigure_xmpp {
  46. echo -n ''
  47. }
  48. function update_prosody_modules {
  49. if [ ! -d $INSTALL_DIR/prosody-modules ]; then
  50. return
  51. fi
  52. if [ ! -d /usr/lib/prosody ]; then
  53. return
  54. fi
  55. cd $INSTALL_DIR/prosody-modules
  56. hg pull
  57. hg update
  58. # support onion addresses
  59. if [ -f $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua ]; then
  60. cp $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua /usr/lib/prosody/modules/mod_onions.lua
  61. fi
  62. # XEP-0313 message archive management
  63. # https://modules.prosody.im/mod_mam.html
  64. # Allows you to download your previous messages onto a new client
  65. # This only applies if you are not using forward secret crypto
  66. # such as OTR or OMEMO (eg. OpenPGP)
  67. if [ -d $INSTALL_DIR/prosody-modules/mod_mam ]; then
  68. cp $INSTALL_DIR/prosody-modules/mod_mam/*.lua /usr/lib/prosody/modules
  69. fi
  70. # XEP-0352 Client State Indication
  71. # Notifies the server if the app is in the background or not
  72. if [ -d $INSTALL_DIR/prosody-modules/mod_csi ]; then
  73. cp $INSTALL_DIR/prosody-modules/mod_csi/*.lua /usr/lib/prosody/modules
  74. fi
  75. # XEP-0280 Message Carbons
  76. # Ensures all messages get delivered to all clients (if you have a mobile and desktop client)
  77. if [ -d $INSTALL_DIR/prosody-modules/mod_carbons ]; then
  78. cp $INSTALL_DIR/prosody-modules/mod_carbons/*.lua /usr/lib/prosody/modules
  79. fi
  80. # XEP-0198 Stream management
  81. # Helps mobile apps recover when a device switches networks.
  82. if [ -d $INSTALL_DIR/prosody-modules/mod_smacks ]; then
  83. cp $INSTALL_DIR/prosody-modules/mod_smacks/*.lua /usr/lib/prosody/modules
  84. fi
  85. if [ -d $INSTALL_DIR/prosody-modules/mod_smacks_offline ]; then
  86. cp $INSTALL_DIR/prosody-modules/mod_smacks_offline/*.lua /usr/lib/prosody/modules
  87. fi
  88. # XEP-0191: blocking
  89. if [ -d $INSTALL_DIR/prosody-modules/mod_blocking ]; then
  90. cp $INSTALL_DIR/prosody-modules/mod_blocking/*.lua /usr/lib/prosody/modules
  91. fi
  92. # XEP-0016 Privacy lists
  93. if [ -d $INSTALL_DIR/prosody-modules/mod_privacy_lists ]; then
  94. cp $INSTALL_DIR/prosody-modules/mod_privacy_lists/*.lua /usr/lib/prosody/modules
  95. fi
  96. # If offline then send messages to email
  97. if [ -d $INSTALL_DIR/prosody-modules/mod_offline_email ]; then
  98. cp $INSTALL_DIR/prosody-modules/mod_offline_email/*.lua /usr/lib/prosody/modules
  99. fi
  100. }
  101. function upgrade_xmpp {
  102. if ! grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
  103. return
  104. fi
  105. function_check update_prosody_modules
  106. update_prosody_modules
  107. }
  108. function backup_local_xmpp {
  109. source_directory=/var/lib/prosody xmpp
  110. if [ -d $source_directory ]; then
  111. dest_directory=xmpp
  112. echo $"Backing up $source_directory to $dest_directory"
  113. function_check backup_directory_to_usb
  114. backup_directory_to_usb $source_directory $dest_directory
  115. echo $"Backup to $dest_directory complete"
  116. fi
  117. }
  118. function restore_local_xmpp {
  119. if [ -d /var/lib/prosody ]; then
  120. echo $"Restoring XMPP settings"
  121. temp_restore_dir=/root/tempxmpp
  122. function_check restore_directory_from_usb
  123. restore_directory_from_usb $temp_restore_dir xmpp
  124. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  125. if [ ! "$?" = "0" ]; then
  126. function_check set_user_permissions
  127. set_user_permissions
  128. function_check backup_unmount_drive
  129. backup_unmount_drive
  130. exit 725
  131. fi
  132. rm -rf $temp_restore_dir
  133. service prosody restart
  134. chown -R prosody:prosody /var/lib/prosody/*
  135. echo $"Restore of XMPP settings complete"
  136. fi
  137. }
  138. function backup_remote_xmpp {
  139. if [ -d /var/lib/prosody ]; then
  140. echo $"Backing up the XMPP settings"
  141. backup_directory_to_friend /var/lib/prosody xmpp
  142. echo $"Backup of XMPP settings complete"
  143. fi
  144. }
  145. function restore_remote_xmpp {
  146. if [ -d /var/lib/prosody ]; then
  147. echo $"Restoring XMPP settings"
  148. temp_restore_dir=/root/tempxmpp
  149. function_check restore_directory_from_friend
  150. restore_directory_from_friend $temp_restore_dir xmpp
  151. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  152. if [ ! "$?" = "0" ]; then
  153. exit 725
  154. fi
  155. rm -rf $temp_restore_dir
  156. service prosody restart
  157. chown -R prosody:prosody /var/lib/prosody/*
  158. echo $"Restore of XMPP settings complete"
  159. fi
  160. }
  161. function configure_firewall_for_xmpp {
  162. if [ ! -d /etc/prosody ]; then
  163. return
  164. fi
  165. if grep -Fxq "configure_firewall_for_xmpp" $COMPLETION_FILE; then
  166. return
  167. fi
  168. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  169. # docker does its own firewalling
  170. return
  171. fi
  172. if [[ $ONION_ONLY != "no" ]]; then
  173. return
  174. fi
  175. iptables -A INPUT -p tcp --dport 5222:5223 -j ACCEPT
  176. iptables -A INPUT -p tcp --dport 5269 -j ACCEPT
  177. iptables -A INPUT -p tcp --dport 5280:5281 -j ACCEPT
  178. function_check save_firewall_settings
  179. save_firewall_settings
  180. OPEN_PORTS+=('XMPP 5222-5223')
  181. OPEN_PORTS+=('XMPP 5269')
  182. OPEN_PORTS+=('XMPP 5280-5281')
  183. echo 'configure_firewall_for_xmpp' >> $COMPLETION_FILE
  184. }
  185. function remove_xmpp_client {
  186. if [[ $(app_is_installed xmpp_client) == "0" ]]; then
  187. return
  188. fi
  189. apt-get -y remove --purge profanity
  190. sed '/install_xmpp_client/d' $COMPLETION_FILE
  191. }
  192. function remove_xmpp {
  193. remove_xmpp_client
  194. if [[ $(app_is_installed xmpp) == "0" ]]; then
  195. return
  196. fi
  197. iptables -D INPUT -p tcp --dport 5222:5223 -j ACCEPT
  198. iptables -D INPUT -p tcp --dport 5269 -j ACCEPT
  199. iptables -D INPUT -p tcp --dport 5280:5281 -j ACCEPT
  200. function_check save_firewall_settings
  201. save_firewall_settings
  202. function_check remove_onion_service
  203. remove_onion_service xmpp 5222 5223 5269
  204. apt-get -y remove --purge prosody prosody-modules
  205. if [ -d $INSTALL_DIR/prosody-modules ]; then
  206. rm -rf $INSTALL_DIR/prosody-modules
  207. fi
  208. if [ -d /etc/prosody ]; then
  209. rm -rf /etc/prosody
  210. fi
  211. sed '/install_xmpp/d' $COMPLETION_FILE
  212. sed '/XMPP /d' $COMPLETION_FILE
  213. }
  214. function xmpp_email_headers {
  215. for d in /home/*/ ; do
  216. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  217. if [[ $(is_valid_user $USERNAME) == "1" ]]; then
  218. if [ -f /home/$USERNAME/.muttrc ]; then
  219. if ! grep -q "Jabber-ID" /home/$USERNAME/.muttrc; then
  220. echo "my_hdr Jabber-ID: ${USERNAME}@${HOSTNAME}" >> /home/$USERNAME/.muttrc
  221. fi
  222. fi
  223. fi
  224. done
  225. }
  226. function install_xmpp_main {
  227. update_prosody_modules
  228. if grep -Fxq "install_xmpp_main" $COMPLETION_FILE; then
  229. return
  230. fi
  231. apt-get -y install lua-sec lua-bitop
  232. apt-get -y install prosody prosody-modules mercurial
  233. if [ ! -d /etc/prosody ]; then
  234. echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
  235. exit 52
  236. fi
  237. # obtain the prosody modules
  238. cd $INSTALL_DIR
  239. hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
  240. if [ ! -d $INSTALL_DIR/prosody-modules/mod_onions ]; then
  241. echo $'mod_onions prosody module could not be found'
  242. exit 73254
  243. fi
  244. # install the onions module
  245. update_prosody_modules
  246. if [ ! -f /usr/lib/prosody/modules/mod_onions.lua ]; then
  247. echo $'mod_onions.lua could not be copied to the prosody modules directory'
  248. exit 63952
  249. fi
  250. # create a certificate
  251. if [ ! -f /etc/ssl/certs/xmpp.dhparam ]; then
  252. ${PROJECT_NAME}-addcert -h xmpp --dhkey $DH_KEYLENGTH
  253. check_certificates xmpp
  254. fi
  255. chown prosody:prosody /etc/ssl/private/xmpp.key
  256. chown prosody:prosody /etc/ssl/certs/xmpp.*
  257. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  258. sed -i 's|/etc/prosody/certs/example.com.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  259. sed -i 's|/etc/prosody/certs/example.com.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  260. if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  261. sed -i '/certificate =/a\ dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
  262. fi
  263. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  264. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
  265. fi
  266. if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  267. sed -i "/certificate =/a\ ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
  268. fi
  269. if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  270. sed -i '/certificate =/a\ depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
  271. fi
  272. if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  273. sed -i "/certificate =/a\ curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
  274. fi
  275. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
  276. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
  277. if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  278. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  279. echo 'modules_enabled = {' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  280. echo ' "bosh"; -- Enable mod_bosh' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  281. echo ' "tls"; -- Enable mod_tls' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  282. echo ' "saslauth"; -- Enable mod_saslauth' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  283. echo ' "onions"; -- Enable chat via onion service' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  284. echo ' "mam"; -- Message archive management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  285. echo ' "csi"; -- Client state indication' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  286. echo ' "carbons"; -- Message carbons' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  287. echo ' "smacks"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  288. echo ' "smacks_offline"; -- Stream management' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  289. echo ' "pep"; -- Personal Eventing Protocol (to support OMEMO)' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  290. echo ' "privacy"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  291. echo ' "privacy_lists"; -- Privacy lists' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  292. echo ' "blocking"; -- Blocking command' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  293. echo ' "roster"; -- Roster versioning' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  294. echo ' "offline_email"; -- If offline send to email' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  295. echo '}' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  296. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  297. echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  298. echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  299. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  300. fi
  301. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  302. sed -i 's|/etc/prosody/certs/localhost.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/prosody.cfg.lua
  303. sed -i 's|/etc/prosody/certs/localhost.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
  304. if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
  305. sed -i '/certificate =/a\ dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
  306. fi
  307. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/prosody.cfg.lua; then
  308. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/prosody.cfg.lua
  309. fi
  310. if ! grep -q 'ciphers =' /etc/prosody/prosody.cfg.lua; then
  311. sed -i "/certificate =/a\ ciphers = $XMPP_CIPHERS;" /etc/prosody/prosody.cfg.lua
  312. fi
  313. if ! grep -q 'depth = "1";' /etc/prosody/prosody.cfg.lua; then
  314. sed -i '/certificate =/a\ depth = "1";' /etc/prosody/prosody.cfg.lua
  315. fi
  316. if ! grep -q 'curve =' /etc/prosody/prosody.cfg.lua; then
  317. sed -i "/certificate =/a\ curve = $XMPP_ECC_CURVE;" /etc/prosody/prosody.cfg.lua
  318. fi
  319. sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
  320. if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
  321. sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
  322. fi
  323. if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/prosody.cfg.lua; then
  324. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  325. fi
  326. sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
  327. sed -i 's/authentication = "internal_plain"/authentication = "internal_hashed"/g' /etc/prosody/prosody.cfg.lua
  328. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/prosody.cfg.lua
  329. sed -i 's|key = "/etc/prosody/certs/example.com.key"|key = "/etc/ssl/private/xmpp.key"|g' /etc/prosody/prosody.cfg.lua
  330. sed -i 's|certificate = "/etc/prosody/certs/example.com.crt"|certificate = "/etc/ssl/certs/xmpp.crt"|g' /etc/prosody/prosody.cfg.lua
  331. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/prosody.cfg.lua
  332. systemctl restart prosody
  333. touch /home/$MY_USERNAME/README
  334. if [ ! -d /var/lib/tor ]; then
  335. echo $'No Tor installation found. XMPP onion site cannot be configured.'
  336. exit 877367
  337. fi
  338. if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
  339. echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
  340. echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
  341. echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
  342. echo $'Added onion site for XMPP chat'
  343. fi
  344. systemctl restart tor
  345. wait_for_onion_service 'xmpp'
  346. if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  347. echo $'XMPP onion site hostname not found'
  348. exit 65349
  349. fi
  350. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  351. if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  352. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  353. echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
  354. echo ' modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  355. fi
  356. if ! grep -q "XMPP onion domain" $COMPLETION_FILE; then
  357. echo "XMPP onion domain:${XMPP_ONION_HOSTNAME}" >> $COMPLETION_FILE
  358. else
  359. sed -i "s|XMPP onion domain.*|XMPP onion domain:${XMPP_ONION_HOSTNAME}|g" $COMPLETION_FILE
  360. fi
  361. if ! grep -q "Your XMPP password is" /home/$MY_USERNAME/README; then
  362. if [ ${#XMPP_PASSWORD} -lt 8 ]; then
  363. if [ -f $IMAGE_PASSWORD_FILE ]; then
  364. XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  365. else
  366. XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  367. fi
  368. fi
  369. prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME $XMPP_PASSWORD
  370. echo '' >> /home/$MY_USERNAME/README
  371. echo '' >> /home/$MY_USERNAME/README
  372. echo $'XMPP' >> /home/$MY_USERNAME/README
  373. echo '====' >> /home/$MY_USERNAME/README
  374. echo $"XMPP onion domain: ${XMPP_ONION_HOSTNAME}" >> /home/$MY_USERNAME/README
  375. echo $"Your XMPP password is: $XMPP_PASSWORD" >> /home/$MY_USERNAME/README
  376. echo $'You can change it with: ' >> /home/$MY_USERNAME/README
  377. echo '' >> /home/$MY_USERNAME/README
  378. echo " prosodyctl passwd $MY_EMAIL_ADDRESS" >> /home/$MY_USERNAME/README
  379. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/README
  380. chmod 600 /home/$MY_USERNAME/README
  381. fi
  382. function_check configure_firewall_for_xmpp
  383. configure_firewall_for_xmpp
  384. xmpp_email_headers
  385. echo 'install_xmpp_main' >> $COMPLETION_FILE
  386. }
  387. function install_xmpp_client {
  388. if grep -Fxq "install_xmpp_client" $COMPLETION_FILE; then
  389. return
  390. fi
  391. apt-get -y install profanity
  392. XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
  393. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  394. if [ ! -d $XMPP_CLIENT_DIR ]; then
  395. mkdir -p $XMPP_CLIENT_DIR
  396. fi
  397. if [[ $ONION_ONLY == 'no' ]]; then
  398. echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
  399. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  400. echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  401. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  402. echo "muc.service=conference.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  403. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  404. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  405. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  406. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  407. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  408. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  409. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  410. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  411. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  412. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  413. fi
  414. fi
  415. if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  416. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  417. echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
  418. if [[ $ONION_ONLY == 'no' ]]; then
  419. echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
  420. else
  421. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  422. fi
  423. echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  424. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  425. echo "muc.service=conference.${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  426. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  427. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  428. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  429. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  430. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  431. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  432. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  433. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  434. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  435. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  436. fi
  437. fi
  438. if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
  439. mkdir /home/$MY_USERNAME/.config/profanity
  440. fi
  441. echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
  442. echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
  443. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
  444. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  445. echo 'install_xmpp_client' >> $COMPLETION_FILE
  446. }
  447. function install_xmpp {
  448. if [[ $(app_is_installed xmpp) == "1" ]]; then
  449. return
  450. fi
  451. install_xmpp_main
  452. install_xmpp_client
  453. install_completed xmpp
  454. }
  455. # NOTE: deliberately no exit 0