freedombone-app-hubzilla 23KB

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