freedombone-app-xmpp 42KB

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