freedombone-app-hubzilla 23KB

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