freedombone-app-hubzilla 23KB

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