freedombone/src/freedombone-app-htmly

657 lines
31 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# .---. . .
# | | |
# |--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-.
# | | (.-' (.-' ( | ( )| | | | )( )| | (.-'
# ' ' --' --' -' - -' ' ' -' -' -' ' - --'
#
# Freedom in the Cloud
#
# Htmly functions
#
# License
# =======
#
2016-10-31 17:24:49 +01:00
# Copyright (C) 2014-2016 Bob Mottram <bob@freedombone.net>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
VARIANTS="full full-vim writer"
2016-10-22 15:11:48 +02:00
IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1
2016-10-16 20:50:56 +02:00
HTMLY_DOMAIN_NAME=
HTMLY_CODE=
HTMLY_ONION_PORT=8086
HTMLY_REPO="https://github.com/danpros/htmly"
HTMLY_COMMIT='bf5fe9486160be4da86d8987d3e5c977e1dc6d32'
2016-10-29 17:15:56 +02:00
HTMLY_TITLE="My Blog"
2016-10-29 17:13:07 +02:00
HTMLY_SUBTITLE="Another ${PROJECT_NAME} blog"
2016-10-16 20:50:56 +02:00
htmly_variables=(HTMLY_REPO
2016-10-29 14:41:49 +02:00
HTMLY_DOMAIN_NAME
HTMLY_CODE
HTMLY_TITLE
HTMLY_SUBTITLE
ONION_ONLY
DDNS_PROVIDER
MY_USERNAME)
function set_avatar_from_url {
AVATAR="$1"
read_config_param "HTMLY_DOMAIN_NAME"
BASE_DIR=/var/www/$HTMLY_DOMAIN_NAME/htdocs
if [ ! -d $BASE_DIR/customimages ]; then
mkdir $BASE_DIR/customimages
fi
# download the image
cd $BASE_DIR/customimages
# convert to png
wget $AVATAR -O avatar
if [[ $AVATAR == *".gif" ]]; then
mv avatar avatar.gif
mogrify -format png avatar.gif
fi
if [[ $AVATAR == *".jpg" ]]; then
mv avatar avatar.jpg
mogrify -format png avatar.jpg
fi
if [[ $AVATAR == *".jpeg" ]]; then
mv avatar avatar.jpeg
mogrify -format png avatar.jpeg
fi
if [ -f avatar ]; then
mv avatar avatar.png
fi
# standard size
mogrify -resize 150x150 avatar.png
if [ ! -f $BASE_DIR/customimages/avatar.png ]; then
echo $'Avatar image could not be downloaded'
return
fi
chown -R www-data:www-data $BASE_DIR/customimages
AVATAR_SET=1
}
function remove_user_htmly {
remove_username="$1"
2016-11-19 20:17:33 +01:00
${PROJECT_NAME}-pass -u $remove_username --rmapp htmly
2016-10-16 20:50:56 +02:00
if [ -f /var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini ]; then
rm /var/www/${HTMLY_DOMAIN_NAME}/htdocs/config/users/${remove_username}.ini
fi
}
function add_user_htmly {
if [[ $(app_is_installed htmly) == "0" ]]; then
echo '0'
return
fi
new_username="$1"
new_user_password="$2"
2016-11-19 20:17:33 +01:00
${PROJECT_NAME}-pass -u $new_username -a htmly -p "$new_user_password"
2016-10-16 20:50:56 +02:00
if [ ! -d /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users ]; then
echo '2'
return
fi
NEW_USER_PASSWORD_HASH=$(${PROJECT_NAME}-sec --htmlyhash "$new_user_password")
if [ ${#NEW_USER_PASSWORD_HASH} -lt 8 ]; then
echo '3'
return
fi
2016-10-16 20:50:56 +02:00
echo ';Password' > /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
echo "password = $NEW_USER_PASSWORD_HASH" >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
echo 'encryption = password_hash' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
echo ';Role' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
echo 'role = admin' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$new_username.ini
echo '0'
}
function configure_interactive_htmly {
data=$(tempfile 2>/dev/null)
trap "rm -f $data" 0 1 2 5 15
dialog --title $"Change htmly avatar" \
--backtitle $"Freedombone Control Panel" \
--inputbox $"Enter a URL for an image. It should be approximately a square image." 8 75 2>$data
sel=$?
case $sel in
0)
IMAGE_URL=$(<$data)
if [ ${#IMAGE_URL} -gt 5 ]; then
clear
AVATAR_SET=
set_avatar_from_url $IMAGE_URL
if [ $AVATAR_SET ]; then
dialog --title $"Change htmly avatar" \
--msgbox $"Your htmly avatar has been changed" 6 40
fi
fi
;;
esac
}
function install_interactive_htmly {
if [ ! $ONION_ONLY ]; then
ONION_ONLY='no'
fi
if [[ $ONION_ONLY != "no" ]]; then
2016-11-03 13:45:23 +01:00
HTMLY_TITLE='My Htmly Blog'
2016-10-16 20:50:56 +02:00
HTMLY_DOMAIN_NAME='htmly.local'
write_config_param "HTMLY_TITLE" "$HTMLY_TITLE"
2016-10-16 20:50:56 +02:00
write_config_param "HTMLY_DOMAIN_NAME" "$HTMLY_DOMAIN_NAME"
else
function_check interactive_site_details_with_title
2016-10-16 20:50:56 +02:00
interactive_site_details_with_title "htmly" "HTMLY_TITLE" "HTMLY_DOMAIN_NAME" "HTMLY_CODE"
fi
APP_INSTALLED=1
}
function change_password_htmly {
2016-10-16 20:50:56 +02:00
set_completion_param "htmly domain" "$HTMLY_DOMAIN_NAME"
HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
HTMLY_USERNAME="$1"
HTMLY_PASSWORD="$2"
if [ ${#HTMLY_PASSWORD} -lt 8 ]; then
echo $'Htmly password is too short'
return
fi
2016-11-20 13:37:13 +01:00
${PROJECT_NAME}-pass -u "$HTMLY_USERNAME" -a htmly -p "$HTMLY_PASSWORD"
HTMLY_PASSWORD_HASH=$(${PROJECT_NAME}-sec --htmlyhash "$HTMLY_PASSWORD")
if [ ${#HTMLY_PASSWORD_HASH} -lt 8 ]; then
echo $'Htmly admin password could not be hashed'
exit 625728
fi
2016-10-16 20:50:56 +02:00
sed -i "s|password =.*|password = $HTMLY_PASSWORD_HASH|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$HTMLY_USERNAME.ini
}
function reconfigure_htmly {
echo -n ''
}
function upgrade_htmly {
CURR_HTMLY_COMMIT=$(get_completion_param "htmly commit")
if [[ "$CURR_HTMLY_COMMIT" == "$HTMLY_COMMIT" ]]; then
return
fi
2016-10-16 20:50:56 +02:00
read_config_param "HTMLY_DOMAIN_NAME"
function_check set_repo_commit
2016-10-16 20:50:56 +02:00
set_repo_commit /var/www/$HTMLY_DOMAIN_NAME/htdocs "htmly commit" "$HTMLY_COMMIT" $HTMLY_REPO
}
function backup_local_htmly {
2016-11-08 12:25:52 +01:00
HTMLY_DOMAIN_NAME='htmly.local'
if grep -q "htmly domain" $COMPLETION_FILE; then
2016-10-16 20:50:56 +02:00
HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
fi
2016-10-16 20:50:56 +02:00
source_directory=/var/www/${HTMLY_DOMAIN_NAME}/htdocs
if [ -d $source_directory ]; then
dest_directory=htmly
function_check suspend_site
2016-10-16 20:50:56 +02:00
suspend_site ${HTMLY_DOMAIN_NAME}
function_check backup_directory_to_usb
backup_directory_to_usb $source_directory $dest_directory
function_check restart_site
restart_site
fi
}
function restore_local_htmly {
2016-11-08 12:25:52 +01:00
HTMLY_DOMAIN_NAME='htmly.local'
if grep -q "htmly domain" $COMPLETION_FILE; then
2016-10-16 20:50:56 +02:00
HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
fi
2016-10-16 20:50:56 +02:00
if [ $HTMLY_DOMAIN_NAME ]; then
temp_restore_dir=/root/temphtmly
2016-10-31 18:30:24 +01:00
if [ -d $USB_MOUNT/backup/htmly ]; then
restore_directory_from_usb $temp_restore_dir htmly
2016-10-31 18:30:24 +01:00
else
restore_directory_from_usb $temp_restore_dir blog
fi
2016-10-29 14:41:49 +02:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
2016-11-06 17:42:24 +01:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
rm -rf /var/www/${HTMLY_DOMAIN_NAME}/previous
fi
mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs /var/www/${HTMLY_DOMAIN_NAME}/previous
2016-10-29 14:41:49 +02:00
fi
2016-10-29 18:07:18 +02:00
temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
2016-10-29 17:32:09 +02:00
cp -r ${temp_source_dir} /var/www/${HTMLY_DOMAIN_NAME}/
if [ ! "$?" = "0" ]; then
2016-11-06 17:42:24 +01:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
mv /var/www/${HTMLY_DOMAIN_NAME}/previous /var/www/${HTMLY_DOMAIN_NAME}/htdocs
fi
set_user_permissions
backup_unmount_drive
2016-11-08 14:19:46 +01:00
exit 54675
fi
2016-10-29 14:41:49 +02:00
rm -rf ${temp_restore_dir}
2016-10-16 20:50:56 +02:00
if [ ! -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content ]; then
echo $"No content directory found after restoring htmly"
set_user_permissions
backup_unmount_drive
2016-11-08 14:19:46 +01:00
exit 34578
fi
2016-10-16 20:50:56 +02:00
chown -R www-data:www-data /var/www/${HTMLY_DOMAIN_NAME}/htdocs
# Ensure that the bundled SSL cert is being used
2016-10-16 20:50:56 +02:00
if [ -f /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt ]; then
sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}
fi
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
2016-10-16 20:50:56 +02:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post ]; then
mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post
fi
fi
done
2016-10-16 20:50:56 +02:00
if [ -d /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME} ]; then
ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${HTMLY_DOMAIN_NAME}.key
ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem
fi
fi
}
function backup_remote_htmly {
if grep -q "htmly domain" $COMPLETION_FILE; then
2016-10-16 20:50:56 +02:00
HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
temp_backup_dir=/var/www/${HTMLY_DOMAIN_NAME}/htdocs
if [ -d $temp_backup_dir ]; then
echo $"Backing up htmly"
backup_directory_to_friend $temp_backup_dir htmly
echo $"Backup of htmly complete"
else
echo $"Htmly domain specified but not found in $temp_backup_dir"
exit 2578
fi
fi
}
function restore_remote_htmly {
if [ -d $SERVER_DIRECTORY/backup/htmly ]; then
2016-10-16 20:50:56 +02:00
HTMLY_DOMAIN_NAME=$(get_completion_param "htmly domain")
echo $"Restoring htmly installation $HTMLY_DOMAIN_NAME"
temp_restore_dir=/root/temphtmly
mkdir $temp_restore_dir
function_check restore_directory_from_friend
restore_directory_from_friend $temp_restore_dir htmly
2016-10-29 14:41:49 +02:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs ]; then
2016-11-06 17:42:24 +01:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
rm -rf /var/www/${HTMLY_DOMAIN_NAME}/previous
fi
mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs /var/www/${HTMLY_DOMAIN_NAME}/previous
2016-10-29 14:41:49 +02:00
fi
2016-10-29 18:07:18 +02:00
temp_source_dir=$(find ${temp_restore_dir} -name htdocs)
2016-10-29 17:32:09 +02:00
cp -r ${temp_source_dir} /var/www/${HTMLY_DOMAIN_NAME}/
if [ ! "$?" = "0" ]; then
2016-11-06 17:42:24 +01:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/previous ]; then
mv /var/www/${HTMLY_DOMAIN_NAME}/previous /var/www/${HTMLY_DOMAIN_NAME}/htdocs
fi
exit 593
fi
2016-10-29 14:41:49 +02:00
rm -rf ${temp_restore_dir}
2016-10-16 20:50:56 +02:00
if [ ! -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content ]; then
echo $"No content directory found after restoring htmly"
exit 287
fi
# Ensure that the bundled SSL cert is being used
2016-10-16 20:50:56 +02:00
if [ -f /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.bundle.crt ]; then
sed -i "s|${HTMLY_DOMAIN_NAME}.crt|${HTMLY_DOMAIN_NAME}.bundle.crt|g" /etc/nginx/sites-available/${HTMLY_DOMAIN_NAME}
fi
for d in /home/*/ ; do
USERNAME=$(echo "$d" | awk -F '/' '{print $3}')
if [[ $(is_valid_user "$USERNAME") == "1" ]]; then
2016-10-16 20:50:56 +02:00
if [ -d /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post ]; then
mv /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/*.md /var/www/${HTMLY_DOMAIN_NAME}/htdocs/content/$USERNAME/htmly/uncategorized/post
fi
fi
done
2016-10-16 20:50:56 +02:00
if [ -d /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME} ]; then
ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/privkey.pem /etc/ssl/private/${HTMLY_DOMAIN_NAME}.key
ln -s /etc/letsencrypt/live/${HTMLY_DOMAIN_NAME}/fullchain.pem /etc/ssl/certs/${HTMLY_DOMAIN_NAME}.pem
fi
echo $"Restore of htmly complete"
fi
}
function remove_htmly {
2016-10-16 20:50:56 +02:00
if [ ${#HTMLY_DOMAIN_NAME} -eq 0 ]; then
return
fi
2016-10-16 20:50:56 +02:00
read_config_param "HTMLY_DOMAIN_NAME"
nginx_dissite $HTMLY_DOMAIN_NAME
2016-10-20 23:02:16 +02:00
remove_certs ${HTMLY_DOMAIN_NAME}
2016-10-16 20:50:56 +02:00
if [ -f /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME ]; then
rm -f /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
fi
2016-10-16 20:50:56 +02:00
if [ -d /var/www/$HTMLY_DOMAIN_NAME ]; then
rm -rf /var/www/$HTMLY_DOMAIN_NAME
fi
2016-10-17 14:59:45 +02:00
remove_config_param HTMLY_DOMAIN_NAME
remove_config_param HTMLY_CODE
function_check remove_onion_service
2016-10-16 20:50:56 +02:00
remove_onion_service htmly ${HTMLY_ONION_PORT}
2016-10-18 11:43:08 +02:00
remove_completion_param "install_htmly"
2016-10-28 12:59:24 +02:00
sed -i '/Htmly/d' $COMPLETION_FILE
sed -i '/htmly/d' $COMPLETION_FILE
function_check remove_ddns_domain
remove_ddns_domain $HTMLY_DOMAIN_NAME
}
function install_htmly_social_networks {
# set social networks
2016-10-16 20:50:56 +02:00
if grep -q "social.hubzilla" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini; then
sed -i "s|;social.hubzilla|social.hubzilla|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
sed -i "s|social.hubzilla.*|social.hubzilla = \"$HUBZILLA_DOMAIN_NAME\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
fi
2016-10-16 20:50:56 +02:00
if grep -q "social.gnusocial" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini; then
sed -i "s|;social.gnusocial|social.gnusocial|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
sed -i "s|social.gnusocial.*|social.gnusocial = \"$MICROHTMLY_DOMAIN_NAME\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
fi
# clear proprietary social network strings
2016-10-16 20:50:56 +02:00
sed -i 's|social.facebook.*|social.facebook = ""|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
sed -i 's|social.twitter.*|social.twitter = ""|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
sed -i 's|social.google.*|social.google = ""|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
}
function install_htmly_user {
# create a user password
2016-11-19 10:37:35 +01:00
if [ -f $IMAGE_PASSWORD_FILE ]; then
HTMLY_ADMIN_PASSWORD="$(printf `cat $IMAGE_PASSWORD_FILE`)"
2016-11-19 20:17:33 +01:00
else
2016-11-19 10:37:35 +01:00
HTMLY_ADMIN_PASSWORD="$(create_password ${MINIMUM_PASSWORD_LENGTH})"
fi
# create a user
2016-10-16 20:50:56 +02:00
HTMLY_ADMIN_PASSWORD_HASH=$(${PROJECT_NAME}-sec --htmlyhash "$HTMLY_ADMIN_PASSWORD")
if [ ${#HTMLY_ADMIN_PASSWORD_HASH} -lt 8 ]; then
echo $'Htmly admin password could not be hashed'
exit 625728
fi
2016-10-16 20:50:56 +02:00
echo ';Password' > /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
echo "password = $HTMLY_ADMIN_PASSWORD_HASH" >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
echo 'encryption = password_hash' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
echo ';Role' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
echo 'role = admin' >> /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/users/$MY_USERNAME.ini
}
function install_htmly_settings {
2016-10-16 20:50:56 +02:00
cp /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini.example /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
sed -i "s|site.url.*|site.url = '/'|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
2016-10-29 17:07:01 +02:00
sed -i "s|blog.title.*|blog.title = \"$HTMLY_TITLE\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
sed -i "s|blog.tagline.*|blog.tagline = \"$HTMLY_SUBTITLE\"|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
2016-10-16 20:50:56 +02:00
sed -i 's|timezone.*|timezone = "Europe/London"|g' /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
sed -i "s|Your name|$MY_NAME|g" /var/www/$HTMLY_DOMAIN_NAME/htdocs/config/config.ini
}
function install_htmly_website {
function_check nginx_http_redirect
2016-10-16 20:50:56 +02:00
nginx_http_redirect $HTMLY_DOMAIN_NAME
echo 'server {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-11-17 23:45:20 +01:00
echo ' listen [::]:443 ssl;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
echo " root /var/www/$HTMLY_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " server_name $HTMLY_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-11-10 14:26:31 +01:00
echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-11-18 19:33:08 +01:00
echo " error_log /dev/null;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
echo ' index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' charset utf-8;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
function_check nginx_ssl
2016-10-16 20:50:56 +02:00
nginx_ssl $HTMLY_DOMAIN_NAME
function_check nginx_disable_sniffing
2016-10-16 20:50:56 +02:00
nginx_disable_sniffing $HTMLY_DOMAIN_NAME
echo ' add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location / {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
function_check nginx_limits
2016-10-16 20:50:56 +02:00
nginx_limits $HTMLY_DOMAIN_NAME
echo ' rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-11-11 18:36:30 +01:00
nginx_keybase ${HTMLY_DOMAIN_NAME}
2016-10-16 20:50:56 +02:00
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # statically serve these file types when possible' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # allow browser to cache them' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' expires 30d;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # block these file types' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # or a unix socket' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~* \.php$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2017-05-29 15:40:34 +02:00
echo ' # With php-cgi alone:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
echo ' # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2017-05-29 15:40:34 +02:00
echo ' # With php-fpm:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2017-06-03 21:20:04 +02:00
echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
echo ' include fastcgi_params;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # deny access to all dot files' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /\. {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' #deny access to store' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /store {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /\.ht {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '}' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
}
function install_htmly_website_onion {
2016-10-16 20:50:56 +02:00
echo 'server {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " listen 127.0.0.1:${HTMLY_ONION_PORT} default_server;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " root /var/www/$HTMLY_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " server_name $HTMLY_DOMAIN_NAME;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-11-10 14:26:31 +01:00
echo ' access_log /dev/null;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-11-18 19:33:08 +01:00
echo " error_log /dev/null;" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
echo ' index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' charset utf-8;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' proxy_read_timeout 86400s;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
function_check nginx_disable_sniffing
2016-10-16 20:50:56 +02:00
nginx_disable_sniffing $HTMLY_DOMAIN_NAME
echo ' add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # rewrite to front controller as default rule' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location / {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
function_check nginx_limits
2016-10-16 20:50:56 +02:00
nginx_limits $HTMLY_DOMAIN_NAME
echo ' rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-11-11 18:36:30 +01:00
nginx_keybase ${HTMLY_DOMAIN_NAME}
2016-10-16 20:50:56 +02:00
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # statically serve these file types when possible' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # otherwise fall back to front controller' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # allow browser to cache them' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # added .htm for advanced source code editor library' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~* \.(jpg|jpeg|gif|png|ico|css|js|htm|html|ttf|woff|svg)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' expires 30d;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' try_files $uri /index.php?q=$uri&$args;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # block these file types' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~* \.(tpl|md|tgz|log|out)$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # or a unix socket' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~* \.php$ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
function_check nginx_limits
2016-10-16 20:50:56 +02:00
nginx_limits $HTMLY_DOMAIN_NAME
echo ' # Zero-day exploit defense.' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # http://forum.nginx.org/read.php?2,88845,page=3' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # Won't work properly (404 error) if the file is not stored on this" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # server, which is entirely possible with php-fpm/php-fcgi." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # Comment the 'try_files' line out if you set up php-fpm/php-fcgi on" >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo " # another machine. And then cross your fingers that you won't get hacked." >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' try_files $uri $uri/ /index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2017-05-29 15:40:34 +02:00
echo ' # With php-cgi alone:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
echo ' # fastcgi_pass 127.0.0.1:9000;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2017-05-29 15:40:34 +02:00
echo ' # With php-fpm:' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2017-06-03 21:20:04 +02:00
echo ' fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
echo ' include fastcgi_params;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' # deny access to all dot files' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /\. {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' #deny access to store' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /store {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /(data|conf|bin|inc)/ {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' location ~ /\.ht {' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' deny all;' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo ' }' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
echo '}' >> /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
}
function install_htmly_from_repo {
2016-10-16 20:50:56 +02:00
if [ ! -d /var/www/$HTMLY_DOMAIN_NAME ]; then
mkdir /var/www/$HTMLY_DOMAIN_NAME
fi
2016-10-16 20:50:56 +02:00
cd /var/www/$HTMLY_DOMAIN_NAME
2017-06-15 13:33:16 +02:00
if [ -d /repos/htmly ]; then
mkdir htdocs
cp -r -p /repos/htmly/* htdocs
cd htdocs
git pull
else
git_clone $HTMLY_REPO htdocs
fi
cd htdocs
2016-10-16 20:50:56 +02:00
git checkout $HTMLY_COMMIT -b $HTMLY_COMMIT
set_completion_param "htmly commit" "$HTMLY_COMMIT"
}
function install_htmly {
if [ ! $ONION_ONLY ]; then
ONION_ONLY='no'
fi
2016-10-16 20:50:56 +02:00
if [ ! $HTMLY_DOMAIN_NAME ]; then
echo $'The htmly domain name was not specified'
exit 5062
fi
# for the avatar changing command
2017-06-03 18:42:22 +02:00
apt-get -yq install imagemagick libfcgi0ldbl
function_check install_htmly_from_repo
install_htmly_from_repo
if [[ $ONION_ONLY == "no" ]]; then
function_check install_htmly_website
install_htmly_website
else
2016-10-16 20:50:56 +02:00
echo -n '' > /etc/nginx/sites-available/$HTMLY_DOMAIN_NAME
fi
function_check install_htmly_website_onion
install_htmly_website_onion
function_check create_site_certificate
2016-10-16 20:50:56 +02:00
create_site_certificate $HTMLY_DOMAIN_NAME 'yes'
function_check configure_php
configure_php
function_check install_htmly_settings
install_htmly_settings
function_check install_htmly_social_networks
install_htmly_social_networks
function_check install_htmly_user
install_htmly_user
2016-10-16 20:50:56 +02:00
chown -R www-data:www-data /var/www/$HTMLY_DOMAIN_NAME/htdocs
2016-10-16 20:50:56 +02:00
HTMLY_ONION_HOSTNAME=$(add_onion_service htmly 80 ${HTMLY_ONION_PORT})
function_check nginx_ensite
2016-10-16 20:50:56 +02:00
nginx_ensite $HTMLY_DOMAIN_NAME
2017-06-01 20:05:15 +02:00
systemctl restart php7.0-fpm
systemctl restart nginx
2016-11-19 20:17:33 +01:00
${PROJECT_NAME}-pass -u $MY_USERNAME -a htmly -p "$HTMLY_ADMIN_PASSWORD"
function_check add_ddns_domain
2016-10-16 20:50:56 +02:00
add_ddns_domain $HTMLY_DOMAIN_NAME
2016-10-16 20:50:56 +02:00
set_completion_param "htmly domain" "$HTMLY_DOMAIN_NAME"
APP_INSTALLED=1
}
# NOTE: deliberately no exit 0