freedombone-app-htmly 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #!/bin/bash
  2. # _____ _ _
  3. # | __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
  4. # | __| _| -_| -_| . | . | | . | . | | -_|
  5. # |__| |_| |___|___|___|___|_|_|_|___|___|_|_|___|
  6. #
  7. # Freedom in the Cloud
  8. #
  9. # Htmly functions
  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 writer"
  29. IN_DEFAULT_INSTALL=0
  30. SHOW_ON_ABOUT=1
  31. HTMLY_DOMAIN_NAME=
  32. HTMLY_CODE=
  33. HTMLY_ONION_PORT=8086
  34. HTMLY_REPO="https://github.com/danpros/htmly"
  35. HTMLY_COMMIT='bf5fe9486160be4da86d8987d3e5c977e1dc6d32'
  36. HTMLY_TITLE="My Blog"
  37. HTMLY_SUBTITLE="Another ${PROJECT_NAME} blog"
  38. htmly_variables=(HTMLY_REPO
  39. HTMLY_DOMAIN_NAME
  40. HTMLY_CODE
  41. HTMLY_TITLE
  42. HTMLY_SUBTITLE
  43. ONION_ONLY
  44. DDNS_PROVIDER
  45. MY_USERNAME)
  46. function logging_on_htmly {
  47. echo -n ''
  48. }
  49. function logging_off_htmly {
  50. echo -n ''
  51. }
  52. function set_avatar_from_url {
  53. AVATAR="$1"
  54. read_config_param "HTMLY_DOMAIN_NAME"
  55. BASE_DIR=/var/www/$HTMLY_DOMAIN_NAME/htdocs
  56. if [ ! -d $BASE_DIR/customimages ]; then
  57. mkdir $BASE_DIR/customimages
  58. fi
  59. # download the image
  60. cd "$BASE_DIR/customimages" || exit 2468246
  61. # convert to png
  62. wget "$AVATAR" -O avatar
  63. if [[ "$AVATAR" == *".gif" ]]; then
  64. mv avatar avatar.gif
  65. mogrify -format png avatar.gif
  66. fi
  67. if [[ "$AVATAR" == *".jpg" ]]; then
  68. mv avatar avatar.jpg
  69. mogrify -format png avatar.jpg
  70. fi
  71. if [[ "$AVATAR" == *".jpeg" ]]; then
  72. mv avatar avatar.jpeg
  73. mogrify -format png avatar.jpeg
  74. fi
  75. if [ -f avatar ]; then
  76. mv avatar avatar.png
  77. fi
  78. # standard size
  79. mogrify -resize 150x150 avatar.png
  80. if [ ! -f $BASE_DIR/customimages/avatar.png ]; then
  81. echo $'Avatar image could not be downloaded'
  82. return
  83. fi
  84. chown -R www-data:www-data $BASE_DIR/customimages
  85. AVATAR_SET=1
  86. }
  87. function remove_user_htmly {
  88. remove_username="$1"
  89. "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp htmly
  90. if [ -f "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini" ]; then
  91. rm "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini"
  92. fi
  93. }
  94. function add_user_htmly {
  95. if [[ $(app_is_installed htmly) == "0" ]]; then
  96. echo '0'
  97. return
  98. fi
  99. new_username="$1"
  100. new_user_password="$2"
  101. "${PROJECT_NAME}-pass" -u "$new_username" -a htmly -p "$new_user_password"
  102. if [ ! -d /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users ]; then
  103. echo '2'
  104. return
  105. fi
  106. NEW_USER_PASSWORD_HASH=$("${PROJECT_NAME}-sec" --htmlyhash "$new_user_password")
  107. if [ ${#NEW_USER_PASSWORD_HASH} -lt 8 ]; then
  108. echo '3'
  109. return
  110. fi
  111. { echo ';Password';
  112. echo "password = $NEW_USER_PASSWORD_HASH";
  113. echo 'encryption = password_hash';
  114. echo ';Role';
  115. echo 'role = admin'; } > "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini"
  116. echo '0'
  117. }
  118. function configure_interactive_htmly {
  119. data=$(mktemp 2>/dev/null)
  120. dialog --title $"Change htmly avatar" \
  121. --backtitle $"Freedombone Control Panel" \
  122. --inputbox $"Enter a URL for an image. It should be approximately a square image." 8 75 2>"$data"
  123. sel=$?
  124. case $sel in
  125. 0)
  126. IMAGE_URL=$(<"$data")
  127. if [ ${#IMAGE_URL} -gt 5 ]; then
  128. clear
  129. AVATAR_SET=
  130. set_avatar_from_url "$IMAGE_URL"
  131. if [ $AVATAR_SET ]; then
  132. dialog --title $"Change htmly avatar" \
  133. --msgbox $"Your htmly avatar has been changed" 6 40
  134. fi
  135. fi
  136. ;;
  137. esac
  138. rm -f "$data"
  139. }
  140. function install_interactive_htmly {
  141. if [ ! "$ONION_ONLY" ]; then
  142. ONION_ONLY='no'
  143. fi
  144. if [[ $ONION_ONLY != "no" ]]; then
  145. HTMLY_TITLE='My Htmly Blog'
  146. HTMLY_DOMAIN_NAME='htmly.local'
  147. write_config_param "HTMLY_TITLE" "$HTMLY_TITLE"
  148. write_config_param "HTMLY_DOMAIN_NAME" "$HTMLY_DOMAIN_NAME"
  149. else
  150. function_check interactive_site_details_with_title
  151. interactive_site_details_with_title "htmly" "HTMLY_TITLE" "HTMLY_DOMAIN_NAME" "HTMLY_CODE"
  152. fi
  153. APP_INSTALLED=1
  154. }
  155. function change_password_htmly {
  156. set_completion_param "htmly domain" "$HTMLY_DOMAIN_NAME"
  157. HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
  158. HTMLY_USERNAME="$1"
  159. HTMLY_PASSWORD="$2"
  160. if [ ${#HTMLY_PASSWORD} -lt 8 ]; then
  161. echo $'Htmly password is too short'
  162. return
  163. fi
  164. "${PROJECT_NAME}-pass" -u "$HTMLY_USERNAME" -a htmly -p "$HTMLY_PASSWORD"
  165. HTMLY_PASSWORD_HASH=$("${PROJECT_NAME}-sec" --htmlyhash "$HTMLY_PASSWORD")
  166. if [ ${#HTMLY_PASSWORD_HASH} -lt 8 ]; then
  167. echo $'Htmly admin password could not be hashed'
  168. exit 625728
  169. fi
  170. sed -i "s|password =.*|password = $HTMLY_PASSWORD_HASH|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$HTMLY_USERNAME.ini"
  171. }
  172. function reconfigure_htmly {
  173. echo -n ''
  174. }
  175. function upgrade_htmly {
  176. CURR_HTMLY_COMMIT=$(get_completion_param "htmly commit")
  177. if [[ "$CURR_HTMLY_COMMIT" == "$HTMLY_COMMIT" ]]; then
  178. return
  179. fi
  180. read_config_param "HTMLY_DOMAIN_NAME"
  181. function_check set_repo_commit
  182. set_repo_commit "/var/www/$HTMLY_DOMAIN_NAME/htdocs" "htmly commit" "$HTMLY_COMMIT" $HTMLY_REPO
  183. }
  184. function backup_local_htmly {
  185. HTMLY_DOMAIN_NAME='htmly.local'
  186. if grep -q "htmly domain" "$COMPLETION_FILE"; then
  187. HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
  188. fi
  189. source_directory="/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
  190. if [ -d "$source_directory" ]; then
  191. dest_directory=htmly
  192. function_check suspend_site
  193. suspend_site "${HTMLY_DOMAIN_NAME}"
  194. function_check backup_directory_to_usb
  195. backup_directory_to_usb "$source_directory" "$dest_directory"
  196. function_check restart_site
  197. restart_site
  198. fi
  199. }
  200. function restore_local_htmly {
  201. HTMLY_DOMAIN_NAME='htmly.local'
  202. if grep -q "htmly domain" "$COMPLETION_FILE"; then
  203. HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
  204. fi
  205. if [ "$HTMLY_DOMAIN_NAME" ]; then
  206. temp_restore_dir=/root/temphtmly
  207. if [ -d "$USB_MOUNT/backup/htmly" ]; then
  208. restore_directory_from_usb $temp_restore_dir htmly
  209. else
  210. restore_directory_from_usb $temp_restore_dir blog
  211. fi
  212. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
  213. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
  214. rm -rf "/var/www/${HTMLY_DOMAIN_NAME}/previous"
  215. fi
  216. # shellcheck disable=SC2086
  217. mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs /var/www/${HTMLY_DOMAIN_NAME}/previous
  218. fi
  219. if [ -d "${temp_restore_dir}/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
  220. temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
  221. cp -r "${temp_source_dir}" "/var/www/${HTMLY_DOMAIN_NAME}/"
  222. else
  223. if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
  224. mkdir "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
  225. fi
  226. cp -r "${temp_restore_dir}/"* "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/"
  227. fi
  228. # shellcheck disable=SC2181
  229. if [ ! "$?" = "0" ]; then
  230. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
  231. # shellcheck disable=SC2086
  232. mv /var/www/${HTMLY_DOMAIN_NAME}/previous /var/www/${HTMLY_DOMAIN_NAME}/htdocs
  233. fi
  234. set_user_permissions
  235. backup_unmount_drive
  236. exit 54675
  237. fi
  238. rm -rf ${temp_restore_dir}
  239. if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content" ]; then
  240. echo $"No content directory found after restoring htmly"
  241. set_user_permissions
  242. backup_unmount_drive
  243. exit 34578
  244. fi
  245. chown -R www-data:www-data "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
  246. # Ensure that the bundled SSL cert is being used
  247. if [ -f "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt" ]; then
  248. sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" "/etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}"
  249. fi
  250. for d in /home/*/ ; do
  251. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  252. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  253. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post" ]; then
  254. # shellcheck disable=SC2086
  255. mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post
  256. fi
  257. fi
  258. done
  259. if [ -d "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}" ]; then
  260. ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem" "/etc/ssl/private/${HTMLY_DOMAIN_NAME}.key"
  261. ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem" "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem"
  262. fi
  263. fi
  264. }
  265. function backup_remote_htmly {
  266. if grep -q "htmly domain" "$COMPLETION_FILE"; then
  267. HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
  268. temp_backup_dir=/var/www/${HTMLY_DOMAIN_NAME}/htdocs
  269. if [ -d "$temp_backup_dir" ]; then
  270. echo $"Backing up htmly"
  271. backup_directory_to_friend "$temp_backup_dir" htmly
  272. echo $"Backup of htmly complete"
  273. else
  274. echo $"Htmly domain specified but not found in $temp_backup_dir"
  275. exit 2578
  276. fi
  277. fi
  278. }
  279. function restore_remote_htmly {
  280. if [ -d "$SERVER_DIRECTORY/backup/htmly" ]; then
  281. HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
  282. echo $"Restoring htmly installation $HTMLY_DOMAIN_NAME"
  283. temp_restore_dir=/root/temphtmly
  284. mkdir $temp_restore_dir
  285. function_check restore_directory_from_friend
  286. restore_directory_from_friend $temp_restore_dir htmly
  287. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
  288. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
  289. rm -rf "/var/www/${HTMLY_DOMAIN_NAME}/previous"
  290. fi
  291. # shellcheck disable=SC2086
  292. mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs /var/www/${HTMLY_DOMAIN_NAME}/previous
  293. fi
  294. if [ -d "${temp_restore_dir}/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
  295. temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
  296. cp -r "${temp_source_dir}" "/var/www/${HTMLY_DOMAIN_NAME}/"
  297. else
  298. if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs" ]; then
  299. mkdir "/var/www/${HTMLY_DOMAIN_NAME}/htdocs"
  300. fi
  301. cp -r "${temp_restore_dir}/"* "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/"
  302. fi
  303. # shellcheck disable=SC2181
  304. if [ ! "$?" = "0" ]; then
  305. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/previous" ]; then
  306. # shellcheck disable=SC2086
  307. mv /var/www/${HTMLY_DOMAIN_NAME}/previous /var/www/${HTMLY_DOMAIN_NAME}/htdocs
  308. fi
  309. exit 593
  310. fi
  311. rm -rf ${temp_restore_dir}
  312. if [ ! -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content" ]; then
  313. echo $"No content directory found after restoring htmly"
  314. exit 287
  315. fi
  316. # Ensure that the bundled SSL cert is being used
  317. if [ -f "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt" ]; then
  318. sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" "/etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}"
  319. fi
  320. for d in /home/*/ ; do
  321. USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
  322. if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
  323. if [ -d "/var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post" ]; then
  324. # shellcheck disable=SC2086
  325. mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post
  326. fi
  327. fi
  328. done
  329. if [ -d "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}" ]; then
  330. ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem" "/etc/ssl/private/${HTMLY_DOMAIN_NAME}.key"
  331. ln -s "/etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem" "/etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem"
  332. fi
  333. echo $"Restore of htmly complete"
  334. fi
  335. }
  336. function remove_htmly {
  337. if [ ${#HTMLY_DOMAIN_NAME} -eq 0 ]; then
  338. return
  339. fi
  340. read_config_param "HTMLY_DOMAIN_NAME"
  341. nginx_dissite "$HTMLY_DOMAIN_NAME"
  342. remove_certs "${HTMLY_DOMAIN_NAME}"
  343. if [ -f "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME" ]; then
  344. rm -f "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  345. fi
  346. if [ -d "/var/www/$HTMLY_DOMAIN_NAME" ]; then
  347. rm -rf "/var/www/$HTMLY_DOMAIN_NAME"
  348. fi
  349. remove_config_param HTMLY_DOMAIN_NAME
  350. remove_config_param HTMLY_CODE
  351. function_check remove_onion_service
  352. remove_onion_service htmly ${HTMLY_ONION_PORT}
  353. remove_completion_param "install_htmly"
  354. sed -i '/Htmly/d' "$COMPLETION_FILE"
  355. sed -i '/htmly/d' "$COMPLETION_FILE"
  356. function_check remove_ddns_domain
  357. remove_ddns_domain "$HTMLY_DOMAIN_NAME"
  358. }
  359. function install_htmly_social_networks {
  360. # set social networks
  361. if grep -q "social.hubzilla" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"; then
  362. sed -i "s|;social.hubzilla|social.hubzilla|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  363. sed -i "s|social.hubzilla.*|social.hubzilla = \"$HUBZILLA_DOMAIN_NAME\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  364. fi
  365. if grep -q "social.gnusocial" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"; then
  366. sed -i "s|;social.gnusocial|social.gnusocial|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  367. sed -i "s|social.gnusocial.*|social.gnusocial = \"$MICROHTMLY_DOMAIN_NAME\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  368. fi
  369. # clear proprietary social network strings
  370. sed -i 's|social.facebook.*|social.facebook = ""|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  371. sed -i 's|social.twitter.*|social.twitter = ""|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  372. sed -i 's|social.google.*|social.google = ""|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  373. }
  374. function install_htmly_user {
  375. # create a user password
  376. if [ -f "$IMAGE_PASSWORD_FILE" ]; then
  377. HTMLY_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
  378. else
  379. HTMLY_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
  380. fi
  381. # create a user
  382. HTMLY_ADMIN_PASSWORD_HASH=$("${PROJECT_NAME}-sec" --htmlyhash "$HTMLY_ADMIN_PASSWORD")
  383. if [ ${#HTMLY_ADMIN_PASSWORD_HASH} -lt 8 ]; then
  384. echo $'Htmly admin password could not be hashed'
  385. exit 625728
  386. fi
  387. { echo ';Password';
  388. echo "password = $HTMLY_ADMIN_PASSWORD_HASH";
  389. echo 'encryption = password_hash';
  390. echo ';Role';
  391. echo 'role = admin'; } > "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini"
  392. }
  393. function install_htmly_settings {
  394. cp "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini.example" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  395. sed -i "s|site.url.*|site.url = '/'|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  396. sed -i "s|blog.title.*|blog.title = \"$HTMLY_TITLE\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  397. sed -i "s|blog.tagline.*|blog.tagline = \"$HTMLY_SUBTITLE\"|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  398. sed -i 's|timezone.*|timezone = "Europe/London"|g' "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  399. sed -i "s|Your name|$MY_NAME|g" "/var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini"
  400. }
  401. function install_htmly_website {
  402. function_check nginx_http_redirect
  403. nginx_http_redirect "$HTMLY_DOMAIN_NAME"
  404. { echo 'server {';
  405. echo ' listen 443 ssl;';
  406. echo ' #listen [::]:443 ssl;';
  407. echo " root /var/www/$HTMLY_DOMAIN_NAME/htdocs;";
  408. echo " server_name $HTMLY_DOMAIN_NAME;";
  409. echo ' access_log /dev/null;';
  410. echo " error_log /dev/null;";
  411. echo ' index index.php;';
  412. echo ' charset utf-8;';
  413. echo ' proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  414. function_check nginx_ssl
  415. nginx_ssl "$HTMLY_DOMAIN_NAME"
  416. function_check nginx_security_options
  417. nginx_security_options "$HTMLY_DOMAIN_NAME"
  418. { echo ' add_header Strict-Transport-Security "max-age=0;";';
  419. echo '';
  420. echo ' # rewrite to front controller as default rule';
  421. echo ' location / {'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  422. function_check nginx_limits
  423. nginx_limits "$HTMLY_DOMAIN_NAME"
  424. { echo " rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
  425. echo ' }';
  426. echo '';
  427. echo ' # statically serve these file types when possible';
  428. echo ' # otherwise fall back to front controller';
  429. echo ' # allow browser to cache them';
  430. echo ' # added .htm for advanced source code editor library';
  431. echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
  432. echo ' expires 30d;';
  433. echo " try_files \$uri /index.php?q=\$uri&\$args;";
  434. echo ' }';
  435. echo '';
  436. echo ' # block these file types';
  437. echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
  438. echo ' deny all;';
  439. echo ' }';
  440. echo '';
  441. echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
  442. echo ' # or a unix socket';
  443. echo ' location ~* \.php$ {';
  444. echo ' # Zero-day exploit defense.';
  445. echo ' # http://forum.nginx.org/read.php?2,88845,page=3';
  446. echo " # Won't work properly (404 error) if the file is not stored on this";
  447. echo " # server, which is entirely possible with php-fpm/php-fcgi.";
  448. echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
  449. echo " # another machine. And then cross your fingers that you won't get hacked.";
  450. echo " try_files \$uri \$uri/ /index.php;";
  451. echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
  452. echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;';
  453. echo ' # With php-cgi alone:';
  454. echo ' # fastcgi_pass 127.0.0.1:9000;';
  455. echo ' # With php-fpm:';
  456. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
  457. echo ' include fastcgi_params;';
  458. echo ' fastcgi_read_timeout 30;';
  459. echo ' fastcgi_index index.php;';
  460. echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
  461. echo ' }';
  462. echo '';
  463. echo ' # deny access to all dot files';
  464. echo ' location ~ /\. {';
  465. echo ' deny all;';
  466. echo ' }';
  467. echo '';
  468. echo ' #deny access to store';
  469. echo ' location ~ /store {';
  470. echo ' deny all;';
  471. echo ' }';
  472. echo ' location ~ /(data|conf|bin|inc)/ {';
  473. echo ' deny all;';
  474. echo ' }';
  475. echo ' location ~ /\.ht {';
  476. echo ' deny all;';
  477. echo ' }';
  478. echo '}';
  479. echo ''; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  480. }
  481. function install_htmly_website_onion {
  482. { echo 'server {';
  483. echo " listen 127.0.0.1:${HTMLY_ONION_PORT} default_server;";
  484. echo " root /var/www/$HTMLY_DOMAIN_NAME/htdocs;"; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  485. if [[ "$ONION_ONLY" != 'yes' ]]; then
  486. echo " server_name $HTMLY_DOMAIN_NAME;" >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  487. else
  488. echo " server_name $HTMLY_ONION_HOSTNAME;" >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  489. fi
  490. { echo ' access_log /dev/null;';
  491. echo " error_log /dev/null;";
  492. echo ' index index.php;';
  493. echo ' charset utf-8;';
  494. echo ' proxy_read_timeout 86400s;'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  495. function_check nginx_security_options
  496. nginx_security_options "$HTMLY_DOMAIN_NAME"
  497. { echo ' add_header Strict-Transport-Security "max-age=0;";';
  498. echo '';
  499. echo ' # rewrite to front controller as default rule';
  500. echo ' location / {'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  501. function_check nginx_limits
  502. nginx_limits "$HTMLY_DOMAIN_NAME"
  503. { echo " rewrite ^/(.*) /index.php?q=\$uri&\$args last;";
  504. echo ' }';
  505. echo '';
  506. echo ' # statically serve these file types when possible';
  507. echo ' # otherwise fall back to front controller';
  508. echo ' # allow browser to cache them';
  509. echo ' # added .htm for advanced source code editor library';
  510. echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {';
  511. echo ' expires 30d;';
  512. echo " try_files \$uri /index.php?q=\$uri&\$args;";
  513. echo ' }';
  514. echo '';
  515. echo ' # block these file types';
  516. echo ' location ~* \.(tpl|md|tgz|log|out)$ {';
  517. echo ' deny all;';
  518. echo ' }';
  519. echo '';
  520. echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000';
  521. echo ' # or a unix socket';
  522. echo ' location ~* \.php$ {'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  523. function_check nginx_limits
  524. nginx_limits "$HTMLY_DOMAIN_NAME"
  525. { echo ' # Zero-day exploit defense.';
  526. echo ' # http://forum.nginx.org/read.php?2,88845,page=3';
  527. echo " # Won't work properly (404 error) if the file is not stored on this";
  528. echo " # server, which is entirely possible with php-fpm/php-fcgi.";
  529. echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on";
  530. echo " # another machine. And then cross your fingers that you won't get hacked.";
  531. echo " try_files \$uri \$uri/ /index.php;";
  532. echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini';
  533. echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;';
  534. echo ' # With php-cgi alone:';
  535. echo ' # fastcgi_pass 127.0.0.1:9000;';
  536. echo ' # With php-fpm:';
  537. echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;';
  538. echo ' include fastcgi_params;';
  539. echo ' fastcgi_read_timeout 30;';
  540. echo ' fastcgi_index index.php;';
  541. echo " fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;";
  542. echo ' }';
  543. echo '';
  544. echo ' # deny access to all dot files';
  545. echo ' location ~ /\. {';
  546. echo ' deny all;';
  547. echo ' }';
  548. echo '';
  549. echo ' #deny access to store';
  550. echo ' location ~ /store {';
  551. echo ' deny all;';
  552. echo ' }';
  553. echo ' location ~ /(data|conf|bin|inc)/ {';
  554. echo ' deny all;';
  555. echo ' }';
  556. echo ' location ~ /\.ht {';
  557. echo ' deny all;';
  558. echo ' }';
  559. echo '}'; } >> "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  560. }
  561. function install_htmly_from_repo {
  562. if [ ! -d "/var/www/$HTMLY_DOMAIN_NAME" ]; then
  563. mkdir "/var/www/$HTMLY_DOMAIN_NAME"
  564. fi
  565. cd "/var/www/$HTMLY_DOMAIN_NAME" || exit 34684682
  566. if [ -d /repos/htmly ]; then
  567. mkdir htdocs
  568. cp -r -p /repos/htmly/. htdocs
  569. cd htdocs || exit 3468735
  570. git pull
  571. else
  572. git_clone $HTMLY_REPO htdocs
  573. fi
  574. cd htdocs || exit 3479835
  575. git checkout $HTMLY_COMMIT -b $HTMLY_COMMIT
  576. set_completion_param "htmly commit" "$HTMLY_COMMIT"
  577. }
  578. function install_htmly {
  579. if [ ! "$ONION_ONLY" ]; then
  580. ONION_ONLY='no'
  581. fi
  582. if [ ! "$HTMLY_DOMAIN_NAME" ]; then
  583. echo $'The htmly domain name was not specified'
  584. exit 5062
  585. fi
  586. # for the avatar changing command
  587. apt-get -yq install imagemagick libfcgi0ldbl
  588. function_check install_htmly_from_repo
  589. install_htmly_from_repo
  590. if [[ $ONION_ONLY == "no" ]]; then
  591. function_check install_htmly_website
  592. install_htmly_website
  593. else
  594. echo -n '' > "/etc/nginx/sites-available/$HTMLY_DOMAIN_NAME"
  595. fi
  596. HTMLY_ONION_HOSTNAME=$(add_onion_service htmly 80 ${HTMLY_ONION_PORT})
  597. function_check install_htmly_website_onion
  598. install_htmly_website_onion
  599. function_check create_site_certificate
  600. create_site_certificate "$HTMLY_DOMAIN_NAME" 'yes'
  601. function_check configure_php
  602. configure_php
  603. function_check install_htmly_settings
  604. install_htmly_settings
  605. function_check install_htmly_social_networks
  606. install_htmly_social_networks
  607. function_check install_htmly_user
  608. install_htmly_user
  609. chown -R www-data:www-data "/var/www/$HTMLY_DOMAIN_NAME/htdocs"
  610. function_check nginx_ensite
  611. nginx_ensite "$HTMLY_DOMAIN_NAME"
  612. systemctl restart php7.0-fpm
  613. systemctl restart nginx
  614. "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a htmly -p "$HTMLY_ADMIN_PASSWORD"
  615. function_check add_ddns_domain
  616. add_ddns_domain "$HTMLY_DOMAIN_NAME"
  617. set_completion_param "htmly domain" "$HTMLY_DOMAIN_NAME"
  618. APP_INSTALLED=1
  619. }
  620. # NOTE: deliberately no exit 0