freedombone-app-hubzilla 32KB

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