freedombone-app-friendica 24KB

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