freedombone-app-xmpp 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  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@freedombone.net>
  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 full-vim chat'
  31. IN_DEFAULT_INSTALL=0
  32. SHOW_ON_ABOUT=1
  33. # Directory where XMPP settings are stored
  34. XMPP_DIRECTORY="/var/lib/prosody"
  35. XMPP_PASSWORD=
  36. 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"'
  37. XMPP_ECC_CURVE='"secp384r1"'
  38. xmpp_variables=(ONION_ONLY
  39. INSTALLED_WITHIN_DOCKER
  40. XMPP_CIPHERS
  41. XMPP_ECC_CURVE
  42. XMPP_ECC_CURVE
  43. MY_USERNAME
  44. DEFAULT_DOMAIN_NAME
  45. XMPP_DOMAIN_CODE)
  46. function remove_user_xmpp {
  47. remove_username="$1"
  48. ${PROJECT_NAME}-pass -u $remove_username --rmapp xmpp
  49. ${PROJECT_NAME}-rmxmpp -e "${remove_username}@$HOSTNAME"
  50. }
  51. function add_user_xmpp {
  52. new_username="$1"
  53. new_user_password="$2"
  54. ${PROJECT_NAME}-pass -u $new_username -a xmpp -p "$new_user_password"
  55. ${PROJECT_NAME}-addxmpp -e "$new_username@$HOSTNAME" -p "$new_user_password"
  56. if [ ! "$?" = "0" ]; then
  57. echo '1'
  58. return
  59. fi
  60. XMPP_CLIENT_DIR=/home/$new_username/.local/share/profanity
  61. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  62. if [ ! -d $XMPP_CLIENT_DIR ]; then
  63. mkdir -p $XMPP_CLIENT_DIR
  64. fi
  65. if [ ! -d /home/$new_username/.config/profanity ]; then
  66. mkdir -p /home/$new_username/.config/profanity
  67. fi
  68. echo "[${new_username}@${HOSTNAME}]" > $XMPP_CLIENT_ACCOUNTS
  69. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  70. echo "jid=${new_username}@${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  71. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  72. echo "muc.service=conference.${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  73. echo "muc.nick=${new_username}" >> $XMPP_CLIENT_ACCOUNTS
  74. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  75. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  76. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  77. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  78. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  79. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  80. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  81. echo '[connection]' > /home/$new_username/.config/profanity/profrc
  82. echo "account=${new_username}@${HOSTNAME}" >> /home/$new_username/.config/profanity/profrc
  83. chown -R $new_username:$new_username /home/$new_username/.local
  84. chown -R $new_username:$new_username /home/$new_username/.config
  85. echo '0'
  86. }
  87. function run_client_xmpp {
  88. torify profanity
  89. }
  90. function install_interactive_xmpp {
  91. echo -n ''
  92. APP_INSTALLED=1
  93. }
  94. function change_password_xmpp {
  95. curr_username="$1"
  96. new_user_password="$2"
  97. read_config_param DEFAULT_DOMAIN_NAME
  98. ${PROJECT_NAME}-pass -u $curr_username -a xmpp -p "$new_user_password"
  99. # TODO: this is currently interactive. Really there needs to be a
  100. # non-interactive password change option for prosodyctl
  101. clear
  102. echo ''
  103. echo $'Currently Prosody requires password changes to be done interactively'
  104. prosodyctl passwd ${curr_username}@${DEFAULT_DOMAIN_NAME}
  105. }
  106. function reconfigure_xmpp {
  107. echo -n ''
  108. }
  109. function update_prosody_modules {
  110. if [ ! -d $INSTALL_DIR/prosody-modules ]; then
  111. return
  112. fi
  113. if [ ! -d /usr/lib/prosody ]; then
  114. return
  115. fi
  116. cd $INSTALL_DIR/prosody-modules
  117. hg pull
  118. hg update
  119. # support onion addresses
  120. if [ -f $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua ]; then
  121. cp $INSTALL_DIR/prosody-modules/mod_onions/mod_onions.lua /usr/lib/prosody/modules/mod_onions.lua
  122. fi
  123. # XEP-0313 message archive management
  124. # https://modules.prosody.im/mod_mam.html
  125. # Allows you to download your previous messages onto a new client
  126. # This only applies if you are not using forward secret crypto
  127. # such as OTR or OMEMO (eg. OpenPGP)
  128. if [ -d $INSTALL_DIR/prosody-modules/mod_mam ]; then
  129. cp $INSTALL_DIR/prosody-modules/mod_mam/*.lua /usr/lib/prosody/modules
  130. fi
  131. # XEP-0352 Client State Indication
  132. # Notifies the server if the app is in the background or not
  133. if [ -d $INSTALL_DIR/prosody-modules/mod_csi ]; then
  134. cp $INSTALL_DIR/prosody-modules/mod_csi/*.lua /usr/lib/prosody/modules
  135. fi
  136. # XEP-0280 Message Carbons
  137. # Ensures all messages get delivered to all clients (if you have a mobile and desktop client)
  138. if [ -d $INSTALL_DIR/prosody-modules/mod_carbons ]; then
  139. cp $INSTALL_DIR/prosody-modules/mod_carbons/*.lua /usr/lib/prosody/modules
  140. cp $INSTALL_DIR/prosody-modules/mod_carbons_adhoc/*.lua /usr/lib/prosody/modules
  141. cp $INSTALL_DIR/prosody-modules/mod_carbons_copies/*.lua /usr/lib/prosody/modules
  142. fi
  143. # XEP-0198 Stream management
  144. # Helps mobile apps recover when a device switches networks.
  145. if [ -d $INSTALL_DIR/prosody-modules/mod_smacks ]; then
  146. cp $INSTALL_DIR/prosody-modules/mod_smacks/*.lua /usr/lib/prosody/modules
  147. fi
  148. if [ -d $INSTALL_DIR/prosody-modules/mod_smacks_offline ]; then
  149. cp $INSTALL_DIR/prosody-modules/mod_smacks_offline/*.lua /usr/lib/prosody/modules
  150. fi
  151. # XEP-0191: blocking
  152. if [ -d $INSTALL_DIR/prosody-modules/mod_blocking ]; then
  153. cp $INSTALL_DIR/prosody-modules/mod_blocking/*.lua /usr/lib/prosody/modules
  154. fi
  155. # XEP-0016 Privacy lists
  156. if [ -d $INSTALL_DIR/prosody-modules/mod_privacy_lists ]; then
  157. cp $INSTALL_DIR/prosody-modules/mod_privacy_lists/*.lua /usr/lib/prosody/modules
  158. fi
  159. # If offline then send messages to email
  160. if [ -d $INSTALL_DIR/prosody-modules/mod_offline_email ]; then
  161. cp $INSTALL_DIR/prosody-modules/mod_offline_email/*.lua /usr/lib/prosody/modules
  162. fi
  163. }
  164. function upgrade_xmpp {
  165. function_check update_prosody_modules
  166. update_prosody_modules
  167. }
  168. function backup_local_xmpp {
  169. source_directory=/var/lib/prosody
  170. if [ -d $source_directory ]; then
  171. dest_directory=xmpp
  172. function_check backup_directory_to_usb
  173. backup_directory_to_usb $source_directory $dest_directory
  174. fi
  175. }
  176. function restore_local_xmpp {
  177. if [ -d /var/lib/prosody ]; then
  178. echo $"Restoring xmpp settings"
  179. temp_restore_dir=/root/tempxmpp
  180. function_check restore_directory_from_usb
  181. restore_directory_from_usb $temp_restore_dir xmpp
  182. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  183. if [ ! "$?" = "0" ]; then
  184. function_check set_user_permissions
  185. set_user_permissions
  186. function_check backup_unmount_drive
  187. backup_unmount_drive
  188. exit 725
  189. fi
  190. rm -rf $temp_restore_dir
  191. service prosody restart
  192. chown -R prosody:prosody /var/lib/prosody/*
  193. echo $"Restore of xmpp settings complete"
  194. fi
  195. }
  196. function backup_remote_xmpp {
  197. if [ -d /var/lib/prosody ]; then
  198. echo $"Backing up the xmpp settings"
  199. backup_directory_to_friend /var/lib/prosody xmpp
  200. echo $"Backup of xmpp settings complete"
  201. fi
  202. }
  203. function restore_remote_xmpp {
  204. if [ -d /var/lib/prosody ]; then
  205. echo $"Restoring xmpp settings"
  206. temp_restore_dir=/root/tempxmpp
  207. function_check restore_directory_from_friend
  208. restore_directory_from_friend $temp_restore_dir xmpp
  209. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  210. if [ ! "$?" = "0" ]; then
  211. exit 725
  212. fi
  213. rm -rf $temp_restore_dir
  214. service prosody restart
  215. chown -R prosody:prosody /var/lib/prosody/*
  216. echo $"Restore of xmpp settings complete"
  217. fi
  218. }
  219. function configure_firewall_for_xmpp {
  220. if [ ! -d /etc/prosody ]; then
  221. return
  222. fi
  223. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  224. return
  225. fi
  226. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  227. # docker does its own firewalling
  228. return
  229. fi
  230. if [[ $ONION_ONLY != "no" ]]; then
  231. return
  232. fi
  233. firewall_add XMPP 5222 tcp
  234. firewall_add XMPP 5223 tcp
  235. firewall_add XMPP 5269 tcp
  236. firewall_add XMPP 5280 tcp
  237. firewall_add XMPP 5281 tcp
  238. mark_completed $FUNCNAME
  239. }
  240. function remove_xmpp_client {
  241. apt-get -yq remove --purge profanity
  242. remove_completion_param install_xmpp_client
  243. remove_certs xmpp
  244. }
  245. function remove_xmpp {
  246. remove_xmpp_client
  247. firewall_remove 5222 tcp
  248. firewall_remove 5223 tcp
  249. firewall_remove 5269 tcp
  250. firewall_remove 5280 tcp
  251. firewall_remove 5281 tcp
  252. function_check remove_onion_service
  253. remove_onion_service xmpp 5222 5223 5269
  254. apt-get -yq remove --purge prosody prosody-modules
  255. if [ -d $INSTALL_DIR/prosody-modules ]; then
  256. rm -rf $INSTALL_DIR/prosody-modules
  257. fi
  258. if [ -d /etc/prosody ]; then
  259. rm -rf /etc/prosody
  260. fi
  261. if [ -d /var/lib/prosody ]; then
  262. rm -rf /var/lib/prosody
  263. fi
  264. groupdel prosody
  265. remove_completion_param install_xmpp
  266. sed -i '/xmpp/d' $COMPLETION_FILE
  267. }
  268. function xmpp_email_headers {
  269. for d in /home/*/ ; do
  270. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  271. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  272. if [ -f /home/$USERNAME/.muttrc ]; then
  273. if ! grep -q "Jabber-ID" /home/$USERNAME/.muttrc; then
  274. echo "my_hdr Jabber-ID: ${USERNAME}@${HOSTNAME}" >> /home/$USERNAME/.muttrc
  275. fi
  276. fi
  277. fi
  278. done
  279. }
  280. function xmpp_modules {
  281. filename=$1
  282. echo 'modules_enabled = {' >> $filename
  283. echo ' "pubsub";' >> $filename
  284. echo ' "dialback"; -- s2s dialback support' >> $filename
  285. echo ' "disco"; -- Service discovery' >> $filename
  286. echo ' "private"; -- Private XML storage (for room bookmarks, etc.)' >> $filename
  287. echo ' "vcard"; -- Allow users to set vCards' >> $filename
  288. echo ' "version"; -- Replies to server version requests' >> $filename
  289. echo ' "uptime"; -- Report how long server has been running' >> $filename
  290. echo ' "time"; -- Let others know the time here on this server' >> $filename
  291. echo ' "ping"; -- Replies to XMPP pings with pongs' >> $filename
  292. echo ' "admin_adhoc"; -- Allows administration via an XMPP client that supports ad-hoc commands' >> $filename
  293. echo ' "posix"; -- POSIX functionality, sends server to background, enables syslog, etc.' >> $filename
  294. echo ' "bosh"; -- Enable mod_bosh' >> $filename
  295. echo ' "tls"; -- Enable mod_tls' >> $filename
  296. echo ' "saslauth"; -- Enable mod_saslauth' >> $filename
  297. echo ' "onions"; -- Enable chat via onion service' >> $filename
  298. echo ' "mam"; -- Message archive management' >> $filename
  299. echo ' "csi"; -- Client state indication' >> $filename
  300. echo ' "carbons"; -- Message carbons' >> $filename
  301. echo ' "smacks"; -- Stream management' >> $filename
  302. echo ' "smacks_offline"; -- Stream management' >> $filename
  303. echo ' "pep"; -- Personal Eventing Protocol (to support OMEMO)' >> $filename
  304. echo ' "privacy"; -- Privacy lists' >> $filename
  305. echo ' "privacy_lists"; -- Privacy lists' >> $filename
  306. echo ' "blocking"; -- Blocking command' >> $filename
  307. echo ' "roster"; -- Roster versioning' >> $filename
  308. echo ' "offline_email"; -- If offline send to email' >> $filename
  309. echo ' "offline"; -- Store offline messages' >> $filename
  310. echo '};' >> $filename
  311. }
  312. function xmpp_create_config {
  313. echo "admins = { \"$MY_USERNAME@$DEFAULT_DOMAIN_NAME\" }" > /etc/prosody/prosody.cfg.lua
  314. echo '' >> /etc/prosody/prosody.cfg.lua
  315. xmpp_modules /etc/prosody/prosody.cfg.lua
  316. echo '' >> /etc/prosody/prosody.cfg.lua
  317. echo 'allow_registration = false;' >> /etc/prosody/prosody.cfg.lua
  318. echo '' >> /etc/prosody/prosody.cfg.lua
  319. echo 'daemonize = true;' >> /etc/prosody/prosody.cfg.lua
  320. echo '' >> /etc/prosody/prosody.cfg.lua
  321. echo 'pidfile = "/var/run/prosody/prosody.pid";' >> /etc/prosody/prosody.cfg.lua
  322. echo '' >> /etc/prosody/prosody.cfg.lua
  323. echo 'ssl = {' >> /etc/prosody/prosody.cfg.lua
  324. echo " key = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  325. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  326. echo " curve = $XMPP_ECC_CURVE;" >> /etc/prosody/prosody.cfg.lua
  327. echo ' depth = "1";' >> /etc/prosody/prosody.cfg.lua
  328. echo " ciphers = $XMPP_CIPHERS;" >> /etc/prosody/prosody.cfg.lua
  329. echo ' options = {"no_sslv2", "no_sslv3" };' >> /etc/prosody/prosody.cfg.lua
  330. echo " dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  331. echo '}' >> /etc/prosody/prosody.cfg.lua
  332. echo '' >> /etc/prosody/prosody.cfg.lua
  333. echo 'c2s_require_encryption = true' >> /etc/prosody/prosody.cfg.lua
  334. echo 's2s_require_encryption = true' >> /etc/prosody/prosody.cfg.lua
  335. echo '' >> /etc/prosody/prosody.cfg.lua
  336. echo 's2s_secure_auth = false' >> /etc/prosody/prosody.cfg.lua
  337. echo '' >> /etc/prosody/prosody.cfg.lua
  338. echo 'authentication = "internal_hashed"' >> /etc/prosody/prosody.cfg.lua
  339. echo '' >> /etc/prosody/prosody.cfg.lua
  340. echo 'log = {' >> /etc/prosody/prosody.cfg.lua
  341. echo ' info = "/dev/null";' >> /etc/prosody/prosody.cfg.lua
  342. echo ' error = "/dev/null";' >> /etc/prosody/prosody.cfg.lua
  343. echo ' { levels = { "error" }; to = "/dev/null"; };' >> /etc/prosody/prosody.cfg.lua
  344. echo '}' >> /etc/prosody/prosody.cfg.lua
  345. echo '' >> /etc/prosody/prosody.cfg.lua
  346. echo "VirtualHost \"${DEFAULT_DOMAIN_NAME}\"" >> /etc/prosody/prosody.cfg.lua
  347. echo ' ssl = {' >> /etc/prosody/prosody.cfg.lua
  348. echo " key = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  349. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  350. echo " curve = $XMPP_ECC_CURVE;" >> /etc/prosody/prosody.cfg.lua
  351. echo ' depth = "1";' >> /etc/prosody/prosody.cfg.lua
  352. echo " ciphers = $XMPP_CIPHERS;" >> /etc/prosody/prosody.cfg.lua
  353. echo ' options = {"no_sslv2", "no_sslv3" };' >> /etc/prosody/prosody.cfg.lua
  354. echo " dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  355. echo ' }' >> /etc/prosody/prosody.cfg.lua
  356. echo '' >> /etc/prosody/prosody.cfg.lua
  357. echo 'Include "conf.d/*.cfg.lua"' >> /etc/prosody/prosody.cfg.lua
  358. }
  359. function install_xmpp_main {
  360. update_prosody_modules
  361. if [[ $(app_is_installed xmpp_main) == "1" ]]; then
  362. return
  363. fi
  364. if [[ $ONION_ONLY == 'no' ]]; then
  365. # obtain a cert for the default domain
  366. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "0" ]]; then
  367. echo $'Obtaining certificate for the main domain'
  368. create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
  369. fi
  370. fi
  371. apt-get -yq install lua-sec lua-bitop
  372. apt-get -yq install prosody prosody-modules mercurial
  373. if [ ! -d /etc/prosody ]; then
  374. echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
  375. exit 52367
  376. fi
  377. groupadd prosody
  378. if [ ! -d /var/lib/prosody ]; then
  379. mkdir /var/lib/prosody
  380. fi
  381. if [ ! -d /etc/prosody/conf.d ]; then
  382. mkdir /etc/prosody/conf.d
  383. fi
  384. chmod -R 700 /etc/prosody/conf.d
  385. chown -R prosody /var/lib/prosody
  386. chown -R prosody /etc/prosody/conf.d
  387. # obtain the prosody modules
  388. cd $INSTALL_DIR
  389. hg clone https://hg.prosody.im/prosody-modules/ prosody-modules
  390. if [ ! -d $INSTALL_DIR/prosody-modules/mod_onions ]; then
  391. echo $'mod_onions prosody module could not be found'
  392. exit 73254
  393. fi
  394. # install the onions module
  395. update_prosody_modules
  396. if [ ! -f /usr/lib/prosody/modules/mod_onions.lua ]; then
  397. echo $'mod_onions.lua could not be copied to the prosody modules directory'
  398. exit 63952
  399. fi
  400. # create a certificate
  401. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "0" ]]; then
  402. if [[ "$(cert_exists xmpp)" == "0" ]]; then
  403. ${PROJECT_NAME}-addcert -h xmpp --dhkey ${DH_KEYLENGTH}
  404. check_certificates xmpp
  405. fi
  406. fi
  407. groupadd default
  408. chmod 600 /etc/shadow
  409. chmod 600 /etc/gshadow
  410. usermod -g default prosody
  411. chmod 0000 /etc/shadow
  412. chmod 0000 /etc/gshadow
  413. chown root:default /etc/ssl/private/xmpp.*
  414. chown root:default /etc/ssl/certs/xmpp.*
  415. chown root:default /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.*
  416. chown root:default /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.*
  417. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  418. if [ ! -d /etc/prosody/certs ]; then
  419. mkdir /etc/prosody/certs
  420. fi
  421. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "1" ]]; then
  422. sed -i "s|/etc/prosody/certs/example.com.key|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  423. sed -i "s|/etc/prosody/certs/example.com.crt|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  424. else
  425. sed -i 's|/etc/prosody/certs/example.com.key|/etc/prosody/certs/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  426. sed -i 's|/etc/prosody/certs/example.com.crt|/etc/prosody/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  427. fi
  428. if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  429. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME})" == "1" ]]; then
  430. sed -i "/certificate =/a\ dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" /etc/prosody/conf.avail/xmpp.cfg.lua
  431. else
  432. sed -i '/certificate =/a\ dhparam = "/etc/prosody/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
  433. fi
  434. fi
  435. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  436. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
  437. fi
  438. if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  439. sed -i "/certificate =/a\ ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
  440. fi
  441. if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  442. sed -i '/certificate =/a\ depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
  443. fi
  444. if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  445. sed -i "/certificate =/a\ curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
  446. fi
  447. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
  448. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
  449. if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  450. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  451. xmpp_modules /etc/prosody/conf.avail/xmpp.cfg.lua
  452. fi
  453. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  454. if ! grep -q "c2s_require_encryption" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  455. echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  456. else
  457. sed -i 's|c2s_require_encryption.*|c2s_require_encryption = true|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  458. fi
  459. if ! grep -q "s2s_require_encryption" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  460. echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  461. else
  462. sed -i 's|s2s_require_encryption.*|s2s_require_encryption = true|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  463. fi
  464. if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  465. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  466. else
  467. sed -i 's|allow_unencrypted_plain_auth.*|allow_unencrypted_plain_auth = false|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  468. fi
  469. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  470. if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  471. sed -i "s|/etc/prosody/certs/localhost.key|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key|g" /etc/prosody/prosody.cfg.lua
  472. sed -i "s|/etc/prosody/certs/localhost.crt|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/prosody/prosody.cfg.lua
  473. else
  474. sed -i 's|/etc/prosody/certs/localhost.key|/etc/prosody/certs/xmpp.key|g' /etc/prosody/prosody.cfg.lua
  475. sed -i 's|/etc/prosody/certs/localhost.crt|/etc/prosody/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
  476. fi
  477. if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
  478. if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam ]; then
  479. sed -i "/certificate =/a\ dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" /etc/prosody/prosody.cfg.lua
  480. else
  481. sed -i '/certificate =/a\ dhparam = "/etc/prosody/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
  482. fi
  483. fi
  484. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/prosody.cfg.lua; then
  485. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/prosody.cfg.lua
  486. fi
  487. if ! grep -q 'ciphers =' /etc/prosody/prosody.cfg.lua; then
  488. sed -i "/certificate =/a\ ciphers = $XMPP_CIPHERS;" /etc/prosody/prosody.cfg.lua
  489. fi
  490. if ! grep -q 'depth = "1";' /etc/prosody/prosody.cfg.lua; then
  491. sed -i '/certificate =/a\ depth = "1";' /etc/prosody/prosody.cfg.lua
  492. fi
  493. if ! grep -q 'curve =' /etc/prosody/prosody.cfg.lua; then
  494. sed -i "/certificate =/a\ curve = $XMPP_ECC_CURVE;" /etc/prosody/prosody.cfg.lua
  495. fi
  496. sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
  497. if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
  498. sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
  499. fi
  500. if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/prosody.cfg.lua; then
  501. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  502. fi
  503. sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
  504. sed -i 's/authentication = "internal_plain"/authentication = "internal_hashed"/g' /etc/prosody/prosody.cfg.lua
  505. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/prosody.cfg.lua
  506. if [ -f /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  507. # use an existing cert if possible
  508. sed -i "s|key = \"/etc/prosody/certs/example.com.key\"|key = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key\"|g" /etc/prosody/prosody.cfg.lua
  509. sed -i "s|certificate = \"/etc/prosody/certs/example.com.crt\"|certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem\"|g" /etc/prosody/prosody.cfg.lua
  510. else
  511. sed -i 's|key = "/etc/prosody/certs/example.com.key"|key = "/etc/prosody/certs/xmpp.key"|g' /etc/prosody/prosody.cfg.lua
  512. sed -i 's|certificate = "/etc/prosody/certs/example.com.crt"|certificate = "/etc/prosody/certs/xmpp.crt"|g' /etc/prosody/prosody.cfg.lua
  513. fi
  514. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/prosody.cfg.lua
  515. if [ ! -d /var/lib/tor ]; then
  516. echo $'No Tor installation found. xmpp onion site cannot be configured.'
  517. exit 877367
  518. fi
  519. if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
  520. echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
  521. echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
  522. echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
  523. echo $'Added onion site for xmpp chat'
  524. fi
  525. onion_update
  526. wait_for_onion_service 'xmpp'
  527. if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  528. echo $'xmpp onion site hostname not found'
  529. exit 65349
  530. fi
  531. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  532. if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  533. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  534. echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
  535. echo ' modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  536. fi
  537. set_completion_param "xmpp onion domain" "${XMPP_ONION_HOSTNAME}"
  538. if [ -f $IMAGE_PASSWORD_FILE ]; then
  539. XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  540. else
  541. if [ ${#XMPP_PASSWORD} -lt 8 ]; then
  542. XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  543. fi
  544. fi
  545. prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME "$XMPP_PASSWORD"
  546. if [ ! "$?" = "0" ]; then
  547. echo $'Unable to register prosody user'
  548. exit 347682
  549. fi
  550. ${PROJECT_NAME}-pass -u $MY_USERNAME -a xmpp -p "$XMPP_PASSWORD"
  551. function_check configure_firewall_for_xmpp
  552. configure_firewall_for_xmpp
  553. xmpp_email_headers
  554. cp /etc/ssl/certs/xmpp.* /etc/prosody/certs
  555. cp /etc/ssl/private/xmpp.* /etc/prosody/certs
  556. chown -R prosody:default /etc/prosody
  557. update_default_domain
  558. xmpp_create_config
  559. systemctl restart prosody
  560. install_completed xmpp_main
  561. }
  562. function install_xmpp_client {
  563. if [[ $(app_is_installed xmpp_client) == "1" ]]; then
  564. return
  565. fi
  566. apt-get -yq install profanity
  567. XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
  568. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  569. if [ ! -d $XMPP_CLIENT_DIR ]; then
  570. mkdir -p $XMPP_CLIENT_DIR
  571. fi
  572. if [[ $ONION_ONLY == 'no' ]]; then
  573. echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
  574. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  575. echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  576. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  577. echo "muc.service=conference.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  578. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  579. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  580. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  581. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  582. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  583. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  584. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  585. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  586. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  587. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  588. fi
  589. fi
  590. if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  591. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  592. echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
  593. if [[ $ONION_ONLY == 'no' ]]; then
  594. echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
  595. else
  596. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  597. fi
  598. echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  599. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  600. echo "muc.service=conference.${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  601. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  602. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  603. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  604. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  605. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  606. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  607. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  608. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  609. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  610. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  611. fi
  612. fi
  613. if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
  614. mkdir -p /home/$MY_USERNAME/.config/profanity
  615. fi
  616. echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
  617. echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
  618. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
  619. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  620. install_completed xmpp_client
  621. }
  622. function install_xmpp {
  623. install_xmpp_main
  624. install_xmpp_client
  625. APP_INSTALLED=1
  626. }
  627. # NOTE: deliberately no exit 0