freedombone-app-postactiv 36KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # postactiv application
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 2016-2018 Bob Mottram <bob@freedombone.net>
  15. #
  16. # This program is free software: you can redistribute it and/or modify
  17. # it under the terms of the GNU Affero General Public License as published by
  18. # the Free Software Foundation, either version 3 of the License, or
  19. # (at your option) any later version.
  20. #
  21. # This program is distributed in the hope that it will be useful,
  22. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. # GNU Affero General Public License for more details.
  25. #
  26. # You should have received a copy of the GNU Affero General Public License
  27. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  28. VARIANTS='full full-vim media'
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=1
  31. POSTACTIV_DOMAIN_NAME=
  32. POSTACTIV_CODE=
  33. POSTACTIV_ONION_PORT=8100
  34. POSTACTIV_REPO="http://gitea.postactiv.com/postActiv/postActiv.git"
  35. POSTACTIV_COMMIT='3c88992eeb'
  36. POSTACTIV_ADMIN_PASSWORD=
  37. POSTACTIV_BACKGROUND_IMAGE_URL=
  38. POSTACTIV_TITLE='PostActiv'
  39. # Number of months after which posts expire
  40. POSTACTIV_EXPIRE_MONTHS=3
  41. postactiv_variables=(ONION_ONLY
  42. POSTACTIV_DOMAIN_NAME
  43. POSTACTIV_CODE
  44. DDNS_PROVIDER
  45. MY_USERNAME
  46. POSTACTIV_BACKGROUND_IMAGE_URL
  47. POSTACTIV_EXPIRE_MONTHS
  48. POSTACTIV_TITLE)
  49. function logging_on_postactiv {
  50. echo -n ''
  51. }
  52. function logging_off_postactiv {
  53. echo -n ''
  54. }
  55. function postactiv_customise_logo {
  56. domain_name=$1
  57. if [ -f "/var/www/${domain_name}/htdocs/static/logo.png" ]; then
  58. if [ -f "$HOME/${PROJECT_NAME}/img/postactiv.png" ]; then
  59. cp "$HOME/${PROJECT_NAME}/img/postactiv.png" "/var/www/${domain_name}/htdocs/static/logo.png"
  60. else
  61. if [ -f "/home/$MY_USERNAME/${PROJECT_NAME}/img/postactiv.png" ]; then
  62. cp "/home/$MY_USERNAME/${PROJECT_NAME}/img/postactiv.png" "/var/www/${domain_name}/htdocs/static/logo.png"
  63. fi
  64. fi
  65. fi
  66. }
  67. function remove_user_postactiv {
  68. remove_username="$1"
  69. "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp postactiv
  70. function_check get_completion_param
  71. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  72. if [ -d "/var/www/$POSTACTIV_DOMAIN_NAME" ]; then
  73. cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 3658254254
  74. php scripts/deleteprofile.php -n "$remove_username" -y
  75. fi
  76. }
  77. function add_user_postactiv {
  78. new_username="$1"
  79. new_user_password="$2"
  80. "${PROJECT_NAME}-pass" -u "$new_username" -a postactiv -p "$new_user_password"
  81. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  82. if [ -d "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs" ]; then
  83. cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 346846834
  84. php scripts/registeruser.php -n "$new_username" -w "$new_user_password" -e "$new_username@$HOSTNAME"
  85. "${PROJECT_NAME}-addemail" -u "$new_username" -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
  86. echo '0'
  87. else
  88. echo '1'
  89. fi
  90. }
  91. function install_interactive_postactiv {
  92. if [ ! "$ONION_ONLY" ]; then
  93. ONION_ONLY='no'
  94. fi
  95. if [[ $ONION_ONLY != "no" ]]; then
  96. POSTACTIV_DOMAIN_NAME='postactiv.local'
  97. else
  98. POSTACTIV_DETAILS_COMPLETE=
  99. while [ ! $POSTACTIV_DETAILS_COMPLETE ]
  100. do
  101. data=$(mktemp 2>/dev/null)
  102. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  103. dialog --backtitle $"Freedombone Configuration" \
  104. --title $"PostActiv Configuration" \
  105. --form $"\\nPlease enter your PostActiv details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
  106. $"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  107. $"Title:" 2 1 "$(grep "$POSTACTIV_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  108. $"Background image URL:" 3 1 "$(grep "$POSTACTIV_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  109. $"Code:" 4 1 "$(grep 'POSTACTIV_CODE' temp.cfg | awk -F '=' '{print $2}')" 4 25 33 255 \
  110. 2> "$data"
  111. else
  112. dialog --backtitle $"Freedombone Configuration" \
  113. --title $"PostActiv Configuration" \
  114. --form $"\\nPlease enter your PostActiv details. The background image URL can be left blank.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 16 65 4 \
  115. $"Domain:" 1 1 "$(grep 'POSTACTIV_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
  116. $"Title:" 2 1 "$(grep "$POSTACTIV_TITLE" temp.cfg | awk -F '=' '{print $2}')" 2 25 255 255 \
  117. $"Background image URL:" 3 1 "$(grep "$POSTACTIV_BACKGROUND_IMAGE_URL" temp.cfg | awk -F '=' '{print $2}')" 3 25 255 255 \
  118. 2> "$data"
  119. fi
  120. sel=$?
  121. case $sel in
  122. 1) rm -f "$data"
  123. exit 1;;
  124. 255) rm -f "$data"
  125. exit 1;;
  126. esac
  127. POSTACTIV_DOMAIN_NAME=$(sed -n 1p < "$data")
  128. title=$(sed -n 2p < "$data")
  129. if [ ${#title} -gt 1 ]; then
  130. POSTACTIV_TITLE=$title
  131. fi
  132. img_url=$(sed -n 3p < "$data")
  133. if [ ${#img_url} -gt 1 ]; then
  134. POSTACTIV_BACKGROUND_IMAGE_URL=$img_url
  135. fi
  136. if [ "$POSTACTIV_DOMAIN_NAME" ]; then
  137. if [[ "$POSTACTIV_DOMAIN_NAME" == "$HUBZILLA_DOMAIN_NAME" ]]; then
  138. POSTACTIV_DOMAIN_NAME=""
  139. fi
  140. TEST_DOMAIN_NAME=$POSTACTIV_DOMAIN_NAME
  141. validate_domain_name
  142. if [[ "$TEST_DOMAIN_NAME" != "$POSTACTIV_DOMAIN_NAME" ]]; then
  143. POSTACTIV_DOMAIN_NAME=
  144. dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
  145. else
  146. if [[ $DDNS_PROVIDER == "default@freedns.afraid.org" ]]; then
  147. POSTACTIV_CODE=$(sed -n 4p < "$data")
  148. validate_freedns_code "$POSTACTIV_CODE"
  149. if [ ! "$VALID_CODE" ]; then
  150. POSTACTIV_DOMAIN_NAME=
  151. fi
  152. fi
  153. fi
  154. fi
  155. if [ $POSTACTIV_DOMAIN_NAME ]; then
  156. POSTACTIV_DETAILS_COMPLETE="yes"
  157. fi
  158. rm -f "$data"
  159. done
  160. # remove any invalid characters
  161. if [ ${#POSTACTIV_TITLE} -gt 0 ]; then
  162. new_title=${POSTACTIV_TITLE//\'/}
  163. POSTACTIV_TITLE="$new_title"
  164. fi
  165. # save the results in the config file
  166. write_config_param "POSTACTIV_CODE" "$POSTACTIV_CODE"
  167. write_config_param "POSTACTIV_TITLE" "$POSTACTIV_TITLE"
  168. write_config_param "POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_BACKGROUND_IMAGE_URL"
  169. fi
  170. write_config_param "POSTACTIV_DOMAIN_NAME" "$POSTACTIV_DOMAIN_NAME"
  171. APP_INSTALLED=1
  172. }
  173. function change_password_postactiv {
  174. curr_username="$1"
  175. new_user_password="$2"
  176. read_config_param 'POSTACTIV_DOMAIN_NAME'
  177. cd "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts" || exit 246824682
  178. php setpassword.php "$curr_username" "$new_user_password"
  179. "${PROJECT_NAME}-pass" -u "$curr_username" -a postactiv -p "$new_user_password"
  180. }
  181. function postactiv_create_database {
  182. if [ -f "$IMAGE_PASSWORD_FILE" ]; then
  183. POSTACTIV_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
  184. else
  185. if [ ! "$POSTACTIV_ADMIN_PASSWORD" ]; then
  186. POSTACTIV_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  187. fi
  188. fi
  189. if [ ! "$POSTACTIV_ADMIN_PASSWORD" ]; then
  190. return
  191. fi
  192. function_check create_database
  193. create_database postactiv "$POSTACTIV_ADMIN_PASSWORD" "$MY_USERNAME"
  194. }
  195. function postactiv_running_script {
  196. gnusocial_hourly_script postactiv $POSTACTIV_DOMAIN_NAME
  197. # This was a hack to fix a bug in master, but may no longer be needed
  198. #echo "if ! grep -q \"//define('POSTACTIV',true);\" scripts/commandline.inc; then" >> /etc/cron.hourly/postactiv-daemons
  199. #echo " sed -i \"s|define('POSTACTIV',true);|//define('POSTACTIV',true);|g\" scripts/commandline.inc" >> /etc/cron.hourly/postactiv-daemons
  200. #echo 'fi' >> /etc/cron.hourly/postactiv-daemons
  201. }
  202. function reconfigure_postactiv {
  203. echo -n ''
  204. }
  205. function postactiv_set_background_image {
  206. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  207. data=$(mktemp 2>/dev/null)
  208. dialog --title $"PostActiv" \
  209. --backtitle $"Freedombone Control Panel" \
  210. --inputbox $'Set a background image URL' 10 60 2>"$data"
  211. sel=$?
  212. case $sel in
  213. 0)
  214. temp_background=$(<"$data")
  215. if [ ${#temp_background} -gt 0 ]; then
  216. POSTACTIV_BACKGROUND_IMAGE_URL="$temp_background"
  217. write_config_param "POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_BACKGROUND_IMAGE_URL"
  218. if [[ $(pleroma_set_background_image_from_url "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE" | tail -n 1) == "0" ]]; then
  219. dialog --title $"Set PostActiv background" \
  220. --msgbox $"The background image has been set" 6 60
  221. fi
  222. fi
  223. ;;
  224. esac
  225. rm -f "$data"
  226. }
  227. function postactiv_set_title {
  228. data=$(mktemp 2>/dev/null)
  229. dialog --title $"PostActiv" \
  230. --backtitle $"Freedombone Control Panel" \
  231. --inputbox $'Set a title' 10 60 2>"$data"
  232. sel=$?
  233. case $sel in
  234. 0)
  235. new_title=$(<"$data")
  236. if [ ${#new_title} -gt 0 ]; then
  237. POSTACTIV_TITLE="$new_title"
  238. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  239. write_config_param "POSTACTIV_TITLE" "$POSTACTIV_TITLE"
  240. cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/static" || exit 782452452
  241. sed -i "s|\"name\":.*|\"name\": \"${POSTACTIV_TITLE}\",|g" config.json
  242. dialog --title $"Set PostActiv title" \
  243. --msgbox $"The title has been set" 6 60
  244. fi
  245. ;;
  246. esac
  247. rm -f "$data"
  248. }
  249. function postactiv_set_expire_months {
  250. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  251. read_config_param "POSTACTIV_EXPIRE_MONTHS"
  252. data=$(mktemp 2>/dev/null)
  253. dialog --title $"PostActiv" \
  254. --backtitle $"Freedombone Control Panel" \
  255. --inputbox $'Set an expiry period for posts in months. Anything older will be deleted. Lower values help to keep the database size small and as fast as possible.' 12 60 "$POSTACTIV_EXPIRE_MONTHS" 2>"$data"
  256. sel=$?
  257. case $sel in
  258. 0)
  259. new_expiry_months=$(<"$data")
  260. if [ ${#new_expiry_months} -gt 0 ]; then
  261. # should contain no spaces
  262. if [[ "$new_expiry_months" == *" "* ]]; then
  263. return
  264. fi
  265. # should be a number
  266. re='^[0-9]+$'
  267. if ! [[ $new_expiry_months =~ $re ]] ; then
  268. return
  269. fi
  270. # set the new value
  271. POSTACTIV_EXPIRE_MONTHS=$new_expiry_months
  272. write_config_param "POSTACTIV_EXPIRE_MONTHS" "$POSTACTIV_EXPIRE_MONTHS"
  273. expire_gnusocial_posts "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_EXPIRE_MONTHS"
  274. dialog --title $"Set PostActiv post expiry period" \
  275. --msgbox $"Expiry period set to $POSTACTIV_EXPIRE_MONTHS months" 6 60
  276. fi
  277. ;;
  278. esac
  279. rm -f "$data"
  280. }
  281. function configure_interactive_postactiv {
  282. read_config_param "POSTACTIV_EXPIRE_MONTHS"
  283. while true
  284. do
  285. W=(1 $"Set a background image"
  286. 2 $"Set the title"
  287. 3 $"Set post expiry period (currently $POSTACTIV_EXPIRE_MONTHS months)"
  288. 4 $"Select Qvitter user interface"
  289. 5 $"Select Pleroma user interface"
  290. 6 $"Select Classic user interface")
  291. # shellcheck disable=SC2068
  292. selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"PostActiv" --menu $"Choose an operation, or ESC to exit:" 15 60 6 "${W[@]}" 3>&2 2>&1 1>&3)
  293. if [ ! "$selection" ]; then
  294. break
  295. fi
  296. case $selection in
  297. 1) postactiv_set_background_image;;
  298. 2) postactiv_set_title;;
  299. 3) postactiv_set_expire_months;;
  300. 4) gnusocial_use_qvitter postactiv;;
  301. 5) gnusocial_use_pleroma postactiv;;
  302. 6) gnusocial_use_classic postactiv;;
  303. esac
  304. done
  305. }
  306. function upgrade_postactiv {
  307. CURR_POSTACTIV_COMMIT=$(get_completion_param "postactiv commit")
  308. if [[ "$CURR_POSTACTIV_COMMIT" == "$POSTACTIV_COMMIT" ]]; then
  309. return
  310. fi
  311. if grep -q "postactiv domain" "$COMPLETION_FILE"; then
  312. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  313. fi
  314. # update to the next commit
  315. function_check set_repo_commit
  316. set_repo_commit "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" "postactiv commit" "$POSTACTIV_COMMIT" $POSTACTIV_REPO
  317. # Ensure that installation script is removed
  318. if [ -f "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php" ]; then
  319. rm "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php"
  320. fi
  321. if [ -f "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index_qvitter.php" ]; then
  322. if [ -f "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index.php" ]; then
  323. # shellcheck disable=SC2086
  324. mv /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index.php /var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/index_qvitter.php
  325. fi
  326. fi
  327. function_check postactiv_running_script
  328. postactiv_running_script
  329. gnusocial_block_user_script
  330. gnusocial_block_domain_script postactiv "$POSTACTIV_DOMAIN_NAME"
  331. upgrade_pleroma_frontend "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
  332. postactiv_customise_logo "$POSTACTIV_DOMAIN_NAME"
  333. install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
  334. chown -R www-data:www-data "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs"
  335. systemctl restart mariadb
  336. }
  337. function backup_local_postactiv {
  338. POSTACTIV_DOMAIN_NAME='postactiv'
  339. if grep -q "postactiv domain" "$COMPLETION_FILE"; then
  340. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  341. fi
  342. # don't backup more data than we need to
  343. /etc/cron.daily/postactiv-expire
  344. source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/backup
  345. if [ ! -d "$source_directory" ]; then
  346. mkdir "$source_directory"
  347. fi
  348. cp -p "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/config.php" "$source_directory"
  349. if [ -d "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static" ]; then
  350. cp -rp "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static" "$source_directory"
  351. fi
  352. function_check suspend_site
  353. suspend_site "${POSTACTIV_DOMAIN_NAME}"
  354. function_check backup_directory_to_usb
  355. dest_directory=postactivconfig
  356. backup_directory_to_usb "$source_directory" "$dest_directory"
  357. source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/file
  358. dest_directory=postactivfile
  359. backup_directory_to_usb "$source_directory" "$dest_directory"
  360. function_check backup_database_to_usb
  361. backup_database_to_usb postactiv
  362. function_check restart_site
  363. restart_site
  364. }
  365. function restore_local_postactiv {
  366. if ! grep -q "postactiv domain" "$COMPLETION_FILE"; then
  367. return
  368. fi
  369. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  370. if [ "$POSTACTIV_DOMAIN_NAME" ]; then
  371. echo $"Restoring postactiv"
  372. temp_restore_dir=/root/temppostactiv
  373. postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
  374. # stop the daemons
  375. cd "$postactiv_dir" || exit 468246242
  376. scripts/stopdaemons.sh
  377. function_check postactiv_create_database
  378. postactiv_create_database
  379. restore_database postactiv
  380. if [ -d $temp_restore_dir ]; then
  381. rm -rf $temp_restore_dir
  382. fi
  383. function_check restore_directory_from_usb
  384. restore_directory_from_usb $temp_restore_dir postactivconfig
  385. if [ -d $temp_restore_dir ]; then
  386. if [ -d "$temp_restore_dir$postactiv_dir" ]; then
  387. cp "$temp_restore_dir$postactiv_dir/backup/config.php" "$postactiv_dir/"
  388. cp -rp "$temp_restore_dir$postactiv_dir/static" "$postactiv_dir/"
  389. else
  390. cp "$temp_restore_dir/backup/config.php" "$postactiv_dir/"
  391. if [ ! -d "$postactiv_dir/static" ]; then
  392. mkdir "$postactiv_dir/static"
  393. fi
  394. cp -rp "$temp_restore_dir/static/"* "$postactiv_dir/static/"
  395. fi
  396. chown www-data:www-data "$postactiv_dir/config.php"
  397. chown -R www-data:www-data "$postactiv_dir/static"
  398. rm -rf $temp_restore_dir
  399. fi
  400. restore_directory_from_usb $temp_restore_dir postactivfile
  401. if [ -d $temp_restore_dir ]; then
  402. if [ -d "$temp_restore_dir$postactiv_dir/file" ]; then
  403. cp -rp "$temp_restore_dir$postactiv_dir/file" "$postactiv_dir/"
  404. else
  405. if [ ! -d "$postactiv_dir/file" ]; then
  406. mkdir "$postactiv_dir/file"
  407. fi
  408. cp -rp "$temp_restore_dir/"* "$postactiv_dir/file/"
  409. fi
  410. chown -R www-data:www-data "$postactiv_dir/file"
  411. rm -rf $temp_restore_dir
  412. fi
  413. gnusocial_update_after_restore postactiv "${POSTACTIV_DOMAIN_NAME}"
  414. echo $"Restore of postactiv complete"
  415. fi
  416. }
  417. function backup_remote_postactiv {
  418. POSTACTIV_DOMAIN_NAME='postactiv'
  419. if grep -q "postactiv domain" "$COMPLETION_FILE"; then
  420. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  421. fi
  422. # don't backup more data than we need to
  423. /etc/cron.daily/postactiv-expire
  424. source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/backup
  425. if [ ! -d "$source_directory" ]; then
  426. mkdir "$source_directory"
  427. fi
  428. cp -p "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/config.php" "$source_directory"
  429. if [ -d "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static" ]; then
  430. cp -rp "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static" "$source_directory"
  431. fi
  432. function_check suspend_site
  433. suspend_site "${POSTACTIV_DOMAIN_NAME}"
  434. function_check backup_directory_to_friend
  435. dest_directory=postactivconfig
  436. backup_directory_to_friend "$source_directory" "$dest_directory"
  437. source_directory=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/file
  438. dest_directory=postactivfile
  439. backup_directory_to_friend "$source_directory" "$dest_directory"
  440. function_check backup_database_to_friend
  441. backup_database_to_friend postactiv
  442. function_check restart_site
  443. restart_site
  444. }
  445. function restore_remote_postactiv {
  446. if ! grep -q "postactiv domain" "$COMPLETION_FILE"; then
  447. return
  448. fi
  449. POSTACTIV_DOMAIN_NAME=$(get_completion_param "postactiv domain")
  450. if [ "$POSTACTIV_DOMAIN_NAME" ]; then
  451. echo $"Restoring postactiv"
  452. temp_restore_dir=/root/temppostactiv
  453. postactiv_dir=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs
  454. # stop the daemons
  455. cd "$postactiv_dir" || exit 24682464
  456. scripts/stopdaemons.sh
  457. function_check postactiv_create_database
  458. postactiv_create_database
  459. function_check restore_database_from_friend
  460. restore_database_from_friend postactiv
  461. if [ -d $temp_restore_dir ]; then
  462. rm -rf $temp_restore_dir
  463. fi
  464. function_check restore_directory_from_friend
  465. restore_directory_from_friend $temp_restore_dir postactivconfig
  466. if [ -d $temp_restore_dir ]; then
  467. if [ -d "$temp_restore_dir$postactiv_dir" ]; then
  468. cp "$temp_restore_dir$postactiv_dir/backup/config.php" "$postactiv_dir/"
  469. cp -rp "$temp_restore_dir$postactiv_dir/static" "$postactiv_dir/"
  470. else
  471. cp "$temp_restore_dir/config.php" "$postactiv_dir/"
  472. if [ ! -d "$postactiv_dir/static" ]; then
  473. mkdir "$postactiv_dir/static"
  474. fi
  475. cp -rp "$temp_restore_dir/static/"* "$postactiv_dir/static/"
  476. fi
  477. chown www-data:www-data "$postactiv_dir/config.php"
  478. chown -R www-data:www-data "$postactiv_dir/static"
  479. rm -rf $temp_restore_dir
  480. fi
  481. restore_directory_from_friend $temp_restore_dir postactivfile
  482. if [ -d $temp_restore_dir ]; then
  483. if [ -d "$temp_restore_dir$postactiv_dir/file" ]; then
  484. cp -rp "$temp_restore_dir$postactiv_dir/file" "$postactiv_dir/"
  485. else
  486. if [ ! -d "$postactiv_dir/file" ]; then
  487. mkdir "$postactiv_dir/file"
  488. fi
  489. cp -rp "$temp_restore_dir/"* "$postactiv_dir/file/"
  490. fi
  491. chown -R www-data:www-data "$postactiv_dir/file"
  492. rm -rf $temp_restore_dir
  493. fi
  494. gnusocial_update_after_restore postactiv "${POSTACTIV_DOMAIN_NAME}"
  495. echo $"Restore of postactiv complete"
  496. fi
  497. }
  498. function remove_postactiv {
  499. if [ ${#POSTACTIV_DOMAIN_NAME} -eq 0 ]; then
  500. return
  501. fi
  502. function_check remove_nodejs
  503. remove_nodejs pleroma-postactiv
  504. read_config_param "POSTACTIV_DOMAIN_NAME"
  505. read_config_param "MY_USERNAME"
  506. echo "Removing $POSTACTIV_DOMAIN_NAME"
  507. nginx_dissite "$POSTACTIV_DOMAIN_NAME"
  508. remove_certs "$POSTACTIV_DOMAIN_NAME"
  509. if [ -f /etc/cron.hourly/postactiv-daemons ]; then
  510. rm /etc/cron.hourly/postactiv-daemons
  511. fi
  512. if [ -f "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/stopdaemons.sh" ]; then
  513. cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 2467245248
  514. scripts/stopdaemons.sh
  515. fi
  516. kill_pid=$(pgrep "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/queuedaemon.php" | head -n 1)
  517. kill -9 "$kill_pid"
  518. if [ -d "/var/www/$POSTACTIV_DOMAIN_NAME" ]; then
  519. rm -rf "/var/www/$POSTACTIV_DOMAIN_NAME"
  520. fi
  521. if [ -f "/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME" ]; then
  522. rm "/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME"
  523. fi
  524. function_check drop_database
  525. drop_database postactiv
  526. function_check remove_onion_service
  527. remove_onion_service postactiv ${POSTACTIV_ONION_PORT}
  528. if grep -q "postactiv" /etc/crontab; then
  529. sed -i "/postactiv/d" /etc/crontab
  530. fi
  531. remove_app postactiv
  532. remove_completion_param install_postactiv
  533. sed -i '/postactiv/d' "$COMPLETION_FILE"
  534. remove_backup_database_local postactiv
  535. sed -i '/postactiv-firewall/d' /etc/crontab
  536. sed -i 's|mysqli.allow_persistent.*|mysqli.allow_persistent = On|g' /etc/php/7.0/cli/php.ini
  537. sed -i 's|mysqli.reconnect.*|mysqli.reconnect = Off|g' /etc/php/7.0/cli/php.ini
  538. if [ -f /usr/bin/postactiv-firewall ]; then
  539. rm /usr/bin/postactiv-firewall
  540. fi
  541. function_check remove_ddns_domain
  542. remove_ddns_domain "$POSTACTIV_DOMAIN_NAME"
  543. }
  544. function install_postactiv_main {
  545. if [ ! "$POSTACTIV_DOMAIN_NAME" ]; then
  546. echo $'No domain name was given for postactiv'
  547. exit 7359
  548. fi
  549. if [[ $(app_is_installed postactiv_main) == "1" ]]; then
  550. return
  551. fi
  552. function_check postactiv_running_script
  553. postactiv_running_script
  554. function_check install_mariadb
  555. install_mariadb
  556. function_check get_mariadb_password
  557. get_mariadb_password
  558. function_check repair_databases_script
  559. repair_databases_script
  560. apt-get -yq install php-gettext php-curl php-gd php-mysql git curl
  561. apt-get -yq install memcached php-memcached php-intl exiftool libfcgi0ldbl
  562. apt-get -yq install php7.0-bcmath php7.0-curl php7.0-exif php7.0-gd
  563. apt-get -yq install php7.0-intl php7.0-mbstring php7.0-mysqlnd
  564. apt-get -yq install php7.0-opcache php7.0-readline php7.0-xmlwriter
  565. if [ ! -d "/var/www/$POSTACTIV_DOMAIN_NAME" ]; then
  566. mkdir "/var/www/$POSTACTIV_DOMAIN_NAME"
  567. fi
  568. if [ ! -d "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" ]; then
  569. if [ -d /repos/postactiv ]; then
  570. mkdir "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
  571. cp -r -p /repos/postactiv/. "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
  572. cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 46824682682
  573. git pull
  574. else
  575. # This is deliberately non-recursive
  576. git clone "$POSTACTIV_REPO" "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
  577. fi
  578. if [ ! -d "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" ]; then
  579. echo $'Unable to clone postactiv repo'
  580. exit 87525
  581. fi
  582. fi
  583. cd "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" || exit 46287462828
  584. git checkout $POSTACTIV_COMMIT -b $POSTACTIV_COMMIT
  585. set_completion_param "postactiv commit" "$POSTACTIV_COMMIT"
  586. chmod g+w "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
  587. chmod a+w "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/avatar"
  588. chmod a+w "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/file"
  589. chown -R www-data:www-data "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs"
  590. chmod +x "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php"
  591. chmod 755 "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Serializer.php"
  592. chmod -x "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/extlib/HTMLPurifier/HTMLPurifier/DefinitionCache/Serializer.php"
  593. function_check postactiv_create_database
  594. postactiv_create_database
  595. if [ ! -f "/etc/aliases" ]; then
  596. touch /etc/aliases
  597. fi
  598. if ! grep -q "www-data: root" /etc/aliases; then
  599. echo 'www-data: root' >> /etc/aliases
  600. fi
  601. if ! grep -q "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" /etc/aliases; then
  602. echo "*: /var/www/$POSTACTIV_DOMAIN_NAME/htdocs/scripts/maildaemon.php" >> /etc/aliases
  603. fi
  604. function_check add_ddns_domain
  605. add_ddns_domain "$POSTACTIV_DOMAIN_NAME"
  606. POSTACTIV_ONION_HOSTNAME=$(add_onion_service postactiv 80 ${POSTACTIV_ONION_PORT})
  607. postactiv_nginx_site=/etc/nginx/sites-available/$POSTACTIV_DOMAIN_NAME
  608. if [[ $ONION_ONLY == "no" ]]; then
  609. function_check nginx_http_redirect
  610. nginx_http_redirect "$POSTACTIV_DOMAIN_NAME" "index index.php"
  611. { echo 'server {';
  612. echo ' listen 443 ssl;';
  613. echo ' #listen [::]:443 ssl;';
  614. echo " server_name $POSTACTIV_DOMAIN_NAME;";
  615. echo ''; } >> "$postactiv_nginx_site"
  616. function_check nginx_compress
  617. nginx_compress "$POSTACTIV_DOMAIN_NAME"
  618. echo '' >> "$postactiv_nginx_site"
  619. echo ' # Security' >> "$postactiv_nginx_site"
  620. function_check nginx_ssl
  621. nginx_ssl "$POSTACTIV_DOMAIN_NAME"
  622. function_check nginx_security_options
  623. nginx_security_options "$POSTACTIV_DOMAIN_NAME"
  624. { echo ' add_header Strict-Transport-Security max-age=15768000;';
  625. echo '';
  626. echo ' # Logs';
  627. echo ' access_log /dev/null;';
  628. echo ' error_log /dev/null;';
  629. echo '';
  630. echo ' # Root';
  631. echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;";
  632. echo '';
  633. echo ' # Index';
  634. echo ' index index.php;';
  635. echo '';
  636. echo ' # PHP';
  637. echo ' location ~ \.php {';
  638. echo ' client_max_body_size 50m;';
  639. echo ' client_body_buffer_size 50m;';
  640. echo ' include snippets/fastcgi-php.conf;';
  641. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
  642. echo ' fastcgi_read_timeout 30;';
  643. echo ' }';
  644. echo '';
  645. echo ' # Location';
  646. echo ' location / {'; } >> "$postactiv_nginx_site"
  647. function_check nginx_limits
  648. nginx_limits "$POSTACTIV_DOMAIN_NAME" '15m'
  649. { echo " try_files \$uri \$uri/ @postactiv;";
  650. echo ' }';
  651. echo '';
  652. echo ' # Fancy URLs';
  653. echo ' location @postactiv {';
  654. echo ' client_max_body_size 50m;';
  655. echo ' client_body_buffer_size 50m;';
  656. echo " rewrite ^(.*)\$ /index.php?p=\$1 last;";
  657. echo ' }';
  658. echo '';
  659. echo ' # Restrict access that is unnecessary anyway';
  660. echo ' location ~ /\.(ht|git) {';
  661. echo ' deny all;';
  662. echo ' }';
  663. echo '}'; } >> "$postactiv_nginx_site"
  664. else
  665. echo -n '' > "$postactiv_nginx_site"
  666. fi
  667. { echo 'server {';
  668. echo " listen 127.0.0.1:$POSTACTIV_ONION_PORT default_server;";
  669. echo " server_name $POSTACTIV_ONION_HOSTNAME;";
  670. echo ''; } >> "$postactiv_nginx_site"
  671. function_check nginx_security_options
  672. nginx_security_options "$POSTACTIV_DOMAIN_NAME"
  673. echo '' >> "$postactiv_nginx_site"
  674. function_check nginx_compress
  675. nginx_compress "$POSTACTIV_DOMAIN_NAME"
  676. { echo '';
  677. echo ' # Logs';
  678. echo ' access_log /dev/null;';
  679. echo ' error_log /dev/null;';
  680. echo '';
  681. echo ' # Root';
  682. echo " root /var/www/$POSTACTIV_DOMAIN_NAME/htdocs;";
  683. echo '';
  684. echo ' # Index';
  685. echo ' index index.php;';
  686. echo '';
  687. echo ' # PHP';
  688. echo ' location ~ \.php {';
  689. echo ' client_max_body_size 50m;';
  690. echo ' client_body_buffer_size 50m;';
  691. echo ' include snippets/fastcgi-php.conf;';
  692. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
  693. echo ' fastcgi_read_timeout 30;';
  694. echo ' }';
  695. echo '';
  696. echo ' # Location';
  697. echo ' location / {'; } >> "$postactiv_nginx_site"
  698. function_check nginx_limits
  699. nginx_limits "$POSTACTIV_DOMAIN_NAME" '15m'
  700. { echo " try_files \$uri \$uri/ @postactiv;";
  701. echo ' }';
  702. echo '';
  703. echo ' # Fancy URLs';
  704. echo ' location @postactiv {';
  705. echo ' client_max_body_size 50m;';
  706. echo ' client_body_buffer_size 50m;';
  707. echo " rewrite ^(.*)\$ /index.php?p=\$1 last;";
  708. echo ' }';
  709. echo '';
  710. echo ' # Restrict access that is unnecessary anyway';
  711. echo ' location ~ /\.(ht|git) {';
  712. echo ' deny all;';
  713. echo ' }';
  714. echo '}'; } >> "$postactiv_nginx_site"
  715. function_check gnusocial_set_limits
  716. gnusocial_set_limits "$postactiv_nginx_site"
  717. function_check configure_php
  718. configure_php
  719. function_check create_site_certificate
  720. create_site_certificate "$POSTACTIV_DOMAIN_NAME" 'yes'
  721. # Ensure that the database gets backed up locally, if remote
  722. # backups are not being used
  723. function_check backup_databases_script_header
  724. backup_databases_script_header
  725. function_check backup_database_local
  726. backup_database_local postactiv
  727. function_check nginx_ensite
  728. nginx_ensite "$POSTACTIV_DOMAIN_NAME"
  729. # NOTE: For the typical case always enable SSL and only
  730. # disable it if in onion only mode. This is due to complexities
  731. # with the way URLs are generated by postactiv
  732. postactiv_ssl='always'
  733. if [[ $ONION_ONLY != 'no' ]]; then
  734. postactiv_ssl='never'
  735. fi
  736. POSTACTIV_SERVER=${POSTACTIV_DOMAIN_NAME}
  737. if [[ $ONION_ONLY != 'no' ]]; then
  738. POSTACTIV_SERVER=${POSTACTIV_ONION_HOSTNAME}
  739. fi
  740. # Create the configuration
  741. postactiv_installer=/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/scripts/install_cli.php
  742. if [ ! -f "$postactiv_installer" ]; then
  743. rm -rf "/var/www/$POSTACTIV_DOMAIN_NAME"
  744. echo $'No postactiv commandline installer found'
  745. exit 53026
  746. fi
  747. ${postactiv_installer} --server "${POSTACTIV_SERVER}" \
  748. --host="localhost" --database="postactiv" \
  749. --dbtype=mysql --username="root" -v \
  750. --password="$MARIADB_PASSWORD" \
  751. --sitename=$"postactiv" --fancy='yes' \
  752. --admin-nick="$MY_USERNAME" \
  753. --admin-pass="$POSTACTIV_ADMIN_PASSWORD" \
  754. --site-profile="community" \
  755. --ssl=${postactiv_ssl}
  756. # There can be a lot of warnings here so the return value check is disabled
  757. #if [ ! "$?" = "0" ]; then
  758. # # failed to install
  759. # echo $'Could not install postactiv'
  760. # exit 72357
  761. #fi
  762. # check postactiv has a config file
  763. postactiv_config_file="/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/config.php"
  764. if [ ! -f "$postactiv_config_file" ]; then
  765. drop_database postactiv
  766. rm -rf "/var/www/$POSTACTIV_DOMAIN_NAME"
  767. echo $'Postactiv config.php not found'
  768. exit 87586
  769. fi
  770. # Some useful settings
  771. if ! grep -q "Recommended postactiv settings" "$postactiv_config_file"; then
  772. { echo "";
  773. echo "// Recommended postactiv settings";
  774. echo "\$config['thumbnail']['maxsize'] = 3000;";
  775. echo "\$config['profile']['delete'] = true;";
  776. echo "\$config['profile']['changenick'] = true;";
  777. echo "\$config['public']['localonly'] = false;";
  778. echo "addPlugin('StoreRemoteMedia');";
  779. echo "\$config['queue']['enabled'] = true;";
  780. echo "\$config['queue']['daemon'] = true;";
  781. echo "\$config['ostatus']['hub_retries'] = 3;"; } >> "$postactiv_config_file"
  782. fi
  783. echo "\$config['mail']['domain'] = '${DEFAULT_DOMAIN_NAME}';" >> "$postactiv_config_file"
  784. # This improves performance
  785. sed -i "s|//\$config\\['db'\\]\\['schemacheck'\\].*|\$config\\['db'\\]\\['schemacheck'\\] = 'script';|g" "$postactiv_config_file"
  786. # remove the install script
  787. if [ -f "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php" ]; then
  788. rm "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs/install.php"
  789. fi
  790. # php configuration
  791. sed -i 's|mysqli.allow_persistent.*|mysqli.allow_persistent = On|g' /etc/php/7.0/cli/php.ini
  792. sed -i 's|mysqli.reconnect.*|mysqli.reconnect = On|g' /etc/php/7.0/cli/php.ini
  793. systemctl restart mariadb
  794. systemctl restart php7.0-fpm
  795. systemctl restart nginx
  796. "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$POSTACTIV_DOMAIN_NAME" -g postactiv --public no
  797. "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a postactiv -p "$POSTACTIV_ADMIN_PASSWORD"
  798. gnusocial_block_user_script
  799. gnusocial_block_domain_script postactiv "$POSTACTIV_DOMAIN_NAME"
  800. set_completion_param "postactiv domain" "$POSTACTIV_DOMAIN_NAME"
  801. install_completed postactiv_main
  802. }
  803. function install_postactiv {
  804. if [ ! "$ONION_ONLY" ]; then
  805. ONION_ONLY='no'
  806. fi
  807. install_postactiv_main
  808. install_qvitter "$POSTACTIV_DOMAIN_NAME" "postactiv"
  809. install_gnusocial_markdown "$POSTACTIV_DOMAIN_NAME" "postactiv"
  810. install_gnusocial_plugin_sharings "$POSTACTIV_DOMAIN_NAME" "postactiv"
  811. install_gnusocial_plugin_sharings_theme "$POSTACTIV_DOMAIN_NAME" "postactiv"
  812. # Currently Pleroma won't install on ARM systems
  813. # because it uses node-sass which doesn't support ARM
  814. if [[ "$(arch)" == "arm"* || "$(arch)" == "aarch"* ]]; then
  815. echo -m $'WARNING: Pleroma currently does not support ARM '
  816. echo $'architecture, so it will not be installed'
  817. else
  818. function_check install_nodejs
  819. install_nodejs pleroma-gnusocial
  820. install_pleroma_front_end "postactiv" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
  821. install_gnusocial_default_background "postactiv" "$POSTACTIV_DOMAIN_NAME"
  822. postactiv_customise_logo "$POSTACTIV_DOMAIN_NAME"
  823. sed -i 's|"theme":.*|"theme": "base16-harmonic16-light.css",|g' "/var/www/${POSTACTIV_DOMAIN_NAME}/htdocs/static/config.json"
  824. fi
  825. expire_gnusocial_posts "$POSTACTIV_DOMAIN_NAME" "postactiv" "$POSTACTIV_EXPIRE_MONTHS"
  826. # unleash the daemons!
  827. /etc/cron.hourly/postactiv-daemons
  828. systemctl restart nginx
  829. # Set qvitter to be the default UI. It's probably the most stable.
  830. # And doesn't forget logins
  831. gnusocial_use_qvitter postactiv
  832. if [ "$POSTACTIV_BACKGROUND_IMAGE_URL" ]; then
  833. pleroma_set_background_image_from_url "/var/www/$POSTACTIV_DOMAIN_NAME/htdocs" "$POSTACTIV_DOMAIN_NAME" "$POSTACTIV_BACKGROUND_IMAGE_URL" "$POSTACTIV_TITLE"
  834. fi
  835. APP_INSTALLED=1
  836. }
  837. # NOTE: deliberately there is no "exit 0"