freedombone-app-hubzilla 23KB

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