diff --git a/kazewp.sh b/kazewp.sh index c5d9dfc..eef8856 100755 --- a/kazewp.sh +++ b/kazewp.sh @@ -41,47 +41,45 @@ install_site() { setup_directories DOMAIN="$1" - #db_prefix="$(openssl rand -base64 6)"_ - - -while true; do - read -p "Enter admin email: " ADMIN_EMAIL - if validate_email "$ADMIN_EMAIL"; then - break + + WP_PROJECT_DIR="${WORDPRESS_DIR}/${DOMAIN}" + if [ -d "$WP_PROJECT_DIR" ]; then + echo -e "${RED}Directory ${WP_PROJECT_DIR} already exists!${NC}" + exit 1 fi -done - -read -p "Enter admin username: " ADMIN_USER - -read -s -p "Enter password (press Enter for random password): " ADMIN_PASSWORD -echo - -if [ -z "$ADMIN_PASSWORD" ]; then - ADMIN_PASSWORD=$(generate_password) - echo "Generated password: $ADMIN_PASSWORD" -fi - -read -p "Enter site title: " SITE_TITLE - -MYSQL_ROOT_PASSWORD=$(openssl rand -base64 32) -MYSQL_PASSWORD=$(openssl rand -base64 32) - -WP_PROJECT_DIR="${WORDPRESS_DIR}/${DOMAIN}" -if [ -d "$WP_PROJECT_DIR" ]; then - echo -e "${RED}Directory ${WP_PROJECT_DIR} already exists!${NC}" - exit 1 -fi - -mkdir -p "$WP_PROJECT_DIR" -cd "$WP_PROJECT_DIR" - -create_docker_compose "$DOMAIN" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD" -create_caddy_config "$DOMAIN" -create_wp_setup "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$SITE_TITLE" -create_env_file "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD" + while true; do + read -p "Enter admin email: " ADMIN_EMAIL + if validate_email "$ADMIN_EMAIL"; then + break + fi + done + + read -p "Enter admin username: " ADMIN_USER + + read -s -p "Enter password (press Enter for random password): " ADMIN_PASSWORD + echo + + if [ -z "$ADMIN_PASSWORD" ]; then + ADMIN_PASSWORD=$(generate_password) + echo "Generated password: $ADMIN_PASSWORD" + fi + + read -p "Enter site title: " SITE_TITLE + + MYSQL_ROOT_PASSWORD=$(openssl rand -base64 32) + MYSQL_PASSWORD=$(openssl rand -base64 32) + + mkdir -p "$WP_PROJECT_DIR" + cd "$WP_PROJECT_DIR" + + + create_docker_compose "$DOMAIN" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD" + create_caddy_config "$DOMAIN" + create_wp_setup "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$SITE_TITLE" + create_env_file "$DOMAIN" "$ADMIN_USER" "$ADMIN_PASSWORD" "$ADMIN_EMAIL" "$MYSQL_ROOT_PASSWORD" "$MYSQL_PASSWORD" while true; do diff --git a/lib/caddy.sh b/lib/caddy.sh index f9a967d..48d0b63 100644 --- a/lib/caddy.sh +++ b/lib/caddy.sh @@ -33,6 +33,38 @@ create_caddy_docker_compose() { admin off persist_config off } +(wordpress) { + + # Some static files Cache-Control. + @static { + path *.ico *.css *.js *.gif *.jpg *.jpeg *.png *.svg *.woff *.json + } + header @static Cache-Control max-age=2592000 + + # Security + @forbidden { + not path /wp-includes/ms-files.php + path /wp-admin/includes/*.php + path /wp-includes/*.php + path /wp-config.php + path /wp-content/uploads/*.php + path /.user.ini + path /wp-content/debug.log + } + respond @forbidden "Access denied" 403 + + # Cache Enabler + @cache_enabler { + not header_regexp Cookie "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in" + not path_regexp "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(index)?.xml|[a-z0-9-]+-sitemap([0-9]+)?.xml)" + not method POST + not expression {query} != '' + } + + route @cache_enabler { + try_files /wp-content/cache/cache-enabler/{host}{uri}/https-index.html /wp-content/cache/cache-enabler/{host}{uri}/index.html {path} {path}/index.php?{query} + } +} # Site configurations will be imported below import sites/*.caddy diff --git a/templates/caddy.template b/templates/caddy.template index 9e5c83f..01fff21 100644 --- a/templates/caddy.template +++ b/templates/caddy.template @@ -1,7 +1,6 @@ ${DOMAIN} { - #reverse_proxy wordpress_${DOMAIN}:80 - - tls internal + + #tls internal root * /var/www/${DOMAIN}/html encode zstd gzip @@ -18,5 +17,6 @@ ${DOMAIN} { X-Frame-Options "SAMEORIGIN" X-Content-Type-Options "nosniff" } + import wordpress } diff --git a/templates/wp-setup.sh.template b/templates/wp-setup.sh.template index 2eb2e55..8edaded 100644 --- a/templates/wp-setup.sh.template +++ b/templates/wp-setup.sh.template @@ -11,20 +11,60 @@ while [ "$(docker inspect --format='{{.State.Health.Status}}' db_${DOMAIN})" != sleep 5 done +if ! wpcli core is-installed ; then + echo "Installing WordPress..." + wpcli core install \ + --url="https://${DOMAIN}" \ + --title="${SITE_TITLE}" \ + --admin_user="${ADMIN_USER}" \ + --admin_password="${ADMIN_PASSWORD}" \ + --admin_email="${ADMIN_EMAIL}" \ + --skip-email -echo "Installing WordPress..." -wpcli core install \ - --url="https://${DOMAIN}" \ - --title="${SITE_TITLE}" \ - --admin_user="${ADMIN_USER}" \ - --admin_password="${ADMIN_PASSWORD}" \ - --admin_email="${ADMIN_EMAIL}" \ - --skip-email + echo "Installing and activating plugins..." + wpcli plugin install wordfence cache-enabler --activate + wpcli option update cache_enabler '{ + "version": "1.8.15", + "use_trailing_slashes": 1, + "permalink_structure": "has_trailing_slash", + "cache_expires": 1, + "cache_expiry_time": 8, + "clear_site_cache_on_saved_post": 0, + "clear_site_cache_on_saved_comment": 0, + "clear_site_cache_on_saved_term": 0, + "clear_site_cache_on_saved_user": 0, + "clear_site_cache_on_changed_plugin": 0, + "convert_image_urls_to_webp": 0, + "mobile_cache": 0, + "compress_cache": 1, + "minify_html": 1, + "minify_inline_css_js": 1, + "excluded_post_ids": "", + "excluded_page_paths": "", + "excluded_query_strings": "", + "excluded_cookies": "" + }' --format=json -echo "Installing and activating plugins..." -wpcli plugin install wordfence --activate -wpcli theme install twentytwentyfour --activate -wpcli plugin update --all -wpcli theme update --all + wpcli theme install kadence --activate + wpcli plugin update --all + wpcli theme update --all -echo "WordPress setup completed!" \ No newline at end of file + # List users + echo "== User List ==" + wpcli user list + echo "" + + # Show installed plugin + echo "== Theme List ==" + wpcli theme list + echo "" + + # Show installed plugin + echo "== Plugin List ==" + wpcli plugin list + echo "" + + echo "WordPress setup completed!" +else + echo "WordPress is already installed. Exiting now..." +fi \ No newline at end of file