freedombone-app-htmly 26KB

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