freedombone-app-xmpp 46KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  1. #!/bin/bash
  2. #
  3. # .---. . .
  4. # | | |
  5. # |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
  6. # | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
  7. # ' ' --' --' -' - -' ' ' -' -' -' ' - --'
  8. #
  9. # Freedom in the Cloud
  10. #
  11. # XMPP functions
  12. #
  13. # The two directories for prosody modules seem necessary.
  14. # Trying to remove /usr/lib/prosody/modules causes problems, and that's
  15. # part of the package install.
  16. #
  17. # License
  18. # =======
  19. #
  20. # Copyright (C) 2014-2018 Bob Mottram <bob@freedombone.net>
  21. #
  22. # This program is free software: you can redistribute it and/or modify
  23. # it under the terms of the GNU Affero General Public License as published by
  24. # the Free Software Foundation, either version 3 of the License, or
  25. # (at your option) any later version.
  26. #
  27. # This program is distributed in the hope that it will be useful,
  28. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  29. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  30. # GNU Affero General Public License for more details.
  31. #
  32. # You should have received a copy of the GNU Affero General Public License
  33. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  34. VARIANTS='full full-vim chat'
  35. IN_DEFAULT_INSTALL=0
  36. SHOW_ON_ABOUT=1
  37. # Directory where XMPP settings are stored
  38. XMPP_DIRECTORY="/var/lib/prosody"
  39. XMPP_PASSWORD=
  40. 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"'
  41. XMPP_ECC_CURVE='"secp384r1"'
  42. prosody_latest_version='0.10'
  43. prosody_nightly=468
  44. prosody_nightly_hash='c72aaab1182a86090188284f443d2f819889ca242d4e955258ef60f4c7c9a1ba'
  45. prosody_filename=prosody-${prosody_latest_version}-1nightly${prosody_nightly}
  46. prosody_nightly_url="https://prosody.im/nightly/${prosody_latest_version}/latest/${prosody_filename}.tar.gz"
  47. # From https://hg.prosody.im/prosody-modules
  48. prosody_modules_filename='prosody-modules-20180322.tar.gz'
  49. prosody_modules_hash='982d0dfcef98e9cb9cee4cc3801b8ce9a503a32e44c32b99df6fe94545b90072'
  50. xmpp_variables=(ONION_ONLY
  51. INSTALLED_WITHIN_DOCKER
  52. XMPP_CIPHERS
  53. XMPP_ECC_CURVE
  54. XMPP_ECC_CURVE
  55. MY_USERNAME
  56. MY_EMAIL_ADDRESS
  57. DEFAULT_DOMAIN_NAME
  58. XMPP_DOMAIN_CODE)
  59. function logging_on_xmpp {
  60. if [ -d /etc/prosody ]; then
  61. if [ ! -d /var/log/prosody ]; then
  62. mkdir /var/log/prosody
  63. chown root:adm /var/log/prosody
  64. fi
  65. if ! grep -q "/var/log/prosody/prosody.log" /etc/prosody/prosody.cfg.lua; then
  66. sed -i 's|info = "/dev/null";|info = "/var/log/prosody/prosody.log";|g' /etc/prosody/prosody.cfg.lua
  67. sed -i 's|error = "/dev/null";|error = "/var/log/prosody/prosody.err";|g' /etc/prosody/prosody.cfg.lua
  68. sed -i 's|levels = { "error" }; to = "/dev/null";|levels = { "error" }; to = "syslog";|g' /etc/prosody/prosody.cfg.lua
  69. fi
  70. fi
  71. }
  72. function logging_off_xmpp {
  73. if [ -d /etc/prosody ]; then
  74. if grep -q "/var/log/prosody/prosody.log" /etc/prosody/prosody.cfg.lua; then
  75. sed -i 's|info = "/var/log/prosody/prosody.log";|info = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  76. sed -i 's|error = "/var/log/prosody/prosody.err";|error = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  77. sed -i 's|levels = { "error" }; to = "syslog";|levels = { "error" }; to = "/dev/null";|g' /etc/prosody/prosody.cfg.lua
  78. $REMOVE_FILES_COMMAND /var/log/prosody/*
  79. rm -rf /var/log/prosody
  80. fi
  81. fi
  82. }
  83. function xmpp_add_onion_address {
  84. domain_name="$1"
  85. onion_address="$2"
  86. if [ ${#domain_name} -eq 0 ]; then
  87. return
  88. fi
  89. if [ ${#onion_address} -eq 0 ]; then
  90. return
  91. fi
  92. if ! grep "${onion_address}" /etc/prosody/prosody.cfg.lua; then
  93. if grep -q "[\"${domain_name}\"]" /etc/prosody/prosody.cfg.lua; then
  94. sed -i "s|[\"${domain_name}\"].*|[\"${domain_name}\"] = \"${onion_address}\";|g" /etc/prosody/prosody.cfg.lua
  95. else
  96. sed -i "/onions_map = {/a [\"${domain_name}\"] = \"${onion_address}\";" /etc/prosody/prosody.cfg.lua
  97. fi
  98. systemctl restart prosody
  99. fi
  100. }
  101. function xmpp_add_onion_address_interactive {
  102. data=$(mktemp 2>/dev/null)
  103. dialog --backtitle $"Freedombone Control Panel" \
  104. --title $"Add an ICANN to Onion domain mapping" \
  105. --form $"Sepecify an ICANN domain name and its equivalent onion address\\n" 9 50 2 \
  106. $"Domain:" 1 1 "" 1 18 26 25 \
  107. $"Onion address:" 2 1 "" 2 18 26 25 \
  108. 2> "$data"
  109. sel=$?
  110. case $sel in
  111. 1) rm -f "$data"
  112. return;;
  113. 255) rm -f "$data"
  114. return;;
  115. esac
  116. domain_name=$(sed -n 1p < "$data")
  117. onion_address=$(sed -n 2p < "$data")
  118. rm -f "$data"
  119. if [[ "$onion_address" != *".onion" ]]; then
  120. return
  121. fi
  122. if [[ "$domain_name" != *"."* ]]; then
  123. return
  124. fi
  125. xmpp_add_onion_address "$domain_name" "$onion_address"
  126. dialog --title $"Add an ICANN to Onion domain mapping" \
  127. --msgbox $"${domain_name} -> ${onion_address} added" 6 70
  128. }
  129. function xmpp_remove_onion_address {
  130. domain_name="$1"
  131. if [ ${#domain_name} -eq 0 ]; then
  132. return
  133. fi
  134. xmpp_changed=
  135. if grep -q "[\"${domain_name}\"]" /etc/prosody/prosody.cfg.lua; then
  136. sed -i "/[\"${domain_name}\"]/d" /etc/prosody/prosody.cfg.lua
  137. xmpp_changed=1
  138. fi
  139. if grep -q "= \"${domain_name}\";" /etc/prosody/prosody.cfg.lua; then
  140. sed -i "/= \"${domain_name}\";/d" /etc/prosody/prosody.cfg.lua
  141. xmpp_changed=1
  142. fi
  143. if [ $xmpp_changed ]; then
  144. systemctl restart prosody
  145. fi
  146. }
  147. function xmpp_remove_onion_address_interactive {
  148. data=$(mktemp 2>/dev/null)
  149. dialog --title $"Remove ICANN to Onion domain mapping" \
  150. --backtitle $"Freedombone Control Panel" \
  151. --inputbox $'Enter the domain name or onion address to be removed' 8 60 2>"$data"
  152. sel=$?
  153. case $sel in
  154. 0) domain_name=$(<"$data")
  155. if [[ "$domain_name" != *"."* ]]; then
  156. rm -f "$data"
  157. return
  158. fi
  159. xmpp_remove_onion_address "$domain_name"
  160. dialog --title $"Remove an ICANN to Onion domain mapping" \
  161. --msgbox $"${domain_name} removed" 6 70
  162. ;;
  163. esac
  164. rm -f "$data"
  165. }
  166. function configure_interactive_xmpp {
  167. W=(1 $"Add an ICANN to onion domain mapping"
  168. 2 $"Remove an ICANN to onion domain mapping")
  169. while true
  170. do
  171. # shellcheck disable=SC2068
  172. selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"XMPP" --menu $"Choose an operation, or ESC to exit:" 10 60 2 "${W[@]}" 3>&2 2>&1 1>&3)
  173. if [ ! "$selection" ]; then
  174. break
  175. fi
  176. case $selection in
  177. 1) xmpp_add_onion_address_interactive;;
  178. 2) xmpp_remove_onion_address_interactive;;
  179. esac
  180. done
  181. }
  182. function remove_user_xmpp {
  183. remove_username="$1"
  184. "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp xmpp
  185. if [[ "$ONION_ONLY" != "no" ]]; then
  186. DOMAIN=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  187. else
  188. DOMAIN=${HOSTNAME}
  189. fi
  190. prosodyctl deluser "${remove_username}@${DOMAIN}"
  191. }
  192. function add_user_xmpp_client {
  193. new_username="$1"
  194. new_user_password="$2"
  195. if [ -f /usr/local/bin/profanity ]; then
  196. XMPP_CLIENT_DIR=/home/$new_username/.local/share/profanity
  197. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  198. if [ ! -d "$XMPP_CLIENT_DIR" ]; then
  199. mkdir -p "$XMPP_CLIENT_DIR"
  200. fi
  201. if [ ! -d "/home/$new_username/.config/profanity" ]; then
  202. mkdir -p "/home/$new_username/.config/profanity"
  203. fi
  204. MY_GPG_PUBLIC_KEY_ID=$(gpg_pubkey_from_email "$new_username" "$new_username@$HOSTNAME")
  205. { echo "[${new_username}@${HOSTNAME}]";
  206. echo 'enabled=true';
  207. echo "jid=${new_username}@${HOSTNAME}";
  208. echo "server=$XMPP_ONION_HOSTNAME";
  209. echo "pgp.keyid=$MY_GPG_PUBLIC_KEY_ID";
  210. echo 'resource=profanity';
  211. echo "muc.service=conference.${HOSTNAME}";
  212. echo "muc.nick=${new_username}";
  213. echo 'presence.last=online';
  214. echo 'presence.login=online';
  215. echo 'priority.online=0';
  216. echo 'priority.chat=0';
  217. echo 'priority.away=0';
  218. echo 'priority.xa=0';
  219. echo 'priority.dnd=0'; } > "$XMPP_CLIENT_ACCOUNTS"
  220. echo '[connection]' > "/home/$new_username/.config/profanity/profrc"
  221. if [[ $ONION_ONLY != "no" ]]; then
  222. echo "account=${new_username}@${XMPP_ONION_HOSTNAME}" >> "/home/$new_username/.config/profanity/profrc"
  223. else
  224. echo "account=${new_username}@${HOSTNAME}" >> "/home/$new_username/.config/profanity/profrc"
  225. fi
  226. { echo '';
  227. echo '[plugins]';
  228. echo 'load=prof_omemo_plugin.py;';
  229. echo '';
  230. echo '[otr]';
  231. echo 'policy=opportunistic';
  232. echo 'log=off';
  233. echo '';
  234. echo '[pgp]';
  235. echo 'log=off';
  236. echo '';
  237. echo '[ui]';
  238. echo 'enc.warn=true'; } >> "/home/$new_username/.config/profanity/profrc"
  239. chown -R "$new_username":"$new_username" "/home/$new_username/.local"
  240. chown -R "$new_username":"$new_username" "/home/$new_username/.config"
  241. fi
  242. }
  243. function add_user_xmpp {
  244. new_username="$1"
  245. new_user_password="$2"
  246. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  247. "${PROJECT_NAME}-pass" -u "$new_username" -a xmpp -p "$new_user_password"
  248. if [[ "$ONION_ONLY" != "no" ]]; then
  249. DOMAIN_NAME=$XMPP_ONION_HOSTNAME
  250. else
  251. DOMAIN_NAME=$HOSTNAME
  252. fi
  253. EMAIL_ADDRESS="$new_username@$DOMAIN_NAME"
  254. if [ ${#new_user_password} -eq 0 ]; then
  255. prosodyctl adduser "$EMAIL_ADDRESS"
  256. else
  257. if ! prosodyctl register "$new_username" "$DOMAIN_NAME" "$new_user_password"; then
  258. exit 653456375
  259. fi
  260. fi
  261. # add the xmpp address to email headers
  262. if [ -f "/home/$new_username/.muttrc" ]; then
  263. if ! grep -q "Jabber-ID" "/home/$new_username/.muttrc"; then
  264. echo "my_hdr Jabber-ID: $EMAIL_ADDRESS" >> "/home/$new_username/.muttrc"
  265. else
  266. sed -i "s|my_hdr Jabber-ID.*|my_hdr Jabber-ID: $EMAIL_ADDRESS|g" "/home/$new_username/.muttrc"
  267. fi
  268. fi
  269. add_user_xmpp_client "$new_username" "$new_user_password"
  270. echo '0'
  271. }
  272. function install_interactive_xmpp {
  273. echo -n ''
  274. APP_INSTALLED=1
  275. }
  276. function change_password_xmpp {
  277. curr_username="$1"
  278. new_user_password="$2"
  279. read_config_param DEFAULT_DOMAIN_NAME
  280. "${PROJECT_NAME}-pass" -u "$curr_username" -a xmpp -p "$new_user_password"
  281. # TODO: this is currently interactive. Really there needs to be a
  282. # non-interactive password change option for prosodyctl
  283. clear
  284. echo ''
  285. echo $'Currently Prosody requires password changes to be done interactively'
  286. prosodyctl passwd "${curr_username}@${DEFAULT_DOMAIN_NAME}"
  287. if [ -f /usr/local/bin/profanity ]; then
  288. XMPP_CLIENT_DIR=/home/$curr_username/.local/share/profanity
  289. XMPP_CLIENT_ACCOUNTS=$XMPP_CLIENT_DIR/accounts
  290. if [ -f "$XMPP_CLIENT_ACCOUNTS" ]; then
  291. sed -i "s|password=.*|password=$new_user_password|g" "$XMPP_CLIENT_ACCOUNTS"
  292. fi
  293. fi
  294. }
  295. function reconfigure_xmpp {
  296. echo -n ''
  297. }
  298. function update_prosody_modules {
  299. if [ ! "$1" ]; then
  300. if [ ! -d /var/lib/prosody/prosody-modules ]; then
  301. return
  302. fi
  303. fi
  304. if [ ! -d /usr/lib/prosody ]; then
  305. return
  306. fi
  307. if [ ! -f "$INSTALL_DIR/$prosody_modules_filename" ]; then
  308. # Obtain the modules
  309. if [ -f ~/freedombone/image_build/$prosody_modules_filename ]; then
  310. cp ~/freedombone/image_build/$prosody_modules_filename "$INSTALL_DIR"
  311. else
  312. if [ -f "/home/$MY_USERNAME/freedombone/image_build/$prosody_modules_filename" ]; then
  313. cp "/home/$MY_USERNAME/freedombone/image_build/$prosody_modules_filename" "$INSTALL_DIR"
  314. fi
  315. fi
  316. if [ -f "$INSTALL_DIR/$prosody_modules_filename" ]; then
  317. cd "$INSTALL_DIR" || exit 246824684
  318. # Check the hash
  319. curr_hash=$(sha256sum "$INSTALL_DIR/$prosody_modules_filename" | awk -F ' ' '{print $1}')
  320. if [[ "$curr_hash" != "$prosody_modules_hash" ]]; then
  321. echo $'Prosody modules hash does not match'
  322. exit 83562
  323. else
  324. # Extract the modules
  325. if [ -d "$INSTALL_DIR/prosody-modules" ]; then
  326. rm -rf "$INSTALL_DIR/prosody-modules"
  327. fi
  328. tar -xzvf $prosody_modules_filename
  329. if [ -d "$INSTALL_DIR/prosody-modules" ]; then
  330. systemctl stop prosody
  331. if [ ! -d /var/lib/prosody/prosody-modules ]; then
  332. mkdir -p /var/lib/prosody/prosody-modules
  333. fi
  334. cp -r "$INSTALL_DIR/prosody-modules/"* /var/lib/prosody/prosody-modules/
  335. cp -r "$INSTALL_DIR/prosody-modules/"* /usr/lib/prosody/modules/
  336. chown -R prosody:prosody /var/lib/prosody/prosody-modules
  337. chown -R prosody:prosody /usr/lib/prosody/modules
  338. systemctl start prosody
  339. else
  340. echo $'Prosody modules not extracted'
  341. exit 72524
  342. fi
  343. fi
  344. fi
  345. fi
  346. if ! grep -q '"vcard"' /etc/prosody/prosody.cfg.lua; then
  347. systemctl stop prosody
  348. sed -i '/"pep"/a "vcard";' /etc/prosody/prosody.cfg.lua
  349. systemctl start prosody
  350. fi
  351. if ! grep -q "omemo_all_access" /etc/prosody/prosody.cfg.lua; then
  352. sed -i '/"pep";/a "omemo_all_access"; -- Fix for PEP with OMEMO' /etc/prosody/prosody.cfg.lua
  353. sed -i 's|"omemo_all_access";| "omemo_all_access";|g' /etc/prosody/prosody.cfg.lua
  354. fi
  355. if ! grep -q "omemo_all_access" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  356. sed -i '/"pep";/a "omemo_all_access"; -- Fix for PEP with OMEMO' /etc/prosody/conf.avail/xmpp.cfg.lua
  357. sed -i 's|"omemo_all_access";| "omemo_all_access";|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  358. fi
  359. }
  360. function prosody_daemon_restart_script {
  361. # On rare occasions the daemon appears to get stuck
  362. # i.e. still active, but not accepting connections
  363. # This ensures that it will unstick itself at least once per day
  364. if [ -f /etc/cron.daily/prosody ]; then
  365. rm /etc/cron.daily/prosody
  366. fi
  367. if [ ! -f /etc/cron.hourly/prosody ]; then
  368. { echo '#!/bin/bash';
  369. echo "is_active=\$(systemctl is-active prosody)";
  370. echo "if [[ \"\$is_active\" != 'active' ]]; then";
  371. echo ' systemctl restart prosody'
  372. echo 'fi'; } > /etc/cron.hourly/prosody
  373. chmod +x /etc/cron.hourly/prosody
  374. fi
  375. }
  376. function upgrade_xmpp {
  377. if [ -d /etc/letsencrypt ]; then
  378. prosody_groups=$(groups prosody)
  379. if [[ "$prosody_groups" != *'ssl-cert'* ]]; then
  380. usermod -a -G ssl-cert prosody
  381. fi
  382. fi
  383. prosody_daemon_restart_script
  384. function_check update_prosody_modules
  385. update_prosody_modules
  386. xmpp_onion_addresses /etc/prosody/prosody.cfg.lua
  387. xmpp_contact_info /etc/prosody/prosody.cfg.lua
  388. if grep -q "/etc/ssl/certs/xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
  389. cp /etc/ssl/certs/xmpp.dhparam /etc/prosody/xmpp.dhparam
  390. chown prosody:prosody /etc/prosody/xmpp.dhparam
  391. sed -i 's|/etc/ssl/certs/xmpp.dhparam|/etc/prosody/xmpp.dhparam|g' /etc/prosody/prosody.cfg.lua
  392. sed -i 's|/etc/ssl/certs/xmpp.dhparam|/etc/prosody/xmpp.dhparam|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  393. fi
  394. if grep -q "/etc/ssl/private/xmpp.key" /etc/prosody/prosody.cfg.lua; then
  395. if [ -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/privkey.pem" ]; then
  396. sed -i "s|/etc/ssl/private/xmpp.key|/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/privkey.pem|g" /etc/prosody/prosody.cfg.lua
  397. fi
  398. fi
  399. if grep -q "/etc/ssl/certs/xmpp.crt" /etc/prosody/prosody.cfg.lua; then
  400. if [ -f "/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem" ]; then
  401. sed -i "s|/etc/ssl/certs/xmpp.crt|/etc/letsencrypt/live/${DEFAULT_DOMAIN_NAME}/fullchain.pem|g" /etc/prosody/prosody.cfg.lua
  402. fi
  403. fi
  404. curr_prosody_filename=$(grep "prosody_filename" "$COMPLETION_FILE" | awk -F ':' '{print $2}')
  405. if [[ "$curr_prosody_filename" != "$prosody_filename" ]]; then
  406. if [ -d "${INSTALL_DIR}/${prosody_filename}" ]; then
  407. # ensure that the binaries have not been overwritten
  408. # by an operating system upgrade
  409. cd "${INSTALL_DIR}/${prosody_filename}" || exit 462846284
  410. make prefix=/usr install
  411. else
  412. cd "$INSTALL_DIR" || exit 23681468
  413. # Try to get the source from the project repo
  414. if [ -f "/root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" ]; then
  415. cp "/root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" .
  416. else
  417. if [ -f "/home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" ]; then
  418. cp "/home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" .
  419. else
  420. wget $prosody_nightly_url
  421. fi
  422. fi
  423. if [ ! -f "${INSTALL_DIR}/${prosody_filename}.tar.gz" ]; then
  424. echo $"Failed to download prosody nightly $prosody_nightly_url"
  425. return
  426. fi
  427. hash_value=$(sha256sum "${INSTALL_DIR}/${prosody_filename}.tar.gz" | awk -F ' ' '{print $1}')
  428. if [[ "$hash_value" != "$prosody_nightly_hash" ]]; then
  429. rm "${INSTALL_DIR}/${prosody_filename}.tar.gz"
  430. echo $'Unexpected hash value for prosody nightly download'
  431. return
  432. fi
  433. tar -xzvf "${INSTALL_DIR}/${prosody_filename}.tar.gz"
  434. cd "${INSTALL_DIR}/${prosody_filename}" || exit 246872468246
  435. ./configure --ostype=debian --prefix=/usr
  436. make prefix=/usr
  437. make prefix=/usr install
  438. if [ -f /usr/local/bin/prosody ]; then
  439. echo $'Failed to build prosody nightly to /usr/bin'
  440. rm "${INSTALL_DIR}/${prosody_filename}.tar.gz"
  441. rm -rf "${INSTALL_DIR:?}/${prosody_filename}"
  442. return
  443. fi
  444. rm "${INSTALL_DIR:?}/${prosody_filename}.tar.gz"
  445. fi
  446. # add onion addresses for known servers
  447. if ! grep -q "onions_map =" /etc/prosody/prosody.cfg.lua; then
  448. echo '' >> /etc/prosody/prosody.cfg.lua
  449. xmpp_onion_addresses /etc/prosody/prosody.cfg.lua
  450. fi
  451. set_completion_param "prosody_filename" "${prosody_filename}"
  452. fi
  453. cp -r "$INSTALL_DIR/prosody-modules/"* /var/lib/prosody/prosody-modules/
  454. chown -R prosody:prosody /var/lib/prosody/prosody-modules
  455. systemctl restart prosody
  456. }
  457. function backup_local_xmpp {
  458. source_directory=/var/lib/prosody
  459. if [ -d $source_directory ]; then
  460. dest_directory=xmpp
  461. function_check backup_directory_to_usb
  462. backup_directory_to_usb $source_directory $dest_directory
  463. fi
  464. }
  465. function restore_local_xmpp {
  466. if [ -d /var/lib/prosody ]; then
  467. echo $"Restoring xmpp settings"
  468. temp_restore_dir=/root/tempxmpp
  469. function_check restore_directory_from_usb
  470. restore_directory_from_usb $temp_restore_dir xmpp
  471. if [ -d $temp_restore_dir/var/lib/prosody ]; then
  472. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  473. else
  474. cp -r $temp_restore_dir/* /var/lib/prosody/
  475. fi
  476. # shellcheck disable=SC2181
  477. if [ ! "$?" = "0" ]; then
  478. function_check set_user_permissions
  479. set_user_permissions
  480. function_check backup_unmount_drive
  481. backup_unmount_drive
  482. exit 725
  483. fi
  484. rm -rf $temp_restore_dir
  485. systemctl restart prosody
  486. chown -R prosody:prosody /var/lib/prosody/*
  487. echo $"Restore of xmpp settings complete"
  488. fi
  489. }
  490. function backup_remote_xmpp {
  491. if [ -d /var/lib/prosody ]; then
  492. echo $"Backing up the xmpp settings"
  493. backup_directory_to_friend /var/lib/prosody xmpp
  494. echo $"Backup of xmpp settings complete"
  495. fi
  496. }
  497. function restore_remote_xmpp {
  498. if [ -d /var/lib/prosody ]; then
  499. echo $"Restoring xmpp settings"
  500. temp_restore_dir=/root/tempxmpp
  501. function_check restore_directory_from_friend
  502. restore_directory_from_friend $temp_restore_dir xmpp
  503. if [ -d $temp_restore_dir/var/lib/prosody ]; then
  504. cp -r $temp_restore_dir/var/lib/prosody/* /var/lib/prosody
  505. else
  506. cp -r $temp_restore_dir/* /var/lib/prosody/
  507. fi
  508. # shellcheck disable=SC2181
  509. if [ ! "$?" = "0" ]; then
  510. exit 725
  511. fi
  512. rm -rf $temp_restore_dir
  513. systemctl restart prosody
  514. chown -R prosody:prosody /var/lib/prosody/*
  515. echo $"Restore of xmpp settings complete"
  516. fi
  517. }
  518. function configure_firewall_for_xmpp {
  519. if [ ! -d /etc/prosody ]; then
  520. return
  521. fi
  522. if [[ $(is_completed "${FUNCNAME[0]}") == "1" ]]; then
  523. return
  524. fi
  525. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  526. # docker does its own firewalling
  527. return
  528. fi
  529. if [[ $ONION_ONLY != "no" ]]; then
  530. return
  531. fi
  532. firewall_add XMPP 5222 tcp
  533. firewall_add XMPP 5223 tcp
  534. firewall_add XMPP 5269 tcp
  535. firewall_add XMPP 5280 tcp
  536. firewall_add XMPP 5281 tcp
  537. mark_completed "${FUNCNAME[0]}"
  538. }
  539. function remove_xmpp {
  540. remove_profanity
  541. remove_movim
  542. firewall_remove 5222 tcp
  543. firewall_remove 5223 tcp
  544. firewall_remove 5269 tcp
  545. firewall_remove 5280 tcp
  546. firewall_remove 5281 tcp
  547. function_check remove_onion_service
  548. remove_onion_service xmpp 5222 5223 5269
  549. sed -i '/HiddenServiceVersion 2/d' /etc/tor/torrc
  550. apt-mark -q unhold prosody
  551. apt-get -yq remove --purge prosody
  552. rm /etc/cron.daily/prosody
  553. if [ -f "$INSTALL_DIR/$prosody_modules_filename" ]; then
  554. rm "$INSTALL_DIR/$prosody_modules_filename"
  555. fi
  556. if [ -d "$INSTALL_DIR/prosody-modules" ]; then
  557. rm -rf "$INSTALL_DIR/prosody-modules"
  558. fi
  559. if [ -d /etc/prosody ]; then
  560. rm -rf /etc/prosody
  561. fi
  562. if [ -d /var/lib/prosody ]; then
  563. rm -rf /var/lib/prosody
  564. fi
  565. if [ -d /usr/lib/prosody ]; then
  566. rm -rf /usr/lib/prosody
  567. fi
  568. if [ -f /usr/local/bin/prosody ]; then
  569. rm /usr/local/bin/prosody
  570. fi
  571. if [ -f /usr/local/bin/prosodyctl ]; then
  572. rm /usr/local/bin/prosodyctl
  573. fi
  574. groupdel prosody
  575. remove_completion_param install_xmpp
  576. sed -i '/xmpp/d' "$COMPLETION_FILE"
  577. sed -i '/prosody/d' "$COMPLETION_FILE"
  578. rm /etc/avahi/services/xmpp.service
  579. rm /etc/avahi/services/xmpp-server.service
  580. systemctl restart avahi-daemon
  581. }
  582. function xmpp_email_headers {
  583. for d in /home/*/ ; do
  584. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  585. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  586. if [ -f "/home/$USERNAME/.muttrc" ]; then
  587. if ! grep -q "Jabber-ID" "/home/$USERNAME/.muttrc"; then
  588. echo "my_hdr Jabber-ID: ${USERNAME}@${HOSTNAME}" >> "/home/$USERNAME/.muttrc"
  589. fi
  590. fi
  591. fi
  592. done
  593. }
  594. function xmpp_contact_info {
  595. filename="$1"
  596. if grep -q "contact_info =" "$filename"; then
  597. return
  598. fi
  599. { echo 'contact_info = {';
  600. echo "abuse = { \"mailto:${MY_EMAIL_ADDRESS}\", \"xmpp:${MY_USERNAME}@${HOSTNAME}\" };";
  601. echo "admin = { \"mailto:${MY_EMAIL_ADDRESS}\", \"xmpp:${MY_USERNAME}@${HOSTNAME}\" };";
  602. echo "feedback = { \"mailto:${MY_EMAIL_ADDRESS}\", \"xmpp:${MY_USERNAME}@${HOSTNAME}\" };";
  603. echo "security = { \"xmpp:${MY_USERNAME}@${HOSTNAME}\" };";
  604. echo "support = { \"xmpp:${MY_USERNAME}@${HOSTNAME}\" };";
  605. echo '};'; } >> "$filename"
  606. }
  607. function xmpp_modules {
  608. filename="$1"
  609. { echo 'modules_enabled = {';
  610. echo ' "server_contact_info";';
  611. echo ' "pubsub";';
  612. echo ' "pubsub_hub";';
  613. echo ' "dialback"; -- s2s dialback support';
  614. echo ' "disco"; -- Service discovery';
  615. echo ' "private"; -- Private XML storage (for room bookmarks, etc.)';
  616. echo ' "version"; -- Replies to server version requests';
  617. echo ' "uptime"; -- Report how long server has been running';
  618. echo ' "time"; -- Let others know the time here on this server';
  619. echo ' "ping"; -- Replies to XMPP pings with pongs';
  620. echo ' "admin_adhoc"; -- Allows administration via an XMPP client that supports ad-hoc commands';
  621. echo ' "posix"; -- POSIX functionality, sends server to background, enables syslog, etc.';
  622. echo ' "bosh"; -- Enable mod_bosh';
  623. echo ' "tls"; -- Enable mod_tls';
  624. echo ' "saslauth"; -- Enable mod_saslauth';
  625. echo ' "onions"; -- Enable chat via onion service';
  626. echo ' "mam"; -- Message archive management';
  627. echo ' "csi"; -- Client state indication';
  628. echo ' "carbons"; -- Message carbons';
  629. echo ' "carbons_adhoc"; -- Message carbons';
  630. echo ' "carbons_copies"; -- Message carbons';
  631. echo ' "smacks"; -- Stream management';
  632. echo ' "smacks_offline"; -- Stream management';
  633. echo ' "pep"; -- Personal Eventing Protocol (to support OMEMO)';
  634. echo ' "omemo_all_access"; -- Fix for PEP with OMEMO';
  635. echo ' "vcard"; -- Personal Eventing Protocol (to support OMEMO)';
  636. echo ' "e2e_policy"; -- To support OMEMO';
  637. echo ' "pep_vcard_avatar"; -- Personal Eventing Protocol (to support OMEMO)';
  638. echo ' "blocklist"; -- Privacy lists';
  639. echo ' "privacy_lists"; -- Privacy lists';
  640. echo ' "blocking"; -- Blocking command';
  641. echo ' "roster"; -- Roster versioning';
  642. echo ' "offline_email"; -- If offline send to email';
  643. echo ' "offline"; -- Store offline messages';
  644. echo ' "http";';
  645. echo ' "http_upload";';
  646. echo ' "websocket";';
  647. echo ' "throttle_presence"; -- Reduce battery and bandwidth usage';
  648. echo ' "filter_chatstates"; -- Reduce battery and bandwidth usage';
  649. echo '};'; } >> "$filename"
  650. }
  651. function xmpp_onion_addresses {
  652. filename="$1"
  653. sed -i '/onions_map = {/,/};/d' "$filename"
  654. { echo 'onions_map = {';
  655. echo ' ["anonymitaet-im-inter.net"] = "rwf5skuv5vqzcdit.onion";';
  656. echo ' ["autistici.org"] = "wi7qkxyrdpu5cmvr.onion";';
  657. echo ' ["jabber.calyxinstitute.org"] = "ijeeynrc6x2uy5ob.onion";';
  658. echo ' ["jabber.ccc.de"] = "okj7xc6j2szr2y75.onion";';
  659. echo ' ["cloak.dk"] = "m2dsl4banuimpm6c.onion";';
  660. echo ' ["jabber.cryptoparty.is"] = "cryjabkbdljzohnp.onion";';
  661. echo ' ["daemons.cf"] = "daemon4jidu2oig6.onion";';
  662. echo ' ["dukgo.com"] = "wlcpmruglhxp6quz.onion";';
  663. echo ' ["evil.im"] = "evilxro6nvjuvxqo.onion";';
  664. echo ' ["xmpp.evil.im"] = "evilxro6nvjuvxqo.onion";';
  665. echo ' ["inventati.org"] = "wi7qkxyrdpu5cmvr.onion";';
  666. echo ' ["jabber.ipredator.se"] = "3iffdebkzzkpgipa.onion";';
  667. echo ' ["jabber-germany.de"] = "dbbrphko5tqcpar3.onion";';
  668. echo ' ["kode.im"] = "ihkw7qy3tok45dun.onion";';
  669. echo ' ["im.koderoot.net"] = "ihkw7qy3tok45dun.onion";';
  670. echo ' ["adb-centralen.se"] = "qai7jjjnhbrdiexf.onion";';
  671. echo ' ["joelpurra.se"] = "37x6i3wgr2jyublb.onion";';
  672. echo ' ["nordberg.se"] = "qai7jjjnhbrdiexf.onion";';
  673. echo ' ["jabber.lqdn.fr"] = "jabber63t4r2qi57.onion";';
  674. echo ' ["jabber.otr.im"] = "5rgdtlawqkcplz75.onion";';
  675. echo ' ["otromundo.cf"] = "arauemwe2utqqzye.onion";';
  676. echo ' ["patchcord.be"] = "xsydhi3dnbjuatpz.onion";';
  677. echo ' ["riseup.net"] = "4cjw6cwpeaeppfqz.onion";';
  678. echo ' ["xmpp.riseup.net"] = "4cjw6cwpeaeppfqz.onion";';
  679. echo ' ["rows.io"] = "yz6yiv2hxyagvwy6.onion";';
  680. echo ' ["xmpp.rows.io"] = "yz6yiv2hxyagvwy6.onion";';
  681. echo ' ["securejabber.me"] = "giyvshdnojeivkom.onion";';
  682. echo ' ["so36.net"] = "s4fgy24e2b5weqdb.onion";';
  683. echo ' ["jabber.so36.net"] = "s4fgy24e2b5weqdb.onion";';
  684. echo ' ["jabber.systemli.org"] = "x5tno6mwkncu5m3h.onion";';
  685. echo ' ["taolo.ga"] = "l3ybpw4vs6ie5rv2.onion";';
  686. echo ' ["tchncs.de"] = "duvfmyqmdlyvc3mi.onion";';
  687. echo ' ["wtfismyip.com"] = "ofkztxcohimx34la.onion";';
  688. echo ' ["prosody.xmpp.is"] = "y2qmqomqpszzryei.onion";';
  689. echo ' ["xndr.de"] = "trcubpttd6zkc3tf.onion";';
  690. echo ' ["jabber.cat"] = "sybzodlxacch7st7.onion";';
  691. echo ' ["trashserver.net"] = "m4c722bvc2r7brnn.onion";';
  692. echo '};'; } >> "$filename"
  693. }
  694. function xmpp_create_config {
  695. echo "admins = { \"$MY_USERNAME@$DEFAULT_DOMAIN_NAME\" }" > /etc/prosody/prosody.cfg.lua
  696. echo 'plugin_paths = { "/var/lib/prosody/prosody-modules" }' >> /etc/prosody/prosody.cfg.lua
  697. echo '' >> /etc/prosody/prosody.cfg.lua
  698. xmpp_modules /etc/prosody/prosody.cfg.lua
  699. echo '' >> /etc/prosody/prosody.cfg.lua
  700. xmpp_onion_addresses /etc/prosody/prosody.cfg.lua
  701. xmpp_contact_info /etc/prosody/prosody.cfg.lua
  702. { echo '';
  703. echo 'allow_registration = false;';
  704. echo '';
  705. echo 'daemonize = true;';
  706. echo '';
  707. echo 'pidfile = "/var/run/prosody/prosody.pid";';
  708. echo '';
  709. echo 'https_ports = { 5281 }';
  710. echo 'https_interfaces = { "*" }';
  711. echo 'https_ssl = {'; } >> /etc/prosody/prosody.cfg.lua
  712. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
  713. echo " certificate = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  714. echo " key = \"/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  715. else
  716. echo " certificate = \"/etc/ssl/certs/xmpp.crt\";" >> /etc/prosody/prosody.cfg.lua
  717. echo " key = \"/etc/ssl/private/xmpp.key\";" >> /etc/prosody/prosody.cfg.lua
  718. fi
  719. { echo " curve = $XMPP_ECC_CURVE;";
  720. echo " ciphers = $XMPP_CIPHERS;";
  721. echo ' options = {"no_sslv2", "no_sslv3" };'; } >> /etc/prosody/prosody.cfg.lua
  722. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
  723. echo " dhparam = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  724. else
  725. echo " dhparam = \"/etc/ssl/certs/xmpp.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  726. fi
  727. { echo "}";
  728. echo '';
  729. echo 'ssl = {'; } >> /etc/prosody/prosody.cfg.lua
  730. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
  731. echo " certificate = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  732. echo " key = \"/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  733. else
  734. echo " certificate = \"/etc/ssl/certs/xmpp.crt\";" >> /etc/prosody/prosody.cfg.lua
  735. echo " key = \"/etc/ssl/private/xmpp.key\";" >> /etc/prosody/prosody.cfg.lua
  736. fi
  737. { echo " curve = $XMPP_ECC_CURVE;";
  738. echo ' depth = "2";';
  739. echo " ciphers = $XMPP_CIPHERS;";
  740. echo ' options = {"no_sslv2", "no_sslv3" };'; } >> /etc/prosody/prosody.cfg.lua
  741. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
  742. echo " dhparam = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  743. else
  744. echo " dhparam = \"/etc/ssl/certs/xmpp.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  745. fi
  746. { echo '}';
  747. echo '';
  748. echo 'c2s_require_encryption = true';
  749. echo 's2s_require_encryption = true';
  750. echo '';
  751. echo 's2s_secure_auth = false';
  752. echo '';
  753. echo 'authentication = "internal_hashed"';
  754. echo '';
  755. echo 'storage = "sql"';
  756. echo 'sql = { driver = "SQLite3", database = "prosody.sqlite" }';
  757. echo '';
  758. echo 'log = {';
  759. echo ' info = "/dev/null";';
  760. echo ' error = "/dev/null";';
  761. echo ' { levels = { "error" }; to = "/dev/null"; };';
  762. echo '}';
  763. echo ''; } >> /etc/prosody/prosody.cfg.lua
  764. if [[ "$ONION_ONLY" != 'no' ]]; then
  765. echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"" >> /etc/prosody/prosody.cfg.lua
  766. else
  767. echo "VirtualHost \"${DEFAULT_DOMAIN_NAME}\"" >> /etc/prosody/prosody.cfg.lua
  768. fi
  769. echo ' ssl = {' >> /etc/prosody/prosody.cfg.lua
  770. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
  771. echo " certificate = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem\";" >> /etc/prosody/prosody.cfg.lua
  772. echo " key = \"/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key\";" >> /etc/prosody/prosody.cfg.lua
  773. else
  774. echo " certificate = \"/etc/ssl/certs/xmpp.crt\";" >> /etc/prosody/prosody.cfg.lua
  775. echo " key = \"/etc/ssl/private/xmpp.key\";" >> /etc/prosody/prosody.cfg.lua
  776. fi
  777. { echo " curve = $XMPP_ECC_CURVE;";
  778. echo ' depth = "2";';
  779. echo " ciphers = $XMPP_CIPHERS;";
  780. echo ' options = {"no_sslv2", "no_sslv3" };'; } >> /etc/prosody/prosody.cfg.lua
  781. if [ -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
  782. echo " dhparam = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  783. else
  784. echo " dhparam = \"/etc/ssl/certs/xmpp.dhparam\";" >> /etc/prosody/prosody.cfg.lua
  785. fi
  786. { echo ' }';
  787. echo '';
  788. echo 'Include "conf.d/*.cfg.lua"';
  789. echo 'http_upload_path = "/var/lib/prosody/http_uploads"';
  790. echo 'http_upload_file_size_limit = 307200';
  791. echo '';
  792. echo "Component \"chat.${DEFAULT_DOMAIN_NAME}\" \"muc\"";
  793. echo ' restrict_room_creation = true';
  794. echo ' name = "Chatrooms"';
  795. echo ' modules_enabled = {';
  796. echo ' "muc_limits";';
  797. echo ' "muc_log";';
  798. echo ' "mam_muc";';
  799. echo ' "muc_log_http";';
  800. echo ' }';
  801. echo 'storage = { muc_log = "sql"; }';
  802. echo 'sql = { driver = "SQLite3", database = "prosody.sqlite" }';
  803. echo 'muc_event_rate = 0.5;';
  804. echo 'muc_burst_factor = 10;';
  805. echo 'muc_log_by_default = false;';
  806. echo 'muc_log_all_rooms = false;';
  807. echo 'max_archive_query_results = 10;';
  808. echo 'max_history_messages = 10;'; } >> /etc/prosody/prosody.cfg.lua
  809. }
  810. function install_xmpp_nightly {
  811. if [ ! -d "$INSTALL_DIR" ]; then
  812. mkdir -p "$INSTALL_DIR"
  813. fi
  814. cd "$INSTALL_DIR" || exit 2468274
  815. # Try to get the source from the project repo
  816. if [ -f "/root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" ]; then
  817. cp "/root/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" .
  818. else
  819. if [ -f "/home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" ]; then
  820. cp "/home/${MY_USERNAME}/${PROJECT_NAME}/image_build/${prosody_filename}.tar.gz" .
  821. else
  822. wget "$prosody_nightly_url"
  823. fi
  824. fi
  825. if [ ! -f "${INSTALL_DIR}/${prosody_filename}.tar.gz" ]; then
  826. echo $"Failed to download prosody nightly $prosody_nightly_url"
  827. exit 78352
  828. fi
  829. hash_value=$(sha256sum "${INSTALL_DIR}/${prosody_filename}.tar.gz" | awk -F ' ' '{print $1}')
  830. if [[ "$hash_value" != "$prosody_nightly_hash" ]]; then
  831. rm "${INSTALL_DIR}/${prosody_filename}.tar.gz"
  832. echo $'Unexpected hash value for prosody nightly download'
  833. exit 68224283
  834. fi
  835. tar -xzvf "${INSTALL_DIR}/${prosody_filename}.tar.gz"
  836. cd "${INSTALL_DIR}/${prosody_filename}" || exit 7246284245
  837. ./configure --ostype=debian --prefix=/usr
  838. make prefix=/usr
  839. make prefix=/usr install
  840. if [ -f /usr/local/bin/prosody ]; then
  841. echo $'Failed to build prosody nightly to /usr/bin'
  842. rm "${INSTALL_DIR}/${prosody_filename}.tar.gz"
  843. rm -rf "${INSTALL_DIR:?}/${prosody_filename}"
  844. exit 628732
  845. fi
  846. rm "${INSTALL_DIR}/${prosody_filename}.tar.gz"
  847. set_completion_param "prosody_filename" "${prosody_filename}"
  848. }
  849. function install_xmpp {
  850. if [ ! -d "$INSTALL_DIR" ]; then
  851. mkdir -p "$INSTALL_DIR"
  852. fi
  853. # remove any existing install attempt
  854. if [ -f "$INSTALL_DIR/$prosody_modules_filename" ]; then
  855. rm "$INSTALL_DIR/$prosody_modules_filename"
  856. fi
  857. if [ -d "$INSTALL_DIR/prosody-modules" ]; then
  858. rm -rf "$INSTALL_DIR/prosody-modules"
  859. fi
  860. update_prosody_modules
  861. # obtain a cert for the default domain
  862. if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}" pem)" == "0" ]]; then
  863. create_site_certificate "${DEFAULT_DOMAIN_NAME}" 'yes'
  864. if [[ "$ONION_ONLY" == 'no' ]]; then
  865. if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}" pem)" == "0" ]]; then
  866. echo $'LetsEncrypt cert could not be obtained for xmpp'
  867. exit 72342
  868. fi
  869. fi
  870. fi
  871. apt-get -yq install lua-sec lua-bitop lua5.1 liblua5.1-dev
  872. apt-get -yq install libidn11-dev libssl-dev lua-dbi-sqlite3
  873. apt-get -yq install mercurial
  874. apt-get -yq install prosody
  875. if [ ! -f /usr/bin/hg ]; then
  876. echo $"Couldn't install mercurial"
  877. exit 52825
  878. fi
  879. if [ ! -d /etc/prosody ]; then
  880. echo $"ERROR: prosody does not appear to have installed. $CHECK_MESSAGE"
  881. exit 52367
  882. fi
  883. groupadd prosody
  884. if [ ! -d /var/lib/prosody/http_uploads ]; then
  885. mkdir -p /var/lib/prosody/http_uploads
  886. fi
  887. if [ ! -d /etc/prosody/conf.d ]; then
  888. mkdir -p /etc/prosody/conf.d
  889. fi
  890. chmod -R 700 /etc/prosody/conf.d
  891. chown -R prosody /var/lib/prosody
  892. chown -R prosody /etc/prosody/conf.d
  893. # install modules
  894. update_prosody_modules initial
  895. if [ ! -d /var/lib/prosody/prosody-modules ]; then
  896. echo $'No prosody modules available'
  897. exit 82634
  898. fi
  899. # create a certificate
  900. if [ ! -f "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem" ]; then
  901. if [ ! -f /etc/ssl/certs/xmpp.crt ]; then
  902. "${PROJECT_NAME}-addcert" -h xmpp --dhkey "${DH_KEYLENGTH}"
  903. CHECK_HOSTNAME=xmpp
  904. check_certificates xmpp
  905. if [ ! -f /etc/ssl/certs/xmpp.crt ]; then
  906. echo $'Failed to create xmpp certificate'
  907. exit 72352
  908. fi
  909. if [ ! -f /etc/ssl/private/xmpp.key ]; then
  910. echo $'Failed to create xmpp private certificate'
  911. exit 36829
  912. fi
  913. chmod g=rX /etc/ssl/private/xmpp.key
  914. chmod g=rX /etc/ssl/certs/xmpp.*
  915. fi
  916. fi
  917. groupadd default
  918. chmod 600 /etc/shadow
  919. chmod 600 /etc/gshadow
  920. usermod -g default prosody
  921. chmod 0000 /etc/shadow
  922. chmod 0000 /etc/gshadow
  923. chown root:default /etc/ssl/private/xmpp.*
  924. chown root:default /etc/ssl/certs/xmpp.*
  925. chown root:default "/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.*"
  926. chown root:default "/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.*"
  927. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  928. if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}" pem)" == "1" ]]; then
  929. sed -i "s|key =.*|key = \"/etc/ssl/private/${DEFAULT_DOMAIN_NAME}.key\";|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  930. sed -i "s|certificate =.*|certificate = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.pem\";|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  931. else
  932. sed -i "s|key =.*|key = \"/etc/ssl/private/xmpp.key\";|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  933. sed -i "s|certificate =.*|certificate = \"/etc/ssl/certs/xmpp.crt\";|g" /etc/prosody/conf.avail/xmpp.cfg.lua
  934. fi
  935. if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  936. if [[ "$(cert_exists "${DEFAULT_DOMAIN_NAME}")" == "1" ]]; then
  937. sed -i "/certificate =/a\\ dhparam = \"/etc/ssl/certs/${DEFAULT_DOMAIN_NAME}.dhparam\";" /etc/prosody/conf.avail/xmpp.cfg.lua
  938. else
  939. sed -i '/certificate =/a\\ dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
  940. fi
  941. fi
  942. if ! grep -q 'options = {"no_sslv2", "no_sslv3" }' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  943. sed -i '/certificate =/a\ options = {"no_sslv2", "no_sslv3" };' /etc/prosody/conf.avail/xmpp.cfg.lua
  944. fi
  945. if ! grep -q 'ciphers =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  946. sed -i "/certificate =/a\\ ciphers = $XMPP_CIPHERS;" /etc/prosody/conf.avail/xmpp.cfg.lua
  947. fi
  948. if ! grep -q 'depth = "2";' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  949. sed -i '/certificate =/a\ depth = "2";' /etc/prosody/conf.avail/xmpp.cfg.lua
  950. fi
  951. if ! grep -q 'curve =' /etc/prosody/conf.avail/xmpp.cfg.lua; then
  952. sed -i "/certificate =/a\\ curve = $XMPP_ECC_CURVE;" /etc/prosody/conf.avail/xmpp.cfg.lua
  953. fi
  954. sed -i "s/example.com/$DEFAULT_DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
  955. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
  956. if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  957. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  958. xmpp_modules /etc/prosody/conf.avail/xmpp.cfg.lua
  959. fi
  960. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  961. if ! grep -q "c2s_require_encryption" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  962. echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  963. else
  964. sed -i 's|c2s_require_encryption.*|c2s_require_encryption = true|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  965. fi
  966. if ! grep -q "s2s_require_encryption" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  967. echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  968. else
  969. sed -i 's|s2s_require_encryption.*|s2s_require_encryption = true|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  970. fi
  971. if ! grep -q "allow_unencrypted_plain_auth" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  972. echo 'allow_unencrypted_plain_auth = false' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  973. else
  974. sed -i 's|allow_unencrypted_plain_auth.*|allow_unencrypted_plain_auth = false|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  975. fi
  976. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  977. if [ ! -d /var/lib/tor ]; then
  978. echo $'No Tor installation found. xmpp onion site cannot be configured.'
  979. exit 877367
  980. fi
  981. if ! grep -q "hidden_service_xmpp" /etc/tor/torrc; then
  982. { echo 'HiddenServiceDir /var/lib/tor/hidden_service_xmpp/';
  983. echo 'HiddenServiceVersion 2';
  984. echo "HiddenServicePort 5222 127.0.0.1:5222";
  985. echo "HiddenServicePort 5269 127.0.0.1:5269"; } >> /etc/tor/torrc
  986. echo $'Added onion site for xmpp chat'
  987. fi
  988. onion_update
  989. wait_for_onion_service 'xmpp'
  990. if [ ! -f /var/lib/tor/hidden_service_xmpp/hostname ]; then
  991. echo $'xmpp onion site hostname not found'
  992. exit 65349
  993. fi
  994. XMPP_ONION_HOSTNAME=$(cat /var/lib/tor/hidden_service_xmpp/hostname)
  995. if ! grep -q "${XMPP_ONION_HOSTNAME}" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  996. { echo '';
  997. echo "VirtualHost \"${XMPP_ONION_HOSTNAME}\"";
  998. echo ' modules_enabled = { "onions" };'; } >> /etc/prosody/conf.avail/xmpp.cfg.lua
  999. fi
  1000. set_completion_param "xmpp onion domain" "${XMPP_ONION_HOSTNAME}"
  1001. if [ -f "$IMAGE_PASSWORD_FILE" ]; then
  1002. XMPP_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
  1003. else
  1004. if [ ${#XMPP_PASSWORD} -lt 8 ]; then
  1005. XMPP_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  1006. fi
  1007. fi
  1008. function_check configure_firewall_for_xmpp
  1009. configure_firewall_for_xmpp
  1010. xmpp_email_headers
  1011. update_default_domain
  1012. xmpp_create_config
  1013. # TODO comment this out after debian supports prosody 0.10 or later
  1014. install_xmpp_nightly
  1015. chown -R prosody /etc/prosody
  1016. chown -R prosody /var/lib/prosody
  1017. chown -R prosody /usr/lib/prosody
  1018. chmod -R 700 /etc/prosody/conf.d
  1019. usermod -a -G www-data prosody
  1020. # Avoid STIG failures
  1021. if [ -f /usr/lib/ssl/private/xmpp.key ]; then
  1022. chown root:root /usr/lib/ssl/private/xmpp.key
  1023. fi
  1024. if [ -f /usr/lib/ssl/certs/xmpp.crt ]; then
  1025. chown root:root /usr/lib/ssl/certs/xmpp.crt
  1026. fi
  1027. if [ -f /usr/lib/ssl/certs/xmpp.dhparam ]; then
  1028. chown root:root /usr/lib/ssl/certs/xmpp.dhparam
  1029. fi
  1030. if [ -d /etc/letsencrypt ]; then
  1031. usermod -a -G ssl-cert prosody
  1032. fi
  1033. if [ -f /etc/ssl/certs/xmpp.dhparam ]; then
  1034. cp /etc/ssl/certs/xmpp.dhparam /etc/prosody/xmpp.dhparam
  1035. chown prosody:prosody /etc/prosody/xmpp.dhparam
  1036. sed -i 's|/etc/ssl/certs/xmpp.dhparam|/etc/prosody/xmpp.dhparam|g' /etc/prosody/prosody.cfg.lua
  1037. sed -i 's|/etc/ssl/certs/xmpp.dhparam|/etc/prosody/xmpp.dhparam|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  1038. fi
  1039. apt-mark -q hold prosody
  1040. systemctl restart prosody
  1041. if [[ $ONION_ONLY != 'no' ]]; then
  1042. prosodyctl register "$MY_USERNAME" "$XMPP_ONION_HOSTNAME" "$XMPP_PASSWORD"
  1043. else
  1044. prosodyctl register "$MY_USERNAME" "$DEFAULT_DOMAIN_NAME" "$XMPP_PASSWORD"
  1045. fi
  1046. # shellcheck disable=SC2181
  1047. if [ ! "$?" = "0" ]; then
  1048. echo ''
  1049. echo ''
  1050. systemctl status prosody -l
  1051. echo ''
  1052. echo ''
  1053. which prosody
  1054. which prosodyctl
  1055. echo ''
  1056. echo ''
  1057. cat /etc/prosody/prosody.cfg.lua
  1058. echo ''
  1059. echo ''
  1060. cat /etc/prosody/conf.avail/xmpp.cfg.lua
  1061. echo ''
  1062. echo ''
  1063. #remove_xmpp
  1064. echo $'Unable to register prosody user'
  1065. exit 347682
  1066. fi
  1067. prosody_daemon_restart_script
  1068. "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a xmpp -p "$XMPP_PASSWORD"
  1069. # Add avahi services
  1070. { echo '<?xml version="1.0" standalone="no"?><!--*-nxml-*-->';
  1071. echo '<!DOCTYPE service-group SYSTEM "avahi-service.dtd">';
  1072. echo '<service-group>';
  1073. echo ' <name replace-wildcards="yes">%h XMPP</name>';
  1074. echo ' <service>';
  1075. echo ' <type>_xmpp._tcp</type>';
  1076. echo " <port>5222</port>";
  1077. echo ' </service>';
  1078. echo ' <service>';
  1079. echo ' <type>_xmpp-server._tcp</type>';
  1080. echo " <port>5269</port>";
  1081. echo ' </service>';
  1082. echo '</service-group>'; } > /etc/avahi/services/xmpp.service
  1083. systemctl restart avahi-daemon
  1084. APP_INSTALLED=1
  1085. }
  1086. # NOTE: deliberately no exit 0