freedombone-app-xmpp 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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. prosody_latest_version='0.10'
  39. prosody_nightly=333
  40. prosody_nightly_hash='a104a1b211eeff88247f1b98d7897c96b9d2f76a12b6d738a4c955e569821363'
  41. prosody_filename=prosody-${prosody_latest_version}-1nightly${prosody_nightly}
  42. prosody_nightly_url="https://prosody.im/nightly/${prosody_latest_version}/latest/${prosody_filename}.tar.gz"
  43. LIBMESODE_REPO="https://github.com/boothj5/libmesode"
  44. LIBMESODE_COMMIT='e3db0e9bfba61b2d82193874343a94a88f910800'
  45. PROFANITY_REPO="https://github.com/boothj5/profanity"
  46. PROFANITY_COMMIT='b64646979ea50a13d0c7ec0b1a46969f661569a8'
  47. PROFANITY_OMEMO_PLUGIN_REPO="https://github.com/ReneVolution/profanity-omemo-plugin"
  48. PROFANITY_OMEMO_PLUGIN_COMMIT='d2383f5bf1300c2a8acdc9e104453144c66891ee'
  49. xmpp_variables=(ONION_ONLY
  50. INSTALLED_WITHIN_DOCKER
  51. XMPP_CIPHERS
  52. XMPP_ECC_CURVE
  53. XMPP_ECC_CURVE
  54. MY_USERNAME
  55. DEFAULT_DOMAIN_NAME
  56. XMPP_DOMAIN_CODE)
  57. function xmpp_add_onion_address {
  58. domain_name="$1"
  59. onion_address="$2"
  60. if [ ${#domain_name} -eq 0 ]; then
  61. return
  62. fi
  63. if [ ${#onion_address} -eq 0 ]; then
  64. return
  65. fi
  66. if grep -q "[\"${domain_name}\"]" /etc/prosody/prosody.cfg.lua; then
  67. sed -i "s|[\"${domain_name}\"].*|[\"${domain_name}\"] = \"${onion_address}\";|g" /etc/prosody/prosody.cfg.lua
  68. else
  69. sed -i "/onions_map = {/a [\"${domain_name}\"] = \"${onion_address}\";" /etc/prosody/prosody.cfg.lua
  70. fi
  71. systemctl restart prosody
  72. }
  73. function xmpp_add_onion_address_interactive {
  74. data=$(tempfile 2>/dev/null)
  75. trap "rm -f $data" 0 1 2 5 15
  76. dialog --backtitle $"Freedombone Control Panel" \
  77. --title $"Add an ICANN to Onion domain mapping" \
  78. --form $"Sepecify an ICANN domain name and its equivalent onion address\n" 9 50 2 \
  79. $"Domain:" 1 1 "" 1 18 26 25 \
  80. $"Onion address:" 2 1 "" 2 18 26 25 \
  81. 2> $data
  82. sel=$?
  83. case $sel in
  84. 1) return;;
  85. 255) return;;
  86. esac
  87. domain_name=$(cat $data | sed -n 1p)
  88. onion_address=$(cat $data | sed -n 2p)
  89. if [[ "$onion_address" != *".onion" ]]; then
  90. return
  91. fi
  92. if [[ "$domain_name" != *"."* ]]; then
  93. return
  94. fi
  95. xmpp_add_onion_address "$domain_name" "$onion_address"
  96. dialog --title $"Add an ICANN to Onion domain mapping" \
  97. --msgbox $"${domain_name} -> ${onion_address} added" 6 70
  98. }
  99. function xmpp_remove_onion_address {
  100. domain_name="$1"
  101. if [ ${#domain_name} -eq 0 ]; then
  102. return
  103. fi
  104. if grep -q "[\"${domain_name}\"]" /etc/prosody/prosody.cfg.lua; then
  105. sed -i "/[\"${domain_name}\"]/d" /etc/prosody/prosody.cfg.lua
  106. fi
  107. if grep -q "= \"${domain_name}\";" /etc/prosody/prosody.cfg.lua; then
  108. sed -i "/= \"${domain_name}\";/d" /etc/prosody/prosody.cfg.lua
  109. fi
  110. systemctl restart prosody
  111. }
  112. function xmpp_remove_onion_address_interactive {
  113. data=$(tempfile 2>/dev/null)
  114. trap "rm -f $data" 0 1 2 5 15
  115. dialog --title $"Remove ICANN to Onion domain mapping" \
  116. --backtitle $"Freedombone Control Panel" \
  117. --inputbox $'Enter the domain name or onion address to be removed' 8 60 2>$data
  118. sel=$?
  119. case $sel in
  120. 0) domain_name=$(<$data)
  121. if [[ "$domain_name" != *"."* ]]; then
  122. return
  123. fi
  124. xmpp_remove_onion_address "$domain_name"
  125. dialog --title $"Remove an ICANN to Onion domain mapping" \
  126. --msgbox $"${domain_name} removed" 6 70
  127. ;;
  128. esac
  129. }
  130. function configure_interactive_xmpp {
  131. while true
  132. do
  133. data=$(tempfile 2>/dev/null)
  134. trap "rm -f $data" 0 1 2 5 15
  135. dialog --backtitle $"Freedombone Control Panel" \
  136. --title $"XMPP" \
  137. --radiolist $"Choose an operation:" 12 70 3 \
  138. 1 $"Add an ICANN to onion domain mapping" off \
  139. 2 $"Remove an ICANN to onion domain mapping" off \
  140. 3 $"Return to administrator control panel" on 2> $data
  141. sel=$?
  142. case $sel in
  143. 1) return;;
  144. 255) return;;
  145. esac
  146. case $(cat $data) in
  147. 1) xmpp_add_onion_address_interactive;;
  148. 2) xmpp_remove_onion_address_interactive;;
  149. 3) break;;
  150. esac
  151. done
  152. }
  153. function remove_user_xmpp {
  154. remove_username="$1"
  155. ${PROJECT_NAME}-pass -u $remove_username --rmapp xmpp
  156. ${PROJECT_NAME}-rmxmpp -e "${remove_username}@$HOSTNAME"
  157. }
  158. function add_user_xmpp {
  159. new_username="$1"
  160. new_user_password="$2"
  161. ${PROJECT_NAME}-pass -u $new_username -a xmpp -p "$new_user_password"
  162. ${PROJECT_NAME}-addxmpp -e "$new_username@$HOSTNAME" -p "$new_user_password"
  163. if [ ! "$?" = "0" ]; then
  164. echo '1'
  165. return
  166. fi
  167. XMPP_CLIENT_DIR=/home/$new_username/.local/share/profanity
  168. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  169. if [ ! -d $XMPP_CLIENT_DIR ]; then
  170. mkdir -p $XMPP_CLIENT_DIR
  171. fi
  172. if [ ! -d /home/$new_username/.config/profanity ]; then
  173. mkdir -p /home/$new_username/.config/profanity
  174. fi
  175. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  176. GPG_PUBLIC_KEY_ID=$(su -c "gpg --list-keys $new_username@$HOSTNAME | grep 'pub '" - $new_username | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  177. echo "[${new_username}@${HOSTNAME}]" > $XMPP_CLIENT_ACCOUNTS
  178. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  179. echo "jid=${new_username}@${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  180. echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
  181. echo "pgp.keyid=$GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
  182. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  183. echo "muc.service=conference.${HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  184. echo "muc.nick=${new_username}" >> $XMPP_CLIENT_ACCOUNTS
  185. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  186. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  187. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  188. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  189. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  190. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  191. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  192. echo '[connection]' > /home/$new_username/.config/profanity/profrc
  193. echo "account=${new_username}@${HOSTNAME}" >> /home/$new_username/.config/profanity/profrc
  194. chown -R $new_username:$new_username /home/$new_username/.local
  195. chown -R $new_username:$new_username /home/$new_username/.config
  196. echo '0'
  197. }
  198. function run_client_xmpp {
  199. torify profanity
  200. }
  201. function install_interactive_xmpp {
  202. echo -n ''
  203. APP_INSTALLED=1
  204. }
  205. function change_password_xmpp {
  206. curr_username="$1"
  207. new_user_password="$2"
  208. read_config_param DEFAULT_DOMAIN_NAME
  209. ${PROJECT_NAME}-pass -u $curr_username -a xmpp -p "$new_user_password"
  210. # TODO: this is currently interactive. Really there needs to be a
  211. # non-interactive password change option for prosodyctl
  212. clear
  213. echo ''
  214. echo $'Currently Prosody requires password changes to be done interactively'
  215. prosodyctl passwd ${curr_username}@${DEFAULT_DOMAIN_NAME}
  216. XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
  217. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  218. if [ -f $XMPP_CLIENT_ACCOUNTS ]; then
  219. sed -i "s|password=.*|password=$new_user_password|g" $XMPP_CLIENT_ACCOUNTS
  220. fi
  221. }
  222. function reconfigure_xmpp {
  223. echo -n ''
  224. }
  225. function update_prosody_modules {
  226. if [ ! -d /var/lib/prosody/prosody-modules ]; then
  227. return
  228. fi
  229. if [ ! -d /usr/lib/prosody ]; then
  230. return
  231. fi
  232. cd /var/lib/prosody/prosody-modules
  233. hg pull
  234. hg update
  235. # change to using profile rather than pep and vcard modules
  236. if grep '"pep"' /etc/prosody/prosody.cfg.lua; then
  237. if grep '"vcard"' /etc/prosody/prosody.cfg.lua; then
  238. sed -i 's|"pep"|"profile"|g' /etc/prosody/prosody.cfg.lua
  239. sed -i '/"vcard"/d' /etc/prosody/prosody.cfg.lua
  240. fi
  241. fi
  242. }
  243. function upgrade_xmpp_server {
  244. function_check update_prosody_modules
  245. update_prosody_modules
  246. if [ -d ${INSTALL_DIR}/${prosody_filename} ]; then
  247. # ensure that the binaries have not been overwritten
  248. # by an operating system upgrade
  249. cd ${INSTALL_DIR}/${prosody_filename}
  250. make prefix=/usr install
  251. else
  252. cd $INSTALL_DIR
  253. # Try to get the source from the project repo
  254. if [ -f /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
  255. cp /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
  256. else
  257. if [ -f /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
  258. cp /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
  259. else
  260. wget $prosody_nightly_url
  261. fi
  262. fi
  263. if [ ! -f ${INSTALL_DIR}/${prosody_filename}.tar.gz ]; then
  264. echo $"Failed to download prosody nightly $prosody_nightly_url"
  265. return
  266. fi
  267. hash_value=$(sha256sum ${INSTALL_DIR}/${prosody_filename}.tar.gz | awk -F ' ' '{print $1}')
  268. if [[ "$hash_value" != "$prosody_nightly_hash" ]]; then
  269. rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
  270. echo $'Unexpected hash value for prosody nightly download'
  271. return
  272. fi
  273. tar -xzvf ${INSTALL_DIR}/${prosody_filename}.tar.gz
  274. cd ${INSTALL_DIR}/${prosody_filename}
  275. ./configure --ostype=debian --prefix=/usr
  276. make prefix=/usr
  277. make prefix=/usr install
  278. if [ -f /usr/local/bin/prosody ]; then
  279. echo $'Failed to build prosody nightly to /usr/bin'
  280. rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
  281. rm -rf ${INSTALL_DIR}/${prosody_filename}
  282. return
  283. fi
  284. rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
  285. fi
  286. # add onion addresses for known servers
  287. if ! grep -q "onions_map =" /etc/prosody/prosody.cfg.lua; then
  288. echo '' >> /etc/prosody/prosody.cfg.lua
  289. xmpp_onion_addresses /etc/prosody/prosody.cfg.lua
  290. fi
  291. systemctl restart prosody
  292. }
  293. function upgrade_xmpp_client {
  294. # update profanity client
  295. if [ -f /usr/bin/profanity ]; then
  296. apt-get -y remove --purge profanity
  297. fi
  298. rm -rf /tmp/*
  299. function_check set_repo_commit
  300. set_repo_commit $INSTALL_DIR/libmesode "libmesode commit" "$LIBMESODE_COMMIT" $LIBMESODE_REPO
  301. cd $INSTALL_DIR/libmesode
  302. ./bootstrap.sh
  303. ./configure
  304. make
  305. make install
  306. cp /usr/local/lib/libmesode* /usr/lib
  307. rm -rf /tmp/*
  308. function_check set_repo_commit
  309. set_repo_commit $INSTALL_DIR/profanity "profanity commit" "$PROFANITY_COMMIT" $PROFANITY_REPO
  310. cd $INSTALL_DIR/profanity
  311. ./bootstrap.sh
  312. ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
  313. make
  314. make install
  315. # upgrade omemo plugins for all users
  316. set_repo_commit $INSTALL_DIR/profanity-omemo-plugin "profanity omemo plugin commit" "$PROFANITY_OMEMO_PLUGIN_COMMIT" $PROFANITY_OMEMO_PLUGIN_REPO
  317. for d in /home/*/ ; do
  318. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  319. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  320. if [ ! -d /home/$USERNAME/.local/share/profanity/plugins ]; then
  321. mkdir -p /home/$USERNAME/.local/share/profanity/plugins
  322. fi
  323. cp $INSTALL_DIR/profanity-omemo-plugin/omemo.py /home/$USERNAME/.local/share/profanity/plugins
  324. chown -R $USERNAME:$USERNAME /home/$USERNAME/.local
  325. fi
  326. done
  327. cp $INSTALL_DIR/profanity-omemo-plugin/omemo.py /etc/skel/.local/share/profanity/plugins
  328. }
  329. function upgrade_xmpp {
  330. upgrade_xmpp_server
  331. upgrade_xmpp_client
  332. }
  333. function backup_local_xmpp {
  334. source_directory=/var/lib/prosody
  335. if [ -d $source_directory ]; then
  336. dest_directory=xmpp
  337. function_check backup_directory_to_usb
  338. backup_directory_to_usb $source_directory $dest_directory
  339. fi
  340. }
  341. function restore_local_xmpp {
  342. if [ -d /var/lib/prosody ]; then
  343. echo $"Restoring xmpp settings"
  344. temp_restore_dir=/root/tempxmpp
  345. function_check restore_directory_from_usb
  346. restore_directory_from_usb $temp_restore_dir xmpp
  347. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  348. if [ ! "$?" = "0" ]; then
  349. function_check set_user_permissions
  350. set_user_permissions
  351. function_check backup_unmount_drive
  352. backup_unmount_drive
  353. exit 725
  354. fi
  355. rm -rf $temp_restore_dir
  356. service prosody restart
  357. chown -R prosody:prosody /var/lib/prosody/*
  358. echo $"Restore of xmpp settings complete"
  359. fi
  360. }
  361. function backup_remote_xmpp {
  362. if [ -d /var/lib/prosody ]; then
  363. echo $"Backing up the xmpp settings"
  364. backup_directory_to_friend /var/lib/prosody xmpp
  365. echo $"Backup of xmpp settings complete"
  366. fi
  367. }
  368. function restore_remote_xmpp {
  369. if [ -d /var/lib/prosody ]; then
  370. echo $"Restoring xmpp settings"
  371. temp_restore_dir=/root/tempxmpp
  372. function_check restore_directory_from_friend
  373. restore_directory_from_friend $temp_restore_dir xmpp
  374. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  375. if [ ! "$?" = "0" ]; then
  376. exit 725
  377. fi
  378. rm -rf $temp_restore_dir
  379. service prosody restart
  380. chown -R prosody:prosody /var/lib/prosody/*
  381. echo $"Restore of xmpp settings complete"
  382. fi
  383. }
  384. function configure_firewall_for_xmpp {
  385. if [ ! -d /etc/prosody ]; then
  386. return
  387. fi
  388. if [[ $(is_completed $FUNCNAME) == "1" ]]; then
  389. return
  390. fi
  391. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  392. # docker does its own firewalling
  393. return
  394. fi
  395. if [[ $ONION_ONLY != "no" ]]; then
  396. return
  397. fi
  398. firewall_add XMPP 5222 tcp
  399. firewall_add XMPP 5223 tcp
  400. firewall_add XMPP 5269 tcp
  401. firewall_add XMPP 5280 tcp
  402. firewall_add XMPP 5281 tcp
  403. mark_completed $FUNCNAME
  404. }
  405. function remove_xmpp_client {
  406. apt-get -yq remove --purge profanity
  407. remove_completion_param install_xmpp_client
  408. remove_certs xmpp
  409. }
  410. function remove_xmpp {
  411. remove_xmpp_client
  412. firewall_remove 5222 tcp
  413. firewall_remove 5223 tcp
  414. firewall_remove 5269 tcp
  415. firewall_remove 5280 tcp
  416. firewall_remove 5281 tcp
  417. function_check remove_onion_service
  418. remove_onion_service xmpp 5222 5223 5269
  419. apt-get -yq remove --purge prosody
  420. if [ -d /etc/prosody ]; then
  421. rm -rf /etc/prosody
  422. fi
  423. if [ -d /var/lib/prosody ]; then
  424. rm -rf /var/lib/prosody
  425. fi
  426. if [ -d /usr/lib/prosody ]; then
  427. rm -rf /usr/lib/prosody
  428. fi
  429. if [ -f /usr/local/bin/prosody ]; then
  430. rm /usr/local/bin/prosody
  431. fi
  432. if [ -f /usr/local/bin/prosodyctl ]; then
  433. rm /usr/local/bin/prosodyctl
  434. fi
  435. groupdel prosody
  436. remove_completion_param install_xmpp
  437. sed -i '/xmpp/d' $COMPLETION_FILE
  438. }
  439. function xmpp_email_headers {
  440. for d in /home/*/ ; do
  441. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  442. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  443. if [ -f /home/$USERNAME/.muttrc ]; then
  444. if ! grep -q "Jabber-ID" /home/$USERNAME/.muttrc; then
  445. echo "my_hdr Jabber-ID: ${USERNAME}@${HOSTNAME}" >> /home/$USERNAME/.muttrc
  446. fi
  447. fi
  448. fi
  449. done
  450. }
  451. function xmpp_modules {
  452. filename=$1
  453. echo 'modules_enabled = {' >> $filename
  454. echo ' "pubsub";' >> $filename
  455. echo ' "dialback"; -- s2s dialback support' >> $filename
  456. echo ' "disco"; -- Service discovery' >> $filename
  457. echo ' "private"; -- Private XML storage (for room bookmarks, etc.)' >> $filename
  458. echo ' "version"; -- Replies to server version requests' >> $filename
  459. echo ' "uptime"; -- Report how long server has been running' >> $filename
  460. echo ' "time"; -- Let others know the time here on this server' >> $filename
  461. echo ' "ping"; -- Replies to XMPP pings with pongs' >> $filename
  462. echo ' "admin_adhoc"; -- Allows administration via an XMPP client that supports ad-hoc commands' >> $filename
  463. echo ' "posix"; -- POSIX functionality, sends server to background, enables syslog, etc.' >> $filename
  464. echo ' "bosh"; -- Enable mod_bosh' >> $filename
  465. echo ' "tls"; -- Enable mod_tls' >> $filename
  466. echo ' "saslauth"; -- Enable mod_saslauth' >> $filename
  467. echo ' "onions"; -- Enable chat via onion service' >> $filename
  468. echo ' "mam"; -- Message archive management' >> $filename
  469. echo ' "csi"; -- Client state indication' >> $filename
  470. echo ' "carbons"; -- Message carbons' >> $filename
  471. echo ' "carbons_adhoc"; -- Message carbons' >> $filename
  472. echo ' "carbons_copies"; -- Message carbons' >> $filename
  473. echo ' "smacks"; -- Stream management' >> $filename
  474. echo ' "smacks_offline"; -- Stream management' >> $filename
  475. echo ' "profile"; -- Personal Eventing Protocol (to support OMEMO)' >> $filename
  476. echo ' "e2e_policy"; -- To support OMEMO' >> $filename
  477. echo ' "pep_vcard_avatar"; -- Personal Eventing Protocol (to support OMEMO)' >> $filename
  478. echo ' "blocklist"; -- Privacy lists' >> $filename
  479. echo ' "privacy_lists"; -- Privacy lists' >> $filename
  480. echo ' "blocking"; -- Blocking command' >> $filename
  481. echo ' "roster"; -- Roster versioning' >> $filename
  482. echo ' "offline_email"; -- If offline send to email' >> $filename
  483. echo ' "offline"; -- Store offline messages' >> $filename
  484. echo ' "http";' >> $filename
  485. echo ' "http_upload";' >> $filename
  486. echo ' "websocket";' >> $filename
  487. echo '};' >> $filename
  488. }
  489. function xmpp_onion_addresses {
  490. filename=$1
  491. echo 'onions_map = {' >> $filename
  492. echo ' ["anonymitaet-im-inter.net"] = "rwf5skuv5vqzcdit.onion";' >> $filename
  493. echo ' ["autistici.org"] = "wi7qkxyrdpu5cmvr.onion";' >> $filename
  494. echo ' ["jabber.calyxinstitute.org"] = "ijeeynrc6x2uy5ob.onion";' >> $filename
  495. echo ' ["jabber.ccc.de"] = "okj7xc6j2szr2y75.onion";' >> $filename
  496. echo ' ["cloak.dk"] = "m2dsl4banuimpm6c.onion";' >> $filename
  497. echo ' ["jabber.cryptoparty.is"] = "cryjabkbdljzohnp.onion";' >> $filename
  498. echo ' ["daemons.cf"] = "daemon4jidu2oig6.onion";' >> $filename
  499. echo ' ["dukgo.com"] = "wlcpmruglhxp6quz.onion";' >> $filename
  500. echo ' ["evil.im"] = "evilxro6nvjuvxqo.onion";' >> $filename
  501. echo ' ["xmpp.evil.im"] = "evilxro6nvjuvxqo.onion";' >> $filename
  502. echo ' ["inventati.org"] = "wi7qkxyrdpu5cmvr.onion";' >> $filename
  503. echo ' ["jabber.ipredator.se"] = "3iffdebkzzkpgipa.onion";' >> $filename
  504. echo ' ["jabber-germany.de"] = "dbbrphko5tqcpar3.onion";' >> $filename
  505. echo ' ["kode.im"] = "ihkw7qy3tok45dun.onion";' >> $filename
  506. echo ' ["im.koderoot.net"] = "ihkw7qy3tok45dun.onion";' >> $filename
  507. echo ' ["adb-centralen.se"] = "37x6i3wgr2jyublb.onion";' >> $filename
  508. echo ' ["joelpurra.se"] = "37x6i3wgr2jyublb.onion";' >> $filename
  509. echo ' ["nordberg.se"] = "37x6i3wgr2jyublb.onion";' >> $filename
  510. echo ' ["jabber.lqdn.fr"] = "jabber63t4r2qi57.onion";' >> $filename
  511. echo ' ["jabber.otr.im"] = "5rgdtlawqkcplz75.onion";' >> $filename
  512. echo ' ["otromundo.cf"] = "arauemwe2utqqzye.onion";' >> $filename
  513. echo ' ["patchcord.be"] = "xsydhi3dnbjuatpz.onion";' >> $filename
  514. echo ' ["riseup.net"] = "4cjw6cwpeaeppfqz.onion";' >> $filename
  515. echo ' ["xmpp.riseup.net"] = "4cjw6cwpeaeppfqz.onion";' >> $filename
  516. echo ' ["rows.io"] = "yz6yiv2hxyagvwy6.onion";' >> $filename
  517. echo ' ["xmpp.rows.io"] = "yz6yiv2hxyagvwy6.onion";' >> $filename
  518. echo ' ["securejabber.me"] = "giyvshdnojeivkom.onion";' >> $filename
  519. echo ' ["so36.net"] = "s4fgy24e2b5weqdb.onion";' >> $filename
  520. echo ' ["jabber.so36.net"] = "s4fgy24e2b5weqdb.onion";' >> $filename
  521. echo ' ["jabber.systemli.org"] = "x5tno6mwkncu5m3h.onion";' >> $filename
  522. echo ' ["taolo.ga"] = "l3ybpw4vs6ie5rv2.onion";' >> $filename
  523. echo ' ["tchncs.de"] = "duvfmyqmdlyvc3mi.onion";' >> $filename
  524. echo ' ["wtfismyip.com"] = "ofkztxcohimx34la.onion";' >> $filename
  525. echo ' ["prosody.xmpp.is"] = "y2qmqomqpszzryei.onion";' >> $filename
  526. echo ' ["xndr.de"] = "trcubpttd6zkc3tf.onion";' >> $filename
  527. echo ' ["trashserver.net"] = "m4c722bvc2r7brnn.onion";' >> $filename
  528. echo '};' >> $filename
  529. }
  530. function xmpp_create_config {
  531. echo "admins = { \"$MY_USERNAME@$DEFAULT_DOMAIN_NAME\" }" > /etc/prosody/prosody.cfg.lua
  532. echo 'plugin_paths = { "/var/lib/prosody/prosody-modules" }' >> /etc/prosody/prosody.cfg.lua
  533. echo '' >> /etc/prosody/prosody.cfg.lua
  534. xmpp_modules /etc/prosody/prosody.cfg.lua
  535. echo '' >> /etc/prosody/prosody.cfg.lua
  536. xmpp_onion_addresses /etc/prosody/prosody.cfg.lua
  537. echo '' >> /etc/prosody/prosody.cfg.lua
  538. echo 'allow_registration = false;' >> /etc/prosody/prosody.cfg.lua
  539. echo '' >> /etc/prosody/prosody.cfg.lua
  540. echo 'daemonize = true;' >> /etc/prosody/prosody.cfg.lua
  541. echo '' >> /etc/prosody/prosody.cfg.lua
  542. echo 'pidfile = "/var/run/prosody/prosody.pid";' >> /etc/prosody/prosody.cfg.lua
  543. echo '' >> /etc/prosody/prosody.cfg.lua
  544. echo 'https_ports = { 5281 }' >> /etc/prosody/prosody.cfg.lua
  545. echo 'https_interfaces = { "*" }' >> /etc/prosody/prosody.cfg.lua
  546. echo 'https_ssl = {' >> /etc/prosody/prosody.cfg.lua
  547. if [ -f /etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  548. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  549. else
  550. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.crt\";" >> /etc/prosody/prosody.cfg.lua
  551. fi
  552. echo " key = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  553. echo " curve = $XMPP_ECC_CURVE;" >> /etc/prosody/prosody.cfg.lua
  554. echo " ciphers = $XMPP_CIPHERS;" >> /etc/prosody/prosody.cfg.lua
  555. echo ' options = {"no_sslv2", "no_sslv3" };' >> /etc/prosody/prosody.cfg.lua
  556. echo " dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  557. echo "}" >> /etc/prosody/prosody.cfg.lua
  558. echo '' >> /etc/prosody/prosody.cfg.lua
  559. echo 'ssl = {' >> /etc/prosody/prosody.cfg.lua
  560. echo " key = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  561. if [ -f /etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  562. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  563. else
  564. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.crt\";" >> /etc/prosody/prosody.cfg.lua
  565. fi
  566. echo " curve = $XMPP_ECC_CURVE;" >> /etc/prosody/prosody.cfg.lua
  567. echo ' depth = "1";' >> /etc/prosody/prosody.cfg.lua
  568. echo " ciphers = $XMPP_CIPHERS;" >> /etc/prosody/prosody.cfg.lua
  569. echo ' options = {"no_sslv2", "no_sslv3" };' >> /etc/prosody/prosody.cfg.lua
  570. echo " dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  571. echo '}' >> /etc/prosody/prosody.cfg.lua
  572. echo '' >> /etc/prosody/prosody.cfg.lua
  573. echo 'c2s_require_encryption = true' >> /etc/prosody/prosody.cfg.lua
  574. echo 's2s_require_encryption = true' >> /etc/prosody/prosody.cfg.lua
  575. echo '' >> /etc/prosody/prosody.cfg.lua
  576. echo 's2s_secure_auth = false' >> /etc/prosody/prosody.cfg.lua
  577. echo '' >> /etc/prosody/prosody.cfg.lua
  578. echo 'authentication = "internal_hashed"' >> /etc/prosody/prosody.cfg.lua
  579. echo '' >> /etc/prosody/prosody.cfg.lua
  580. echo 'storage = "sql"' >> /etc/prosody/prosody.cfg.lua
  581. echo 'sql = { driver = "SQLite3", database = "prosody.sqlite" }' >> /etc/prosody/prosody.cfg.lua
  582. echo '' >> /etc/prosody/prosody.cfg.lua
  583. echo 'log = {' >> /etc/prosody/prosody.cfg.lua
  584. echo ' info = "/dev/null";' >> /etc/prosody/prosody.cfg.lua
  585. echo ' error = "/dev/null";' >> /etc/prosody/prosody.cfg.lua
  586. echo ' { levels = { "error" }; to = "/dev/null"; };' >> /etc/prosody/prosody.cfg.lua
  587. echo '}' >> /etc/prosody/prosody.cfg.lua
  588. echo '' >> /etc/prosody/prosody.cfg.lua
  589. echo "VirtualHost \"${DEFAULT_DOMAIN_NAME}\"" >> /etc/prosody/prosody.cfg.lua
  590. echo ' ssl = {' >> /etc/prosody/prosody.cfg.lua
  591. echo " key = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  592. if [ -f /etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem ]; then
  593. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  594. else
  595. echo " certificate = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.crt\";" >> /etc/prosody/prosody.cfg.lua
  596. fi
  597. echo " curve = $XMPP_ECC_CURVE;" >> /etc/prosody/prosody.cfg.lua
  598. echo ' depth = "1";' >> /etc/prosody/prosody.cfg.lua
  599. echo " ciphers = $XMPP_CIPHERS;" >> /etc/prosody/prosody.cfg.lua
  600. echo ' options = {"no_sslv2", "no_sslv3" };' >> /etc/prosody/prosody.cfg.lua
  601. echo " dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  602. echo ' }' >> /etc/prosody/prosody.cfg.lua
  603. echo '' >> /etc/prosody/prosody.cfg.lua
  604. echo 'Include "conf.d/*.cfg.lua"' >> /etc/prosody/prosody.cfg.lua
  605. echo 'http_upload_path = "/var/lib/prosody/http_uploads"' >> /etc/prosody/prosody.cfg.lua
  606. echo 'http_upload_file_size_limit = 307200' >> /etc/prosody/prosody.cfg.lua
  607. echo '' >> /etc/prosody/prosody.cfg.lua
  608. echo "Component \"chat.${DEFAULT_DOMAIN_NAME}\" \"muc\"" >> /etc/prosody/prosody.cfg.lua
  609. echo ' name = "Chatrooms"' >> /etc/prosody/prosody.cfg.lua
  610. echo ' modules_enabled = {' >> /etc/prosody/prosody.cfg.lua
  611. echo ' "muc_limits";' >> /etc/prosody/prosody.cfg.lua
  612. echo ' "muc_log";' >> /etc/prosody/prosody.cfg.lua
  613. echo ' "mam_muc";' >> /etc/prosody/prosody.cfg.lua
  614. echo ' "muc_log_http";' >> /etc/prosody/prosody.cfg.lua
  615. echo ' }' >> /etc/prosody/prosody.cfg.lua
  616. echo 'storage = { muc_log = "sql"; }' >> /etc/prosody/prosody.cfg.lua
  617. echo 'sql = { driver = "SQLite3", database = "prosody.sqlite" }' >> /etc/prosody/prosody.cfg.lua
  618. echo 'muc_event_rate = 0.5;' >> /etc/prosody/prosody.cfg.lua
  619. echo 'muc_burst_factor = 10;' >> /etc/prosody/prosody.cfg.lua
  620. echo 'muc_log_by_default = false;' >> /etc/prosody/prosody.cfg.lua
  621. echo 'muc_log_all_rooms = false;' >> /etc/prosody/prosody.cfg.lua
  622. echo 'max_archive_query_results = 10;' >> /etc/prosody/prosody.cfg.lua
  623. echo 'max_history_messages = 10;' >> /etc/prosody/prosody.cfg.lua
  624. }
  625. function install_xmpp_nightly {
  626. if [ ! -d $INSTALL_DIR ]; then
  627. mkdir -p $INSTALL_DIR
  628. fi
  629. cd $INSTALL_DIR
  630. # Try to get the source from the project repo
  631. if [ -f /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
  632. cp /root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
  633. else
  634. if [ -f /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz ]; then
  635. cp /home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz .
  636. else
  637. wget $prosody_nightly_url
  638. fi
  639. fi
  640. if [ ! -f ${INSTALL_DIR}/${prosody_filename}.tar.gz ]; then
  641. echo $"Failed to download prosody nightly $prosody_nightly_url"
  642. exit 78352
  643. fi
  644. hash_value=$(sha256sum ${INSTALL_DIR}/${prosody_filename}.tar.gz | awk -F ' ' '{print $1}')
  645. if [[ "$hash_value" != "$prosody_nightly_hash" ]]; then
  646. rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
  647. echo $'Unexpected hash value for prosody nightly download'
  648. exit 68224283
  649. fi
  650. tar -xzvf ${INSTALL_DIR}/${prosody_filename}.tar.gz
  651. cd ${INSTALL_DIR}/${prosody_filename}
  652. ./configure --ostype=debian --prefix=/usr
  653. make prefix=/usr
  654. make prefix=/usr install
  655. if [ -f /usr/local/bin/prosody ]; then
  656. echo $'Failed to build prosody nightly to /usr/bin'
  657. rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
  658. rm -rf ${INSTALL_DIR}/${prosody_filename}
  659. exit 628732
  660. fi
  661. rm ${INSTALL_DIR}/${prosody_filename}.tar.gz
  662. }
  663. function install_xmpp_main {
  664. update_prosody_modules
  665. if [[ $(app_is_installed xmpp_main) == "1" ]]; then
  666. return
  667. fi
  668. if [[ $ONION_ONLY == 'no' ]]; then
  669. # obtain a cert for the default domain
  670. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "0" ]]; then
  671. echo $'Obtaining certificate for the main domain'
  672. create_site_certificate ${DEFAULT_DOMAIN_NAME} 'yes'
  673. fi
  674. fi
  675. apt-get -yq install lua-sec lua-bitop lua5.1 liblua5.1-dev
  676. apt-get -yq install libidn11-dev libssl-dev lua-dbi-sqlite3
  677. apt-get -yq mercurial
  678. apt-get -yq install prosody
  679. if [ ! -d /etc/prosody ]; then
  680. echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
  681. exit 52367
  682. fi
  683. groupadd prosody
  684. if [ ! -d /var/lib/prosody/http_uploads ]; then
  685. mkdir -p /var/lib/prosody/http_uploads
  686. fi
  687. if [ ! -d /etc/prosody/conf.d ]; then
  688. mkdir /etc/prosody/conf.d
  689. fi
  690. # obtain the prosody modules
  691. if [ ! -d /var/lib/prosody/prosody-modules ]; then
  692. hg clone https://hg.prosody.im/prosody-modules/ /var/lib/prosody/prosody-modules
  693. fi
  694. if [ ! -d /var/lib/prosody/prosody-modules/mod_onions ]; then
  695. echo $'mod_onions prosody module could not be found'
  696. exit 73254
  697. fi
  698. chmod -R 700 /etc/prosody/conf.d
  699. chown -R prosody /var/lib/prosody
  700. chown -R prosody /etc/prosody/conf.d
  701. # install the onions module
  702. update_prosody_modules
  703. # create a certificate
  704. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "0" ]]; then
  705. if [[ "$(cert_exists xmpp)" == "0" ]]; then
  706. ${PROJECT_NAME}-addcert -h xmpp --dhkey ${DH_KEYLENGTH}
  707. check_certificates xmpp
  708. fi
  709. fi
  710. groupadd default
  711. chmod 600 /etc/shadow
  712. chmod 600 /etc/gshadow
  713. usermod -g default prosody
  714. chmod 0000 /etc/shadow
  715. chmod 0000 /etc/gshadow
  716. chown root:default /etc/ssl/private/xmpp.*
  717. chown root:default /etc/ssl/certs/xmpp.*
  718. chown root:default /etc/ssl/private/${DEFAULT_DOMAIN_NAME}.*
  719. chown root:default /etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.*
  720. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  721. if [ ! -d /etc/prosody/certs ]; then
  722. mkdir /etc/prosody/certs
  723. fi
  724. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME} pem)" == "1" ]]; then
  725. sed -i "s|/etc/prosody/certs/example.com.key|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.key|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  726. sed -i "s|/etc/prosody/certs/example.com.crt|/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.pem|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  727. else
  728. sed -i 's|/etc/prosody/certs/example.com.key|/etc/prosody/certs/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  729. sed -i 's|/etc/prosody/certs/example.com.crt|/etc/prosody/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  730. fi
  731. if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  732. if [[ "$(cert_exists ${DEFAULT_DOMAIN_NAME})" == "1" ]]; then
  733. sed -i "/certificate =/a\ dhparam = \"/etc/prosody/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" /etc/prosody/conf.avail/xmpp.cfg.lua
  734. else
  735. sed -i '/certificate =/a\ dhparam = "/etc/prosody/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
  736. fi
  737. fi
  738. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  739. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
  740. fi
  741. if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  742. sed -i "/certificate =/a\ ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
  743. fi
  744. if ! grep -q 'depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  745. sed -i '/certificate =/a\ depth = "1";' /etc/prosody/conf.avail/xmpp.cfg.lua
  746. fi
  747. if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  748. sed -i "/certificate =/a\ curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
  749. fi
  750. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
  751. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
  752. if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  753. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  754. xmpp_modules /etc/prosody/conf.avail/xmpp.cfg.lua
  755. fi
  756. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  757. if ! grep -q "c2s_require_encryption" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  758. echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  759. else
  760. sed -i 's|c2s_require_encryption.*|c2s_require_encryption = true|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  761. fi
  762. if ! grep -q "s2s_require_encryption" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  763. echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  764. else
  765. sed -i 's|s2s_require_encryption.*|s2s_require_encryption = true|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  766. fi
  767. if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  768. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  769. else
  770. sed -i 's|allow_unencrypted_plain_auth.*|allow_unencrypted_plain_auth = false|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  771. fi
  772. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  773. if [ ! -d /var/lib/tor ]; then
  774. echo $'No Tor installation found. xmpp onion site cannot be configured.'
  775. exit 877367
  776. fi
  777. if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
  778. echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/' >> /etc/tor/torrc
  779. echo "HiddenServicePort 5222 127.0.0.1:5222" >> /etc/tor/torrc
  780. echo "HiddenServicePort 5269 127.0.0.1:5269" >> /etc/tor/torrc
  781. echo $'Added onion site for xmpp chat'
  782. fi
  783. onion_update
  784. wait_for_onion_service 'xmpp'
  785. if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  786. echo $'xmpp onion site hostname not found'
  787. exit 65349
  788. fi
  789. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  790. if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  791. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  792. echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/conf.avail/xmpp.cfg.lua
  793. echo ' modules_enabled = { "onions" };' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  794. fi
  795. set_completion_param "xmpp onion domain" "${XMPP_ONION_HOSTNAME}"
  796. if [ -f $IMAGE_PASSWORD_FILE ]; then
  797. XMPP_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
  798. else
  799. if [ ${#XMPP_PASSWORD} -lt 8 ]; then
  800. XMPP_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
  801. fi
  802. fi
  803. function_check configure_firewall_for_xmpp
  804. configure_firewall_for_xmpp
  805. xmpp_email_headers
  806. cp /etc/ssl/certs/xmpp.* /etc/prosody/certs
  807. cp /etc/ssl/private/xmpp.* /etc/prosody/certs
  808. update_default_domain
  809. xmpp_create_config
  810. # TODO comment this out after debian supports prosody 0.10 or later
  811. install_xmpp_nightly
  812. chown -R prosody /etc/prosody
  813. chown -R prosody /var/lib/prosody
  814. chown -R prosody /usr/lib/prosody
  815. chmod -R 700 /etc/prosody/conf.d
  816. systemctl restart prosody
  817. cd
  818. prosodyctl register $MY_USERNAME $DEFAULT_DOMAIN_NAME "$XMPP_PASSWORD"
  819. if [ ! "$?" = "0" ]; then
  820. echo ''
  821. echo ''
  822. systemctl status prosody -l
  823. echo ''
  824. echo ''
  825. which prosody
  826. which prosodyctl
  827. echo ''
  828. echo ''
  829. cat /etc/prosody/prosody.cfg.lua
  830. echo ''
  831. echo ''
  832. cat /etc/prosody/conf.avail/xmpp.cfg.lua
  833. echo ''
  834. echo ''
  835. remove_xmpp
  836. echo $'Unable to register prosody user'
  837. exit 347682
  838. fi
  839. ${PROJECT_NAME}-pass -u $MY_USERNAME -a xmpp -p "$XMPP_PASSWORD"
  840. install_completed xmpp_main
  841. }
  842. function install_xmpp_client {
  843. # install profanity from source in order to get OMEMO support
  844. if [[ $(app_is_installed xmpp_client) == "1" ]]; then
  845. return
  846. fi
  847. if [ ! -d $INSTALL_DIR ]; then
  848. mkdir -p $INSTALL_DIR
  849. fi
  850. apt-get -yq install automake autoconf autoconf-archive libtool build-essential
  851. apt-get -yq install libncursesw5-dev libglib2.0-dev libcurl3-dev sqlite3
  852. apt-get -yq install libotr5-dev libgpgme11-dev python-dev libreadline-dev
  853. # dependency for profanity not available in debian
  854. git_clone $LIBMESODE_REPO $INSTALL_DIR/libmesode
  855. cd $INSTALL_DIR/libmesode
  856. git checkout $LIBMESODE_COMMIT -b $LIBMESODE_COMMIT
  857. ./bootstrap.sh
  858. ./configure
  859. make
  860. make install
  861. cp /usr/local/lib/libmesode* /usr/lib
  862. # build profanity
  863. git_clone $PROFANITY_REPO $INSTALL_DIR/profanity
  864. cd $INSTALL_DIR/profanity
  865. git checkout $PROFANITY_COMMIT -b $PROFANITY_COMMIT
  866. ./bootstrap.sh
  867. ./configure --disable-notifications --disable-icons --enable-otr --enable-pgp --enable-plugins --enable-c-plugins --enable-python-plugins --without-xscreensaver
  868. make
  869. make install
  870. if [ ! -f /usr/local/bin/profanity ]; then
  871. echo $'Unable to build profanity'
  872. exit 7825272
  873. fi
  874. # install the omemo plugin
  875. git_clone $PROFANITY_OMEMO_PLUGIN_REPO $INSTALL_DIR/profanity-omemo-plugin
  876. cd $INSTALL_DIR/profanity-omemo-plugin
  877. git checkout $PROFANITY_OMEMO_PLUGIN_COMMIT -b $PROFANITY_OMEMO_PLUGIN_COMMIT
  878. if [ ! -f $INSTALL_DIR/profanity-omemo-plugin/omemo.py ]; then
  879. echo $'omemo.py not found'
  880. exit 389225
  881. fi
  882. mkdir -p /etc/skel/.local/share/profanity/plugins
  883. cp $INSTALL_DIR/profanity-omemo-plugin/omemo.py /etc/skel/.local/share/profanity/plugins
  884. cp $INSTALL_DIR/profanity-omemo-plugin/omemo.py /home/$MY_USERNAME/.local/share/profanity/plugins
  885. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
  886. XMPP_CLIENT_DIR=/home/$MY_USERNAME/.local/share/profanity
  887. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  888. if [ ! -d $XMPP_CLIENT_DIR ]; then
  889. mkdir -p $XMPP_CLIENT_DIR
  890. fi
  891. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  892. MY_GPG_PUBLIC_KEY_ID=$(su -c "gpg --list-keys $MY_USERNAME@$DEFAULT_DOMAIN_NAME | grep 'pub '" - $MY_USERNAME | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}')
  893. if [[ $ONION_ONLY == 'no' ]]; then
  894. echo "[${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}]" > $XMPP_CLIENT_ACCOUNTS
  895. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  896. echo "jid=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  897. echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
  898. echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
  899. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  900. echo "muc.service=chat.${DEFAULT_DOMAIN_NAME}" >> $XMPP_CLIENT_ACCOUNTS
  901. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  902. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  903. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  904. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  905. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  906. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  907. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  908. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  909. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  910. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  911. fi
  912. fi
  913. if [ -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  914. echo "[${MY_USERNAME}@${XMPP_ONION_HOSTNAME}]" >> $XMPP_CLIENT_ACCOUNTS
  915. if [[ $ONION_ONLY == 'no' ]]; then
  916. echo 'enabled=false' >> $XMPP_CLIENT_ACCOUNTS
  917. else
  918. echo 'enabled=true' >> $XMPP_CLIENT_ACCOUNTS
  919. fi
  920. echo "jid=${MY_USERNAME}@${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  921. echo "server=$XMPP_ONION_HOSTNAME" >> $XMPP_CLIENT_ACCOUNTS
  922. echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID" >> $XMPP_CLIENT_ACCOUNTS
  923. echo 'resource=profanity' >> $XMPP_CLIENT_ACCOUNTS
  924. echo "muc.service=${XMPP_ONION_HOSTNAME}" >> $XMPP_CLIENT_ACCOUNTS
  925. echo "muc.nick=${MY_USERNAME}" >> $XMPP_CLIENT_ACCOUNTS
  926. echo 'presence.last=online' >> $XMPP_CLIENT_ACCOUNTS
  927. echo 'presence.login=online' >> $XMPP_CLIENT_ACCOUNTS
  928. echo 'priority.online=0' >> $XMPP_CLIENT_ACCOUNTS
  929. echo 'priority.chat=0' >> $XMPP_CLIENT_ACCOUNTS
  930. echo 'priority.away=0' >> $XMPP_CLIENT_ACCOUNTS
  931. echo 'priority.xa=0' >> $XMPP_CLIENT_ACCOUNTS
  932. echo 'priority.dnd=0' >> $XMPP_CLIENT_ACCOUNTS
  933. if [ ${#XMPP_PASSWORD} -gt 2 ]; then
  934. echo "password=$XMPP_PASSWORD" >> $XMPP_CLIENT_ACCOUNTS
  935. fi
  936. fi
  937. if [ ! -d /home/$MY_USERNAME/.config/profanity ]; then
  938. mkdir -p /home/$MY_USERNAME/.config/profanity
  939. fi
  940. echo '[connection]' > /home/$MY_USERNAME/.config/profanity/profrc
  941. echo "account=${MY_USERNAME}@${DEFAULT_DOMAIN_NAME}" >> /home/$MY_USERNAME/.config/profanity/profrc
  942. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.local
  943. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.config
  944. install_completed xmpp_client
  945. }
  946. function install_xmpp {
  947. install_xmpp_main
  948. install_xmpp_client
  949. APP_INSTALLED=1
  950. }
  951. # NOTE: deliberately no exit 0