freedombone-app-friendica 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Friendica application
  10. #
  11. # License
  12. # =======
  13. #
  14. # Copyright (C) 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 social'
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=1
  31. FRIENDICA_DOMAIN_NAME=
  32. FRIENDICA_CODE=
  33. FRIENDICA_ONION_PORT=8114
  34. FRIENDICA_REPO="https://github.com/friendica/friendica"
  35. FRIENDICA_ADDONS_REPO="https://github.com/friendica/friendica-addons"
  36. FRIENDICA_ADMIN_PASSWORD=
  37. FRIENDICA_COMMIT='b5a42c5b31fae5315bacd37769eba20ab2345aaa'
  38. FRIENDICA_ADDONS_COMMIT='7cb9dbdda7f227462895c07be3c968405561d40e'
  39. friendica_variables=(ONION_ONLY
  40. FRIENDICA_DOMAIN_NAME
  41. FRIENDICA_CODE
  42. DDNS_PROVIDER
  43. MY_USERNAME
  44. FRIENDICA_REPO
  45. FRIENDICA_ADDONS_REPO)
  46. function logging_on_friendica {
  47. echo -n ''
  48. }
  49. function logging_off_friendica {
  50. echo -n ''
  51. }
  52. function remove_user_friendica {
  53. remove_username="$1"
  54. "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp friendica
  55. }
  56. function add_user_friendica {
  57. if [[ $(app_is_installed friendica) == "0" ]]; then
  58. echo '0'
  59. return
  60. fi
  61. new_username="$1"
  62. new_user_password="$2"
  63. "${PROJECT_NAME}-pass" -u "$new_username" -a friendica -p "$new_user_password"
  64. echo '0'
  65. }
  66. function friendica_renew_cert {
  67. dialog --title $"Renew SSL certificate" \
  68. --backtitle $"Freedombone Control Panel" \
  69. --yesno $"\\nThis will renew a letsencrypt certificate. Select 'yes' to continue" 16 60
  70. sel=$?
  71. case $sel in
  72. 1) return;;
  73. 255) return;;
  74. esac
  75. FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain")
  76. if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" ]; then
  77. dialog --title $"Renew SSL certificate" \
  78. --msgbox $"Friendica install directory not found" 6 40
  79. return
  80. fi
  81. if ! "${PROJECT_NAME}-renew-cert" -h "$FRIENDICA_DOMAIN_NAME" -p 'letsencrypt'; then
  82. any_key
  83. else
  84. dialog --title $"Renew SSL certificate" \
  85. --msgbox $"Friendica certificate has been renewed" 6 40
  86. fi
  87. }
  88. function friendica_channel_directory_server {
  89. if ! grep -q "friendica domain" "$COMPLETION_FILE"; then
  90. dialog --title $"Friendica channel directory server" \
  91. --msgbox $"Friendica is not installed on this system" 6 40
  92. return
  93. fi
  94. FRIENDICA_DOMAIN_NAME=$(get_completion_param "friendica domain")
  95. if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs" ]; then
  96. dialog --title $"Friendica channel directory server" \
  97. --msgbox $"Friendica install directory not found" 6 40
  98. return
  99. fi
  100. CURR_DIR_SERVER=$(grep directory "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php" | awk -F "'" '{print $6}')
  101. data=$(mktemp 2>/dev/null)
  102. dialog --title $"Friendica channel directory server" \
  103. --backtitle $"Freedombone Control Panel" \
  104. --inputbox $"When you click on 'channel directory' this is where Friendica will obtain its list from" 8 60 "$CURR_DIR_SERVER" 2>"$data"
  105. sel=$?
  106. case $sel in
  107. 0)
  108. friendica_domain_server=$(<"$data")
  109. if [[ "$friendica_domain_server" != *"."* ]]; then
  110. rm -f "$data"
  111. return
  112. fi
  113. if [[ "$friendica_domain_server" != "http"* ]]; then
  114. dialog --title $"Friendica channel directory server" \
  115. --msgbox $"Invalid domain - include the https://" 6 40
  116. rm -f "$data"
  117. return
  118. fi
  119. sed -i "s|\['directory'\] = .*|\['directory'\] = \'$friendica_domain_server\';|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php"
  120. dialog --title $"Friendica channel directory server" \
  121. --msgbox $"Domain channel directory server changed to $friendica_domain_server" 6 40
  122. ;;
  123. esac
  124. rm -f "$data"
  125. }
  126. function friendica_close_registrations {
  127. sed -i "s|REGISTER_OPEN|REGISTER_CLOSED|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php"
  128. dialog --title $"Friendica Account Registrations" \
  129. --msgbox $"New registrations are now closed" 6 40
  130. }
  131. function friendica_allow_registrations {
  132. sed -i "s|REGISTER_CLOSED|REGISTER_OPEN|g" "/var/www/$FRIENDICA_DOMAIN_NAME/htdocs/.htconfig.php"
  133. dialog --title $"Friendica Account Registrations" \
  134. --msgbox $"New registrations are permitted" 6 40
  135. }
  136. function configure_interactive_friendica {
  137. W=(1 $"Set channel directory server"
  138. 2 $"Renew SSL certificate"
  139. 3 $"Close new account registrations"
  140. 4 $"Allow new account registrations")
  141. while true
  142. do
  143. # shellcheck disable=SC2068
  144. selection=$(dialog --backtitle $"Freedombone Administrator Control Panel" --title $"Friendica" --menu $"Choose an operation, or ESC to exit:" 14 60 4 "${W[@]}" 3>&2 2>&1 1>&3)
  145. if [ ! "$selection" ]; then
  146. break
  147. fi
  148. case $selection in
  149. 1) friendica_channel_directory_server;;
  150. 2) friendica_renew_cert;;
  151. 3) friendica_close_registrations;;
  152. 4) friendica_allow_registrations;;
  153. esac
  154. done
  155. }
  156. function install_interactive_friendica {
  157. if [[ $ONION_ONLY != "no" ]]; then
  158. return
  159. fi
  160. function_check interactive_site_details
  161. interactive_site_details friendica
  162. APP_INSTALLED=1
  163. }
  164. function change_password_friendica {
  165. #FRIENDICA_USERNAME="$1"
  166. FRIENDICA_PASSWORD="$2"
  167. if [ ${#FRIENDICA_PASSWORD} -lt 8 ]; then
  168. echo $'Friendica password is too short'
  169. return
  170. fi
  171. # TODO: This doesn't actually change the password
  172. #${PROJECT_NAME}-pass -u $FRIENDICA_USERNAME -a friendica -p "$FRIENDICA_PASSWORD"
  173. }
  174. function friendica_create_database {
  175. if [ -f "$IMAGE_PASSWORD_FILE" ]; then
  176. FRIENDICA_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
  177. fi
  178. if [ ! "$FRIENDICA_ADMIN_PASSWORD" ]; then
  179. FRIENDICA_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  180. fi
  181. "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a friendica -p "$FRIENDICA_ADMIN_PASSWORD"
  182. if [ ! "$FRIENDICA_ADMIN_PASSWORD" ]; then
  183. return
  184. fi
  185. function_check create_database
  186. create_database friendica "$FRIENDICA_ADMIN_PASSWORD"
  187. }
  188. function reconfigure_friendica {
  189. echo -n ''
  190. }
  191. function upgrade_friendica {
  192. CURR_FRIENDICA_COMMIT=$(get_completion_param "friendica commit")
  193. if [[ "$CURR_FRIENDICA_COMMIT" == "$FRIENDICA_COMMIT" ]]; then
  194. return
  195. fi
  196. FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
  197. function_check set_repo_commit
  198. set_repo_commit "$FRIENDICA_PATH" "friendica commit" "$FRIENDICA_COMMIT" $FRIENDICA_REPO
  199. set_repo_commit "$FRIENDICA_PATH/addon" "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT" $FRIENDICA_ADDONS_REPO
  200. }
  201. function backup_local_friendica {
  202. friendica_path="/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs"
  203. if [ -d "$friendica_path" ]; then
  204. function_check backup_database_to_usb
  205. backup_database_to_usb friendica
  206. backup_directory_to_usb "$friendica_path" friendica
  207. fi
  208. }
  209. function restore_local_friendica {
  210. temp_restore_dir=/root/tempfriendica
  211. friendica_dir=/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs
  212. function_check friendica_create_database
  213. friendica_create_database
  214. restore_database friendica "${FRIENDICA_DOMAIN_NAME}"
  215. if [ -d "$USB_MOUNT/backup/friendica" ]; then
  216. if [ ! -d "$friendica_dir/store/[data]/smarty3" ]; then
  217. mkdir -p "$friendica_dir/store/[data]/smarty3"
  218. fi
  219. chmod 1777 "$friendica_dir/store/[data]/smarty3"
  220. chown -R www-data:www-data "$friendica_dir/"*
  221. if [ -d $temp_restore_dir ]; then
  222. rm -rf $temp_restore_dir
  223. fi
  224. MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
  225. FRIENDICA_PATH=/var/www/$FRIENDICA_DOMAIN_NAME/htdocs
  226. sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$FRIENDICA_PATH/.htconfig.php"
  227. MARIADB_PASSWORD=
  228. fi
  229. }
  230. function backup_remote_friendica {
  231. temp_backup_dir="/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs"
  232. if [ -d "$temp_backup_dir" ]; then
  233. suspend_site "${FRIENDICA_DOMAIN_NAME}"
  234. backup_database_to_friend friendica
  235. echo "Backing up Friendica installation"
  236. backup_directory_to_friend "$temp_backup_dir" friendica
  237. restart_site
  238. echo "Backup of Friendica complete"
  239. else
  240. echo $"Friendica domain specified but not found in /var/www/${FRIENDICA_DOMAIN_NAME}"
  241. exit 2578
  242. fi
  243. }
  244. function restore_remote_friendica {
  245. function_check restore_database_from_friend
  246. function_check friendica_create_database
  247. friendica_create_database
  248. restore_database_from_friend friendica "${FRIENDICA_DOMAIN_NAME}"
  249. if [ -d "$SERVER_DIRECTORY/backup/friendica" ]; then
  250. if [ ! -d "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3" ]; then
  251. mkdir -p "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3"
  252. fi
  253. chmod 1777 "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/store/[data]/smarty3"
  254. chown -R www-data:www-data "/var/www/${FRIENDICA_DOMAIN_NAME}/htdocs/"*
  255. fi
  256. if [ -d /root/tempfriendica ]; then
  257. rm -rf /root/tempfriendica
  258. fi
  259. MARIADB_PASSWORD=$("${PROJECT_NAME}-pass" -u root -a mariadb)
  260. FRIENDICA_PATH="/var/www/$FRIENDICA_DOMAIN_NAME/htdocs"
  261. sed -i "s|\$db_pass =.*|\$db_pass = '${MARIADB_PASSWORD}';|g" "$FRIENDICA_PATH/.htconfig.php"
  262. MARIADB_PASSWORD=
  263. }
  264. function remove_friendica {
  265. if [ ${#FRIENDICA_DOMAIN_NAME} -eq 0 ]; then
  266. return
  267. fi
  268. nginx_dissite "$FRIENDICA_DOMAIN_NAME"
  269. remove_certs "${FRIENDICA_DOMAIN_NAME}"
  270. if [ -d "/var/www/$FRIENDICA_DOMAIN_NAME" ]; then
  271. rm -rf "/var/www/$FRIENDICA_DOMAIN_NAME"
  272. fi
  273. if [ -f "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME" ]; then
  274. rm "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  275. fi
  276. function_check drop_database
  277. drop_database friendica
  278. function_check remove_onion_service
  279. remove_onion_service friendica ${FRIENDICA_ONION_PORT}
  280. sed -i '/friendica/d' "$COMPLETION_FILE"
  281. sed -i '/poller.php/d' /etc/crontab
  282. function_check remove_ddns_domain
  283. remove_ddns_domain "$FRIENDICA_DOMAIN_NAME"
  284. }
  285. function install_friendica {
  286. if [ ! "$FRIENDICA_DOMAIN_NAME" ]; then
  287. return
  288. fi
  289. if [[ "$ONION_ONLY" != "no" ]]; then
  290. return
  291. fi
  292. FRIENDICA_PATH="/var/www/$FRIENDICA_DOMAIN_NAME/htdocs"
  293. function_check install_mariadb
  294. install_mariadb
  295. function_check get_mariadb_password
  296. get_mariadb_password
  297. function_check repair_databases_script
  298. repair_databases_script
  299. apt-get -yq install php-common php-cli php-curl php-gd php-mysql php-mcrypt git
  300. apt-get -yq install php-dev imagemagick php-imagick libfcgi0ldbl
  301. apt-get -yq install php-memcached
  302. if [ ! -d "/var/www/$FRIENDICA_DOMAIN_NAME" ]; then
  303. mkdir "/var/www/$FRIENDICA_DOMAIN_NAME"
  304. fi
  305. if [ ! -d "$FRIENDICA_PATH" ]; then
  306. mkdir "$FRIENDICA_PATH"
  307. fi
  308. if [ ! -f "$FRIENDICA_PATH/index.php" ]; then
  309. cd "$INSTALL_DIR" || exit 2346824864
  310. if [ -d /repos/friendica ]; then
  311. mkdir friendica
  312. cp -r -p /repos/friendica/. friendica
  313. cd friendica || exit 24682462
  314. git pull
  315. else
  316. function_check git_clone
  317. git_clone "$FRIENDICA_REPO" friendica
  318. fi
  319. git checkout $FRIENDICA_COMMIT -b $FRIENDICA_COMMIT
  320. set_completion_param "friendica commit" "$FRIENDICA_COMMIT"
  321. rm -rf "$FRIENDICA_PATH"
  322. # shellcheck disable=SC2086
  323. mv friendica $FRIENDICA_PATH
  324. git_clone "$FRIENDICA_ADDONS_REPO" "$FRIENDICA_PATH/addon"
  325. cd "$FRIENDICA_PATH/addon" || exit 34835685
  326. git checkout "$FRIENDICA_ADDONS_COMMIT" -b "$FRIENDICA_ADDONS_COMMIT"
  327. set_completion_param "friendica addons commit" "$FRIENDICA_ADDONS_COMMIT"
  328. chown -R www-data:www-data "$FRIENDICA_PATH"
  329. fi
  330. FRIENDICA_ONION_HOSTNAME=
  331. if [[ $ONION_ONLY != "no" ]]; then
  332. FRIENDICA_ONION_HOSTNAME=$(add_onion_service friendica 80 ${FRIENDICA_ONION_PORT})
  333. fi
  334. friendica_create_database
  335. if ! grep -q "$FRIENDICA_PATH" /etc/crontab; then
  336. echo "12,22,32,42,52 * * * * root cd $FRIENDICA_PATH; /usr/bin/timeout 500 /usr/bin/php include/poller.php" >> /etc/crontab
  337. fi
  338. function_check add_ddns_domain
  339. add_ddns_domain "$FRIENDICA_DOMAIN_NAME"
  340. if [[ "$ONION_ONLY" == "no" ]]; then
  341. function_check nginx_http_redirect
  342. nginx_http_redirect "$FRIENDICA_DOMAIN_NAME"
  343. { echo 'server {';
  344. echo ' listen 443 ssl;';
  345. echo ' #listen [::]:443 ssl;';
  346. echo " root $FRIENDICA_PATH;";
  347. echo " server_name $FRIENDICA_DOMAIN_NAME;";
  348. echo " error_log /dev/null;";
  349. echo ' index index.php;';
  350. echo ' charset utf-8;';
  351. echo ' access_log /dev/null;'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  352. function_check nginx_ssl
  353. nginx_ssl "$FRIENDICA_DOMAIN_NAME"
  354. function_check nginx_security_options
  355. nginx_security_options "$FRIENDICA_DOMAIN_NAME"
  356. { echo ' add_header Strict-Transport-Security max-age=15768000;';
  357. echo '';
  358. echo ' # rewrite to front controller as default rule';
  359. echo ' location / {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  360. function_check nginx_limits
  361. nginx_limits "$FRIENDICA_DOMAIN_NAME"
  362. { echo " rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
  363. echo ' }';
  364. echo '';
  365. echo ' # statically serve these file types when possible';
  366. echo ' # otherwise fall back to front controller';
  367. echo ' # allow browser to cache them';
  368. echo ' # added .htm for advanced source code editor library';
  369. echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
  370. echo ' expires 30d;';
  371. echo " try_files \$uri /index.php?q=\$uri&\$args;";
  372. echo ' }';
  373. echo '';
  374. echo ' # block these file types';
  375. echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
  376. echo ' deny all;';
  377. echo ' }';
  378. echo '';
  379. echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
  380. echo ' # or a unix socket';
  381. echo ' location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  382. function_check nginx_limits
  383. nginx_limits "$FRIENDICA_DOMAIN_NAME"
  384. { echo ' # Zero-day exploit defense.';
  385. echo ' # http://forum.nginx.org/read.php?2,88845,page=3';
  386. echo " # Won't work properly (404 error) if the file is not stored on this";
  387. echo " # server, which is entirely possible with php-fpm/php-fcgi.";
  388. echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
  389. echo " # another machine. And then cross your fingers that you won't get hacked.";
  390. echo " try_files \$uri \$uri/ /index.php;";
  391. echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
  392. echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;';
  393. echo ' # With php-cgi alone:';
  394. echo ' # fastcgi_pass 127.0.0.1:9000;';
  395. echo ' # With php-fpm:';
  396. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
  397. echo ' include fastcgi_params;';
  398. echo ' fastcgi_read_timeout 30;';
  399. echo ' fastcgi_index index.php;';
  400. echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
  401. echo ' fastcgi_read_timeout 300;';
  402. echo ' }';
  403. echo '';
  404. echo ' # deny access to all dot files';
  405. echo ' location ~ /\. {';
  406. echo ' deny all;';
  407. echo ' }';
  408. echo '';
  409. echo ' location ~ /\.ht {';
  410. echo ' deny all;';
  411. echo ' }';
  412. echo '}';
  413. echo ''; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  414. else
  415. { echo 'server {';
  416. echo " listen 127.0.0.1:${FRIENDICA_ONION_PORT} default_server;";
  417. echo " root $FRIENDICA_PATH;";
  418. echo " server_name $FRIENDICA_ONION_HOSTNAME;";
  419. echo " error_log /dev/null;";
  420. echo ' index index.php;';
  421. echo ' charset utf-8;';
  422. echo ' access_log /dev/null;';
  423. echo ' add_header Strict-Transport-Security max-age=15768000;';
  424. echo '';
  425. echo ' # rewrite to front controller as default rule';
  426. echo ' location / {'; } > "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  427. nginx_limits "$FRIENDICA_DOMAIN_NAME"
  428. nginx_security_options "$FRIENDICA_DOMAIN_NAME"
  429. { echo " rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
  430. echo ' }';
  431. echo '';
  432. echo ' # statically serve these file types when possible';
  433. echo ' # otherwise fall back to front controller';
  434. echo ' # allow browser to cache them';
  435. echo ' # added .htm for advanced source code editor library';
  436. echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
  437. echo ' expires 30d;';
  438. echo " try_files \$uri /index.php?q=\$uri&\$args;";
  439. echo ' }';
  440. echo '';
  441. echo ' # block these file types';
  442. echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
  443. echo ' deny all;';
  444. echo ' }';
  445. echo '';
  446. echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
  447. echo ' # or a unix socket';
  448. echo ' location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  449. nginx_limits "$FRIENDICA_DOMAIN_NAME"
  450. nginx_security_options "$FRIENDICA_DOMAIN_NAME"
  451. { echo ' # Zero-day exploit defense.';
  452. echo ' # http://forum.nginx.org/read.php?2,88845,page=3';
  453. echo " # Won't work properly (404 error) if the file is not stored on this";
  454. echo " # server, which is entirely possible with php-fpm/php-fcgi.";
  455. echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
  456. echo " # another machine. And then cross your fingers that you won't get hacked.";
  457. echo " try_files \$uri \$uri/ /index.php;";
  458. echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
  459. echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;';
  460. echo ' # With php-cgi alone:';
  461. echo ' # fastcgi_pass 127.0.0.1:9000;';
  462. echo ' # With php-fpm:';
  463. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
  464. echo ' include fastcgi_params;';
  465. echo ' fastcgi_read_timeout 30;';
  466. echo ' fastcgi_index index.php;';
  467. echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
  468. echo ' fastcgi_read_timeout 300;';
  469. echo ' }';
  470. echo '';
  471. echo ' # deny access to all dot files';
  472. echo ' location ~ /\. {';
  473. echo ' deny all;';
  474. echo ' }';
  475. echo '';
  476. echo ' location ~ /\.ht {';
  477. echo ' deny all;';
  478. echo ' }';
  479. echo '}'; } >> "/etc/nginx/sites-available/$FRIENDICA_DOMAIN_NAME"
  480. fi
  481. function_check configure_php
  482. configure_php
  483. function_check create_site_certificate
  484. create_site_certificate "$FRIENDICA_DOMAIN_NAME" 'yes'
  485. if [ ! -d "$FRIENDICA_PATH/view/tpl/smarty3" ]; then
  486. mkdir "$FRIENDICA_PATH/view/tpl/smarty3"
  487. fi
  488. if [ ! -d "$FRIENDICA_PATH/store" ]; then
  489. mkdir "$FRIENDICA_PATH/store"
  490. fi
  491. if [ ! -d "$FRIENDICA_PATH/store/[data]" ]; then
  492. mkdir "$FRIENDICA_PATH/store/[data]"
  493. fi
  494. if [ ! -d "$FRIENDICA_PATH/store/[data]/smarty3" ]; then
  495. mkdir "$FRIENDICA_PATH/store/[data]/smarty3"
  496. chmod 1777 "$FRIENDICA_PATH/store/[data]/smarty3"
  497. fi
  498. chmod 1777 "$FRIENDICA_PATH/view/tpl"
  499. chown -R www-data:www-data "$FRIENDICA_PATH/store"
  500. chmod 1777 "$FRIENDICA_PATH/view/tpl/smarty3"
  501. # Ensure that the database gets backed up locally, if remote
  502. # backups are not being used
  503. function_check backup_databases_script_header
  504. backup_databases_script_header
  505. function_check backup_database_local
  506. backup_database_local friendica
  507. chown -R www-data:www-data "$FRIENDICA_PATH"
  508. function_check nginx_ensite
  509. nginx_ensite "$FRIENDICA_DOMAIN_NAME"
  510. # initialize the database
  511. if [ ! -f "$FRIENDICA_PATH/database.sql" ]; then
  512. echo $'No database schema found for friendica'
  513. exit 252782
  514. fi
  515. function_check initialise_database
  516. initialise_database friendica "$FRIENDICA_PATH/database.sql"
  517. # create the config file
  518. { echo '<?php';
  519. echo "\$db_host = 'localhost';";
  520. echo "\$db_user = 'root';";
  521. echo "\$db_pass = '${MARIADB_PASSWORD}';";
  522. echo "\$db_data = 'friendica';";
  523. echo "\$default_timezone = 'Europe/London';"; } > "$FRIENDICA_PATH/.htconfig.php"
  524. if [[ $ONION_ONLY == 'no' ]]; then
  525. echo "\$a->config['system']['baseurl'] = 'https://${FRIENDICA_DOMAIN_NAME}';" >> "$FRIENDICA_PATH/.htconfig.php"
  526. else
  527. echo "\$a->config['system']['baseurl'] = 'http://${FRIENDICA_ONION_HOSTNAME}';" >> "$FRIENDICA_PATH/.htconfig.php"
  528. fi
  529. { echo "\$a->config['sitename'] = \"Friendica\";";
  530. echo "\$a->config['register_policy'] = REGISTER_OPEN;";
  531. echo "\$a->config['register_text'] = '';";
  532. echo "\$a->config['admin_email'] = '${MY_EMAIL_ADDRESS}';";
  533. echo "\$a->config['system']['no_regfullname'] = true;";
  534. echo "\$a->config['max_import_size'] = 200000;";
  535. echo "\$a->config['system']['maximagesize'] = 800000;";
  536. echo "\$a->config['php_path'] = '/usr/bin/php';";
  537. echo "\$a->config['system']['directory'] = 'http://dir.friendi.ca';";
  538. echo "\$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero,smoothly';";
  539. echo "\$a->config['system']['theme'] = 'vier';";
  540. echo "\$a->config['system']['huburl'] = '[internal]';";
  541. echo "\$a->config['system']['language'] = 'en';";
  542. echo "\$a->config['system']['rino_encrypt'] = 2;";
  543. echo "\$a->config['system']['allowed_link_protocols'] = array('mailto', 'cid');"; } >> "$FRIENDICA_PATH/.htconfig.php"
  544. chown www-data:www-data "$FRIENDICA_PATH/.htconfig.php"
  545. chmod 755 "$FRIENDICA_PATH/.htconfig.php"
  546. systemctl restart mariadb
  547. systemctl restart php7.0-fpm
  548. systemctl restart nginx
  549. systemctl restart cron
  550. "${PROJECT_NAME}-addemail" -u "$MY_USERNAME" -e "noreply@$FRIENDICA_DOMAIN_NAME" -g friendica --public no
  551. set_completion_param "friendica domain" "${FRIENDICA_DOMAIN_NAME}"
  552. APP_INSTALLED=1
  553. }
  554. # NOTE: deliberately there is no "exit 0"